【问题标题】:get the attributes for attribute set in magento获取magento中属性集的属性
【发布时间】:2013-09-05 04:05:35
【问题描述】:

如何找到产品属性集的值?

例如,

  1. 衬衫,我需要获取所有活动属性,例如颜色、尺寸和 性别。

  2. 手机,我需要获取所有活动属性,如颜色(大小 手机属性不存在)

如何找到产品属性集的值?

我可以通过以下方式获取属性集值:

 $product = Mage::getModel('catalog/product')->load($productId); 
   $prodAttributeSet = Mage::getModel('eav/entity_attribute_set')->load($product->getAttributeSetId())->getAttributeSetName();

【问题讨论】:

    标签: magento


    【解决方案1】:
    Mage::getModel('catalog/product_attribute_set_api')->items($setId);
    

    类是Mage_Catalog_Model_Product_Attribute_Api 好像有两个方法。 items() 方法似乎可以满足您的要求,即“Retrieve attributes from specified attribute set

    也可以参考

    http://www.blog.magepsycho.com/playing-with-attribute-set-in-magento/

    $attributes = Mage::getModel('catalog/product_attribute_api')->items($attributeSetId);
    foreach($attributes as $_attribute){
        print_r($_attribute);
    }
    

    良好的属性集文档

    http://www.blog.magepsycho.com/playing-with-attribute-set-in-magento/

    希望对你有所帮助。

    【讨论】:

      【解决方案2】:

      您不一定需要访问 API 类。有一种更自然的方法可用。如果您有产品:

      /** @var Mage_Catalog_Model_Product $product **/
      $attributes = $product->getTypeInstance(true)->getSetAttributes($product);
      

      如果没有:

      $attributes = Mage::getModel('catalog/product')->getResource()
        ->loadAllAttributes()
        ->getSortedAttributes($attributeSetId);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-09
        • 2014-04-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多