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

Обновление цены при выборе опции, не работает с ЧПУ


Recommended Posts

 

Здравствуйте,

столкнулся с такой проблемой, установил модуль обновления цены при выборе опции все ок работает! но когда товару даешь ЧПУ ссылку то не работает!

файл модификатора 

Спойлер

<file path="catalog/model/catalog/product.php">
        <operation>
            <search>
               <![CDATA['weight'                  => $product_option_value['weight'],]]>
            </search>
            <add position="before">
            <![CDATA[
            'points'        => $product_option_value['points'],
            'points_prefix' => $product_option_value['points_prefix'],
            ]]>
            </add>
        </operation>
    </file>
    <file path="catalog/view/theme/*/template/product/product.twig">
        <operation>
            <search>
               <![CDATA[{{ footer }}]]>
            </search>
            <add position="before">
           <![CDATA[
            <script defer src="index.php?route=product/live_options/js&product_id={{ product_id }}"></script>
            ]]>
            </add>
        </operation>
        <operation>
            <search>
               <![CDATA[{{ price }}]]>
            </search>
            <add position="replace">
            <![CDATA[
            <span class="{{ live_options['module_live_options_price_container'] }}">{{ price }}</span>
            ]]>
            </add>
        </operation>
        <operation>
            <search>
               <![CDATA[{{ special }}]]>
            </search>
            <add position="replace">
            <![CDATA[
            <span class="{{ live_options['module_live_options_special_container'] }}">{{ special }}</span>
            ]]>
            </add>
        </operation>
        <operation>
            <search>
               <![CDATA[{{ points }}]]>
            </search>
            <add position="replace">
            <![CDATA[
            <span class="{{ live_options['module_live_options_points_container'] }}">{{ points }}</span>
            ]]>
            </add>
        </operation>
        <operation>
            <search>
               <![CDATA[{{ reward }}]]>
            </search>
            <add position="replace">
            <![CDATA[
            <span class="{{ live_options['module_live_options_reward_container'] }}">{{ reward }}</span>
            ]]>
            </add>
        </operation>
        <operation>
            <search>
               <![CDATA[{{ tax }}]]>
            </search>
            <add position="replace">
            <![CDATA[
            <span class="{{ live_options['module_live_options_tax_container'] }}">{{ tax }}</span>
            ]]>
            </add>
        </operation>
        
    </file>
    <file path="catalog/controller/product/product.php">
        <operation info="Define CSS calss name">
            <search><![CDATA[$data['products'] = array();]]></search>
            <add position="before"><![CDATA[
            // Ajax Live Options
            if($this->config->get('module_live_options_status')){
                $data['live_options'] = array(
                    'module_live_options_container' => substr($this->config->get('module_live_options_container'), 1),
                    'module_live_options_special_container' => substr($this->config->get('module_live_options_special_container'), 1),
                    'module_live_options_price_container' => substr($this->config->get('module_live_options_price_container'), 1),
                    'module_live_options_tax_container' => substr($this->config->get('module_live_options_tax_container'), 1),
                    'module_live_options_points_container' => substr($this->config->get('module_live_options_points_container'), 1),
                    'module_live_options_reward_container' => substr($this->config->get('module_live_options_reward_container'), 1),
                );
            }
            ]]></add>
        </operation>
        <operation info="Show Full Option Price">
            <search><![CDATA[foreach ($option['product_option_value'] as $option_value) {]]></search>
            <add position="after"><![CDATA[
            // show total amount
            if($this->config->get('module_live_options_status') && !$this->config->get('module_live_options_show_options_type') && $option_value['price'] > 0){
                if ($option_value['price_prefix'] == '-' && $option_value['price']) {
                    $option_value['price'] = (($product_info['special'] ? ($product_info['special'] - $option_value['price']) : ($product_info['price']) - $option_value['price']));
                } elseif ($option_value['price_prefix'] == '+' && $option_value['price']) {
                    $option_value['price'] = (($product_info['special'] ? ($product_info['special'] + $option_value['price']) : ($product_info['price']) + $option_value['price']));
                }
                $option_value['price_prefix'] = '';
            }
            ]]></add>
        </operation>
        <operation info="Show Full Option Price">
            <search><![CDATA[
                $price = $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax') ? 'P' : false)
                ]]></search>
            <add position="before"><![CDATA[
                $currency_code = $this->session->data['currency'];
                
                // show total amount
                if($this->config->get('module_live_options_status') && !$this->config->get('module_live_options_show_options_type')){
                    $price = $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $currency_code);
                }
                else
            ]]></add>
        </operation>
    </file>

 

