Magento – Is it possible to pass some custom values as parameter while adding products to the cart

cartmagento-1.9

Please see the code that we use to add product to the cart.

$product = Mage::getModel('catalog/product')->load($productId);
$cart = Mage::getModel('checkout/cart');
$cart->init();
$result = $cart->addProduct($product, array('qty' => quantity);
$cart->save();

While adding the product to the cart i need to add some additional information along with the products details so that it can be accessed from the shipping module. For example is it possible to do something like this?

$result = $cart->addProduct($product, array('qty' => quantity,'s_class'=>'next');

I have added a variable s_class and its value in the parameter array. Is it possible to do this so that i can get the value for the s_class in the shipping module?
I tried above code, there is no error while adding the product to the cart.

But not sure how to access the same from the shipping module.

Are there any alternative ways to achieve this ie adding some values with the products while adding it to the cart the and get the same in shipping module?

Best Answer

You can try this with custom options & add custom option values this way:

 $params = array(
    'product' => $productId,
    'qty'     => 1,
    'options' => array(
        $optionId => $optinValueId,
        )
);

$result = $cart->addProduct($product,$params);
Related Topic