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.email, ps_customer.firstname,
ps_customer.lastname, ps_customer.passwd, ps_customer.company,
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.city, ps_address.phone, 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"?>
<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.

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, address.email, 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:

app/etc/modules/Retailon_Configurable.xml

<config>
<modules>
<Retailon_Configurable>
<active>true</active>
<codePool>local</codePool>
</Retailon_Configurable>
</modules>
</config>

app/code/local/Retailon/etc/config.xml

<?xml version="1.0"?>
<config>
<global>
<models>
<retailon_configurable>
<class>Retailon_Configurable_Model</class>
</retailon_configurable>
</models>
</global>
<frontend>
<events>
<catalog_block_product_list_collection>
<observers>
<retailon_configurable_list>
<type>singleton</type>
<class>retailon_configurable/observer</class>
<method>addInStockOnlyFilter</method>
-</retailon_configurable_list>
</observers>
</catalog_block_product_list_collection>
</events>
</frontend>
</config>

app/code/local/Retailon/Model/Observer.php

<?php

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/>';
}
}
}

if(count($proArray)){
foreach ($proArray as $key) {
$productCollection->removeItemByKey($key);
}
}

$observer->getEvent()->setCollection($productCollection);
}

}

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.

How to develop Firefox OS Apps

Are you a developer ? Do you want to develop Apps for  Firefox OS ? Here is a small walk through which will be helpful in getting you started with it. But before directly jumping into developing the App let’s first define what is Firefox OS.

Firefox OS (codenamed Boot2Gecko or B2G) is a mobile operating system based on Linux and Mozilla’s Gecko technology. It is built upon open web standards like HTML5, CSS3, and JavaScript.

Here is a screenshot of a Firefox OS device.

geeksphone

Though this new mobile OS is an emerging technology, it is quickly catching the eyes of users, developers, and critics. Now let’s get down to the development of the Apps.

Where to run and test my App:

1.. Firefox OS device to run your app and check how it’s working.

2. Simulator: If you are not having a Firefox OS device still you can run and check you App on the simulator. Simulator is an add-on which is used to test apps in a Firefox OS-like environment that looks and feels like a mobile phone. If you need here you can download the Simulator and install.

3. Firefox Browser :  If you are not having Simulator installed still you can check your app on the Firefox browser opening it in the mobile mode using Ctrl+Shift+M also you can check it in various sizes choosing the sizes given.

It was all about running and testing the app. Now Let’s start building an App.

There are two types of apps you can build: packed Apps which are essentially a zip file containing all of of an apps assets: HTML, CSS, JavaScript, images, manifest, etc or hosted Apps, which are basically a website wrapped in an app. You’ll need server hosting for a hosted app.

Here I will be building a small App to write something into an text field and output it on the screen.

App Manifest:

Every Firefox OS App contains a manifest file.

1. create a folder and inside it create a file named manifest.webapp and paste the following code.

{
“name”: “Hello World”,
“description”: “An appication to check the entered value”,
“launch_path”: “/index.html”,
“icons”: {
“128”: “/images.png”
},
“developer”: {
“name”: “Your name”,
“url”: “Your Blog site url”
},
“default_locale”: “en”
}

2. Create a file named index.html and paste the following code.

<!DOCTYPE html>
<html>
<head>
<title>My First App!</title>
</head>

<body>
<h1>Hello, World!</h1>
<br />
<input type=’text’ id=’myTextInput’ value=’Type something!’onclick=”this.value=”;” />
<button id=’myButton’>Click Me!</button>
<!– link to your javascript folder –>
<script src=’hello.js’></script>
</body>
</html>

3. create a file named hello.js and paste the following code.

var button = document.getElementById(‘myButton’);
var txtInput = document.getElementById(‘myTextInput’);
button.addEventListener(‘click’, function(){
var text = txtInput.value;
// Show alert box with this text
document.write(“You have successfully typed: <strong>”+text +”</strong> !!!”);
})

4. paste any image of size 128*128 pixels and name it images.png.

Now you are done with your code. To run your App open Simulator (go to Firefox browsers Tool->Web Developer->Firefox OS Simulator) and if you are having apps installed you will see a screen like this otherwise a blank screen.

simulatorscreen

5. Click Add Directory and add your manifest file to it. Now open the simulator by clicking the stopped button and your App is installed now. Slide left on your Simulator device and click on your app you will see a screen like this:

hello_worldType something and test it.

testingappWoohha!!! Now you are done with your first app. For making the user interface of your app stylish play with css and making the buttons alive play with JavaScript codes to make the mobile world wonderful. Thank you.