Доброго времени суток. Решил реализовать опции в категории opencart 2,0,3,1. Пробовал готовый модуль - но с ним есть не большие траблы. Собственно что я предпринял: В контроллере category.php добавил сл строки : перед $data['products'][] = array(
$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');
$data['currency'] = $var_currency;
$options = $this->model_catalog_product->getProductOptions($result['product_id']);
в самом массиве добавил сл:
'options' => $options,
'price_no_format' => $result['price'],
'special_no_format' => $result['special'],
Далее во вьюхе вывел сами опции
<div class="options">
<?php if ($product['options']) { ?>
<div id="option_<?php echo $product['product_id']; ?>">
<?php foreach ($product['options'] as $option) { ?>
<?php if ($option['type'] == 'select') { ?>
<div id="option-<?php echo $option['product_option_id']; ?>" class="option">
<?php if ($option['required']) { ?>*<?php } ?> <label><?php echo $option['name']; ?>:</label><br />
<select name="option[<?php echo $option['product_option_id']; ?>]" onchange="recalc(<?php echo $product['product_id']; ?>);" id="<?php echo $product['product_id']; ?>">
<option value="" price_prefix="" price=""><?php echo $text_select; ?></option>
<?php foreach ($option['product_option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['product_option_value_id']; ?>" price_prefix="<?php echo $option_value['price_prefix']; ?>" price="<?php echo $option_value['price']; ?>"><?php echo $option_value['name']; ?> <?php if ($option_value['price']) { ?>(<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)<?php } ?></option>
<?php } ?>
</select>
</div>
<?php } ?>
<?php if ($option['type'] == 'radio') { ?>
<div id="option-<?php echo $option['product_option_id']; ?>" class="option">
<?php if ($option['required']) { ?>*<?php } ?> <label><?php echo $option['name']; ?>:</label><br />
<?php foreach ($option['product_option_value'] as $option_value) { ?>
<input type="radio" price_prefix="<?php echo $option_value['price_prefix']; ?>" price="<?php echo $option_value['price']; ?>" onchange="recalc(<?php echo $product['product_id']; ?>);" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" id="option-value-<?php echo $option_value['product_option_value_id']; ?>" />
<label for="option-value-<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?> <?php if ($option_value['price']) { ?>(<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)<?php } ?></label><br />
<?php } ?>
</div>
<?php } ?>
<?php if ($option['type'] == 'checkbox') { ?>
<div id="option-<?php echo $option['product_option_id']; ?>" class="option">
<?php if ($option['required']) { ?>*<?php } ?> <label><?php echo $option['name']; ?>:</label><br />
<?php foreach ($option['product_option_value'] as $option_value) { ?>
<input type="checkbox" price_prefix="<?php echo $option_value['price_prefix']; ?>" price="<?php echo $option_value['price']; ?>" onchange="recalc(<?php echo $product['product_id']; ?>);" name="option[<?php echo $option['product_option_id']; ?>][]" value="<?php echo $option_value['product_option_value_id']; ?>" id="option-value-<?php echo $option_value['product_option_value_id']; ?>" />
<label for="option-value-<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?> <?php if ($option_value['price']) { ?>(<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)<?php } ?></label><br />
<?php } ?>
</div>
<?php } ?>
<?php } ?>
</div>
<?php } ?>
</div>
Для того, что бы менялось значении цены взял код с модуля обновления цены для карточки товара
<script type="text/javascript"><!--
function price_format(n)
{
c = 2;
d = '.'; // decimal separator
t = ','; // thousands separator
s_left = '';
s_right = ' грн.';
n = n * 1.00000000;
//sign = (n < 0) ? '-' : '';
//extracting the absolute value of the integer part of the number and converting to string
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_tax(price)
{
return price;
}
function process_discounts(price, quantity)
{
return price;
}
animate_delay = 20;
main_price_final = calculate_tax(Number($('.price').attr('price')));
main_price_start = calculate_tax(Number($('.price').attr('price')));
main_step = 0;
main_timeout_id = 0;
function animateMainPrice_callback() {
main_price_start += main_step;
if ((main_step > 0) && (main_price_start > main_price_final)){
main_price_start = main_price_final;
} else if ((main_step < 0) && (main_price_start < main_price_final)) {
main_price_start = main_price_final;
} else if (main_step == 0) {
main_price_start = main_price_final;
}
$('.price').html( price_format(main_price_start) );
if (main_price_start != main_price_final) {
main_timeout_id = setTimeout(animateMainPrice_callback, animate_delay);
}
}
function animateMainPrice(price) {
main_price_start = main_price_final;
main_price_final = price;
main_step = (main_price_final - main_price_start) / 10;
clearTimeout(main_timeout_id);
main_timeout_id = setTimeout(animateMainPrice_callback, animate_delay);
}
function recalculateprice()
{
var main_price = Number($('.price').attr('price'));
var input_quantity = Number($('input[name="quantity"]').val());
var special = Number($('#formated_special').attr('price'));
var tax = 0;
if (isNaN(input_quantity)) input_quantity = 0;
// Process Discounts.
main_price = process_discounts(main_price, input_quantity);
tax = process_discounts(tax, input_quantity);
var option_price = 0;
$('input:checked,option:selected').each(function() {
if ($(this).attr('price_prefix') == '=') {
option_price += Number($(this).attr('price'));
main_price = 0;
special = 0;
}
});
$('input:checked,option:selected').each(function() {
if ($(this).attr('price_prefix') == '+') {
option_price += Number($(this).attr('price'));
}
if ($(this).attr('price_prefix') == '-') {
option_price -= Number($(this).attr('price'));
}
if ($(this).attr('price_prefix') == 'u') {
pcnt = 1.0 + (Number($(this).attr('price')) / 100.0);
option_price *= pcnt;
main_price *= pcnt;
special *= pcnt;
}
if ($(this).attr('price_prefix') == '*') {
option_price *= Number($(this).attr('price'));
main_price *= Number($(this).attr('price'));
special *= Number($(this).attr('price'));
}
});
special += option_price;
main_price += option_price;
tax = main_price;
// Process TAX.
main_price = calculate_tax(main_price);
special = calculate_tax(special);
// Раскомментировать, если нужен вывод цены с умножением на количество
//main_price *= input_quantity;
//special *= input_quantity;
//tax *= input_quantity;
// Display Main Price
//$('.price').html( price_format(main_price) );
animateMainPrice(main_price);
}
$(document).ready(function() {
$('input[type="checkbox"]').bind('change', function() { recalculateprice(); });
$('input[type="radio"]').bind('change', function() { recalculateprice(); });
$('select').bind('change', function() { recalculateprice(); });
$quantity = $('input[name="quantity"]');
$quantity.data('val', $quantity.val());
(function() {
if ($quantity.val() != $quantity.data('val')){
$quantity.data('val',$quantity.val());
recalculateprice();
}
setTimeout(arguments.callee, 250);
})();
recalculateprice();
});
//--></script>
Цена обновляется при выборе опции. Но вот в чем трабла - какую бы опцию не выбрали товар в корзину уходит со старой ценой (та цена, которую опенкарт выводит по умолчанию). Прошу помощи - сломал голову что исправить что бы в корзину товар уходил с адекватной ценой