Magento 显示可配置产品的动态 SKU...在选择所有选项之前不显示

Magento Display Dynamic SKU for configurable Product... Don't Display until all options are selected

所以我发现 this code 几乎可以满足我的要求。我需要代码在选择选项时动态显示可配置产品的 sku(简单产品的 sku)。唯一的问题是,在选择选项之前,它会显示第一个简单的产品 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 直到所有选项都被选中,或者如果有人返回编辑他们的选择,我如何隐藏它?

提前致谢!

如果您评论(或删除)以下行,它不会在 div 加载中添加任何内容:

$j("#productcode").html("Product Code: " +Skus[1]);

当 select 更改时,以下代码仍会在其中写入 SKU:

$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]);
});

希望对您有所帮助。