Retrive Product from wishlist API in magento
This is simple api creating in magento. In this code i check the customer logged and after get product that are wishlist by the logged customer.
<?php
require_once("../../app/Mage.php");
umask(0);
Mage::app();
ini_set('display_errors', 1);
$email = $_REQUEST['email'];
$password = $_REQUEST['password'];
$productId=2;
Mage::getSingleton("core/session", array("name" => "frontend"));
$websiteId = Mage::app()->getWebsite()->getId();
$store = Mage::app()->getStore();
$customer = Mage::getModel("customer/customer");
$customer->website_id = $websiteId;
$customer->setStore($store);
try
{
$customer->loadByEmail($email);
$session = Mage::getSingleton('customer/session')->setCustomerAsLoggedIn($customer);
$session->login($email, $password);
$customerData = Mage::getModel('customer/customer')->load($session->getId())->getData();
json_encode($customerData['email']);
if($customerData['email']): /* checking db emails */
//$result['result'] = 'logged in';
//$result['getdata'] = $customerData;
$customerData = Mage::getSingleton('customer/session')->getCustomer();
$customerId = $customerData->getId();
$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customerId, true);
$wishListItemCollection = $wishlist->getItemCollection();
//$data['simple_product'] = $wishListItemCollection->getData();
$i=0;
foreach($wishListItemCollection as $item)
{
$products[$i]['id'] = $item->getId();
$products[$i]['name'] = $item->getName();
$products[$i]['price'] = $item->getPrice();
$products[$i]['image'] = (string)Mage::helper('catalog/image')->init($item, 'thumbnail');
$i++;
}
$result['wishlist_product'] =$products;
echo json_encode($result);
endif;
}
catch(Exception $e){
$result['result'] = 'Wrong Credentials! Please login First.';
echo json_encode($result);
}
?>
No comments:
Post a Comment