0

I just want to display my event name :

app\etc\modules\Gta_RestrictProductByCountry.xml

<?xml version="1.0"?>

<config>

    <modules>

        <Gta_RestrictProductByCountry>

            <codePool>local</codePool>
            <active>true</active>

        </Gta_RestrictProductByCountry>

    </modules>

</config>

app\code\local\Gta\RestrictProductByCountry\etc\config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Gta_RestrictProductByCountry>
            <version>1.0.0</version>
        </Gta_RestrictProductByCountry>
    </modules>
    <global> 
        <models>
            <gta_restrictproductbycountry>
                <class>Gta_RestrictProductByCountry_Model</class>
            </gta_restrictproductbycountry>
        </models> 
     </global> 
    <frontend>
        <events>
            <!-- <sales_order_place_before> -->
            <checkout_cart_product_add_after>
                <observers>
                    <gta_restrictproductbycountry_observer>   
                        <type>singleton</type>
                        <class>gta_restrictproductbycountry/observer</class>
                        <method>cartevent</method>
                    </gta_restrictproductbycountry_observer>
                </observers>
            <!-- </sales_order_place_before>       -->
            </checkout_cart_product_add_after>      
        </events>
    </frontend>

</config>

app\code\local\Gta\RestrictProductByCountry\Model\Observer.php

<?php
class Gta_RestrictProductByCountry_Model_Observer
{
    public function cartevent($Observer)
    {

        $cart_product_check = $Observer->getEvent();
        Mage::log($cart_product_check->getName(), null, 'orderproduct.log',true);
    }
}
2
  • what is the issue - i mean event is not working ? Oct 14, 2019 at 6:36
  • Yes, after placed an order 'orderproduct.log' not generated in var/log
    – zus
    Oct 14, 2019 at 6:37

2 Answers 2

0

Please try update below code :

<checkout_cart_product_add_after>
                <observers>
                    <gta_restrictproductbycountry_observer>   
                        <type>singleton</type>
                   <class>gta_restrictproductbycountry/observer</class>
                        <method>cartevent</method>
                    </gta_restrictproductbycountry_observer>
                </observers>
            </checkout_cart_product_add_after> 

app\code\local\Gta\RestrictProductByCountry\Model\Observer.php

<?php
class Gta_RestrictProductByCountry_Model_Observer
{
    public function cartevent($Observer)
    {

        $cart_product_check = $Observer->getEvent();
        Mage::log($cart_product_check->getName(), null, 'orderproduct.log',true);
    }
}
5
  • Pls check with my updated post, still 'orderproduct.log' not generated under var/log @Anas Mansuri
    – zus
    Oct 14, 2019 at 7:05
  • can you please replace with - <gta_restrictproductbycountry_observer> Oct 14, 2019 at 7:06
  • Still no luck, orderproduct.log not generated.
    – zus
    Oct 14, 2019 at 7:17
  • pls check with my updated post
    – zus
    Oct 14, 2019 at 7:19
  • please check i update my answer Oct 14, 2019 at 7:25
0

Finally done with below changes,

<frontend>
        <events>
            <!-- <sales_order_place_before> -->
            <checkout_cart_product_add_after>
                <observers>
                    <Gta_RestrictProductByCountry_Model_Observer>   
                        <type>singleton</type>
                        <class>Gta_RestrictProductByCountry_Model_Observer</class>
                        <method>cartevent</method>
                    </Gta_RestrictProductByCountry_Model_Observer>
                </observers>
            <!-- </sales_order_place_before>       -->
            </checkout_cart_product_add_after>      
        </events>
    </frontend>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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