2015-06-23 46 views
0

所以我只是發現this code,做我想要的,差不多。當選擇選項時,我需要代碼來動態顯示可配置產品(簡單產品的sku)的sku。唯一的問題是,在選擇選項之前,它會顯示第一個簡單產品SKU。我希望它不顯示任何東西,直到所有的選項被選中。Magento顯示動態SKU的可配置產品...不要顯示,直到所有選項被選中

下面是代碼: 應用程序/設計/前端/ RWD /默認/模板/目錄/產品/視圖/類型/選項/ 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> 

和: 應用程序/設計/前端/rwd/default/template/catalog/product/view/view.phtml

<div id="productcode"></div> 

目前,動態SKU顯示第一個SKU記錄,直到選擇了所有選項,然後顯示正確的一個。如何在隱藏sku直到所有選項被選中或隱藏它,如果有人回去編輯他們的選擇?

在此先感謝!

回答

1

如果你對此有何評論(或刪除)以下行也不會放任何東西在div的onload:

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

下面的代碼仍然會寫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]); 
}); 

希望有幫助。

+0

當我刪除建議的行,沒有顯示。我是否需要添加第二段代碼?如果是,在哪裏? – NotJay

+0

其實,第二段代碼已經是原代碼的一部分了......這段代碼需要進行任何更改嗎?如果是,在哪裏和什麼? – NotJay

相關問題