Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

[WIP] Remove “cart_address_id” from “ShippingMethodInput” #609

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public function execute(QuoteAddress $address): array
}

$addressData = array_merge($addressData, [
'address_id' => $address->getId(),
'address_type' => $addressType,
'country' => [
'code' => $address->getCountryId(),
Expand Down
83 changes: 0 additions & 83 deletions app/code/Magento/QuoteGraphQl/Model/Cart/GetQuoteAddress.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,17 @@
*/
class SetShippingMethodsOnCart implements SetShippingMethodsOnCartInterface
{
/**
* @var GetQuoteAddress
*/
private $getQuoteAddress;

/**
* @var AssignShippingMethodToCart
*/
private $assignShippingMethodToCart;

/**
* @param GetQuoteAddress $getQuoteAddress
* @param AssignShippingMethodToCart $assignShippingMethodToCart
*/
public function __construct(
GetQuoteAddress $getQuoteAddress,
AssignShippingMethodToCart $assignShippingMethodToCart
) {
$this->getQuoteAddress = $getQuoteAddress;
$this->assignShippingMethodToCart = $assignShippingMethodToCart;
}

Expand All @@ -50,11 +42,6 @@ public function execute(ContextInterface $context, CartInterface $cart, array $s
}
$shippingMethodInput = current($shippingMethodsInput);

if (!isset($shippingMethodInput['cart_address_id']) || empty($shippingMethodInput['cart_address_id'])) {
throw new GraphQlInputException(__('Required parameter "cart_address_id" is missing.'));
}
$cartAddressId = $shippingMethodInput['cart_address_id'];

if (!isset($shippingMethodInput['carrier_code']) || empty($shippingMethodInput['carrier_code'])) {
throw new GraphQlInputException(__('Required parameter "carrier_code" is missing.'));
}
Expand All @@ -65,7 +52,7 @@ public function execute(ContextInterface $context, CartInterface $cart, array $s
}
$methodCode = $shippingMethodInput['method_code'];

$quoteAddress = $this->getQuoteAddress->execute($cart, $cartAddressId, $context->getUserId());
$this->assignShippingMethodToCart->execute($cart, $quoteAddress, $carrierCode, $methodCode);
$shippingAddress = $cart->getShippingAddress();
$this->assignShippingMethodToCart->execute($cart, $shippingAddress, $carrierCode, $methodCode);
}
}
2 changes: 0 additions & 2 deletions app/code/Magento/QuoteGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ input SetShippingMethodsOnCartInput {
}

input ShippingMethodInput {
cart_address_id: Int!
carrier_code: String!
method_code: String!
}
Expand Down Expand Up @@ -188,7 +187,6 @@ type Cart {
}

type CartAddress {
address_id: Int
firstname: String
lastname: String
company: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ public function testCheckoutWorkflow()
$this->addProductToCart($cartId, $qty, $sku);

$this->setBillingAddress($cartId);
$shippingAddress = $this->setShippingAddress($cartId);
$shippingMethod = $this->setShippingAddress($cartId);

$shippingMethod = current($shippingAddress['available_shipping_methods']);
$paymentMethod = $this->setShippingMethod($cartId, $shippingAddress['address_id'], $shippingMethod);
$paymentMethod = $this->setShippingMethod($cartId, $shippingMethod);
$this->setPaymentMethod($cartId, $paymentMethod);

$orderId = $this->placeOrder($cartId);
Expand Down Expand Up @@ -307,7 +306,6 @@ private function setShippingAddress(string $cartId): array
) {
cart {
shipping_addresses {
address_id
available_shipping_methods {
carrier_code
method_code
Expand All @@ -325,8 +323,6 @@ private function setShippingAddress(string $cartId): array
self::assertCount(1, $response['setShippingAddressesOnCart']['cart']['shipping_addresses']);

$shippingAddress = current($response['setShippingAddressesOnCart']['cart']['shipping_addresses']);
self::assertArrayHasKey('address_id', $shippingAddress);
self::assertNotEmpty($shippingAddress['address_id']);
self::assertArrayHasKey('available_shipping_methods', $shippingAddress);
self::assertCount(1, $shippingAddress['available_shipping_methods']);

Expand All @@ -340,24 +336,22 @@ private function setShippingAddress(string $cartId): array
self::assertArrayHasKey('amount', $availableShippingMethod);
self::assertNotEmpty($availableShippingMethod['amount']);

return $shippingAddress;
return $availableShippingMethod;
}

/**
* @param string $cartId
* @param int $addressId
* @param array $method
* @return array
*/
private function setShippingMethod(string $cartId, int $addressId, array $method): array
private function setShippingMethod(string $cartId, array $method): array
{
$query = <<<QUERY
mutation {
setShippingMethodsOnCart(input: {
cart_id: "{$cartId}",
shipping_methods: [
{
cart_address_id: {$addressId}
carrier_code: "{$method['carrier_code']}"
method_code: "{$method['method_code']}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace Magento\GraphQl\Quote\Customer;

use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
use Magento\GraphQl\Quote\GetQuoteShippingAddressIdByReservedQuoteId;
use Magento\Integration\Api\CustomerTokenServiceInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\GraphQlAbstract;
Expand All @@ -23,11 +22,6 @@ class SetOfflineShippingMethodsOnCartTest extends GraphQlAbstract
*/
private $getMaskedQuoteIdByReservedOrderId;

/**
* @var GetQuoteShippingAddressIdByReservedQuoteId
*/
private $getQuoteShippingAddressIdByReservedQuoteId;

/**
* @var CustomerTokenServiceInterface
*/
Expand All @@ -40,9 +34,6 @@ protected function setUp()
{
$objectManager = Bootstrap::getObjectManager();
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
$this->getQuoteShippingAddressIdByReservedQuoteId = $objectManager->get(
GetQuoteShippingAddressIdByReservedQuoteId::class
);
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
}

Expand All @@ -64,13 +55,11 @@ protected function setUp()
public function testSetOfflineShippingMethod(string $carrierCode, string $methodCode, float $amount, string $label)
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
$quoteAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute('test_quote');

$query = $this->getQuery(
$maskedQuoteId,
$methodCode,
$carrierCode,
$quoteAddressId
$carrierCode
);
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMap());

Expand Down Expand Up @@ -111,22 +100,19 @@ public function offlineShippingMethodDataProvider(): array
* @param string $maskedQuoteId
* @param string $shippingMethodCode
* @param string $shippingCarrierCode
* @param int $shippingAddressId
* @return string
*/
private function getQuery(
string $maskedQuoteId,
string $shippingMethodCode,
string $shippingCarrierCode,
int $shippingAddressId
string $shippingCarrierCode
): string {
return <<<QUERY
mutation {
setShippingMethodsOnCart(input:
{
cart_id: "$maskedQuoteId",
shipping_methods: [{
cart_address_id: $shippingAddressId
carrier_code: "$shippingCarrierCode"
method_code: "$shippingMethodCode"
}]
Expand Down
Loading