一些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();
|
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