Skip to content

Commit 8eb6373

Browse files
committed
Merge remote-tracking branch 'github-magento/MAGETWO-94407' into EPAM-PR-8
2 parents 263b315 + 28d72fa commit 8eb6373

File tree

10 files changed

+363
-3
lines changed

10 files changed

+363
-3
lines changed

app/code/Magento/Catalog/Test/Mftf/Section/AdminEditProductAttributesSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
<element name="AttributeDescription" type="text" selector="#description"/>
1919
<element name="ChangeAttributeDescriptionToggle" type="checkbox" selector="#toggle_description"/>
2020
<element name="Save" type="button" selector="button[title=Save]" timeout="30"/>
21+
<element name="defaultLabel" type="text" selector="//td[contains(text(), '{{attributeName}}')]/following-sibling::td[contains(@class, 'col-frontend_label')]" parameterized="true"/>
2122
</section>
2223
</sections>

app/code/Magento/Checkout/Test/Mftf/Section/StorefrontMiniCartSection.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@
2525
<element name="miniCartSubtotalField" type="text" selector=".block-minicart .amount span.price"/>
2626
<element name="itemQuantity" type="input" selector="//a[text()='{{productName}}']/../..//input[contains(@class,'cart-item-qty')]" parameterized="true"/>
2727
<element name="itemQuantityUpdate" type="button" selector="//a[text()='{{productName}}']/../..//span[text()='Update']" parameterized="true"/>
28+
<element name="itemDiscount" type="text" selector="//tr[@class='totals']//td[@class='amount']/span"/>
29+
<element name="subtotal" type="text" selector="//tr[@class='totals sub']//td[@class='amount']/span"/>
2830
</section>
2931
</sections>

app/code/Magento/ConfigurableProduct/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"magento/module-msrp": "*",
2323
"magento/module-webapi": "*",
2424
"magento/module-sales": "*",
25+
"magento/module-sales-rule": "*",
2526
"magento/module-product-video": "*",
2627
"magento/module-configurable-sample-data": "*",
2728
"magento/module-product-links-sample-data": "*"

app/code/Magento/ConfigurableProduct/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,11 @@
228228
</argument>
229229
</arguments>
230230
</type>
231+
<type name="Magento\SalesRule\Model\Quote\ChildrenValidationLocator">
232+
<arguments>
233+
<argument name="productTypeChildrenValidationMap" xsi:type="array">
234+
<item name="configurable" xsi:type="boolean">false</item>
235+
</argument>
236+
</arguments>
237+
</type>
231238
</config>

