-
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-4393: [Cart Operations] Remove item mutation #373
- Merge Pull Request magento/graphql-ce#373 from pmclain/graphql-ce:issue/37 - Merged commits: 1. 75573a9 2. beec4a4 3. 71ce4d5 4. e5c5f41 5. 445c02d
- Loading branch information
Showing
31 changed files
with
879 additions
and
287 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
59 changes: 59 additions & 0 deletions
59
app/code/Magento/QuoteGraphQl/Model/Cart/AssignBillingAddressToCart.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,59 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\QuoteGraphQl\Model\Cart; | ||
|
||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; | ||
use Magento\Quote\Api\Data\CartInterface; | ||
use Magento\Quote\Api\BillingAddressManagementInterface; | ||
use Magento\Quote\Model\Quote\Address as QuoteAddress; | ||
|
||
/** | ||
* Set billing address for a specified shopping cart | ||
*/ | ||
class AssignBillingAddressToCart | ||
{ | ||
/** | ||
* @var BillingAddressManagementInterface | ||
*/ | ||
private $billingAddressManagement; | ||
|
||
/** | ||
* @param BillingAddressManagementInterface $billingAddressManagement | ||
*/ | ||
public function __construct( | ||
BillingAddressManagementInterface $billingAddressManagement | ||
) { | ||
$this->billingAddressManagement = $billingAddressManagement; | ||
} | ||
|
||
/** | ||
* Assign billing address to cart | ||
* | ||
* @param CartInterface $cart | ||
* @param QuoteAddress $billingAddress | ||
* @param bool $useForShipping | ||
* @throws GraphQlInputException | ||
* @throws GraphQlNoSuchEntityException | ||
*/ | ||
public function execute( | ||
CartInterface $cart, | ||
QuoteAddress $billingAddress, | ||
bool $useForShipping | ||
): void { | ||
try { | ||
$this->billingAddressManagement->assign($cart->getId(), $billingAddress, $useForShipping); | ||
} catch (NoSuchEntityException $e) { | ||
throw new GraphQlNoSuchEntityException(__($e->getMessage())); | ||
} catch (LocalizedException $e) { | ||
throw new GraphQlInputException(__($e->getMessage())); | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
app/code/Magento/QuoteGraphQl/Model/Cart/AssignShippingAddressToCart.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,57 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\QuoteGraphQl\Model\Cart; | ||
|
||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; | ||
use Magento\Quote\Api\Data\CartInterface; | ||
use Magento\Quote\Model\Quote\Address as QuoteAddress; | ||
use Magento\Quote\Model\ShippingAddressManagementInterface; | ||
|
||
/** | ||
* Assign shipping address to cart | ||
*/ | ||
class AssignShippingAddressToCart | ||
{ | ||
/** | ||
* @var ShippingAddressManagementInterface | ||
*/ | ||
private $shippingAddressManagement; | ||
|
||
/** | ||
* @param ShippingAddressManagementInterface $shippingAddressManagement | ||
*/ | ||
public function __construct( | ||
ShippingAddressManagementInterface $shippingAddressManagement | ||
) { | ||
$this->shippingAddressManagement = $shippingAddressManagement; | ||
} | ||
|
||
/** | ||
* Assign shipping address to cart | ||
* | ||
* @param CartInterface $cart | ||
* @param QuoteAddress $shippingAddress | ||
* @throws GraphQlInputException | ||
* @throws GraphQlNoSuchEntityException | ||
*/ | ||
public function execute( | ||
CartInterface $cart, | ||
QuoteAddress $shippingAddress | ||
): void { | ||
try { | ||
$this->shippingAddressManagement->assign($cart->getId(), $shippingAddress); | ||
} catch (NoSuchEntityException $e) { | ||
throw new GraphQlNoSuchEntityException(__($e->getMessage())); | ||
} catch (LocalizedException $e) { | ||
throw new GraphQlInputException(__($e->getMessage())); | ||
} | ||
} | ||
} |
68 changes: 0 additions & 68 deletions
68
app/code/Magento/QuoteGraphQl/Model/Cart/ExtractDataFromCart.php
This file was deleted.
Oops, something went wrong.
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/QuoteAddressFactory.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\Customer\Api\Data\AddressInterface as CustomerAddress; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
use Magento\Quote\Model\Quote\Address as QuoteAddress; | ||
use Magento\Quote\Model\Quote\AddressFactory as BaseQuoteAddressFactory; | ||
|
||
/** | ||
* Create QuoteAddress | ||
*/ | ||
class QuoteAddressFactory | ||
{ | ||
/** | ||
* @var BaseQuoteAddressFactory | ||
*/ | ||
private $quoteAddressFactory; | ||
|
||
/** | ||
* @param BaseQuoteAddressFactory $quoteAddressFactory | ||
*/ | ||
public function __construct( | ||
BaseQuoteAddressFactory $quoteAddressFactory | ||
) { | ||
$this->quoteAddressFactory = $quoteAddressFactory; | ||
} | ||
|
||
/** | ||
* Create QuoteAddress based on input data | ||
* | ||
* @param array $addressInput | ||
* @return QuoteAddress | ||
*/ | ||
public function createBasedOnInputData(array $addressInput): QuoteAddress | ||
{ | ||
$addressInput['country_id'] = $addressInput['country_code'] ?? ''; | ||
|
||
$quoteAddress = $this->quoteAddressFactory->create(); | ||
$quoteAddress->addData($addressInput); | ||
return $quoteAddress; | ||
} | ||
|
||
/** | ||
* Create QuoteAddress based on CustomerAddress | ||
* | ||
* @param CustomerAddress $customerAddress | ||
* @return QuoteAddress | ||
* @throws GraphQlInputException | ||
*/ | ||
public function createBasedOnCustomerAddress(CustomerAddress $customerAddress): QuoteAddress | ||
{ | ||
$quoteAddress = $this->quoteAddressFactory->create(); | ||
try { | ||
$quoteAddress->importCustomerAddressData($customerAddress); | ||
} catch (LocalizedException $e) { | ||
throw new GraphQlInputException(__($e->getMessage())); | ||
} | ||
return $quoteAddress; | ||
} | ||
} |
Oops, something went wrong.