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

 - Merge Pull Request magento/graphql-ce#169 from magento/graphql-ce:hashed-cart-create-refactor
 - Merged commits:
   1. 8771f41
   2. 8b6aab6
   3. afa2169
  • Loading branch information
magento-engcom-team committed Sep 17, 2018
2 parents a9ff217 + afa2169 commit e0c7383
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
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
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;
}
}
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 e0c7383

Please sign in to comment.