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

How to call webservice in php?

I have called web services in php by using curl function. In below I have given  one example.  I have sent XML Request by using curl function.Because My web services return data on XML Format.

$xml_data = ''; //pass parameter using XML request provide By webservices
$postData = array(     // You can pass parameter using Array and pass in postfields.

    'authId'=>'',
    'siteId'=>'',
    'countryId'=>'',
    'regionId'=>'',
	'weekType'=>'',
	'startDate'=>''
);

$URL = "http://www.yourwebservices.com/";

$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
print_r($output);

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

How to load XML file using jquery ajax ?

you can load the xml data by using  jquery ajax by below Demo.

This is code in data.XML File

<?xml version="1.0" encoding="UTF-8"?>
<tabledata>
<row>
<column>India</column>
<column>China</column>
<column>Japan</column>
</row>
<row>
<column>Russia</column>
<column>France</column>
<column>Germany</column>
</row>
<row>
<column>USA</column>
<column>Canada</column>
<column>Brasil</column>
</row>
</tabledata>

NOTE:- You can just paste the above code to create a simple XML file

Continue reading

Display Most popular Posts In WordPress

Add code in your theme where ever you want the popular 5 posts to be displayed.

<ul>
    <?php $pc = new WP_Query('orderby=comment_count&posts_per_page=5'); 
		
      while ($pc->have_posts()) : $pc->the_post(); ?>
		<li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
		<p>Posted by <strong><?php the_author() ?></strong> with <?php comments_popup_link('No Comments;', '1 Comment', '% Comments'); ?></p></li>
      <?php endwhile; ?>
</ul>