Skip to content

Commit a3adb88

Browse files
authored
Merge pull request #421 from magento-falcons/MAGETWO-58658
Fixed issues: * MAGETWO-57820: [GITHUB] php bin/magento i18n:pack creates unwanted dir #6260 Bug - P1 * MAGETWO-58337: [Github] Duplicated & missing product rows in system product export #4531 * MAGETWO-58289: [Github] Product URL Key not automatically generating during import #5128 * MAGETWO-58134: [GitHub] Products became “out of stock” after update from 2.0.7 to 2.1.0 #5222 * MAGETWO-58132: [GitHub] module:uninstall can remove code it uses itself #5797 * MAGETWO-58236: Sync requirements of composer.json of Sample-data with mainline
2 parents 2c22ac4 + bf8953d commit a3adb88

File tree

15 files changed

+438
-42
lines changed

15 files changed

+438
-42
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ public function export()
817817
while (true) {
818818
++$page;
819819
$entityCollection = $this->_getEntityCollection(true);
820-
$entityCollection->setOrder('has_options', 'asc');
820+
$entityCollection->setOrder('entity_id', 'asc');
821821
$entityCollection->setStoreId(Store::DEFAULT_STORE_ID);
822822
$this->_prepareEntityCollection($entityCollection);
823823
$this->paginateCollection($page, $this->getItemsPerPage());

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,10 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
561561
/** @var array */
562562
protected $productUrlSuffix = [];
563563

564-
/** @var array */
564+
/**
565+
* @var array
566+
* @deprecated
567+
*/
565568
protected $productUrlKeys = [];
566569

567570
/**
@@ -1508,6 +1511,10 @@ protected function _saveProducts()
15081511
}
15091512
$rowScope = $this->getRowScope($rowData);
15101513

1514+
if (empty($rowData[self::URL_KEY])) {
1515+
$rowData[self::URL_KEY] = $this->getUrlKey($rowData);
1516+
}
1517+
15111518
$rowSku = $rowData[self::COL_SKU];
15121519

15131520
if (null === $rowSku) {
@@ -2562,12 +2569,14 @@ protected function getProductUrlSuffix($storeId = null)
25622569
protected function getUrlKey($rowData)
25632570
{
25642571
if (!empty($rowData[self::URL_KEY])) {
2565-
$this->productUrlKeys[$rowData[self::COL_SKU]] = $rowData[self::URL_KEY];
2572+
return $rowData[self::URL_KEY];
2573+
}
2574+
2575+
if (!empty($rowData[self::COL_NAME])) {
2576+
return $this->productUrl->formatUrlKey($rowData[self::COL_NAME]);
25662577
}
2567-
$urlKey = !empty($this->productUrlKeys[$rowData[self::COL_SKU]])
2568-
? $this->productUrlKeys[$rowData[self::COL_SKU]]
2569-
: $this->productUrl->formatUrlKey($rowData[self::COL_NAME]);
2570-
return $urlKey;
2578+
2579+
return '';
25712580
}
25722581

25732582
/**

app/code/Magento/CatalogImportExport/Test/Unit/Model/Export/ProductTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ public function testExportCountZeroBreakInternalCalls()
403403
$this->product->expects($this->once())->method('_prepareEntityCollection')->with($this->abstractCollection);
404404
$this->product->expects($this->once())->method('getItemsPerPage')->willReturn($itemsPerPage);
405405
$this->product->expects($this->once())->method('paginateCollection')->with($page, $itemsPerPage);
406-
$this->abstractCollection->expects($this->once())->method('setOrder')->with('has_options', 'asc');
406+
$this->abstractCollection->expects($this->once())->method('setOrder')->with('entity_id', 'asc');
407407
$this->abstractCollection->expects($this->once())->method('setStoreId')->with(Store::DEFAULT_STORE_ID);
408408

409409
$this->abstractCollection->expects($this->once())->method('count')->willReturn(0);
@@ -434,7 +434,7 @@ public function testExportCurPageEqualToLastBreakInternalCalls()
434434
$this->product->expects($this->once())->method('_prepareEntityCollection')->with($this->abstractCollection);
435435
$this->product->expects($this->once())->method('getItemsPerPage')->willReturn($itemsPerPage);
436436
$this->product->expects($this->once())->method('paginateCollection')->with($page, $itemsPerPage);
437-
$this->abstractCollection->expects($this->once())->method('setOrder')->with('has_options', 'asc');
437+
$this->abstractCollection->expects($this->once())->method('setOrder')->with('entity_id', 'asc');
438438
$this->abstractCollection->expects($this->once())->method('setStoreId')->with(Store::DEFAULT_STORE_ID);
439439

440440
$this->abstractCollection->expects($this->once())->method('count')->willReturn(1);
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogInventory\Setup;
7+
8+
use Magento\CatalogInventory\Api\StockConfigurationInterface;
9+
use Magento\Framework\Indexer\AbstractProcessor;
10+
use Magento\Framework\Setup\UpgradeDataInterface;
11+
use Magento\Framework\Setup\ModuleContextInterface;
12+
use Magento\Framework\Setup\ModuleDataSetupInterface;
13+
use Magento\Store\Model\StoreManagerInterface;
14+
15+
/**
16+
* Upgrade Data script
17+
* @codeCoverageIgnore
18+
*/
19+
class UpgradeData implements UpgradeDataInterface
20+
{
21+
/**
22+
* @var StockConfigurationInterface
23+
*/
24+
private $configuration;
25+
26+
/**
27+
* @var AbstractProcessor
28+
*/
29+
private $indexerProcessor;
30+
31+
/**
32+
* @var StoreManagerInterface
33+
*/
34+
private $storeManager;
35+
36+
/**
37+
* @param StockConfigurationInterface $configuration
38+
* @param StoreManagerInterface $storeManager
39+
* @param AbstractProcessor $indexerProcessor
40+
*/
41+
public function __construct(
42+
StockConfigurationInterface $configuration,
43+
StoreManagerInterface $storeManager,
44+
AbstractProcessor $indexerProcessor
45+
) {
46+
$this->configuration = $configuration;
47+
$this->storeManager = $storeManager;
48+
$this->indexerProcessor = $indexerProcessor;
49+
}
50+
51+
/**
52+
* {@inheritdoc}
53+
*/
54+
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
55+
{
56+
$setup->startSetup();
57+
if (version_compare($context->getVersion(), '2.0.2') < 0) {
58+
$this->upgradeCatalogInventoryStockItem($setup);
59+
}
60+
$setup->endSetup();
61+
}
62+
63+
/**
64+
* @param ModuleDataSetupInterface $setup
65+
* @return void
66+
*/
67+
private function upgradeCatalogInventoryStockItem($setup)
68+
{
69+
$setup->getConnection()->update(
70+
$setup->getTable('cataloginventory_stock_item'),
71+
['website_id' => $this->configuration->getDefaultScopeId()],
72+
['website_id = ?' => $this->storeManager->getWebsite()->getId()]
73+
);
74+
$this->indexerProcessor->getIndexer()->invalidate();
75+
}
76+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,9 @@
7474
<type name="Magento\Catalog\Api\ProductRepositoryInterface">
7575
<plugin name="catalogInventoryAroundSave" sortOrder="20" type="Magento\CatalogInventory\Model\Plugin\AroundProductRepositorySave"/>
7676
</type>
77+
<type name="Magento\CatalogInventory\Setup\UpgradeData">
78+
<arguments>
79+
<argument name="indexerProcessor" xsi:type="object">Magento\CatalogInventory\Model\Indexer\Stock\Processor</argument>
80+
</arguments>
81+
</type>
7782
</config>

app/code/Magento/CatalogInventory/etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9-
<module name="Magento_CatalogInventory" setup_version="2.0.1">
9+
<module name="Magento_CatalogInventory" setup_version="2.0.2">
1010
<sequence>
1111
<module name="Magento_Catalog"/>
1212
</sequence>

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,42 @@ public function testExistingProductWithUrlKeys()
12311231
}
12321232
}
12331233

