I want to add an item to the cart, but if this item is already in the cart, Magento by default just increases the quantity of this item. I want to add a new row in the database table sales_flat_quote_item where magento saves its cart items. The reason why I want to do this is to show in the cart page the 2 or more items in different rows, for some reason.
I tried to track the flow of magento in saving the cart, but I ended up with this code: Mage::dispatchEvent('sales_quote_product_add_after', array('items' => $items));
I'm trying to find where is this method, but I cant find it. I hope that the solution that I've been searching for is here. Does anyone know where this method is located? Or, if I'm wrong with my assumption, what might be the solution to my problem?
This is the call of magento event which calls other module methods one by one that have registered for listen to that event. So you need to look every config.xml file of every module for sales_quote_product_add_after string under <events> tag. For more about events and observers in magento go to:
http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/customizing_magento_using_event-observer_method
Default magento implementation has no observers for this event and it wouldn't lead you to the solution. Check this blog post about the cart flow, especially the part entitled 'Quote Model Adds a New Item or Changes Existing One Qty'
Related
I'm currently attempting to extend the inherent Magento product view to divide the custom options belonging to a configurable product into sections loaded by ajax. The end goal is to create a step by step process guiding the user through each step of the product configuration process before they would add the product to the cart.
Advanced Custom Product Options
We are also utilizing Mageworx's Advanced Custom Product Options to allow for the larger customization of products.
Simple Products Linked to Configurable
Our current environment is set up to handle simple products as configurators for their parent configurable product. When a user navigates to the simple product, they are directed to the configurable product with the option represented by the simple product pre-selected.
End Goal
The hopeful endpoint would be that once a user clicks on a simple product, they would be redirected to the configurable product with a single pre-selected option depending on the simple product. The user would then be able to customize their order, or jump directly to adding it to the cart as is. The customization process would re-evaluate at each step to determine if there is a concurrent step, for example, if the user were to select to add trim, there would be an additional step to customize that trim, whereas if they opted out, the step would be skipped.
The idea is simply a product configurator within the Magento framework, something similar, in function, as to what appears below. The checkout steps being Style, Color, and Size, each which have their own page.
The Overarching Question
I am fairly new to the development of Magento, and am wondering what the best method of attacking this problem is. I have thought of using an observer to hook into before add to cart, but I am unsure it would allow me to refresh the blocks and load in new data. My other idea was to tap into view.phtml and set up some ajax loading within the page itself, but that seemed a bit 'hacky'.
I have spent quite a while searching for examples on how some have overcome this problems, but haven't found much outside of some very vague ideas on what could work. If any one has insight onto a solution to my problem, their thoughts would be much appreciated.
Current Approach
So far I've tried creating a Router for a Controller to handle POST requests to change out the Product Option sidebar when a value is changed. It seems a little bit slow, however.
I want to add products automatically to my magento cart.
The situation is I have product Y and it needs extra components to be assembled, so I want that the assembly parts to be added automatically to the cart when product Y is added.
I have googled a lot and could only find extensions for promotion product and free gifts but I need a solution which just adds the product to the cart and that it adds in the same quantity of product Y.
Are there extensions which I can use or how can I alter my code to get my desired behaviour?
You can use that kind of extension or make you own with a listener on the sales_quote_item_set_product event to check if the product added is yours and need a new product to be added.
I had a similar request that was abandonned as it is illegal in France (and in most of the part of Europe) to sell a product linked to another and that was not requested. Moreover, the customer can already have this second product and do not want it. We added a popup that said which products can be needed with this one. This second part is just an advice.
Well, if you looking programming solutions:
Write Custom module that observe event checkout_cart_add_product_complete.
In your observer, add products by following code.
The code is:
$prouctToAdd = Mage::getModel('catalog/product')->load('product_id ');
$qty = 'currently_added_produt'
$cart =Mage::getSingleton('checkout/cart');
$cart->addProduct($product, array('qty'=>$qty));
$cart->save();
Is it possible, in Magento, to build a button to add a new simple product while creating an order in the backend?
It is not important that the product would be saved in the catalog: it should to be saved into the order. Only two of the product's attributes would be needed: name and tax rate (optionally others). Qty e price could be edited from the order cart.
Yes, it's posible, you need a controller in order to do that.
Remember that you need to provide us the code that you're working on, and don't expect that we program all for you.
Thanks
Thanks to Beto Castillo I went into the spirit to think more clearly about this. The project is yet under construction. Anyway starting steps could be:
Create the right inputs to add a new product in a ChildHtml of sales/order/create/data.phtml, and adjust the layout files. Along with the inputs there will be a button to trigger the creation of the product. In one of this inputs I have to load options for tax rates.
There is plenty of ways to create a new product, i.e. Magento: Adding new products programmatically. I just need to get the above inputs.
The product should be added to order quotes in the database (I could start with this: Create order programmatically in Magento)
Update the create order view, calling an ajax function to reload the item grid. Part of the code already exists in Magento. All this steps should be packed into the same ajax call: here comes the controller action named by Beto Castillo.
So the answer is yes, it is possible.
I am doing a magento customaization site,I am new to magento . My product has model type and model version.I want to pass model type and version to cart page and checkoutpage, So i decided to store the two field in cart table where should i found the cart insertion code for magento and how can i add these two fields in cart table? please anybody help!
I have tried the below code in addAction() of Mage/checkout/controllers/cartcontroller.php to post the extra fields.
$postData = Mage::app()->getRequest()->getPost();
instead of finding the magento core code, what you can do is you can write observer for magento events. Like whenever the product added into cart or deleted from cart or if just landed to checkout page or you just placed an order... like this for each and every actions in magento there is an event generated for this... you just need to write the logic in observer what to do ...and also you are getting cart items and all the details of cart in observer object ...
following links may be helpful ...
http://www.excellencemagentoblog.com/magento-add-custom-fields-checkout-page
http://www.nicksays.co.uk/magento-events-cheat-sheet-1-7/
you can search for "events and observers in magento" in google
I'm completely new on working with Magento and I'm going to create a module in order to validate and in some cases manipulate some cart/order information.
To be specific I'm gonna restrict the customer from buying an item more than X times.
I've started working on this a bit, but I'm not so satisfied with the solution.
This is how I've done it so far:
I've created a new module with a controller which subclasses Mage_Checkout_CartController and there I've implemented the addAction-method. So every time a product is added to the cart I search through the user's order history and look for previous orders containing this product. Then I prevent it from being added and trigger an error-message.
It has a lot of shortcomings. For instance, if the customer isn't logged in at the time he can add the product, you can update the cart with too many... etc.
I would be me comfortable if I could hook on events, but I don't know where to start. Haven't found so good guides about this.
I want to do this verification when listing cart, updating cart and before submitting order.
So, my questions are:
How do I add observers on these events in my module? I couldn't get config.xml-configuration for event observing to work. I also need to know the names of these events.
How do I manipulate the quantity of an item in cart / delete it? When updating cart with too many of the products I want to change the quantity and trigger an error.
If you have any other ideas on a better solution for this, you're very welcome to comment.
I appreciate any help. Thanks.
I think this article should answer on all your questions. See events list at the bottom of this article. Do not forget delete cache after each change made to config.xml and other xml files in your module etc folder.