Skip to content

Commit a1de60d

Browse files
authored
Merge branch 'magento-commerce:2.4-develop' into eav-graphql
2 parents bd8c356 + af9ab20 commit a1de60d

File tree

12 files changed

+14535
-14337
lines changed

12 files changed

+14535
-14337
lines changed

app/code/Magento/CatalogGraphQl/DataProvider/Product/LayeredNavigation/AttributeOptionProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public function getOptions(array $optionIds, ?int $storeId, array $attributeCode
6363
'attribute_id' => 'a.attribute_id',
6464
'attribute_code' => 'a.attribute_code',
6565
'attribute_label' => 'a.frontend_label',
66+
'attribute_type' => 'a.frontend_input',
6667
'position' => 'attribute_configuration.position'
6768
]
6869
)
@@ -137,6 +138,7 @@ private function formatResult(Select $select): array
137138
'attribute_code' => $option['attribute_code'],
138139
'attribute_label' => $option['attribute_store_label']
139140
? $option['attribute_store_label'] : $option['attribute_label'],
141+
'attribute_type' => $option['attribute_type'],
140142
'position' => $option['position'],
141143
'options' => [],
142144
];

app/code/Magento/CatalogGraphQl/DataProvider/Product/LayeredNavigation/Builder/Attribute.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Framework\Api\Search\AggregationValueInterface;
1414
use Magento\Framework\Api\Search\BucketInterface;
1515
use Magento\CatalogGraphQl\DataProvider\Product\LayeredNavigation\Formatter\LayerFormatter;
16+
use Magento\Config\Model\Config\Source\Yesno;
1617

1718
/**
1819
* @inheritdoc
@@ -49,18 +50,26 @@ class Attribute implements LayerBuilderInterface
4950
self::CATEGORY_BUCKET
5051
];
5152

53+
/**
54+
* @var Yesno
55+
*/
56+
private Yesno $YesNo;
57+
5258
/**
5359
* @param AttributeOptionProvider $attributeOptionProvider
5460
* @param LayerFormatter $layerFormatter
61+
* @param Yesno $YesNo
5562
* @param array $bucketNameFilter
5663
*/
5764
public function __construct(
5865
AttributeOptionProvider $attributeOptionProvider,
5966
LayerFormatter $layerFormatter,
67+
Yesno $YesNo,
6068
$bucketNameFilter = []
6169
) {
6270
$this->attributeOptionProvider = $attributeOptionProvider;
6371
$this->layerFormatter = $layerFormatter;
72+
$this->YesNo = $YesNo;
6473
$this->bucketNameFilter = \array_merge($this->bucketNameFilter, $bucketNameFilter);
6574
}
6675

@@ -87,7 +96,11 @@ public function build(AggregationInterface $aggregation, ?int $storeId): array
8796
isset($attribute['position']) ? $attribute['position'] : null
8897
);
8998

