Перейти до вмісту
Пошук в
  • Детальніше...
Шукати результати, які ...
Шукати результати в ...

Ошибка: PHP Warning: array_merge(): Argument #1 is not an array in


Recommended Posts

Привет народ!

Есть ошибка массива, точнее его отсутствия: 

Вот ошибка: 

2018-07-24 22:54:48 - PHP Warning:  array_merge(): Argument #1 is not an array in /home/system/storage/modification/catalog/controller/product/product.php on line 738

Вот код на который ругается: 

$results[] = array_merge($this->model_catalog_product->getProduct($p['product_id']), array("quantity_pack" => $p['quantity']));

А это полный код из модификатора: 

$data['pack'] = array();
			$this->load->library("ocmodules");
            $this->ocmodules->loadPlugin("productpacks");
			$pack = $this->productpacks->getPack($this->request->get['product_id']);

			$results = array();

			foreach ($pack as $p) {
				$results[] = array_merge($this->model_catalog_product->getProduct($p['product_id']), array("quantity_pack" => $p['quantity']));
			}
			if ($results) $this->document->addStyle('catalog/view/theme/default/stylesheet/packs.css');
			foreach ($results as $result) {
				if ($result['image']) {
					$image = $this->model_tool_image->resize($result['image'], $this->config->get($this->config->get('config_theme') . '_image_related_width'), $this->config->get($this->config->get('config_theme') . '_image_related_height'));
				} else {
					$image = $this->model_tool_image->resize('placeholder.png', $this->config->get($this->config->get('config_theme') . '_image_related_width'), $this->config->get($this->config->get('config_theme') . '_image_related_height'));
				}

				if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
					$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
				} else {
					$price = false;
				}

				if ((float)$result['special']) {
					$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
				} else {
					$special = false;
				}

				if ($this->config->get('config_tax')) {
					$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
				} else {
					$tax = false;
				}

				if ($this->config->get('config_review_status')) {
					$rating = (int)$result['rating'];
				} else {
					$rating = false;
				}

				$data['pack'][] = array(
					"quantity"    =>$result["quantity_pack"],
					'product_id'  => $result['product_id'],
					'thumb'       => $image,
					'name'        => $result['name'],
					'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get($this->config->get('config_theme') . '_product_description_length')) . '..',
					'price'       => $price,
					'special'     => $special,
					'tax'         => $tax,
					'minimum'     => $result['minimum'] > 0 ? $result['minimum'] : 1,
					'rating'      => $rating,
					'href'        => $this->url->link('product/product', 'product_id=' . $result['product_id'])
				);
			}

Кто подскажет почему ругается? 

Змінено користувачем DrBraun
Надіслати
Поділитися на інших сайтах


Надо так:

$product_info = $this->model_catalog_product->getProduct($p['product_id']);
$results[] = array_merge(product_info, array("quantity_pack" => $p['quantity']));

Или так:

$product_info = $this->model_catalog_product->getProduct($p['product_id']);
$product_info['quantity_pack'] = $p['quantity'];
$results[] = product_info;

Но самый правильный вариант - это добавить нужные данные непосредственно в модели.

Один раз. И не надо будет править кучу контроллеров. Эти данные будут везде, где используется штатный метод getProduct.

  • +1 1
Надіслати
Поділитися на інших сайтах

  • 6 months later...
В 24.07.2018 в 23:26, mpn2005 сказал:

Но самый правильный вариант - это добавить нужные данные непосредственно в модели.

Один раз. И не надо будет править кучу контроллеров. Эти данные будут везде, где используется штатный метод getProduct.

Данный вариант не помог. Все равно выдает ошибку. Не подскажите каким образом добавить данные в model ? 

Надіслати
Поділитися на інших сайтах


Створіть аккаунт або увійдіть для коментування

Ви повинні бути користувачем, щоб залишити коментар

Створити обліковий запис

Зареєструйтеся для отримання облікового запису. Це просто!

Зареєструвати аккаунт

Вхід

Уже зареєстровані? Увійдіть тут.

Вхід зараз
  • Зараз на сторінці   0 користувачів

    • Ні користувачів, які переглядиють цю сторінку
×
×
  • Створити...

Important Information

На нашому сайті використовуються файли cookie і відбувається обробка деяких персональних даних користувачів, щоб поліпшити користувальницький інтерфейс. Щоб дізнатися для чого і які персональні дані ми обробляємо перейдіть за посиланням . Якщо Ви натиснете «Я даю згоду», це означає, що Ви розумієте і приймаєте всі умови, зазначені в цьому Повідомленні про конфіденційність.