Magento: Export product attributes with category name and product URL

You can use following code to export product attributes, categories, and complete product URL link. Customize it according to your need.

require_once 'app/Mage.php';
// output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
$userModel = Mage::getModel('admin/user');
$collection = Mage::getModel('catalog/product')
->addAttributeToSelect('*') //Select everything from the table
->addUrlRewrite(); //Generate nice URLs

fputcsv($output, array(
'sku', 'Category ', 'Color', 'url_key'

foreach($collection as $product) {
$_cat = array();
$categoryName = array();

foreach ($product->getCategoryIds() as $Id) {
$_cat = Mage::getModel('catalog/category')->setStoreId(Mage::app()->getStore()->getId())->load($Id);
$categoryName[] = $_cat->getName();
$color = array();
$color = implode(',', $product->getAttributeText('color'));
$comma_separated = implode(",", $categoryName);
fputcsv($output, array(

Prestashop – Customer data Export

In the previous tutorial Customer Password Migration – Prestashop to Magento, we were discussing about customer data migration from Prestashop to Magento. Through Prestashop admin panel, it’s not possible to export all customers data, so you need to write custom sql query to select all customer data in PHPMYADMIN and export CSV sheet.

Using following query you can select all customers who are having addresses.

select ps_customer.id_customer,, ps_customer.firstname,
ps_customer.lastname, ps_customer.passwd,,
ps_customer.birthday, ps_customer.newsletter,
ps_address.id_country, ps_address.id_state, ps_address.address1, ps_address.address2,
ps_address.postcode,,, ps_address.vat_number
from ps_customer INNER JOIN ps_address
ON ps_customer.id_customer=ps_address.id_customer;


Using following query you can select all customers who are not having addresses.

SELECT id_customer, email, firstname, lastname, passwd, company, birthday, newsletter
FROM ps_customer WHERE id_customer NOT IN (SELECT id_customer FROM ps_address);

Customize your query based on your need of customer attributes.

Customer Password Migration – Prestashop to Magento

To get the migrated passwords from Prestashop to Magento working, we need go through these 2 steps:

Step 1

Export customers from Prestashop.
In Prestashop, there is no straight forward method to export customers password, but you can always write your custom query to get the reuired information from database. Login to Prestashop admin section go to Advanced Parameters->SQL Manager and write a new sql query “select email, firstname, lastname, passwd from ps_customer; “ which will be used to select customers email id, firstname, lastname and password from customer table. If you want to select more fields, write your sql query accordingly. Afterwars export the information in csv file.

Step 2

The process through which Prestashop and Magento creates customer password is slightly different. Prestashop uses ‘Cookie Key’ prefix to the customer password, which is then MD5 encrypted. Magento uses MD5 and salt at the end. It’s not possible to convert passwords to plain text once it is encrypted using MD5 , so we need to rewrite customer authentication model to extend default validation process and validate passwords imported from Prestashop by adding prefix Cookie Key value to the passwords which was used to generate passwords in Prestashop.

Rewriting Mage_Customer_Model_Customer Model

1. Create a module with namespace Retailon and modulename Customerimport
2. Enable your Module in app/etc/modules/Retailon_Customerimport.xml

<?xml version="1.0"?>

3. Create config.xml file app/code/local/Retailon/Customerimport/etc/config.xml with following content:

<?xml version="1.0"?>

4. Create model file app/code/local/Retailon/Customerimport/Model/Customer.php with following content:

class Retailon_Customerimport_Model_Customer extends Mage_Customer_Model_Customer {

public function authenticate($login, $password)

if ($this->getConfirmation() && $this->isConfirmationRequired()) {
throw Mage::exception('Mage_Core', Mage::helper('customer')->__('This account is not confirmed.'),
if (!$this->validatePassword($password) && !$this->validatePassword('u4qrHpFiADz3peo8rS5tBkWARaa2WqN3qa7XqCI8iddIo7gdbj3KPNzGyK0'.$password)) {
throw Mage::exception('Mage_Core', Mage::helper('customer')->__('Invalid login or password.'),
Mage::dispatchEvent('customer_customer_authenticated', array(
'model' => $this,
'password' => $password,
return true;

5. You will see a long string prepended to the password variable in authenticate method, which is the cookie string used to generate passwords in Prestashop. Go to config/
file of your Prestashop project’s directory and you will see a line like

define('_COOKIE_KEY_', 'u4qrHpFiADz3peo8rS5tBkWARaa2WqN3qa7XqCI8iddIo7gdbj3KPNzGyK0'); 

Copy this string and replace the cookie sting of your Magento’s authenticate function.

That’s all you need to do. Now you should be able to login to Magento store using your Prestashop credentials.

In the next article Prestashop – Customer data Export, I’m going to write about How you can export customer data from Prestashop. Stay tuned.

Magento – Export last 3 months shipment information

Recently I was supposed to export shipping carrier, order number, shipment number and associated customer info of an order. Here goes the code:

SELECT orders.increment_id, grid.increment_id, grid.created_at, address.firstname, address.lastname,, track.track_number, title-- prior to 1.6 `track_number` should be `number`
FROM sales_flat_order AS orders
JOIN sales_flat_order_address AS address ON address.parent_id = orders.entity_id
JOIN sales_flat_shipment_grid AS grid ON grid.order_increment_id = orders.increment_id
JOIN sales_flat_shipment_track AS track ON track.order_id = orders.entity_id
WHERE address.address_type =  'shipping' and grid.created_at >= '2015-04-10'

Modify it according to your need and export the sheet.

Magento product list collection modification

According to Marius, events are always the best approach to modify and apply filter on product listing page. This way, your changes are independent of the presentation layer (theme). If you have 2 websites with different themes you will have all modifications in one place. Changing the template file may result in pagination problems.

I had a requirement to customize product listing (category) page such that if a configurable product is present, and even a single associated product for that configurable product is out of stock, configurable product should not appear in product listing (category) page.

I’ve created my own module and observer and customized it. Here goes the code:




<?xml version="1.0"?>



class Retailon_Configurable_Model_Observer {
* Observes the catalog_block_product_list_collection event
public function addInStockOnlyFilter($observer){
$productCollection = $observer->getEvent()->getCollection();

foreach ($productCollection as $product) {
if ($product->getTypeId() == "configurable"){
$product->getTypeInstance(true)->getUsedProducts ( null, $product);
foreach ($product->getTypeInstance(true)->getUsedProducts ( null, $product) as $simple) {
//all associated pro
if($simple->getStockItem()->getQty() < 1 ){
$proArray[] = $product->getId();
$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($simple)->getQty();
echo $simple->getName()." with size ".$simple->getSize()." have a stock of ".$stock. " have sku "
.$simple->getSku()."Qty of ".$simple->getStockItem()->getQty();
echo '<br/>';

foreach ($proArray as $key) {



Installing solr search with Magento Enterprise Edition


Recently I struggled a lot to integrate solr search with Magento as it is one of the most popular search engine nowadays.

Most of the informations are covered here: How to Use the Solr Search Engine With Magento Enterprise Edition .

What is the process you have to follow to make solr work with Magento?

  • Grab the solr version compatible with your Magento enterprise edition.
  • Install solr in your system.
  • Copy all the files from [magento-installation-root]/lib/Apache/Solr/Conf to [solr-installation-folder]/example/solr/conf
  • Start start.jar file available in [solr-installation-folder]/example using command java -jar start.jar .
  • Test solr connection in Magento admin panel. Successful??

Solr Connection test

  • Save the configurations and server settings as it is. By default solr runs at port 8983.
  • Now everything is ready. But most of the times you wont be able to see products in your catalog. Why?? Because Solr needs re-indexing of the documents.


How to re-index all the documents ?

  1. First go to shell(magento root) folder using command prompt  [magento-installation-root]/shell
  2. Check the current status of indexing using php indexer.php –status . Here you may see all the index types with current status.
  3. Re-index all the data using php indexer.php –reindexall . You can also re-index individual data’s as php indexer.php –reindex catalog_product_attribute

On completion of the re-indexing you will see

Solr re-indexing

Wooha. Solr re-indexing is successful. Now you should be able to see products in your categories and your solr search should be enabled.

References: Magento re-indexing by Shell scripting , Solr category search is not working in Magento EE


Magento Files and Folder Structure

Hello Devs,

I’m Amit, a Magento Developer building cool e-commerce websites for RetailOn.

Magento is one of the widely used e-commerce platform based on Zend framework. Today I would like to explain few important Magento files and folders. Please have patience and let me know if you have any queries. I would love to help you out.

Once you will install Magento on your server you will see the following files/folders. MagentoFolderapp Directory
This is one of the most important directory of Magento.It contains different application development related files, module configuration files, design and theme related files and different localization files. app directory contains following folders and files.

  • code
  • design
  • etc
  • locale
  • Mage.php

code Directory
Most of the time developers have to play around this code directory only. It contains three different directories.

  • core
  • community
  • local

app/code/core: It contains Magento core folders. Only Core Magento Developers, who have written Magento are allowed to make modification in this folder. If your are planning to upgrade your your Magento version in future, never modify this folder.

app/code/community: It contains extensions installed from Magento Connect.

app/code/local:  It contains modules developed by developers locally. It is highly recommended to make your modification in this folder only(If you are not developing an extension).

app/design It contains all the designing files/folders . It contains following three sub folders.
  frontend : It contains all the design files related to fronend of Magento.
adminhtml: It contains all the design files related to back-end of Magento.
  install: It contains all the design Files related to Magento Installer.

app/etc: This directory contains all the configuration files related to the website (xml files).

app/locale: This directory contains localization specific csv files.