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