php 属性集属性范围产品属性集

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 属性集属性范围产品属性集相关的知识,希望对你有一定的参考价值。

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

-------- Get attributes by attribute group Magento get product attribute by group name 

<?php
    $setId = $_product->getAttributeSetId();
    $groups = Mage::getModel('eav/entity_attribute_group')
        ->getResourceCollection()
        ->setAttributeSetFilter($setId)
        ->setSortOrder()
        ->load();

    $attributeCodes = array();
    foreach ($groups as $group) {
        if($group->getAttributeGroupName() == 'Saw Specs'){
        $attributes = Mage::getResourceModel('catalog/product_attribute_collection')
            ->setAttributeGroupFilter($group->getId())
            ->addVisibleFilter()
            ->checkConfigurableProducts()
            ->load();
            if ($attributes->getSize() > 0):
?>
    <dt class="tab">
        <span><?php echo $this->__( 'Specifications' ); ?></span>
    </dt>
    <dd class="tab-container ">
        <div class="tab-content">
            <strong class="title"><?php echo $this->__( 'Specifications' ); ?></strong>
            <h2><?php echo $this->__( 'COSEN' ); ?> <?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h2>

            <table class="data-table" id="product-attribute-specs-table">
                <tbody>
                <?php foreach ($attributes->getItems() as $attribute): ?>
                    <tr>

                        <?php
                            $current_attribute = $_product->getAttributeText( $attribute->getAttributeCode() );
                            $value = '';
                            if( !empty( $current_attribute ) )
                            {
                                if(is_array($current_attribute))
                                {
                                    $counter = 0;
                                    foreach( $current_attribute as $attribute_value ){
                                        ++$counter;
                                        if( $counter != count( $current_attribute ) ){
                                            $value .= $attribute_value.', ';
                                        }else{
                                           $value .= $attribute_value;
                                        }
                                    }
                                }else{
                                    $value .= $_product->getAttributeText( $attribute->getAttributeCode() );
                                }
                            }
                            else
                            {
                                $value .= $_product->getData( $attribute->getAttributeCode() );
                            }

                            if( !empty( $value ) ):
                        ?>
                            <th class="label"><?php echo $_product->getResource()->getAttribute( $attribute->getAttributeCode() )->getFrontend()->getLabel($_product); ?></th>
                            <td class="data"><?php echo $value; ?></td>
                        <?php endif; ?>

                    </tr>
                <?php endforeach; ?>
                </tbody>
            </table>

            <em class="comment"><?php echo $this->__( '* Design and specifications are subject to change without notice & obligation. Machines may be shown with some options.' ); ?></em>
        </div>
    </dd>
        <?php endif; ?>
<?php
      }
    }
?>

<?php
$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() == 'Product Features'){ // 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();   
echo $_product->getResource()->getAttribute($attribute->getAttributeCode())->getFrontend()->getValue($_product);                  
            }
        } 
  }
}
print_r($attributeCodes);
?>

<?php
    $setId = $_product->getAttributeSetId();
    $groups = Mage::getModel('eav/entity_attribute_group')
        ->getResourceCollection()
        ->setAttributeSetFilter($setId)
        ->setSortOrder()
        ->load();
        
    $attributeCodes = array();
?>

<?php foreach ($groups as $group):  ?>
    <?php if($group->getAttributeGroupName() == 'Website Design'): ?>
        <li data-label="<?php echo $this->__('Website Design'); ?>" class="alt"></li>
        
        <?php
            $attributes = Mage::getResourceModel('catalog/product_attribute_collection')
            ->setAttributeGroupFilter($group->getId())
            ->addVisibleFilter()
            ->checkConfigurableProducts()
            ->load();
            if ($attributes->getSize() > 0):
        ?>
            <?php foreach ($attributes->getItems() as $attribute): ?>
                <li data-label="<?php echo $_product->getResource()->getAttribute($attribute->getAttributeCode())->getFrontend()->getLabel($_product); ?>">
                    <?php
                        $value = $_product->getResource()->getAttribute($attribute->getAttributeCode())->getFrontend()->getValue($_product);
                        if(strtolower($value) == 'yes' || strtolower($value) == 'no'):
                    ?>
                        <span class="icon-<?php echo strtolower($value); ?>"><?php echo $value; ?></span>
                    <?php else: ?>
                        <?php echo $value; ?>
                    <?php endif; ?>
                </li>
            <?php endforeach; ?>
        <?php endif; ?>
        
    <?php endif; ?>
    
    <?php if($group->getAttributeGroupName() == 'Marketing Expertise'): ?>
        <li data-label="Marketing Expertise" class="alt"></li>
        
        <?php
            $attributes = Mage::getResourceModel('catalog/product_attribute_collection')
            ->setAttributeGroupFilter($group->getId())
            ->addVisibleFilter()
            ->checkConfigurableProducts()
            ->load();
            if ($attributes->getSize() > 0):
        ?>
            <?php foreach ($attributes->getItems() as $attribute): ?>
                <li data-label="<?php echo $_product->getResource()->getAttribute($attribute->getAttributeCode())->getFrontend()->getLabel($_product); ?>">
                    <?php
                        $value = $_product->getResource()->getAttribute($attribute->getAttributeCode())->getFrontend()->getValue($_product);
                        if(strtolower($value) == 'yes' || strtolower($value) == 'no'):
                    ?>
                        <span class="icon-<?php echo strtolower($value); ?>"><?php echo $value; ?></span>
                    <?php else: ?>
                        <?php echo $value; ?>
                    <?php endif; ?>
                </li>
            <?php endforeach; ?>
        <?php endif; ?>
        
    <?php endif; ?>
<?php endforeach; ?>

以上是关于php 属性集属性范围产品属性集的主要内容,如果未能解决你的问题,请参考以下文章

Magmi 属性集 Importer 不设置产品属性

如何获取属性集名称?

使用带有 liquibase 变更集上下文属性的 Spring Boot 配置文件来管理变更集范围

Magento开发经验总结(一 初初见你——产品属性集搜索模块)

使用程序集属性的最佳实践是啥?

如何根据Magento可配置产品中的不同属性集更改产品图像?