Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit c307d25

Browse files
authored
Merge pull request #3552 from magento-panda/MAGETWO-94394-93769
[PANDA] [B2B] Unable to add large catalog to shared catalog & Cover new customer addresses grid by MFTF tests
2 parents 4ee3bb3 + 7362c89 commit c307d25

26 files changed

+702
-26
lines changed

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function __construct(
9797
}
9898

9999
/**
100-
* {@inheritdoc}
100+
* @inheritdoc
101101
*/
102102
public function get(array $skus)
103103
{
@@ -107,7 +107,7 @@ public function get(array $skus)
107107
}
108108

109109
/**
110-
* {@inheritdoc}
110+
* @inheritdoc
111111
*/
112112
public function update(array $prices)
113113
{
@@ -128,7 +128,7 @@ public function update(array $prices)
128128
}
129129

130130
/**
131-
* {@inheritdoc}
131+
* @inheritdoc
132132
*/
133133
public function replace(array $prices)
134134
{
@@ -144,7 +144,7 @@ public function replace(array $prices)
144144
}
145145

146146
/**
147-
* {@inheritdoc}
147+
* @inheritdoc
148148
*/
149149
public function delete(array $prices)
150150
{
@@ -171,16 +171,17 @@ private function getExistingPrices(array $skus, $groupBySku = false)
171171
$ids = $this->retrieveAffectedIds($skus);
172172
$rawPrices = $this->tierPricePersistence->get($ids);
173173
$prices = [];
174-
175-
$linkField = $this->tierPricePersistence->getEntityLinkField();
176-
$skuByIdLookup = $this->buildSkuByIdLookup($skus);
177-
foreach ($rawPrices as $rawPrice) {
178-
$sku = $skuByIdLookup[$rawPrice[$linkField]];
179-
$price = $this->tierPriceFactory->create($rawPrice, $sku);
180-
if ($groupBySku) {
181-
$prices[$sku][] = $price;
182-
} else {
183-
$prices[] = $price;
174+
if ($rawPrices) {
175+
$linkField = $this->tierPricePersistence->getEntityLinkField();
176+
$skuByIdLookup = $this->buildSkuByIdLookup($skus);
177+
foreach ($rawPrices as $rawPrice) {
178+
$sku = $skuByIdLookup[$rawPrice[$linkField]];
179+
$price = $this->tierPriceFactory->create($rawPrice, $sku);
180+
if ($groupBySku) {
181+
$prices[$sku][] = $price;
182+
} else {
183+
$prices[] = $price;
184+
}
184185
}
185186
}
186187

app/code/Magento/Catalog/Model/ProductIdLocator.php

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,43 @@ class ProductIdLocator implements \Magento\Catalog\Model\ProductIdLocatorInterfa
3737
*/
3838
private $idsBySku = [];
3939

40+
/**
41+
* Batch size to iterate collection
42+
*
43+
* @var int
44+
*/
45+
private $batchSize;
46+
4047
/**
4148
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
4249
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory
43-
* @param string $limitIdsBySkuValues
50+
* @param string $idsLimit
51+
* @param int $batchSize defines how many items can be processed by one iteration
4452
*/
4553
public function __construct(
4654
\Magento\Framework\EntityManager\MetadataPool $metadataPool,
4755
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory,
48-
$idsLimit
56+
$idsLimit,
57+
int $batchSize = 5000
4958
) {
5059
$this->metadataPool = $metadataPool;
5160
$this->collectionFactory = $collectionFactory;
5261
$this->idsLimit = (int)$idsLimit;
62+
$this->batchSize = $batchSize;
5363
}
5464

5565
/**
56-
* {@inheritdoc}
66+
* @inheritdoc
67+
*
68+
* Load product items by provided products SKUs.
69+
* Products collection will be iterated by pages with the $this->batchSize as a page size (for a cases when to many
70+
* products SKUs were provided in parameters.
71+
* Loaded products will be chached in the $this->idsBySku variable, but in the end of the method these storage will
72+
* be truncated to $idsLimit quantity.
73+
* As a result array with the products data will be returned with the following scheme:
74+
* $data['product_sku']['link_field_value' => 'product_type']
75+
*
76+
* @throws \Exception
5777
*/
5878
public function retrieveProductIdsBySkus(array $skus)
5979
{
@@ -72,8 +92,16 @@ public function retrieveProductIdsBySkus(array $skus)
7292
$linkField = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class)
7393
->getLinkField();
7494

75-
foreach ($collection as $item) {
76-
$this->idsBySku[strtolower(trim($item->getSku()))][$item->getData($linkField)] = $item->getTypeId();
95+
$collection->setPageSize($this->batchSize);
96+
$pages = $collection->getLastPageNumber();
97+
for ($currentPage = 1; $currentPage <= $pages; $currentPage++) {
98+
$collection->setCurPage($currentPage);
99+
foreach ($collection->getItems() as $item) {
100+
$sku = strtolower(trim($item->getSku()));
101+
$itemIdentifier = $item->getData($linkField);
102+
$this->idsBySku[$sku][$itemIdentifier] = $item->getTypeId();
103+
}
104+
$collection->clear();
77105
}
78106
}
79107

app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Collection\Abstrac
290290
*/
291291
private $dimensionFactory;
292292

293+
/**
294+
* @var \Magento\Framework\DataObject
295+
*/
296+
private $emptyItem;
297+
293298
/**
294299
* Collection constructor
295300
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
@@ -550,7 +555,10 @@ protected function _prepareStaticFields()
550555
*/
551556
public function getNewEmptyItem()
552557
{
553-
$object = parent::getNewEmptyItem();
558+
if (null === $this->emptyItem) {
559+
$this->emptyItem = parent::getNewEmptyItem();
560+
}
561+
$object = clone $this->emptyItem;
554562
if ($this->isEnabledFlat()) {
555563
$object->setIdFieldName($this->getEntity()->getIdFieldName());
556564
}

app/code/Magento/Catalog/Test/Unit/Model/Product/Price/TierPriceStorageTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,30 @@ public function testGet()
152152
$this->assertEquals(2, count($prices));
153153
}
154154

155+
/**
156+
* Test get method without tierprices.
157+
*
158+
* @return void
159+
*/
160+
public function testGetWithoutTierPrices()
161+
{
162+
$skus = ['simple', 'virtual'];
163+
$this->tierPriceValidator
164+
->expects($this->once())
165+
->method('validateSkus')
166+
->with($skus)
167+
->willReturn($skus);
168+
$this->productIdLocator->expects($this->atLeastOnce())
169+
->method('retrieveProductIdsBySkus')
170+
->with(['simple', 'virtual'])
171+
->willReturn(['simple' => ['2' => 'simple'], 'virtual' => ['3' => 'virtual']]);
172+
$this->tierPricePersistence->expects($this->once())->method('get')->willReturn([]);
173+
$this->tierPricePersistence->expects($this->never())->method('getEntityLinkField');
174+
$this->tierPriceFactory->expects($this->never())->method('create');
175+
$prices = $this->tierPriceStorage->get($skus);
176+
$this->assertEmpty($prices);
177+
}
178+
155179
/**
156180
* Test update method.
157181
*

app/code/Magento/Catalog/Test/Unit/Model/ProductIdLocatorTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,16 @@ public function testRetrieveProductIdsBySkus()
5858
{
5959
$skus = ['sku_1', 'sku_2'];
6060
$collection = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Collection::class)
61-
->setMethods(['getIterator', 'addFieldToFilter'])
61+
->setMethods(
62+
[
63+
'getItems',
64+
'addFieldToFilter',
65+
'setPageSize',
66+
'getLastPageNumber',
67+
'setCurPage',
68+
'clear'
69+
]
70+
)
6271
->disableOriginalConstructor()->getMock();
6372
$product = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class)
6473
->setMethods(['getSku', 'getData', 'getTypeId'])
@@ -69,7 +78,11 @@ public function testRetrieveProductIdsBySkus()
6978
$this->collectionFactory->expects($this->once())->method('create')->willReturn($collection);
7079
$collection->expects($this->once())->method('addFieldToFilter')
7180
->with(\Magento\Catalog\Api\Data\ProductInterface::SKU, ['in' => $skus])->willReturnSelf();
72-
$collection->expects($this->once())->method('getIterator')->willReturn(new \ArrayIterator([$product]));
81+
$collection->expects($this->atLeastOnce())->method('getItems')->willReturn([$product]);
82+
$collection->expects($this->atLeastOnce())->method('setPageSize')->willReturnSelf();
83+
$collection->expects($this->atLeastOnce())->method('getLastPageNumber')->willReturn(1);
84+
$collection->expects($this->atLeastOnce())->method('setCurPage')->with(1)->willReturnSelf();
85+
$collection->expects($this->atLeastOnce())->method('clear')->willReturnSelf();
7386
$this->metadataPool
7487
->expects($this->once())
7588
->method('getMetadata')

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/CollectionTest.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,18 @@ class CollectionTest extends \PHPUnit\Framework\TestCase
5858
*/
5959
private $storeManager;
6060

61+
/**
62+
* @var \Magento\Framework\Data\Collection\EntityFactory|\PHPUnit_Framework_MockObject_MockObject
63+
*/
64+
private $entityFactory;
65+
6166
/**
6267
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
6368
*/
6469
protected function setUp()
6570
{
6671
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
67-
$entityFactory = $this->createMock(\Magento\Framework\Data\Collection\EntityFactory::class);
72+
$this->entityFactory = $this->createMock(\Magento\Framework\Data\Collection\EntityFactory::class);
6873
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)
6974
->disableOriginalConstructor()
7075
->getMockForAbstractClass();
@@ -168,7 +173,7 @@ protected function setUp()
168173
$this->collection = $this->objectManager->getObject(
169174
\Magento\Catalog\Model\ResourceModel\Product\Collection::class,
170175
[
171-
'entityFactory' => $entityFactory,
176+
'entityFactory' => $this->entityFactory,
172177
'logger' => $logger,
173178
'fetchStrategy' => $fetchStrategy,
174179
'eventManager' => $eventManager,
@@ -379,4 +384,20 @@ public function testAddTierPriceData()
379384

380385
$this->assertSame($this->collection, $this->collection->addTierPriceData());
381386
}
387+
388+
/**
389+
* Test for getNewEmptyItem() method
390+
*
391+
* @return void
392+
*/
393+
public function testGetNewEmptyItem()
394+
{
395+
$item = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
396+
->disableOriginalConstructor()
397+
->getMock();
398+
$this->entityFactory->expects($this->once())->method('create')->willReturn($item);
399+
$firstItem = $this->collection->getNewEmptyItem();
400+
$secondItem = $this->collection->getNewEmptyItem();
401+
$this->assertEquals($firstItem, $secondItem);
402+
}
382403
}

app/code/Magento/Customer/Test/Mftf/Data/AddressData.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@
6868
<requiredEntity type="region">RegionNY</requiredEntity>
6969
<data key="country">United States</data>
7070
</entity>
71+
<entity name="US_Address_NY_Not_Default_Address" type="address">
72+
<data key="firstname">John</data>
73+
<data key="lastname">Doe</data>
74+
<data key="company">368</data>
75+
<array key="street">
76+
<item>368 Broadway St.</item>
77+
<item>Apt. 113</item>
78+
</array>
79+
<data key="city">New York</data>
80+
<data key="state">New York</data>
81+
<data key="country_id">US</data>
82+
<data key="postcode">10001</data>
83+
<data key="telephone">512-345-6789</data>
84+
<requiredEntity type="region">RegionNY</requiredEntity>
85+
<data key="country">United States</data>
86+
</entity>
7187
<entity name="US_Address_CA" type="address">
7288
<data key="firstname">John</data>
7389
<data key="lastname">Doe</data>

app/code/Magento/Customer/Test/Mftf/Data/CustomerData.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@
5959
<requiredEntity type="address">US_Address_NY</requiredEntity>
6060
<requiredEntity type="address">UK_Not_Default_Address</requiredEntity>
6161
</entity>
62+
<entity name="Simple_US_Customer_Multiple_Addresses_No_Default_Address" type="customer">
63+
<data key="group_id">0</data>
64+
<data key="default_billing">true</data>
65+
<data key="default_shipping">true</data>
66+
<data key="email" unique="prefix">[email protected]</data>
67+
<data key="firstname">John</data>
68+
<data key="lastname">Doe</data>
69+
<data key="fullname">John Doe</data>
70+
<data key="password">pwdTest123!</data>
71+
<data key="store_id">0</data>
72+
<data key="website_id">0</data>
73+
<requiredEntity type="address">US_Address_NY_Not_Default_Address</requiredEntity>
74+
<requiredEntity type="address">UK_Not_Default_Address</requiredEntity>
75+
</entity>
6276
<entity name="Simple_US_Customer_NY" type="customer">
6377
<data key="group_id">0</data>
6478
<data key="default_billing">true</data>

app/code/Magento/Customer/Test/Mftf/Page/AdminEditCustomerPage.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/PageObject.xsd">
1010
<page name="AdminEditCustomerPage" url="/customer/index/edit/id/{{var1}}" area="admin" module="Magento_Customer" parameterized="true">
1111
<section name="AdminCustomerAccountInformationSection"/>
12+
<section name="AdminCustomerAddressesGridSection"/>
13+
<section name="AdminCustomerAddressesGridActionsSection"/>
14+
<section name="AdminCustomerAddressesSection"/>
1215
<section name="AdminCustomerMainActionsSection"/>
1316
</page>
1417
</pages>

app/code/Magento/Customer/Test/Mftf/Section/AdminCustomerAddressFiltersSection.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
<element name="countryInput" type="input" selector="select[name=country_id]"/>
2020
<element name="telephoneInput" type="input" selector="input[name=telephone]"/>
2121
<element name="applyFilter" type="button" selector="button[data-action=grid-filter-apply]" timeout="30"/>
22-
<element name="clearAll" type="button" selector=".admin__data-grid-header .action-tertiary.action-clear"/>
22+
<element name="clearAll" type="button" selector=".admin__data-grid-header .action-tertiary.action-clear" timeout="30"/>
2323
</section>
2424
</sections>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
11+
<section name="AdminCustomerAddressesDefaultBillingSection">
12+
<element name="addressDetails" type="text" selector="//div[@class='customer-default-billing-address-content']//div[@class='address_details']"/>
13+
<element name="address" type="text" selector="//div[@class='customer-default-billing-address-content']//address//span"/>
14+
<element name="editButton" type="text" selector="//button[@data-index='edit_billing_address']"/>
15+
</section>
16+
</sections>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
11+
<section name="AdminCustomerAddressesDefaultShippingSection">
12+
<element name="addressDetails" type="text" selector="//div[@class='customer-default-shipping-address-content']//div[@class='address_details']"/>
13+
<element name="address" type="text" selector="//div[@class='customer-default-shipping-address-content']//address//span"/>
14+
<element name="editButton" type="text" selector="//button[@data-index='edit_shipping_address']"/>
15+
</section>
16+
</sections>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
11+
<section name="AdminCustomerAddressesGridActionsSection">
12+
<element name="spinner" type="button" selector=".spinner"/>
13+
<element name="gridLoadingMask" type="button" selector=".admin__data-grid-loading-mask"/>
14+
<element name="search" type="input" selector="#fulltext"/>
15+
<element name="delete" type="button" selector="//*[contains(@class, 'admin__data-grid-header')]//span[contains(@class,'action-menu-item') and text()='Delete']"/>
16+
<element name="actions" type="text" selector="//div[@class='admin__data-grid-header']//button[@class='action-select']"/>
17+
<element name="filters" type="button" selector="button[data-action='grid-filter-expand']" timeout="30"/>
18+
<element name="ok" type="button" selector="//button[@data-role='action']//span[text()='OK']"/>
19+
</section>
20+
</sections>

0 commit comments

Comments
 (0)