<?php
include 'app/Mage.php';
Mage::app();
// Need for start the session
Mage::getSingleton('core/session', array('name' => 'frontend'));
try {
$product_id = '389';
$product = Mage::getModel('catalog/product')->load($product_id);
$cart = Mage::getModel('checkout/cart');
$cart->init();
$params = array(
'product' => $product_id,
'super_attribute' => array(
1102 => 351,
),
'qty' => 1,
);
$cart->addProduct($product, $params);
$cart->save();
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
Mage::getSingleton('core/session')->addSuccess('Product added successfully');
header('Location: ' . 'index.php/checkout/cart/');
} catch (Exception $e) {
echo $e->getMessage();
}
?>
Monday, January 2, 2017
How to add to cart configurable product in magento programmatically ?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment