Skip to content

Commit 137022f

Browse files
author
Volodymyr Klymenko
authored
Merge pull request #1152 from magento-tsg/develop-pr2
[TSGAB] Bugfixing for 2.2 (pr2)
2 parents 875d859 + 9789518 commit 137022f

File tree

17 files changed

+470
-27
lines changed

17 files changed

+470
-27
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
use Magento\Catalog\Model\Product\Visibility;
1212
use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface as ValidatorInterface;
1313
use Magento\Framework\App\Filesystem\DirectoryList;
14+
use Magento\Framework\App\ObjectManager;
1415
use Magento\Framework\Model\ResourceModel\Db\ObjectRelationProcessor;
1516
use Magento\Framework\Model\ResourceModel\Db\TransactionManagerInterface;
1617
use Magento\Framework\Stdlib\DateTime;
18+
use Magento\Framework\Filesystem;
1719
use Magento\ImportExport\Model\Import;
1820
use Magento\ImportExport\Model\Import\Entity\AbstractEntity;
1921
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingError;
@@ -658,6 +660,13 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
658660
*/
659661
private $multiLineSeparatorForRegexp;
660662

663+
/**
664+
* Container for filesystem object.
665+
*
666+
* @var Filesystem
667+
*/
668+
private $filesystem;
669+
661670
/**
662671
* Catalog config.
663672
*
@@ -761,6 +770,7 @@ public function __construct(
761770
$this->_linkFactory = $linkFactory;
762771
$this->_proxyProdFactory = $proxyProdFactory;
763772
$this->_uploaderFactory = $uploaderFactory;
773+
$this->filesystem = $filesystem;
764774
$this->_mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
765775
$this->_stockResItemFac = $stockResItemFac;
766776
$this->_localeDate = $localeDate;
@@ -1678,6 +1688,7 @@ protected function _saveProducts()
16781688
foreach ($columnImages as $columnImageKey => $columnImage) {
16791689
if (!isset($uploadedImages[$columnImage])) {
16801690
$uploadedFile = $this->uploadMediaFiles($columnImage, true);
1691+
$uploadedFile = $uploadedFile ?: $this->getSystemFile($columnImage);
16811692
if ($uploadedFile) {
16821693
$uploadedImages[$columnImage] = $uploadedFile;
16831694
} else {
@@ -2013,6 +2024,21 @@ protected function uploadMediaFiles($fileName, $renameFileOff = false)
20132024
}
20142025
}
20152026

2027+
/**
2028+
* Try to find file by it's path.
2029+
*
2030+
* @param string $fileName
2031+
* @return string
2032+
*/
2033+
private function getSystemFile($fileName)
2034+
{
2035+
$filePath = 'catalog' . DIRECTORY_SEPARATOR . 'product' . DIRECTORY_SEPARATOR . $fileName;
2036+
/** @var \Magento\Framework\Filesystem\Directory\ReadInterface $read */
2037+
$read = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
2038+
2039+
return $read->isExist($filePath) && $read->isReadable($filePath) ? $fileName : '';
2040+
}
2041+
20162042
/**
20172043
* Save product media gallery.
20182044
*

app/code/Magento/CatalogSearch/Model/Indexer/Fulltext.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Magento\Store\Model\StoreManagerInterface;
1515

1616
/**
17-
* Provide functionality for Fulltext Search indexing
17+
* Provide functionality for Fulltext Search indexing.
1818
*/
1919
class Fulltext implements \Magento\Framework\Indexer\ActionInterface, \Magento\Framework\Mview\ActionInterface
2020
{
@@ -122,7 +122,8 @@ public function execute($ids)
122122
]);
123123
foreach ($storeIds as $storeId) {
124124
$dimension = $this->dimensionFactory->create(['name' => 'scope', 'value' => $storeId]);
125-
$saveHandler->deleteIndex([$dimension], new \ArrayObject($ids));
125+
$productIds = array_unique(array_merge($ids, $this->fulltextResource->getRelationsByChild($ids)));
126+
$saveHandler->deleteIndex([$dimension], new \ArrayObject($productIds));
126127
$saveHandler->saveIndex([$dimension], $this->fullAction->rebuildStoreIndex($storeId, $ids));
127128
}
128129
}

app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
*/
66
namespace Magento\CatalogSearch\Model\ResourceModel;
77

8+
use Magento\Catalog\Api\Data\ProductInterface;
9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\EntityManager\MetadataPool;
11+
812
/**
913
* CatalogSearch Fulltext Index resource model
1014
*/
@@ -17,17 +21,27 @@ class Fulltext extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
1721
*/
1822
protected $_eventManager;
1923

24+
/**
25+
* Holder for MetadataPool instance.
26+
*
27+
* @var MetadataPool
28+
*/
29+
private $metadataPool;
30+
2031
/**
2132
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
2233
* @param \Magento\Framework\Event\ManagerInterface $eventManager
2334
* @param string $connectionName
35+
* @param MetadataPool $metadataPool
2436
*/
2537
public function __construct(
2638
\Magento\Framework\Model\ResourceModel\Db\Context $context,
2739
\Magento\Framework\Event\ManagerInterface $eventManager,
28-
$connectionName = null
40+
$connectionName = null,
41+
MetadataPool $metadataPool = null
2942
) {
3043
$this->_eventManager = $eventManager;
44+
$this->metadataPool = $metadataPool ? : ObjectManager::getInstance()->get(MetadataPool::class);
3145
parent::__construct($context, $connectionName);
3246
}
3347