Файл product/live_options.php

Спойлер

<?php
class ControllerProductLiveOptions extends Controller {
	private $error = array(); 
	private $data  = array(); 

	public function __construct($params) {
    	parent::__construct($params);

		$this->use_cache               = $this->config->get('module_live_options_use_cache') ? TRUE : FALSE;
		$this->calculate_quantity      = $this->config->get('module_live_options_calculate_quantity') ? TRUE : FALSE;
		$this->show_type               = $this->config->get('module_live_options_show_type') ? TRUE : FALSE;
		$this->show_option_type        = $this->config->get('module_live_options_show_options_type') ? TRUE : FALSE;

		$this->options_container       = $this->config->get('module_live_options_container');
		$this->special_price_container = $this->config->get('module_live_options_special_container');
		$this->price_container         = $this->config->get('module_live_options_price_container');
		$this->tax_price_container     = $this->config->get('module_live_options_tax_container');
		$this->points_container        = $this->config->get('module_live_options_points_container');
		$this->reward_container        = $this->config->get('module_live_options_reward_container');
	}
	public function index() { 
		$json           = array();
		$update_cache   = false;
		$options_makeup = $options_makeup_notax = $options_points = 0;
		
		$currency_cache = $currency_code = $this->session->data['currency'];
		

		if (isset($this->request->get['product_id'])) {
			$product_id = (int)$this->request->get['product_id'];
		} else {
			$product_id = 0;
		}

		if ($this->calculate_quantity && isset($this->request->post['quantity'])) {
			$quantity = (int)$this->request->post['quantity'];
		} else {
			$quantity = 1;
		}

		$this->load->model('catalog/product');

		// Cache name
		if (isset($this->request->post['option']) && is_array($this->request->post['option'])) {
			$options_hash = serialize($this->request->post['option']);
		} else {
			$options_hash = '';
		}
		$cache_key = 'live_options_'. md5($product_id . $quantity. $options_hash . $currency_cache . $this->session->data['language'] . $this->show_type . $this->show_option_type . $this->calculate_quantity);
		if (!$this->use_cache || (!$json = $this->cache->get($cache_key))) {
			$product_info = $this->model_catalog_product->getProduct($product_id);
			// Prepare data
			if ($product_info) {
				$update_cache = true;

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

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

				// Discount
				$discount_price = $this->get_discount_price($product_id, $quantity);
				if($discount_price && !$this->data['special']){
					if ((float)$discount_price) {
						$this->data['price'] = $this->tax->calculate($discount_price, $product_info['tax_class_id'], $this->config->get('config_tax'));
					} else {
						$this->data['price'] = false;
					}
				}

				// If some options are selected
				if (isset($this->request->post['option']) && $this->request->post['option']) {
					$option_tax = $this->config->get('config_tax') ? 'P' : false;
					foreach ($this->model_catalog_product->getProductOptions($product_id) as $option) { 
						foreach ($option['product_option_value'] as $option_value) {
							if (isset($this->request->post['option'][$option['product_option_id']])) {
								if(is_array($this->request->post['option'][$option['product_option_id']])){
									foreach ($this->request->post['option'][$option['product_option_id']] as $product_option_id) {
										if($product_option_id == $option_value['product_option_value_id']){
											$options_makeup += $this->get_options_makeup($option_value, $product_info['tax_class_id'], $option_tax);
											$options_makeup_notax += $this->get_options_makeup($option_value, 0, $option_tax);

											// add points
											if($option_value['points']){
												$options_points += $this->get_options_makeup($option_value, $product_info['tax_class_id'], false, 'points');
											}
										}
									}
								}
								elseif($this->request->post['option'][$option['product_option_id']] == $option_value['product_option_value_id']){
									$options_makeup += $this->get_options_makeup($option_value, $product_info['tax_class_id'], $option_tax);
									$options_makeup_notax += $this->get_options_makeup($option_value, 0, $option_tax);

									// add points
									if($option_value['points']){
										$options_points += $this->get_options_makeup($option_value, $product_info['tax_class_id'], false, 'points');
									}
								}
							}
						}
					}
				}

				// Show extra price
				if($this->show_type){
					$prefix_makeup = $options_makeup > 0 ? ' + ' : '';
					$options_makeup = ($options_makeup == 0) ? '' : ' ('.$prefix_makeup.$this->currency->format($options_makeup * $quantity, $currency_code).')';
					$options_makeup_notax = ($options_makeup_notax == 0) ? '' : ' ('.$prefix_makeup.$this->currency->format($options_makeup_notax * $quantity, $currency_code).')';

					if ($this->data['price']) {
						$json['new_price']['price'] = $this->currency->format($this->data['price'] * $quantity, $currency_code) . $options_makeup;
					} else {
						$json['new_price']['price'] = false;
					}
					if ($this->data['special']) {
						$json['new_price']['special'] = $this->currency->format($this->data['special'] * $quantity, $currency_code) . $options_makeup;
					} else {
						$json['new_price']['special'] = false;
					}
					if ($this->config->get('config_tax')) {
						$json['new_price']['tax'] = $this->currency->format(((float)$product_info['special'] ? $product_info['special'] : $product_info['price']) * $quantity, $currency_code ) . $options_makeup_notax;
					} else {
						$json['new_price']['tax'] = false;
					}
				}
				// Show total price
				else{
					if ($this->data['price']) {
						$json['new_price']['price'] = $this->currency->format(($this->data['price'] + $options_makeup) * $quantity, $currency_code);
					} else {
						$json['new_price']['price'] = false;
					}

					if ($this->data['special']) {
						$json['new_price']['special'] = $this->currency->format(($this->data['special'] + $options_makeup) * $quantity, $currency_code);
					} else {
						$json['new_price']['special'] = false;
					}

					if ($this->config->get('config_tax')) {
						$json['new_price']['tax'] = $this->currency->format(((float)$product_info['special'] ? ($product_info['special'] + $options_makeup) : ($product_info['price'] + $options_makeup_notax)) * $quantity, $currency_code );
					} else {
						$json['new_price']['tax'] = false;
					}
				}
				$json['new_price']['reward'] = ($product_info['reward'] > 0) ? (abs($product_info['reward']) * $quantity) : 0;
				$json['new_price']['points'] = ($product_info['points'] + $options_points > 0) ? abs($product_info['points'] + $options_points) * $quantity : 0;

				$json['success'] = true;
			} else {
				$json['success'] = false;
			}
		}

		if ($update_cache && $this->use_cache) {
			$this->cache->set($cache_key, $json);
		}

		$this->response->addHeader('Content-Type: application/json');
		$this->response->setOutput(json_encode($json));
  	}
	private function get_options_makeup($option_value, $tax_class_id, $tax_type, $param = 'price'){
		$options_makeup = 0;
		if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
			if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value[$param]) {
				$price = $this->tax->calculate($option_value[$param], $tax_class_id, $tax_type);
			} else {
				$price = false;
			}
			if ($price) {
				if ($option_value[$param.'_prefix'] === '+') {
					$options_makeup = $options_makeup + (float)$price;
				} else {
					$options_makeup = $options_makeup - (float)$price;
				}
			}
			unset($price);
		}
		return $options_makeup;
	}

	private function get_discount_price($product_id, $discount_quantity){
		$price = false;
		$product_discount_query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND quantity <= '" . (int)$discount_quantity . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity DESC, priority ASC, price ASC LIMIT 1");

		if ($product_discount_query->num_rows) {
			$price = (float)$product_discount_query->row['price'];
		}
		return $price;
	}
	function js() {
		header("Content-Type: text/javascript; charset=utf-8");
		$product_id = isset($this->request->get['product_id']) ? (int)$this->request->get['product_id'] : 0;
		if ($product_id == 0 || !$this->config->get('module_live_options_status')) {
			exit;
		}

		$js = <<<HTML
			var price_with_options_ajax_call = function() {
				alert('BEBE!');
				$.ajax({
					type: 'POST',
					url: 'index.php?route=product/live_options/index&product_id=$product_id',
					data: $('{$this->options_container} input[type=\'text\'], {$this->options_container} input[type=\'hidden\'], {$this->options_container} input[type=\'radio\']:checked, {$this->options_container} input[type=\'checkbox\']:checked, {$this->options_container} select, {$this->options_container} textarea'),
					dataType: 'json',
					beforeSend: function() {
						// you can add smth useful here
					},
					complete: function() {
						// you can add smth useful here
					},
					success: function(json) {
						alert('KUKU!')
						if (json.success) {
							if ($('{$this->options_container} {$this->tax_price_container}').length > 0 && json.new_price.tax) {
								animation_on_change_price_with_options('{$this->options_container} {$this->tax_price_container}', json.new_price.tax);
							}
							if ($('{$this->options_container} {$this->special_price_container}').length > 0 && json.new_price.special) {
								animation_on_change_price_with_options('{$this->options_container} {$this->special_price_container}', json.new_price.special);
							}
							if ($('{$this->options_container} {$this->price_container}').length > 0 && json.new_price.price) {
								animation_on_change_price_with_options('{$this->options_container} {$this->price_container}', json.new_price.price);
							}
							// points
							if ($('{$this->options_container} {$this->points_container}').length > 0 && json.new_price.points) {
								animation_on_change_price_with_options('{$this->options_container} {$this->points_container}', json.new_price.points);
							}
							// reward
							if ($('{$this->options_container} {$this->reward_container}').length > 0 && json.new_price.reward) {
								animation_on_change_price_with_options('{$this->options_container} {$this->reward_container}', json.new_price.reward);
							}
						}
					},
					error: function(error) {
						console.log('error: '+error);
					}
				});
			}
			
			var animation_on_change_price_with_options = function(selector_class_or_id, new_html_content) {
				$(selector_class_or_id).fadeOut(150, function() {
					$(this).html(new_html_content).fadeIn(50);
				});
			}

			if ( jQuery.isFunction(jQuery.fn.on) ) 
			{
				$(document).on('change', '{$this->options_container} input[type=\'text\'], {$this->options_container} input[type=\'hidden\'], {$this->options_container} input[type=\'radio\']:checked, {$this->options_container} input[type=\'checkbox\'], {$this->options_container} select, {$this->options_container} textarea, {$this->options_container} input[name=\'quantity\']', function () {
					
					price_with_options_ajax_call();
				});
			} 
			else 
			{
				$('{$this->options_container} input[type=\'text\'], {$this->options_container} input[type=\'hidden\'], {$this->options_container} input[type=\'radio\']:checked, {$this->options_container} input[type=\'checkbox\'], {$this->options_container} select, {$this->options_container} textarea, {$this->options_container} input[name=\'quantity\']').live('change', function() {
					price_with_options_ajax_call();
				});
			}
			// Support spinner_quantity
			if( $('.number-spinner button').length ){
				$(document).on('click', '.number-spinner button', function () {
					setTimeout(function() {
						price_with_options_ajax_call();
					}, 100);
				});
			}
			// Support Pav theme
			if( $('.quantity-adder .add-action').length ){
				$(".quantity-adder .add-action").bind( "mouseup touchend", function(e){
					setTimeout(function() {
						price_with_options_ajax_call();
					}, 100);
				});
			}
			// Support vitalia
			if( $('#q_up').length || $('#q_down').length ){
				$('#q_up,#q_down').click(function(){
					setTimeout(function() {
						price_with_options_ajax_call();
					}, 100);
				});
			}
HTML;

		echo $js;
		exit;
	}
}

