I have a strange problem on my test system. I'm quite new to magento and think this problem might exist, because it is a test system.
I have some products with related products. If I try to add a product to the shopping cart with it's related product(s). The related product(s) do not get added to the cart.
My first guess was a broken javascript but everything seems to be ok there. My next step was to get myself temper data for firefox. I have verified, that the PostData contains:
product = $id_of_product
related_product = $id_of_related_product
qty = $qty_of_product
Still the related product does not get added to the cart. Could this be a problem with the setup of the test system? Changing the quantities works fine for the normal product. Changing the id of the related_product to the id of another product does not add anything to the cart, too.
Thanks in advance
EDIT
Ok, as others might have the same problem I leave the original question and describe here how to debug this.
The first thing to do is to deactivate all modules in local and community. The easiest way is to temporarily rename the folders app/code/local
and app/code/community
and test if it works afterwards. If it does not work you have to search further.
If the error still persists check the post message sent to the server. An easy way to do this is to get the Tamper Data addon for firefox. If the post message does not look like the message in the picture:
The error is probably inside the JavaScript of your app/design/frontend/base/default/template/catalog/product/list/related.phtml
file. Change the path to the theme you are using.
The POSTDATA
field should contain related_product=Comma_Separated_Ids_Of_Selected_Related_Products
If everything looks good so far, the mistake is somewhere in the code of magento. How magento adds products to the cart is described in a blog post here: http://www.ecomdev.org/2012/12/12/magento-checkout-shopping-cart-flow.html
The POSTDATA is computed in app/code/core/Magento/Checkout/controllers/CartController.php
at the lines below
193 $cart->addProduct($product, $params);
194 if (!empty($related)) {
195 $cart->addProductsByIds(explode(',', $related));
196 }
Make sure the $related
variable contains the ids of your related products.
If this is the case this will lead you to app/code/core/Mage/Checkout/Model/Cart.php
where in my case the error was.
related_product=12,4,5,7