1. Start
  2. Description
  3. API key
  4. Class methods
  5. Example + output

Price comparison PHP class

Let Google find the best prices for you


Description


With the 'Price comparison PHP class' you can easily find the best price for a product. You can filter results by adding methods like search by brand. 

API key


Before we get started you need to have an API key. You can get one by clicking on the following url: https://code.google.com/apis/console/.

Class methods


Include class

include 'classes/Comparison.php';

getProduct( $product)

Add product name (e,g. MP3 Player).

Example:

 

<?php

$key = 'AIza........Vm1o';

$com = new Comparison($key);

$product = $com->getProduct('MP3 player')->run();

var_dump($product);

 


orderBy($type, $order = 'ascending')

You can order the output by relevancy, modification time or price.

Parameter Options Default
$type relevancy, modificationTime, price -
$order ascending, descending ascending

Example:

 

<?php

$key = 'AIza........Vm1o';

$com = new Comparison($key);

$product = $com->getProduct('MP3 player')->orderBy('price','descending')->run();

var_dump($product);

brand( $values)

You can filter the search by only selecting specified brands/companies (e.g. Samsung, Apple)

 

Example:

<?php

$key = 'AIza........Vm1o';

$com = new Comparison($key);

$product = $com->getProduct('MP3 player')->brand(array('samsung','apple','philips'))->run();

var_dump($product);

 


language( $country = 'us')

You can change the language which will also change the selected e-shops by the used country.

 

Example:

<?php

$key = 'AIza........Vm1o';

$com = new Comparison($key);

$product = $com->getProduct('MP3 player')->language('nl')->run();

var_dump($product);

 

This example will only return products from dutch e-shops.


spellcheck()

This function works like a automatic 'did you mean' autocorrection.

 

Example:

<?php

$key = 'AIza........Vm1o';

$com = new Comparison($key);

$product = $com->getProduct('MP3 player')->spellcheck()->run();

var_dump($product);

 


pagination($maxResults = 25, $startIndex = 1)

This function helps you ouput less results. 

 

Example:

<?php

$key = 'AIza........Vm1o';

$com = new Comparison($key);

$product = $com->getProduct('MP3 player')->pagination(20,5)->run();

var_dump($product);

 

The output of this example will be 20 results and set the start index at 5.

Example + output


In this example I will use the following code:

 

<?php

include 'classes/Comparrison.php';

$key = 'AIza........m1o';

$com = new Comparison($key);

$product = $com->getProduct('MP3 player')->brand(array('samsung','apple','philips'))->orderBy('price','descending')->language('us')->spellcheck()->pagination(4,5)->run();

