Skip to content

Commit 130b479

Browse files
authored
Merge pull request #5169 from magento-tango/PR-01-02-2020
PR Tango 01-02-2020
2 parents 84c71b5 + 969c82c commit 130b479

File tree

38 files changed

+1711
-306
lines changed

38 files changed

+1711
-306
lines changed

app/code/Magento/Bundle/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AbstractModifierTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ protected function setUp()
4545
$this->locatorMock = $this->getMockBuilder(LocatorInterface::class)
4646
->getMockForAbstractClass();
4747
$this->productMock = $this->getMockBuilder(ProductInterface::class)
48+
->setMethods(['getPriceType'])
4849
->getMockForAbstractClass();
4950

5051
$this->locatorMock->expects($this->any())
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Bundle\Test\Unit\Ui\DataProvider\Product\Form\Modifier;
7+
8+
use Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\BundlePrice;
9+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
10+
use Magento\Framework\Stdlib\ArrayManager;
11+
12+
class BundlePriceTest extends AbstractModifierTest
13+
{
14+
/**
15+
* @return BundlePrice
16+
*/
17+
protected function createModel()
18+
{
19+
return $this->objectManager->getObject(
20+
BundlePrice::class,
21+
[
22+
'locator' => $this->locatorMock,
23+
'arrayManager' => $this->arrayManagerMock
24+
]
25+
);
26+
}
27+
28+
/**
29+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
30+
*/
31+
public function testModifyMeta()
32+
{
33+
$this->productMock->expects($this->any())
34+
->method('getId')
35+
->willReturn(true);
36+
$this->productMock->expects($this->any())
37+
->method('getPriceType')
38+
->willReturn(0);
39+
$priceTypePath = 'bundle-items/children/' . BundlePrice::CODE_PRICE_TYPE;
40+
$priceTypeConfigPath = $priceTypePath . BundlePrice::META_CONFIG_PATH;
41+
$pricePath = 'product-details/children/' . ProductAttributeInterface::CODE_PRICE;
42+
$priceConfigPath = $pricePath . BundlePrice::META_CONFIG_PATH;
43+
$sourceMeta = [
44+
'bundle-items' => [
45+
'children' => [
46+
BundlePrice::CODE_PRICE_TYPE => []
47+
]
48+
]
49+
];
50+
$priceTypeParams = [
51+
'disabled' => true,
52+
'valueMap' => [
53+
'false' => '1',
54+
'true' => '0'
55+
],
56+
'validation' => [
57+
'required-entry' => false
58+
]
59+
];
60+
$priceTypeMeta = [
61+
'bundle-items' => [
62+
'children' => [
63+
BundlePrice::CODE_PRICE_TYPE => $priceTypeParams
64+
]
65+
]
66+
];
67+
$priceParams = [
68+
'imports' => [
69+
'disabled' => 'ns = ${ $.ns }, index = ' . BundlePrice::CODE_PRICE_TYPE . ':checked'
70+
]
71+
];
72+
$priceMeta = [
73+
'product-details' => [
74+
'children' => [
75+
BundlePrice::CODE_PRICE_TYPE => []
76+
]
77+
],
78+
'bundle-items' => [
79+
'children' => [
80+
ProductAttributeInterface::CODE_PRICE => $priceParams
81+
]
82+
]
83+
];
84+
$taxParams = [
85+
'service' => [
86+
'template' => ''
87+
]
88+
];
89+
90+
$this->arrayManagerMock->expects(static::any())
91+
->method('findPath')
92+
->willReturnMap(
93+
[
94+
[
95+
BundlePrice::CODE_PRICE_TYPE,
96+
$sourceMeta,
97+
null,
98+
'children',
99+
ArrayManager::DEFAULT_PATH_DELIMITER,
100+
$priceTypePath
101+
],
102+
[
103+
ProductAttributeInterface::CODE_PRICE,
104+
$priceTypeMeta,
105+
BundlePrice::DEFAULT_GENERAL_PANEL . '/children',
106+
'children',
107+
ArrayManager::DEFAULT_PATH_DELIMITER,
108+
$pricePath
109+
],
110+
[
111+
BundlePrice::CODE_TAX_CLASS_ID,
112+
$priceMeta,
113+
null,
114+
'children',
115+
ArrayManager::DEFAULT_PATH_DELIMITER,
116+
$pricePath
117+
],
118+
[
119+
BundlePrice::CODE_TAX_CLASS_ID,
120+
$priceMeta,
121+
null,
122+
'children',
123+
ArrayManager::DEFAULT_PATH_DELIMITER,
124+
$pricePath
125+
]
126+
]
127+
);
128+
$this->arrayManagerMock->expects($this->exactly(4))
129+
->method('merge')
130+
->willReturnMap(
131+
[
132+
[
133+
$priceTypeConfigPath,
134+
$sourceMeta,
135+
$priceTypeParams,
136+
ArrayManager::DEFAULT_PATH_DELIMITER,
137+
$priceTypeMeta
138+
],
139+
[
140+
$priceConfigPath,
141+
$priceTypeMeta,
142+
$priceParams,
143+
ArrayManager::DEFAULT_PATH_DELIMITER,
144+
$priceMeta
145+
],
146+
[
147+
$priceConfigPath,
148+
$priceMeta,
149+
$priceParams,
150+
ArrayManager::DEFAULT_PATH_DELIMITER,
151+
$priceMeta
152+
],
153+
[
154+
$priceConfigPath,
155+
$priceMeta,
156+
$taxParams,
157+
ArrayManager::DEFAULT_PATH_DELIMITER,
158+
$priceMeta
159+
]
160+
]
161+
);
162+
163+
$this->assertSame($priceMeta, $this->getModel()->modifyMeta($sourceMeta));
164+
}
165+
166+
public function testModifyData()
167+
{
168+
$expectedData = [];
169+
$this->assertEquals($expectedData, $this->getModel()->modifyData($expectedData));
170+
}
171+
}

