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.

<?php
require_once 'app/Mage.php';
umask(0);
// 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');
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$userModel = Mage::getModel('admin/user');
$userModel->setUserId(0);
$collection = Mage::getModel('catalog/product')
->getCollection()
->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(
$product->getSku(),
$comma_separated,
$color,
str_replace('export.php/','',Mage::getBaseUrl()).$product->getUrlPath($category)
)
);
}
?>
Advertisements

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"?>
<config>
<modules>
<Retailon_Customerimport>
<active>true</active>
<codePool>local</codePool>
</Retailon_Customerimport>
</modules>
</config>

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


<?xml version="1.0"?>
<config>
<modules>
<Retailon_Customerimport>
<version>0.1.0</version>
</Retailon_Customerimport>
</modules>
<global>
<models>
<customer>
<rewrite>
<customer>Retailon_Customerimport_Model_Customer</customer>
</rewrite>
</customer>
</models>
</global>
</config>

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


<?php
class Retailon_Customerimport_Model_Customer extends Mage_Customer_Model_Customer {

public function authenticate($login, $password)
{
$this->loadByEmail($login);

if ($this->getConfirmation() && $this->isConfirmationRequired()) {
throw Mage::exception('Mage_Core', Mage::helper('customer')->__('This account is not confirmed.'),
self::EXCEPTION_EMAIL_NOT_CONFIRMED
);
}
if (!$this->validatePassword($password) && !$this->validatePassword('u4qrHpFiADz3peo8rS5tBkWARaa2WqN3qa7XqCI8iddIo7gdbj3KPNzGyK0'.$password)) {
throw Mage::exception('Mage_Core', Mage::helper('customer')->__('Invalid login or password.'),
self::EXCEPTION_INVALID_EMAIL_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/settings.inc.php
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.

Installing solr search with Magento Enterprise Edition

Solr

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.

PmVHV

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.