Skip to content

Commit 35a6465

Browse files
author
Evgeniy Kolesov
committed
Merge remote-tracking branch 'origin/develop' into PR-copy1
2 parents 363602e + 03033d3 commit 35a6465

File tree

45 files changed

+2081
-57
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2081
-57
lines changed

app/code/Magento/BundleImportExport/Model/Export/RowCustomizer.php

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Bundle\Model\ResourceModel\Selection\Collection as SelectionCollection;
1212
use Magento\ImportExport\Controller\Adminhtml\Import;
1313
use Magento\ImportExport\Model\Import as ImportModel;
14+
use \Magento\Catalog\Model\Product\Type\AbstractType;
1415

1516
/**
1617
* Class RowCustomizer
@@ -87,6 +88,32 @@ class RowCustomizer implements RowCustomizerInterface
8788
*/
8889
protected $bundleData = [];
8990

91+
/**
92+
* Column name for shipment_type attribute
93+
*
94+
* @var string
95+
*/
96+
private $shipmentTypeColumn = 'bundle_shipment_type';
97+
98+
/**
99+
* Mapping for shipment type
100+
*
101+
* @var array
102+
*/
103+
private $shipmentTypeMapping = [
104+
AbstractType::SHIPMENT_TOGETHER => 'together',
105+
AbstractType::SHIPMENT_SEPARATELY => 'separately',
106+
];
107+
108+
/**
109+
* Retrieve list of bundle specific columns
110+
* @return array
111+
*/
112+
private function getBundleColumns()
113+
{
114+
return array_merge($this->bundleColumns, [$this->shipmentTypeColumn]);
115+
}
116+
90117
/**
91118
* Prepare data for export
92119
*
@@ -116,7 +143,7 @@ public function prepareData($collection, $productIds)
116143
*/
117144
public function addHeaderColumns($columns)
118145
{
119-
$columns = array_merge($columns, $this->bundleColumns);
146+
$columns = array_merge($columns, $this->getBundleColumns());
120147

121148
return $columns;
122149
}
@@ -161,6 +188,9 @@ protected function populateBundleData($collection)
161188
foreach ($collection as $product) {
162189
$id = $product->getEntityId();
163190
$this->bundleData[$id][self::BUNDLE_PRICE_TYPE_COL] = $this->getTypeValue($product->getPriceType());
191+
$this->bundleData[$id][$this->shipmentTypeColumn] = $this->getShipmentTypeValue(
192+
$product->getShipmentType()
193+
);
164194
$this->bundleData[$id][self::BUNDLE_SKU_TYPE_COL] = $this->getTypeValue($product->getSkuType());
165195
$this->bundleData[$id][self::BUNDLE_PRICE_VIEW_COL] = $this->getPriceViewValue($product->getPriceView());
166196
$this->bundleData[$id][self::BUNDLE_WEIGHT_TYPE_COL] = $this->getTypeValue($product->getWeightType());
@@ -281,6 +311,17 @@ protected function getPriceTypeValue($type)
281311
return isset($this->priceTypeMapping[$type]) ? $this->priceTypeMapping[$type] : null;
282312
}
283313

