Try the Demo

Magento Forum

   
change add to cart message
 
Paul-xib
Sr. Member
 
Avatar
Total Posts:  107
Joined:  2009-02-02
The Netherlands
 

hi,

I am looking for the code to change the messages when a customer add a product to the cart. above the product view you get the succes message (green colour).

now i want to at some code to that succes line so i can call a custom block.

where can i find this code?

in product/view.phtml is see this:

<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>

but what is the location of the messageblock?

 Signature 

http://www.aquablog.nl
Everything you want to know about aquascaping.

 
Magento Community Magento Community
Magento Community
Magento Community
 
kiatng
Enthusiast
 
Total Posts:  870
Joined:  2008-09-03
Kuala Lumpur, Malaysia
 

First, you may like to try docs.magentocommerce.com to search for location of a particular method.  But in this case, the first place to look for getMessageBlock is in app/core/Mage/Catalog/Block/Product/View.php.  If you look at the directory structure, you’ll see that it is similar to product/view.phtml.  If the method is not there, then it is in the parent class. (If you can’t find the method anywhere else, then it may be the magic getter method because all/most (I’m not sure) classes have their roots as a Verian Object.) Because there is a getGroupedHtml(), we can safely tell that getMessageBlock returns an object, probably of Model Class. And when I looked it up in docs.magentocommerce.com, it is in fact of type Mage_Core_Block_Messages. 

Actually, if all you want to do is to call a custom block, then knowing the above may not help in your case.  Easiest way is to declare your block in checkout.xml.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ivn03
Member
 
Total Posts:  57
Joined:  2011-10-11
 

I am trying to do something similar.

When a product is being added to the cart, I would like the success message to show upsell_products block appended to it. I was thinking of editing the CartController.php but to no success.

Can anyone help me with this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
arabgento
Sr. Member
 
Avatar
Total Posts:  124
Joined:  2011-08-04
sale-morocco
 

the green in top is flash message
you must search how customise
in cartController in action addAction
$message = $this->__(’%s was added to your shopping cart.’, Mage::helper(’core’)->htmlEscape($product->getName()));
$this->_getSession()->addSuccess($message);

but he output is the template inside
app/design/frontend/base/default/template/core/message.phtml
this ligne ($this->getMessagesBlock()->getGroupedHtml()
inside app/design/frontend/base/default/template/chekout/success.phtml) =equal = (Mage_Core_Block_Messages + app/design/frontend/base/default/template/core/message.phtml)

 Signature 

Founder of Magento Arab Community : http://www.arabgento.com
Support of Magento in Arab World
Languages : Arabic, French, English

 
Magento Community Magento Community
Magento Community
Magento Community
 
Tykhon_Dziuban
Jr. Member
 
Avatar
Total Posts:  24
Joined:  2010-08-09
Kyiv, Ukraine
 

Why cant you just change this:

if (!$this->_getSession()->getNoCartRedirect(true)) {
                
if (!$cart->getQuote()->getHasError()){
                    $message 
$this->__('%s was added to your shopping cart.'Mage::helper('core')->htmlEscape($product->getName())) . ;
                    
$this->_getSession()->addSuccess($message);
                
}
                $this
->_goBack();
            
}
Into something like this?:
if (!$this->_getSession()->getNoCartRedirect(true)) {
                
if (!$cart->getQuote()->getHasError()){
                    $customBlock 
= new CustomBlockClass;
                    
$message $this->__('%s was added to your shopping cart.'Mage::helper('core')->htmlEscape($product->getName())) . $customBlock->_toHtml();
                    
$this->_getSession()->addSuccess($message);
                
}
                $this
->_goBack();
            
}
Code might be found in app/code/core/Mage/Checkout/controllers/CartController.php

 
Magento Community Magento Community
Magento Community
Magento Community
 
plu_australia
Sr. Member
 
Total Posts:  132
Joined:  2010-04-20
 

Hi, I wanted to add a line to the success message when an item is added to the cart so changed:

if (!$this->_getSession()->getNoCartRedirect(true)) {
                
if (!$cart->getQuote()->getHasError()){
                    $message 
$this->__('%s was added to your shopping basket.'Mage::helper('core')->htmlEscape($product->getName()));
                    
$this->_getSession()->addSuccess($message);
                
}
                $this
->_goBack();
            
}

to:

if (!$this->_getSession()->getNoCartRedirect(true)) {
if (!$cart->getQuote()->getHasError()){
$message = $this->__(’%s was added to your shopping basket.<br><br>Our dispatch facility is taking short well-deserved break! All orders placed between the 11th and 17th of January will be processed and shipped on Friday January 18.
‘, Mage::helper(’core’)->htmlEscape($product->getName()));
$this->_getSession()->addSuccess($message);
}
$this->_goBack();
}

Cleared cache etc however the change is not showing up on the front end.
Change was made to /public_html/app/code/core/Mage/Checkout/controllers/CartController.php

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top