Skip to content

Commit

Permalink
NTR: pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitalij Mik committed Dec 13, 2024
1 parent e54da67 commit 78b13ef
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
16 changes: 11 additions & 5 deletions src/Components/OrderExpiration/ExpireAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public function __construct(
OrderExpireService $orderExpireService,
SettingsService $settingsService,
LoggerInterface $logger
) {
)
{
$this->orderRepository = $orderRepository;
$this->salesChannelRepository = $salesChannelRepository;
$this->orderExpireService = $orderExpireService;
Expand Down Expand Up @@ -78,13 +79,18 @@ private function expireOrdersInSalesChannel(SalesChannelEntity $salesChannelEnti
$date = new \DateTime();
$date->modify(sprintf('-%d days', (BankTransferPayment::DUE_DATE_MAX_DAYS + 1)));


$orFilterArray = [
new EqualsFilter('transactions.stateMachineState.technicalName', OrderTransactionStates::STATE_IN_PROGRESS),
];
if (defined('\Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionStates\OrderTransactionStates::STATE_UNCONFIRMED')) {
$orFilterArray[] = new EqualsFilter('transactions.stateMachineState.technicalName', OrderTransactionStates::STATE_UNCONFIRMED);
}
$criteria = new Criteria();
$criteria->addAssociation('transactions.stateMachineState');
$criteria->addAssociation('transactions.paymentMethod');
$criteria->addFilter(new OrFilter([
new EqualsFilter('transactions.stateMachineState.technicalName', OrderTransactionStates::STATE_IN_PROGRESS),
new EqualsFilter('transactions.stateMachineState.technicalName', OrderTransactionStates::STATE_UNCONFIRMED)
]));

$criteria->addFilter(new OrFilter($orFilterArray));

$criteria->addFilter(new EqualsFilter('salesChannelId', $salesChannelEntity->getId()));
$criteria->addFilter(new RangeFilter('orderDateTime', [RangeFilter::GTE => $date->format(Defaults::STORAGE_DATE_TIME_FORMAT)]));
Expand Down
6 changes: 5 additions & 1 deletion src/Service/Order/OrderStatusUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,13 @@ public function updatePaymentStatus(OrderTransactionEntity $transaction, string
switch ($targetShopwareStatusKey) {
case MolliePaymentStatus::MOLLIE_PAYMENT_OPEN:
{
$states = [OrderTransactionStates::STATE_IN_PROGRESS];
if (defined('\Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionStates\OrderTransactionStates::STATE_UNCONFIRMED')) {
$states[] = OrderTransactionStates::STATE_UNCONFIRMED;
}
# if we are already in_progress...then don't switch to OPEN again
# otherwise SEPA bank transfer would switch back to OPEN
if (! in_array($currentShopwareStatusKey, [OrderTransactionStates::STATE_IN_PROGRESS, OrderTransactionStates::STATE_UNCONFIRMED]) || $context->hasState(self::ORDER_STATE_FORCE_OPEN)) {
if (! in_array($currentShopwareStatusKey, $states) || $context->hasState(self::ORDER_STATE_FORCE_OPEN)) {
$addLog = true;
$this->transactionTransitionService->reOpenTransaction($transaction, $context);
}
Expand Down
14 changes: 11 additions & 3 deletions src/Service/Transition/TransactionTransitionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Shopware\Core\System\StateMachine\Aggregation\StateMachineState\StateMachineStateEntity;
use Shopware\Core\System\StateMachine\Aggregation\StateMachineTransition\StateMachineTransitionActions;


class TransactionTransitionService implements TransactionTransitionServiceInterface
{
/**
Expand Down Expand Up @@ -46,19 +47,26 @@ public function __construct(
public function processTransaction(OrderTransactionEntity $transaction, Context $context): void
{
$technicalName = ($transaction->getStateMachineState() instanceof StateMachineStateEntity) ? $transaction->getStateMachineState()->getTechnicalName() : '';
$defaultState = OrderTransactionStates::STATE_IN_PROGRESS;
$action = StateMachineTransitionActions::ACTION_PROCESS;

if (defined('\Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionStates\OrderTransactionStates::STATE_UNCONFIRMED')) {
$defaultState = OrderTransactionStates::STATE_UNCONFIRMED;
$action = StateMachineTransitionActions::ACTION_PROCESS_UNCONFIRMED;
}

if ($this->isFinalOrTargetStatus($technicalName, [OrderTransactionStates::STATE_UNCONFIRMED])) {
if ($this->isFinalOrTargetStatus($technicalName, [$defaultState])) {
return;
}

$entityId = $transaction->getId();
$availableTransitions = $this->getAvailableTransitions($entityId, $context);

if (!$this->transitionIsAllowed(StateMachineTransitionActions::ACTION_PROCESS_UNCONFIRMED, $availableTransitions)) {
if (!$this->transitionIsAllowed($action, $availableTransitions)) {
$this->reOpenTransaction($transaction, $context);
}

$this->performTransition($entityId, StateMachineTransitionActions::ACTION_PROCESS_UNCONFIRMED, $context);
$this->performTransition($entityId, $action, $context);
}

public function reOpenTransaction(OrderTransactionEntity $transaction, Context $context): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ context("Order Status Mapping Tests", () => {

context(devices.getDescription(device), () => {

it('C4028: Test Status Open stays In-Progress', () => {
it('C4028: Test Status Open stays Unconfirmed/In progress', () => {

// we create a SEPA bank transfer payment
// the payment status will be IN PROGRESS then in Shopware.
Expand All @@ -66,7 +66,13 @@ context("Order Status Mapping Tests", () => {

adminLogin.login();
adminOrders.assertLatestOrderStatus('Open');
adminOrders.assertLatestPaymentStatus('In Progress');
if (shopware.isVersionLower('6.4.4.0')) {
adminOrders.assertLatestPaymentStatus('In Progress');
}else{
adminOrders.assertLatestPaymentStatus('Unconfirmed');
}


})

it('C4023: Test Status Paid', () => {
Expand Down

0 comments on commit 78b13ef

Please sign in to comment.