Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Get product option in custom module
 
bharath chinna
Jr. Member
 
Avatar
Total Posts:  23
Joined:  2012-04-06
Chennai
 

Hi team,

I have created new module for product collection. But i dont know how to get product options like addtocart url, custom option, pricehtml and so on with magento structure....

i.e I have get collection using

Mage::getModel('catalog/product')->getCollection();
. If i print these, i got product id name,sku and some product attribute.  I want product image(resize option), addtocart url etc....

Pls help me....smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
Siggi_Schmitz
Enthusiast
 
Avatar
Total Posts:  811
Joined:  2011-07-03
 

foreach (Mage::getModel(’catalog/product’)->getCollection() as $product) {
Mage::log($product->getData());
}

I think there is all data in the product objects.

But you can display which methods the object has, for example with:

$obj = new ReflectionObject($product);
Mage::log($obj->getMethods());

Maybe you see then in the log files the methods which do you want.

Or try to explizit load the product models with:

foreach (Mage::getModel(’catalog/product’)->getCollection() as $product) {
$obj = Mage::getModel(’catalog/product’)->load($product->getId());
Mage::log($obj->getData());
}

I am not sure if then is more data in the object.

 
Magento Community Magento Community
Magento Community
Magento Community
 
bharath chinna
Jr. Member
 
Avatar
Total Posts:  23
Joined:  2012-04-06
Chennai
 

Hi schmitz,

Thanks for ur response....I got product attributes by usnig catalog/product model. But i want to use methods like getAddToCartUrl(), getOption(), getProductUrl() (same as in list.phtml and product/view.phtml)in my custom module. So how to set current product id and how to use catalog/product_list block to get method information.

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Siggi_Schmitz
Enthusiast
 
Avatar
Total Posts:  811
Joined:  2011-07-03
 

You can load a product with Mage::getModel(’catalog/product’)->load($productId); // integer product id

As i wrote, you can see all available product object methods with ReflectionObject:

$obj = new ReflectionObject($product);
Mage::log($obj->getMethods());

And with

Mage::log($product-getData());

you see all product datas. Methods like getProductUrl() are automatically Methods, getProductUrl() is the same as getData(’product_url’);

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top