app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundlePrice.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Bundle\Ui\DataProvider\Product\Form\Modifier;
77

8+
use Magento\Bundle\Model\Product\Price;
89
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
910
use Magento\Catalog\Api\Data\ProductAttributeInterface;
1011
use Magento\Framework\Stdlib\ArrayManager;
@@ -39,7 +40,7 @@ public function __construct(
3940
$this->locator = $locator;
4041
$this->arrayManager = $arrayManager;
4142
}
42-
43+
4344
/**
4445
* @inheritdoc
4546
*/
@@ -89,7 +90,22 @@ public function modifyMeta(array $meta)
8990
]
9091
]
9192
);
92-
93+
if ($this->locator->getProduct()->getPriceType() == Price::PRICE_TYPE_DYNAMIC) {
94+
$meta = $this->arrayManager->merge(
95+
$this->arrayManager->findPath(
96+
static::CODE_TAX_CLASS_ID,
97+
$meta,
98+
null,
99+
'children'
100+
) . static::META_CONFIG_PATH,
101+
$meta,
102+
[
103+
'service' => [
104+
'template' => ''
105+
]
106+
]
107+
);
108+
}
93109
return $meta;
94110
}
95111

app/code/Magento/Catalog/Model/Product/Type/Price.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ protected function _applyTierPrice($product, $qty, $finalPrice)
262262

