Skip to content

Commit

Permalink
Fix issue when confirmed cart does not match the current cart
Browse files Browse the repository at this point in the history
CS-5639
  • Loading branch information
MarijaIv committed Jul 12, 2024
1 parent e491948 commit 2cd6003
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Controller/Comeback/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function execute()
$metadata = $this->cookieMetadataFactory
->createPublicCookieMetadata()
->setPath('/');
$sectiondata = json_decode($this->cookieManager->getCookie('section_data_ids'));
$sectiondata = json_decode($this->cookieManager->getCookie('section_data_ids') ?: '');
if($sectiondata){
$sectiondata->cart += 1000;
$this->cookieManager->setPublicCookie(
Expand Down
6 changes: 5 additions & 1 deletion Model/Api/Builders/CreateOrderRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ public function __construct(

public function build(): CreateOrderRequest
{
$this->quote = $this->quoteRepository->getActive($this->cartId);
try {
$this->quote = $this->quoteRepository->getActive($this->cartId);
} catch (\Exception $e) {
$this->quote = $this->quoteRepository->get($this->cartId);
}

return $this->generateCreateOrderRequest();
}
Expand Down
35 changes: 34 additions & 1 deletion Services/BusinessLogic/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use DateTime;
use Exception;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Quote\Api\CartManagementInterface;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Sales\Api\OrderManagementInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use SeQura\Core\BusinessLogic\Domain\Order\Exceptions\InvalidOrderStateException;
Expand All @@ -22,6 +24,7 @@
use SeQura\Core\Infrastructure\Http\Exceptions\HttpRequestException;
use SeQura\Core\Infrastructure\ServiceRegister;
use SeQura\Core\BusinessLogic\Domain\Order\Service\OrderService as SeQuraOrderService;
use Sequra\Core\Model\Api\Builders\CreateOrderRequestBuilderFactory;
use Sequra\Core\Services\BusinessLogic\Utility\SeQuraTranslationProvider;

/**
Expand Down Expand Up @@ -64,14 +67,24 @@ class OrderService implements ShopOrderService
* @var SeQuraOrderService
*/
private $sequraOrderService;
/**
* @var CartRepositoryInterface
*/
private $cartRepository;
/**
* @var CreateOrderRequestBuilderFactory
*/
private $createOrderRequestBuilderFactory;

public function __construct(
SearchCriteriaBuilder $searchOrderCriteriaBuilder,
OrderRepositoryInterface $shopOrderRepository,
OrderManagementInterface $orderManagement,
CartManagementInterface $cartManagement,
SeQuraOrderRepositoryInterface $seQuraOrderRepository,
SeQuraTranslationProvider $translationProvider
SeQuraTranslationProvider $translationProvider,
CartRepositoryInterface $cartProvider,
CreateOrderRequestBuilderFactory $createOrderRequestBuilderFactory
)
{
$this->searchOrderCriteriaBuilder = $searchOrderCriteriaBuilder;
Expand All @@ -80,6 +93,8 @@ public function __construct(
$this->cartManagement = $cartManagement;
$this->seQuraOrderRepository = $seQuraOrderRepository;
$this->translationProvider = $translationProvider;
$this->cartRepository = $cartProvider;
$this->createOrderRequestBuilderFactory = $createOrderRequestBuilderFactory;
}

/**
Expand Down Expand Up @@ -141,6 +156,24 @@ public function getOrderUrl(string $merchantReference): string
return '';
}

/**
* @inheritDoc
*
* @throws NoSuchEntityException
*/
public function getCreateOrderRequest(string $orderReference): CreateOrderRequest
{
$seQuraOrder = $this->seQuraOrderRepository->getByOrderReference($orderReference);
$quote = $this->cartRepository->get($seQuraOrder->getCartId());

$builder = $this->createOrderRequestBuilderFactory->create([
'cartId' => $quote->getId(),
'storeId' => (string)$quote->getStore()->getId(),
]);

return $builder->build();
}

/**
* Updates the Magento order and SeQuraOrder statuses.
*
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"minimum-stability": "stable",
"require": {
"php": ">=7.4",
"sequra/integration-core": "v1.0.13",
"sequra/integration-core": "dev-fix/CS-5639",
"ext-json": "*"
},
"repositories": [
Expand Down
72 changes: 35 additions & 37 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2cd6003

Please sign in to comment.