На моей странице продукта есть несколько настраиваемых опций (выпадающих списков), которые добавляются в sku для тележки. Тем не менее, я хотел бы отобразить обновленную страницу на странице продукта при выборе параметров.Страница продукта Magento Simple - Dynamicically Update SKU с настраиваемыми опциями
Я нашел similar post about configurable items, однако, он не будет работать для моего случая, потому что я использую простые продукты с вариантами, не конфигурируемых продуктов.
Как я могу отобразить и обновить sku для простого продукта на странице продукта?
Настраиваемый Код товара для динамического Sku:
<?php
$_product = $this->getProduct();
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());
?>
<?php if ($_product->isSaleable() && count($_attributes)):?>
<dl>
<?php foreach($_attributes as $_attribute): ?>
<dt><label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label></dt>
<dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>>
<div class="input-box">
<select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select"
onchange="return changeSku(<?php echo $_attribute->getAttributeId() ?>, this);">
<option><?php echo $this->__('Choose an Option...') ?></option>
</select>
</div>
</dd>
<?php endforeach; ?>
</dl>
<script type="text/javascript">
var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
</script>
<?php endif;?>
<div id="sku-container"></div>
<?php
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$col = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
$productMap = array();
foreach($col as $simpleProduct){
$productMap[$simpleProduct->getId()] = $simpleProduct->getSku();
}
?>
<script type="text/javascript">
document.observe("dom:loaded", function() {
$("sku-container").update("<strong>Product Id: </strong> Select an option to display Product Id");
});
function changeSku(confAttributeId, sel) {
var productMap = <?php echo Mage::helper('core')->jsonEncode($productMap);?>;
var selectedAttributeId = sel.options[sel.selectedIndex].value;
if (selectedAttributeId) {
var options = spConfig.config.attributes[confAttributeId].options;
var productId = options.find(function (option) {return option.id == selectedAttributeId}).products[0]
$("sku-container").update("<strong>Product Id: </strong>" + productMap[productId]);
} else {
$("sku-container").update("<strong>Product Id: </strong> Select an option to display Product Id");
}
}
</script>
BTW Я использую Magento Community Edition 1.9.x – NotJay
Уверен, что у вас была причина идти в направлении, которое вы сделали, но, похоже, вы пытаетесь изобрести колесо и работать с встроенными структурами данных Magento , – fantasticrice
@fantasticrice Я фактически не реализовал этот код, который я использую в качестве ссылки. Я ищу решение для демонстрации динамического ски для простых продуктов. – NotJay