最新消息:Excel无乱码转CSV,由于工作原因很少更新博客和回复大家的评论,非常抱歉。

magento二次开发中常用的一些小技巧

1.加载某个attribute:

    $attributeCode=Mage::getModel('catalog/resource_eav_attribute')
                        ->load($attrbuteId)
                        ->getData("attribute_code");

2.获取某个attribute的所有option:

$attributeObject=Mage::getModel('eav/config')->getAttribute('catalog_product')->load($attributeId);
        $options = $attributeObject->setStoreId(Mage::app()->getStore()->getId())->getSource()->getAllOptions(false);
$table       = $attributeObject->getBackend()->getTable();

    public function getAttributeOptionsByAttributeCode($entityType, $attributeCode){

    $entityType = Mage::getSingleton('eav/config')->getEntityType($entityType);
         $attributeObject = Mage::getModel('customer/attribute')->loadByCode($entityType, $attributeCode);
         return $attributeObject->setStoreId(Mage::app()->getStore()->getId())->getSource()->getAllOptions(false);

    }

或者:

$optionCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
                ->setAttributeFilter($attr_model->getId())
                ->setStoreFilter($storeId, false)
                ->load();

3.获取某个attribute的所有多语言label:

$attributeLabelsArray= Mage::getResourceModel('eav/entity_attribute')
                        ->getStoreLabelsByAttributeId($attrbuteId);

4.获取所有的产品属性的attribute:

$attributes = Mage::getResourceModel ( 'catalog/product_attribute_collection' )
             ->addFieldToFilter ( "frontend_input", "select" )
             ->load ();

5.获取某个product的所有attribute:

注:如果是在collection中获取自定义的attribute,必须加addAttributeToSelect(), 如下:

product=Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect("dropdownlistone");

6.利用静态block

<?php echo $this->getLayout()->createBlock('clientnumber/widget_name')
                    ->setObject($this->getAddress())
                    ->toHtml() ?>

7.获取某个种类的所有attribute:

$entityTypeId = Mage::getSingleton('eav/config')
                ->getEntityType('catalog_product')
                ->getEntityTypeId();
            $items = Mage::getResourceSingleton('catalog/product_attribute_collection')
                ->setEntityTypeFilter($entityTypeId)
                ->getItems();

8.获取某个attribute_set的所有attribute:

$attributes = Mage::getResourceModel('catalog/product_attribute_collection')
   ->setAttributeSetFilter($attribute_set_id)
   ->load();

 $attributeSetCollection = Mage::getResourceModel('eav/entity_attribute_set_collection')
            ->load();

9.获取attribute 对象 by attribute code

$muarqspFrom = Mage::getSingleton('eav/config')->getAttribute('catalog_product', '
muarqsp_from');

$attrCollection = Mage::getResourceModel('eav/entity_attribute_collection')
               ->setCodeFilter($attributeCode)
               ->load();

转载请注明:嗨酷哥,有你更酷! » magento二次开发中常用的一些小技巧

与本文相关文章

发表我的评论

取消评论
表情 插代码

Hi,您需要填写昵称和邮箱!

  • 必填项
  • 必填项

网友评论0