473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Magento Own Custom Module for add-to-cart Not Working

aveeva
33
Created module like No other products add to cart if restricted product available in cart and vice versa.

My Module :

app/etc/modules/Brst_Test.xml



Expand|Select|Wrap|Line Numbers
  1.  
  2. <?xml version="1.0"?>
  3. <config>
  4.     <modules>
  5.         <Brst_Test>
  6.             <active>true</active>
  7.             <codePool>community</codePool>
  8.         </Brst_Test>
  9.     </modules>
  10. </config>
  11.  

This is my observer file

app/code/community/Brst/Test/Model/Observer.php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. ini_set('display_errors', '1');
  3.  
  4. // Mage::log('Hy observer called', null, 'logfile.log');
  5. class Brst_Test_Model_Observer
  6. {
  7.     //Put any event as per your requirement
  8.     public function logCartAdd() {
  9.         $product = Mage::getModel('catalog/product')
  10.                         ->load(Mage::app()->getRequest()->getParam('product', 0));
  11.         $cart_qty = (int) Mage::getModel('checkout/cart')->getQuote()->getItemsQty();
  12.  
  13.         if ($product->getId()==31588 && cart_qty > 0) {
  14.             Mage::throwException("You can not add This special Product, empty cart before add it");
  15.         }
  16.  
  17.         // $quote = Mage::getSingleton('checkout/session')->getQuote();
  18.         // if ($quote->hasProductId(2)) 
  19.         //{
  20.         //  Mage::getSingleton("core/session")->addError("Cart has Special Product you can not add another");
  21.         //  return;
  22.         // }
  23.         $quote = Mage::getModel('checkout/cart')->getQuote();
  24.         foreach ($quote->getAllItems() as $item) {
  25.             $productId = $item->getProductId();
  26.             if($productId==31588){
  27.                 Mage::throwException("Cart has Special Product you can not add another");
  28.             }
  29.         }
  30.  
  31.     }
  32. }
  33. ?>
  34.  
app/code/community/Brst/Test/etc/config.xml

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <config>
  3.     <modules>
  4.         <Brst_Test>
  5.            <version>0.1.0</version>
  6.         </Brst_Test>
  7.     </modules>
  8.     <global>
  9.         <models>
  10.             <brst_test>
  11.                 <class>Brst_Test_Model</class>
  12.             </brst_test>
  13.         </models>
  14.     </global>
  15.     <frontend>
  16.         <events>
  17.             <controller_action_predispatch_checkout_cart_add>
  18.                 <observers>
  19.                     <brst_test_log_cart_add>
  20.                         <class>brst_test/observer</class>
  21.                         <method>logCartAdd</method>
  22.                     </brst_test_log_cart_add>
  23.                 </observers>
  24.             </controller_action_predispatch_checkout_cart_add>
  25.         </events>
  26.     </frontend>
  27. </config>
  28.  
Not working, how to solve the error?
Jun 27 '19 #1
3 1049
zmbd
5,501 Expert Mod 4TB
Not working, how to solve the error?
Why don't you invest a bit of time telling us exactly what it is that you are trying to do, what it is that you have tried to troubleshoot your own code, what it is that the code is doing when you attempt to execute it, and what errors are you receiving and when you are receiving those errors!

Posting a bunch of code and asking us to "fix it / Make it work for me" really isn't what we do here.
Jun 28 '19 #2
aveeva
33
I am new for Magento, I just created the module like if restricted products available in the cart no other products allow to adding to cart and vice versa, i am not asking full code, actually i give my complete code, i post because of atleast i am getting an idea for solving my issue. New people getting struggle initially developing module right?
Jun 28 '19 #3
zmbd
5,501 Expert Mod 4TB
Yes, Aveeva, new users struggle, I've been there myself and have received a great deal of help from a lot of places - especially here at Bytes.com :)

Even with that said, there are certain minimums that one needs to have in a question - I've stated those in my prior post.

If you had asked for code the thread would have been deleted.

As your post stands now, you've asked for someone to do the work for you - which isn't going to help you learn.

Please re-read my prior post and answer the questions - I think this thread is salvageable if you will do so or I would have closed and removed it.
Jun 28 '19 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Scott David Daniels | last post by:
I've been working on a module to get at the bits of all numeric types (no, I haven't thought of how to solve the decimal data type that is coming). I've finally got the bits module to pass all of...
15
by: john fabiani | last post by:
Hi, newbie question: PyPgSQL (postgres driver) returns a list (not a tuple O'Rielly states DBAPI returns a tuple) and most of the books describe how to work with tuples and dictionaries when...
6
by: | last post by:
Hi, I added dotnetfx.exe to a setup project as a custom action to be installed before the main app is installed. I set the Arguments property to /q:a /c:"install /l /q" for a silent install...
9
by: Nick | last post by:
the customError feature is not working. I have it setup as the help says in my web.config file. <customErrors defaultRedirect="DsAppError.aspx" mode="RemoteOnly"/> I tried in a couple...
4
by: Dmitry Duginov | last post by:
Hi, Can anybody recommend a custom module for DotnetNuke, implementing different kinds of surveys? The standard "Survey" module is too simple and it doesn't cover different real life scenarios....
2
by: xenophon | last post by:
I am trying to format datetime output with an HTTP Module. Right now dates are displaying in US format like "MM/DD/YYYY 12:00:00". I want to change the output to "MM/DD/YYYY" if US or "DD.MM.YYYY"...
1
by: Elie Medeiros via .NET 247 | last post by:
Hi there, I have written a custom validator function to validate a datefrom a user-filled field. The function tries to parse the dateand if it can't, sets (serverValidateEventArgs)e.IsValid...
0
by: Umut Tezduyar | last post by:
This post is related with .Net 1.1. I have written my custom module by inheriting IHttpModule. I realized that, at the first compile, framework creates the instance of my module and then caches...
2
by: Raf256 | last post by:
Hello, my custom streambuf works fine with output via << and with input via .get() but fails to input via >> or getline... any idea why? -------------------- A custom stream buffer (for...
1
by: Alan Silver | last post by:
Hello, I am writing a page that makes use of a lot of custom validators. So far, all the custom client-side validation code has been added in the <head> tag of the page, but I decided to move it...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.