0

I'm trying to call a custom attribute in the cart.phtml and success.phtml pages so that a module can see the text that is contained. The attribute is a dropdown that isn't visible on the frontend at all.

The attribute contains a keyword that the module searches for, if the keyword is found, different finance options appear.

I've got this working on the product page by adding the following to view.phtml and it works perfectly but using the same/similar code on cart.phtml and success.phtml does not work:

$pro->getAttributeText('my_attribute')

I've done some searches and found that I needed to create a custom module and add the attribute in the config.xml of this module but that didn't work. My php knowledge isn't great so I'm sure I'm missing something.

This is what the snippet of code looks like from cart.phtml:

$prodname = "";
if($cart->getAllItems()):
 foreach ($cart->getAllItems() as $item):
 $prodname .= "|||".$item->getProduct()->getAttributeText('my_attribute').$item->getProduct()->getName();
 endforeach;
endif;

I've also tried with $_item and without the ->getProduct() with no luck.

In the admin panel I can see my custom module where I've put the config.xml is enabled. This is the config.xml:

<config>
<modules>
<module_name>
<version>0.0.1</version>
</module_name>
</modules>
 <global>
 <sales>
 <quote>
 <item>
 <product_attributes>
 <my_attribute />
 </product_attributes>
 </item>
 </quote>
 </sales>
 </global>
</config>

Help me stackexchange, you're my only hope

asked Feb 17, 2018 at 17:09

2 Answers 2

0

If you are not getting your custom attribute value/text, then you can try to load the product using id that you will get from $item->getProduct()->getData(). I think $item->getProduct() is not loading all data that is why you are getting your custom product attribute data.

answered Feb 17, 2018 at 18:19
0

In your foreach loop, try:

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

This however will have impact on your site performance. See https://stackoverflow.com/questions/19379792/magento-get-a-custom-attribute-value-without-loading-the-entire-product for possible improvement.

Alternatively you can implement a custom collection load with only the attribute you want to prevent too many call to the db.

answered Feb 18, 2018 at 10:37
1
  • Thanks for the suggestion but that didn't work. I tried the suggestion in the other thread and had no luck also. Commented Feb 19, 2018 at 11:13

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.