I am making rest api's for add product to cart for that I wrote this code:
public function _create(array $data) {
$id = $data['id'];
$qty = $data['qty'];
$product = Mage::getModel('catalog/product')
// load the product object
->load($data['id']);
$quote = Mage::getModel('sales/quote');
$quote->addProduct($product, $qty);
$quote->collectTotals()->save();
return json_encode(array("customer", $quote->getId()));
}
from this the product successfully adding in shopping cart(sales_flat_quote table) and it returns quote ID but I want to add this product to particular(logged in) user's cart for that I load quote from customer like this:
$customer = Mage::getModel('customer/customer')->load(21);
// Load quote by Customer
$quote = Mage::getModel('sales/quote')
->loadByCustomer($customer);
But still it is not associating with customer(in table customer ID is 0). Please let me know where I am doing wrong or I have to do more for that.