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.
Update your config/app.php
with the service provider:
'Tesco\TescoServiceProvider`,
and facade:
'Tesco' => 'Tesco\Facades\Laravel\Tesco`
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.
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);
$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();
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();
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);
$categories = Tesco::getCategories();
You can then loop the categories to get the product collections:
foreach ($categories as $category)
{
$category->getProducts();
}
$tesco = Tesco::getOffers();