Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

Название категорий товаров в корзине(Opencart 3.0.2.0)


Recommended Posts

Добрый гдень! Возникла проблема с Opencart 3.0.2.0 

 

Задача икая: Надо вывести название категории товаров, которые находятся в корзине. У меня полулилось вывести название категорий, но оно заменяет название товара.

 

Что я гделал для этого:

1) Нашел файл \system\library\cart.php Там нашел строку

$product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'");

и заменил на строку

$product_query = $this->db->query("SELECT *, cd.name as category_name FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_category ptc ON (ptc.product_id=p.product_id) LEFT JOIN " . DB_PREFIX . "category_description cd ON (cd.category_id=ptc.category_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'");

2) Дное в том же файле я нашел массив

$product_data[] = array(...

и добавил в него строчку

'category_id' => $product_query->row['category_id'],

3) Выводить пыился ик:

{% if product.category_id %}
  {# {% for catlist in catname %} #}
    <li>{{ product.category_id }}</li>
  {# {% endfor %} #}
{% endif %}

Даже пыился всячески менять этот вывод, но ничего не выводит.

 

4) Название категории начало после всех добавлений выводится вместо названия товара, который я вывожу ик

{% for product in products %}
<span>
  <a href="{{ product.href }}" class="cart-name">{{ product.name }}</a>
</span>
{% endfor %}

unknown.png

Edited by wAsOne
Link to comment
Share on other sites


А почему правки в библиотеку вносили, а не в контроллер самой корзины или чекауи?

А вообещё скорее всего ошибка вот тут

$product_data[] = array(..

и строчку

'name'            => $product_query->row['name'],

нужно заменить на что-то типа

 

'name'            => $product_query->row['pd.name'],

 

Link to comment
Share on other sites


21 hours ago, openprice said:

А почему правки в библиотеку вносили, а не в контроллер самой корзины или чекауи?

А вообещё скорее всего ошибка вот тут

$product_data[] = array(..

и строчку

'name'            => $product_query->row['name'],

нужно заменить на что-то типа

 

'name'            => $product_query->row['pd.name'],

 

 

Добавлял в библиотеку, ипотому что гделал по этому примеру

икже подобных переменных в контроллере нет, им немного иная система, но подобный массив имеется(снизу):

$data['products'] = array();

			$products = $this->cart->getProducts();

			foreach ($products as $product) {
				$product_total = 0;

				foreach ($products as $product_2) {
					if ($product_2['product_id'] == $product['product_id']) {
						$product_total += $product_2['quantity'];
					}
				}

				if ($product['minimum'] > $product_total) {
					$data['error_warning'] = sprintf($this->language->get('error_minimum'), $product['name'], $product['minimum']);
				}

				if ($product['image']) {
					$image = $this->model_tool_image->resize($product['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_cart_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_cart_height'));
				} else {
					$image = '';
				}

				$option_data = array();

				foreach ($product['option'] as $option) {
					if ($option['type'] != 'file') {
						$value = $option['value'];
					} else {
						$upload_info = $this->model_tool_upload->getUploadByCode($option['value']);

						if ($upload_info) {
							$value = $upload_info['name'];
						} else {
							$value = '';
						}
					}

					$option_data[] = array(
						'name'  => $option['name'],
						'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value)
					);
				}

				// Display prices
				if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
					$unit_price = $this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'));
					
					$price = $this->currency->format($unit_price, $this->session->data['currency']);
					$total = $this->currency->format($unit_price * $product['quantity'], $this->session->data['currency']);
				} else {
					$price = false;
					$total = false;
				}

				$recurring = '';

				if ($product['recurring']) {
					$frequencies = array(
						'day'        => $this->language->get('text_day'),
						'week'       => $this->language->get('text_week'),
						'semi_month' => $this->language->get('text_semi_month'),
						'month'      => $this->language->get('text_month'),
						'year'       => $this->language->get('text_year')
					);

					if ($product['recurring']['trial']) {
						$recurring = sprintf($this->language->get('text_trial_description'), $this->currency->format($this->tax->calculate($product['recurring']['trial_price'] * $product['quantity'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']), $product['recurring']['trial_cycle'], $frequencies[$product['recurring']['trial_frequency']], $product['recurring']['trial_duration']) . ' ';
					}

					if ($product['recurring']['duration']) {
						$recurring .= sprintf($this->language->get('text_payment_description'), $this->currency->format($this->tax->calculate($product['recurring']['price'] * $product['quantity'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']), $product['recurring']['cycle'], $frequencies[$product['recurring']['frequency']], $product['recurring']['duration']);
					} else {
						$recurring .= sprintf($this->language->get('text_payment_cancel'), $this->currency->format($this->tax->calculate($product['recurring']['price'] * $product['quantity'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']), $product['recurring']['cycle'], $frequencies[$product['recurring']['frequency']], $product['recurring']['duration']);
					}
				}

				$data['products'][] = array(
					'cart_id'   => $product['cart_id'],
					'thumb'     => $image,
					'name'      => $product['name'],
					'model'     => $product['model'],
					'option'    => $option_data,
					'recurring' => $recurring,
					'quantity'  => $product['quantity'],
					'stock'     => $product['stock'] ? true : !(!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning')),
					'reward'    => ($product['reward'] ? sprintf($this->language->get('text_points'), $product['reward']) : ''),
					'price'     => $price,
					'total'     => $total,
					'href'      => $this->url->link('product/product', 'product_id=' . $product['product_id'])
				);
			}

 

При замене на: 

'name'            => $product_query->row['pd.name'],

Выходит из корзины и выкидывает на страницу товара, ггде при попытке зайти в корзину с товаром выводит ошибку:

image.png.ce594cc949e95e270ec908c7cccfee6b.png

 

Edited by wAsOne
Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.