Necesita mostrar un mensaje de advertencia si un producto de una categoría determinada está en el carrito

magento.stackexchange https://magento.stackexchange.com//questions/33614

  •  12-12-2019
  •  | 
  •  

Pregunta

Necesito agregar un mensaje de advertencia a la página de Methips Methods en el carrito si se ha ordenado un producto de una categoría determinada.

Por ejemplo, si nuestros muebles de pedido de los clientes de la categoría ID 76, entonces necesito un mensaje para aparecer diciendo "¡ADVERTENCIA! La entrega puede tardar más lejos que los 2-5 días hábiles" es posible ".Sé que necesitaría una declaración si no sé qué escribir en él o dónde ponerlo.

//////////// añadido //////////////

excepcion.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

Gracias si puedes ayudar

¿Fue útil?

Solución

Adam, puede hacer usando el evento Observador en el evento 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

código parece esto: 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: y paso3:

    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;

            }
        }

Oye de acuerdo con su solicitud:

Editar: crear

config.xml en la aplicación / código / local / stackExchange / magento3614 / 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 en App / Code / Local / StackExchange / Magento3614 / Model y el código es

<?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: crea stackexchange_magento33614.xml en la aplicación / etc / módulos /

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top