Sunday 28 December 2014

Magento Installation - PHP Extensions "pdo_mysql" must be loaded.

You must recompile Apache with PDO MySQL support.



Go to WHM-> Software-> EasyApache (Apache Update)



In the "Exhaustive Options List" you find "PDO MySQL"






Thursday 25 December 2014

"There has been an error processing your request" error in Magento

When I logged in to the admin panel or open base url of magento site (http://www.example.com/admin or http://www.example.com/). I got this wierd looking page on my screen.



I googled this "There has been an error processing your request" and found the solution as follows-

1.   Open Magento root directory and create tmp folder.

2.   Set directory permissions to 777 or 755

3.   Open "lib/Zend/Cache/Backend/File.php"

4.   locate the following code:


             
protected $_options = array(
                     'cache_dir' => null,


                           and replace with


                 protected $_options = array(
                       'cache_dir' => 'tmp',



Reference: 


http://stackoverflow.com/questions/15473705/there-has-been-an-error-processing-your-request-error-log-record-number


http://magento.stackexchange.com/questions/8905/there-has-been-an-error-processing-your-request

        


Best Wishes!!!

Tuesday 23 December 2014

Magento: Delete All Products Using PhpMyAdmin

Copy and Paste following code in phpmyadmin under sql tab and run it:



SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE 'catalog_product_bundle_option';
TRUNCATE TABLE 'catalog_product_bundle_option_value';
TRUNCATE TABLE 'catalog_product_bundle_selection';
TRUNCATE TABLE 'catalog_product_entity_datetime';
TRUNCATE TABLE 'catalog_product_entity_decimal';
TRUNCATE TABLE 'catalog_product_entity_gallery';
TRUNCATE TABLE 'catalog_product_entity_int';
TRUNCATE TABLE 'catalog_product_entity_media_gallery';
TRUNCATE TABLE 'catalog_product_entity_media_gallery_value';
TRUNCATE TABLE 'catalog_product_entity_text';
TRUNCATE TABLE 'catalog_product_entity_tier_price';
TRUNCATE TABLE 'catalog_product_entity_varchar';
TRUNCATE TABLE 'catalog_product_link';
TRUNCATE TABLE 'catalog_product_link_attribute';
TRUNCATE TABLE 'catalog_product_link_attribute_decimal';
TRUNCATE TABLE 'catalog_product_link_attribute_int';
TRUNCATE TABLE 'catalog_product_link_attribute_varchar';
TRUNCATE TABLE 'catalog_product_link_type';
TRUNCATE TABLE 'catalog_product_option';
TRUNCATE TABLE 'catalog_product_option_price';
TRUNCATE TABLE 'catalog_product_option_title';
TRUNCATE TABLE 'catalog_product_option_type_price';
TRUNCATE TABLE 'catalog_product_option_type_title';
TRUNCATE TABLE 'catalog_product_option_type_value';
TRUNCATE TABLE 'catalog_product_super_attribute_label';
TRUNCATE TABLE 'catalog_product_super_attribute_pricing';
TRUNCATE TABLE 'catalog_product_super_attribute';
TRUNCATE TABLE 'catalog_product_super_link';
TRUNCATE TABLE 'catalog_product_enabled_index';
TRUNCATE TABLE 'catalog_product_website';
TRUNCATE TABLE 'catalog_category_product_index';
TRUNCATE TABLE 'catalog_category_product';
TRUNCATE TABLE 'cataloginventory_stock_item';
TRUNCATE TABLE 'cataloginventory_stock_status';
TRUNCATE TABLE 'cataloginventory_stock';
INSERT  INTO 'catalog_product_link_type'('link_type_id','code') VALUES (1,'relation'),(2,'bundle'),(3,'super'),(4,'up_sell'),(5,'cross_sell');
INSERT  INTO 'catalog_product_link_attribute'('product_link_attribute_id','link_type_id','product_link_attribute_code','data_type') VALUES (1,2,'qty','decimal'),(2,1,'position','int'),(3,4,'position','int'),(4,5,'position','int'),(6,1,'qty','decimal'),(7,3,'position','int'),(8,3,'qty','decimal');
INSERT  INTO 'cataloginventory_stock'('stock_id','stock_name') VALUES (1,'Default');
TRUNCATE TABLE 'catalog_product_entity';
SET FOREIGN_KEY_CHECKS = 1;

Friday 19 December 2014

Magento : Delete all Products of Particular category id

Create one file and paste following code:


<?php
require_once ("app/Mage.php");
Mage::app('admin');
$category_id = your_cat_id;
$products = Mage::getModel('catalog/product')->getCollection();
foreach($products as $product){
 $categories = $product->getCategoryIds();
 if(in_array($category_id, $categories)) {
  $product_load = Mage::getSingleton('catalog/product')->load($product->getId());
  Mage::dispatchEvent('catalog_controller_product_delete', array('product' => $product_load));
  $product_load->delete();
 }
}
?>


And upload file on root of server and run as:

www.example.com/file_name.php

Thursday 18 December 2014

Import csv file with multiple images in magento

First make a copy of


app/code/core/Mage/Catalog/Model/Convert/Adapter/Product.php 

  into 

app/code/local/Mage/Catalog/Model/Convert/Adapter/


Edit 

app/code/local/Mage/Catalog/Model/Convert/Adapter/Product.php 

and add the following code after line 778:



if (isset($importData['media_gallery']) && !empty($importData['media_gallery'])) {

        $x = explode(',', $importData['media_gallery']);

        foreach ($x as $file) {

            $imagesToAdd[] = array('file' => trim($file));

        }

        $mediaGalleryBackendModel->addImagesWithDifferentMediaAttributes(

            $product,

            $imagesToAdd, Mage::getBaseDir('media') . DS . 'import',

            false,

            false

        );

    }





Now file look like following: 

773        $addedFilesCorrespondence = $mediaGalleryBackendModel->addImagesWithDifferentMediaAttributes(
774            $product,
775            $arrayToMassAdd, Mage::getBaseDir('media') . DS . 'import',
776            false,
777            false
778        );


779    if (isset($importData['media_gallery']) && !empty($importData['media_gallery'])) {


780    $x = explode(',', $importData['media_gallery']);

781       foreach ($x as $file) {
782            $imagesToAdd[] = array('file' => trim($file));
783        }
784        $mediaGalleryBackendModel->addImagesWithDifferentMediaAttributes(
785            $product,
786            $imagesToAdd, Mage::getBaseDir('media') . DS . 'import',
787            false,
788            false
789        );
790    }




Now add a column *media_gallery* in your  CSV file, and put your other images in /media/import also. 

Add images as following:


media_gallery

-------------


/second_image.png, /third_image.png, /fourth_image.png




Wednesday 3 December 2014

Get any product attribute value in magento


 Get any product attribute value in magento. Change 'custom_attribute' from your attribute code.


<?php echo $this->htmlEscape($_product->getData('custom_attribute')); ?>

Tuesday 2 December 2014

Magento Get Dropdown Attribute value

The attribute code is supposed to be 'my_custom_attribute'





$attributeValue = Mage::getModel('catalog/product')


            ->load($_product->getId())


            ->getAttributeText('my_custom_attribute');