90-
$options = $this->getSortedOptions($bucket, isset($attribute['options']) ? $attribute['options'] : []);
99+
$options = $this->getSortedOptions(
100+
$bucket,
101+
isset($attribute['options']) ? $attribute['options'] : [],
102+
($attribute['attribute_type']) ? $attribute['attribute_type']: ''
103+
);
91104
foreach ($options as $option) {
92105
$result[$bucketName]['options'][] = $this->layerFormatter->buildItem(
93106
$option['label'],
@@ -168,9 +181,11 @@ function (AggregationValueInterface $value) {
168181
*
169182
* @param BucketInterface $bucket
170183
* @param array $optionLabels
184+
* @param string $attributeType
171185
* @return array
186+
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
172187
*/
173-
private function getSortedOptions(BucketInterface $bucket, array $optionLabels): array
188+
private function getSortedOptions(BucketInterface $bucket, array $optionLabels, string $attributeType): array
174189
{
175190
/**
176191
* Option labels array has been sorted
@@ -179,7 +194,16 @@ private function getSortedOptions(BucketInterface $bucket, array $optionLabels):
179194
foreach ($bucket->getValues() as $value) {
180195
$metrics = $value->getMetrics();
181196
$optionValue = $metrics['value'];
182-
$optionLabel = $optionLabels[$optionValue] ?? $optionValue;
197+
if (isset($optionLabels[$optionValue])) {
198+
$optionLabel = $optionLabels[$optionValue];
199+
} else {
200+
if ($attributeType === 'boolean') {
201+
$yesNoOptions = $this->YesNo->toArray();
202+
$optionLabel = $yesNoOptions[$optionValue];
203+
} else {
204+
$optionLabel = $optionValue;
205+
}
206+
}
183207
$options[$optionValue] = $metrics + ['label' => $optionLabel];
184208
}
185209

@@ -188,7 +212,7 @@ private function getSortedOptions(BucketInterface $bucket, array $optionLabels):
188212
*/
189213
foreach ($options as $optionId => $option) {
190214
if (!is_array($options[$optionId])) {
191-
unset($options[$optionId]);
215+
unset($options[$optionId]);
192216
}
193217
}
194218

app/code/Magento/CatalogGraphQl/Model/AttributesJoiner.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function join(FieldNode $fieldNode, AbstractCollection $collection, Resol
6161
*
6262
* @param FieldNode $fieldNode
6363
* @param ResolveInfo $resolveInfo
64+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
6465
* @return string[]
6566
*/
6667
public function getQueryFields(FieldNode $fieldNode, ResolveInfo $resolveInfo): array
@@ -77,7 +78,11 @@ public function getQueryFields(FieldNode $fieldNode, ResolveInfo $resolveInfo):
7778
($spreadFragmentNode = $resolveInfo->fragments[$field->name->value])) {
7879

7980
foreach ($spreadFragmentNode->selectionSet->selections as $spreadNode) {
80-
if (isset($spreadNode->selectionSet->selections)) {
81+
if (isset($spreadNode->selectionSet->selections)
82+
&& $spreadNode->kind === NodeKind::INLINE_FRAGMENT) {
83+
$fragmentFields[] = $this->addInlineFragmentFields($resolveInfo, $spreadNode);
84+
} elseif (isset($spreadNode->selectionSet->selections)
85+
&& $spreadNode->kind !== NodeKind::INLINE_FRAGMENT) {
8186
$fragmentFields[] = $this->getQueryFields($spreadNode, $resolveInfo);
8287
} else {
8388
$selectedFields[] = $spreadNode->name->value;

app/code/Magento/CatalogGraphQl/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"magento/module-catalog-search": "*",
1515
"magento/framework": "*",
1616
"magento/module-graph-ql": "*",
17+
"magento/module-config": "*",
1718
"magento/module-advanced-search": "*"
1819
},
1920
"suggest": {

app/code/Magento/CatalogGraphQl/etc/module.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<module name="Magento_Store"/>
1414
<module name="Magento_Eav"/>
1515
<module name="Magento_GraphQl"/>
16+
<module name="Magento_Config"/>
1617
<module name="Magento_StoreGraphQl"/>
1718
<module name="Magento_EavGraphQl"/>
1819
</sequence>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="UTF-8"?><!--
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
8+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
9+
<test name="StorefrontFreeShippingShouldNotApplyIfOtherDiscountAppliedTest">
10+
<annotations>
11+
<features value="Shipping"/>
12+
<stories value="Offline Shipping Methods"/>
13+
<title value="Free Shipping Should Not Applicable if Other Discount Reduce the Matching Amount"/>
14+
<description value="Free Shipping Should Not Applicable if Other Discount Reduce the Matching Amount"/>
15+
<severity value="CRITICAL"/>
16+
<testCaseId value="AC-7886"/>
17+
<group value="shipping"/>
18+
</annotations>
19+
<before>
20+
<!-- Create cart price rule -->
21+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
22+
<!--Create active cart price rule-->
23+
<actionGroup ref="AdminCreateCartPriceRuleActionsWithSubtotalExclTaxActionGroup" stepKey="createFreeShippingCartPriceRule">
24+
<argument name="ruleName" value="CartPriceRuleFreeShippingAppliedOnly"/>
25+
</actionGroup>
26+
<actionGroup ref="AdminCreateCartPriceRuleWithCouponCodeActionGroup" stepKey="createCartPriceRule">
27+
<argument name="ruleName" value="CartPriceRuleConditionWithCouponAppliedForSubtotalExclTax"/>
28+
<argument name="couponCode" value="CartPriceRuleConditionWithCouponAppliedForSubtotalExclTax.coupon_code"/>
29+
</actionGroup>
30+
<!-- Add simple product -->
31+
<createData entity="SimpleProduct2" stepKey="createSimpleProduct">
32+
<field key="price">100.00</field>
33+
</createData>
34+
</before>
35+
<after>
36+
<actionGroup ref="DeleteCartPriceRuleByName" stepKey="deleteFreeShippingCartPriceRule">
37+
<argument name="ruleName" value="{{CartPriceRuleFreeShippingAppliedOnly.name}}"/>
38+
</actionGroup>
39+
<actionGroup ref="DeleteCartPriceRuleByName" stepKey="deleteCartPriceRule">
40+
<argument name="ruleName" value="{{CartPriceRuleConditionWithCouponAppliedForSubtotalExclTax.name}}"/>
41+
</actionGroup>
42+
<!-- Remove simple product-->
43+
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>
44+
45+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
46+
</after>
47+
<!-- Add simple product to cart -->
48+
<actionGroup ref="AddSimpleProductToCartActionGroup" stepKey="addProductToCart">
49+
<argument name="product" value="$$createSimpleProduct$$"/>
50+
</actionGroup>
51+
52+
<!-- Assert that table rate value is correct for US -->
53+
<actionGroup ref="StorefrontCartPageOpenActionGroup" stepKey="openShoppingCartPage"/>
54+
<waitForElement time="30" selector="{{CheckoutCartSummarySection.estimateShippingAndTaxForm}}" stepKey="waitForEstimateShippingAndTaxForm"/>
55+
<waitForElement time="30" selector="{{CheckoutCartSummarySection.shippingMethodForm}}" stepKey="waitForShippingMethodForm"/>
56+
<conditionalClick selector="{{CheckoutCartSummarySection.estimateShippingAndTax}}" dependentSelector="{{CheckoutCartSummarySection.country}}" visible="false" stepKey="expandEstimateShippingandTax" />
57+
<see selector="{{CheckoutCartSummarySection.shippingPrice}}" userInput="$0.00" stepKey="seeFlatShippingZero"/>
58+
59+
<!-- Apply Discount Coupon to the Order -->
60+
<actionGroup ref="StorefrontShoppingCartClickApplyDiscountButtonActionGroup" stepKey="clickApplyButton"/>
61+
<actionGroup ref="StorefrontShoppingCartFillCouponCodeFieldActionGroup" stepKey="fillDiscountCodeField">
62+
<argument name="discountCode" value="{{CartPriceRuleConditionWithCouponAppliedForSubtotalExclTax.coupon_code}}"/>
63+
</actionGroup>
64+
<actionGroup ref="StorefrontShoppingCartClickApplyDiscountButtonActionGroup" stepKey="clickApplyDiscountButton"/>
65+
<actionGroup ref="AssertMessageCustomerChangeAccountInfoActionGroup" stepKey="assertSuccessMessage">
66+
<argument name="message" value='You used coupon code "{{CartPriceRuleConditionWithCouponAppliedForSubtotalExclTax.coupon_code}}".'/>
67+
</actionGroup>
68+
<waitForElement time="30" selector="{{CheckoutCartSummarySection.estimateShippingAndTaxForm}}" stepKey="waitForEstimateShippingAndTaxFormAfterCouponApplied"/>
69+
<waitForElement time="30" selector="{{CheckoutCartSummarySection.shippingMethodForm}}" stepKey="waitForShippingMethodFormAfterCouponApplied"/>
70+
<see selector="{{CheckoutCartSummarySection.shippingPrice}}" userInput="$5.00" stepKey="seeFlatShippingPrice"/>
71+
</test>
72+
</tests>

app/code/Magento/Sales/Model/Order.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
198198
/**
199199
* @var \Magento\Catalog\Api\ProductRepositoryInterface
200200
* @deprecated 100.1.0 Remove unused dependency.
201+
* @see no alternative
201202
*/
202203
protected $productRepository;
203204

@@ -1741,7 +1742,17 @@ public function getStatusHistoryById($statusId)
17411742
public function addStatusHistory(\Magento\Sales\Model\Order\Status\History $history)
17421743
{
17431744
$history->setOrder($this);
1744-
$this->setStatus($history->getStatus());
1745+
if (!$history->getStatus()) {
1746+
$previousStatus = $this->getStatusHistoryCollection()->getFirstItem()->getData('status');
1747+
if (!$previousStatus) {
1748+
$defaultStatus = $this->getConfig()->getStateDefaultStatus($this->getState());
1749+
$history->setStatus($defaultStatus);
1750+
} else {
1751+
$history->setStatus($previousStatus);
1752+
}
1753+
} else {
1754+
$this->setStatus($history->getStatus());
1755+
}
17451756
if (!$history->getId()) {
17461757
$this->setStatusHistories(array_merge($this->getStatusHistories(), [$history]));
17471758
$this->setDataChanges(true);

app/code/Magento/SalesRule/Model/Quote/Discount.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ public function collect(
222222
$total->setBaseSubtotalWithDiscount($total->getBaseSubtotal() + $total->getBaseDiscountAmount());
223223
$address->setDiscountAmount($total->getDiscountAmount());
224224
$address->setBaseDiscountAmount($total->getBaseDiscountAmount());
225+
$address->setBaseSubtotalWithDiscount($total->getBaseSubtotal() + $total->getBaseDiscountAmount());
226+
$address->setSubtotalWithDiscount($total->getSubtotal() + $total->getDiscountAmount());
225227
return $this;
226228
}
227229

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminCreateCartPriceRuleActionsWithSubtotalExclTaxActionGroup" extends="AdminCreateCartPriceRuleActionGroup">
12+
<annotations>
13+
<description>EXTENDS: AdminCreateCartPriceRuleActionGroup. Removes 'fillDiscountAmount'. Adds sub total excl tax conditions for free shipping to a Cart Price Rule.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="ruleName"/>
17+
</arguments>
18+
<remove keyForRemoval="fillDiscountAmount"/>
19+
<!-- Expand the conditions section -->
20+
<grabTextFrom selector="{{AdminCartPriceRulesFormSection.ruleName}}" after="fillRuleName" stepKey="getSubtotalRule"/>
21+
<click selector="{{AdminCartPriceRulesFormSection.conditionsHeader}}" stepKey="openConditionsSection" after="selectActionType"/>
22+
<click selector="#conditions__1__children>li:nth-child(1)>span:nth-child(1) a" after="openConditionsSection" stepKey="addFirstCondition"/>
23+
<selectOption selector="{{AdminCartPriceRulesFormSection.conditionSelect}}" userInput="{{ruleName.condition1}}" after="addFirstCondition" stepKey="selectCondition1"/>
24+
<waitForPageLoad after="selectCondition1" stepKey="waitForConditionLoad"/>
25+
<click selector="{{AdminCartPriceRulesFormSection.condition(ruleName.ruleToChange1)}}" after="waitForConditionLoad" stepKey="clickToChooseOption"/>
26+
<selectOption selector="{{AdminCartPriceRulesFormSection.conditionsOperator}}" userInput="{{ruleName.rule1}}" after="clickToChooseOption" stepKey="setOperatorType"/>
27+
<click selector="{{AdminCartPriceRulesFormSection.targetEllipsis}}" after="setOperatorType" stepKey="clickEllipsis"/>
28+
<fillField selector="{{AdminCartPriceRulesFormSection.ruleFieldByIndex('1--1')}}" userInput="{{ruleName.subtotal}}" after="clickEllipsis" stepKey="fillSubtotalParameter"/>
29+
<click selector="{{AdminCartPriceRulesFormSection.discardSubsequentRules}}" after="fillSubtotalParameter" stepKey="clickDiscardSubsequentRules"/>
30+
<selectOption selector="{{AdminCartPriceRulesFormSection.freeShipping}}" userInput="{{ruleName.simple_free_shipping}}" after="clickDiscardSubsequentRules" stepKey="selectForMatchingItemsOnly"/>
31+
</actionGroup>
32+
</actionGroups>

app/code/Magento/SalesRule/Test/Mftf/Data/SalesRuleData.xml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,49 @@
357357
<data key="defaultRuleLabelAllStoreViews">Free Shipping in conditions</data>
358358
<data key="defaultStoreView">Free Shipping in conditions</data>
359359
</entity>
360+
<entity name="CartPriceRuleFreeShippingAppliedOnly">
361+
<data key="name" unique="suffix">Cart Price Rule For FreeShipping Only</data>
362+
<data key="description">Description for Cart Price Rule</data>
363+
<data key="is_active">Yes</data>
364+
<data key="websites">Main Website</data>
365+
<data key="customerGroups">NOT LOGGED IN</data>
366+
<data key="coupon_type">No Coupon</data>
367+
<data key="simple_action">Percent of product price discount</data>
368+
<data key="discount_amount">0</data>
369+
<data key="maximumQtyDiscount">0</data>
370+
<data key="discount_step">0</data>
371+
<data key="apply">Percent of product price discount</data>
372+
<data key="condition1">Subtotal (Excl. Tax)</data>
373+
<data key="rule1">equals or greater than</data>
374+
<data key="subtotal">100</data>
375+
<data key="ruleToChange1">is</data>
376+
<data key="apply_to_shipping">0</data>
377+
<data key="stop_rules_processing">false</data>
378+
<data key="simple_free_shipping">For matching items only</data>
379+
<data key="defaultRuleLabelAllStoreViews">Free Shipping in conditions</data>
380+
<data key="defaultStoreView">Free Shipping in conditions</data>
381+
</entity>
382+
<entity name="CartPriceRuleConditionWithCouponAppliedForSubtotalExclTax">
383+
<data key="name" unique="suffix">Cart Price Rule For Rule Condition</data>
384+
<data key="description">Description for Cart Price Rule</data>
385+
<data key="is_active">Yes</data>
386+
<data key="websites">Main Website</data>
387+
<data key="customerGroups">NOT LOGGED IN</data>
388+
<data key="coupon_type">Specific Coupon</data>
389+
<data key="coupon_code" unique="suffix">123-abc-ABC-987</data>
390+
<data key="uses_per_coupon">13</data>
391+
<data key="uses_per_customer">63</data>
392+
<data key="simple_action">Percent of product price discount</data>
393+
<data key="discount_amount">10</data>
394+
<data key="maximumQtyDiscount">0</data>
395+
<data key="discount_step">0</data>
396+
<data key="apply_to_shipping">0</data>
397+
<data key="simple_free_shipping">No</data>
398+
<data key="stop_rules_processing">false</data>
399+
<data key="apply">Percent of product price discount</data>
400+
<data key="defaultRuleLabelAllStoreViews">Free Shipping in Rule conditions</data>
401+
<data key="defaultStoreView">Free Shipping in Rule conditions</data>
402+
</entity>
360403
<entity name="CartPriceRuleConditionAppliedForSubtotal">
361404
<data key="name" unique="suffix">Cart Price Rule For Rule Condition</data>
362405
<data key="description">Description for Cart Price Rule</data>

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductSearchAggregationsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ function ($a) {
3737
$booleanAggregation = reset($booleanAggregation);
3838
$this->assertEquals('Boolean Attribute', $booleanAggregation['label']);
3939
$this->assertEquals('boolean_attribute', $booleanAggregation['attribute_code']);
40-
$this->assertContainsEquals(['label' => '1', 'value' => '1', 'count' => '3'], $booleanAggregation['options']);
40+
$this->assertContainsEquals(['label' => 'Yes', 'value' => '1', 'count' => '3'], $booleanAggregation['options']);
4141

4242
$this->assertEquals(2, $booleanAggregation['count']);
4343
$this->assertCount(2, $booleanAggregation['options']);
44-
$this->assertContainsEquals(['label' => '0', 'value' => '0', 'count' => '2'], $booleanAggregation['options']);
44+
$this->assertContainsEquals(['label' => 'No', 'value' => '0', 'count' => '2'], $booleanAggregation['options']);
4545
}
4646

4747
/**

0 commit comments

Comments
 (0)