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

Обновление этоны при выпотому чторе опции, не рилииет с ЧПУ


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;
	}
}

?>

 

Edited by axaxaxa
Link to comment
Share on other sites


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

<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

Link to comment
Share on other sites


2 минуты назад, spectre сказал:

в исключения сеопро видимо надо добавить

мог бы подсказать как сгделать это? как ему запретить?

Link to comment
Share on other sites


Только что, 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
Link to comment
Share on other sites

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

catalog/controller/startup/seo_pro.php

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

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

image.png.02184fc13705286af0463cd778e89f03.png

Edited by axaxaxa
Link to comment
Share on other sites


В 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;
        }

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

Link to comment
Share on other sites


  • 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;
        }

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

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.