in magento how can i Get related product in the product listing page
I am doing a magento project where i have to bring related product and upsell product in th开发者_如何学Pythone product listing page which is product/list.phtml i can get all the product details from
foreach ($_productCollection as $_product): $_product->but i can't get any related product and upsell product using $_product->
please help me pleaseYou can do the following (inside the foreach loop)
$related_product_collection = $_product->getRelatedProductCollection();
$related_product_collection->AddStoreFilter();
Regards, Kenny
PS: If you want to know which methods are available, you can always run the
var_dump(get_class_methods($_product)); die;
//or
Mage::log(print_r(get_class_methods($_product),true));
First one will print all available methods on the screen while second one will output it in the system.log located in the /var/log/system.log (make sure that in configuration->developer you have logging enabled of course)
You can pass product id for which you require related product.
E.g You need related product for a particular product (Say $_product)
You can get related product ids by
$_product->getRelatedProductIds()
You can see array of ids by :
print_r($_product->getRelatedProductIds());
I hope this will help you.
Regards, Kamesh J
On list page you get all product details with id.
using this code $_product=Mage::getModel('catalog/product')->load(product_id);
you get product for that id.
After use this code to get details of related product
$relatedProductsId=$_product->getRelatedProductIds();
$relatedProducts=array();
$i=0;
foreach($relatedProductsId as $relatedProductId)
{
$relatedProducts[$i] = Mage::getModel('catalog/product')->load($relatedProductId)->getName();
$i++;
}
and you get all related product
精彩评论