jupi/prestashop-webservice-bundle

PrestaShop Webservice 库的 Symfony 集成

安装: 185

依赖: 0

建议: 0

安全: 0

星标: 3

关注者: 1

分支: 1

开放问题: 1

类型:symfony-bundle

v1.2.0 2022-03-14 11:55 UTC

This package is auto-updated.

Last update: 2024-09-14 17:43:06 UTC


README

PrestaShop Webservice 库和 PrestaShop Webservice lib Extra 的 Symfony 集成。

安装

确保全局已安装 Composer,如 Composer 文档中的安装章节所述。

使用 Symfony Flex 的应用程序

打开命令行,进入项目目录,执行以下命令:

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

未使用 Symfony Flex 的应用程序

步骤 1:下载 Bundle

打开命令行,进入项目目录,执行以下命令以下载此 Bundle 的最新稳定版本:

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

步骤 2:启用 Bundle

然后,通过将其添加到项目 config/bundles.php 文件中注册的 Bundle 列表中来启用该 Bundle。

// config/bundles.php

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

配置

先决条件

首先,您必须启用 PrestaShop 店的 webservice 功能并创建 API 密钥访问。请参阅官方文档:创建对 Webservice 的访问

建议将如 API 密钥之类的敏感信息填充到 .env.local 文件中。

为此,创建一个 config/packages/jupi_presta_shop_webservice.yaml

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

然后将这些环境变量添加到您的 .env.local

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

使用

只需通过将类型提示的参数指定为 Jupi\PrestaShopWebserviceBundle\Services\PrestaShopWebservicePrestaShopWebserviceExtra 类来注入服务。

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

use Jupi\PrestaShopWebserviceBundle\Services\PrestaShopWebservice;
// or
use Jupi\PrestaShopWebserviceBundle\Services\PrestaShopWebserviceExtra;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class ProductController extends AbstractController
{
    #[Route('/products', name: 'products')]
    public function list(PrestaShopWebservice $psWebservice): Response
    {
        $products = $psWebservice->get(['resource' => 'products']);

        // ...
    }

    // or

    #[Route('/products', name: 'products')]
    public function list(PrestaShopWebserviceExtra $psWebservice): Response
    {
        $products = $psWebservice->get('products')
                                 ->executeQuery();

        // ...
    }
}

一旦您有了 PrestaShopWebservicePrestaShopWebserviceExtra 实例,就可以像使用正常对应的库一样使用它。

有关更多信息,请参阅官方文档:https://devdocs.prestashop.com/1.7/webservice/tutorials/prestashop-webservice-lib/

还可以查看 PrestaShop Webservice lib Extra 存储库。