app/code/Magento/SalesRule/Model/Rule/Condition/Product.php

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,130 @@ protected function _addSpecialAttributes(array &$attributes)
2525
$attributes['quote_item_qty'] = __('Quantity in cart');
2626
$attributes['quote_item_price'] = __('Price in cart');
2727
$attributes['quote_item_row_total'] = __('Row total in cart');
28+
29+
$attributes['parent::category_ids'] = __('Category (Parent only)');
30+
$attributes['children::category_ids'] = __('Category (Children Only)');
31+
}
32+
33+
/**
34+
* Retrieve attribute
35+
*
36+
* @return string
37+
*/
38+
public function getAttribute()
39+
{
40+
$attribute = $this->getData('attribute');
41+
if (strpos($attribute, '::') !== false) {
42+
list (, $attribute) = explode('::', $attribute);
43+
}
44+
return $attribute;
45+
}
46+
47+
/**
48+
* @inheritdoc
49+
*/
50+
public function getAttributeName()
51+
{
52+
$attribute = $this->getAttribute();
53+
if ($this->getAttributeScope()) {
54+
$attribute = $this->getAttributeScope() . '::' . $attribute;
55+
}
56+
return $this->getAttributeOption($attribute);
57+
}
58+
59+
/**
60+
* @inheritdoc
61+
*/
62+
public function loadAttributeOptions()
63+
{
64+
$productAttributes = $this->_productResource->loadAllAttributes()->getAttributesByCode();
65+
66+
$attributes = [];
67+
foreach ($productAttributes as $attribute) {
68+
/* @var $attribute \Magento\Catalog\Model\ResourceModel\Eav\Attribute */
69+
if (!$attribute->isAllowedForRuleCondition()
70+
|| !$attribute->getDataUsingMethod($this->_isUsedForRuleProperty)
71+
) {
72+
continue;
73+
}
74+
$frontLabel = $attribute->getFrontendLabel();
75+
$attributes[$attribute->getAttributeCode()] = $frontLabel;
76+
$attributes['parent::' . $attribute->getAttributeCode()] = $frontLabel . __('(Parent Only)');
77+
$attributes['children::' . $attribute->getAttributeCode()] = $frontLabel . __('(Children Only)');
78+
}
79+
80+
$this->_addSpecialAttributes($attributes);
81+
82+
asort($attributes);
83+
$this->setAttributeOption($attributes);
84+
85+
return $this;
86+
}
87+
88+
/**
89+
* @inheritdoc
90+
*/
91+
public function getAttributeElementHtml()
92+
{
93+
$html = parent::getAttributeElementHtml() .
94+
$this->getAttributeScopeElement()->getHtml();
95+
return $html;
96+
}
97+
98+
/**
99+
* Retrieve form element for scope element
100+
*
101+
* @return \Magento\Framework\Data\Form\Element\AbstractElement
102+
*/
103+
private function getAttributeScopeElement()
104+
{
105+
return $this->getForm()->addField(
106+
$this->getPrefix() . '__' . $this->getId() . '__attribute_scope',
107+
'hidden',
108+
[
109+
'name' => $this->elementName . '[' . $this->getPrefix() . '][' . $this->getId() . '][attribute_scope]',
110+
'value' => $this->getAttributeScope(),
111+
'no_span' => true,
112+
'class' => 'hidden',
113+
'data-form-part' => $this->getFormName()
114+
]
115+
);
116+
}
117+
118+
/**
119+
* Set attribute value
120+
*
121+
* @param string $value
122+
*/
123+
public function setAttribute($value)
124+
{
125+
if (strpos($value, '::') !== false) {
126+
list($scope, $attribute) = explode('::', $value);
127+
$this->setData('attribute_scope', $scope);
128+
$this->setData('attribute', $attribute);
129+
} else {
130+
$this->setData('attribute', $value);
131+
}
132+
}
133+
134+
/**
135+
* @inheritdoc
136+
*/
137+
public function loadArray($arr)
138+
{
139+
parent::loadArray($arr);
140+
$this->setAttributeScope(isset($arr['attribute_scope']) ? $arr['attribute_scope'] : null);
141+
return $this;
142+
}
143+
144+
/**
145+
* @inheritdoc
146+
*/
147+
public function asArray(array $arrAttributes = [])
148+
{
149+
$out = parent::asArray($arrAttributes);
150+
$out['attribute_scope'] = $this->getAttributeScope();
151+
return $out;
28152
}
29153

30154
/**
@@ -89,6 +213,8 @@ public function getValueElementChooserUrl()
89213
}
90214

91215
/**
216+
* Get formatted price.
217+
*
92218
* @param string $value
93219
* @return float|null
94220
*/

app/code/Magento/SalesRule/Model/Rule/Condition/Product/Combine.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Catalog\Model\ResourceModel\Product\Collection;
99

