0

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);
$cart->save();

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

Array
(
[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.

2

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.

1

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()) {
            $this->_goBack();
            return;
        }
        $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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.