[Помогите] с модулем "Выбор количества товара на любой странице PRO v1.0"

Тема в разделе "OpenCart", создана пользователем etens1212, 14 апр 2016.

  1. etens1212

    etens1212

    Регистрация:
    1 май 2013
    Сообщения:
    339
    Симпатии:
    19
    привет, поставил данный модуль
    все работает хорошо, кроме одного ...
    когда меняю количество, цена обновляется, но не учитывает скидку
    напиклад товар стоит 25
    при 10 шт. 23
    в корзине пишет, общая сумма 250
    а в категориях на товаре нет (
    как мне умножить на скидку вывод цены?

    [​IMG]

    вот xml

    Код:
    <?xml version="1.0" encoding="UTF-8"?>
    <modification>
    <id>Quantity +/- on any page with min/max control</id>
    <version>Pro v1.0</version>
    <vqmver required="true">2.4.0</vqmver>
    <author>[email protected]</author>
    
    <file name="catalog/controller/product/*.php">
        <operation error="skip">
        <search position="after"><![CDATA[ $this->data['products'][] = array( ]]></search>
        <add><![CDATA[
        'quantity' => $result['quantity'],
        'minimum'      => $result['minimum'],
        'price_value'       => $result['price'],
        'special_value'     => $result['special'],  
        ]]></add>
        </operation>
    </file>  
    
    <file name="catalog/controller/module/*.php">
        <operation error="skip">
        <search position="after"><![CDATA[ 'product_id' => $result['product_id'], ]]></search>
        <add><![CDATA[
        'quantity' => $result['quantity'],
        'minimum'      => $result['minimum'],
        'price_value'       => $result['price'],
        'special_value'     => $result['special'],  
        ]]></add>
        </operation>
    </file>
    
    <file name="catalog/controller/module/*.php">
        <operation error="skip">
        <search position="after"><![CDATA[ 'product_id' => $product_info['product_id'], ]]></search>
        <add><![CDATA[
        'quantity' => $product_info['quantity'],
        'minimum'      => $product_info['minimum'],  
        'price_value'       => $product_info['price'],
        'special_value'     => $product_info['special'],
        ]]></add>
        </operation>
    </file>  
      
    <file name="catalog/controller/product/product.php">
        <operation error="skip">
        <search position="after"><![CDATA[ $this->data['points'] = $product_info['points']; ]]></search>
        <add><![CDATA[
        $this->data['quantity'] = $product_info['quantity'];
        $this->data['price_value'] = $product_info['price'];
        $this->data['special_value'] = $product_info['special'];
        ]]></add>
        </operation>
    </file>  
    
    <file name="catalog/controller/common/footer.php">
    <operation error="skip">
        <search position="before"><![CDATA[ $this->load->model('catalog/information'); ]]></search>
        <add>
        <![CDATA[
        $var_currency = array();
        $var_currency['value'] = $this->currency->getValue();
        $var_currency['symbol_left'] = $this->currency->getSymbolLeft();
        $var_currency['symbol_right'] = $this->currency->getSymbolRight();
        $var_currency['decimals'] = $this->currency->getDecimalPlace();
        $var_currency['decimal_point'] = $this->language->get('decimal_point');
        $var_currency['thousand_point'] = $this->language->get('thousand_point');
        $this->data['currency'] = $var_currency;
      
        $this->data['config_stock'] = $this->config->get('config_stock_checkout');
        ]]>
        </add>
        </operation>
    </file>  
      
    <file name="catalog/view/theme/*/template/product/*.tpl">
        <operation error="skip">
        <search position="replace"><![CDATA[ <input type="button" value="<?php echo $button_cart; ?>" onclick ]]></search>
        <add><![CDATA[
        <div class="quantity_div <?php echo $product['product_id']; ?>">
        <span class="minus">-</span>
        <input type="text" name="quantity" class="quantity_input" size="2" value="<?php echo $product['minimum']; ?>" data-id="<?php echo $product['product_id']; ?>" data-maximum="<?php echo $product['quantity']; ?>" />    
        <span class="plus">+</span>
        <div class="stock_warning"></div>
        </div>
      
        <div class="pricer-ctg"><?php echo $text_pricer; ?> </div>
      
      
        <input type="button" value="<?php echo $button_cart; ?>" onclick
        ]]></add>
      
        </operation>
        <operation error="skip">
        <search position="replace"><![CDATA[ addToCart('<?php echo $product['product_id']; ?>'); ]]></search>
        <add><![CDATA[ addToCart('<?php echo $product['product_id']; ?>', $(this).parent().parent().find('.quantity_input').val()); ]]></add>
        </operation>
        <operation error="skip">
        <search position="before"><![CDATA[ $.totalStorage('display', 'list'); ]]></search>
        <add><![CDATA[ all_inputs(); ]]></add>
        </operation>
        <operation error="skip">
        <search position="before"><![CDATA[ $.totalStorage('display', 'grid'); ]]></search>
        <add><![CDATA[ all_inputs(); ]]></add>
        </operation>
        <operation error="skip">
        <search position="replace"><![CDATA[<?php echo $product['price']; ?>]]></search>
        <add><![CDATA[<span id="formated_price_<?php echo $product['product_id']; ?>" price="<?php echo $product['price_value']; ?>"><?php echo $product['price']; /**/ ?></span>]]></add>
        </operation>
        <operation error="skip">
        <search position="replace"><![CDATA[<?php echo $product['special']; ?>]]></search>
        <add><![CDATA[<span id="formated_special_<?php echo $product['product_id']; ?>" price="<?php echo $product['special_value']; ?>"><?php echo $product['special']; /**/ ?></span>]]></add>
        </operation>
    </file>
    
    <file name="catalog/view/theme/*/template/module/*.tpl">
        <operation error="skip">
        <search position="replace"><![CDATA[<?php echo $product['price']; ?>]]></search>
        <add><![CDATA[<span id="formated_price_<?php echo $product['product_id']; ?>" price="<?php echo $product['price_value']; ?>"><?php echo $product['price']; /**/ ?></span>]]></add>
        </operation>
        <operation error="skip">
        <search position="replace"><![CDATA[<?php echo $product['special']; ?>]]></search>
        <add><![CDATA[<span id="formated_special_<?php echo $product['product_id']; ?>" price="<?php echo $product['special_value']; ?>"><?php echo $product['special']; /**/ ?></span>]]></add>
        </operation>
        <operation error="skip">
        <search position="before"><![CDATA[ <div class="cart"> ]]></search>
        <add><![CDATA[
        <div class="quantity_div <?php echo $product['product_id']; ?>">
        <span class="minus">-</span>
        <input type="text" name="quantity" class="quantity_input" size="2" value="<?php echo $product['minimum']; ?>" data-id="<?php echo $product['product_id']; ?>" data-maximum="<?php echo $product['quantity']; ?>" />    
        <span class="plus">+</span>
        <div class="stock_warning"></div>
        </div>
        ]]></add>
        </operation>
        <operation error="skip">
        <search position="replace"><![CDATA[ addToCart('<?php echo $product['product_id']; ?>'); ]]></search>
        <add><![CDATA[ addToCart('<?php echo $product['product_id']; ?>', $(this).parent().parent().find('.quantity_input').val()); ]]></add>
        </operation>
    </file>
    
    <file name="catalog/view/theme/*/template/product/product.tpl">
        <operation error="skip">
        <search position="replace"><![CDATA[ <input type="text" name="quantity" size="2" value="<?php echo $minimum; ?>" /> ]]></search>
        <add><![CDATA[
        <div class="quantity_div <?php echo $product_id; ?>">
        <span class="minus">-</span>
        <input type="text" name="quantity" class="quantity_input" size="2" value="<?php echo $minimum; ?>" data-id="<?php echo $product_id; ?>" data-maximum="<?php echo $quantity; ?>" />    
        <span class="plus">+</span>
        <div class="stock_warning"></div>
        </div>
        ]]></add>
        </operation>
        <operation error="skip">                          
          <search position="replace"><![CDATA[<span class="price-old"><?php echo $price; ?></span>]]></search>
          <add><![CDATA[<span id="formated_price" class="price-old" price="<?php echo $price_value; ?>"><?php echo $price; ?></span>]]></add>
        </operation>      
        <operation error="skip">                          
          <search position="replace"><![CDATA[<?php echo $special; ?>]]></search>
          <add><![CDATA[<span id="formated_special" price="<?php echo $special_value; ?>"><?php echo $special; ?></span>]]></add>
        </operation>      
        <operation error="skip">
          <search position="replace"><![CDATA[<?php echo $price; ?>]]></search>
          <add><![CDATA[<span id="formated_price" price="<?php echo $price_value; ?>"><?php echo $price; ?></span>]]></add>
        </operation>
        <operation error="skip">
          <search position="replace"><![CDATA[<?php echo $points; ?>]]></search>
          <add><![CDATA[<span id="formated_points" points="<?php echo $points; ?>"><?php echo $points; ?></span>]]></add>
        </operation>
    </file>
    
    <file name="catalog/view/theme/*/template/common/footer.tpl">
        <operation error="skip">
        <search position="before"><![CDATA[ </body> ]]></search>
        <add><![CDATA[
        <script>
        $(document).ready(function() {  
            all_inputs();
            if ($('.quantity_cart').length != 0) {    $('.quantity_div').remove(); }  
        });
      
        function all_inputs() {
            $('input[name^=quantity]').each(function() {
                var product_id = $(this).attr('data-id');
                var minimum = Number($(this).val());
    <?php if($config_stock) { ?>
                var maximum = 9999;
    <?php } else { ?>
                var maximum = Number($(this).attr('data-maximum'));
    <?php } ?>
                quantity_control(product_id ,minimum, maximum);
                calculate_price(product_id, minimum);
              
                $(this).bind('input', function() {
                    var value2 = $(this).val();
                    if (~~value2 > maximum) {
                        $(this).val(maximum);
                        quantity_alert(product_id, maximum);
                    }
                    calculate_price(product_id, $(this).val())
                });
              
                if(maximum <= 0) {
                    $('.' + product_id + ' input').val('0');
                    $('.' + product_id).parent().find('.button').attr('disabled', 'disabled');
                }
            });
        }  
      
        function quantity_control(product_id ,minimum, maximum) {
            $('.' + product_id + ' input').next().click(function () {
                if ((Number($('.' + product_id + ' input').val()) + minimum) <= maximum) {
                    $('.' + product_id + ' input').val(Math.round((Number($('.' + product_id + ' input').val()) + minimum)*10)/10);
                    calculate_price(product_id, $(this).prev().val())
                } else {
                    quantity_alert(product_id, maximum);
                }
            });
      
            $('.' + product_id + ' input').prev().click(function () {
                if (Number($('.' + product_id + ' input').val()) > minimum) {
                    $('.' + product_id + ' input').val(Math.round((Number($('.' + product_id + ' input').val()) - minimum)*10)/10);
                    calculate_price(product_id, $(this).next().val())
                }
            });
        }
      
        function quantity_alert(product_id, maximum) {
            if(maximum == 0) {
                $('.stock_warning').text('На нашем складе данный товар закончился.');
            } else {
                $('.stock_warning').text('На нашем складе данного товара осталось всего ' + maximum + ' шт!');
            }
            $('.' + product_id + ' .stock_warning').fadeIn().delay('2000').fadeOut();
        }
      
        function price_format(n){    
            c = <?php echo (empty($currency['decimals']) ? "0" : $currency['decimals'] ); ?>;
            d = '<?php echo $currency['decimal_point']; ?>';
            t = '<?php echo $currency['thousand_point']; ?>';
            s_left = '<?php echo $currency['symbol_left']; ?>';
            s_right = '<?php echo $currency['symbol_right']; ?>';
            n = n * <?php echo $currency['value']; ?>;
            i = parseInt(n = Math.abs(n).toFixed(c)) + '';
            j = ((j = i.length) > 3) ? j % 3 : 0;
            return s_left + (j ? i.substr(0, j) + t : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : '') + s_right;
        }
    
        function calculate_price(product_id, minimum) {
        if ($('.product-info').length == 0) {
            var main_price = Number($('#formated_price_'+product_id).attr('price'));
            var special = Number($('#formated_special_'+product_id).attr('price'));
            var new_price = main_price * minimum;
            var new_special = special * minimum;
            $('#formated_price_'+product_id).html(price_format(new_price));
            $('#formated_special_'+product_id).html(price_format(new_special));
        } else {
      
            var options_price = 0;
            var points = Number($('#formated_points').attr('points'));
          
            $('.options input:checked, .options option:selected').each(function() {
            if ($(this).attr('price_prefix') == '+')
                options_price += Number($(this).attr('price'));
            if ($(this).attr('price_prefix') == '-')
                options_price -= Number($(this).attr('price'));
                points += Number($(this).attr('points'));
            });
      
            var main_price = Number($('#formated_price').attr('price'));
            var special = Number($('#formated_special').attr('price'));
            var new_price = (main_price + options_price) * minimum;
            var new_special = (special + options_price) * minimum;
            var new_points = points * minimum;
            $('#formated_price').html(price_format(new_price));
            $('#formated_special').html(price_format(new_special));
            $('#formated_points').html(new_points);
        }
        }
        </script>
        <style>
            .quantity_div {display: block; position: relative; padding: 0; text-align: center; line-height: normal !important;}
            .product-info .quantity_div {display:inline-block; vertical-align:middle;}
            .quantity_div .quantity_input {text-align: center; width: 100px; line-height: 10px; background: #fff !important; color: #555 !important;}
            .quantity_div .plus, .minus {display: inline-block; color: #38221B; line-height: 38px; width: 35px; cursor: pointer; background: rgba(243, 243, 243, 0.97);}
        </style>
        ]]></add>
        </operation>
    </file>
    
    <file name="catalog/view/theme/*/template/product/product.tpl">
        <operation error="skip">
        <search position="replace"><![CDATA[ var new_price = main_price + options_price; ]]></search>
        <add><![CDATA[ var new_price = (main_price + options_price) * Number($('input[name^=quantity]').val()); ]]></add>
        </operation>
    </file>
    <file name="catalog/view/theme/*/template/product/product.tpl">
        <operation error="skip">
        <search position="replace"><![CDATA[ var new_special = special + options_price; ]]></search>
        <add><![CDATA[ var new_special = (special + options_price) * Number($('input[name^=quantity]').val()); ]]></add>
        </operation>
    </file>
    </modification>