Skip to content

Commit

Permalink
Merge branch 'magento-commerce:2.4-develop' into eav-graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
bl4de authored Apr 18, 2023
2 parents bd8c356 + af9ab20 commit a1de60d
Show file tree
Hide file tree
Showing 12 changed files with 14,535 additions and 14,337 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function getOptions(array $optionIds, ?int $storeId, array $attributeCode
'attribute_id' => 'a.attribute_id',
'attribute_code' => 'a.attribute_code',
'attribute_label' => 'a.frontend_label',
'attribute_type' => 'a.frontend_input',
'position' => 'attribute_configuration.position'
]
)
Expand Down Expand Up @@ -137,6 +138,7 @@ private function formatResult(Select $select): array
'attribute_code' => $option['attribute_code'],
'attribute_label' => $option['attribute_store_label']
? $option['attribute_store_label'] : $option['attribute_label'],
'attribute_type' => $option['attribute_type'],
'position' => $option['position'],
'options' => [],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Magento\Framework\Api\Search\AggregationValueInterface;
use Magento\Framework\Api\Search\BucketInterface;
use Magento\CatalogGraphQl\DataProvider\Product\LayeredNavigation\Formatter\LayerFormatter;
use Magento\Config\Model\Config\Source\Yesno;

/**
* @inheritdoc
Expand Down Expand Up @@ -49,18 +50,26 @@ class Attribute implements LayerBuilderInterface
self::CATEGORY_BUCKET
];

/**
* @var Yesno
*/
private Yesno $YesNo;

/**
* @param AttributeOptionProvider $attributeOptionProvider
* @param LayerFormatter $layerFormatter
* @param Yesno $YesNo
* @param array $bucketNameFilter
*/
public function __construct(
AttributeOptionProvider $attributeOptionProvider,
LayerFormatter $layerFormatter,
Yesno $YesNo,
$bucketNameFilter = []
) {
$this->attributeOptionProvider = $attributeOptionProvider;
$this->layerFormatter = $layerFormatter;
$this->YesNo = $YesNo;
$this->bucketNameFilter = \array_merge($this->bucketNameFilter, $bucketNameFilter);
}

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

