Add Product to wishlist API in magento
<?php
require_once("../../app/Mage.php");
umask(0);
Mage::app();
ini_set('display_errors', 1);
/*code for login*/
$email = $_REQUEST['email'];
$password = $_REQUEST['password'];
$productId=$_REQUEST['product_id'];
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);
$product = Mage::getModel('catalog/product')->load($productId);
$buyRequest = new Varien_Object(array());
$result = $wishlist->addNewItem($product, $buyRequest);
$wishlist->save();
echo json_encode($result);
echo 'product add to wishlist..';
//echo json_encode($customerData);
else:
$result['result'] = 'Wrong Credentials! Please login First.';
echo json_encode($result);
endif;
}
catch(Exception $e){
$result['result'] = 'Wrong Credentials! Please login First.';
echo json_encode($result);
}
?>
<?php
require_once("../../app/Mage.php");
umask(0);
Mage::app();
ini_set('display_errors', 1);
/*code for login*/
$email = $_REQUEST['email'];
$password = $_REQUEST['password'];
$productId=$_REQUEST['product_id'];
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);
$product = Mage::getModel('catalog/product')->load($productId);
$buyRequest = new Varien_Object(array());
$result = $wishlist->addNewItem($product, $buyRequest);
$wishlist->save();
echo json_encode($result);
echo 'product add to wishlist..';
//echo json_encode($customerData);
else:
$result['result'] = 'Wrong Credentials! Please login First.';
echo json_encode($result);
endif;
}
catch(Exception $e){
$result['result'] = 'Wrong Credentials! Please login First.';
echo json_encode($result);
}
?>
No comments:
Post a Comment