prestashopcorp/module-lib-billing

用于检索为PS构建的上下文及其他工具包

3.3.1 2024-07-26 06:02 UTC

README

用于检索为PS构建的上下文及其他工具包

Latest Stable Version Minimum PHP Version Quality Control PHP

安装

此包可在 Packagist 上找到,您可以通过 Composer 安装它。

composer require prestashopcorp/module-lib-billing

版本指南

在PSx容器中注册为服务

在此之前,您必须已经定义了 PS 账户服务

示例

services:
  #####################
  # PS Billing
  ps_billings.context_wrapper:
    class: 'PrestaShopCorp\Billing\Wrappers\BillingContextWrapper'
    arguments:
      - "@ps_accounts.facade"
      - "@rbm_example.context"
      - true # if true you are in sandbox mode, if false or empty not in sandbox

  ps_billings.facade:
    class: 'PrestaShopCorp\Billing\Presenter\BillingPresenter'
    arguments:
      - "@ps_billings.context_wrapper"
      - "@rbm_example.module"

  # Remove this if you don't need BillingService
  ps_billings.service:
    class: PrestaShopCorp\Billing\Services\BillingService
    public: true
    arguments:
      - "@ps_billings.context_wrapper"
      - "@rbm_example.module"

如何使用它

展示者

例如,在主模块的 getContent 方法中。

  // Load context for PsBilling
  $billingFacade = $this->getService('ps_billings.facade');

  // Remove this if you don't need to set an image
  $partnerLogo = $this->getLocalPath() . ' views/img/partnerLogo.png';

  // Billing
  Media::addJsDef($billingFacade->present([
      'logo' => $partnerLogo,
      'tosLink' => 'https://yoururl/',
      'privacyLink' => 'https://yoururl/',
      'emailSupport' => 'you@email',
  ]));

贡献

代码风格

php vendor/bin/php-cs-fixer fix

自动测试

安装

请按照以下步骤启动单元测试

# Needs to have wget, for OS without wget pleae see the official website (or just visit this link)
PHP_VERSION=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;")
if [[ ${PHP_VERSION} -gt "72" ]]; then
  wget -O phpunit https://phar.phpunit.de/phpunit-9.phar
else
  wget -O phpunit https://phar.phpunit.de/phpunit-8.phar
fi

chmod +x phpunit

# Should display the version
./phpunit --version

运行

./phpunit tests

在 module-lib-billing 中引入破坏性更改

PrestaShop 模块系统无法处理同一库的多个版本。

以下是一个示例

  • 模块A需要libA的v1版本
  • 模块B需要同一libA的v2版本

如果某人先安装模块A然后安装模块B,只有libA的v1版本将被用于模块A和模块B。

解决方案

在引入类或方法签名中的破坏性更改时,您应该创建一个新的类而不是更改现有的类。

通过创建一个新的类,将强制自动加载器使用库的最后一个版本。