0

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:

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

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?

0

Simple as that:

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

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')
     ->addAttributeToSelect('product_link')
     ->addAttributeToFilter('entity_id',  $item->getProduct()->getId())
     ->setPageSize(1);

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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