【问题标题】:Get attributes by attribute group Magento按属性组 Magento 获取属性
【发布时间】:2014-02-05 17:30:18
【问题描述】:

我有产品:

<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>

我有属性组的名称(不是 ID)。

我需要列出此属性组中的所有属性名称和值(与属性集无关)。

如果我只知道产品和属性组名称,我如何从属性组中获取属性和值?

【问题讨论】:

    标签: magento


    【解决方案1】:
      $setId = $_product->getAttributeSetId(); // Attribute set Id
            $groups = Mage::getModel('eav/entity_attribute_group')
                ->getResourceCollection()
                ->setAttributeSetFilter($setId)
                ->setSortOrder()
                ->load();
    
            $attributeCodes = array();
            foreach ($groups as $group) {
                if($group->getAttributeGroupName() == 'Somename'){ // set name
                //$groupName          = $group->getAttributeGroupName();
                //$groupId            = $group->getAttributeGroupId();
    
                $attributes = Mage::getResourceModel('catalog/product_attribute_collection')
                    ->setAttributeGroupFilter($group->getId())
                    ->addVisibleFilter()
                    ->checkConfigurableProducts()
                    ->load();
                    if ($attributes->getSize() > 0) {
                        foreach ($attributes->getItems() as $attribute) {
                            /* @var $child Mage_Eav_Model_Entity_Attribute */
                            $attributeCodes[] = $attribute->getAttributeCode();                     
                        }
                    } 
              }
            }
            print_r($attributeCodes);
    

    【讨论】:

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