Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 618f408

Browse files
committed
Moved adjustments to plugin.
1 parent 5b95b22 commit 618f408

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Magento\ConfigurableProduct\Plugin\SalesRule\Model\Rule\Condition;
4+
5+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
6+
7+
/**
8+
* Class Product
9+
*
10+
* @package Magento\ConfigurableProduct\Plugin\SalesRule\Model\Rule\Condition
11+
*/
12+
class Product
13+
{
14+
/**
15+
* @param \Magento\SalesRule\Model\Rule\Condition\Product $subject
16+
* @param \Magento\Framework\Model\AbstractModel $model
17+
*/
18+
public function beforeValidate(
19+
\Magento\SalesRule\Model\Rule\Condition\Product $subject,
20+
\Magento\Framework\Model\AbstractModel $model
21+
) {
22+
$model->setProduct(
23+
$this->getProductToValidate($subject, $model)
24+
);
25+
}
26+
27+
28+
/**
29+
* @param \Magento\SalesRule\Model\Rule\Condition\Product $subject
30+
* @param \Magento\Framework\Model\AbstractModel $model
31+
*
32+
* @return \Magento\Catalog\Api\Data\ProductInterface|\Magento\Catalog\Model\Product
33+
*/
34+
private function getProductToValidate(
35+
\Magento\SalesRule\Model\Rule\Condition\Product $subject,
36+
\Magento\Framework\Model\AbstractModel $model
37+
) {
38+
/** @var \Magento\Catalog\Model\Product $product */
39+
$product = $model->getProduct();
40+
41+
$attrCode = $subject->getAttribute();
42+
43+
/* Check for attributes which are not available for configurable products */
44+
if ($product->getTypeId() == Configurable::TYPE_CODE && !$product->hasData($attrCode)) {
45+
/** @var \Magento\Catalog\Model\AbstractModel $childProduct */
46+
$childProduct = current($model->getChildren())->getProduct();
47+
if ($childProduct->hasData($attrCode)) {
48+
$product = $childProduct;
49+
}
50+
}
51+
52+
return $product;
53+
}
54+
}

app/code/Magento/ConfigurableProduct/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"suggest": {
2020
"magento/module-webapi": "100.2.*",
2121
"magento/module-sales": "101.0.*",
22+
"magento/module-sales-rule": "101.0.*",
2223
"magento/module-product-video": "100.2.*",
2324
"magento/module-configurable-sample-data": "Sample Data version:100.2.*",
2425
"magento/module-product-links-sample-data": "Sample Data version:100.2.*"

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,7 @@
221221
<type name="Magento\Catalog\Model\Product">
222222
<plugin name="product_identities_extender" type="Magento\ConfigurableProduct\Model\Plugin\ProductIdentitiesExtender" />
223223
</type>
224+
<type name="Magento\SalesRule\Model\Rule\Condition\Product">
225+
<plugin name="apply_rule_on_configurable_children" type="Magento\ConfigurableProduct\Plugin\SalesRule\Model\Rule\Condition\Product" />
226+
</type>
224227
</config>

0 commit comments

Comments
 (0)