@@ -53,4 +67,29 @@ public function resetSearchResults()
5367
$this->_eventManager->dispatch('catalogsearch_reset_search_result');
5468
return $this;
5569
}
70+
71+
/**
72+
* Retrieve product relations by children.
73+
*
74+
* @param int|array $childIds
75+
* @return array
76+
*/
77+
public function getRelationsByChild($childIds)
78+
{
79+
$connection = $this->getConnection();
80+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
81+
$select = $connection->select()->from(
82+
['relation' => $this->getTable('catalog_product_relation')],
83+
[]
84+
)->join(
85+
['cpe' => $this->getTable('catalog_product_entity')],
86+
'cpe.' . $linkField . ' = relation.parent_id',
87+
['cpe.entity_id']
88+
)->where(
89+
'relation.child_id IN (?)',
90+
$childIds
91+
)->distinct(true);
92+
93+
return $connection->fetchCol($select);
94+
}
5695
}

app/code/Magento/CatalogSearch/Test/Unit/Model/Indexer/FulltextTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55
*/
66
namespace Magento\CatalogSearch\Test\Unit\Model\Indexer;
77

8-
use Magento\CatalogSearch\Model\ResourceModel\Fulltext as FulltextResource;
9-
use Magento\Framework\Search\Request\Config as SearchRequestConfig;
10-
use Magento\Framework\Search\Request\DimensionFactory;
118
use Magento\Framework\Search\Request\Dimension;
9+
use Magento\Framework\Search\Request\DimensionFactory;
1210
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
13-
use \Magento\CatalogSearch\Model\Indexer\Fulltext\IndexSwitcher;
1411

1512
/**
1613
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -128,6 +125,9 @@ public function testExecute()
128125
$ids = [1, 2, 3];
129126
$stores = [0 => 'Store 1', 1 => 'Store 2'];
130127
$indexData = new \ArrayObject([]);
128+
$this->fulltextResource->expects($this->exactly(2))
129+
->method('getRelationsByChild')
130+
->willReturn($ids);
131131
$this->storeManager->expects($this->once())->method('getStores')->willReturn($stores);
132132
$this->saveHandler->expects($this->exactly(count($stores)))->method('deleteIndex');
133133
$this->saveHandler->expects($this->exactly(2))->method('saveIndex');
@@ -184,6 +184,9 @@ public function testExecuteList()
184184
$ids = [1, 2, 3];
185185
$stores = [0 => 'Store 1', 1 => 'Store 2'];
186186
$indexData = new \ArrayObject([]);
187+
$this->fulltextResource->expects($this->exactly(2))
188+
->method('getRelationsByChild')
189+
->willReturn($ids);
187190
$this->storeManager->expects($this->once())->method('getStores')->willReturn($stores);
188191
$this->saveHandler->expects($this->exactly(count($stores)))->method('deleteIndex');
189192
$this->saveHandler->expects($this->exactly(2))->method('saveIndex');
@@ -199,6 +202,9 @@ public function testExecuteRow()
199202
$id = 1;
200203
$stores = [0 => 'Store 1', 1 => 'Store 2'];
201204
$indexData = new \ArrayObject([]);
205+
$this->fulltextResource->expects($this->exactly(2))
206+
->method('getRelationsByChild')
207+
->willReturn([$id]);
202208
$this->storeManager->expects($this->once())->method('getStores')->willReturn($stores);
203209
$this->saveHandler->expects($this->exactly(count($stores)))->method('deleteIndex');
204210
$this->saveHandler->expects($this->exactly(2))->method('saveIndex');

app/code/Magento/CatalogSearch/Test/Unit/Model/ResourceModel/FulltextTest.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Magento\CatalogSearch\Model\ResourceModel\Fulltext;
1010
use Magento\Framework\App\ResourceConnection;
1111
use Magento\Framework\DB\Adapter\AdapterInterface;
12+
use Magento\Framework\EntityManager\EntityMetadata;
13+
use Magento\Framework\EntityManager\MetadataPool;
1214
use Magento\Framework\Model\ResourceModel\Db\Context;
1315
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1416

@@ -29,6 +31,13 @@ class FulltextTest extends \PHPUnit_Framework_TestCase
2931
*/
3032
private $context;
3133

34+
/**
35+
* Holder for MetadataPool mock object.
36+
*
37+
* @var MetadataPool|\PHPUnit_Framework_MockObject_MockObject
38+
*/
39+
private $metadataPool;
40+
3241
/**
3342
* @var Fulltext
3443
*/
@@ -51,12 +60,16 @@ protected function setUp()
5160
$this->resource->expects($this->once())
5261
->method('getConnection')
5362
->willReturn($this->connection);
63+
$this->metadataPool = $this->getMockBuilder(MetadataPool::class)
64+
->disableOriginalConstructor()
65+
->getMock();
5466

