定制 monsieurbiz/sylius-order-history-plugin 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

monsieurbiz/sylius-order-history-plugin

最新稳定版本:v1.1.1

Composer 安装命令:

composer require monsieurbiz/sylius-order-history-plugin

包简介

Add a timeline with all the order events on back-office.

README 文档

README

Banner of Sylius Order History plugin

Order History for Sylius

Order History Plugin license Tests Status Security Status

This plugin saves order events and allows you to display them in the order history as a timeline. It is based on state machine events.

Demo of the Order History

Compatibility

Sylius Version PHP Version
1.12 8.1 - 8.2 - 8.3
1.13 8.1 - 8.2 - 8.3
1.14 8.1 - 8.2 - 8.3

Installation

If you want to use our recipes, you can configure your composer.json by running:

composer config --no-plugins --json extra.symfony.endpoint '["https://api.github.com/repos/monsieurbiz/symfony-recipes/contents/index.json?ref=flex/master","flex://defaults"]'

Install the plugin via composer:

composer require monsieurbiz/sylius-order-history-plugin

For the installation without flex, follow these additional steps

Change your config/bundles.php file to add this line for the plugin declaration:

<?php

return [
    //..
    MonsieurBiz\SyliusOrderHistoryPlugin\MonsieurBizSyliusOrderHistoryPlugin::class => ['all' => true],
];

Copy the plugin configuration files in your config folder:

cp -Rv vendor/monsieurbiz/sylius-order-history-plugin/recipes/1.0/config/ config

Doctrine migration

In order to create dedicated tables for the plugin, don't forget to execute doctrine migration commands:

bin/console doctrine:migrations:migrate

Getting started

Show any order on the Sylius backend and click on the top right History button.

How does it work?

This plugin is based on the state machine events. It uses both the native Winzou state machine callback system and Symfony Workflow events to save named order events when they are triggered.

Depending on your sylius_state_machine_abstraction.default_adapter configuration:

# src/Resources/config/state_machine/checkout.yaml
winzou_state_machine:
  sylius_order_checkout:
    callbacks:
      after:
        monsieur_biz_order_history_notify_address:
          on: 'address'
          do: [ '@MonsieurBiz\SyliusOrderHistoryPlugin\Notifier\OrderHistoryWithAddressesDataNotifier', 'notifyEvent' ]
          args: [ 'object', 'constant("MonsieurBiz\\SyliusOrderHistoryPlugin\\Entity\\OrderHistoryEventInterface::TYPE_CHECKOUT")', '"addressed"' ]

or

<?php

declare(strict_types=1);

namespace App\EventListener\Workflow;

use MonsieurBiz\SyliusOrderHistoryPlugin\Entity\OrderHistoryEventInterface;
use MonsieurBiz\SyliusOrderHistoryPlugin\Notifier\OrderHistoryNotifierInterface;
use MonsieurBiz\SyliusOrderHistoryPlugin\Notifier\OrderHistoryWithAddressesDataNotifier;
use Sylius\Component\Core\Model\OrderInterface;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\Workflow\Event\CompletedEvent;

final class CheckoutWorkflowEventListener
{
    public function __construct(
        #[Autowire(service: OrderHistoryWithAddressesDataNotifier::class)]
        private OrderHistoryNotifierInterface $orderHistoryWithAddressesDataNotifier,
    ) {
    }

    #[AsEventListener(event: 'workflow.sylius_order_checkout.completed.addressed')]
    public function addressed(CompletedEvent $event): void
    {
        $order = $event->getSubject();
        if (!$order instanceof OrderInterface) {
            return;
        }

        $this->orderHistoryWithAddressesDataNotifier->notifyEvent(
            $order,
            OrderHistoryEventInterface::TYPE_CHECKOUT,
            'addressed',
        );
    }
}

Callback dedicated notifier service / actions who add different details following context:

  • \MonsieurBiz\SyliusOrderHistoryPlugin\Notifier\OrderHistoryNotifier is a basic notifier with no particular details except the given ones as parameters.
  • \MonsieurBiz\SyliusOrderHistoryPlugin\Notifier\OrderHistoryWithAddressesDataNotifier is a notifier dedicated to address events. It adds the billing and shipping address data.
  • \MonsieurBiz\SyliusOrderHistoryPlugin\Notifier\ShipmentOrderHistoryNotifier is a notifier dedicated to shipment events. It adds the shipment method name and the shipment state.
  • \MonsieurBiz\SyliusOrderHistoryPlugin\Notifier\PaymentOrderHistoryNotifier is a notifier dedicated to payment events. It adds the payment method name and the payment state.

How to

Contributing

You can find a way to run the plugin without effort in the file DEVELOPMENT.md.

Then you can open an issue or a Pull Request if you want! 😘
Thank you!

License

This plugin is completely free and released under the MIT License.

统计信息

  • 总下载量: 8.95k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 3
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-07-25