Thursday, February 5, 2015

Magento Auto Login and Auto Authorize for Rest API

We can skip login and authorize page when your doing rest api call in magento we can just make it admin login and create the token by using that token and secret key we can access need rest api for more information you can contact me +91-9916038230

Sunday, November 10, 2013

Remove the products from category products and update or map new product to category in magento programmatically

In some time you need to remove all the products from category or unset all products from category and add or update new product to category at that time you use below code for ex:- you need to run cron job which will run every day and get a product collection of sale attribute and map that products to that category
    define('MAGENTO', '..');
    require_once MAGENTO . '/app/Mage.php';

    //Load product model collecttion filtered by sale attribute
     $proCollection = Mage::getModel('catalog/product')
                        ->addAttributeToFilter('sale', '1');
$writeConnection = Mage::getSingleton('core/resource')->getConnection('core_write');

        // Delete Existing Mapped product from Sale Category
        $delQuery = 'Delete from catalog_category_product where category_id ='.$catId;
        $products = array();
        foreach ($proCollection as $product){
                $category_products .=$product->getId().'=1&';            
        parse_str($category_products, $products);    
        $process = Mage::getModel('index/indexer')->getProcessByCode('catalog_category_product');
        echo 'successfully mapped the data<br>';

Download file setSale.php

Get Todays start and end date with time in Magento

Some time we need to get collection of report or product collection of today date ,at that time need to set start date from 00:00:00 time and end with 23:59:59 for that use below code
 $todayStartOfDayDate      = Mage::app()->getLocale()->date()->setTime('00:00:00')->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
    $todayEndOfDayDate      = Mage::app()->getLocale()->date()->setTime('23:59:59')->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); 
or eg:- newarrival of product collection;
 $proCollection = Mage::getModel('catalog/product')
                        ->addAttributeToFilter('news_from_date', array('or'=> array(
                                    0 => array('date' => true, 'to' => $todayEndOfDayDate),
                                    1 => array('is' => new Zend_Db_Expr('null')))
                                ), 'left')
                                ->addAttributeToFilter('news_to_date', array('or'=> array(
                                    0 => array('date' => true, 'from' => $todayStartOfDayDate),
                                    1 => array('is' => new Zend_Db_Expr('null')))
                                ), 'left')
                                        array('attribute' => 'news_from_date', 'is'=>new Zend_Db_Expr('not null')),
                                        array('attribute' => 'news_to_date', 'is'=>new Zend_Db_Expr('not null'))

Friday, November 8, 2013

Cache a particular block or html in Magento

Hi, we can cache the block and also we can cache the particular HTML block code 1st time it will cache and from next time it will call from cache for eg:- in product view page your list a information in for each loop so each time it will kill your performance so 1st time cache and next time load it from cache we can cache in 2 ways 1. Cache a Block in block php add below code ex List.php
 public function __construct()
            'cache_lifetime'    => 1800,
            'cache_tags'        => array(Mage_Catalog_Model_Product::CACHE_TAG),
            'cache_key'         => $this->getCacheKey()

    public function getCacheKey()
        return $this->getRequest()->getRequestUri().$this->getCacheCurrencyCode();

    //retreive current currency code
    public function getCacheCurrencyCode()
        return Mage::app()->getStore()->getCurrentCurrencyCode();
2. cache a particular html block (only html code will cache it will not cache any objects ) you can do below logic even by creating new block file and can call it in product view page if you dont want to create new block for this small things you can cache the information
$cache = Mage::getSingleton('core/cache');
$cacheTag    = array(
$currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
$storeId = Mage::app()->getStore()->getId();
$plantationkey=str_replace(' ', '_', $plantation);
$cacheKey    = 'Origin_' .$plantationkey . $storeId .$currentCurrencyCode;
$orginhtml = $cache->load($cacheKey);

    echo $orginhtml;
    $theProductBlock = new Mage_Catalog_Block_Product;
    $Bestsellerproducts = Mage::getResourceModel('catalog/product_collection')
                    ->addAttributeToFilter('visibility', $this->visibility)
                    ->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
                    ->addCategoryFilter($category); ?>

    <?php if(count($Bestsellerproducts)):?>
    $orginhtml ='<ul>';
    foreach($Bestsellerproducts as $bestseller){ 
    $orginhtml .='<li>
        <a href="'.$bestseller->getProductUrl().'" class="product-img"><img src="'.$this->helper('catalog/image')->init($bestseller, 'small_image')->resize(229).'" width="229" height="229" alt="'.$this->stripTags($this->getImageLabel($bestseller, 'small_image'), null, true).'" title="'.$bestseller->getName().'" /></a>
        <h2 class="product-name"><a href="'.$bestseller->getProductUrl().'">'.$bestseller->getName().'</a>
 endif; ?>    

<?php echo $orginhtml; ?>
<?php $cache->save($orginhtml, $cacheKey, $cacheTag, 3600); ?>
<?php }    ?>

Friday, May 31, 2013

Product Grid in Admin Edit Form or Page in Magento


Today i created one module which will save products that is in admin edit page you can add product grid and select the product and save it it will show back when you come to edit

some thing like in admin product edit page you have cross sells or related product tabs where user can search products ,sort filter the products and select it and save it

which can be extend to custom module custom product grid in edit page where we can filter,sort or search the product and select and save it

For more information you can contact me!!

Wednesday, May 29, 2013

Split Order into 2 order in magento

if you need to split the order before it placed
that is if condition is true order will be Split ed into 2 order and place 2 order i created a module which will split the order into 2 and placed it based on the condition
here i took condition based on attribute set of product which can be modified easily
you can contact me if you need !!!

Wednesday, May 22, 2013

Product Tag Import In Magento

if you need to import tags for product you can use the attached file and see read_me.txt which will explain clearly
in this code you have to use advance profile to import the tags for product
for file go to this link where file is attached