-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENGCOM-4790: magento/graphql-ce#607: Expanded "createdEmptyCart" muta…
…tion with not… #610
- Loading branch information
Showing
7 changed files
with
336 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
app/code/Magento/QuoteGraphQl/Model/Cart/CreateEmptyCartForCustomer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\QuoteGraphQl\Model\Cart; | ||
|
||
use Magento\Quote\Api\CartManagementInterface; | ||
use Magento\Quote\Model\QuoteIdMaskFactory; | ||
use Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask as QuoteIdMaskResourceModel; | ||
|
||
/** | ||
* Create empty cart for customer | ||
*/ | ||
class CreateEmptyCartForCustomer | ||
{ | ||
/** | ||
* @var CartManagementInterface | ||
*/ | ||
private $cartManagement; | ||
|
||
/** | ||
* @var QuoteIdMaskFactory | ||
*/ | ||
private $quoteIdMaskFactory; | ||
|
||
/** | ||
* @var QuoteIdMaskResourceModel | ||
*/ | ||
private $quoteIdMaskResourceModel; | ||
|
||
/** | ||
* @param CartManagementInterface $cartManagement | ||
* @param QuoteIdMaskFactory $quoteIdMaskFactory | ||
* @param QuoteIdMaskResourceModel $quoteIdMaskResourceModel | ||
*/ | ||
public function __construct( | ||
CartManagementInterface $cartManagement, | ||
QuoteIdMaskFactory $quoteIdMaskFactory, | ||
QuoteIdMaskResourceModel $quoteIdMaskResourceModel | ||
) { | ||
$this->cartManagement = $cartManagement; | ||
$this->quoteIdMaskFactory = $quoteIdMaskFactory; | ||
$this->quoteIdMaskResourceModel = $quoteIdMaskResourceModel; | ||
} | ||
|
||
/** | ||
* @param string|null $predefinedMaskedQuoteId | ||
* @return string | ||
*/ | ||
public function execute(int $customerId, string $predefinedMaskedQuoteId = null): string | ||
{ | ||
$quoteId = $this->cartManagement->createEmptyCartForCustomer($customerId); | ||
|
||
$quoteIdMask = $this->quoteIdMaskFactory->create(); | ||
$quoteIdMask->setQuoteId($quoteId); | ||
|
||
if (isset($predefinedMaskedQuoteId)) { | ||
$quoteIdMask->setMaskedId($predefinedMaskedQuoteId); | ||
} | ||
|
||
$this->quoteIdMaskResourceModel->save($quoteIdMask); | ||
return $quoteIdMask->getMaskedId(); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
app/code/Magento/QuoteGraphQl/Model/Cart/CreateEmptyCartForGuest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\QuoteGraphQl\Model\Cart; | ||
|
||
use Magento\Quote\Api\GuestCartManagementInterface; | ||
use Magento\Quote\Model\QuoteIdMaskFactory; | ||
use Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask as QuoteIdMaskResourceModel; | ||
|
||
/** | ||
* Create empty cart for guest | ||
*/ | ||
class CreateEmptyCartForGuest | ||
{ | ||
/** | ||
* @var GuestCartManagementInterface | ||
*/ | ||
private $guestCartManagement; | ||
|
||
/** | ||
* @var QuoteIdMaskFactory | ||
*/ | ||
private $quoteIdMaskFactory; | ||
|
||
/** | ||
* @var QuoteIdMaskResourceModel | ||
*/ | ||
private $quoteIdMaskResourceModel; | ||
|
||
/** | ||
* @param GuestCartManagementInterface $guestCartManagement | ||
* @param QuoteIdMaskFactory $quoteIdMaskFactory | ||
* @param QuoteIdMaskResourceModel $quoteIdMaskResourceModel | ||
*/ | ||
public function __construct( | ||
GuestCartManagementInterface $guestCartManagement, | ||
QuoteIdMaskFactory $quoteIdMaskFactory, | ||
QuoteIdMaskResourceModel $quoteIdMaskResourceModel | ||
) { | ||
$this->guestCartManagement = $guestCartManagement; | ||
$this->quoteIdMaskFactory = $quoteIdMaskFactory; | ||
$this->quoteIdMaskResourceModel = $quoteIdMaskResourceModel; | ||
} | ||
|
||
/** | ||
* @param string|null $predefinedMaskedQuoteId | ||
* @return string | ||
*/ | ||
public function execute(string $predefinedMaskedQuoteId = null): string | ||
{ | ||
$maskedQuoteId = $this->guestCartManagement->createEmptyCart(); | ||
|
||
if (isset($predefinedMaskedQuoteId)) { | ||
$quoteIdMask = $this->quoteIdMaskFactory->create(); | ||
$this->quoteIdMaskResourceModel->load($quoteIdMask, $maskedQuoteId, 'masked_id'); | ||
|
||
$quoteIdMask->setMaskedId($predefinedMaskedQuoteId); | ||
$this->quoteIdMaskResourceModel->save($quoteIdMask); | ||
} | ||
return $predefinedMaskedQuoteId ?? $maskedQuoteId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.