doutuosai3504 2015-06-23 20:59
浏览 99
已采纳

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

So I just found this code that does what I want, almost. I need for the code to dynamically display the sku of a configurable product (simple product's sku) when the options are selected. The only problem is that until the options are selected, it shows the first simple product sku. I want it to show nothing until all the options are selected.

Here is the code: 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.'";'. "
";
$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>

And: app/design/frontend/rwd/default/template/catalog/product/view/view.phtml

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

Currently, the dynamic sku shows the first sku record until all the options are selected and then shows the correct one. How can I hide the sku until all options are selected or hide it if someone goes back to edit their selections?

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • doumei3828 2015-06-24 09:55
    关注

    If you comment (or remove) the following line it won't put anything in the div onload:

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

    The following code will still write the SKU there when the select is changed:

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

    Hope that helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效