0

please check my code cart list not coming on "postman".

<?php
ini_set("default_socket_timeout", 200);
ini_set("max_execution_time", 200);
ini_set('display_errors','On');
error_reporting(E_ALL);

if($_REQUEST['hashkey'] =='NXqXAgFZA0jiWp5t6+=lGpgWJXEkbo' AND $_REQUEST['custid'] != '' )
{

$customer = $_REQUEST['custid'];

require_once ($_SERVER['DOCUMENT_ROOT'] .'/app/Mage.php');
Mage::app();
Mage::app()->getTranslator()->init('frontend');
Mage::getSingleton('core/session', array('name' => 'frontend'));

if($customer)
{
  $items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();

foreach ($items as $item)
{
   $id= $item->getId();
   $p_id = $item->getProductId();
   if (is_null($id)) {
     $ret[$id]['id'] = "";
   }else{
     $ret[$id]['id'] = $item->getProductId();
   }

   if (is_null($item->getName())) {
     $ret[$id]['name'] = "";
   }else{
     $ret[$id]['name'] = $item->getName();
   }

   if (is_null($item->getPrice())) {
     $ret[$id]['price'] = "";
   }else{
     $ret[$id]['price'] = round($item->getPrice(),4);
   }

    $ret[$id]['cart'] = "1";

   $ret[$id]['sku'] = Mage::getModel('catalog/product')->load($p_id)->getSku();;


if (is_null($item->getQty())) {
    $ret[$id]['qty'] = "";
}else{
    $ret[$id]['qty'] = $item->getQty();
}

  $product = Mage::getModel('catalog/product')->load($p_id);
  $productimage = Mage::helper('catalog/image')->init($product, 'thumbnail');
  $ret[$id] ['image'] = (string)$productimage;
}

}
    $ret = array_values($ret);
$retfinal=array("success"=>"1" ,"message"=>"cart Items List","addtocart"=>$ret );
$result=json_encode($retfinal);
echo $result;

} else{
   $ret['success'] = "0";
   $ret['message'] = "This is error message...";
   $result=json_encode($ret);
   echo $result;   
}


?>
0

In Mage_Sales_Model_Quote class you can see the function to get customer quote by customer

/** @var Mage_Customer_Model_Customer $customer **/

$quote = Mage::getModel('sales/quote')->loadByCustomer($customer);

With customer quote you can get cart and cart items $cart->getAllVisibleItems()

  • 1
    Thanks its working – neha rani May 20 at 6:51

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.