magento 常用方法

一些magento的常用方法,记录备用.

获取产品属性集

1
$sets  = Mage::getResourceModel( 'eav/entity_attribute_set_collection' ) ->setEntityTypeFilter(Mage::getModel( 'catalog/product' )->getResource()->getTypeId()) ->load() ->toOptionHash();

加载某个attribute:

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

获取某个种类的所有attribute:

1
2
3
4
5
$entityTypeId  = Mage::getSingleton( 'eav/config' )
 
->getEntityType( 'catalog_product' )
 
->getEntityTypeId();
获取某个attribute的所有option:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
$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);
 
}

或者:

1
2
3
4
5
6
7
$optionCollection  = Mage::getResourceModel( 'eav/entity_attribute_option_collection' )
 
->setAttributeFilter( $attr_model ->getId())
 
->setStoreFilter( $storeId , false)
 
->load();

产品缩略图

1
$_thumb  = Mage::helper( 'catalog/image' )->init( $product 'thumbnail' )->resize(50, 50)->setWatermarkSize( '30x10' );

获取登录的用户信息

1
Mage::getSingleton( 'customer/session' )->getCustomer()

获取订单信息

1
2
3
$order  = Mage::getModel( 'sales/order' )->loadByIncrementId( $orderNumber );
 
$order  = Mage::getModel( 'sales/order' )->load( $orderId );

摘自 http://www.hqit.cn/magento-sz-news/article-a-9849.html


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值