0
$appEmulation = Mage::getSingleton("core/app_emulation");
$initialEnvironmentInfo =   $appEmulation->startEnvironmentEmulation($storeId);
$customer = Mage::getModel("customer/customer")->load($customerId)->setStoreId($storeId);
Mage::getSingleton("customer/session")->setCustomer($customer);
$cart = Mage::getSingleton("checkout/cart");

//params can have any value from following

$params = array("related_product" => null, "links" => $links, "options" => $paramOption, "qty" => $qty, "product" => $productId);
OR
$params = array("related_product" => null, "super_group" => $super_group, "product" => $productId);
        OR
$params = array("related_product" => null, "super_attribute" => $super_attribute, "options" => $paramOption, "qty" => $qty, "product" => $productId);
        OR
$params = array("related_product" => null, "bundle_option" => $bundle_option, "bundle_option_qty" => $bundle_option_qty, "options" => $paramOption, "qty" => $qty, "product" => $productId);
        OR
$params = array("related_product" => null, "options" => $paramOption, "qty" => $qty, "product" => $productId);

$cart->addProduct($product, $params);
$cart->save();
Mage::getSingleton("checkout/session")
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);

i tried this code but it isn't seems to work, there is something else that have to be set in checkout session before adding product to cart.

Please Help.

4
  • Please specify version of magento? – amit_game Aug 14 '15 at 7:21
  • my magento version is 1.9.0.2 – Mojo Jojo Aug 14 '15 at 10:39
  • go through your code and tried your first params, its working fine on 1.9.1.0 ver, is there is any error message? – amit_game Aug 14 '15 at 10:44
  • product got added to cart but with price equal to 0 – Mojo Jojo Aug 17 '15 at 12:40

Your Answer

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

Browse other questions tagged or ask your own question.