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

Сравнение - уведомление о превышение лимии товаров


Recommended Posts

Добрый гдень.
Хотел сгделать уведомление при достижении 5 товаров в сравнении, но 'success' возвращает пустое значение. Хотел бы понять почему ик происходит. 
 


		if ($product_info) {
			if (!in_array($this->request->post['product_id'], $this->session->data['compare'])) {
				if (count($this->session->data['compare']) >= 5) {

					$json['success'] = $this->language->get('text_compare_limit'); //возвращает unexpected end of json input
					$json['total'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
					$this->response->addHeader('Content-Type: application/json');
					$this->response->setOutput(json_encode($json));
					
					die();
					
					array_shift($this->session->data['compare']);
				}

				$this->session->data['compare'][] = $this->request->post['product_id'];
			}

			$json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . $this->request->post['product_id']), $product_info['name'], $this->url->link('product/compare'));

			$json['total'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
		}

 

Link to comment
Share on other sites


  • 2 weeks later...

Для потомков - решение:
в /catalog/controller/account/wishlist.php
меняем


		if ($product_info) {
			if (!in_array($this->request->post['product_id'], $this->session->data['compare'])) {
				if (count($this->session->data['compare']) >= 4) {
					array_shift($this->session->data['compare']);
				}

				$this->session->data['compare'][] = $this->request->post['product_id'];
			}

			$json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . $this->request->post['product_id']), $product_info['name'], $this->url->link('product/compare'));

			$json['total'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
		}

 

на 

 

			if ($product_info) {
				if (!in_array($this->request->post['product_id'], $this->session->data['compare'])) {
					if (count($this->session->data['compare']) >= 5) {
						//array_shift($this->session->data['compare']);
					}

					if (count($this->session->data['compare']) < 5) {
						$this->session->data['compare'][] = $this->request->post['product_id'];
					}
				}

				//$json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . $this->request->post['product_id']), $product_info['name'], $this->url->link('product/compare'));
				
				if (count($this->session->data['compare']) >= 5) {
					$json['warning'] = 'В сравнении 5 из 5';
				} else {
					$json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . $this->request->post['product_id']), $product_info['name'], $this->url->link('product/compare'));
				}

				$json['total'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
			}


Открываем /catalog/view/javascript/common.js

В var compare = { иещём 

 

if (json['success']) {
					$('#content').parent().before('<div class="alert alert-success alert-dismissible"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');

					$('#compare-total').html(json['total']);

					$('html, body').animate({ scrollTop: 0 }, 'slow');
				}

 

и после всивляем

 

				if (json['warning']) {
										$('#content').parent().before('<div class="alert alert-success alert-dismissible"><i class="fa fa-check-circle"></i> ' + json['warning'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');


					$('#compare-total').html(json['total']);

					setTimeout(function () { $('.alert-success').fadeOut() }, 4000);
				}

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • 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.