/*add wishlist*/
<?php
require_once("../../app/Mage.php");
umask(0);
Mage::app();
ini_set('display_errors', 1);
$customerId=$_REQUEST['customer_id'];
$productId=$_REQUEST['product_id'];
$custid_ln=strlen($customerId);
$prod_ln=strlen($productId);
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);
/* for count the product is already added in wishlist*/
$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customerId, true);
$wishListItemCollection = $wishlist->getItemCollection();
$j=0;
foreach($wishListItemCollection as $item)
{
$product = $item->getProduct();
$prod_id[$i]=$product->getId();
if($prod_id[$i]==$productId)
{
$j++;
}
}
/*for check product id availabel or not */
$_productCollection = Mage::getModel('catalog/product')
->getCollection();
$pc=0;
foreach($_productCollection as $item)
{
$prod[$i]=$item->getId();
if($prod[$i]==$productId)
{
$pc++;
break;
}
}
/*for checking customer id availabel or not */
$collection = mage::getModel('customer/customer')->getCollection();
$c=0;
foreach($collection as $item)
{
$custId[$i]=$item->getId();
if($custId[$i]==$customerId)
{
$c++;
break;
}
}
if($custid_ln<=0)
{
$result['status']='failier';
$result['add_wishlist']='Customer Id should not be empty!';
}else if($c<=0)
{
$result['status']='failier!';
$result['add_wishlist']='Customer Id not exit!';
}else if($prod_ln<=0)
{
$result['status']='failier!';
$result['add_wishlist']='product Id should not be empty!';
}else if($pc<=0){
$result['status']='failier!';
$result['add_wishlist']='Product Id not exit!';
}else if($j>0){
$result['status']='failier!';
$result['add_wishlist']='This product already added to wishlist!';
}else{
$customer = Mage::getModel('customer/customer');
$wishlist = Mage::getModel('wishlist/wishlist');
$product = Mage::getModel('catalog/product');
$customer->load($customerId);
$wishlist->loadByCustomer($customerId);
$wishlist->addNewItem($product->load($productId));
if($wishlist->save())
{
$result['status']='success!';
$result['add_wishlist']='Product add to wishlist!';
}
}
echo json_encode($result);
?>
/*Rerive wishlist*/
<?php
require_once("../../app/Mage.php");
umask(0);
Mage::app();
ini_set('display_errors', 1);
$customerId=$_REQUEST['customer_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);
$collection = mage::getModel('customer/customer')->getCollection();
$c=0;
foreach($collection as $item)
{
$custId[$i]=$item->getId();
if($custId[$i]==$customerId)
{
$c++;
break;
}
}
if($c<=0)
{
$result['status']='failier!';
$result['wishlist_product'] ='Customer id not exit!';
}else
{
$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customerId, true);
$wishListItemCollection = $wishlist->getItemCollection();
$i=0;
foreach($wishListItemCollection as $item)
{
$product = $item->getProduct();
$products[$i]['id'] = $product->getId();
$products[$i]['name'] = $item->getName();
$products[$i]['price'] = $item->getPrice();
$products[$i]['image'] = (string)Mage::helper('catalog/image')->init($item, 'thumbnail');
$i++;
}
$result['status']='success!';
$result['wishlist_product'] =$products;
}
if($i<=0)
{
$result['status']='success!';
$result['wishlist_product']=array();
}
echo json_encode($result);
?>
/*Remove wishlist*/
<?php
require_once("../../app/Mage.php");
umask(0);
Mage::app();
ini_set('display_errors', 1);
$customerId=$_REQUEST['customer_id'];
$productId=$_REQUEST['product_id'];
$custid_ln=strlen($customerId);
$prod_ln=strlen($productId);
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);
$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customerId, true);
$wishListItemCollection = $wishlist->getItemCollection();
$j=0;
foreach($wishListItemCollection as $item)
{
$product = $item->getProduct();
$prod_id[$i]=$product->getId();
if($prod_id[$i]==$productId)
{
$j++;
}
}
$_productCollection = Mage::getModel('catalog/product')
->getCollection();
$pc=0;
foreach($_productCollection as $item)
{
$prod[$i]=$item->getId();
if($prod[$i]==$productId)
{
$pc++;
break;
}
}
$collection = mage::getModel('customer/customer')->getCollection();
$c=0;
foreach($collection as $item)
{
$custId[$i]=$item->getId();
if($custId[$i]==$customerId)
{
$c++;
break;
}
}
if($custid_ln<=0)
{
$result['status']='failier!';
$result['remove_wishlist']='Customer Id should not be empty!';
}else if($c<=0)
{
$result['status']='failier!';
$result['remove_wishlist']='Customer Id not exit!';
}else if($prod_ln<=0)
{
$result['status']='failier!';
$result['remove_wishlist']='product Id should not be empty!';
}else if($pc<=0){
$result['status']='failier!';
$result['remove_wishlist']='Product Id not exit!';
}else if($j<=0){
$result['status']='failier!';
$result['remove_wishlist']='Product not available in wishlist!';
}else{
$itemCollection = Mage::getModel('wishlist/item')->getCollection()
->addCustomerIdFilter($customerId);
foreach($itemCollection as $item) {
$pid= $item->getProduct()->getId();
if($pid == $productId){
$item->delete();
$result['status']='success!';
$result['remove_wishlist']='Product remove from wishlist!';
}
}
}
echo json_encode($result);
?>
//for register
->setIsDefaultBilling('1')
->setIsDefaultShipping('1')
->setSaveInAddressBook('1')
<?php
require_once("../../app/Mage.php");
umask(0);
Mage::app();
ini_set('display_errors', 1);
$customerId=$_REQUEST['customer_id'];
$productId=$_REQUEST['product_id'];
$custid_ln=strlen($customerId);
$prod_ln=strlen($productId);
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);
/* for count the product is already added in wishlist*/
$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customerId, true);
$wishListItemCollection = $wishlist->getItemCollection();
$j=0;
foreach($wishListItemCollection as $item)
{
$product = $item->getProduct();
$prod_id[$i]=$product->getId();
if($prod_id[$i]==$productId)
{
$j++;
}
}
/*for check product id availabel or not */
$_productCollection = Mage::getModel('catalog/product')
->getCollection();
$pc=0;
foreach($_productCollection as $item)
{
$prod[$i]=$item->getId();
if($prod[$i]==$productId)
{
$pc++;
break;
}
}
/*for checking customer id availabel or not */
$collection = mage::getModel('customer/customer')->getCollection();
$c=0;
foreach($collection as $item)
{
$custId[$i]=$item->getId();
if($custId[$i]==$customerId)
{
$c++;
break;
}
}
if($custid_ln<=0)
{
$result['status']='failier';
$result['add_wishlist']='Customer Id should not be empty!';
}else if($c<=0)
{
$result['status']='failier!';
$result['add_wishlist']='Customer Id not exit!';
}else if($prod_ln<=0)
{
$result['status']='failier!';
$result['add_wishlist']='product Id should not be empty!';
}else if($pc<=0){
$result['status']='failier!';
$result['add_wishlist']='Product Id not exit!';
}else if($j>0){
$result['status']='failier!';
$result['add_wishlist']='This product already added to wishlist!';
}else{
$customer = Mage::getModel('customer/customer');
$wishlist = Mage::getModel('wishlist/wishlist');
$product = Mage::getModel('catalog/product');
$customer->load($customerId);
$wishlist->loadByCustomer($customerId);
$wishlist->addNewItem($product->load($productId));
if($wishlist->save())
{
$result['status']='success!';
$result['add_wishlist']='Product add to wishlist!';
}
}
echo json_encode($result);
?>
/*Rerive wishlist*/
<?php
require_once("../../app/Mage.php");
umask(0);
Mage::app();
ini_set('display_errors', 1);
$customerId=$_REQUEST['customer_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);
$collection = mage::getModel('customer/customer')->getCollection();
$c=0;
foreach($collection as $item)
{
$custId[$i]=$item->getId();
if($custId[$i]==$customerId)
{
$c++;
break;
}
}
if($c<=0)
{
$result['status']='failier!';
$result['wishlist_product'] ='Customer id not exit!';
}else
{
$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customerId, true);
$wishListItemCollection = $wishlist->getItemCollection();
$i=0;
foreach($wishListItemCollection as $item)
{
$product = $item->getProduct();
$products[$i]['id'] = $product->getId();
$products[$i]['name'] = $item->getName();
$products[$i]['price'] = $item->getPrice();
$products[$i]['image'] = (string)Mage::helper('catalog/image')->init($item, 'thumbnail');
$i++;
}
$result['status']='success!';
$result['wishlist_product'] =$products;
}
if($i<=0)
{
$result['status']='success!';
$result['wishlist_product']=array();
}
echo json_encode($result);
?>
/*Remove wishlist*/
<?php
require_once("../../app/Mage.php");
umask(0);
Mage::app();
ini_set('display_errors', 1);
$customerId=$_REQUEST['customer_id'];
$productId=$_REQUEST['product_id'];
$custid_ln=strlen($customerId);
$prod_ln=strlen($productId);
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);
$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customerId, true);
$wishListItemCollection = $wishlist->getItemCollection();
$j=0;
foreach($wishListItemCollection as $item)
{
$product = $item->getProduct();
$prod_id[$i]=$product->getId();
if($prod_id[$i]==$productId)
{
$j++;
}
}
$_productCollection = Mage::getModel('catalog/product')
->getCollection();
$pc=0;
foreach($_productCollection as $item)
{
$prod[$i]=$item->getId();
if($prod[$i]==$productId)
{
$pc++;
break;
}
}
$collection = mage::getModel('customer/customer')->getCollection();
$c=0;
foreach($collection as $item)
{
$custId[$i]=$item->getId();
if($custId[$i]==$customerId)
{
$c++;
break;
}
}
if($custid_ln<=0)
{
$result['status']='failier!';
$result['remove_wishlist']='Customer Id should not be empty!';
}else if($c<=0)
{
$result['status']='failier!';
$result['remove_wishlist']='Customer Id not exit!';
}else if($prod_ln<=0)
{
$result['status']='failier!';
$result['remove_wishlist']='product Id should not be empty!';
}else if($pc<=0){
$result['status']='failier!';
$result['remove_wishlist']='Product Id not exit!';
}else if($j<=0){
$result['status']='failier!';
$result['remove_wishlist']='Product not available in wishlist!';
}else{
$itemCollection = Mage::getModel('wishlist/item')->getCollection()
->addCustomerIdFilter($customerId);
foreach($itemCollection as $item) {
$pid= $item->getProduct()->getId();
if($pid == $productId){
$item->delete();
$result['status']='success!';
$result['remove_wishlist']='Product remove from wishlist!';
}
}
}
echo json_encode($result);
?>
//for register
->setIsDefaultBilling('1')
->setIsDefaultShipping('1')
->setSaveInAddressBook('1')
No comments:
Post a Comment