-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Add ability to set custom product option with negative price #14342
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
|
|
||
| namespace Magento\Catalog\Model\Product\Option\Validator; | ||
|
|
||
| use Magento\Catalog\Model\Config\Source\ProductPriceOptionsInterface; | ||
| use Magento\Catalog\Model\Product\Option; | ||
| use Zend_Validate_Exception; | ||
|
|
||
|
|
@@ -132,7 +133,15 @@ protected function validateOptionType(Option $option) | |
| */ | ||
| protected function validateOptionValue(Option $option) | ||
| { | ||
| return $this->isInRange($option->getPriceType(), $this->priceTypes) && !$this->isNegative($option->getPrice()); | ||
| $productPrice = 0.0; | ||
| if ($option->getPriceType() === ProductPriceOptionsInterface::VALUE_PERCENT) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you cover these changes with tests? |
||
| $productPrice = 100.0; | ||
| } elseif ($option->getProduct()) { | ||
| $productPrice = $option->getProduct()->getSpecialPrice() ?: $option->getProduct()->getPrice(); | ||
| } | ||
|
|
||
| return $this->isInRange($option->getPriceType(), $this->priceTypes) | ||
| && !$this->isNegative($productPrice + $option->getPrice()); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
|
|
||
| namespace Magento\Catalog\Model\Product\Option\Validator; | ||
|
|
||
| use Magento\Catalog\Model\Config\Source\ProductPriceOptionsInterface; | ||
| use Magento\Catalog\Model\Product\Option; | ||
|
|
||
| class Select extends DefaultValidator | ||
|
|
@@ -47,16 +48,25 @@ protected function validateOptionValue(Option $option) | |
| } | ||
|
|
||
| $storeId = \Magento\Store\Model\Store::DEFAULT_STORE_ID; | ||
| $productPrice = 0.0; | ||
| if ($option->getProduct()) { | ||
| $storeId = $option->getProduct()->getStoreId(); | ||
| $productPrice = $option->getProduct()->getSpecialPrice() ?: $option->getProduct()->getPrice(); | ||
| } | ||
| foreach ($values as $value) { | ||
| if (isset($value['is_delete']) && (bool)$value['is_delete']) { | ||
| continue; | ||
| } | ||
| $type = isset($value['price_type']) ? $value['price_type'] : null; | ||
| $price = isset($value['price']) ? $value['price'] : null; | ||
| $title = isset($value['title']) ? $value['title'] : null; | ||
| $type = $value['price_type'] ?? null; | ||
| $price = $value['price'] ?? 0.0; | ||
| $title = $value['title'] ?? null; | ||
|
|
||
| if ($type === ProductPriceOptionsInterface::VALUE_PERCENT) { | ||
| $price += 100.0; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you describe why do we need to add +100 there? |
||
| } else { | ||
| $price += $productPrice; | ||
| } | ||
|
|
||
| if (!$this->isValidOptionPrice($type, $price, $storeId) | ||
| || !$this->isValidOptionTitle($title, $storeId) | ||
| ) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,8 +20,10 @@ define([ | |
| optionConfig: {}, | ||
| optionHandlers: {}, | ||
| optionTemplate: '<%= data.label %>' + | ||
| '<% if (data.finalPrice.value) { %>' + | ||
| '<% if (data.finalPrice.value > 0) { %>' + | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't get, why do we need this change? |
||
| ' +<%- data.finalPrice.formatted %>' + | ||
| '<% } else if (data.finalPrice.value) { %>' + | ||
| ' <%- data.finalPrice.formatted %>' + | ||
| '<% } %>', | ||
| controlContainer: 'dd' | ||
| }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this change?