Skip to content

Commit 39b168f

Browse files
Merge branch 'MAGETWO-49180' into MAGETWO-48913
2 parents 9bb335f + 6a432e5 commit 39b168f

File tree

6 files changed

+217
-21
lines changed

6 files changed

+217
-21
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,8 @@ public function testGetCollection()
9494
$this->productLinkRepositoryMock->expects($this->once())
9595
->method('getList')
9696
->willReturn([]);
97-
$this->requestMock->expects($this->once())
97+
$this->requestMock->expects($this->exactly(2))
9898
->method('getParam')
99-
->with('current_product_id')
10099
->willReturn(1);
101100

102101
$this->assertInstanceOf(Collection::class, $this->getModel()->getCollection());

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

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Catalog\Api\ProductLinkRepositoryInterface;
99
use Magento\Catalog\Api\ProductRepositoryInterface;
1010
use Magento\Catalog\Model\Locator\LocatorInterface;
11+
use Magento\Eav\Api\AttributeSetRepositoryInterface;
1112
use Magento\Framework\Phrase;
1213
use Magento\Framework\UrlInterface;
1314
use Magento\Ui\Component\DynamicRows;
@@ -18,6 +19,7 @@
1819
use Magento\Ui\Component\Form\Fieldset;
1920
use Magento\Ui\Component\Modal;
2021
use Magento\Catalog\Helper\Image as ImageHelper;
22+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
2123

2224
/**
2325
* Class Related
@@ -66,25 +68,41 @@ class Related extends AbstractModifier
6668
*/
6769
protected $imageHelper;
6870

71+
/**
72+
* @var Status
73+
*/
74+
protected $status;
75+
76+
/**
77+
* @var AttributeSetRepositoryInterface
78+
*/
79+
protected $attributeSetRepository;
80+
6981
/**
7082
* @param LocatorInterface $locator
7183
* @param UrlInterface $urlBuilder
7284
* @param ProductLinkRepositoryInterface $productLinkRepository
7385
* @param ProductRepositoryInterface $productRepository
7486
* @param ImageHelper $imageHelper
87+
* @param Status $status
88+
* @param AttributeSetRepositoryInterface $attributeSetRepository
7589
*/
7690
public function __construct(
7791
LocatorInterface $locator,
7892
UrlInterface $urlBuilder,
7993
ProductLinkRepositoryInterface $productLinkRepository,
8094
ProductRepositoryInterface $productRepository,
81-
ImageHelper $imageHelper
95+
ImageHelper $imageHelper,
96+
Status $status,
97+
AttributeSetRepositoryInterface $attributeSetRepository
8298
) {
8399
$this->locator = $locator;
84100
$this->urlBuilder = $urlBuilder;
85101
$this->productLinkRepository = $productLinkRepository;
86102
$this->productRepository = $productRepository;
87103
$this->imageHelper = $imageHelper;
104+
$this->status = $status;
105+
$this->attributeSetRepository = $attributeSetRepository;
88106
}
89107

90108
/**
@@ -146,11 +164,19 @@ public function modifyData(array $data)
146164
}
147165

148166
/** @var \Magento\Catalog\Model\Product $linkedProduct */
149-
$linkedProduct = $this->productRepository->get($linkItem->getLinkedProductSku());
167+
$linkedProduct = $this->productRepository->get(
168+
$linkItem->getLinkedProductSku(),
169+
false,
170+
$this->locator->getStore()->getId()
171+
);
150172
$data[$productId]['links'][$dataScope][] = [
151173
'id' => $linkedProduct->getId(),
152174
'thumbnail' => $this->imageHelper->init($linkedProduct, 'product_listing_thumbnail')->getUrl(),
153175
'name' => $linkedProduct->getName(),
176+
'status' => $this->status->getOptionText($linkedProduct->getStatus()),
177+
'attribute_set' => $this->attributeSetRepository
178+
->get($linkedProduct->getAttributeSetId())
179+
->getAttributeSetName(),
154180
'sku' => $linkItem->getLinkedProductSku(),
155181
'price' => $linkedProduct->getPrice(),
156182
'position' => $linkItem->getPosition(),
@@ -159,6 +185,7 @@ public function modifyData(array $data)
159185
}
160186

161187
$data[$productId][self::DATA_SOURCE_DEFAULT]['current_product_id'] = $productId;
188+
$data[$productId][self::DATA_SOURCE_DEFAULT]['current_store_id'] = $this->locator->getStore()->getId();
162189

