.

.

Show Row Number to Magento Dataflow Import Errors



The code which generates the HTML for the error messages is at app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Run.php. Make a copy of this file at app/code/local/Mage/Adminhtml/Block/System/Convert/Profile/Run.php
Locate this part:

$this->setBatchConfig(
                        ...
                        'template' => '<li style="#{style}" id="#{id}">'
                                    . '<img id="#{id}_img" src="#{image}" class="v-middle" style="margin-right:5px"/>'
                                    . '<span id="#{id}_status" class="text">#{text}</span>'
                                    . '</li>',
                         ...

change From :

'<span id="#{id}_status" class="text">#{text}</span>'

to:

'<span id="#{id}_status" class="text">Row #{id} - #{text}</span>'


Remove Item From Wishlist by Logged In User in Magento Programattically

Remove a product having productid $productId of a customer having customerid $customerId
<?php
 require_once 'app/Mage.php';
 Mage::app('default');    
 Mage::getSingleton("core/session", array("name" => "frontend"));
 
  ?>
<?php
if(Mage::getSingleton('customer/session')->isLoggedIn()) {
$customer = Mage::getSingleton('customer/session')->getCustomer();
$customerId=$customer->getId(); 


$productId=$_REQUEST['productId'];
if($_REQUEST['productId'])
{
$itemCollection = Mage::getModel('wishlist/item')->getCollection()->addCustomerIdFilter($customerId);
 $countcollection=count($itemCollection);
if($countcollection>0)
{
foreach($itemCollection as $item) {
    if($item->getProduct()->getId() == $productId){
        $item->delete();
    }
}

$data['responseCode']='1';
$data['msg']='Removed Product From Wishlist Successfully';
}
else
{
$data['responseCode']='0';
$data['msg']='No Wishlist Found';
}
}
else
{
$data['responseCode']='0';
$data['msg']='Please Select Product';
}
}
else
{
 $data['responseCode']='0';
 $data['msg']='Please Login First';
 
 }
$data2=json_encode($data);
echo $data2;
?>

Get Logged In User Product Wishlist in Magento Programatically


Get Wishlist by CustomerId with product detail .Let see example


<?php
require_once 'app/Mage.php';
Mage::app('default');
Mage::getSingleton("core/session", array("name" => "frontend"));
?>
<?php

if(Mage::getSingleton('customer/session')->isLoggedIn()) {
 
$customer = Mage::getSingleton('customer/session')->getCustomer();

$customerId=$customer->getId();

$wishList = Mage::getSingleton('wishlist/wishlist')->loadByCustomer($customerId);

$wishListItemCollection = $wishList->getItemCollection();
// get current currency
$currency_code = Mage::app()->getStore()->getCurrentCurrencyCode(); 
if (count($wishListItemCollection)) {
    $arrProductIds = array();
foreach ($wishListItemCollection as $item) {
        /* @var $product Mage_Catalog_Model_Product */
        $product = $item->getProduct();
        $arrProductIds[] = $product->getId();
    }
}
//print_r($arrProductIds);
$countprod = count($arrProductIds);
$productMediaConfig = Mage::getModel('catalog/product_media_config'); 
$j=0;
if($countprod > 0)
{
foreach($arrProductIds as $prdid)
{
// get product category model
$product2 = Mage::getModel('catalog/product')->load($prdid); 
// get productname
if($product2->getName()!='')
{
$productname = $product2->getName();
}else{ $productname=''; } 
if($product2->getThumbnail()!='')
 {
$thumbnailUrl = $productMediaConfig->getMediaUrl($product2->getThumbnail());
}
else
{
$thumbnailUrl='';
}
//get Product's Regular Price
if($product2->getPrice()!='')
{
$regularprice= $product2->getPrice();
}
else
{
$regularprice='';
}
//get Product's Special price
if($product2->getSpecialPrice()!='')
{
$specialprice= $product2->getSpecialPrice();
}
else
{
$specialprice='';
}
$productlist[$j]=array("productId"=>$prdid,"productName"=>$productname,"thumbnailUrl"=>$thumbnailUrl,"currencyCode"=>$currency_code,"regularPrice"=>$regularprice,"specialPrice"=>$specialprice);
$j++;
}
$data['responseCode']='1';
  $data['msg']='successfull';
  $data['currency']=$currency_code;
  $data['wishlistResponse']=$productlist;
 }
 else
 {
 $data['responseCode']='0';
 $data['msg']='No Wishlist Found';
 }
 
}
else
{
 $data['responseCode']='0';
 $data['msg']='Please Login First';
 
 }
  $data2=json_encode($data);
  echo $data2;
?>

Add Product to wishlist by Logged In Customer in magento programatically

For adding product to wishlist, we need customer id & product id . Let see example.
<?php
require_once 'app/Mage.php';
Mage::app('default');
Mage::getSingleton("core/session", array("name" => "frontend"));
?>
<?php
if(Mage::getSingleton('customer/session')->isLoggedIn()) {
$customer = Mage::getSingleton('customer/session')->getCustomer();
$customerId=$customer->getId(); 
$productId=$_REQUEST['productId'];
if($_REQUEST['productId'])
{
$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customerId, true);
$product = Mage::getModel('catalog/product')->load($productId);
$buyRequest = new Varien_Object(array()); // any possible options that are configurable and you want to save with the product
$result = $wishlist->addNewItem($product, $buyRequest);
$wishlist->save();
$data['responseCode']='1';
$data['msg']="Add Product to wishlist Successfully";
}
else
{
$data['responseCode']='0';
$data['msg']='Please select Customer Or Product';
}
}
else
{
 $data['responseCode']='0';
 $data['msg']='Please Login First';
 
 }
