Skip to content

Commit 22d9923

Browse files
author
Prabhu Ram
committed
Merge branch 'MC-18402' of github.com:magento-honey-badgers/magento2ce into MC-18402
2 parents 363e270 + 52ef22b commit 22d9923

File tree

2 files changed

+91
-4
lines changed

2 files changed

+91
-4
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/CartPromotionsTest.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,93 @@ public function testCartPromotionsSingleCartRulesWithTaxes()
267267
}
268268
}
269269

270+
/**
271+
* Apply cart rule with a fixed discount when specific coupon code
272+
*
273+
* @magentoApiDataFixture Magento/Catalog/_files/multiple_products.php
274+
* @magentoApiDataFixture Magento/SalesRule/_files/coupon_code_with_wildcard.php
275+
*/
276+
public function testCartPromotionsWithCoupons()
277+
{
278+
$objectManager = Bootstrap::getObjectManager();
279+
/** @var ProductRepositoryInterface $productRepository */
280+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
281+
/** @var Product $prod2 */
282+
$prod1 = $productRepository->get('simple1');
283+
$prod2 = $productRepository->get('simple2');
284+
$productsInCart = [$prod1, $prod2];
285+
$prod2->setVisibility(Visibility::VISIBILITY_BOTH);
286+
$productRepository->save($prod2);
287+
$skus =['simple1', 'simple2'];
288+
289+
/** @var Collection $ruleCollection */
290+
$ruleCollection = $objectManager->get(Collection::class);
291+
$ruleLabels = [];
292+
/** @var Rule $rule */
293+
foreach ($ruleCollection as $rule) {
294+
$ruleLabels = $rule->getStoreLabels();
295+
}
296+
$qty = 2;
297+
// coupon code obtained from the fixture
298+
$couponCode = '2?ds5!2d';
299+
$cartId = $this->createEmptyCart();
300+
$this->addMultipleSimpleProductsToCart($cartId, $qty, $skus[0], $skus[1]);
301+
$this->applyCouponToCart($cartId, $couponCode);
302+
$query = $this->getCartItemPricesQuery($cartId);
303+
$response = $this->graphQlMutation($query);
304+
$this->assertCount(2, $response['cart']['items']);
305+
$productsInResponse = array_map(null, $response['cart']['items'], $productsInCart);
306+
$count = count($productsInCart);
307+
for ($itemIndex = 0; $itemIndex < $count; $itemIndex++) {
308+
$this->assertNotEmpty($productsInResponse[$itemIndex]);
309+
$sumOfPricesForBothProducts = 43.96;
310+
$rowTotal = ($productsInCart[$itemIndex]->getSpecialPrice()*$qty);
311+
$this->assertResponseFields(
312+
$productsInResponse[$itemIndex][0],
313+
[
314+
'quantity' => $qty,
315+
'prices' => [
316+
'row_total' => ['value' => $productsInCart[$itemIndex]->getSpecialPrice()*$qty],
317+
'row_total_including_tax' => ['value' => $productsInCart[$itemIndex]->getSpecialPrice()*$qty],
318+
'discount' => ['value' => round(($rowTotal/$sumOfPricesForBothProducts)*5, 2)],
319+
'discounts' => [
320+
0 =>[
321+
'amount' =>
322+
['value' => round(($rowTotal/$sumOfPricesForBothProducts)*5, 2)],
323+
'label' => $ruleLabels[0]
324+
]
325+
]
326+
],
327+
]
328+
);
329+
}
330+
}
331+
332+
/**
333+
* Apply coupon to the cart
334+
*
335+
* @param string $cartId
336+
* @param string $couponCode
337+
*/
338+
private function applyCouponToCart(string $cartId, string $couponCode)
339+
{
340+
$query = <<<QUERY
341+
mutation {
342+
applyCouponToCart(input: {cart_id: "$cartId", coupon_code: "$couponCode"}) {
343+
cart {
344+
applied_coupon {
345+
code
346+
}
347+
}
348+
}
349+
}
350+
QUERY;
351+
$response = $this->graphQlMutation($query);
352+
353+
self::assertArrayHasKey('applyCouponToCart', $response);
354+
self::assertEquals($couponCode, $response['applyCouponToCart']['cart']['applied_coupon']['code']);
355+
}
356+
270357
/**
271358
* @param string $cartId
272359
* @return string

setup/performance-toolkit/benchmark.jmx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41934,7 +41934,7 @@ vars.put("product_sku", product.get("sku"));
4193441934
<collectionProp name="Arguments.arguments">
4193541935
<elementProp name="" elementType="HTTPArgument">
4193641936
<boolProp name="HTTPArgument.always_encode">false</boolProp>
41937-
<stringProp name="Argument.value">{"query":"{\n cart(cart_id: \"${quote_id}\") {\n items {\n id\n quantity\n product {\n sku\n }\n }\n }\n}","variables":null,"operationName":null}</stringProp>
41937+
<stringProp name="Argument.value">{"query":"{\n cart(cart_id: \"${quote_id}\") {\n items {\n id\n quantity\n prices {\n row_total{\n value\n }\n row_total_including_tax{\n value\n }\n total_item_discount{value}\n discounts{\n amount{value}\n label\n }\n }\n product {\n sku\n }\n }\n prices {\n applied_taxes {\n amount {\n currency\n value\n }\n label\n }\n discounts {\n amount {\n currency\n value\n }\n label\n }\n grand_total {\n currency\n value\n }\n subtotal_excluding_tax {\n value\n currency\n }\n subtotal_including_tax {\n value\n currency\n }\n subtotal_with_discount_excluding_tax {\n value\n currency\n }\n }\n }\n}\n","variables":null,"operationName":null}</stringProp>
4193841938
<stringProp name="Argument.metadata">=</stringProp>
4193941939
</elementProp>
4194041940
</collectionProp>
@@ -42240,7 +42240,7 @@ vars.put("product_sku", product.get("sku"));
4224042240
<collectionProp name="Arguments.arguments">
4224142241
<elementProp name="" elementType="HTTPArgument">
4224242242
<boolProp name="HTTPArgument.always_encode">false</boolProp>
42243-
<stringProp name="Argument.value">{"query":"{\n cart(cart_id: \"${quote_id}\") {\n items {\n id\n quantity\n product {\n sku\n }\n }\n }\n}","variables":null,"operationName":null}</stringProp>
42243+
<stringProp name="Argument.value">{"query":"{\n cart(cart_id: \"${quote_id}\") {\n items {\n id\n quantity\n prices {\n row_total{\n value\n }\n row_total_including_tax{\n value\n }\n total_item_discount{value}\n discounts{\n amount{value}\n label\n }\n }\n product {\n sku\n }\n }\n prices {\n applied_taxes {\n amount {\n currency\n value\n }\n label\n }\n discounts {\n amount {\n currency\n value\n }\n label\n }\n grand_total {\n currency\n value\n }\n subtotal_excluding_tax {\n value\n currency\n }\n subtotal_including_tax {\n value\n currency\n }\n subtotal_with_discount_excluding_tax {\n value\n currency\n }\n }\n }\n}\n","variables":null,"operationName":null}</stringProp>
4224442244
<stringProp name="Argument.metadata">=</stringProp>
4224542245
</elementProp>
4224642246
</collectionProp>
@@ -42498,7 +42498,7 @@ vars.put("product_sku", product.get("sku"));
4249842498
<collectionProp name="Arguments.arguments">
4249942499
<elementProp name="" elementType="HTTPArgument">
4250042500
<boolProp name="HTTPArgument.always_encode">false</boolProp>
42501-
<stringProp name="Argument.value">{"query":"{\n cart(cart_id: \"${quote_id}\") {\n items {\n id\n quantity\n product {\n sku\n }\n }\n }\n}","variables":null,"operationName":null}</stringProp>
42501+
<stringProp name="Argument.value">{"query":"{\n cart(cart_id: \"${quote_id}\") {\n items {\n id\n quantity\n prices {\n row_total{\n value\n }\n row_total_including_tax{\n value\n }\n total_item_discount{value}\n discounts{\n amount{value}\n label\n }\n }\n product {\n sku\n }\n }\n prices {\n applied_taxes {\n amount {\n currency\n value\n }\n label\n }\n discounts {\n amount {\n currency\n value\n }\n label\n }\n grand_total {\n currency\n value\n }\n subtotal_excluding_tax {\n value\n currency\n }\n subtotal_including_tax {\n value\n currency\n }\n subtotal_with_discount_excluding_tax {\n value\n currency\n }\n }\n }\n}\n","variables":null,"operationName":null}</stringProp>
4250242502
<stringProp name="Argument.metadata">=</stringProp>
4250342503
</elementProp>
4250442504
</collectionProp>
@@ -42804,7 +42804,7 @@ vars.put("product_sku", product.get("sku"));
4280442804
<collectionProp name="Arguments.arguments">
4280542805
<elementProp name="" elementType="HTTPArgument">
4280642806
<boolProp name="HTTPArgument.always_encode">false</boolProp>
42807-
<stringProp name="Argument.value">{"query":"{\n cart(cart_id: \"${quote_id}\") {\n items {\n id\n quantity\n product {\n sku\n }\n }\n }\n}","variables":null,"operationName":null}</stringProp>
42807+
<stringProp name="Argument.value">{"query":"{\n cart(cart_id: \"${quote_id}\") {\n items {\n id\n quantity\n prices {\n row_total{\n value\n }\n row_total_including_tax{\n value\n }\n total_item_discount{value}\n discounts{\n amount{value}\n label\n }\n }\n product {\n sku\n }\n }\n prices {\n applied_taxes {\n amount {\n currency\n value\n }\n label\n }\n discounts {\n amount {\n currency\n value\n }\n label\n }\n grand_total {\n currency\n value\n }\n subtotal_excluding_tax {\n value\n currency\n }\n subtotal_including_tax {\n value\n currency\n }\n subtotal_with_discount_excluding_tax {\n value\n currency\n }\n }\n }\n}\n","variables":null,"operationName":null}</stringProp>
4280842808
<stringProp name="Argument.metadata">=</stringProp>
4280942809
</elementProp>
4281042810
</collectionProp>

0 commit comments

Comments
 (0)