Skip to content

Commit

Permalink
ENGCOM-4850: Fix Quote Schema inconsistency #634
Browse files Browse the repository at this point in the history
  • Loading branch information
naydav authored Apr 29, 2019
2 parents 2426688 + 9a887ee commit b76602b
Show file tree
Hide file tree
Showing 22 changed files with 135 additions and 135 deletions.
24 changes: 12 additions & 12 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/qty', $cartItemData);
if (!isset($qty)) {
throw new GraphQlInputException(__('Missing key "qty" in cart item data'));
$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
2 changes: 1 addition & 1 deletion app/code/Magento/QuoteGraphQl/Model/Resolver/CartItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value

$itemsData[] = [
'id' => $cartItem->getItemId(),
'qty' => $cartItem->getQty(),
'quantity' => $cartItem->getQty(),
'product' => $productData,
'model' => $cartItem,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,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 @@ -108,10 +108,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->validateCartItem($cartItem);
$this->cartItemRepository->save($cartItem);
}
Expand Down
8 changes: 4 additions & 4 deletions app/code/Magento/QuoteGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ input VirtualProductCartItemInput {

input CartItemInput {
sku: String!
qty: Float!
quantity: Float!
}

input CustomizableOptionInput {
Expand All @@ -62,10 +62,10 @@ input ApplyCouponToCartInput {

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

input CartItemQuantityInput {
input CartItemUpdateInput {
cart_item_id: Int!
quantity: Float!
}
Expand Down Expand Up @@ -304,7 +304,7 @@ type VirtualCartItem implements CartItemInterface @doc(description: "Virtual Car

interface CartItemInterface @typeResolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\CartItemTypeResolver") {
id: String!
qty: Float!
quantity: Float!
product: ProductInterface!
}

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 Expand Up @@ -115,7 +115,7 @@ private function getQuery(string $maskedQuoteId, string $sku, float $qty) : stri
cartItems: [
{
data: {
qty: $qty
quantity: $qty
sku: "$sku"
}
}
Expand All @@ -124,7 +124,7 @@ private function getQuery(string $maskedQuoteId, string $sku, float $qty) : stri
) {
cart {
items {
qty
quantity
}
}
}
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]['qty']);
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: {
qty: {$qty}
quantity: {$quantity}
sku: "{$variantSku}"
}
}
Expand All @@ -107,7 +107,7 @@ private function getQuery(string $maskedQuoteId, string $variantSku, int $qty):
cart {
items {
id
qty
quantity
product {
name
sku
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: {
qty: $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: {
qty: $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: {
qty: $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: {
qty: $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]['qty']);
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: {
qty: {$qty}
quantity: {$quantity}
sku: "{$sku}"
}
}
Expand All @@ -151,7 +151,7 @@ private function getQuery(string $maskedQuoteId, string $sku, int $qty): string
cart {
items {
id
qty
quantity
product {
sku
}
Expand Down
Loading

0 comments on commit b76602b

Please sign in to comment.