Skip to content

Commit 2a61f49

Browse files
Merge branch 'MAGETWO-49201' of https://github.corp.magento.com/magento-tango/magento2ce into MAGETWO-48913
2 parents 985c3a8 + 14c63ff commit 2a61f49

File tree

8 files changed

+202
-4
lines changed

8 files changed

+202
-4
lines changed

app/code/Magento/Bundle/Test/Unit/Ui/DataProvider/Product/BundleDataProviderTest.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,17 @@ protected function setUp()
5252
->getMockForAbstractClass();
5353
$this->collectionMock = $this->getMockBuilder(Collection::class)
5454
->disableOriginalConstructor()
55-
->setMethods(['toArray', 'isLoaded', 'addAttributeToFilter', 'load', 'getSize'])
56-
->getMock();
55+
->setMethods(
56+
[
57+
'toArray',
58+
'isLoaded',
59+
'addAttributeToFilter',
60+
'load',
61+
'getSize',
62+
'addFilterByRequiredOptions',
63+
'addStoreFilter'
64+
]
65+
)->getMock();
5766
$this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)
5867
->disableOriginalConstructor()
5968
->setMethods(['create'])
@@ -100,6 +109,11 @@ public function testGetData()
100109
$this->collectionMock->expects($this->once())
101110
->method('addAttributeToFilter')
102111
->with('type_id', [self::ALLOWED_TYPE]);
112+
$this->collectionMock->expects($this->once())
113+
->method('addFilterByRequiredOptions');
114+
$this->collectionMock->expects($this->once())
115+
->method('addStoreFilter')
116+
->with(\Magento\Store\Model\Store::DEFAULT_STORE_ID);
103117
$this->collectionMock->expects($this->once())
104118
->method('toArray')
105119
->willReturn($items);

app/code/Magento/Bundle/Ui/DataProvider/Product/BundleDataProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ public function getData()
6666
'type_id',
6767
$this->dataHelper->getAllowedSelectionTypes()
6868
);
69+
$this->getCollection()->addFilterByRequiredOptions();
70+
$this->getCollection()->addStoreFilter(
71+
\Magento\Store\Model\Store::DEFAULT_STORE_ID
72+
);
6973
$this->getCollection()->load();
7074
}
7175
$items = $this->getCollection()->toArray();

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,10 @@ protected function getBundleSelections()
577577
'dataScope' => 'selection_qty',
578578
'value' => '1',
579579
'sortOrder' => 100,
580+
'validation' => [
581+
'validate-number' => true,
582+
'validate-digits' => true,
583+
],
580584
],
581585
],
582586
],

app/code/Magento/GroupedProduct/Test/Unit/Ui/DataProvider/Product/Form/Modifier/GroupedTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Magento\Catalog\Helper\Image as ImageHelper;
2121
use Magento\Eav\Api\AttributeSetRepositoryInterface;
2222
use Magento\Eav\Api\Data\AttributeSetInterface;
23+
use Magento\Store\Api\Data\StoreInterface;
2324

2425
/**
2526
* Class GroupedTest
@@ -75,6 +76,11 @@ class GroupedTest extends AbstractModifierTest
7576
*/
7677
protected $attributeSetRepositoryMock;
7778

79+
/**
80+
* @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject
81+
*/
82+
protected $storeMock;
83+
7884

7985
protected function setUp()
8086
{
@@ -137,9 +143,15 @@ protected function setUp()
137143
->method('get')
138144
->with(self::LINKED_PRODUCT_SKU)
139145
->willReturn($this->linkedProductMock);
146+
$this->storeMock = $this->getMockBuilder(StoreInterface::class)
147+
->setMethods(['getId'])
148+
->getMockForAbstractClass();
140149
$this->locatorMock->expects($this->any())
141150
->method('getProduct')
142151
->willReturn($this->productMock);
152+
$this->locatorMock->expects($this->any())
153+
->method('getStore')
154+
->willReturn($this->storeMock);
143155
}
144156

