我正在为报价请求开发一个插件,我正在按照订单方法创建报价请求,我需要在创建订单时将订单状态从打开更改为报价,我尝试更改 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');
}
}
最佳答案
我通过添加 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 - 如何在 shopware6 中创建的订单上将订单状态从打开更改为报价?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69088973/