1234+
/**
1235+
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_url_key.php
1236+
* @magentoAppIsolation enabled
1237+
*/
1238+
public function testImportWithoutUrlKeys()
1239+
{
1240+
$products = [
1241+
'simple1' => 'simple-1',
1242+
'simple2' => 'simple-2',
1243+
'simple3' => 'simple-3'
1244+
];
1245+
$filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
1246+
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
1247+
$source = $this->objectManager->create(
1248+
\Magento\ImportExport\Model\Import\Source\Csv::class,
1249+
[
1250+
'file' => __DIR__ . '/_files/products_to_import_without_url_keys.csv',
1251+
'directory' => $directory
1252+
]
1253+
);
1254+
1255+
$errors = $this->_model->setParameters(
1256+
['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product']
1257+
)
1258+
->setSource($source)
1259+
->validateData();
1260+
1261+
$this->assertTrue($errors->getErrorsCount() == 0);
1262+
$this->_model->importData();
1263+
1264+
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
1265+
foreach ($products as $productSku => $productUrlKey) {
1266+
$this->assertEquals($productUrlKey, $productRepository->get($productSku)->getUrlKey());
1267+
}
1268+
}
1269+
12341270
/**
12351271
* @magentoAppIsolation enabled
12361272
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
sku,product_type,store_view_code,name,price,attribute_set_code,url_key
2+
simple1,simple,,"simple 1",25,Default,""
3+
simple2,simple,,"simple 2",34,Default,""
4+
simple3,simple,,"simple 3",58,Default,""

dev/tests/integration/testsuite/Magento/Framework/Composer/RemoveTest.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@
55
*/
66
namespace Magento\Framework\Composer;
77

