Skip to content

Commit 3351222

Browse files
committed
MAGETWO-88504: Tiered pricing and quantity Increments do not work with decimal inventory
1 parent 8e203be commit 3351222

File tree

2 files changed

+4
-65
lines changed

2 files changed

+4
-65
lines changed

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AdvancedPricing.php

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
use Magento\Ui\Component\Form\Element\Select;
2525
use Magento\Ui\Component\Form\Field;
2626
use Magento\Ui\Component\Modal;
27-
use Magento\CatalogInventory\Api\StockRegistryInterface;
28-
use Magento\Framework\Exception\NoSuchEntityException;
2927

3028
/**
3129
* Class AdvancedPricing
@@ -102,11 +100,6 @@ class AdvancedPricing extends AbstractModifier
102100
*/
103101
private $customerGroupSource;
104102

105-
/**
106-
* @var StockRegistryInterface
107-
*/
108-
private $stockRegistry;
109-
110103
/**
111104
* @param LocatorInterface $locator
112105
* @param StoreManagerInterface $storeManager
@@ -118,7 +111,6 @@ class AdvancedPricing extends AbstractModifier
118111
* @param ArrayManager $arrayManager
119112
* @param string $scopeName
120113
* @param GroupSourceInterface $customerGroupSource
121-
* @param StockRegistryInterface $stockRegistry
122114
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
123115
*/
124116
public function __construct(
@@ -131,8 +123,7 @@ public function __construct(
131123
Data $directoryHelper,
132124
ArrayManager $arrayManager,
133125
$scopeName = '',
134-
GroupSourceInterface $customerGroupSource = null,
135-
StockRegistryInterface $stockRegistry = null
126+
GroupSourceInterface $customerGroupSource = null
136127
) {
137128
$this->locator = $locator;
138129
$this->storeManager = $storeManager;
@@ -145,8 +136,6 @@ public function __construct(
145136
$this->scopeName = $scopeName;
146137
$this->customerGroupSource = $customerGroupSource
147138
?: ObjectManager::getInstance()->get(GroupSourceInterface::class);
148-
$this->stockRegistry = $stockRegistry
149-
?: ObjectManager::getInstance()->get(StockRegistryInterface::class);
150139
}
151140

152141
/**
@@ -511,8 +500,8 @@ private function getTierPriceStructure($tierPricePath)
511500
'validation' => [
512501
'required-entry' => true,
513502
'validate-greater-than-zero' => true,
503+
'validate-digits' => false,
514504
'validate-number' => true,
515-
'validate-digits' => $this->hasPriceQtyDigitsValidationPassed(),
516505
],
517506
],
518507
],
@@ -686,25 +675,4 @@ private function getStore()
686675
{
687676
return $this->locator->getStore();
688677
}
689-
690-
/**
691-
* Get Price Qty digits validation
692-
*
693-
* @return bool
694-
*/
695-
private function hasPriceQtyDigitsValidationPassed(): bool
696-
{
697-
$productId = $this->locator->getProduct()->getId();
698-
if ($productId) {
699-
try {
700-
$result = $this->stockRegistry->getStockItem($productId)->getIsQtyDecimal();
701-
} catch (NoSuchEntityException $e) {
702-
$result = false;
703-
}
704-
} else {
705-
$result = false;
706-
}
707-
708-
return $result;
709-
}
710678
}

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/General.php

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
use Magento\Catalog\Model\Locator\LocatorInterface;
1010
use Magento\Ui\Component\Form;
1111
use Magento\Framework\Stdlib\ArrayManager;
12-
use Magento\CatalogInventory\Api\StockRegistryInterface;
13-
use Magento\Framework\Exception\NoSuchEntityException;
1412

1513
/**
1614
* Data provider for main panel of product page
@@ -37,25 +35,16 @@ class General extends AbstractModifier
3735
*/
3836
private $localeCurrency;
3937

40-
/**
41-
* @var StockRegistryInterface
42-
*/
43-
private $stockRegistry;
44-
4538
/**
4639
* @param LocatorInterface $locator
4740
* @param ArrayManager $arrayManager
48-
* @param StockRegistryInterface $stockRegistry
4941
*/
5042
public function __construct(
5143
LocatorInterface $locator,
52-
ArrayManager $arrayManager,
53-
StockRegistryInterface $stockRegistry = null
44+
ArrayManager $arrayManager
5445
) {
5546
$this->locator = $locator;
5647
$this->arrayManager = $arrayManager;
57-
$this->stockRegistry = $stockRegistry
58-
?: \Magento\Framework\App\ObjectManager::getInstance()->get(StockRegistryInterface::class);
5948
}
6049

6150
/**
@@ -117,7 +106,7 @@ protected function customizeAdvancedPriceFormat(array $data)
117106
$value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE] =
118107
$this->formatPrice($value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE]);
119108
$value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE_QTY] =
120-
$this->formatPriceQty($value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE_QTY]);
109+
(float) $value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE_QTY];
121110
}
122111
}
123112

@@ -419,24 +408,6 @@ protected function formatPrice($value)
419408
return $value;
420409
}
421410

422-
/**
423-
* Make price qty even int or decimal
424-
*
425-
* @param int|float|string $priceQty
426-
* @return int|float
427-
*/
428-
private function formatPriceQty($priceQty)
429-
{
430-
$productId = $this->locator->getProduct()->getId();
431-
try {
432-
$isQtyDecimal = $this->stockRegistry->getStockItem($productId)->getIsQtyDecimal();
433-
} catch (NoSuchEntityException $e) {
434-
$isQtyDecimal = false;
435-
}
436-
437-
return ($isQtyDecimal ? (float) $priceQty : (int) $priceQty);
438-
}
439-
440411
/**
441412
* Format number according to the locale of the currency and precision of input
442413
*

0 commit comments

Comments
 (0)