Magento Cara Menambahkan Produk ke Cart menggunakan PHP

Tutorial Magento untuk menambahkan produk ke cart menggunakan code PHP.
106  
       

Tutorial Magento untuk menambahkan produk ke cart menggunakan code PHP.

[code]
Mage::init(‘default’);
Mage::getSingleton(‘core/session’, array(‘name’ => ‘frontend’));

// Get customer session
$session = Mage::getSingleton(‘customer/session’);

// Get cart instance
$cart = Mage::getSingleton(‘checkout/cart’);
$cart->init();

// Add a product (simple); id:12, qty: 3
$cart->addProduct(12, 3);

// Add a product with custom options
$productInstance = Mage::getModel(‘catalog/product’)->load($productId);
$param = array(
‘product’ => $productInstance->getId(),
‘qty’ => 1,
‘options’ => array(
234 => ‘A value’ // Custom option with id: 234
)
);
$request = new Varien_Object();
$request->setData($param);
$cart->addProduct($productInstance, $request);

// Set shipping method
$quote = $cart->getQuote();
$shippingAddress = $quote->getShippingAddress();
$shippingAddress->setShippingMethod(‘flatrate_flatrate’)->save();

// update session
$session->setCartWasUpdated(true);

// save the cart
$cart->save();
[/code]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>