【问题标题】:get configurable product attributes labels and id of current product in magento在magento中获取当前产品的可配置产品属性标签和ID
【发布时间】:2015-06-02 10:16:40
【问题描述】:

当我print_r$myArray..它显示color属性的所有标签..

我只想显示当前产品使用的那些属性(标签和 ID)。此外,我的网站正在使用一些自定义主题,我想启用默认的可配置选项以与产品一起显示。目前它不是。

<?php 
 $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'color');
 foreach ($attribute->getSource()->getAllOptions(true, true) as $instance) 
 {
         $myArray[$instance['value']] = $instance['label']; 
 }
 print_r($myArray);
?>

【问题讨论】:

    标签: php magento product catalog


    【解决方案1】:

    此代码可能会有所帮助,我也在搜索确切的内容并在另一个博客上找到了它

    <?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)
                    {
                        ?>
                        <dl>
                            <dt><label class="required"><em>*</em><?php echo $attributes["label"]; ?></label></dt>
                            <dd>
                                <div class="input-box">
                                    <select name="super_attribute[<?php echo $attributes['attribute_id'] ?>]" id="attribute<?php echo $attributes['attribute_id'] ?>">
                                        <?php
                                        foreach($attributes["values"] as $values)
                                        {
                                            echo "<option>".$values["label"]."</option>";
                                        }
                                        ?>
                                    </select>
                                </div>
                            </dd>
                        </dl>
                        <?php
                    }
                }?> 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-25
      • 1970-01-01
      • 2018-07-18
      • 1970-01-01
      • 1970-01-01
      • 2014-02-01
      相关资源
      最近更新 更多