314+
/**
315+
* Retrieve bundle shipment type value by code
316+
*
317+
* @param string $type
318+
* @return string
319+
*/
320+
private function getShipmentTypeValue($type)
321+
{
322+
return isset($this->shipmentTypeMapping[$type]) ? $this->shipmentTypeMapping[$type] : null;
323+
}
324+
284325
/**
285326
* Remove bundle specified additional attributes as now they are stored in specified columns
286327
*
@@ -311,7 +352,7 @@ protected function getNotBundleAttributes($additionalAttributes)
311352
$cleanedAdditionalAttributes = '';
312353
foreach ($additionalAttributes as $attribute) {
313354
list($attributeCode, $attributeValue) = explode(ImportProductModel::PAIR_NAME_VALUE_SEPARATOR, $attribute);
314-
if (!in_array('bundle_' . $attributeCode, $this->bundleColumns)) {
355+
if (!in_array('bundle_' . $attributeCode, $this->getBundleColumns())) {
315356
$cleanedAdditionalAttributes .= $attributeCode
316357
. ImportProductModel::PAIR_NAME_VALUE_SEPARATOR
317358
. $attributeValue

app/code/Magento/BundleImportExport/Model/Import/Product/Type/Bundle.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
namespace Magento\BundleImportExport\Model\Import\Product\Type;
1010

1111
use \Magento\Bundle\Model\Product\Price as BundlePrice;
12+
use \Magento\BundleImportExport\Model\Export\RowCustomizer;
13+
use \Magento\Catalog\Model\Product\Type\AbstractType;
1214

1315
/**
1416
* Class Bundle
@@ -113,6 +115,7 @@ class Bundle extends \Magento\CatalogImportExport\Model\Import\Product\Type\Abst
113115
*/
114116
protected $_customFieldsMapping = [
115117
'price_type' => 'bundle_price_type',
118+
'shipment_type' => 'bundle_shipment_type',
116119
'price_view' => 'bundle_price_view',
117120
'weight_type' => 'bundle_weight_type',
118121
'sku_type' => 'bundle_sku_type',
@@ -413,13 +416,20 @@ public function prepareAttributesWithDefaultValueForSave(array $rowData, $withDe
413416
protected function transformBundleCustomAttributes($rowData)
414417
{
415418
$resultAttrs = [];
416-
417-
foreach (array_keys($this->_customFieldsMapping) as $oldKey) {
419+
foreach ($this->_customFieldsMapping as $oldKey => $newKey) {
418420
if (isset($rowData[$oldKey])) {
419-
if ($oldKey != self::NOT_FIXED_DYNAMIC_ATTRIBUTE) {
420-
$resultAttrs[$oldKey] = (($rowData[$oldKey] == self::VALUE_FIXED) ?
421-
BundlePrice::PRICE_TYPE_FIXED :
422-
BundlePrice::PRICE_TYPE_DYNAMIC);
421+
switch ($newKey) {
422+
case $this->_customFieldsMapping['price_view']:
423+
break;
424+
case $this->_customFieldsMapping['shipment_type']:
425+
$resultAttrs[$oldKey] = (($rowData[$oldKey] == 'separately') ?
426+
AbstractType::SHIPMENT_SEPARATELY :
427+
AbstractType::SHIPMENT_TOGETHER);
428+
break;
429+
default:
430+
$resultAttrs[$oldKey] = (($rowData[$oldKey] == self::VALUE_FIXED) ?
431+
BundlePrice::PRICE_TYPE_FIXED :
432+
BundlePrice::PRICE_TYPE_DYNAMIC);
423433
}
424434
}
425435
}

app/code/Magento/BundleImportExport/Test/Unit/Model/Export/Product/RowCustomizerTest.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ protected function setUp()
7373
[
7474
'getEntityId',
7575
'getPriceType',
76+
'getShipmentType',
7677
'getSkuType',
7778
'getPriceView',
7879
'getWeightType',
@@ -86,6 +87,7 @@ protected function setUp()
8687
);
8788
$this->product->expects($this->any())->method('getEntityId')->willReturn(1);
8889
$this->product->expects($this->any())->method('getPriceType')->willReturn(1);
90+
$this->product->expects($this->any())->method('getShipmentType')->willReturn(1);
8991
$this->product->expects($this->any())->method('getSkuType')->willReturn(1);
9092
$this->product->expects($this->any())->method('getPriceView')->willReturn(1);
9193
$this->product->expects($this->any())->method('getWeightType')->willReturn(1);
@@ -159,12 +161,13 @@ public function testAddHeaderColumns()
159161
{
160162
$productData = [0 => 'sku'];
161163
$expectedData = [
162-
0 => 'sku',
163-
1 => 'bundle_price_type',
164-
2 => 'bundle_sku_type',
165-
3 => 'bundle_price_view',
166-
4 => 'bundle_weight_type',
167-
5 => 'bundle_values'
164+
'sku',
165+
'bundle_price_type',
166+
'bundle_sku_type',
167+
'bundle_price_view',
168+
'bundle_weight_type',
169+
'bundle_values',
170+
'bundle_shipment_type'
168171
];
169172
$this->assertEquals($expectedData, $this->rowCustomizerMock->addHeaderColumns($productData));
170173
}
@@ -175,15 +178,17 @@ public function testAddHeaderColumns()
175178
public function testAddData()
176179
{
177180
$preparedData = $this->rowCustomizerMock->prepareData($this->productResourceCollection, [1]);
181+
$attributes = 'attribute=1,sku_type=1,price_type=1,price_view=1,weight_type=1,values=values,shipment_type=1';
178182
$dataRow = [
179183
'sku' => 'sku1',
180-
'additional_attributes' => 'attribute=1,sku_type=1,price_type=1,price_view=1,weight_type=1,values=values'
184+
'additional_attributes' => $attributes
181185
];
182186
$preparedRow = $preparedData->addData($dataRow, 1);
183187
$expected = [
184188
'sku' => 'sku1',
185189
'additional_attributes' => 'attribute=1',
186190
'bundle_price_type' => 'fixed',
191+
'bundle_shipment_type' => 'separately',
187192
'bundle_sku_type' => 'fixed',
188193
'bundle_price_view' => 'As low as',
189194
'bundle_weight_type' => 'fixed',

app/code/Magento/BundleImportExport/Test/Unit/Model/Import/Product/Type/BundleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ public function testSaveData($skus, $bunch, $allowImport)
253253
'sku' => '1',
254254
'price' => '10',
255255
'price_type' => 'fixed',
256+
'shipment_type' => '1',
256257
'default_qty' => '1',
257258
'is_defaul' => '1',
258259
'position' => '1',
@@ -274,6 +275,7 @@ public function testSaveData($skus, $bunch, $allowImport)
274275
'sku' => '222',
275276
'price' => '10',
276277
'price_type' => 'percent',
278+
'shipment_type' => 0,
277279
'default_qty' => '2',
278280
'is_defaul' => '1',
279281
'position' => '6',
@@ -323,6 +325,7 @@ public function testSaveDataProvider()
323325
. 'sku=1,'
324326
. 'price=10,'
325327
. 'price_type=fixed,'
328+
. 'shipment_type=separately,'
326329
. 'default_qty=1,'
327330
. 'is_defaul=1,'
328331
. 'position=1,'
@@ -403,6 +406,7 @@ public function testIsRowValid()
403406
$this->entityModel->expects($this->any())->method('getRowScope')->will($this->returnValue(-1));
404407
$rowData = [
405408
'bundle_price_type' => 'dynamic',
409+
'bundle_shipment_type' => 'separately',
406410
'bundle_price_view' => 'bundle_price_view'
407411
];
408412
$this->assertEquals($this->bundle->isRowValid($rowData, 0), true);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Helper;
8+
9+
/**
10+
* Default Category helper
11+
*/
12+
class DefaultCategory
13+
{
14+
/**
15+
* Default Category ID
16+
*
17+
* @var int
18+
*/
19+
private $defaultCategoryId = 2;
20+
21+
/**
22+
* @return int
23+
*/
24+
public function getId()
25+
{
26+
return $this->defaultCategoryId;
27+
}
28+
}

app/code/Magento/Catalog/Setup/InstallData.php

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\Setup\InstallDataInterface;
1010
use Magento\Framework\Setup\ModuleContextInterface;
1111
use Magento\Framework\Setup\ModuleDataSetupInterface;
12+
use Magento\Catalog\Helper\DefaultCategory;
1213

1314
/**
1415
* @codeCoverageIgnore
@@ -22,6 +23,24 @@ class InstallData implements InstallDataInterface
2223
*/
2324
private $categorySetupFactory;
2425

26+
/**
27+
* @var DefaultCategory
28+
*/
29+
private $defaultCategory;
30+
31+
/**
32+
* @deprecated
33+
* @return DefaultCategory
34+
*/
35+
private function getDefaultCategory()
36+
{
37+
if ($this->defaultCategory === null) {
38+
$this->defaultCategory = \Magento\Framework\App\ObjectManager::getInstance()
39+
->get(DefaultCategory::class);
40+
}
41+
return $this->defaultCategory;
42+
}
43+
2544
/**
2645
* Init
2746
*
@@ -42,32 +61,35 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface
4261
{
4362
/** @var \Magento\Catalog\Setup\CategorySetup $categorySetup */
4463
$categorySetup = $this->categorySetupFactory->create(['setup' => $setup]);
64+
$rootCategoryId = \Magento\Catalog\Model\Category::TREE_ROOT_ID;
65+
$defaultCategoryId = $this->getDefaultCategory()->getId();
4566

4667
$categorySetup->installEntities();
4768
// Create Root Catalog Node
4869
$categorySetup->createCategory()
49-
->load(1)
50-
->setId(1)
70+
->load($rootCategoryId)
71+
->setId($rootCategoryId)
5172
->setStoreId(0)
52-
->setPath('1')
73+
->setPath($rootCategoryId)
5374
->setLevel(0)
5475
->setPosition(0)
5576
->setChildrenCount(0)
5677
->setName('Root Catalog')
5778
->setInitialSetupFlag(true)
5879
->save();
5980

81+
// Create Default Catalog Node
6082
$category = $categorySetup->createCategory();
61-
62-
$categorySetup->createCategory()
83+
$category->load($defaultCategoryId)
84+
->setId($defaultCategoryId)
6385
->setStoreId(0)
64-
->setPath('1')
86+
->setPath($rootCategoryId . '/' . $defaultCategoryId)
6587
->setName('Default Category')
6688
->setDisplayMode('PRODUCTS')
67-
->setAttributeSetId($category->getDefaultAttributeSetId())
6889
->setIsActive(1)
6990
->setLevel(1)
7091
->setInitialSetupFlag(true)
92+
->setAttributeSetId($category->getDefaultAttributeSetId())
7193
->save();
7294

7395
$data = [

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ protected function customizeNameListeners(array $meta)
350350
'imports' => [
351351
'handleChanges' => '${$.provider}:data.product.name',
352352
],
353+
'autoImportIfEmpty' => true,
354+
'allowImport' => $this->locator->getProduct()->getId() ? false : true,
353355
],
354356
],
355357
],
@@ -358,22 +360,6 @@ protected function customizeNameListeners(array $meta)
358360
$meta = $this->arrayManager->merge($listenerPath, $meta, $importsConfig);
359361
}
360362

361-
$skuPath = $this->arrayManager->findPath(ProductAttributeInterface::CODE_SKU, $meta, null, 'children');
362-
$meta = $this->arrayManager->merge(
363-
$skuPath,
364-
$meta,
365-
[
366-
'arguments' => [
367-
'data' => [
368-
'config' => [
369-
'autoImportIfEmpty' => true,
370-
'allowImport' => $this->locator->getProduct()->getId() ? false : true,
371-
],
372-
],
373-
],
374-
]
375-
);
376-
377363
$namePath = $this->arrayManager->findPath(ProductAttributeInterface::CODE_NAME, $meta, null, 'children');
378364

379365
return $this->arrayManager->merge(

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,8 +2365,13 @@ private function _setStockUseConfigFieldsValues($rowData)
23652365
{
23662366
$useConfigFields = array();
23672367
foreach ($rowData as $key => $value) {
2368-
if (isset($this->defaultStockData[$key]) && isset($this->defaultStockData[self::INVENTORY_USE_CONFIG_PREFIX . $key]) && !empty($value)) {
2369-
$useConfigFields[self::INVENTORY_USE_CONFIG_PREFIX . $key] = ($value == self::INVENTORY_USE_CONFIG) ? 1 : 0;
2368+
$useConfigName = self::INVENTORY_USE_CONFIG_PREFIX . $key;
2369+
if (isset($this->defaultStockData[$key])
2370+
&& isset($this->defaultStockData[$useConfigName])
2371+
&& !empty($value)
2372+
&& empty($rowData[$useConfigName])
2373+
) {
2374+
$useConfigFields[$useConfigName] = ($value == self::INVENTORY_USE_CONFIG) ? 1 : 0;
23702375
}
23712376
}
23722377
$rowData = array_merge($rowData, $useConfigFields);

0 commit comments

Comments
 (0)