?>

 

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


Если ссылку которая формируется перед футером открыть на странице без ЧПУ 

<script defer src="index.php?route=product/live_options/js&product_id={{ product_id }}"></script>

то открывается как раз тот скрипт который обрабатывает...

Если открыть эту ссылку на странице у которой есть ЧПУ тогда откроется эта же страница, я сделал вывод что SEO PRO редиректит и эту страницу, но вот сижу уже 2 дня не могу починить....

С выключенным SEO PRO все работает, но тонда нету редиректов со страниц типа index.php?route=product/product&product_id=14621

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


Только что, axaxaxa сказал:

но вот сижу уже 2 дня не могу починить....

 

catalog/controller/startup/seo_pro.php

 

в private function validate() {

 

добавить что-то типа

 

        if (isset($this->request->get['route']) && $this->request->get['route'] == 'product/live_options/js') {
            return;
        }

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

15 часов назад, spectre сказал:

catalog/controller/startup/seo_pro.php

По этому путю нету такого файла есть seo_url.php , оно ???

В файле seo_url.php только типа такого есть....

image.png.02184fc13705286af0463cd778e89f03.png

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


В 29.08.2019 в 18:28, spectre сказал:

 

catalog/controller/startup/seo_pro.php

 

в private function validate() {

 

добавить что-то типа

 

        if (isset($this->request->get['route']) && $this->request->get['route'] == 'product/live_options/js') {
            return;
        }

можешь уточнить пожалуйста!...

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


  • 2 years later...
В 29.08.2019 в 18:28, spectre сказал:

 

catalog/controller/startup/seo_pro.php

 

в private function validate() {

 

добавить что-то типа

 

        if (isset($this->request->get['route']) && $this->request->get['route'] == 'product/live_options/js') {
            return;
        }

После выполнения этих действий все заработало, как нужно, сталкивался с этой проблемой выше. Благодарю вас за то, что спасли рабочий проект, который встал в такой замкнутый круг.

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


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

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

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

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

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

Вхід

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

Вхід зараз

×
×
  • Створити...

Important Information

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