magento getting product type from product sku

时间秒杀一切 提交于 2019-12-08 15:11:43

问题


How can i get the product type(simplee,configurable/grouped ...) using product sku or id, i have loaded product collection and from that trying to prict type by

$_product->getTypeId()

But its not printing the product type. Please help me

Thanks


回答1:


I think $_product->getTypeId() should work. If it doesn't then try $_product->getResource()->getTypeId()




回答2:


I got product type following way in phtml file

$product=Mage::getModel('catalog/product')->load($product_id);
$productType=$product->getTypeID();
//Simple Product    
if($productType == 'simple')
{   
  echo "Simple Product";
}                           
//Configurable Product
if($productType == 'configurable')
{   
  echo "Configurable Product";
}



回答3:


did you know that you can see whats inside an object by just performing print_r($_product->getData())




回答4:


Here's another tip.

If you are iterating though Cart Items, then use the getProductType() for the product type information. For example -

foreach( $cartItems as $item ){
    if($item->getProductType() == "configurable") {


来源:https://stackoverflow.com/questions/5177890/magento-getting-product-type-from-product-sku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!