cross-sell products are not getting added while doing add to cart

Error: You cannot define a correlation name 'store_table' more than once in Magento 2
Magento cart - get the bundle parent and children product

In the product page cross-sell products are showing with checkboxes.
When I check some checkboxes and then click “add to cart” then the product along with the checked cross-sell products should added to the cart.
But only the product is getting added to the cart except the checked crosssell product.
I found that the code for adding product is written in
app/code/core/Mage/Checkout/cotrollers/CartController.php -->addAction()
Inside it some code is as follows..

$cart   = $this->_getCart();
$params = $this->getRequest()->getParams();
echo "<pre>";print_r($params);echo "</pre>";exit;
$cart->addProduct($product, $params);

when I tried to print the $params then following parameters came..

[uenc] => aHR0cDovL2Frc2hheWEuYWZpehyuSDepYS5jb20vcG9zdGJveGVzL3N0yu76ygEtbWljcm8tcG93ZXJsb2NrLTNtLTEwZnQtMC0zMy01MjM,
[product] => 19
[checkboxes] => Array
        [0] => 534
        [1] => 222

[qty] => 1
[related_product] => 

Is it a wrong format of $params ?
If no, then why only 19 is getting saved and 534 and 222 is not getting added ?

i.e. it is getting the crosssell product ids but not adding it.
Could anyone suggest what should be the right way to add $params ?
Thank you.

Related Posts

Error: You cannot define a correlation name 'store_table' more than once in Magento 2
Magento cart - get the bundle parent and children product

2 Comments on this article

  • User November 12, 2016

    In default Magento, cross-sell products are not supposed to be added to cart from product page along with the main product. That said, you can change your template file to mimic as cross-sell products like related products. For that you can try with just changing the name attribute in checkboxes. Change it from ‘checkboxes’ to ‘related_product’ and see if it resolves the issue.


  • User November 12, 2016

    Try to change your related products checkbox name to related_product, Magento used this parameter in Mage_Checkout_CartController addAction() method. See below code:

    public function addAction()
            if (!$this->_validateFormKey()) {
            $cart   = $this->_getCart();
            $params = $this->getRequest()->getParams();
            try {
                if (isset($params['qty'])) {
                    $filter = new Zend_Filter_LocalizedToNormalized(
                        array('locale' => Mage::app()->getLocale()->getLocaleCode())
                    $params['qty'] = $filter->filter($params['qty']);
                $product = $this->_initProduct();
                $related = $this->getRequest()->getParam('related_product');    // Related product items

    And in your case related products checkbox name is checkbox instead related_product. It should work once you change checkbox name.


Add a comment

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax