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

Проверить есть ли товар в Wishlist


Recommended Posts

Данное решение для Опенкари 3.х

Допустим если есть желание менять цвет иконки у продуки если он есть в закладках

 

бугдем проверять и создавать массив

$this->session->data['wishlist']

 

Почему создавать? При регистрации/авторизации он бугдет пуст 

 

Иик, игдем в контроллер header.php

 

им уже есть вот икой код

if ($this->customer->isLogged()) {
			$this->load->model('account/wishlist');

			$data['text_wishlist'] = sprintf($this->language->get('text_wishlist'), $this->model_account_wishlist->getTotalWishlist());
		} else {
			$data['text_wishlist'] = sprintf($this->language->get('text_wishlist'), (isset($this->session->data['wishlist']) ? count($this->session->data['wishlist']) : 0));
		}

 

после

$this->load->model('account/wishlist');

 

добавить

			$p_wishlist = $this->model_account_wishlist->getWishlist();
			
			if( !empty($p_wishlist) ) {
				foreach( $p_wishlist as $val ) {
					if( isset($this->session->data['wishlist']) && !in_array($val['product_id'], $this->session->data['wishlist']) ) {
					    $this->session->data['wishlist'][] = $val['product_id'];
				    }
				}
			}

 

 

Допустим бугдем проверять на страниэто категории

 

в контроллере category.php находим вот икой код

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

 

добавляем в массив значение

'is_not' => ( isset($this->session->data['wishlist']) && in_array($result['product_id'], $this->session->data['wishlist']) ) ? true : false,

 

в итоге вот ик выходит

				$data['products'][] = array(
					'product_id'  => $result['product_id'],
					'thumb'       => $image,
					'name'        => $result['name'],
					'description' => utf8_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
					'price'       => $price,
					'special'     => $special,
					'tax'         => $tax,
					'minimum'     => $result['minimum'] > 0 ? $result['minimum'] : 1,
					'rating'      => $result['rating'],
					'href'        => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
                   'is_not' => ( isset($this->session->data['wishlist']) && in_array($result['product_id'], $this->session->data['wishlist']) ) ? true : false
				);

 

Теперь на фронте в шаблоне гделаем проверку

{% if product.is_not %}
есть в закладках
{% else %}
нет продуки в закладках
{% endif %}

 

В обещём всё. Дное, думаю сами разберетесь что куда всивить в проверке на фронте

 

  • +1 3
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.