Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

I need to add a warning message to my shipping methods page in the cart if a product from a certain category has been ordered.

for example if our customer order furniture from the category ID 76 then i need a message to appear saying "Warning! delivery may take longer than the standard 2-5 working days" is this possible. I know i would need an IF statement i just dont know what to write in it or where to put it.

////////////ADDED/////////////

Exception.log

2013-08-27T14:11:26+00:00 ERR (3): 
exception 'Mage_Core_Exception' with message 'Invalid block type: Mage_Catalog_Block_Product_List_Related2' in /home/senorehe/public_html/app/Mage.php:594
Stack trace:
#0 /home/senorehe/public_html/app/code/core/Mage/Core/Model/Layout.php(495): Mage::throwException('Invalid block t...')
#1 /home/senorehe/public_html/app/code/core/Mage/Core/Model/Layout.php(437): Mage_Core_Model_Layout->_getBlockInstance('catalog/product...', Array)
#2 /home/senorehe/public_html/app/code/core/Mage/Core/Model/Layout.php(472): Mage_Core_Model_Layout->createBlock('catalog/product...', 'content.product...')
#3 /home/senorehe/public_html/app/code/core/Mage/Core/Model/Layout.php(239): Mage_Core_Model_Layout->addBlock('catalog/product...', 'content.product...')
#4 /home/senorehe/public_html/app/code/core/Mage/Core/Model/Layout.php(205): Mage_Core_Model_Layout->_generateBlock(Object(Mage_Core_Model_Layout_Element), Object(Mage_Core_Model_Layout_Element))
#5 /home/senorehe/public_html/app/code/core/Mage/Core/Model/Layout.php(210): Mage_Core_Model_Layout->generateBlocks(Object(Mage_Core_Model_Layout_Element))
#6 /home/senorehe/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(344): Mage_Core_Model_Layout->generateBlocks()
#7 /home/senorehe/public_html/app/code/core/Mage/Catalog/Helper/Product/View.php(73): Mage_Core_Controller_Varien_Action->generateLayoutBlocks()
#8 /home/senorehe/public_html/app/code/core/Mage/Catalog/Helper/Product/View.php(144): Mage_Catalog_Helper_Product_View->initProductLayout(Object(Mage_Catalog_Model_Product), Object(Mage_Catalog_ProductController))
#9 /home/senorehe/public_html/app/code/core/Mage/Catalog/controllers/ProductController.php(132): Mage_Catalog_Helper_Product_View->prepareAndRender(11342, Object(Mage_Catalog_ProductController), Object(Varien_Object))
#10 /home/senorehe/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(419): Mage_Catalog_ProductController->viewAction()
#11 /home/senorehe/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('view')
#12 /home/senorehe/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#13 /home/senorehe/public_html/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#14 /home/senorehe/public_html/app/Mage.php(683): Mage_Core_Model_App->run(Array)
#15 /home/senorehe/public_html/index.php(87): Mage::run('', 'store')
#16 {main}

System.log

2014-08-26T14:10:25+00:00 ERR (3): Warning: simplexml_load_string() [<a href='function.simplexml-load-string'>function.simplexml-load-string</a>]: Entity: line 9: parser error : Premature end of data in tag config line 2  in /home/senorehe/public_html/lib/Varien/Simplexml/Config.php on line 510
2014-08-26T14:10:25+00:00 ERR (3): Warning: simplexml_load_string() [<a href='function.simplexml-load-string'>function.simplexml-load-string</a>]:  /config&gt;  in /home/senorehe/public_html/lib/Varien/Simplexml/Config.php on line 510
2014-08-26T14:10:25+00:00 ERR (3): Warning: simplexml_load_string() [<a href='function.simplexml-load-string'>function.simplexml-load-string</a>]:          ^  in /home/senorehe/public_html/lib/Varien/Simplexml/Config.php on line 510

Thank you if you can help

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Adam ,you can do using event observer on event checkout_cart_product_add_after

