Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Quote masked id creation logic moved to create cart resolver #169

Merged
merged 3 commits into from
Sep 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/code/Magento/Quote/Model/MaskedQuoteIdToQuoteId.php
Original file line number Diff line number Diff line change
@@ -10,6 +10,9 @@
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask as QuoteIdMaskResource;

/**
* MaskedQuoteId to QuoteId resolver
*/
class MaskedQuoteIdToQuoteId implements MaskedQuoteIdToQuoteIdInterface
{
/**
20 changes: 16 additions & 4 deletions app/code/Magento/Quote/Model/QuoteIdToMaskedQuoteId.php
Original file line number Diff line number Diff line change
@@ -8,29 +8,40 @@
namespace Magento\Quote\Model;

use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask as QuoteIdMaskResource;

/**
* QuoteId to MaskedQuoteId resolver
*/
class QuoteIdToMaskedQuoteId implements QuoteIdToMaskedQuoteIdInterface
{
/**
* @var QuoteIdMaskFactory
*/
private $quoteIdMaskFactory;

/**
* @var CartRepositoryInterface
*/
private $cartRepository;

/**
* @var QuoteIdMaskResource
*/
private $quoteIdMaskResource;

/**
* @param QuoteIdMaskFactory $quoteIdMaskFactory
* @param CartRepositoryInterface $cartRepository
* @param QuoteIdMaskResource $quoteIdMaskResource
*/
public function __construct(
QuoteIdMaskFactory $quoteIdMaskFactory,
CartRepositoryInterface $cartRepository
CartRepositoryInterface $cartRepository,
QuoteIdMaskResource $quoteIdMaskResource
) {
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
$this->cartRepository = $cartRepository;
$this->quoteIdMaskResource = $quoteIdMaskResource;
}

/**
@@ -42,8 +53,9 @@ public function execute(int $quoteId): string
$this->cartRepository->get($quoteId);

$quoteIdMask = $this->quoteIdMaskFactory->create();
$quoteIdMask->setQuoteId($quoteId)->save();
$this->quoteIdMaskResource->load($quoteIdMask, $quoteId, 'quote_id');
$maskedId = $quoteIdMask->getMaskedId() ?? '';

return $quoteIdMask->getMaskedId();
return $maskedId;
}
}
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
use Magento\Quote\Api\CartManagementInterface;
use Magento\Quote\Api\GuestCartManagementInterface;
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
use Magento\Quote\Model\QuoteIdMaskFactory;

/**
* @inheritdoc
@@ -26,7 +27,6 @@ class CreateEmptyCart implements ResolverInterface
* @var CartManagementInterface
*/
private $cartManagement;

/**
* @var GuestCartManagementInterface
*/
@@ -47,25 +47,33 @@ class CreateEmptyCart implements ResolverInterface
*/
private $userContext;

/**
* @var QuoteIdMaskFactory
*/
private $quoteIdMaskFactory;

/**
* @param CartManagementInterface $cartManagement
* @param GuestCartManagementInterface $guestCartManagement
* @param ValueFactory $valueFactory
* @param UserContextInterface $userContext
* @param QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedId
* @param QuoteIdMaskFactory $quoteIdMaskFactory
*/
public function __construct(
CartManagementInterface $cartManagement,
GuestCartManagementInterface $guestCartManagement,
ValueFactory $valueFactory,
UserContextInterface $userContext,
QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedId
QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedId,
QuoteIdMaskFactory $quoteIdMaskFactory
) {
$this->cartManagement = $cartManagement;
$this->guestCartManagement = $guestCartManagement;
$this->valueFactory = $valueFactory;
$this->userContext = $userContext;
$this->quoteIdToMaskedId = $quoteIdToMaskedId;
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
}

/**
@@ -77,7 +85,13 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value

if (0 !== $customerId && null !== $customerId) {
$quoteId = $this->cartManagement->createEmptyCartForCustomer($customerId);
$maskedQuoteId = $this->quoteIdToMaskedId->execute($quoteId);
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quoteId);

if (empty($maskedQuoteId)) {
$quoteIdMask = $this->quoteIdMaskFactory->create();
$quoteIdMask->setQuoteId($quoteId)->save();
$maskedQuoteId = $quoteIdMask->getMaskedId();
}
} else {
$maskedQuoteId = $this->guestCartManagement->createEmptyCart();
}