163190
return $data;
164191
}
@@ -412,10 +439,12 @@ protected function getGenericModal(Phrase $title, $scope)
412439
'behaviourType' => 'simple',
413440
'externalFilterMode' => true,
414441
'imports' => [
415-
'productId' => '${ $.provider }:data.product.current_product_id'
442+
'productId' => '${ $.provider }:data.product.current_product_id',
443+
'storeId' => '${ $.provider }:data.product.current_store_id',
416444
],
417445
'exports' => [
418-
'productId' => '${ $.externalProvider }:params.current_product_id'
446+
'productId' => '${ $.externalProvider }:params.current_product_id',
447+
'storeId' => '${ $.externalProvider }:params.current_store_id',
419448
]
420449
],
421450
],
@@ -458,6 +487,8 @@ protected function getGrid($scope)
458487
'map' => [
459488
'id' => 'entity_id',
460489
'name' => 'name',
490+
'status' => 'status_text',
491+
'attribute_set' => 'attribute_set_text',
461492
'sku' => 'sku',
462493
'price' => 'price',
463494
'thumbnail' => 'thumbnail_src',
@@ -501,8 +532,10 @@ protected function getGrid($scope)
501532
],
502533
],
503534
'name' => $this->getTextColumn('name', false, 'Name', 20),
504-
'sku' => $this->getTextColumn('sku', true, 'SKU', 30),
505-
'price' => $this->getTextColumn('price', true, 'Price', 40),
535+
'status' => $this->getTextColumn('status', true, 'Status', 30),
536+
'attribute_set' => $this->getTextColumn('attribute_set', false, 'Attribute Set', 40),
537+
'sku' => $this->getTextColumn('sku', true, 'SKU', 50),
538+
'price' => $this->getTextColumn('price', true, 'Price', 60),
506539
'actionDelete' => [
507540
'arguments' => [
508541
'data' => [
@@ -511,7 +544,7 @@ protected function getGrid($scope)
511544
'componentType' => 'actionDelete',
512545
'dataType' => Text::NAME,
513546
'label' => __('Actions'),
514-
'sortOrder' => 50,
547+
'sortOrder' => 70,
515548
'fit' => true,
516549
],
517550
],
@@ -525,7 +558,7 @@ protected function getGrid($scope)
525558
'formElement' => Input::NAME,
526559
'componentType' => Field::NAME,
527560
'dataScope' => 'position',
528-
'sortOrder' => 60,
561+
'sortOrder' => 80,
529562
'visible' => false,
530563
],
531564
],

app/code/Magento/Catalog/Ui/DataProvider/Product/Related/AbstractDataProvider.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
1414
use Magento\Framework\App\RequestInterface;
1515
use Magento\Catalog\Api\ProductLinkRepositoryInterface;
16+
use Magento\Store\Api\Data\StoreInterface;
17+
use Magento\Store\Api\StoreRepositoryInterface;
1618

1719
/**
1820
* Class AbstractDataProvider
@@ -29,6 +31,11 @@ abstract class AbstractDataProvider extends ProductDataProvider
2931
*/
3032
protected $productRepository;
3133

34+
/**
35+
* @var StoreRepositoryInterface
36+
*/
37+
protected $storeRepository;
38+
3239
/**
3340
* @var ProductLinkRepositoryInterface
3441
*/
@@ -39,13 +46,19 @@ abstract class AbstractDataProvider extends ProductDataProvider
3946
*/
4047
private $product;
4148

49+
/**
50+
* @var StoreInterface
51+
*/
52+
private $store;
53+
4254
/**
4355
* @param string $name
4456
* @param string $primaryFieldName
4557
* @param string $requestFieldName
4658
* @param CollectionFactory $collectionFactory
4759
* @param RequestInterface $request
4860
* @param ProductRepositoryInterface $productRepository
61+
* @param StoreRepositoryInterface $storeRepository
4962
* @param ProductLinkRepositoryInterface $productLinkRepository
5063
* @param array $addFieldStrategies
5164
* @param array $addFilterStrategies
@@ -60,6 +73,7 @@ public function __construct(
6073
CollectionFactory $collectionFactory,
6174
RequestInterface $request,
6275
ProductRepositoryInterface $productRepository,
76+
StoreRepositoryInterface $storeRepository,
6377
ProductLinkRepositoryInterface $productLinkRepository,
6478
$addFieldStrategies,
6579
$addFilterStrategies,
@@ -79,6 +93,7 @@ public function __construct(
7993

8094
$this->request = $request;
8195
$this->productRepository = $productRepository;
96+
$this->storeRepository = $storeRepository;
8297
$this->productLinkRepository = $productLinkRepository;
8398
}
8499

@@ -96,6 +111,11 @@ public function getCollection()
96111
{
97112
/** @var Collection $collection */
98113
$collection = parent::getCollection();
114+
$collection->addAttributeToSelect('status');
115+
116+
if ($this->getStore()) {
117+
$collection->setStore($this->getStore());
118+
}
99119