var_dump($product);
This example will output:
Array
(
    [searchterm] => MP3 player
    [total] => 101676
    [status] => 1
    [products] => Array
        (
            [0] => Array
                (
                    [seller] => Array
                        (
                            [name] => eBay
                            [country] => US
                        )

                    [product] => Array
                        (
                            [title] => Apple Ipod Touch 64gb 4g Mp3 Player
                            [brand] => Apple
                            [description] => Enjoy watching videos on the 3.5-inch Multi-touch Retina display of the iPod touch 4G at a stunning resolution of 960x640p. The FaceTime feature of this Apple media player allows you to seamlessly video call your friend just by sending an invite. Equipped with an A4 processor, this digital media player makes multitasking, placing FaceTime calls or editing videos easy while enhancing the battery life. The Gyro+ Accelerometer of the iPod touch 4G enables better motion sensing like full 3D attitude, rotation rate and user acceleration, making gaming even more enjoyable. With a built-in editing feature, you do not have to wait to get to your PC to edit your videos; you can do that right away on this Apple media player. The two cameras of this digital media player shoot amazing videos in HD 720p resolution while the integrated microphone can record conversations or music simultaneously.
                            [condition] => refurbished
                            [link] => http://rover.ebay.com/rover/1/711-67261-24966-0/2?ipn=psmain&icep_vectorid=263602&mtid=691&kwid=1&crlp=1_263602&icep_item_id=250911167362&itemid=250911167362&icep_meta_categ_id=293&icep_etrs=N&icep_epid=92269142&icep_ctlg=39&icep_cond=Refurbished
                            [availability] => inStock
                            [price] => 331.99
                            [currency] => USD
                        )

                    [products] => Array
                        (
                            [images] => Array
                                (
                                    [0] => http://i.ebayimg.com/00/s/MTAwMFgxMDAw/%24%28KGrHqV,%21lME6B2nKCCwBOmJIULjtQ%7E%7E60_1.JPG?set_id=880000500F
                                )

                        )

                )

            [1] => Array
                (
                    [seller] => Array
                        (
                            [name] => eBay
                            [country] => US
                        )

                    [product] => Array
                        (
                            [title] => Apple Ipod Touch 64gb 4g Mp3 Player - Newest Model
                            [brand] => Apple
                            [description] => Enjoy watching videos on the 3.5-inch Multi-touch Retina display of the iPod touch 4G at a stunning resolution of 960x640p. The FaceTime feature of this Apple media player allows you to seamlessly video call your friend just by sending an invite. Equipped with an A4 processor, this digital media player makes multitasking, placing FaceTime calls or editing videos easy while enhancing the battery life. The Gyro+ Accelerometer of the iPod touch 4G enables better motion sensing like full 3D attitude, rotation rate and user acceleration, making gaming even more enjoyable. With a built-in editing feature, you do not have to wait to get to your PC to edit your videos; you can do that right away on this Apple media player. The two cameras of this digital media player shoot amazing videos in HD 720p resolution while the integrated microphone can record conversations or music simultaneously.
                            [condition] => refurbished
                            [link] => http://rover.ebay.com/rover/1/711-67261-24966-0/2?ipn=psmain&icep_vectorid=263602&mtid=691&kwid=1&crlp=1_263602&icep_item_id=360396212106&itemid=360396212106&icep_meta_categ_id=293&icep_etrs=N&icep_epid=92269142&icep_ctlg=39&icep_cond=Refurbished
                            [availability] => inStock
                            [price] => 331.99
                            [currency] => USD
                        )

                    [products] => Array
                        (
                            [images] => Array
                                (
                                    [0] => http://i.ebayimg.com/00/s/MTAwMFgxMDAw/%24%28KGrHqUOKjsE5VSp-4K4BOfJ87Cb%29w%7E%7E60_1.JPG?set_id=880000500F
                                )

                        )

                )

            [2] => Array
                (
                    [seller] => Array
                        (
                            [name] => Sears
                            [country] => US
                        )

                    [product] => Array
                        (
                            [title] => Apple Ipod Touch 32gb Mp3 Player (4th Generation) With Touch Screen,
                            [brand] => Apple
                            [description] => SOLD BY OUTLET MALL BARGAINS ON SEARS. Hundreds of items sold on sears.com. 100% satisfaction guaranteed. See friends while you talk to them with FaceTime. Shoot, edit, and share stunning HD video. Play games against friends, or unknown foes, with the new Game Center. And do it all on the Retina display the highest-resolution screen on any mobile device. It makes graphics and text look even more amazing. The new iPod touch. It s state-of-the-art fun.
                            [condition] => new
                            [link] => http://www.sears.com/shc/s/p_10153_12605_SPM3242705202P?sid=IDx20101019x00001a&ci_src=14110944&ci_sku=SPM2956820002
                            [availability] => inStock
                            [price] => 304.49
                            [currency] => USD
                        )

                    [products] => Array
                        (
                            [images] => Array
                                (
                                    [0] => http://c.shld.net/rpx/i/s/pi/mp/9647/2956820002p?src=http%3A%2F%2Fc.shld.net%2Frpx%2Fi%2Fs%2Fpi%2Fmp%2F4438%2F1972300301p%3Fsrc%3Dhttp%3A%2F%2Flh3.ggpht.com%2F_Xr3bhACP_r4%2FTP_-iZI6WfI%2FAAAAAAAAARY%2F-x3dm52EH9I%2Fipodtouch.jpg%26d%3Dc46301489e3b43f403fec6bc4d3f1460ec9af18d&d=dcf51e6aad365a3aebc93709fb913143bf4e8880
                                )

                        )

                )

            [3] => Array
                (
                    [seller] => Array
                        (
                            [name] => eBay - purchasedomainnames
                            [country] => US
                        )

                    [product] => Array
                        (
                            [title] => Apple Ipod Touch 8gb Mp3 Player (white 4th Generation Latest Model)
                            [brand] => Apple
                            [description] => Enjoy watching videos on the 3.5-inch Multi-touch Retina display of the iPod touch 4G at a stunning resolution of 960x640p. The FaceTime feature of this Apple media player allows you to seamlessly video call your friend just by sending an invite. Equipped with an A4 processor, this digital media player makes multitasking, placing FaceTime calls or editing videos easy while enhancing the battery life. The Gyro+ Accelerometer of the iPod touch 4G enables better motion sensing like full 3D attitude, rotation rate and user acceleration, making gaming even more enjoyable. With a built-in editing feature, you do not have to wait to get to your PC to edit your videos; you can do that right away on this Apple media player. The two cameras of this digital media player shoot amazing videos in HD 720p resolution while the integrated microphone can record conversations or music simultaneously.
                            [condition] => new
                            [link] => http://rover.ebay.com/rover/1/711-67261-24966-0/2?ipn=psmain&icep_vectorid=263602&mtid=691&kwid=1&crlp=1_263602&icep_item_id=260874634300&itemid=260874634300&icep_meta_categ_id=293&icep_etrs=Y&icep_epid=92352708&icep_ctlg=39&icep_cond=New
                            [availability] => inStock
                            [price] => 299.99
                            [currency] => USD
                        )

                    [products] => Array
                        (
                            [images] => Array
                                (
                                    [0] => http://i.ebayimg.com/00/s/NDg4WDQ3MA==/%24%28KGrHqR,%21lIE6GRqJW9pBOj77sulfg%7E%7E60_1.JPG?set_id=8800005007
                                )

                        )

                )

        )

)