/tesco-php

Tesco API PHP Library - http://techfortesco.com

Primary LanguagePHP

Tesco PHP

Installation

Add "lsjroberts/tesco-php": "dev-master" to your composer.json. Note: this is still in early development so there are not yet any tagged releases.

Laravel

Update your config/app.php with the service provider:

'Tesco\TescoServiceProvider`,

and facade:

'Tesco' => 'Tesco\Facades\Laravel\Tesco`

Standalone

use Tesco\Tesco;

$tesco = new Tesco($devKey, $appKey);

If you wish to create an service provider / adapter for another framework please create a pull request or just create an issue and I'll look into it.

Usage

Log a user into their account

Note: the tesco api doesn't implement OAuth or similar and the endpoint doesn't have a valid SSL certificate (at the time of writing).

$customer = Tesco::login($email, $password);

Search for a product

$jellies = Tesco::search('jelly');

As with many of the commands in this package, this returns an instance of Illuminate\Support\Collection so you are able to call the usual methods. For example, to get the first result call:

$jelly = Tesco::search('jelly')->first();

Get the customer's basket

You can either get the basket from a previously selected customer:

$basket = $customer->getBasket();

Or by using the Tesco facade to get the basket belonging to the last customer you logged in:

$basket = Tesco::getBasket();

Update the customer's basket

The update() method increases the quantity of a product in a basket. A negative quantity will reduce the number of that product in the basket.

Tesco::getBasket()->update($jelly, $quantity);

The remove() method completely removes the product from the basket.

Tesco::getBasket()->remove($jelly);

Get all product categories

$categories = Tesco::getCategories();

You can then loop the categories to get the product collections:

foreach ($categories as $category)
{
	$category->getProducts();
}

Get all current offers

$tesco = Tesco::getOffers();