Skip to content

#14020-Cart-Sales-Rule-with-negated-condition-over-special-price-does… #16342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
90b6803
#14020-Cart-Sales-Rule-with-negated-condition-over-special-price-does…
novikor Jun 22, 2018
2717cb1
Removed empty line due to failing static test
phoenix128 Jun 25, 2018
d2a0de8
Removed dependency to configurable product
phoenix128 Jun 26, 2018
fae98c0
#14020-Cart-Sales-Rule-with-negated-condition-over-special-price-does…
novikor Jul 4, 2018
9a35b45
#14020-Cart-Sales-Rule-with-negated-condition-over-special-price-does…
novikor Jul 4, 2018
887ee4a
#14020-Cart-Sales-Rule-with-negated-condition-over-special-price-does…
novikor Jul 7, 2018
0c9aa81
Revert "#14020-Cart-Sales-Rule-with-negated-condition-over-special-pr…
novikor Jul 22, 2018
4e68337
Merge branch '2.2-develop' into #14020-Cart-Sales-Rule-with-negated-c…
novikor Jul 22, 2018
5b95b22
#14020-Cart-Sales-Rule-with-negated-condition-over-special-price-does…
novikor Jul 22, 2018
618f408
Moved adjustments to plugin.
novikor Jul 22, 2018
7c8482b
#14020-Cart-Sales-Rule-with-negated-condition-over-special-price-does…
novikor Jul 23, 2018
e7130bf
Merge remote-tracking branch 'upstream/2.2-develop' into #14020-Cart-…
novikor Aug 9, 2018
5a7e78a
Merge remote-tracking branch 'origin/#14020-Cart-Sales-Rule-with-nega…
novikor Aug 9, 2018
8d417ac
#14020-Cart-Sales-Rule-with-negated-condition-over-special-price-does…
novikor Aug 9, 2018
90ff989
#14020-Cart-Sales-Rule-with-negated-condition-over-special-price-does…
novikor Aug 9, 2018
c52e0e8
Covered case when simple product is being validated
novikor Aug 9, 2018
5c3154b
#14020-Cart-Sales-Rule-with-negated-condition-over-special-price-does…
novikor Aug 9, 2018
51adb9d
Merge remote-tracking branch 'upstream/2.2-develop' into #14020-Cart-…
novikor Aug 12, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions app/code/Magento/SalesRule/Model/Rule/Condition/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* Product rule condition data model
*
* @author Magento Core Team <[email protected]>
*
* @method string getAttribute()
*/
class Product extends \Magento\Rule\Model\Condition\Product\AbstractProduct
{
Expand All @@ -26,20 +28,47 @@ protected function _addSpecialAttributes(array &$attributes)
$attributes['quote_item_row_total'] = __('Row total in cart');
}

/**
* @param \Magento\Framework\Model\AbstractModel $model
*
* @return \Magento\Catalog\Api\Data\ProductInterface|\Magento\Catalog\Model\Product
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
protected function getProductToValidate(\Magento\Framework\Model\AbstractModel $model)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, make this method private

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, please review: fae98c0 & 9a35b45

{
/** @var \Magento\Catalog\Model\Product $product */
$product = $model->getProduct();
if (!$product instanceof \Magento\Catalog\Model\Product) {
$product = $this->productRepository->getById($model->getProductId());
}

$attrCode = $this->getAttribute();

/* Check for attributes which are not available for configurable products */
if ($product->isComposite() && !$product->hasData($attrCode)) {
/** @var \Magento\Catalog\Api\Data\ProductInterface $childProduct */
$childProduct = current($model->getChildren())->getProduct();
if ($childProduct->hasData($attrCode)) {
$product = $childProduct;
}
}

return $product;
}

/**
* Validate Product Rule Condition
*
* @param \Magento\Framework\Model\AbstractModel $model
*
* @return bool
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function validate(\Magento\Framework\Model\AbstractModel $model)
{
//@todo reimplement this method when is fixed MAGETWO-5713
/** @var \Magento\Catalog\Model\Product $product */
$product = $model->getProduct();
if (!$product instanceof \Magento\Catalog\Model\Product) {
$product = $this->productRepository->getById($model->getProductId());
}
$product = $this->getProductToValidate($model);

$product->setQuoteItemQty(
$model->getQty()
Expand All @@ -49,9 +78,7 @@ public function validate(\Magento\Framework\Model\AbstractModel $model)
$model->getBaseRowTotal()
);

$attrCode = $this->getAttribute();

if ('category_ids' == $attrCode) {
if ('category_ids' == $this->getAttribute()) {
return $this->validateAttribute($this->_getAvailableInCategories($product->getId()));
}

Expand Down