Skip to content

Commit

Permalink
ENGCOM-2994: Quote masked id creation logic moved to create cart reso…
Browse files Browse the repository at this point in the history
…lver #169
  • Loading branch information
Valeriy Naida authored Sep 18, 2018
2 parents 2eb6f84 + e0c7383 commit b4461ef
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
3 changes: 3 additions & 0 deletions app/code/Magento/Quote/Model/MaskedQuoteIdToQuoteId.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand Down
20 changes: 16 additions & 4 deletions app/code/Magento/Quote/Model/QuoteIdToMaskedQuoteId.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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
Expand Up @@ -14,6 +14,7 @@
use Magento\Quote\Api\CartManagementInterface;
use Magento\Quote\Api\GuestCartManagementInterface;
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
use Magento\Quote\Model\QuoteIdMaskFactory;

/**
* @inheritdoc
Expand All @@ -24,7 +25,6 @@ class CreateEmptyCart implements ResolverInterface
* @var CartManagementInterface
*/
private $cartManagement;

/**
* @var GuestCartManagementInterface
*/
Expand All @@ -40,22 +40,30 @@ class CreateEmptyCart implements ResolverInterface
*/
private $userContext;

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

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

/**
Expand All @@ -67,7 +75,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();
}
Expand Down

0 comments on commit b4461ef

Please sign in to comment.