0

I want to display a specific product on cart page using attribute . on cart page phtml file i am implementing php code but its not been working . any help appreciated.

based on comment

<?php $_item = $this->getItem()?> <?php $_product= Mage::getSingleton('catalog/product')->load($_item->getProdu‌​ctId()) ?> 
<?php echo $_product->getResource()->getAttribute('cartvalue')->getFron‌​tend()->getValue($_p‌​roduct); ?> 
5
  • what code you have tried so far ?? Feb 6 '17 at 5:11
  • <?php $_item = $this->getItem()?> <?php $_product= Mage::getSingleton('catalog/product')->load($_item->getProductId()) ?> <?php echo $_product->getResource()->getAttribute('cartvalue')->getFrontend()->getValue($_product); ?>
    – Man S.
    Feb 6 '17 at 5:13
  • where cartvalue set to yes on cart.phtml, and this code just breaking cartfrontend
    – Man S.
    Feb 6 '17 at 5:13
  • so if any product has display cart yes then need to display is this your requirement Feb 6 '17 at 5:16
  • yes , i want to display if cartvalue set to yes
    – Man S.
    Feb 6 '17 at 5:18
1

you can try below code that will fetch all product where yourAttribute Value set to yes

<?php  
     $collection = Mage::getModel('catalog/product')->getCollection()
                   ->addAttributeToSelect('*')
                   ->addAttributeToFilter('cartvalue',array('eq' => 1));
     foreach($collection as $product ){
         //your logic
      }



?>
6
  • what to write in your logic ??
    – Man S.
    Feb 6 '17 at 5:27
  • @ManS. your fetching code what you want to fetch from product Feb 6 '17 at 5:28
  • its loading nothing
    – Man S.
    Feb 6 '17 at 5:29
  • var_dump($product); returning nothing and cart page is also broken
    – Man S.
    Feb 6 '17 at 5:30
  • @ManS. what error you get ?? Feb 6 '17 at 5:31
0

You can get value by this code:

 $item->getProduct()->getResource()->getAttribute('cartvalue')->getFrontend()->getValue($item->getProduct()); 

Or For better way use this code in your config.xml:

<global>
    <sales>
        <quote>
            <item>
                <product_attributes>
                    <cartvalue/>                   
                </product_attributes>
            </item>
        </quote>
    </sales>
</global>

And get value by this code:

$item->getProduct()->getAttributeText('cartvalue');

[Edite]

You can create a basic module: First file we will create is Excellence_Test.xml file in location app/etc/modules/

<?xml version="1.0"?>
<config>
    <modules>
        <Excellence_Test>  
            <active>true</active>  
            <codePool>local</codePool> 
        </Excellence_Test>
    </modules>
</config>

Next we create the configuration file of the module: config.xml inside folder Excellence/Test/etc. So etc/config.xml is created

<?xml version="1.0"?>
<config>
    <modules>
        <Excellence_Test>
            <version>0.1.0</version>    <!-- Version of module -->
        </Excellence_Test>
    </modules>
    <global>
    <sales>
        <quote>
            <item>
                <product_attributes>
                    <cartvalue/>                   
                </product_attributes>
            </item>
        </quote>
    </sales>
</global>
</config>
12
  • and where can i find config.xml ?
    – Man S.
    Feb 6 '17 at 5:51
  • are you familiar with custom module app/code/local/Namespace/Mymodule/etc/config file. ? if you have custom module then add it here
    – Arunendra
    Feb 6 '17 at 5:53
  • i can go till app/code/local
    – Man S.
    Feb 6 '17 at 5:58
  • Did you tried first method. ?
    – Arunendra
    Feb 6 '17 at 6:01
  • yes , that just broke the cart.phtml page
    – Man S.
    Feb 6 '17 at 6:02

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.