Get Upsell products list using Product Id in Magento
Get Upsell products list using Product Id in Magento:-
Sometime we need to show product in custom location file and in that file you also want to show list of upsell product by product id .
Suppose that your product ID is $productId using that ID you can get list of Upsell product. Copy following code and place it in you custom file.
<?php // Get product object. $object = Mage::getModel('catalog/product'); //Get product detail using product id (Suppose you have product id is : $productId) $product = $object->load($productId); // Fetch list of upsell product using query. $upsell_product = $product->getUpSellProductCollection() ->addAttributeToSort('position', Varien_Db_Select::SQL_ASC) ->addStoreFilter(); //check if record is empty or not $count = count($upsell_product); if(empty($count)) : //if empty echo "Record not found"; else: foreach($upsell_product as $upsell): //get detail of single upsell prdocut using upsell product id $upsellproduct = $object->load($upsell->getId()); echo "Product Name : ". $upsellproduct->getName(); echo "Poduct url : ". $upsellproduct>getProductUrl(); echo "Product regular price : ". $upsellproduct->getPrice(); endforeach; endif; ?>