263263
$tierPrice = $product->getTierPrice($qty);
264264
if (is_numeric($tierPrice)) {
265-
$finalPrice = min($finalPrice, $tierPrice);
265+
$finalPrice = min($finalPrice, (float) $tierPrice);
266266
}
267267
return $finalPrice;
268268
}
@@ -645,7 +645,7 @@ public function calculateSpecialPrice(
645645
) {
646646
if ($specialPrice !== null && $specialPrice != false) {
647647
if ($this->_localeDate->isScopeDateInInterval($store, $specialPriceFrom, $specialPriceTo)) {
648-
$finalPrice = min($finalPrice, $specialPrice);
648+
$finalPrice = min($finalPrice, (float) $specialPrice);
649649
}
650650
}
651651
return $finalPrice;

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/ProductCustomOptionsDataProviderTest.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
use Magento\Framework\App\RequestInterface;
1212
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
1313
use Magento\Framework\DB\Select as DbSelect;
14+
use Magento\Framework\EntityManager\MetadataPool;
15+
use Magento\Framework\EntityManager\EntityMetadataInterface;
16+
use Magento\Ui\DataProvider\Modifier\PoolInterface;
1417

1518
class ProductCustomOptionsDataProviderTest extends \PHPUnit\Framework\TestCase
1619
{
@@ -44,6 +47,21 @@ class ProductCustomOptionsDataProviderTest extends \PHPUnit\Framework\TestCase
4447
*/
4548
protected $dbSelectMock;
4649

50+
/**
51+
* @var MetadataPool|\PHPUnit_Framework_MockObject_MockObject
52+
*/
53+
private $metadataPool;
54+
55+
/**
56+
* @var EntityMetadataInterface|\PHPUnit_Framework_MockObject_MockObject
57+
*/
58+
private $entityMetadata;
59+
60+
/**
61+
* @var PoolInterface|\PHPUnit_Framework_MockObject_MockObject
62+
*/
63+
private $modifiersPool;
64+
4765
protected function setUp()
4866
{
4967
$this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)
@@ -73,12 +91,29 @@ protected function setUp()
7391
->method('create')
7492
->willReturn($this->collectionMock);
7593

94+
$this->modifiersPool = $this->getMockBuilder(PoolInterface::class)
95+
->getMockForAbstractClass();
96+
$this->entityMetadata = $this->getMockBuilder(EntityMetadataInterface::class)
97+
->getMockForAbstractClass();
98+
$this->entityMetadata->expects($this->any())
99+
->method('getLinkField')
100+
->willReturn('entity_id');
101+
$this->metadataPool = $this->getMockBuilder(MetadataPool::class)
102+
->disableOriginalConstructor()
103+
->setMethods(['getMetadata'])
104+
->getMock();
105+
$this->metadataPool->expects($this->any())
106+
->method('getMetadata')
107+
->willReturn($this->entityMetadata);
108+
76109
$this->objectManagerHelper = new ObjectManagerHelper($this);
77110
$this->dataProvider = $this->objectManagerHelper->getObject(
78111
ProductCustomOptionsDataProvider::class,
79112
[
80113
'collectionFactory' => $this->collectionFactoryMock,
81-
'request' => $this->requestMock
114+
'request' => $this->requestMock,
115+
'modifiersPool' => $this->modifiersPool,
116+
'metadataPool' => $this->metadataPool
82117
]
83118
);
84119
}

app/code/Magento/Catalog/Ui/DataProvider/Product/ProductCustomOptionsDataProvider.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
use Magento\Catalog\Api\Data\ProductInterface;
1313
use Magento\Catalog\Model\Product\Option as ProductOption;
1414
use Magento\Framework\DataObject;
15+
use Magento\Framework\EntityManager\MetadataPool;
16+
use Magento\Framework\App\ObjectManager;
17+
use Magento\Ui\DataProvider\Modifier\PoolInterface;
1518

1619
/**
1720
* DataProvider for grid on Import Custom Options modal panel
@@ -39,6 +42,11 @@ class ProductCustomOptionsDataProvider extends ProductDataProvider
3942
*/
4043
protected $productOptionValueModel;
4144

45+
/**
46+
* @var MetadataPool
47+
*/
48+
private $metadataPool;
49+
4250
/**
4351
* @param string $name
4452
* @param string $primaryFieldName
@@ -51,6 +59,8 @@ class ProductCustomOptionsDataProvider extends ProductDataProvider
5159
* @param \Magento\Ui\DataProvider\AddFilterToCollectionInterface[] $addFilterStrategies
5260
* @param array $meta
5361
* @param array $data
62+
* @param PoolInterface|null $modifiersPool
63+
* @param MetadataPool|null $metadataPool
5464
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
5565
*/
5666
public function __construct(
@@ -64,7 +74,9 @@ public function __construct(
6474
array $addFieldStrategies = [],
6575
array $addFilterStrategies = [],
6676
array $meta = [],
67-
array $data = []
77+
array $data = [],
78+
PoolInterface $modifiersPool = null,
79+
MetadataPool $metadataPool = null
6880
) {
6981
parent::__construct(
7082
$name,
@@ -74,16 +86,19 @@ public function __construct(
7486
$addFieldStrategies,
7587
$addFilterStrategies,
7688
$meta,
77-
$data
89+
$data,
90+
$modifiersPool
7891
);
7992

8093
$this->request = $request;
8194
$this->productOptionRepository = $productOptionRepository;
8295
$this->productOptionValueModel = $productOptionValueModel;
96+
$this->metadataPool = $metadataPool ?: ObjectManager::getInstance()
97+
->get(MetadataPool::class);
8398
}
8499

85100
/**
86-
* {@inheritdoc}
101+
* @inheritdoc
87102
* @since 101.0.0
88103
*/
89104
public function getData()
@@ -95,9 +110,16 @@ public function getData()
95110
$this->getCollection()->getSelect()->where('e.entity_id != ?', $currentProductId);
96111
}
97112

113+
try {
114+
$entityMetadata = $this->metadataPool->getMetadata(ProductInterface::class);
115+
$linkField = $entityMetadata->getLinkField();
116+
} catch (\Exception $e) {
117+
$linkField = 'entity_id';
118+
}
119+
98120
$this->getCollection()->getSelect()->distinct()->join(
99121
['opt' => $this->getCollection()->getTable('catalog_product_option')],
100-
'opt.product_id = e.entity_id',
122+
'opt.product_id = e.' . $linkField,
101123
null
102124
);
103125
$this->getCollection()->load();

app/code/Magento/Catalog/view/frontend/web/js/product/provider.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ define([
143143
_.each(ids, function (id) {
144144
if (
145145
currentTime - id['added_at'] < ~~this.idsStorage.lifetime &&
146-
!_.contains(currentProductIds, id['product_id'])
146+
!_.contains(currentProductIds, id['product_id']) &&
147+
(!id.hasOwnProperty('website_id') || id['website_id'] === window.checkout.websiteId)
147148
) {
148149
_ids[id['product_id']] = id;
149150

0 commit comments

Comments
 (0)