Skip to content

Commit 0b68905

Browse files
authored
Merge pull request #5938 from magento-tango/TANGO-PR-07-27-2020_23
TANGO PR 07-27-2020 v23
2 parents 65f2d7a + 5b9ff36 commit 0b68905

File tree

12 files changed

+353
-18
lines changed

12 files changed

+353
-18
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Export.php

+16-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Magento\Framework\App\Filesystem\DirectoryList;
1010

1111
/**
12+
* Class Export for exporting grid data as CSV file or MS Excel 2003 XML Document file
13+
*
1214
* @api
1315
* @deprecated 100.2.0 in favour of UI component implementation
1416
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -69,6 +71,8 @@ public function __construct(
6971
}
7072

7173
/**
74+
* Internal constructor, that is called from real constructor
75+
*
7276
* @return void
7377
* @throws \Magento\Framework\Exception\LocalizedException
7478
*/
@@ -242,6 +246,7 @@ protected function _getExportTotals()
242246

243247
/**
244248
* Iterate collection and call callback method per item
249+
*
245250
* For callback method first argument always is item object
246251
*
247252
* @param string $callback
@@ -273,7 +278,12 @@ public function _exportIterateCollection($callback, array $args)
273278

274279
$collection = $this->_getRowCollection($originalCollection);
275280
foreach ($collection as $item) {
276-
call_user_func_array([$this, $callback], array_merge([$item], $args));
281+
//phpcs:ignore Magento2.Functions.DiscouragedFunction
282+
call_user_func_array(
283+
[$this, $callback],
284+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
285+
array_merge([$item], $args)
286+
);
277287
}
278288
}
279289
}
@@ -307,7 +317,7 @@ protected function _exportCsvItem(
307317
*/
308318
public function getCsvFile()
309319
{
310-
$name = md5(microtime());
320+
$name = hash('sha256', microtime());
311321
$file = $this->_path . '/' . $name . '.csv';
312322

313323
$this->_directory->create($this->_path);
@@ -432,11 +442,11 @@ public function getRowRecord(\Magento\Framework\DataObject $data)
432442
*/
433443
public function getExcelFile($sheetName = '')
434444
{
435-
$collection = $this->_getRowCollection();
445+
$collection = $this->_getPreparedCollection();
436446

437447
$convert = new \Magento\Framework\Convert\Excel($collection->getIterator(), [$this, 'getRowRecord']);
438448

439-
$name = md5(microtime());
449+
$name = hash('sha256', microtime());
440450
$file = $this->_path . '/' . $name . '.xml';
441451

442452
$this->_directory->create($this->_path);
@@ -551,6 +561,8 @@ public function _getPreparedCollection()
551561
}
552562

553563
/**
564+
* Get export page size
565+
*
554566
* @return int
555567
*/
556568
public function getExportPageSize()

app/code/Magento/Checkout/view/frontend/web/js/region-updater.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ define([
171171
// Populate state/province dropdown list if available or use input box
172172
if (this.options.regionJson[country]) {
173173
this._removeSelectOptions(regionList);
174-
regionsEntries = Object.entries(this.options.regionJson[country]);
174+
regionsEntries = _.pairs(this.options.regionJson[country]);
175175
regionsEntries.sort(function (a, b) {
176176
return a[1].name > b[1].name ? 1 : -1;
177177
});
@@ -202,7 +202,7 @@ define([
202202
regionList.hide();
203203
container.hide();
204204
} else {
205-
regionList.show();
205+
regionList.removeAttr('disabled').show();
206206
}
207207
}
208208

app/code/Magento/UrlRewriteGraphQl/Model/Resolver/EntityUrl.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
namespace Magento\UrlRewriteGraphQl\Model\Resolver;
99

10+
use Magento\Framework\GraphQl\Config\Element\Field;
1011
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1112
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
12-
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
13-
use Magento\Framework\GraphQl\Config\Element\Field;
1413
use Magento\Framework\GraphQl\Query\ResolverInterface;
14+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1515
use Magento\UrlRewrite\Model\UrlFinderInterface;
1616
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
1717
use Magento\UrlRewriteGraphQl\Model\Resolver\UrlRewrite\CustomUrlLocatorInterface;
@@ -126,10 +126,16 @@ private function rewriteCustomUrls(UrlRewrite $finalUrlRewrite, int $storeId): ?
126126
* @param int $storeId
127127
* @param bool $findCustom
128128
* @return UrlRewrite|null
129+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
129130
*/
130131
private function findFinalUrl(string $requestPath, int $storeId, bool $findCustom = false): ?UrlRewrite
131132
{
132133
$urlRewrite = $this->findUrlFromRequestPath($requestPath, $storeId);
134+
if (empty($urlRewrite) && strpos($requestPath, '/') !== false) {
135+
//CMS hierarchy doesn't have their parents written into the url rewrites as they appear in hierarchy
136+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
137+
$urlRewrite = $this->findUrlFromRequestPath(basename($requestPath), $storeId);
138+
}
133139
if ($urlRewrite) {
134140
$this->redirectType = $urlRewrite->getRedirectType();
135141
while ($urlRewrite && $urlRewrite->getRedirectType() > 0) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Wishlist\Model\Adminhtml\ResourceModel\Item\Product;
9+
10+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
11+
use Magento\Wishlist\Model\ResourceModel\Item\Collection as WishlistItemCollection;
12+
use Magento\Wishlist\Model\ResourceModel\Item\Product\CollectionBuilderInterface;
13+
14+
/**
15+
* Wishlist items products collection builder for adminhtml area
16+
*/
17+
class CollectionBuilder implements CollectionBuilderInterface
18+
{
19+
/**
20+
* @inheritDoc
21+
*/
22+
public function build(WishlistItemCollection $wishlistItemCollection, Collection $productCollection): Collection
23+
{
24+
return $productCollection;
25+
}
26+
}

app/code/Magento/Wishlist/Model/ResourceModel/Item/Collection.php

+15-9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\App\ObjectManager;
1212
use Magento\Framework\EntityManager\MetadataPool;
1313
use Magento\Sales\Model\ConfigInterface;
14+
use Magento\Wishlist\Model\ResourceModel\Item\Product\CollectionBuilderInterface;
1415

1516
/**
1617
* Wishlist item collection
@@ -157,6 +158,10 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
157158
* @var ConfigInterface
158159
*/
159160
private $salesConfig;
161+
/**
162+
* @var CollectionBuilderInterface
163+
*/
164+
private $productCollectionBuilder;
160165

161166
/**
162167
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
@@ -178,8 +183,8 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
178183
* @param \Magento\Framework\App\State $appState
179184
* @param \Magento\Framework\DB\Adapter\AdapterInterface $connection
180185
* @param TableMaintainer|null $tableMaintainer
181-
* @param ConfigInterface|null $salesConfig
182-
*
186+
* @param ConfigInterface|null $salesConfig
187+
* @param CollectionBuilderInterface|null $productCollectionBuilder
183188
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
184189
*/
185190
public function __construct(
@@ -202,7 +207,8 @@ public function __construct(
202207
\Magento\Framework\App\State $appState,
203208
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
204209
TableMaintainer $tableMaintainer = null,
205-
ConfigInterface $salesConfig = null
210+
ConfigInterface $salesConfig = null,
211+
?CollectionBuilderInterface $productCollectionBuilder = null
206212
) {
207213
$this->stockConfiguration = $stockConfiguration;
208214
$this->_adminhtmlSales = $adminhtmlSales;
@@ -219,6 +225,8 @@ public function __construct(
219225
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
220226
$this->tableMaintainer = $tableMaintainer ?: ObjectManager::getInstance()->get(TableMaintainer::class);
221227
$this->salesConfig = $salesConfig ?: ObjectManager::getInstance()->get(ConfigInterface::class);
228+
$this->productCollectionBuilder = $productCollectionBuilder
229+
?: ObjectManager::getInstance()->get(CollectionBuilderInterface::class);
222230
}
223231

224232
/**
@@ -309,12 +317,10 @@ protected function _assignProducts()
309317
$productCollection->setVisibility($this->_productVisibility->getVisibleInSiteIds());
310318
}
311319

312-
$productCollection->addPriceData()
313-
->addTaxPercents()
314-
->addIdFilter($this->_productIds)
315-
->addAttributeToSelect($this->_wishlistConfig->getProductAttributes())
316-
->addOptionsToResult()
317-
->addUrlRewrite();
320+
$productCollection->addIdFilter($this->_productIds)
321+
->addAttributeToSelect($this->_wishlistConfig->getProductAttributes());
322+
323+
$productCollection = $this->productCollectionBuilder->build($this, $productCollection);
318324

319325
if ($this->_productSalable) {
320326
$productCollection = $this->_adminhtmlSales->applySalableProductTypesFilter($productCollection);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Wishlist\Model\ResourceModel\Item\Product;
9+
10+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
11+
use Magento\Wishlist\Model\ResourceModel\Item\Collection as WishlistItemCollection;
12+
13+
/**
14+
* Wishlist items products collection builder
15+
*/
16+
class CollectionBuilder implements CollectionBuilderInterface
17+
{
18+
/**
19+
* @inheritDoc
20+
*/
21+
public function build(WishlistItemCollection $wishlistItemCollection, Collection $productCollection): Collection
22+
{
23+
return $productCollection->addPriceData()
24+
->addTaxPercents()
25+
->addOptionsToResult()
26+
->addUrlRewrite();
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Wishlist\Model\ResourceModel\Item\Product;
9+
10+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
11+
use Magento\Wishlist\Model\ResourceModel\Item\Collection as WishlistItemCollection;
12+
13+
/**
14+
* Wishlist items products collection builder
15+
*/
16+
interface CollectionBuilderInterface
17+
{
18+
/**
19+
* Modify product collection
20+
*
21+
* @param WishlistItemCollection $wishlistItemCollection
22+
* @param Collection $productCollection
23+
* @return Collection
24+
*/
25+
public function build(WishlistItemCollection $wishlistItemCollection, Collection $productCollection): Collection;
26+
}

app/code/Magento/Wishlist/Model/Wishlist.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ public function getItemCollection()
379379
$this
380380
)->addStoreFilter(
381381
$this->getSharedStoreIds()
382-
)->setVisibilityFilter();
382+
)->setVisibilityFilter($this->_useCurrentWebsite);
383383
}
384384

385385
return $this->_itemCollection;

app/code/Magento/Wishlist/etc/adminhtml/di.xml

+2
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@
2424
<type name="Magento\Catalog\Model\ResourceModel\Product">
2525
<plugin name="cleanups_wishlist_item_after_product_delete" type="Magento\Wishlist\Plugin\Model\ResourceModel\Product" />
2626
</type>
27+
<preference for="Magento\Wishlist\Model\ResourceModel\Item\Product\CollectionBuilderInterface"
28+
type="Magento\Wishlist\Model\Adminhtml\ResourceModel\Item\Product\CollectionBuilder"/>
2729
</config>

app/code/Magento/Wishlist/etc/di.xml

+2
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,6 @@
7878
</argument>
7979
</arguments>
8080
</type>
81+
<preference for="Magento\Wishlist\Model\ResourceModel\Item\Product\CollectionBuilderInterface"
82+
type="Magento\Wishlist\Model\ResourceModel\Item\Product\CollectionBuilder"/>
8183
</config>

dev/tests/integration/testsuite/Magento/Wishlist/Model/WishlistTest.php

+21
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,27 @@ public function testUpdateNotExistingProductInWishList(): void
243243
$wishlist->updateItem($item, []);
244244
}
245245

246+
/**
247+
* Test that admin user should be able to update wishlist on second website
248+
*
249+
* @magentoAppArea adminhtml
250+
* @magentoDbIsolation disabled
251+
* @magentoDataFixture Magento/Wishlist/_files/wishlist_on_second_website.php
252+
*
253+
* @return void
254+
*/
255+
public function testUpdateWishListItemOnSecondWebsite(): void
256+
{
257+
$wishlist = $this->getWishlistByCustomerId->execute(1);
258+
$item = $this->getWishlistByCustomerId->getItemBySku(1, 'simple-2');
259+
$this->assertNotNull($item);
260+
$this->assertEquals(1, $item->getQty());
261+
$buyRequest = $this->dataObjectFactory->create(['data' => ['qty' => 2]]);
262+
$wishlist->updateItem($item->getId(), $buyRequest);
263+
$updatedItem = $this->getWishlistByCustomerId->getItemBySku(1, 'simple-2');
264+
$this->assertEquals(2, $updatedItem->getQty());
265+
}
266+
246267
/**
247268
* Assert item in wish list.
248269
*

0 commit comments

Comments
 (0)