145157
/**
@@ -208,6 +220,9 @@ public function testModifyData()
208220
],
209221
],
210222
],
223+
'product' => [
224+
'current_store_id' => null
225+
],
211226
],
212227
];
213228
$this->assertSame($expectedData, $this->getModel()->modifyData([]));
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\GroupedProduct\Test\Unit\Ui\DataProvider\Product;
7+
8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
9+
use Magento\GroupedProduct\Ui\DataProvider\Product\GroupedProductDataProvider;
10+
use Magento\Framework\App\RequestInterface;
11+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
12+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
13+
use Magento\Catalog\Model\ProductTypes\ConfigInterface;
14+
15+
class GroupedProductDataProviderTest extends \PHPUnit_Framework_TestCase
16+
{
17+
const ALLOWED_TYPE = 'simple';
18+
19+
/**
20+
* @var ObjectManager
21+
*/
22+
protected $objectManager;
23+
24+
/**
25+
* @var RequestInterface|\PHPUnit_Framework_MockObject_MockObject
26+
*/
27+
protected $requestMock;
28+
29+
/**
30+
* @var CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
31+
*/
32+
protected $collectionFactoryMock;
33+
34+
/**
35+
* @var Collection|\PHPUnit_Framework_MockObject_MockObject
36+
*/
37+
protected $collectionMock;
38+
39+
/**
40+
* @var ConfigInterface|\PHPUnit_Framework_MockObject_MockObject
41+
*/
42+
protected $configMock;
43+
44+
/**
45+
* @return void
46+
*/
47+
protected function setUp()
48+
{
49+
$this->objectManager = new ObjectManager($this);
50+
51+
$this->requestMock = $this->getMockBuilder(RequestInterface::class)
52+
->getMockForAbstractClass();
53+
$this->collectionMock = $this->getMockBuilder(Collection::class)
54+
->disableOriginalConstructor()
55+
->setMethods(
56+
[
57+
'toArray',
58+
'isLoaded',
59+
'addAttributeToFilter',
60+
'load',
61+
'getSize',
62+
'addFilterByRequiredOptions',
63+
'addStoreFilter'
64+
]
65+
)->getMock();
66+
$this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)
67+
->disableOriginalConstructor()
68+
->setMethods(['create'])
69+
->getMock();
70+
$this->collectionFactoryMock->expects($this->any())
71+
->method('create')
72+
->willReturn($this->collectionMock);
73+
$this->configMock = $this->getMockBuilder(ConfigInterface::class)
74+
->setMethods(['getComposableTypes'])
75+
->getMockForAbstractClass();
76+
}
77+
78+
protected function getModel()
79+
{
80+
return $this->objectManager->getObject(GroupedProductDataProvider::class, [
81+
'name' => 'testName',
82+
'primaryFieldName' => 'testPrimaryFieldName',
83+
'requestFieldName' => 'testRequestFieldName',
84+
'collectionFactory' => $this->collectionFactoryMock,
85+
'request' => $this->requestMock,
86+
'config' => $this->configMock,
87+
'addFieldStrategies' => [],
88+
'addFilterStrategies' => [],
89+
'meta' => [],
90+
'data' => [],
91+
]);
92+
}
93+
94+
public function testGetData()
95+
{
96+
$items = ['testProduct1', 'testProduct2'];
97+
$expectedData = [
98+
'totalRecords' => count($items),
99+
'items' => $items,
100+
];
101+
102+
$this->configMock->expects($this->once())
103+
->method('getComposableTypes')
104+
->willReturn([self::ALLOWED_TYPE]);
105+
$this->collectionMock->expects($this->once())
106+
->method('isLoaded')
107+
->willReturn(false);
108+
$this->collectionMock->expects($this->once())
109+
->method('addAttributeToFilter')
110+
->with('type_id', [self::ALLOWED_TYPE]);
111+
$this->collectionMock->expects($this->once())
112+
->method('toArray')
113+
->willReturn($items);
114+
$this->collectionMock->expects($this->once())
115+
->method('getSize')
116+
->willReturn(count($items));
117+
118+
$this->assertEquals($expectedData, $this->getModel()->getData());
119+
}
120+
121+
public function testGetCollection()
122+
{
123+
$this->assertInstanceOf(Collection::class, $this->getModel()->getCollection());
124+
}
125+
}