100120
if (!$this->getProduct()) {
101121
return $collection;
@@ -155,4 +175,22 @@ protected function getProduct()
155175

156176
return $this->product = $this->productRepository->getById($id);
157177
}
178+
179+
/**
180+
* Retrieve store
181+
*
182+
* @return StoreInterface|null
183+
*/
184+
protected function getStore()
185+
{
186+
if (null !== $this->store) {
187+
return $this->store;
188+
}
189+
190+
if (!($storeId = $this->request->getParam('current_store_id'))) {
191+
return null;
192+
}
193+
194+
return $this->store = $this->storeRepository->getById($storeId);
195+
}
158196
}

app/code/Magento/Catalog/view/adminhtml/ui_component/crosssell_product_listing.xml

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<item name="config" xsi:type="array">
5555
<item name="childDefaults" xsi:type="array">
5656
<item name="fieldAction" xsi:type="array">
57-
<item name="provider" xsi:type="string">groupedProductGrid</item>
57+
<item name="provider" xsi:type="string">crossellProductGrid</item>
5858
<item name="target" xsi:type="string">selectProduct</item>
5959
<item name="params" xsi:type="array">
6060
<item name="0" xsi:type="string">${ $.$data.rowIndex }</item>
@@ -106,6 +106,48 @@
106106
</item>
107107
</argument>
108108
</column>
109+
<column name="attribute_set_id">
110+
<argument name="data" xsi:type="array">
111+
<item name="options" xsi:type="object">Magento\Catalog\Model\Product\AttributeSet\Options</item>
112+
<item name="config" xsi:type="array">
113+
<item name="filter" xsi:type="string">select</item>
114+
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
115+
<item name="dataType" xsi:type="string">select</item>
116+
<item name="label" xsi:type="string" translate="true">Attribute Set</item>
117+
<item name="sortOrder" xsi:type="number">40</item>
118+
</item>
119+
</argument>
120+
</column>
121+
<column name="attribute_set_text" class="Magento\Catalog\Ui\Component\Listing\Columns\AttributeSetText">
122+
<argument name="data" xsi:type="array">
123+
<item name="config" xsi:type="array">
124+
<item name="sortOrder" xsi:type="number">41</item>
125+
<item name="label" xsi:type="string" translate="true">AttributeSetText</item>
126+
<item name="visible" xsi:type="boolean">false</item>
127+
</item>
128+
</argument>
129+
</column>
130+
<column name="status">
131+
<argument name="data" xsi:type="array">
132+
<item name="options" xsi:type="object">Magento\Catalog\Model\Product\Attribute\Source\Status</item>
133+
<item name="config" xsi:type="array">
134+
<item name="filter" xsi:type="string">select</item>
135+
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
136+
<item name="dataType" xsi:type="string">select</item>
137+
<item name="label" xsi:type="string" translate="true">Status</item>
138+
<item name="sortOrder" xsi:type="number">50</item>
139+
</item>
140+
</argument>
141+
</column>
142+
<column name="status_text" class="Magento\Catalog\Ui\Component\Listing\Columns\StatusText">
143+
<argument name="data" xsi:type="array">
144+
<item name="config" xsi:type="array">
145+
<item name="sortOrder" xsi:type="number">51</item>
146+
<item name="label" xsi:type="string" translate="true">StatusText</item>
147+
<item name="visible" xsi:type="boolean">false</item>
148+
</item>
149+
</argument>
150+
</column>
109151
<column name="type_id">
110152
<argument name="data" xsi:type="array">
111153
<item name="options" xsi:type="object">Magento\Catalog\Model\Product\Type</item>
@@ -114,7 +156,7 @@
114156
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
115157
<item name="dataType" xsi:type="string">select</item>
116158
<item name="label" xsi:type="string" translate="true">Type</item>
117-
<item name="sortOrder" xsi:type="number">40</item>
159+
<item name="sortOrder" xsi:type="number">60</item>
118160
</item>
119161
</argument>
120162
</column>
@@ -123,7 +165,7 @@
123165
<item name="config" xsi:type="array">
124166
<item name="filter" xsi:type="string">text</item>
125167
<item name="label" xsi:type="string" translate="true">SKU</item>
126-
<item name="sortOrder" xsi:type="number">50</item>
168+
<item name="sortOrder" xsi:type="number">70</item>
127169
</item>
128170
</argument>
129171
</column>
@@ -133,7 +175,7 @@
133175
<item name="filter" xsi:type="string">textRange</item>
134176
<item name="add_field" xsi:type="boolean">true</item>
135177
<item name="label" xsi:type="string" translate="true">Price</item>
136-
<item name="sortOrder" xsi:type="number">70</item>
178+
<item name="sortOrder" xsi:type="number">80</item>
137179
</item>
138180
</argument>
139181
</column>

0 commit comments

Comments
 (0)