8-
use Magento\Framework\App\Filesystem\DirectoryList;
8+
use Magento\Composer\MagentoComposerApplication;
99

1010
class RemoveTest extends \PHPUnit_Framework_TestCase
1111
{
1212
public function testRemove()
1313
{
14-
$composerAppFactory = $this->getMock(
15-
\Magento\Framework\Composer\MagentoComposerApplicationFactory::class,
16-
[],
17-
[],
18-
'',
19-
false
20-
);
14+
$composerAppFactory = $this->getMockBuilder(MagentoComposerApplicationFactory::class)
15+
->disableOriginalConstructor()
16+
->getMock();
17+
$composerApp = $this->getMockBuilder(MagentoComposerApplication::class)
18+
->disableOriginalConstructor()
19+
->getMock();
2120

22-
$composerApp = $this->getMock(
23-
\Magento\Composer\MagentoComposerApplication::class,
24-
[],
25-
[],
26-
'',
27-
false
28-
);
29-
30-
$composerApp->expects($this->once())->method('runComposerCommand');
31-
32-
$composerAppFactory->expects($this->once())->method('create')->willReturn($composerApp);
21+
$composerApp->expects($this->once())
22+
->method('runComposerCommand')
23+
->with(
24+
[
25+
'command' => 'remove',
26+
'packages' => ['magento/package-a', 'magento/package-b'],
27+
'--no-update' => true,
28+
]
29+
);
30+
$composerAppFactory->expects($this->once())
31+
->method('create')
32+
->willReturn($composerApp);
3333

3434
$remove = new Remove($composerAppFactory);
3535
$remove->remove(['magento/package-a', 'magento/package-b']);

lib/internal/Magento/Framework/Composer/Remove.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public function remove(array $packages)
4545
return $composerApplication->runComposerCommand(
4646
[
4747
'command' => 'remove',
48-
'packages' => $packages
48+
'packages' => $packages,
49+
'--no-update' => true,
4950
]
5051
);
5152
}

setup/src/Magento/Setup/Module/I18n/Context.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private function getComponentName($componentType, $path)
9393
*
9494
* @param string $type
9595
* @param array $value
96-
* @return string
96+
* @return string|null
9797
* @throws \InvalidArgumentException
9898
*/
9999
public function buildPathToLocaleDirectoryByContext($type, $value)
@@ -111,6 +111,7 @@ public function buildPathToLocaleDirectoryByContext($type, $value)
111111
default:
112112
throw new \InvalidArgumentException(sprintf('Invalid context given: "%s".', $type));
113113
}
114-
return $path . '/' . self::LOCALE_DIRECTORY . '/';
114+
115+
return (null === $path) ? null : $path . '/' . self::LOCALE_DIRECTORY . '/';
115116
}
116117
}

