Skip to content

Commit

Permalink
GraphQL-631: Schema inconsistency of "Quantity / Qty" declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
naydav committed Apr 29, 2019
1 parent e8f1369 commit 035f602
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type AddConfigurableProductsToCartOutput {
}

input ConfigurableProductCartItemInput {
data: CartItemQuantityInput!
data: CartItemInput!
variant_sku: String!
customizable_options:[CustomizableOptionInput!]
}
Expand Down
22 changes: 11 additions & 11 deletions app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public function __construct(
public function execute(Quote $cart, array $cartItemData): void
{
$sku = $this->extractSku($cartItemData);
$qty = $this->extractQty($cartItemData);
if ($qty <= 0) {
$quantity = $this->extractQuantity($cartItemData);
if ($quantity <= 0) {
throw new GraphQlInputException(
__('Please enter a number greater than 0 in this field.')
);
Expand All @@ -81,7 +81,7 @@ public function execute(Quote $cart, array $cartItemData): void
}

try {
$result = $cart->addProduct($product, $this->createBuyRequest($qty, $customizableOptions));
$result = $cart->addProduct($product, $this->createBuyRequest($quantity, $customizableOptions));
} catch (\Exception $e) {
throw new GraphQlInputException(
__(
Expand Down Expand Up @@ -113,19 +113,19 @@ private function extractSku(array $cartItemData): string
}

/**
* Extract Qty from cart item data
* Extract quantity from cart item data
*
* @param array $cartItemData
* @return float
* @throws GraphQlInputException
*/
private function extractQty(array $cartItemData): float
private function extractQuantity(array $cartItemData): float
{
$qty = $this->arrayManager->get('data/quantity', $cartItemData);
if (!isset($qty)) {
$quantity = $this->arrayManager->get('data/quantity', $cartItemData);
if (!isset($quantity)) {
throw new GraphQlInputException(__('Missing key "quantity" in cart item data'));
}
return (float)$qty;
return (float)$quantity;
}

/**
Expand All @@ -148,15 +148,15 @@ private function extractCustomizableOptions(array $cartItemData): array
/**
* Format GraphQl input data to a shape that buy request has
*
* @param float $qty
* @param float $quantity
* @param array $customOptions
* @return DataObject
*/
private function createBuyRequest(float $qty, array $customOptions): DataObject
private function createBuyRequest(float $quantity, array $customOptions): DataObject
{
return $this->dataObjectFactory->create([
'data' => [
'qty' => $qty,
'qty' => $quantity,
'options' => $customOptions,
],
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private function processCartItems(Quote $cart, array $items): void
if (!isset($item['quantity'])) {
throw new GraphQlInputException(__('Required parameter "quantity" for "cart_items" is missing.'));
}
$qty = (float)$item['quantity'];
$quantity = (float)$item['quantity'];

$cartItem = $cart->getItemById($itemId);
if ($cartItem === false) {
Expand All @@ -107,10 +107,10 @@ private function processCartItems(Quote $cart, array $items): void
);
}

if ($qty <= 0.0) {
if ($quantity <= 0.0) {
$this->cartItemRepository->deleteById((int)$cart->getId(), $itemId);
} else {
$cartItem->setQty($qty);
$cartItem->setQty($quantity);
$this->cartItemRepository->save($cartItem);
}
}
Expand Down
10 changes: 5 additions & 5 deletions app/code/Magento/QuoteGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ input AddSimpleProductsToCartInput {
}

input SimpleProductCartItemInput {
data: CartItemQuantityInput!
data: CartItemInput!
customizable_options:[CustomizableOptionInput!]
}

Expand All @@ -41,11 +41,11 @@ input AddVirtualProductsToCartInput {
}

input VirtualProductCartItemInput {
data: CartItemQuantityInput!
data: CartItemInput!
customizable_options:[CustomizableOptionInput!]
}

input CartItemQuantityInput {
input CartItemInput {
sku: String!
quantity: Float!
}
Expand All @@ -62,10 +62,10 @@ input ApplyCouponToCartInput {

input UpdateCartItemsInput {
cart_id: String!
cart_items: [CartItemUpdateQuantityInput!]!
cart_items: [CartItemUpdateInput!]!
}

input CartItemUpdateQuantityInput {
input CartItemUpdateInput {
cart_item_id: Int!
quantity: Float!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ protected function setUp()
public function testAddProductIfQuantityIsNotAvailable()
{
$sku = 'simple';
$qty = 200;
$quantity = 200;
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');

$query = $this->getQuery($maskedQuoteId, $sku, $qty);
$query = $this->getQuery($maskedQuoteId, $sku, $quantity);
$this->graphQlMutation($query);
}

Expand All @@ -58,10 +58,10 @@ public function testAddMoreProductsThatAllowed()
$this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/167');

$sku = 'custom-design-simple-product';
$qty = 7;
$quantity = 7;
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');

$query = $this->getQuery($maskedQuoteId, $sku, $qty);
$query = $this->getQuery($maskedQuoteId, $sku, $quantity);
$this->graphQlMutation($query);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ protected function setUp()
public function testAddConfigurableProductToCart()
{
$variantSku = 'simple_41';
$qty = 2;
$quantity = 2;
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');

$query = $this->getQuery($maskedQuoteId, $variantSku, $qty);
$query = $this->getQuery($maskedQuoteId, $variantSku, $quantity);
$response = $this->graphQlMutation($query);

$cartItems = $response['addConfigurableProductsToCart']['cart']['items'];
self::assertEquals($qty, $cartItems[0]['quantity']);
self::assertEquals($quantity, $cartItems[0]['quantity']);
self::assertEquals($variantSku, $cartItems[0]['product']['sku']);
}

Expand All @@ -57,10 +57,10 @@ public function testAddConfigurableProductToCart()
public function testAddProductIfQuantityIsNotAvailable()
{
$variantSku = 'simple_41';
$qty = 200;
$quantity = 200;
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');

$query = $this->getQuery($maskedQuoteId, $variantSku, $qty);
$query = $this->getQuery($maskedQuoteId, $variantSku, $quantity);
$this->graphQlMutation($query);
}

Expand All @@ -73,20 +73,20 @@ public function testAddProductIfQuantityIsNotAvailable()
public function testAddOutOfStockProduct()
{
$variantSku = 'simple_1010';
$qty = 1;
$quantity = 1;
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');

$query = $this->getQuery($maskedQuoteId, $variantSku, $qty);
$query = $this->getQuery($maskedQuoteId, $variantSku, $quantity);
$this->graphQlMutation($query);
}

/**
* @param string $maskedQuoteId
* @param string $variantSku
* @param int $qty
* @param int $quantity
* @return string
*/
private function getQuery(string $maskedQuoteId, string $variantSku, int $qty): string
private function getQuery(string $maskedQuoteId, string $variantSku, int $quantity): string
{
return <<<QUERY
mutation {
Expand All @@ -97,7 +97,7 @@ private function getQuery(string $maskedQuoteId, string $variantSku, int $qty):
{
variant_sku: "{$variantSku}"
data: {
quantity: {$qty}
quantity: {$quantity}
sku: "{$variantSku}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function setUp()
public function testAddSimpleProductWithOptions()
{
$sku = 'simple';
$qty = 1;
$quantity = 1;
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');

$customOptionsValues = $this->getCustomOptionsValuesForQuery($sku);
Expand All @@ -62,7 +62,7 @@ public function testAddSimpleProductWithOptions()
cartItems: [
{
data: {
quantity: $qty
quantity: $quantity
sku: "$sku"
},
customizable_options: $queryCustomizableOptions
Expand Down Expand Up @@ -110,7 +110,7 @@ public function testAddSimpleProductWithOptions()
public function testAddSimpleProductWithNoRequiredOptionsSet()
{
$sku = 'simple';
$qty = 1;
$quantity = 1;
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');

$query = <<<QUERY
Expand All @@ -121,7 +121,7 @@ public function testAddSimpleProductWithNoRequiredOptionsSet()
cartItems: [
{
data: {
quantity: $qty
quantity: $quantity
sku: "$sku"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function setUp()
public function testAddVirtualProductWithOptions()
{
$sku = 'virtual';
$qty = 1;
$quantity = 1;
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');

$customOptionsValues = $this->getCustomOptionsValuesForQuery($sku);
Expand All @@ -62,7 +62,7 @@ public function testAddVirtualProductWithOptions()
cartItems: [
{
data: {
quantity: $qty
quantity: $quantity
sku: "$sku"
},
customizable_options: $queryCustomizableOptions
Expand Down Expand Up @@ -110,7 +110,7 @@ public function testAddVirtualProductWithOptions()
public function testAddVirtualProductWithNoRequiredOptionsSet()
{
$sku = 'virtual';
$qty = 1;
$quantity = 1;
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');

$query = <<<QUERY
Expand All @@ -121,7 +121,7 @@ public function testAddVirtualProductWithNoRequiredOptionsSet()
cartItems: [
{
data: {
quantity: $qty
quantity: $quantity
sku: "$sku"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ protected function setUp()
public function testAddSimpleProductToCart()
{
$sku = 'simple_product';
$qty = 2;
$quantity = 2;
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
$query = $this->getQuery($maskedQuoteId, $sku, $qty);
$query = $this->getQuery($maskedQuoteId, $sku, $quantity);
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMap());

self::assertArrayHasKey('cart', $response['addSimpleProductsToCart']);
self::assertEquals($qty, $response['addSimpleProductsToCart']['cart']['items'][0]['quantity']);
self::assertEquals($quantity, $response['addSimpleProductsToCart']['cart']['items'][0]['quantity']);
self::assertEquals($sku, $response['addSimpleProductsToCart']['cart']['items'][0]['product']['sku']);
}

Expand All @@ -63,10 +63,10 @@ public function testAddSimpleProductToCart()
public function testAddProductToNonExistentCart()
{
$sku = 'simple_product';
$qty = 2;
$quantity = 2;
$maskedQuoteId = 'non_existent_masked_id';

$query = $this->getQuery($maskedQuoteId, $sku, $qty);
$query = $this->getQuery($maskedQuoteId, $sku, $quantity);
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
}

Expand Down Expand Up @@ -130,10 +130,10 @@ public function testAddSimpleProductToAnotherCustomerCart()
/**
* @param string $maskedQuoteId
* @param string $sku
* @param int $qty
* @param float $quantity
* @return string
*/
private function getQuery(string $maskedQuoteId, string $sku, int $qty): string
private function getQuery(string $maskedQuoteId, string $sku, float $quantity): string
{
return <<<QUERY
mutation {
Expand All @@ -142,7 +142,7 @@ private function getQuery(string $maskedQuoteId, string $sku, int $qty): string
cartItems: [
{
data: {
quantity: {$qty}
quantity: {$quantity}
sku: "{$sku}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ protected function setUp()
public function testAddVirtualProductToCart()
{
$sku = 'virtual_product';
$qty = 2;
$quantity = 2;
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
$query = $this->getQuery($maskedQuoteId, $sku, $qty);
$query = $this->getQuery($maskedQuoteId, $sku, $quantity);
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMap());

self::assertArrayHasKey('cart', $response['addVirtualProductsToCart']);
self::assertEquals($qty, $response['addVirtualProductsToCart']['cart']['items'][0]['quantity']);
self::assertEquals($quantity, $response['addVirtualProductsToCart']['cart']['items'][0]['quantity']);
self::assertEquals($sku, $response['addVirtualProductsToCart']['cart']['items'][0]['product']['sku']);
}

Expand Down Expand Up @@ -130,10 +130,10 @@ public function testAddVirtualProductToAnotherCustomerCart()
/**
* @param string $maskedQuoteId
* @param string $sku
* @param int $qty
* @param float $quantity
* @return string
*/
private function getQuery(string $maskedQuoteId, string $sku, int $qty): string
private function getQuery(string $maskedQuoteId, string $sku, float $quantity): string
{
return <<<QUERY
mutation {
Expand All @@ -142,7 +142,7 @@ private function getQuery(string $maskedQuoteId, string $sku, int $qty): string
cartItems: [
{
data: {
quantity: {$qty}
quantity: {$quantity}
sku: "{$sku}"
}
}
Expand Down
Loading

0 comments on commit 035f602

Please sign in to comment.