The best way to access Magento shopping cart data and get items information. Get products id, name, price, quantity, etc. present in your cart. Get number of items in cart and total quantity in cart. Get base total price and grand total price of items in cart.Let see Code
<?php require_once 'app/Mage.php'; Mage::app('default'); Mage::getSingleton("core/session", array("name" => "frontend")); $cartdetails=Mage::getSingleton('checkout/session')->getQuote(); $i=0; $productMediaConfig = Mage::getModel('catalog/product_media_config'); $numcart= count($cartdetails->getAllItems()); if($numcart>0) { //foreach ($cartdetails->getAllItems() as $item) { foreach ($cartdetails->getAllItems() as $item) { //$cartid=$item->getId(); $productid=$item->getProductId(); $product2 = Mage::getModel('catalog/product')->load($item->getProductId()); $productname=$item->getProduct()->getName(); $productsku=$item->getProduct()->getSku(); $productimageurl=$productMediaConfig->getMediaUrl($product2->getThumbnail()); $productqty=Mage::getModel('checkout/cart')->getQuote()->getItemsQty(); $productprice=$item->getProduct()->getPrice(); $currency_code = Mage::app()->getStore()->getCurrentCurrencyCode(); if (Mage::helper('tax')->displayCartPriceInclTax() || Mage::helper('tax')->displayCartBothPrices()): $_incl = $this->helper('checkout')->getPriceInclTax($item); $specialproductprice=Mage::helper('checkout')->formatPrice($_incl- $item->getWeeeTaxDisposition()); else: $specialproductprice=$final_price= $item->getPrice(); endif; $itemsubtotal=$item->getProduct()->getSubtotal(); $itemDetail[$i]=array("productId"=>$productid,"productName"=>$productname,"productSku"=>$productsku,"productQty"=>$item->getQty(),"productPrice"=>$productprice,"currencyCode"=>$currency_code,"specialProductPrice"=>$specialproductprice,"productImageUrl"=>$productimageurl); //print_r($itemDetail); $i++; } // Total items added in cart $totalitems = Mage::getModel('checkout/cart')->getQuote()->getItemsCount(); // Total Quantity added in cart $totalquantity = Mage::getModel('checkout/cart')->getQuote()->getItemsQty(); // Sub Total for item added in cart $subtotal = Mage::getModel('checkout/cart')->getQuote()->getSubtotal(); //grand total for for item added in cart $grandtotal = Mage::getModel('checkout/cart')->getQuote()->getGrandTotal(); $data['responseCode']='1'; $data['msg']='successful'; $data['itemResponse']=$itemDetail; $data['totalItems']=$totalitems; $data['totalQuantity']=$totalquantity; $data['subTotal']=$subtotal; $data['grandTotal']=$grandtotal; //$data['quoteId']=$quotid; } else { $data['responseCode']='0'; $data['msg']='No items found'; } $data2 = json_encode($data); echo $data2; ?>
1 comments:
The blog was absolutely fantastic! Lot of great information which can be helpful in some or the other way. Keep updating the blog, looking forward for more contents...Great job, keep it up..
magento development company in bangalore
EmoticonEmoticon