I am using Magento 1.9.2.

I have custom product attribute for every product in my store. The attribute code is product_link.

I have this code to get all products in the current cart session:

error_reporting(E_ALL | E_STRICT);
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
$app = Mage::app('default'); 

Mage::getSingleton('core/session', array('name' => 'frontend'));

$cart = Mage::getModel('checkout/cart')->getQuote();
foreach ($cart->getAllItems() as $item) {
    $ProductLink = $item->getProduct()->getProductLink();
    $ProductName = $item->getProduct()->getName();
    echo "ProductLink: $ProductLink - ProductName: $ProductName<br>";

I have no problem to get the name of the product which is a default attribute. However i can not get the link value in product_link attribute which all products have.

Where is my mistake how may i fix it?

2 Answers 2


Simple as that:

$ProductLink = Mage::getModel('catalog/product')->load($item->getProduct()->getId())->getProductLink();

Loading the entire product just to get one attribute is very bad in terms of performance here's what you should do:

$collection = Mage::getResourceModel('catalog/product_collection')
     ->addAttributeToFilter('entity_id',  $item->getProduct()->getId())

$productLink = $collection->getFirstItem()->getProductLink();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.