簡體   English   中英

在magento中獲取可配置的產品屬性標簽和當前產品的ID

[英]get configurable product attributes labels and id of current product in magento

當我print_r $myArray ..它顯示color屬性的所有標簽。

我只想顯示當前產品使用的那些屬性(標簽和ID)。我的網站也使用一些自定義主題,因此我希望啟用默認的可配置選項與product.Currently顯示。

<?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 $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
                }
            }?> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM