Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ private function fillProductOptions(Product $product, array $productOptions)
}

$customOption = $this->customOptionFactory->create(['data' => $customOptionData]);
$customOption->setProduct($product);
Copy link
Copy Markdown
Contributor

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?

$customOption->setProductSku($product->getSku());
$customOptions[] = $customOption;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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());
}

/**
Expand Down
16 changes: 13 additions & 3 deletions app/code/Magento/Catalog/Model/Product/Option/Validator/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ protected function getPriceFieldConfig($sortOrder)
'addbeforePool' => $this->productOptionsPrice->prefixesToOptionArray(),
'sortOrder' => $sortOrder,
'validation' => [
'validate-zero-or-greater' => true
'validate-number' => true
],
],
],
Expand Down
4 changes: 3 additions & 1 deletion app/code/Magento/Catalog/view/base/web/js/price-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ define([
optionConfig: {},
optionHandlers: {},
optionTemplate: '<%= data.label %>' +
'<% if (data.finalPrice.value) { %>' +
'<% if (data.finalPrice.value > 0) { %>' +
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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'
};
Expand Down