$data2=json_encode($data);
echo $data2;
?>

Catalog search product list in magento programatically

Magento search section is a bit more complex as they built a mechanism to save queries and results for caching and statistics. So, you need to prepare the query object, then prepare the result and then you can join the product collection with the search result table.
<?php
/*
created by :Rinky Kandwal
created date : 
Description : Search Product List by keyword ?q=
*/
?>
<?php
require_once '../app/Mage.php';
Mage::app();
//header("Content-Type: application/json");

$searchText = $_REQUEST['q'];
$query = Mage::getModel('catalogsearch/query')->setQueryText($searchText)->prepare();
$fulltextResource = Mage::getResourceModel('catalogsearch/fulltext')->prepareResult(
        Mage::getModel('catalogsearch/fulltext'),$searchText,$query);

$collection = Mage::getResourceModel('catalog/product_collection');
$collection->getSelect()->joinInner(
            array('search_result' => $collection->getTable('catalogsearch/result')),
            $collection->getConnection()->quoteInto(
                'search_result.product_id=e.entity_id AND search_result.query_id=?',
                $query->getId()
            ),
            array('relevance' => 'relevance')
        );
$collection->setStore(Mage::app()->getStore());
$collection->addMinimalPrice();
$collection->addFinalPrice();
$collection->addTaxPercents();
$collection->addStoreFilter();
$collection->addUrlRewrite();
$searchresult1=Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
$searchresult2=Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
$obj->collection = $collection;

// get original images of product section
$productMediaConfig = Mage::getModel('catalog/product_media_config');  

// get current currency
$currency_code = Mage::app()->getStore()->getCurrentCurrencyCode(); 
$countrecord = count($collection);
$j=0;
 if($countrecord > 0)
{
foreach($collection as $pc)
   {
    //get product id
 if($pc->getId()!='')
 {
   $prodid = $pc->getId();
 }
 else
 {
 $prodid='';
 } 

// get product category model
$product2 = Mage::getModel('catalog/product')->load($pc->getId()); 

// get productname
if($product2->getName()!='')
{
$productname = $product2->getName();
 }
 else
 {
 $productname='';
 } 
 if($product2->getThumbnail()!='')
 {
$thumbnailUrl = $productMediaConfig->getMediaUrl($product2->getThumbnail());
}
else
{
$thumbnailUrl='';
}
//get Product's Regular Price

if($product2->getPrice()!='')
{
$regularprice= $product2->getPrice();
}
else
{
$regularprice='';
}

//get Product's Special price
if($product2->getSpecialPrice()!='')
{
$specialprice= $product2->getSpecialPrice();
}
else
{
$specialprice='';
}
$productlist[$j]=array("productId"=>$prodid,"productName"=>$productname,"thumbnailUrl"=>$thumbnailUrl,"currencyCode"=>$currency_code,"regularPrice"=>$regularprice,"specialPrice"=>$specialprice);
 
$j++;
 }
 
  $data['responseCode']='1';
  $data['msg']='successfull';
  $data['keyword']=$searchText;
  $data['currency']=$currency_code;
  $data['searchProdResult']=$productlist;
     }
   else
   {
   $data['responseCode']='0';
   $data['msg']='No Record Found';   
   }   
  $data2=json_encode($data);
  echo $data2;
   ?>