5567
$objectManager = new ObjectManager($this);
5668
$this->target = $objectManager->getObject(
5769
\Magento\CatalogSearch\Model\ResourceModel\Fulltext::class,
5870
[
5971
'context' => $this->context,
72+
'metadataPool' => $this->metadataPool
6073
]
6174
);
6275
}
@@ -74,4 +87,71 @@ public function testResetSearchResult()
7487
$result = $this->target->resetSearchResults();
7588
$this->assertEquals($this->target, $result);
7689
}
90+
91+
/**
92+
* @covers \Magento\CatalogSearch\Model\ResourceModel\Fulltext::getRelationsByChild()
93+
*/
94+
public function testGetRelationsByChild()
95+
{
96+
$ids = [1, 2, 3];
97+
$testTable1 = 'testTable1';
98+
$testTable2 = 'testTable2';
99+
$fieldForParent = 'testLinkField';
100+
101+
$metadata = $this->getMockBuilder(EntityMetadata::class)
102+
->disableOriginalConstructor()
103+
->getMock();
104+
$metadata->expects($this->once())
105+
->method('getLinkField')
106+
->willReturn($fieldForParent);
107+
108+
$this->metadataPool->expects($this->once())
109+
->method('getMetadata')
110+
->with(\Magento\Catalog\Api\Data\ProductInterface::class)
111+
->willReturn($metadata);
112+
113+
$select = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
114+
->disableOriginalConstructor()
115+
->getMock();
116+
$select->expects($this->once())
117+
->method('from')
118+
->with(['relation' => $testTable1])
119+
->willReturnSelf();
120+
$select->expects($this->once())
121+
->method('distinct')
122+
->with(true)
123+
->willReturnSelf();
124+
$select->expects($this->once())
125+
->method('where')
126+
->with('relation.child_id IN (?)', $ids)
127+
->willReturnSelf();
128+
$select->expects($this->once())
129+
->method('join')
130+
->with(
131+
['cpe' => $testTable2],
132+
'cpe.' . $fieldForParent . ' = relation.parent_id',
133+
['cpe.entity_id']
134+
)->willReturnSelf();
135+
136+
$this->connection->expects($this->once())
137+
->method('select')
138+
->willReturn($select);
139+
$this->connection->expects($this->once())
140+
->method('fetchCol')
141+
->with($select)
142+
->willReturn($ids);
143+
144+
$this->resource->expects($this->exactly(2))
145+
->method('getTableName')
146+
->withConsecutive(
147+
['catalog_product_relation', ResourceConnection::DEFAULT_CONNECTION],
148+
['catalog_product_entity', ResourceConnection::DEFAULT_CONNECTION]
149+
)
150+
->will($this->onConsecutiveCalls(
151+
$testTable1,
152+
$testTable2
153+
));
154+
155+
self::assertSame($ids, $this->target->getRelationsByChild($ids));
156+
}
77157
}

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Section/ProductDetails/CategoryIds.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ class CategoryIds extends MultisuggestElement
4646
*/
4747
protected $advancedInventoryButton = '[data-index="advanced_inventory_button"]';
4848

49+
/**
50+
* Locator for MultiSelect element.
51+
*
52+
* @var string
53+
*/
54+
private $multiSelectElement = '.admin__action-multiselect-menu-inner-item';
55+
4956
/**
5057
* @constructor
5158
* @param BrowserInterface $browser
@@ -87,8 +94,15 @@ public function setValue($values)
8794
continue;
8895
}
8996
$this->keys([$value]);
97+
98+
// wait when some element of multiSelect will be visible.
99+
$this->waitUntil(function () {
100+
return $this->find($this->multiSelectElement)->isVisible() ? true : null;
101+
});
102+
90103
$searchedItem = $this->find(sprintf($this->resultItem, $value), Locator::SELECTOR_XPATH);
91104
$searchedItem->click();
105+
92106
$closeButton = $this->find($this->closeButton);
93107
if ($closeButton->isVisible()) {
94108
$closeButton->click();

dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/CreateSimpleProductEntityTest.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,6 @@
412412
<constraint name="Magento\Catalog\Test\Constraint\AssertAddToCartButtonAbsent" />
413413
</variation>
414414
<variation name="CreateSimpleProductEntityTestVariation23" summary="Create Simple Product with Creating New Category (Required Fields Only)" ticketId="MAGETWO-27293">
415-
<data name="tag" xsi:type="string">to_maintain:yes</data>
416-
<data name="issue" xsi:type="string">MAGETWO-65468: [FT] Magento\Catalog\Test\TestCase\Product\CreateSimpleProductEntityTest fails on Jenkins</data>
417415
<data name="product/data/category_ids/new_category" xsi:type="string">yes</data>
418416
<data name="product/data/category_ids/dataset" xsi:type="string">default_subcategory_without_url_key</data>
419417
<data name="product/data/website_ids/0/dataset" xsi:type="string">default</data>

0 commit comments

Comments
 (0)