【问题标题】:Magento Configurable Product AttributesMagento 可配置产品属性
【发布时间】:2011-06-25 12:06:24
【问题描述】:

大家好,magento 遇到问题,我似乎无法找到解决方案。

我尝试了很多方法来获取可配置的产品属性(简单产品)并列出它们,现在我有两种方法列出它们,但我使用的方式如下

$confAttributes = @$_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);

    $sizes = array();

    foreach($confAttributes AS $atts){
        //print '';//'<pre style="display:none;">'.print_r($atts).'</pre>';
        if($atts['label'] == 'Size'){

            foreach($atts['values'] AS $val){

                $sizes[] = $val['store_label']; 

            }   

        }

    }

我现在唯一的问题是我只需要撤回库存中的尺寸属性 - 查看 mage 文件以找到解决方案,但看不到任何东西 - 我需要的结果在配置产品 php 文件中完成,但我无法从我需要列出 size 属性的代码中访问它。

任何帮助都会很棒,谢谢!

【问题讨论】:

  • 所以您需要具有尺码属性且有现货的产品?
  • 嗨安东,当我进入一个可配置的产品时,我需要以正确的顺序获得各种尺寸的产品,并且只有库存,经过大量的挖掘,我设法得到了这个。 :D 现在都整理好了!耶

标签: php magento e-commerce


【解决方案1】:

解决方案: 您可以使用以下代码轻松获取任何其他 PHTML 文件上的所有可配置(产品)详细信息页面信息: 例如:在我的情况下,我正在获取有关目录/产品/list.phtml 的详细信息。

 <script src="<?php echo Mage::getBaseUrl('js') ?>varien/configurable.js" type="text/javascript"></script>
        <?php
        $temp = new Mage_Catalog_Block_Product_View_Type_Configurable();
        $temp->setData('product', $_product);                    
        $_attributes = Mage::helper('core')->decorateArray($temp->getAllowAttributes()); 
        ?>
        <?php if ($_product->isSaleable() && count($_attributes)):?>
            <?php foreach($_attributes as $_attribute): ?>
            <?php
                $prices = $_attribute->getPrices();
                foreach($prices as $price) {
                    echo $price['pricing_value'] . "<br/>";
                }
            ?>
            <?php endforeach; ?>
            <script type="text/javascript">
                var spConfig = new Product.Config(<?php echo $temp->getJsonConfig() ?>);
            </script>
        <?php endif;?>      

谢谢,

【讨论】:

  • 谢谢 - 我不再有这个问题,但仍会检查并回复你 - 谢谢!
【解决方案2】:

找到了解决方案,我必须使用上面我已经编码的内容并使用相关产品的尺寸,然后检查库存水平并将它们放入一个数组并在构建我的属性列表时检查库存 - 效果很好 -其他人有更好的解决方案请分享:D谢谢

【讨论】:

  • 只需将 size 和 stock 属性添加到产品集合中作为过滤器,您无需通过“snake pen*is”访问它们 :)
  • @AntonS “将尺寸和库存属性添加到产品系列”是什么意思?我在 list.phtml 中看到了 $_productCollection 变量,但我不确定如何添加 stock 属性,以便可配置产品的特定选项在缺货时不会显示。
  • 你可以加入他们的收藏
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多