Skip to content

Tiered pricing and quantity Increments do not work with decimal inventory MAGETWO-86164 (both front-end and back-end) #13359

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

Closed
wants to merge 1 commit into from
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
1 change: 1 addition & 0 deletions app/code/Magento/Bundle/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function __construct(
\Magento\Catalog\Model\ProductTypes\ConfigInterface $config
) {
$this->config = $config;

parent::__construct($context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Bundle\Ui\DataProvider\Product\BundleDataProvider;
use Magento\Framework\App\RequestInterface;
use Magento\Catalog\Model\ResourceModel\Product\Collection;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\Bundle\Helper\Data;
use Magento\CatalogInventory\Api\StockStateInterface;

class BundleDataProviderTest extends \PHPUnit\Framework\TestCase
{
Expand All @@ -21,11 +21,6 @@ class BundleDataProviderTest extends \PHPUnit\Framework\TestCase
*/
protected $objectManager;

/**
* @var RequestInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $requestMock;

/**
* @var CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
*/
Expand All @@ -41,15 +36,21 @@ class BundleDataProviderTest extends \PHPUnit\Framework\TestCase
*/
protected $dataHelperMock;

/**
* @var StockStateInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $stockStateMock;

/**
* @return void
*/
protected function setUp()
{
$this->objectManager = new ObjectManager($this);

$this->requestMock = $this->getMockBuilder(RequestInterface::class)
$this->stockStateMock = $this->getMockBuilder(StockStateInterface::class)
->getMockForAbstractClass();

$this->collectionMock = $this->getMockBuilder(Collection::class)
->disableOriginalConstructor()
->setMethods(
Expand Down Expand Up @@ -86,15 +87,20 @@ protected function getModel()
'primaryFieldName' => 'testPrimaryFieldName',
'requestFieldName' => 'testRequestFieldName',
'collectionFactory' => $this->collectionFactoryMock,
'request' => $this->requestMock,
'dataHelper' => $this->dataHelperMock,
'stockState' => $this->stockStateMock,
'addFieldStrategies' => [],
'addFilterStrategies' => [],
'meta' => [],
'data' => [],
]);
}

/**
* Testing getData() method
*
* @return void
*/
public function testGetData()
{
$items = ['testProduct1', 'testProduct2'];
Expand Down Expand Up @@ -127,6 +133,11 @@ public function testGetData()
$this->assertEquals($expectedData, $this->getModel()->getData());
}

/**
* Testing getCollection() method
*
* @return void
*/
public function testGetCollection()
{
$this->assertInstanceOf(Collection::class, $this->getModel()->getCollection());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Bundle\Ui\DataProvider\Product;

use Magento\Bundle\Helper\Data;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider;
use Magento\Bundle\Helper\Data;
use Magento\CatalogInventory\Api\StockStateInterface;
use Magento\Framework\App\ObjectManager;

class BundleDataProvider extends ProductDataProvider
{
Expand All @@ -16,6 +19,11 @@ class BundleDataProvider extends ProductDataProvider
*/
protected $dataHelper;

/**
* @var StockStateInterface
*/
private $stockState;

/**
* Construct
*
Expand All @@ -24,10 +32,11 @@ class BundleDataProvider extends ProductDataProvider
* @param string $requestFieldName
* @param CollectionFactory $collectionFactory
* @param Data $dataHelper
* @param \Magento\Ui\DataProvider\AddFieldToCollectionInterface[] $addFieldStrategies
* @param \Magento\Ui\DataProvider\AddFilterToCollectionInterface[] $addFilterStrategies
* @param array $meta
* @param array $data
* @param \Magento\Ui\DataProvider\AddFieldToCollectionInterface[] $addFieldStrategies
* @param \Magento\Ui\DataProvider\AddFilterToCollectionInterface[] $addFilterStrategies
Copy link
Member

Choose a reason for hiding this comment

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

Please remove the duplicate parameter declaration

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, that is not a duplicated declaration. They are different.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, my bad, you are absolutely right!

* @param StockStateInterface $stockState
*/
public function __construct(
$name,
Expand All @@ -38,7 +47,8 @@ public function __construct(
array $meta = [],
array $data = [],
array $addFieldStrategies = [],
array $addFilterStrategies = []
array $addFilterStrategies = [],
StockStateInterface $stockState = null
) {
parent::__construct(
$name,
Expand All @@ -52,6 +62,7 @@ public function __construct(
);

$this->dataHelper = $dataHelper;
$this->stockState = $stockState ?: ObjectManager::getInstance()->get(StockStateInterface::class);
}

/**
Expand All @@ -74,6 +85,13 @@ public function getData()
}
$items = $this->getCollection()->toArray();

foreach ($items as $index => $item) {
if (!is_array($item) || !array_key_exists('entity_id', $item)) {
continue;
}
$items[$index]['selection_qty_is_integer'] = !$this->stockState->isStockQtyDecimal((int)$item['entity_id']);
}

return [
'totalRecords' => $this->getCollection()->getSize(),
'items' => array_values($items),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function __construct(
}

/**
* {@inheritdoc}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, revert this changes. Just remove curly braces for static test.

* @inheritdoc
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function modifyMeta(array $meta)
Expand Down Expand Up @@ -220,7 +220,8 @@ private function removeFixedTierPrice(array $meta)
}

/**
* {@inheritdoc}
* @param array $data
* @return array
*/
public function modifyData(array $data)
{
Expand Down Expand Up @@ -377,6 +378,7 @@ protected function getBundleOptions()
'selection_price_type' => '',
'selection_price_value' => '',
'selection_qty' => '',
'selection_qty_is_integer' => 'selection_qty_is_integer',
],
'links' => ['insertData' => '${ $.provider }:${ $.dataProvider }'],
'imports' => [
Expand Down Expand Up @@ -682,10 +684,11 @@ protected function getBundleSelections()
'validation' => [
'required-entry' => true,
'validate-number' => true,
'validate-digits' => true,
'validate-greater-than-zero' => true
],
'imports' => [
'isInteger' => '${ $.provider }:${ $.parentScope }.selection_qty_is_integer'
'validateDigits' => '${ $.provider }:${ $.parentScope }.selection_qty_is_integer',
],
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
*/
namespace Magento\Bundle\Ui\DataProvider\Product\Form\Modifier;

use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Catalog\Api\Data\ProductAttributeInterface;
use Magento\Framework\Stdlib\ArrayManager;
use Magento\Catalog\Model\Locator\LocatorInterface;
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Framework\Stdlib\ArrayManager;

/**
* Customize Price field
Expand Down Expand Up @@ -41,7 +41,7 @@ public function __construct(
}

/**
* {@inheritdoc}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, revert this changes. Just remove curly braces for static test.

* @inheritdoc
*/
public function modifyMeta(array $meta)
{
Expand Down Expand Up @@ -94,7 +94,8 @@ public function modifyMeta(array $meta)
}

/**
* {@inheritdoc}
* @param array $data
* @return array
*/
public function modifyData(array $data)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
namespace Magento\Bundle\Ui\DataProvider\Product\Form\Modifier;

use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Catalog\Api\Data\ProductAttributeInterface;
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Framework\Stdlib\ArrayManager;

/**
Expand All @@ -30,7 +30,7 @@ public function __construct(ArrayManager $arrayManager)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function modifyMeta(array $meta)
{
Expand Down Expand Up @@ -76,12 +76,13 @@ public function modifyMeta(array $meta)
]
]
);

return $meta;
}

/**
* {@inheritdoc}
* @param array $data
* @return array
*/
public function modifyData(array $data)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
*/
namespace Magento\Bundle\Ui\DataProvider\Product\Form\Modifier;

use Magento\Bundle\Api\ProductOptionRepositoryInterface;
use Magento\Bundle\Model\Product\Type;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Locator\LocatorInterface;
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Framework\ObjectManagerInterface;
use Magento\Ui\DataProvider\Modifier\ModifierInterface;
use Magento\Bundle\Model\Product\Type;
use Magento\Bundle\Api\ProductOptionRepositoryInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;

/**
* Class Bundle customizes Bundle product creation flow
Expand Down Expand Up @@ -67,7 +67,7 @@ public function __construct(
}

/**
* {@inheritdoc}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, revert this changes. Just remove curly braces for static test.

* @inheritdoc
*/
public function modifyMeta(array $meta)
{
Expand All @@ -87,7 +87,8 @@ public function modifyMeta(array $meta)
}

/**
* {@inheritdoc}
* @param array $data
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*/
namespace Magento\Bundle\Ui\DataProvider\Product\Form\Modifier;

use Magento\Bundle\Model\Product\Type;
use Magento\Catalog\Model\Locator\LocatorInterface;
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Bundle\Model\Product\Type;

/**
* Class StockData hides unnecessary fields in Advanced Inventory Modal
Expand All @@ -28,15 +28,17 @@ public function __construct(LocatorInterface $locator)
}

/**
* {@inheritdoc}
* @param array $data
* @return array
*/
public function modifyData(array $data)
{
return $data;
}

/**
* {@inheritdoc}
* @param array $meta
* @return array
*/
public function modifyMeta(array $meta)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
use Magento\Catalog\Api\Data\ProductRender\PriceInfoInterface;
use Magento\Catalog\Api\Data\ProductRender\PriceInfoInterfaceFactory;
use Magento\Catalog\Api\Data\ProductRenderInterface;
use Magento\Catalog\Model\ProductRender\FormattedPriceInfoBuilder;
use Magento\Catalog\Ui\DataProvider\Product\ProductRenderCollectorInterface;
use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Catalog\Model\ProductRender\FormattedPriceInfoBuilder;

/**
* Collect information about bundle price
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ define([
valueUpdate: 'input',
isInteger: true,
validation: {
'validate-number': true
'validate-number': true,
'validate-digits': true
}
},

Expand All @@ -32,6 +33,16 @@ define([
var notEqual = this.value() !== this.initialValue.toString();

return !this.visible() ? false : notEqual;
},

/**
* Update field validation rules
*
* @param {Boolean} value
*/
validateDigits: function (value) {
this.isInteger = value;
this.validation['validate-digits'] = this.isInteger;
}

});
Expand Down
Loading