【发布时间】:2015-06-23 20:59:26
【问题描述】:
所以我刚刚发现 this code 几乎可以满足我的需求。 I need for the code to dynamically display the sku of a configurable product (simple product's sku) when the options are selected.唯一的问题是,在选择选项之前,它会显示第一个简单的产品 sku。在选择所有选项之前,我希望它什么都不显示。
代码如下: app/design/frontend/rwd/default/template/catalog/product/view/type/options/configurable.phtml
<?php
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$col = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
?>
<script type="text/javascript">
var Skus =new Array();
<?php
$count = 1;
$itemId = array();
foreach($col as $simple_product){
$itemId[] = array($simple_product->getSelectLabel() => $simple_product->getSku());
}
foreach($itemId as $val){
foreach($val as $k => $v){
echo 'Skus['.$count.'] = "'.$v.'";'. "\n";
$count++;
}
};
?>
$j(document).ready(function(){
$j("#productcode").html("Product Code: " +Skus[1]);
$j("select#attribute<?php echo $_attribute->getAttributeId() ?>").change(function(){
var position = $j("#attribute<?php echo $_attribute->getAttributeId() ?> option").index($j("#attribute<?php echo $_attribute->getAttributeId() ?> option:selected"));
$j("#productcode").html(Skus[position] ? "Product Code: " +Skus[position] : "Product Code: " +Skus[1]);
});
});
</script>
并且: app/design/frontend/rwd/default/template/catalog/product/view/view.phtml
<div id="productcode"></div>
目前,动态 sku 会显示第一个 sku 记录,直到所有选项都被选中,然后显示正确的选项。如何在选择所有选项之前隐藏 sku,或者在有人返回编辑他们的选择时隐藏它?
提前致谢!
【问题讨论】:
标签: javascript php magento dynamic