È necessario visualizzare un messaggio di avviso se un prodotto da una determinata categoria è nel carrello
Domanda
Devo aggiungere un messaggio di avviso alla pagina dei miei metodi di spedizione nel carrello se è stato ordinato un prodotto da una determinata categoria.
Ad esempio se il nostro ordine del cliente Mobili dalla categoria ID 76 Allora ho bisogno di un messaggio per apparire dicendo "Avvertenza! La consegna potrebbe richiedere più tempo rispetto ai giorni lavorativi standard 2-5".So che avrei bisogno di una dichiarazione se so semplicemente cosa scrivere in esso o dove metterlo.
/////////// Aggiunto /////////////
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> 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
.
Grazie se puoi aiutare
Soluzione
Adamo, è possibile utilizzare Event Observer sull'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
.
Codice assomiglia a questo:
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: E 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;
}
}
Ehi, secondo la tua richiesta:
Modifica: Crea
config.xml a app / codice / locale / 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 a App / Codice / Locale / StackexChange / Magento33614 / Modello
e il codice è
.
<?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 a app / etc / moduli /
.<?xml version="1.0" ?>
<config>
<modules>
<Stackexchange_Magento33614>
<codePool>local</codePool>
<active>true</active>
</Stackexchange_Magento33614>
</modules>
</config>