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.

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

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