Skip to content

Commit

Permalink
Merge pull request #3780 from magento-arcticfoxes/2.3.1-qwerty-pr
Browse files Browse the repository at this point in the history
[arcticfoxes] sync 2.3.1-qwerty with 2.3.1-release PR
  • Loading branch information
joanhe authored Feb 20, 2019
2 parents 4b1d04f + 62c8151 commit f34a59f
Show file tree
Hide file tree
Showing 19 changed files with 654 additions and 849 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,16 @@ public function execute(Quote $cart, array $cartItemData): void
throw new GraphQlNoSuchEntityException(__('Could not find a product with SKU "%sku"', ['sku' => $sku]));
}

$result = $cart->addProduct($product, $this->createBuyRequest($qty, $customizableOptions));
try {
$result = $cart->addProduct($product, $this->createBuyRequest($qty, $customizableOptions));
} catch (\Exception $e) {
throw new GraphQlInputException(
__(
'Could not add the product with SKU %sku to the shopping cart: %message',
['sku' => $sku, 'message' => $e->getMessage()]
)
);
}

if (is_string($result)) {
throw new GraphQlInputException(__($result));
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,42 @@
*/
declare(strict_types=1);

namespace Magento\QuoteGraphQl\Model\Cart\Address\Mapper;
namespace Magento\QuoteGraphQl\Model\Cart;

use Magento\Framework\Api\ExtensibleDataObjectConverter;
use Magento\Quote\Api\Data\AddressInterface;
use Magento\Quote\Model\Quote\Address as QuoteAddress;

/**
* Class Address
*
* Extract the necessary address fields from an Address model
*/
class Address
class ExtractDataFromAddress
{
/**
* Converts Address model data to nested array
* @var ExtensibleDataObjectConverter
*/
private $dataObjectConverter;

/**
* @param ExtensibleDataObjectConverter $dataObjectConverter
*/
public function __construct(ExtensibleDataObjectConverter $dataObjectConverter)
{
$this->dataObjectConverter = $dataObjectConverter;
}

/**
* Converts Address model to flat array
*
* @param QuoteAddress $address
* @return array
*/
public function toNestedArray(QuoteAddress $address): array
public function execute(QuoteAddress $address): array
{
$addressData = [
$addressData = $this->dataObjectConverter->toFlatArray($address, [], AddressInterface::class);
$addressData['model'] = $address;

$addressData = array_merge($addressData, [
'country' => [
'code' => $address->getCountryId(),
'label' => $address->getCountry()
Expand All @@ -41,7 +57,7 @@ public function toNestedArray(QuoteAddress $address): array
],
'items_weight' => $address->getWeight(),
'customer_notes' => $address->getCustomerNotes()
];
]);

if (!$address->hasItems()) {
return $addressData;
Expand Down
18 changes: 18 additions & 0 deletions app/code/Magento/QuoteGraphQl/Model/Cart/ExtractDataFromCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,36 @@

namespace Magento\QuoteGraphQl\Model\Cart;

use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Quote\Model\Quote;
use Magento\Quote\Model\Quote\Item as QuoteItem;
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;

/**
* Extract data from cart
*/
class ExtractDataFromCart
{
/**
* @var QuoteIdToMaskedQuoteIdInterface
*/
private $quoteIdToMaskedQuoteId;

/**
* @param QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
*/
public function __construct(
QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
) {
$this->quoteIdToMaskedQuoteId = $quoteIdToMaskedQuoteId;
}

/**
* Extract data from cart
*
* @param Quote $cart
* @return array
* @throws NoSuchEntityException
*/
public function execute(Quote $cart): array
{
Expand All @@ -43,6 +60,7 @@ public function execute(Quote $cart): array
$appliedCoupon = $cart->getCouponCode();

return [
'cart_id' => $this->quoteIdToMaskedQuoteId->execute((int)$cart->getId()),
'items' => $items,
'applied_coupon' => $appliedCoupon ? ['code' => $appliedCoupon] : null
];
Expand Down
Loading

0 comments on commit f34a59f

Please sign in to comment.