app/code/Magento/GroupedProduct/Ui/DataProvider/Product/Form/Modifier/Grouped.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public function modifyData(array $data)
125125
$product = $this->locator->getProduct();
126126
$modelId = $product->getId();
127127
if ($modelId) {
128+
$storeId = $this->locator->getStore()->getId();
128129
/** @var \Magento\Framework\Currency $currency */
129130
$currency = $this->localeCurrency->getCurrency($this->locator->getBaseCurrencyCode());
130131
$data[$product->getId()]['links'][self::LINK_TYPE] = [];
@@ -133,7 +134,7 @@ public function modifyData(array $data)
133134
continue;
134135
}
135136
/** @var \Magento\Catalog\Api\Data\ProductInterface $linkedProduct */
136-
$linkedProduct = $this->productRepository->get($linkItem->getLinkedProductSku());
137+
$linkedProduct = $this->productRepository->get($linkItem->getLinkedProductSku(), false, $storeId);
137138
$data[$modelId]['links'][self::LINK_TYPE][] = [
138139
'id' => $linkedProduct->getId(),
139140
'name' => $linkedProduct->getName(),
@@ -149,6 +150,7 @@ public function modifyData(array $data)
149150
->getAttributeSetName(),
150151
];
151152
}
153+
$data[$modelId][self::DATA_SOURCE_DEFAULT]['current_store_id'] = $storeId;
152154
}
153155
return $data;
154156
}
@@ -316,6 +318,12 @@ protected function getListing()
316318
'dataLinks' => ['imports' => false, 'exports' => true],
317319
'behaviourType' => 'simple',
318320
'externalFilterMode' => true,
321+
'imports' => [
322+
'storeId' => '${ $.provider }:data.product.current_store_id',
323+
],
324+
'exports' => [
325+
'storeId' => '${ $.externalProvider }:params.current_store_id',
326+
],
319327
],
320328
],
321329
],
@@ -478,6 +486,10 @@ protected function getRows()
478486
'fit' => true,
479487
'additionalClasses' => 'admin__field-small',
480488
'sortOrder' => 80,
489+
'validation' => [
490+
'validate-number' => true,
491+
'validate-digits' => true,
492+
],
481493
],
482494
],
483495
],

app/code/Magento/GroupedProduct/Ui/DataProvider/Product/GroupedProductDataProvider.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,51 @@
99
use Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider;
1010
use Magento\GroupedProduct\Model\Product\Type\Grouped as GroupedProductType;
1111
use Magento\Catalog\Model\ProductTypes\ConfigInterface;
12+
use Magento\Framework\App\RequestInterface;
13+
use Magento\Store\Api\Data\StoreInterface;
14+
use Magento\Store\Api\StoreRepositoryInterface;
1215

1316
class GroupedProductDataProvider extends ProductDataProvider
1417
{
18+
/**
19+
* @var RequestInterface
20+
*/
21+
protected $request;
22+
1523
/**
1624
* @var ConfigInterface
1725
*/
1826
protected $config;
1927

28+
/**
29+
* @var StoreRepositoryInterface
30+
*/
31+
protected $storeRepository;
32+
2033
/**
2134
* Construct
2235
*
2336
* @param string $name
2437
* @param string $primaryFieldName
2538
* @param string $requestFieldName
2639
* @param CollectionFactory $collectionFactory
40+
* @param RequestInterface $request
41+
* @param StoreRepositoryInterface $storeRepository
2742
* @param ConfigInterface $config
2843
* @param \Magento\Ui\DataProvider\AddFieldToCollectionInterface[] $addFieldStrategies
2944
* @param \Magento\Ui\DataProvider\AddFilterToCollectionInterface[] $addFilterStrategies
3045
* @param array $meta
3146
* @param array $data
47+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
3248
*/
3349
public function __construct(
3450
$name,
3551
$primaryFieldName,
3652
$requestFieldName,
3753
CollectionFactory $collectionFactory,
54+
RequestInterface $request,
3855
ConfigInterface $config,
56+
StoreRepositoryInterface $storeRepository,
3957
array $meta = [],
4058
array $data = [],
4159
array $addFieldStrategies = [],
@@ -52,6 +70,8 @@ public function __construct(
5270
$data
5371
);
5472

73+
$this->request = $request;
74+
$this->storeRepository = $storeRepository;
5575
$this->config = $config;
5676
}
5777

@@ -67,6 +87,11 @@ public function getData()
6787
'type_id',
6888
$this->config->getComposableTypes()
6989
);
90+
if ($storeId = $this->request->getParam('current_store_id')) {
91+
/** @var StoreInterface $store */
92+
$store = $this->storeRepository->getById($storeId);
93+
$this->getCollection()->setStore($store);
94+
}
7095
$this->getCollection()->load();
7196
}
7297
$items = $this->getCollection()->toArray();

app/code/Magento/GroupedProduct/view/adminhtml/ui_component/grouped_product_listing.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
<listingToolbar name="listing_top">
3434
<bookmark name="bookmarks"/>
3535
<columnsControls name="columns_controls"/>
36-
<!--<filterSearch name="fulltext"/>-->
3736
<filters name="listing_filters">
3837
<argument name="data" xsi:type="array">
3938
<item name="config" xsi:type="array">

0 commit comments

Comments
 (0)