Magento Addto cart operation - php

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

Related

How to customize cart item in magento

How can we customize cart items in magento. I have used custom options but it is not working as intended. All I need is to show some configurable data in cart page and in order page.
Can some one help how can I achieve it.
Edit: To elaborate, along with cart item, type and qty. I want to display supporting text for each item type. I got it working with custom options, but I had to include qty inside custom options which created an issue on cart page during cart update. Now I am looking for some other way by which I can acheive same thing.
Thanks
According to your question, you are trying to edit the product that are in the cart. Hope i am getting you right. For this you just need to have a look at the file default.phtml in
app/design/frontend/base/default/template/checkout/cart/item/default.phtml
This phtml file is responsible for displaying the item in the cart. Here you can get the custom options of the product as well. You can edit as per your requirement.
But remember before you edit copy this file to your theme because this is the best practice not to edit the magento's core files.
Hope this will help.

magento add extra product to cart automatically

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();

Magento require coupon to purchase product

After searching on Google for quite a while I am going crazy.
My question: Can you configure Magento to require a coupon code to buy specific product?
This is for a promotion my employer is running, basically we want to allow specific customers to buy specific product in our Magento store before any of our other customers. Thank you for your suggestions.
A brief idea I can give here.
Create a backend module, which has own db tables to save linking of products ID to specific coupon, multiple coupon or just a check that coupon is required, depending on your case. From this Module you should be able to define such linking of product to coupon.
Since customer apply a coupon code at cart page, so we will let customer add product into cart. Then edit isDisabled method of Mage_Checkout_Block_Onepage_Link class. where you will check if your quote has any product from the product-coupon linking defined in your module and coupon is not applied yet. Similar thing you can should do for Multishipping method if it is enabled in your Magento. So whenever coupon coupon code will be applied page will refresh and button will get enabled.
Same check you will need to put in indexAction of Mage_Checkout_OnepageController.

Prestashop Product customizer

I have an application which is a T-Shirt customizer which works very good on it's own. But I need to integrate it into prestashop. So after a user uses the application to customize a t-shirt he has to click Add to cart and the product will be added to cart with a custom price and description.
What I need is for this output to be injected into the PrestaShop cart as a custom product with all the custom information and also the generated custom product image to display next to the details in the cart.
So I have the customizer done, I have allready made a custom module and page for Prestashop but I don't know how to integrate it with the cart. My prestashop knowledge is limited.
How can I do this?
When you use this code in CartController.php
$this->context->cart->addTextFieldToProduct($this->id_product, $r["id_customization_field"], Product::CUSTOMIZE_TEXTFIELD, Tools::getValue('product_description'));
then you only save your custom-description in a customization field. But how do you change the price for this customization?
Of course you have to override getPriceStatic method in product.php file to recalculate the custom price. But there is also another problem: what if the customer add same product into the cart but with a different customization and also a different custom price?
Different customization-text is handeled by your used method and is therefor added correctly to the cart, but the different price calculation just overwrites the first custom price because both customizations are associated with the same product.
I did something similar. Here's how I dealt with it.
My module works on its own. I stored customization in the database via object model from the customizer module. Each customization have an ID.
Prestashop offers customization for each products. I hide it from the customer on the prodct page but I use it to store the ID of the customization. That way, you can see in the cart the customization ID for each customized product.
I used _addCustomization method in the Cart object to store the customization ID. Here's a small example:
$context = Context::getContext();
$result = $context->cart->_addCustomization($id_product, $id_product_attribute, 1, 1, $id_customization, 1);
Hope I'm clear enough.
Does this help you out?

Custom Add to Cart

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'

Categories