step1:call an observer on checkout_cart_product_add_after and 
step2:in this observer  you can get product id and get Categories from product
step3: set message using session message

Code look like this: Step1

<checkout_cart_product_add_after>
  <observers>
    <teknoid_catch_standard_add_to_cart>
      <type>singleton</type>
      <class>yourmodule_yourmodel/observer</class>
      <method>catchAddToCart</method>
    </teknoid_catch_standard_add_to_cart>
  </observers>
</checkout_cart_product_add_after>

step2: and Step3:

    public function catchAddToCart($observer) {
            //getting product ID from event data
            $productId = $observer->getProduct()->getId();
            $categoires=null
            $Product = Mage::getModel('catalog/product')->load($productId);
        $categoires= explode(',',$Product->getCategoriesId());
        if(in_array('yourcatid',$categoires)):
    // add message 
 Mage::getSingleton('checkout/session')->addError($this->__('Product is cart from Category page.'));

        endif;

            }
        }

Hey According to your request:

Edit: create

config.xml at app/code/local/Stackexchange/Magento33614/etc/

<?xml version="1.0" ?>
<config>
    <modules>
        <Stackexchange_Magento33614>
            <version>1.0.0</version>
        </Stackexchange_Magento33614>   
    </modules>  
    <global>
        <models>
            <magento33614>
                <class>Stackexchange_Magento33614_Model</class>
            </magento33614> 
        </models>
        <events>
            <checkout_cart_product_add_after>
              <observers>
                <teknoid_catch_standard_add_to_cart>
                  <type>singleton</type>
                  <class>magento33614/observer</class>
                  <method>catchAddToCart</method>
                </teknoid_catch_standard_add_to_cart>
              </observers>
            </checkout_cart_product_add_after>
        </events>   
    </global>
</config>   

Observer.php at app/code/local/Stackexchange/Magento33614/Model and code is

<?php
class Stackexchange_Magento33614_Model_Observer{

    public function catchAddToCart($observer){
         $productId = $observer->getProduct()->getId();
         $categoires=null;
         $Product = Mage::getModel('catalog/product')->load($productId);
         $value='';
         $categoryIds = $Product->getCategoryIds();

         //static code for match cat
        $matchCatId=10;
        if(Mage::registry('current_category') && Mage::registry('current_category')->getId()== $matchCatId){
              $_category = Mage::getModel('catalog/category')->load($matchCatId);
              $message = Mage::helper('checkout')->__('Your product has been cart from . %s .delivery may take longer than the standard 2-5 working days', $_category->getName());
            Mage::getSingleton('checkout/session')->addError( $message);

        }elseif (in_array($matchCatId,$categoryIds)){
                $_category = Mage::getModel('catalog/category')->load($matchCatId);
              $message = Mage::helper('checkout')->__('Your product has been cart from . %s .delivery may take longer than the standard 2-5 working days', $_category->getName());
            Mage::getSingleton('checkout/session')->addError( $message);

        }else{
        Mage::getSingleton('checkout/session')->addError( "not match");
        }



         return;
    }

}

Step3:create Stackexchange_Magento33614.xml at app/etc/modules/

<?xml version="1.0" ?>
<config>
    <modules>
        <Stackexchange_Magento33614>
            <codePool>local</codePool>
            <active>true</active>
        </Stackexchange_Magento33614>   
    </modules>  
</config>
share|improve this answer
    
Thank you i will give this a go in a mintue. Do i just add this to my shipping methods template file? sotty never used event observers before and still learning magento –  Adam Allen Aug 26 at 11:25
    
ok, i will give total cde –  Amit Bera Aug 26 at 11:25
    
thank you so much –  Adam Allen Aug 26 at 11:32
    
When i add the Observer my Add to cart button stops working –  Adam Allen Aug 26 at 13:54
    
can give me system.log and exception.log.. i will check what is the issue –  Amit Bera Aug 26 at 14:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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