@Xtrme

Что за ошибка в товарах product.php on line 432 — 436?

Подскажите, пожалуйста, сайт на локалке, Opencart 3.0.2, когда заходишь в какой-либо товар, все отображается, но сверху страницы выдает ошибку.
Notice: Undefined variable: result in \domains\storage\modification\catalog\controller\product\product.php on line 432Notice: Undefined variable: image in \domains\storage\modification\catalog\controller\product\product.php on line 436.
Вот код этих строк:
$images = $this->model_catalog_product->getProductImages($result['product_id']);
			if(isset($images[0]['image']) && !empty($images)){
				$images = $images[0]['image']; 
			}else{
				$images = $image;
  • Вопрос задан
  • 369 просмотров
Решения вопроса 1
IsSavinykh
@IsSavinykh
Full-Stack Веб-разработчик, мобильный разработчик
Объявите переменную $result = [] перед конструкциями if, foreach и т.д.
$result = [];
if(...) {
     foreach(... as ...) {
          $images = $this->model_catalog_product->getProductImages($result['product_id']);
          if(isset($images[0]['image']) && !empty($images)){
               $images = $images[0]['image']; 
          } else {
               $images = $image;
          }
}
Ответ написан
Пригласить эксперта
Ответы на вопрос 2
@grisha2217
Переменная $result не существует. Возможно $result объявляется внутри foreach или if, поэтому не существует.
Ответ написан
Комментировать
@liza2019
этот кусок у вас от какого то мода. видимо он вставлен не туда куда надо. вне цикла
foreach ($results as $result) {
так что то сказать невозможно. надо смотреть всю функцию куда вставлен этот кусок.
хотя честно говоря смысла в этом куске не особо видно. в родном файле это выглядит так
$results = $this->model_catalog_product->getProductImages($this->request->get['product_id']);

$results = $this->model_catalog_product->getProductImages($this->request->get['product_id']);

			foreach ($results as $result) {
				$data['images'][] = array(
					'popup' => $this->model_tool_image->resize($result['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_height')),
					'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_additional_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_additional_height'))
				);
			}

или попробуйте заменить $result['product_id'] на $product_info['product_id']
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы