From a136a52ecdc4819c504851d3f03520b6758df746 Mon Sep 17 00:00:00 2001 From: Marija Date: Fri, 11 Oct 2024 13:03:11 +0200 Subject: [PATCH] Add compatibility with Shopware 6.4.11.0 CS-6010 --- src/Controller/AdminController.php | 7 ++++--- .../StoreApi/Payment/PaymentController.php | 20 ++++++++++++------- src/Resources/config/services/controllers.xml | 2 +- .../payment/payment-method.html.twig | 8 ++++---- .../order-history/order-detail.html.twig | 2 +- src/Service/PaymentMethodsService.php | 8 ++++---- src/Service/RefundService.php | 4 ++-- .../Repository/SalesChannelRepository.php | 2 +- src/Subscriber/ContextSubscriber.php | 7 +++---- src/Subscriber/PaymentSubscriber.php | 2 +- 10 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index 5cc8f36d..9473ba87 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -148,7 +148,8 @@ public function __construct( } /** - * @Route(path="/api/_action/adyen/verify") + * @Route(path="/api/_action/adyen/verify", + * name="api.action.adyen.verify", methods={"GET", "POST"}) * * @param RequestDataBag $dataBag * @return JsonResponse @@ -311,7 +312,7 @@ public function isManualCaptureEnabled(string $orderId) if (is_null($orderTransaction)) { return new JsonResponse(false); } - + $paymentMethodHandlerIdentifier = $orderTransaction->getPaymentMethod()->getHandlerIdentifier(); return new JsonResponse( @@ -410,7 +411,7 @@ public function getRefunds(string $orderId): JsonResponse * @Route( * "/api/adyen/orders/{orderId}/notifications", * methods={"GET"} - * ) + * ) * @param string $orderId * @return JsonResponse */ diff --git a/src/Controller/StoreApi/Payment/PaymentController.php b/src/Controller/StoreApi/Payment/PaymentController.php index 5b2b00f1..79d7d2bb 100644 --- a/src/Controller/StoreApi/Payment/PaymentController.php +++ b/src/Controller/StoreApi/Payment/PaymentController.php @@ -44,9 +44,10 @@ use Shopware\Core\Checkout\Order\SalesChannel\SetPaymentOrderRouteResponse; use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; +use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; +use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter; use Shopware\Core\Framework\Uuid\Uuid; use Shopware\Core\System\SalesChannel\SalesChannelContext; -use Shopware\Core\System\StateMachine\Loader\InitialStateIdLoader; use Shopware\Core\System\StateMachine\StateMachineRegistry; use Shopware\Core\System\StateMachine\Transition; use Symfony\Component\HttpFoundation\JsonResponse; @@ -114,9 +115,9 @@ class PaymentController */ private $orderTransactionStateHandler; /** - * @var InitialStateIdLoader + * @var EntityRepository */ - private $initialStateIdLoader; + private $stateMachineRepo; /** * StoreApiController constructor. @@ -130,7 +131,7 @@ class PaymentController * @param OrderRepository $orderRepository * @param OrderService $orderService * @param StateMachineRegistry $stateMachineRegistry - * @param InitialStateIdLoader $initialStateIdLoader + * @param EntityRepository $stateMachineRepo * @param EntityRepository $orderTransactionRepository * @param ConfigurationService $configurationService * @param OrderTransactionStateHandler $orderTransactionStateHandler @@ -146,7 +147,7 @@ public function __construct( OrderRepository $orderRepository, OrderService $orderService, StateMachineRegistry $stateMachineRegistry, - InitialStateIdLoader $initialStateIdLoader, + EntityRepository $stateMachineRepo, EntityRepository $orderTransactionRepository, ConfigurationService $configurationService, OrderTransactionStateHandler $orderTransactionStateHandler, @@ -164,7 +165,7 @@ public function __construct( $this->orderTransactionRepository = $orderTransactionRepository; $this->configurationService = $configurationService; $this->orderTransactionStateHandler = $orderTransactionStateHandler; - $this->initialStateIdLoader = $initialStateIdLoader; + $this->stateMachineRepo = $stateMachineRepo; $this->logger = $logger; } @@ -346,7 +347,12 @@ private function setPaymentMethod( SalesChannelContext $salesChannelContext ): void { $context = $salesChannelContext->getContext(); - $initialStateId = $this->initialStateIdLoader->get(OrderTransactionStates::STATE_MACHINE); + $criteria = new Criteria(); + $criteria->addFilter( + new EqualsFilter('technicalName', OrderTransactionStates::STATE_MACHINE) + ); + + $initialStateId = $this->stateMachineRepo->search($criteria, $context)->first()->getInitialStateId(); /** @var OrderEntity $order */ $order = $this->orderRepository->getOrder($orderId, $context, ['transactions']); diff --git a/src/Resources/config/services/controllers.xml b/src/Resources/config/services/controllers.xml index 3b054be5..9884f624 100644 --- a/src/Resources/config/services/controllers.xml +++ b/src/Resources/config/services/controllers.xml @@ -14,7 +14,7 @@ - + + {% if page.isPaymentChangeable is defined and not page.isPaymentChangeable %} + disabled="disabled" + {% endif %} + class="{{ formCheckInputClass ?? 'form-check-input' }} custom-control-input payment-method-input {% if 'handler_adyen_' in payment.formattedHandlerIdentifier %}adyen-payment-method-input-radio{% endif %}"> {% endblock %} {% block component_payment_method_description %} diff --git a/src/Resources/views/storefront/page/account/order-history/order-detail.html.twig b/src/Resources/views/storefront/page/account/order-history/order-detail.html.twig index a1462c57..9fe77af7 100644 --- a/src/Resources/views/storefront/page/account/order-history/order-detail.html.twig +++ b/src/Resources/views/storefront/page/account/order-history/order-detail.html.twig @@ -9,7 +9,7 @@ {% block page_account_order_item_detail_table_labels_summary %} {{ parent() }} - {% if actionType === 'voucher' %} + {% if actionType == 'voucher' %}
Voucher reference:
diff --git a/src/Service/PaymentMethodsService.php b/src/Service/PaymentMethodsService.php index e1fe7f11..7cfc3ab3 100644 --- a/src/Service/PaymentMethodsService.php +++ b/src/Service/PaymentMethodsService.php @@ -32,7 +32,7 @@ use Adyen\Shopware\Util\Currency; use Psr\Log\LoggerInterface; use Shopware\Core\Checkout\Cart\SalesChannel\CartService; -use Shopware\Core\Framework\Adapter\Cache\CacheValueCompressor; +use Shopware\Core\Framework\Adapter\Cache\CacheCompressor; use Shopware\Core\System\SalesChannel\SalesChannelContext; use Symfony\Contracts\Cache\CacheInterface; @@ -96,7 +96,7 @@ public function __construct( ConfigurationService $configurationService, Currency $currency, CartService $cartService, - CacheInterface $cache, + $cache, SalesChannelRepository $salesChannelRepository, OrderRepository $orderRepository ) { @@ -124,7 +124,7 @@ public function getPaymentMethods(SalesChannelContext $context, $orderId = ''): $paymentMethodsResponseCache = $this->cache->getItem($cacheKey); if ($paymentMethodsResponseCache->isHit() && $paymentMethodsResponseCache->get()) { - return CacheValueCompressor::uncompress($paymentMethodsResponseCache->get()); + return CacheCompressor::uncompress($paymentMethodsResponseCache); } $responseData = new PaymentMethodsResponse(); @@ -135,7 +135,7 @@ public function getPaymentMethods(SalesChannelContext $context, $orderId = ''): $responseData = $paymentsApiService->paymentMethods(new PaymentMethodsRequest($requestData)); - $paymentMethodsResponseCache->set(CacheValueCompressor::compress($responseData)); + $paymentMethodsResponseCache = CacheCompressor::compress($paymentMethodsResponseCache, $responseData); $this->cache->save($paymentMethodsResponseCache); } catch (AdyenException $e) { $this->logger->error($e->getMessage()); diff --git a/src/Service/RefundService.php b/src/Service/RefundService.php index 07236963..c0fbab31 100644 --- a/src/Service/RefundService.php +++ b/src/Service/RefundService.php @@ -482,9 +482,9 @@ public function getAdyenOrderTransactionForRefund(OrderEntity $order, array $sta * @return array */ public function getRefundRequest( - mixed $requestRefundAmount, + $requestRefundAmount, string $currencyCode, - mixed $merchantAccount, + $merchantAccount, string $pspReference, array $idempotencyExtraData = null ): array { diff --git a/src/Service/Repository/SalesChannelRepository.php b/src/Service/Repository/SalesChannelRepository.php index 1e4ca1b5..50914e9d 100644 --- a/src/Service/Repository/SalesChannelRepository.php +++ b/src/Service/Repository/SalesChannelRepository.php @@ -41,7 +41,7 @@ class SalesChannelRepository */ public function __construct( EntityRepository $domainRepository, - EntityRepository $salesChannelRepository, + $salesChannelRepository, ConfigurationService $configurationService, EntityRepository $languageRepository ) { diff --git a/src/Subscriber/ContextSubscriber.php b/src/Subscriber/ContextSubscriber.php index fe4077d3..01a48785 100644 --- a/src/Subscriber/ContextSubscriber.php +++ b/src/Subscriber/ContextSubscriber.php @@ -28,7 +28,6 @@ use Adyen\Shopware\Service\PaymentStateDataService; use Adyen\Shopware\Struct\AdyenContextDataStruct; use Adyen\Shopware\Util\Currency; -use Shopware\Core\Checkout\Cart\AbstractCartPersister; use Shopware\Core\Checkout\Cart\CartCalculator; use Shopware\Core\Framework\Routing\Event\SalesChannelContextResolvedEvent; use Shopware\Core\System\SalesChannel\Event\SalesChannelContextRestoredEvent; @@ -41,7 +40,7 @@ class ContextSubscriber implements EventSubscriberInterface private ConfigurationService $configurationService; private PaymentStateDataService $paymentStateDataService; private AbstractContextSwitchRoute $contextSwitchRoute; - private AbstractCartPersister $cartPersister; + private $cartPersister; private CartCalculator $cartCalculator; private Currency $currency; @@ -50,7 +49,7 @@ public function __construct( ConfigurationService $configurationService, PaymentStateDataService $paymentStateDataService, AbstractContextSwitchRoute $contextSwitchRoute, - AbstractCartPersister $cartPersister, + $cartPersister, CartCalculator $cartCalculator, Currency $currency ) { @@ -74,7 +73,7 @@ public static function getSubscribedEvents() public function onContextRestored(SalesChannelContextRestoredEvent $event): void { $token = $event->getRestoredSalesChannelContext()->getToken(); - $oldToken = $event->getCurrentSalesChannelContext()->getToken(); + $oldToken = $_SESSION['_sf2_attributes']['sw-context-token']; $stateData = $this->paymentStateDataService->fetchRedeemedGiftCardsFromContextToken($oldToken); foreach ($stateData->getElements() as $statedataArray) { diff --git a/src/Subscriber/PaymentSubscriber.php b/src/Subscriber/PaymentSubscriber.php index db021ebb..18f20339 100644 --- a/src/Subscriber/PaymentSubscriber.php +++ b/src/Subscriber/PaymentSubscriber.php @@ -158,7 +158,7 @@ public function __construct( ConfigurationService $configurationService, PaymentMethodsService $paymentMethodsService, RequestStack $requestStack, - AbstractCartPersister $cartPersister, + $cartPersister, CartCalculator $cartCalculator, AbstractContextSwitchRoute $contextSwitchRoute, AbstractSalesChannelContextFactory $salesChannelContextFactory,