jupi007/prestashop-webservice-bundle

Symfony integration for PrestaShop Webservice lib

v1.0.2 2021-05-15 15:34 UTC

This package is auto-updated.

Last update: 2021-09-15 16:20:21 UTC


README

Symfony integration of PrestaShop Webservice lib and PrestaShop Webservice lib Extra.

Installation

Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.

Applications that use Symfony Flex

Open a command console, enter your project directory and execute:

$ composer require "jupi007/prestashop-webservice-bundle"

Applications that don't use Symfony Flex

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require "jupi007/prestashop-webservice-bundle"

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the config/bundles.php file of your project:

// config/bundles.php

return [
    // ...
    Jupi007\PrestaShopWebserviceBundle\Jupi007PrestaShopWebserviceBundle::class => ['all' => true],
];

Configuration

Prerequisites

First at all, you must enable the webservice feature of your PrestaShop store and create an API key access. Please have a look at the official doc: Creating access to the Webservice.

It is recommended to fill secret infos like API keys into .env.local file.

To do this, create a config/packages/jupi007_presta_shop_webservice.yaml:

jupi007_presta_shop_webservice:
  connection:
    store_root_path: '%env(PRESTA_WEBSERVICE_ROOT_PATH)%'
    authentication_key: '%env(PRESTA_WEBSERVICE_AUTH_KEY)%'

And then add these environment variables to your .env.local:

PRESTA_WEBSERVICE_ROOT_PATH=https://absolute-path-to-your-store.com
PRESTA_WEBSERVICE_AUTH_KEY=ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789

Usage

Just inject the service by type-hinting an argument with the Jupi007\PrestaShopWebserviceBundle\Services\PrestaShopWebservice or PrestaShopWebserviceExtra class:

// src/Controller/ProductController.php
namespace App\Controller;

use Symfony\Component\HttpFoundation\Response;
use Jupi007\PrestaShopWebserviceBundle\Services\PrestaShopWebservice;
// or
use Jupi007\PrestaShopWebserviceBundle\Services\PrestaShopWebserviceExtra;

class ProductController
{
    /**
     * @Route("/products")
     */
    public function list(PrestaShopWebservice $psWebservice): Response
    {
        $products = $psWebservice->get(['resource' => 'products']);

        // ...
    }

    // or

    /**
     * @Route("/products")
     */
    public function list(PrestaShopWebserviceExtra $psWebservice): Response
    {
        $products = $psWebservice->get('products')
                                 ->executeQuery();

        // ...
    }
}

Once you have a PrestaShopWebservice or PrestaShopWebserviceExtra instance, you can use it just like the normal corresponding library.

See the official documentation for more informations: https://devdocs.prestashop.com/1.7/webservice/tutorials/prestashop-webservice-lib/

And also the PrestaShop Webservice lib Extra repository.