Two way integration of WordPress with Magento

Most of the Magento users are aware of integrating WordPress with Magento using Fishpig. But Fishpig has some limitation like user can’t use Custom posts, Custom Fields or WordPress codes without using additional paid plugin.

To overcome this, we have found a way. Please follow below steps, this will help you use any WordPress code withing you Magento Installation.

Step 1: Install Fishpig plugin in Magento http://www.magentocommerce.com/magento-connect/wordpress-integration-3795.html

Step 2: Install WordPress plugin and follow installation steps given in it https://wordpress.org/plugins/magento-wordpress-integration/

Step 3: Add below code in index.php file
<?php
$admin = 'admin';
$uri = $_SERVER['REQUEST_URI'];
if(!strpos($uri, $admin) && !strpos($uri, 'downloader')) {
require_once(dirname(__FILE__).'/wordpress/wp-load.php');
}

Thats it, your installation should work now.

Advertisements

How To Use Cache In Magento

In this section we will see how to use cache in our custom modules. Suppose you have a custom module and wanted to save some data in magento cache, lets see how to do it.

Saving Data To Cache

$data = array(1,2,3,4); //any data which you want to save to cache $id = 'my_mod_id'; //unique id for your cache data $tags = array('collection'); //cache tags will be explain later in detail $lifetime = false; //false means infinity, or you can specify number of seconds $priority = 8; // number between 0-9, used by few backend cache models Mage::app()->saveCache($data,$id,$tags,$lifetime,$priority); Retrieving Data Mage::app()->loadCache($id);

Deleting Cache Mage::app()->removeCache($id);

Checking If Cache Is Enabled Mage::app()->useCache('collection'); //check if cache group is enabled or not

above are some basic caching function we can use in magento.

Custom Sending emails in magento

you can put this script in controller or any event of user

<?php

$email_to = 'xyz@gmail.com';

$receiveName = 'xyz';

$vars = data of user

$template_id = "New email"; //Name of email template
$email_template = Mage::getModel('core/email_template')->loadByCode($template_id);  //load templa
$email_template->setSenderName(Mage::getStoreConfig('trans_email/ident_sales/name'));
$email_template->setSenderEmail(Mage::getStoreConfig('trans_email/ident_support/email'));

$email_template->send($email_to,$receiveName, $vars);

 

?>

Get Product Image based on its Position – Magento

You might have seen website where the product images changes when you move mouse on it. In this tutorial i’ll show you how to do it with Magento.

You need to create a small module to achieve this. We will add this function in the helper file of the module so it can be called globally anywhere using helper function.

If you are not familiar with module creation i’ll list the steps below:

Step 1: Create a file in “app/etc/modules” named “Greeting_Imagealt.xml”. The content of the file will be.

<?xml version="1.0"?>
<config>
<modules>
<Greeting_Imagealt>
<active>true</active>
<codePool>local</codePool>
</Greeting_Imagealt>
</modules>
</config>

Continue reading

Magento – Install and Upgrade Database script

I struggled a lot to find a method to install a simple database script in Magento for creating a table or upgrading field or column. In the end I thought why not write one for reference. This post is mainly for my reference 😉

Initially you need to create a small extension to install the db script. You can also use the existing one if you want. But i have written a small extension just for the purpose of adding and updating database tables.

Below is the step by step procedure for executing Database queries

1) I have created a small extension named database. Create a file in “app/etc/modules” named “Greeting_Database.xml”.
The content of the file will be.

<?xml version="1.0"?>
<config>
<modules>
<Greeting_Database>
<active>true</active>
<codePool>local</codePool>
</Greeting_Database>
</modules>
</config>

This is just a basic file to let Magento know you have a module named Database. Greeting is the Company name of the module.
Continue reading

Passing values and parameters to template file using XML and ShortCode from Magento Admin

At times there is a need to pass some parameters to template file in Magento. Some of the conditions are as follow:

1) Category Id is needed to be passed to display all the products of that particular category
2) Static block id needs to be passed to call it in template file.

We can pass any parameters in the template file from Magento Admin using two methods

1) Using the shortcode: By using shortcode we can pass the parameter as follows

{{block type="greeting_products/productslider" category_id="11" product_count="10" title="Featured Products" template="greeting/products/featuredslider.phtml" }}

Here category_id and product_count are passed in the file featuredslider.phtml

{{block type="core/template" name="contactForm"  form_action="contacts/index/post"  template="contacts/form.phtml"}}

Here form_action URL is passed as a form action in contact form which will be passed to postAction method of IndexController.php file.
Continue reading

Reset Order id after clearing dummy Orders in Magento

After developing a website, Developers delete all the dummy order placed using either a SQL script or using one of the free extension available on Magento Connect.

After deleting orders, the Order Id still continues to be in the previous range ie if last Order Id was #100000123 the new Order Id will be #100000124. To reset the Order Id to default value ie: #100000001 we need to perform some SQL Queries on our Database.

The queries are as follows :

1) UPDATE eav_entity_store SET increment_last_id = ‘000000000’ WHERE entity_type_id = ‘5’;

2) UPDATE eav_entity_store SET increment_last_id = ‘000000000’ WHERE entity_type_id = ‘6’;

3) UPDATE eav_entity_store SET increment_last_id = ‘000000000’ WHERE entity_type_id = ‘7’;

4) UPDATE eav_entity_store SET increment_last_id = ‘000000000’ WHERE entity_type_id = ‘8’;

Here

5 is for Orders
6 is for Invoice
7 is for Credit Memo
8 is for Shipment