Show error message when adding a product of price 0.

To restrict products having price zero from shopping we need to create a observer on
checkout_cart_product_add_after event such that on every add to cart it will check the
product price and then add to cart.

Create a module and in etc/config.xml define the observer under event node.

Here Our module name is zeroprice under Letsknowit namespace.

File path : app/code/local/Letsknowit/zeroprice/etc/config.xml

 

       

           

               

                    singleton

                    zeroprice/observer

                    checkProductPrice

               

           

       

 

Now in Model folder we need to create observer with function name checkProductPrice.

File path : app/code/local/Letsknowit/zeroprice/Model/Observer.php

 

Class Letsknowit_Zeroprice_Model_Observer {

   

      public function checkProductPrice(Varien_Event_Observer $observer) {

        

        if ($observer->getProduct()->getFinalPrice() == 0) {

            Mage::getSingleton('core/session')->addError('Sorry, you cannot purchase "'.$observer->getProduct()->getName().'" product.Write to us if any query!'));

            $url = Mage::getModel('core/url')->getUrl('checkout/cart/index');

            Mage::app()->getResponse()->setRedirect($url);

            Mage::app()->getResponse()->sendResponse();

            exit();

        }

    }

 

}

?>

0   0
Sikha Goel
profile aliumair 14th March 2024

Please continue this great work and I look forward to more of your awesome blog posts. ac supplier

Write a comment ...
Post comment
Cancel
profile humza 10th March 2024

i am always looking for some free stuffs over the internet. there are also some companies which gives free samples.sesso fetale

Write a comment ...
Post comment
Cancel
profile khalani 20th February 2024

Excellent post. I was always checking this blog, and I’m impressed! Extremely useful info specially the last part, I care for such information a lot. I was exploring this particular info for a long time. Thanks to this blog my exploration has ended. earth tone finishes

Write a comment ...
Post comment
Cancel
profile khalani 19th February 2024

Keukenpunt is your pathway to a beautiful, affordable kitchen. Our personalized approach ensures your kitchen becomes the central hub of your home. Quality and service are our hallmarks, making us the best choice for your new kitchen. Discover the joy of cooking with us. Leeuwarden keukens

Write a comment ...
Post comment
Cancel
profile humza 14th February 2024

I found your this post while searching for some related information on blog search...Its a good post..keep posting and update the information.https://vnwin79.com/

Write a comment ...
Post comment
Cancel
profile khalani 14th February 2024

Keep up the good work , I read few posts on this web site and I conceive that your blog is very interesting and has sets of fantastic information. xo88

Write a comment ...
Post comment
Cancel
profile humza 10th February 2024

Elevate your Gangnam visit with our massage recommendation guide. Uncover diverse options for your well-being and reserve your preferred treatment. Enjoy a seamless experience in the heart of Gangnam's vibrant scene.다오안마

Write a comment ...
Post comment
Cancel
profile mehmood 30th January 2024

TrustShield Oasis, an oasis of trust in the Toto world. Our 2023 members cherish the commitment to security, making it a recommended choice. Revel in the excitement of betting, knowing that your safety is our top priority..토토사이트 추천

Write a comment ...
Post comment
Cancel
profile khalani 29th January 2024

Your work is truly appreciated round the clock and the globe. It is incredibly a comprehensive and helpful blog. Structured Network Cabling Services

Write a comment ...
Post comment
Cancel
profile mehmood 25th January 2024

A very excellent blog post. I am thankful for your blog post. I have found a lot of approaches after visiting your post.thiên đường trò chơi

Write a comment ...
Post comment
Cancel
profile mehmood 25th January 2024

Delight your taste buds and mind with Psilocybin Chocolate in Australia. Experience the magic in every bite as you indulge in the rich flavors of our premium chocolate infused with psychedelic properties. Shipped discreetly for a seamless experience..magic mushroom kit australia

Write a comment ...
Post comment
Cancel
profile Jewel Galore 22nd January 2024

Jewelgalore is your premier destination for online Pakistani jewelry . Explore their exquisite collection and adorn yourself with intricately designed pieces that reflect the cultural richness and artistry of Pakistan.

Write a comment ...
Post comment
Cancel
profile Shalamar Hospital 22nd January 2024

Shalamar Hospital is your destination for top neurological care in Lahore, with the  best neurologist in Lahore  providing expert consultations and treatments.

Write a comment ...
Post comment
Cancel
profile OSH 22nd January 2024

Osh University and  national state university are committed to shaping the future of medical professionals in Kyrgyzstan. Their partnership provides an excellent platform for students to excel in the healthcare field.

Write a comment ...
Post comment
Cancel
profile Ammara 13th January 2024

Discover unique and elegant velvet kaftan designs by Ammara Khan. Browse our collection of Pakistani velvet dresses and velvet kaftans for a truly luxurious and stylish look.

Write a comment ...
Post comment
Cancel

Please rotate your device

We don't support landscape mode on your device. Please rotate to portrait mode for the best view of our site