특정 카테고리의 제품이 카트에있는 경우 경고 메시지를 표시해야합니다.

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

  •  12-12-2019
  •  | 
  •  

문제

특정 카테고리의 제품이 주문 된 경우 카트의 배송 방법 페이지에 경고 메시지를 추가해야합니다.

카테고리 ID 76에서 고객을 주문한 경우 "경고! 배달은 2-5 일 근무일보다 오래 걸릴 수 있습니다"라는 메시지가 필요합니다.나는 if 성명서가 필요하다는 것을 알고 있다는 것을 알고 있다는 것을 알고 있습니다.

////////////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
. 를 도울 수 있다면 감사합니다.

도움이 되었습니까?

해결책

ADAM, 이벤트 Observer에서 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
.

코드는 다음과 같습니다. 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 : 및 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;

            }
        }
.

귀하의 요청에 따라 이봐 요 :

편집 : 를 만듭니다

config.xml 앱 / 코드 / 로컬 / 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 앱 / 코드 / 로컬 / stackexchange / magento33614 / model 코드는 입니다

<?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 : 앱 / etc / modules / 에서 stackexchange_magento33614.xml 생성

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top