【问题标题】:Magento - Get Configurable Product Available SizesMagento - 获取可配置的产品可用尺寸
【发布时间】:2017-04-28 20:54:40
【问题描述】:

我正在尝试在 list.phtml 网格中获取我的可配置产品的所有可用尺寸。

使用下面的代码,我可以成功获取所有尺寸,但它甚至会显示不可用的尺寸。

    <?php if($_product->isSaleable()): ?>
    <div class="taglie">
    <?php $cProduct = Mage::getModel('catalog/product')->load($_product->getId());
    //check if product is a configurable type or not
    if ($cProduct->getData('type_id') == "configurable") {
        //get the configurable data from the product
        $config = $cProduct->getTypeInstance(true);
        //loop through the attributes
        foreach($config->getConfigurableAttributesAsArray($cProduct) as $attributes) { ?>
            <?php foreach($attributes["values"] as $values) {
                echo "<span>".$values["label"]."</span>";
            } ?> 
        <?php 
        } 
    } ?>
</div>
<?php else: ?>
    <?php echo $this->__('Out of Stock') ?>
<?php endif; ?>

我想要做的是隐藏不可用的尺寸选项。

【问题讨论】:

    标签: php magento magento-1.9


    【解决方案1】:
    <p style="margin-top: 8px;">    
        <?php 
            $sizes = array();
            if($_product->isConfigurable()){
                $allProducts = $_product->getTypeInstance(true)->getUsedProducts(null, $_product);
                foreach ($allProducts as $subproduct) {
                    if ($subproduct->isSaleable()) {
                        $sizes[] = $subproduct->getAttributeText('size');
                    }
                }
                if(count($sizes)>0) {
                echo implode(", ", $sizes);
                }
            }
        ?>
    </p>
    

    【讨论】:

      猜你喜欢
      • 2016-02-01
      • 2010-12-09
      • 1970-01-01
      • 1970-01-01
      • 2015-06-23
      • 2014-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多