rem42/scraper-prestashop

API Prestashop 1.7

v3.1.0 2024-02-20 21:27 UTC

README

Packagist version Packagist download Packagist name Packagist php version Github licence Depenabot Codeclimate lines of code Codeclimate maintainability

Scraper can handle multiple request type and transform them into object in order to create some API.

Installation

composer require rem42/scraper-prestashop

Requirement

  • PHP >= 8.1

Usage

Initiate the client with the http client of your choice that implement the Symfony\Contracts\HttpClient\HttpClientInterface interface.

<?php

use Scraper\Scraper\Client;
use Symfony\Component\HttpClient\CurlHttpClient;
use Symfony\Component\HttpClient\NativeHttpClient;

$client = new Client(
    new CurlHttpClient()
    // OR
    new NativeHttpClient()
);

Then you can use the client to make request to the API.

Product list

<?php

use Scraper\ScraperPrestashop\Request\PrestashopGetRequest;
use Scraper\ScraperPrestashop\Entity\PrestashopProducts;

$request = new PrestashopGetRequest(
    'host.com', // Your prestashop host
    'key', // Your prestashop webservice key
    'products', // The resource you want to get, like 'products'
);

// optional for list request
$request
    ->addFilter('limit', 1)
    ->addFilter('offset', 1)
;

/** @var PrestashopProducts $products */
$products = $client->execute($request);

$products->getProducts(); // Return an array of PrestashopProduct

Product detail

<?php

use Scraper\ScraperPrestashop\Request\PrestashopGetRequest;
use Scraper\ScraperPrestashop\Entity\PrestashopProduct;

$request = new PrestashopGetRequest(
    'host.com', // Your prestashop host
    'key', // Your prestashop webservice key
    'products', // The resource you want to get, like 'products'
);

$request->setId(42);

/** @var PrestashopProduct $product */
$product = $client->execute($request);

$product->name; // Return the product name
$product->dateAdd; // Return the product creation date