如何将在 shopware 6 中创建的订单的订单状态从开放更改为报价?

Posted

技术标签:

【中文标题】如何将在 shopware 6 中创建的订单的订单状态从开放更改为报价?【英文标题】:How to change order state from open to quote on order created in shopware6? 【发布时间】:2021-11-04 09:29:30 【问题描述】:

我正在为报价请求开发一个插件,我正在按照订单方法创建报价请求,我需要在创建订单时将 orderstatus 从 open 更改为 quote,我尝试更改 stateId 但它确实做到了不行。后台的订单状态不会变成自定义的。

<?php declare(strict_types=1);

namespace RequestanOffer\Subscriber;

use Shopware\Core\System\SystemConfig\SystemConfigService;
use Shopware\Storefront\Pagelet\Footer\FooterPageletLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Storefront\Page\Checkout\Cart\CheckoutCartPageLoadedEvent;
use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
use Shopware\Core\Checkout\Order\OrderEvents;

use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionStates;
use Shopware\Core\Checkout\Order\OrderStates;

use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenEvent;

use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;


class Subscriber implements EventSubscriberInterface

    public const STATE_MACHINE = 'order.state';
    private $orderRepository;
    private $stateMachineStateRepository;
    private CONST ORDER_OPEN = 'D6A9628852A141B9957FFB1A48EE9551';
    private CONST QUOTE_OPEN = '1FEA95C739834229996CEE2D8BEBFDC0';
    public function __construct(
        EntityRepositoryInterface $orderRepository,
        EntityRepositoryInterface $stateMachineRepository
    )
    
        $this->orderRepository = $orderRepository;
        $this->stateMachineRepository = $stateMachineRepository;
    


    public static function getSubscribedEvents(): array
    
        return [
            ProductPageLoadedEvent::class => 'onProductPageLoaded',
            CheckoutCartPageLoadedEvent::class  => 'onCheckoutPageLoaded',
            CheckoutConfirmPageLoadedEvent::class => 'onCheckoutConfirmPageLoaded',
            OrderEvents::ORDER_WRITTEN_EVENT     => 'onQuoteOrder'
        ];
    


    public function onQuoteOrder(EntityWrittenEvent $stateId, $event) 



           $stateId = $payloads[0]['stateId'] = $this::QUOTE_OPEN;
        $criteria = new Criteria();
        $criteria->addFilter(
            new EqualsFilter('stateId', $stateId)

        );

               var_dump($payloads[0]['stateId']);
               die('dump');
          

【问题讨论】:

【参考方案1】:

在您的代码中,您没有保存任何内容。请查看状态机文档,这是如何实现的:

https://developer.shopware.com/docs/guides/plugins/plugins/checkout/order/using-the-state-machine

【讨论】:

我查看了文档,没有太多解释。如果可能,请您解释一下。 我相信您应该能够使用 developer.shopware.com/docs/guides/plugins/plugins/checkout/… 中描述的 Helpers 来更改状态。也许我没有完全理解你的问题。你能添加更多细节吗?您是否添加了新的自定义状态? 嗨,Alex,感谢您的回复,我在 StateMachineTransitionAction 类中添加了自定义状态 public const ACTION_ACCEPTQUOTE = 'accept_quote';公共常量 ACTION_OFFERQUOTE = 'quotation_request';我希望 orderState 更改为 ACTION_OFFERQUOTE 而不是默认的 OPEN orderstate。如何在初始订单处绕过 OPEN 订单状态? 我通过在 StateMachineTransitionActions 类中添加自定义 orderState 解决了这个问题。 太棒了,不要忘记投票/接受,甚至可能会发布您的完整解决方案作为答案【参考方案2】:

我通过在我的插件中添加 Core/StateMachineTransitionActions.php 类和额外的 StateMachineTransitionActions 解决了这个问题。

public const ACTION_CANCEL = 'cancel';
public const ACTION_COMPLETE = 'complete';
public const ACTION_DO_PAY = 'do_pay';
public const ACTION_FAIL = 'fail';
public const ACTION_PAID = 'paid';
public const ACTION_PAID_PARTIALLY = 'paid_partially';
public const ACTION_PROCESS = 'process';
public const ACTION_REFUND = 'refund';
public const ACTION_REFUND_PARTIALLY = 'refund_partially';
public const ACTION_REMIND = 'remind';
public const ACTION_REOPEN = 'reopen';
public const ACTION_RETOUR = 'retour';
public const ACTION_RETOUR_PARTIALLY = 'retour_partially';
public const ACTION_SHIP = 'ship';
public const ACTION_SHIP_PARTIALLY = 'ship_partially';
public const ACTION_AUTHORIZE = 'authorize';
public const ACTION_CHARGEBACK = 'chargeback';
public const ACTION_ACCEPTQUOTE = 'accept_quote';
public const ACTION_ASKQUOTE = 'ask_quote';
public const ACTION_QUOTATIONREQUEST = 'quotation_request';
public const ACTION_QUOTATIONOFFER = 'quotation_offer';

【讨论】:

以上是关于如何将在 shopware 6 中创建的订单的订单状态从开放更改为报价?的主要内容,如果未能解决你的问题,请参考以下文章

如何将自定义订单状态添加到 shopware 6

在 Shopware 5.4 中捕获订单更改事件。*

使用对象属性的 JPA 命名查询

如何在 Shopware 6 中创建 SEO 网址

C#从mysql数据库获取锁定代码的关键部分

如何在熊猫数据框组中创建订单?