magento中的attribute 总结

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. 获取某个种类的所有attribute:

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


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

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


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

8。 获取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中的attribute 总结

[文章作者]曾健生

[作者邮箱]zengjiansheng1@126.com

[作者QQ]190678908

[博客]  http://blog.csdn.net/newjueqi




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
`HttpPostActionInterface`是Magento 2框架的一个接口,用于处理HTTP POST请求。它定义了一个方法`execute()`,该方法接收一个`RequestInterface`对象作为参数,并返回一个`ResultInterface`对象。 具体来说,当一个HTTP POST请求被发送到Magento应用程序时,Magento会根据请求的路由信息调用相应的控制器类。控制器类将实现`HttpPostActionInterface`接口,并在`execute()`方法执行请求处理逻辑。在`execute()`方法,开发人员可以根据请求参数执行相应的操作,并返回一个表示操作结果的`ResultInterface`对象。 例如,以下代码片段演示了如何实现一个自定义的`HttpPostActionInterface`控制器类: ```php use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Framework\App\RequestInterface; use Magento\Framework\Controller\ResultFactory; class MyController implements HttpPostActionInterface { public function execute(RequestInterface $request) { // 获取请求参数 $param1 = $request->getParam('param1'); $param2 = $request->getParam('param2'); // 执行相应的操作 // ... // 返回操作结果 $result = $this->resultFactory->create(ResultFactory::TYPE_JSON); $result->setData(['success' => true, 'message' => '操作成功']); return $result; } } ``` 在上述示例,我们通过`$request->getParam()`方法获取了请求的参数,并执行了相应的操作。最后,我们创建了一个JSON格式的`ResultInterface`对象并返回它,表示操作成功。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

newjueqi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值