setup/src/Magento/Setup/Module/I18n/Pack/Writer/File/AbstractFile.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ protected function _buildPackFilesData(Dictionary $dictionary)
121121
} catch (\InvalidArgumentException $e) {
122122
throw new \InvalidArgumentException($e->getMessage() . ' Row #' . ($key + 1) . '.');
123123
}
124+
125+
if (null === $path) {
126+
continue;
127+
}
128+
124129
$filename = $path . $this->_locale . '.' . $this->_getFileExtension();
125130
$files[$filename][$phrase->getPhrase()] = $phrase;
126131
}

setup/src/Magento/Setup/Test/Unit/Module/I18n/ContextTest.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testGetContextByPath($context, $path, $pathValues)
4141
{
4242
$this->componentRegistrar->expects($this->any())
4343
->method('getPaths')
44-
->will($this->returnValueMap($pathValues));
44+
->willReturnMap($pathValues);
4545
$this->context = new Context($this->componentRegistrar);
4646
$this->assertEquals($context, $this->context->getContextByPath($path));
4747
}
@@ -108,10 +108,8 @@ public function testBuildPathToLocaleDirectoryByContext($path, $context, $regist
108108
$paths[$module[1]] = $module[2];
109109
}
110110
$this->componentRegistrar->expects($this->any())
111-
->method('getPaths')
112-
->with(ComponentRegistrar::MODULE)
113-
->willReturn($paths);
114-
$this->componentRegistrar->expects($this->any())->method('getPath')->will($this->returnValueMap($registrar));
111+
->method('getPath')
112+
->willReturnMap($registrar);
115113
$this->context = new Context($this->componentRegistrar);
116114
$this->assertEquals($path, $this->context->buildPathToLocaleDirectoryByContext($context[0], $context[1]));
117115
}
@@ -127,7 +125,22 @@ public function dataProviderPathToLocaleDirectoryByContext()
127125
[Context::CONTEXT_TYPE_MODULE, 'Magento_Module'],
128126
[[ComponentRegistrar::MODULE, 'Magento_Module', BP . '/app/code/Magento/Module']]
129127
],
130-
['/i18n/', [Context::CONTEXT_TYPE_THEME, 'theme/test.phtml'], []],
128+
[
129+
BP . '/app/design/frontend/Magento/luma/i18n/',
130+
[Context::CONTEXT_TYPE_THEME, 'frontend/Magento/luma'],
131+
[[ComponentRegistrar::THEME, 'frontend/Magento/luma', BP . '/app/design/frontend/Magento/luma']]
132+
],
133+
134+
[
135+
null,
136+
[Context::CONTEXT_TYPE_MODULE, 'Unregistered_Module'],
137+
[[ComponentRegistrar::MODULE, 'Unregistered_Module', null]]
138+
],
139+
[
140+
null,
141+
[Context::CONTEXT_TYPE_THEME, 'frontend/Magento/unregistered'],
142+
[[ComponentRegistrar::THEME, 'frontend/Magento/unregistered', null]]
143+
],
131144
[BP . '/lib/web/i18n/', [Context::CONTEXT_TYPE_LIB, 'lib/web/module/test.phtml'], []],
132145
];
133146
}
@@ -138,10 +151,8 @@ public function dataProviderPathToLocaleDirectoryByContext()
138151
*/
139152
public function testBuildPathToLocaleDirectoryByContextWithInvalidType()
140153
{
141-
$this->componentRegistrar->expects($this->any())
142-
->method('getPaths')
143-
->with(ComponentRegistrar::MODULE)
144-
->willReturn(['module' => '/path/to/module']);
154+
$this->componentRegistrar->expects($this->never())
155+
->method('getPath');
145156
$this->context = new Context($this->componentRegistrar);
146157
$this->context->buildPathToLocaleDirectoryByContext('invalid_type', 'Magento_Module');
147158
}

0 commit comments

Comments
 (0)