Задача: вывод розничной и оптовой цены за еденицу товара и в количестве.
Столкнулся я с задачей в опенкарте что стандартными методами не выдает он цену за 1 товара он начинает ее пересчитывать и выдает полный результат, козалось бы что может бы проще, но что-то пошло не так.
вот код <div class="sun-roz"> <h5>розничная цена</h5> <p> <?php if($special) { ?> <strong id="special"><?php print $special; ?></strong> <span id="price"><?php print $price; ?></span> <sub class="single-price">цена за 1 еденицу - <b><?php print $special; ?></b></sub> <?php } else { ?> <strong id="price"><?php print $price; ?></strong> <sub class="single-price">цена за 1 еденицу - <b><?php print $price; ?></b></sub> <?php } ?> </p> </div> <?php if($whole_sale_price) { ?> <div class="sun-opt"> <h5>оптовая цена</h5> <p id="whole_sale"><?php print $whole_sale_price; ?></p> <sub class="single-price">цена за 1 еденицу - <b><?php print $whole_sale_price; ?></b></sub> <?php if(!empty($whole_sale_quantity)) { ?> <span>* при заказе от <?php print $whole_sale_quantity; ?> штук</span> <?php }?> <span>** сумма общих покупок должна превышать <?php print $config_min_ws_value; ?></span> </div> <?php } ?> <div class="quantity"> <h5>количество</h5> <form action=""> <input min="1" value="1" type="number" name="quantity"> <input type="hidden" name="product_id" value="<?php echo $product_id; ?>" /> <input type="hidden" name="total_price" value="" /> <input type="hidden" name="total_special" value="" /> <input type="hidden" name="total_whole_sale" value="" /> <input type="hidden" name="no_image" value="<?php echo $popup; ?>" /> и к нему написан js такой var priceHandler = { price: '', special: '', whole_sale: '', quantity: '', init: function(){ var price = $('#price').text(); price = price.split(' '); price = price[0]; this.price = Math.round(price * 100) / 100; var special = $('#special').text(); special = special.split(' '); special = special[0]; this.special = Math.round(special * 100) / 100; var whole_sale = $('#whole_sale').text(); whole_sale = whole_sale.split(' '); whole_sale = whole_sale[0]; this.whole_sale = Math.round(whole_sale * 100) / 100; this.quantity = $('#product input[name=quantity]').val(); this.update(); $('input[name=total_price]').val(this.price); $('input[name=total_special]').val(this.special); $('input[name=total_whole_sale]').val(this.whole_sale); }, update: function(){ this.quantity = $('#product input[name=quantity]').val(); var product_price = priceHandler.price * priceHandler.quantity; var product_special = priceHandler.special * priceHandler.quantity; var product_whole_sale = priceHandler.whole_sale * priceHandler.quantity; $('#product select[name^=\'option\'] option:selected').each(function(){ var option_price_prefix = $(this).data('price-prefix'); var option_price = $(this).data('price'); console.log(String(option_price)); option_price = String(option_price).split(' '); option_price = option_price[0]; if(option_price && option_price_prefix) { if(option_price_prefix == '+') { product_price += option_price * priceHandler.quantity; product_special += option_price * priceHandler.quantity; product_whole_sale += option_price * priceHandler.quantity; } else if(option_price_prefix == '-') { product_price -= option_price * priceHandler.quantity; product_special -= option_price * priceHandler.quantity; product_whole_sale -= option_price * priceHandler.quantity; } } }); product_price = Math.round(product_price * 100) / 100; product_special = Math.round(product_special * 100) / 100; product_whole_sale = Math.round(product_whole_sale * 100) / 100; var price_text = $('#price').text(); var price_data = price_text.split(' '); price_data[0] = product_price; price_text = price_data.join(' '); $('#price').text(price_text); /*$('.sun-roz .single-price b').text(price_text);*/ $('input[name=total_price]').val(product_price); var special_text = $('#special').text(); var special_data = special_text.split(' '); special_data[0] = product_special; special_text = special_data.join(' '); $('#special').text(special_text); $('input[name=total_special]').val(product_special); var whole_sale_text = $('#whole_sale').text(); var whole_sale_data = whole_sale_text.split(' '); whole_sale_data[0] = product_whole_sale; whole_sale_text = whole_sale_data.join(' '); $('#whole_sale').text(whole_sale_text); /* $('.sun-opt .single-price b').text(whole_sale_text); */ $('input[name=total_whole_sale]').val(product_whole_sale); } }; и скрины кину чтоб понятней было на примере. https://prnt.sc/iig3nb https://prnt.sc/iig3wb |
Я думаю все знают такую тему иногда напишеш запрос и хоп и понял чего тупанул. ну вот и в этот раз так же , написал продебажил еще раз и сделал =) добавив
var price_plus_spesial = (product_price_singl + product_special_singl); var whole_sale_plus_spesial = (product_whole_sale_singl + product_special_singl); $('.sun-roz .single-price b').text(price_plus_spesial); $('.sun-opt .single-price b').text(whole_sale_plus_spesial); Извените за беспокойство |
Часовой пояс GMT +3, время: 11:32. |