1010
/**
11+
* Combine conditions for product.
1112
* @api
1213
* @since 100.0.2
1314
*/
@@ -85,4 +86,73 @@ public function collectValidatedAttributes($productCollection)
8586
}
8687
return $this;
8788
}
89+
90+
/**
91+
* @inheritdoc
92+
*/
93+
protected function _isValid($entity)
94+
{
95+
if (!$this->getConditions()) {
96+
return true;
97+
}
98+
99+
$all = $this->getAggregator() === 'all';
100+
$true = (bool)$this->getValue();
101+
102+
foreach ($this->getConditions() as $cond) {
103+
if ($entity instanceof \Magento\Framework\Model\AbstractModel) {
104+
$validated = $this->validateEntity($cond, $entity);
105+
} else {
106+
$validated = $cond->validateByEntityId($entity);
107+
}
108+
if ($all && $validated !== $true) {
109+
return false;
110+
} elseif (!$all && $validated === $true) {
111+
return true;
112+
}
113+
}
114+
return $all ? true : false;
115+
}
116+
117+
/**
118+
* Validate entity.
119+
*
120+
* @param object $cond
121+
* @param \Magento\Framework\Model\AbstractModel $entity
122+
* @return bool
123+
*/
124+
private function validateEntity($cond, \Magento\Framework\Model\AbstractModel $entity)
125+
{
126+
$true = (bool)$this->getValue();
127+
$validated = !$true;
128+
foreach ($this->retrieveValidateEntities($cond->getAttributeScope(), $entity) as $validateEntity) {
129+
$validated = $cond->validate($validateEntity);
130+
if ($validated === $true) {
131+
break;
132+
}
133+
}
134+
135+
return $validated;
136+
}
137+
138+
/**
139+
* Retrieve entities for validation by attribute scope
140+
*
141+
* @param string $attributeScope
142+
* @param \Magento\Framework\Model\AbstractModel $entity
143+
* @return \Magento\Framework\Model\AbstractModel[]
144+
*/
145+
private function retrieveValidateEntities($attributeScope, \Magento\Framework\Model\AbstractModel $entity)
146+
{
147+
if ($attributeScope === 'parent') {
148+
$validateEntities = [$entity];
149+
} elseif ($attributeScope === 'children') {
150+
$validateEntities = $entity->getChildren() ?: [$entity];
151+
} else {
152+
$validateEntities = $entity->getChildren() ?: [];
153+
$validateEntities[] = $entity;
154+
}
155+
156+
return $validateEntities;
157+
}
88158
}

app/code/Magento/SalesRule/Test/Mftf/Section/AdminCartPriceRulesFormSection.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
<!-- Actions sub-form -->
2929
<element name="actionsHeader" type="button" selector="div[data-index='actions']" timeout="30"/>
3030
<element name="apply" type="select" selector="select[name='simple_action']"/>
31+
<element name="conditions" type="button" selector=".rule-param.rule-param-new-child > a"/>
32+
<element name="childAttribute" type="select" selector="//select[contains(@name, 'new_child')]"/>
33+
<element name="condition" type="text" selector="//span[@class='rule-param']/a[text()='{{arg}}']" parameterized="true"/>
34+
<element name="operator" type="select" selector="//select[contains(@name, '[operator]')]"/>
35+
<element name="option" type="select" selector="//ul[@class='rule-param-children']//select[contains(@name, '[value]')]"/>
3136
<element name="applyDiscountToShipping" type="checkbox" selector="input[name='apply_to_shipping']"/>
3237
<element name="applyDiscountToShippingLabel" type="checkbox" selector="input[name='apply_to_shipping']+label"/>
3338
<element name="discountAmount" type="input" selector="input[name='discount_amount']"/>

app/code/Magento/SalesRule/Test/Mftf/Test/AdminCreateCartPriceRuleForCouponCodeTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<argument name="ruleName" value="{{_defaultCoupon.code}}"/>
3131
</actionGroup>
3232
<deleteData createDataKey="createPreReqCategory" stepKey="deletePreReqCategory"/>
33-
<amOnPage url="admin/admin/auth/logout/" stepKey="amOnLogoutPage"/>
33+
<actionGroup ref="logout" stepKey="logout"/>
3434
</after>
3535

3636
<!-- Create a cart price rule based on a coupon code -->

0 commit comments

Comments
 (0)