$options = $this->getSortedOptions($bucket, isset($attribute['options']) ? $attribute['options'] : []);
$options = $this->getSortedOptions(
$bucket,
isset($attribute['options']) ? $attribute['options'] : [],
($attribute['attribute_type']) ? $attribute['attribute_type']: ''
);
foreach ($options as $option) {
$result[$bucketName]['options'][] = $this->layerFormatter->buildItem(
$option['label'],
Expand Down Expand Up @@ -168,9 +181,11 @@ function (AggregationValueInterface $value) {
*
* @param BucketInterface $bucket
* @param array $optionLabels
* @param string $attributeType
* @return array
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
private function getSortedOptions(BucketInterface $bucket, array $optionLabels): array
private function getSortedOptions(BucketInterface $bucket, array $optionLabels, string $attributeType): array
{
/**
* Option labels array has been sorted
Expand All @@ -179,7 +194,16 @@ private function getSortedOptions(BucketInterface $bucket, array $optionLabels):
foreach ($bucket->getValues() as $value) {
$metrics = $value->getMetrics();
$optionValue = $metrics['value'];
$optionLabel = $optionLabels[$optionValue] ?? $optionValue;
if (isset($optionLabels[$optionValue])) {
$optionLabel = $optionLabels[$optionValue];
} else {
if ($attributeType === 'boolean') {
$yesNoOptions = $this->YesNo->toArray();
$optionLabel = $yesNoOptions[$optionValue];
} else {
$optionLabel = $optionValue;
}
}
$options[$optionValue] = $metrics + ['label' => $optionLabel];
}

Expand All @@ -188,7 +212,7 @@ private function getSortedOptions(BucketInterface $bucket, array $optionLabels):
*/
foreach ($options as $optionId => $option) {
if (!is_array($options[$optionId])) {
unset($options[$optionId]);
unset($options[$optionId]);
}
}

Expand Down
7 changes: 6 additions & 1 deletion app/code/Magento/CatalogGraphQl/Model/AttributesJoiner.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function join(FieldNode $fieldNode, AbstractCollection $collection, Resol
*
* @param FieldNode $fieldNode
* @param ResolveInfo $resolveInfo
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @return string[]
*/
public function getQueryFields(FieldNode $fieldNode, ResolveInfo $resolveInfo): array
Expand All @@ -77,7 +78,11 @@ public function getQueryFields(FieldNode $fieldNode, ResolveInfo $resolveInfo):
($spreadFragmentNode = $resolveInfo->fragments[$field->name->value])) {

foreach ($spreadFragmentNode->selectionSet->selections as $spreadNode) {
if (isset($spreadNode->selectionSet->selections)) {
if (isset($spreadNode->selectionSet->selections)
&& $spreadNode->kind === NodeKind::INLINE_FRAGMENT) {
$fragmentFields[] = $this->addInlineFragmentFields($resolveInfo, $spreadNode);
} elseif (isset($spreadNode->selectionSet->selections)
&& $spreadNode->kind !== NodeKind::INLINE_FRAGMENT) {
$fragmentFields[] = $this->getQueryFields($spreadNode, $resolveInfo);
} else {
$selectedFields[] = $spreadNode->name->value;
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/CatalogGraphQl/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"magento/module-catalog-search": "*",
"magento/framework": "*",
"magento/module-graph-ql": "*",
"magento/module-config": "*",
"magento/module-advanced-search": "*"
},
"suggest": {
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/CatalogGraphQl/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<module name="Magento_Store"/>
<module name="Magento_Eav"/>
<module name="Magento_GraphQl"/>
<module name="Magento_Config"/>
<module name="Magento_StoreGraphQl"/>
<module name="Magento_EavGraphQl"/>
</sequence>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?><!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="StorefrontFreeShippingShouldNotApplyIfOtherDiscountAppliedTest">
<annotations>
<features value="Shipping"/>
<stories value="Offline Shipping Methods"/>
<title value="Free Shipping Should Not Applicable if Other Discount Reduce the Matching Amount"/>
<description value="Free Shipping Should Not Applicable if Other Discount Reduce the Matching Amount"/>
<severity value="CRITICAL"/>
<testCaseId value="AC-7886"/>
<group value="shipping"/>
</annotations>
<before>
<!-- Create cart price rule -->
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
<!--Create active cart price rule-->
<actionGroup ref="AdminCreateCartPriceRuleActionsWithSubtotalExclTaxActionGroup" stepKey="createFreeShippingCartPriceRule">
<argument name="ruleName" value="CartPriceRuleFreeShippingAppliedOnly"/>
</actionGroup>
<actionGroup ref="AdminCreateCartPriceRuleWithCouponCodeActionGroup" stepKey="createCartPriceRule">
<argument name="ruleName" value="CartPriceRuleConditionWithCouponAppliedForSubtotalExclTax"/>
<argument name="couponCode" value="CartPriceRuleConditionWithCouponAppliedForSubtotalExclTax.coupon_code"/>
</actionGroup>
<!-- Add simple product -->
<createData entity="SimpleProduct2" stepKey="createSimpleProduct">
<field key="price">100.00</field>
</createData>
</before>
<after>
<actionGroup ref="DeleteCartPriceRuleByName" stepKey="deleteFreeShippingCartPriceRule">
<argument name="ruleName" value="{{CartPriceRuleFreeShippingAppliedOnly.name}}"/>
</actionGroup>
<actionGroup ref="DeleteCartPriceRuleByName" stepKey="deleteCartPriceRule">
<argument name="ruleName" value="{{CartPriceRuleConditionWithCouponAppliedForSubtotalExclTax.name}}"/>
</actionGroup>
<!-- Remove simple product-->
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>

<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
</after>
<!-- Add simple product to cart -->
<actionGroup ref="AddSimpleProductToCartActionGroup" stepKey="addProductToCart">
<argument name="product" value="$$createSimpleProduct$$"/>
</actionGroup>

<!-- Assert that table rate value is correct for US -->
<actionGroup ref="StorefrontCartPageOpenActionGroup" stepKey="openShoppingCartPage"/>
<waitForElement time="30" selector="{{CheckoutCartSummarySection.estimateShippingAndTaxForm}}" stepKey="waitForEstimateShippingAndTaxForm"/>
<waitForElement time="30" selector="{{CheckoutCartSummarySection.shippingMethodForm}}" stepKey="waitForShippingMethodForm"/>
<conditionalClick selector="{{CheckoutCartSummarySection.estimateShippingAndTax}}" dependentSelector="{{CheckoutCartSummarySection.country}}" visible="false" stepKey="expandEstimateShippingandTax" />
<see selector="{{CheckoutCartSummarySection.shippingPrice}}" userInput="$0.00" stepKey="seeFlatShippingZero"/>

<!-- Apply Discount Coupon to the Order -->
<actionGroup ref="StorefrontShoppingCartClickApplyDiscountButtonActionGroup" stepKey="clickApplyButton"/>
<actionGroup ref="StorefrontShoppingCartFillCouponCodeFieldActionGroup" stepKey="fillDiscountCodeField">
<argument name="discountCode" value="{{CartPriceRuleConditionWithCouponAppliedForSubtotalExclTax.coupon_code}}"/>
</actionGroup>
<actionGroup ref="StorefrontShoppingCartClickApplyDiscountButtonActionGroup" stepKey="clickApplyDiscountButton"/>
<actionGroup ref="AssertMessageCustomerChangeAccountInfoActionGroup" stepKey="assertSuccessMessage">
<argument name="message" value='You used coupon code "{{CartPriceRuleConditionWithCouponAppliedForSubtotalExclTax.coupon_code}}".'/>
</actionGroup>
<waitForElement time="30" selector="{{CheckoutCartSummarySection.estimateShippingAndTaxForm}}" stepKey="waitForEstimateShippingAndTaxFormAfterCouponApplied"/>
<waitForElement time="30" selector="{{CheckoutCartSummarySection.shippingMethodForm}}" stepKey="waitForShippingMethodFormAfterCouponApplied"/>
<see selector="{{CheckoutCartSummarySection.shippingPrice}}" userInput="$5.00" stepKey="seeFlatShippingPrice"/>
</test>
</tests>
13 changes: 12 additions & 1 deletion app/code/Magento/Sales/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
/**
* @var \Magento\Catalog\Api\ProductRepositoryInterface
* @deprecated 100.1.0 Remove unused dependency.
* @see no alternative
*/
protected $productRepository;

Expand Down Expand Up @@ -1741,7 +1742,17 @@ public function getStatusHistoryById($statusId)
public function addStatusHistory(\Magento\Sales\Model\Order\Status\History $history)
{
$history->setOrder($this);
$this->setStatus($history->getStatus());
if (!$history->getStatus()) {
$previousStatus = $this->getStatusHistoryCollection()->getFirstItem()->getData('status');
if (!$previousStatus) {
$defaultStatus = $this->getConfig()->getStateDefaultStatus($this->getState());
$history->setStatus($defaultStatus);
} else {
$history->setStatus($previousStatus);
}
} else {
$this->setStatus($history->getStatus());
}
if (!$history->getId()) {
$this->setStatusHistories(array_merge($this->getStatusHistories(), [$history]));
$this->setDataChanges(true);
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/SalesRule/Model/Quote/Discount.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ public function collect(
$total->setBaseSubtotalWithDiscount($total->getBaseSubtotal() + $total->getBaseDiscountAmount());
$address->setDiscountAmount($total->getDiscountAmount());
$address->setBaseDiscountAmount($total->getBaseDiscountAmount());
$address->setBaseSubtotalWithDiscount($total->getBaseSubtotal() + $total->getBaseDiscountAmount());
$address->setSubtotalWithDiscount($total->getSubtotal() + $total->getDiscountAmount());
return $this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminCreateCartPriceRuleActionsWithSubtotalExclTaxActionGroup" extends="AdminCreateCartPriceRuleActionGroup">
<annotations>
<description>EXTENDS: AdminCreateCartPriceRuleActionGroup. Removes 'fillDiscountAmount'. Adds sub total excl tax conditions for free shipping to a Cart Price Rule.</description>
</annotations>
<arguments>
<argument name="ruleName"/>
</arguments>
<remove keyForRemoval="fillDiscountAmount"/>
<!-- Expand the conditions section -->
<grabTextFrom selector="{{AdminCartPriceRulesFormSection.ruleName}}" after="fillRuleName" stepKey="getSubtotalRule"/>
<click selector="{{AdminCartPriceRulesFormSection.conditionsHeader}}" stepKey="openConditionsSection" after="selectActionType"/>
<click selector="#conditions__1__children>li:nth-child(1)>span:nth-child(1) a" after="openConditionsSection" stepKey="addFirstCondition"/>
<selectOption selector="{{AdminCartPriceRulesFormSection.conditionSelect}}" userInput="{{ruleName.condition1}}" after="addFirstCondition" stepKey="selectCondition1"/>
<waitForPageLoad after="selectCondition1" stepKey="waitForConditionLoad"/>
<click selector="{{AdminCartPriceRulesFormSection.condition(ruleName.ruleToChange1)}}" after="waitForConditionLoad" stepKey="clickToChooseOption"/>
<selectOption selector="{{AdminCartPriceRulesFormSection.conditionsOperator}}" userInput="{{ruleName.rule1}}" after="clickToChooseOption" stepKey="setOperatorType"/>
<click selector="{{AdminCartPriceRulesFormSection.targetEllipsis}}" after="setOperatorType" stepKey="clickEllipsis"/>
<fillField selector="{{AdminCartPriceRulesFormSection.ruleFieldByIndex('1--1')}}" userInput="{{ruleName.subtotal}}" after="clickEllipsis" stepKey="fillSubtotalParameter"/>
<click selector="{{AdminCartPriceRulesFormSection.discardSubsequentRules}}" after="fillSubtotalParameter" stepKey="clickDiscardSubsequentRules"/>
<selectOption selector="{{AdminCartPriceRulesFormSection.freeShipping}}" userInput="{{ruleName.simple_free_shipping}}" after="clickDiscardSubsequentRules" stepKey="selectForMatchingItemsOnly"/>
</actionGroup>
</actionGroups>
43 changes: 43 additions & 0 deletions app/code/Magento/SalesRule/Test/Mftf/Data/SalesRuleData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,49 @@
<data key="defaultRuleLabelAllStoreViews">Free Shipping in conditions</data>
<data key="defaultStoreView">Free Shipping in conditions</data>
</entity>
<entity name="CartPriceRuleFreeShippingAppliedOnly">
<data key="name" unique="suffix">Cart Price Rule For FreeShipping Only</data>
<data key="description">Description for Cart Price Rule</data>
<data key="is_active">Yes</data>
<data key="websites">Main Website</data>
<data key="customerGroups">NOT LOGGED IN</data>
<data key="coupon_type">No Coupon</data>
<data key="simple_action">Percent of product price discount</data>
<data key="discount_amount">0</data>
<data key="maximumQtyDiscount">0</data>
<data key="discount_step">0</data>
<data key="apply">Percent of product price discount</data>
<data key="condition1">Subtotal (Excl. Tax)</data>
<data key="rule1">equals or greater than</data>
<data key="subtotal">100</data>
<data key="ruleToChange1">is</data>
<data key="apply_to_shipping">0</data>
<data key="stop_rules_processing">false</data>
<data key="simple_free_shipping">For matching items only</data>
<data key="defaultRuleLabelAllStoreViews">Free Shipping in conditions</data>
<data key="defaultStoreView">Free Shipping in conditions</data>
</entity>
<entity name="CartPriceRuleConditionWithCouponAppliedForSubtotalExclTax">
<data key="name" unique="suffix">Cart Price Rule For Rule Condition</data>
<data key="description">Description for Cart Price Rule</data>
<data key="is_active">Yes</data>
<data key="websites">Main Website</data>
<data key="customerGroups">NOT LOGGED IN</data>
<data key="coupon_type">Specific Coupon</data>
<data key="coupon_code" unique="suffix">123-abc-ABC-987</data>
<data key="uses_per_coupon">13</data>
<data key="uses_per_customer">63</data>
<data key="simple_action">Percent of product price discount</data>
<data key="discount_amount">10</data>
<data key="maximumQtyDiscount">0</data>
<data key="discount_step">0</data>
<data key="apply_to_shipping">0</data>
<data key="simple_free_shipping">No</data>
<data key="stop_rules_processing">false</data>
<data key="apply">Percent of product price discount</data>
<data key="defaultRuleLabelAllStoreViews">Free Shipping in Rule conditions</data>
<data key="defaultStoreView">Free Shipping in Rule conditions</data>
</entity>
<entity name="CartPriceRuleConditionAppliedForSubtotal">
<data key="name" unique="suffix">Cart Price Rule For Rule Condition</data>
<data key="description">Description for Cart Price Rule</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ function ($a) {
$booleanAggregation = reset($booleanAggregation);
$this->assertEquals('Boolean Attribute', $booleanAggregation['label']);
$this->assertEquals('boolean_attribute', $booleanAggregation['attribute_code']);
$this->assertContainsEquals(['label' => '1', 'value' => '1', 'count' => '3'], $booleanAggregation['options']);
$this->assertContainsEquals(['label' => 'Yes', 'value' => '1', 'count' => '3'], $booleanAggregation['options']);

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

/**
Expand Down
Loading

0 comments on commit a1de60d

Please sign in to comment.