Increase product amount in shopping cart
We are selling ready made packs ( total weight 18 kg ) which is include several food products. But we want to make a special thing to our customers which they should make their packs by selecting our product range.
So that, they should make first a base pack with selected products then they can multiply this package in the checkout section.
What I want to do, modify the checkout section of magento to multiply selected products with a text field and calculate total amount by button.
Like in image...
Does开发者_JAVA技巧 anybody help me to make such a thing?
Personally I would do this with frontend code, in prototype. The reason being that you will have to modify your template anyway and your customers will need javascript enabled to get to your cart anyway.
General approach is to have the onclick for your apply button take the id.value for your quantity text box and then update everything with the quantity class in the cart page. Then have this script call the same update url as the standard update quantities button.
Here is my suggestion: in your module you create an observer listening to controller_action_predispatch_checkout_cart_index
. In your observer's method you can get the items in cart with $itemCollection = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
. now you just have to loop through this condition and set the quantity:
foreach ($itemCollection as $item) {
$item->setQty(here_the_integer_you_want);
}
edit: sorry, didn't read about the input and button.
For the input and button, you just have to edit the template (app/design/frontend/base/default/template/checkout/cart.phtml). Or, if you want tom make an independant extension, you could add them by an observer. Check out inchoo's post. This form you've just created will call your controller/action, where you can set the items quantity (so no need for an observer anymore), with the same technique I've put earlier.
Let me know if that's not clear.
HTH
精彩评论