Skip to content

Commit 0ef9256

Browse files
committed
Merge branch '2.0-develop' into MAGETWO-60965
2 parents c54b46f + 809c7c3 commit 0ef9256

File tree

59 files changed

+1727
-548
lines changed

Some content is hidden

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

59 files changed

+1727
-548
lines changed

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

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Magento\CatalogImportExport\Model\Export\RowCustomizerInterface;
1010
use Magento\CatalogImportExport\Model\Import\Product as ImportProductModel;
1111
use Magento\Bundle\Model\ResourceModel\Selection\Collection as SelectionCollection;
12-
use Magento\ImportExport\Controller\Adminhtml\Import;
1312
use Magento\ImportExport\Model\Import as ImportModel;
1413

1514
/**
@@ -291,10 +290,7 @@ protected function getPriceTypeValue($type)
291290
protected function cleanNotBundleAdditionalAttributes($dataRow)
292291
{
293292
if (!empty($dataRow['additional_attributes'])) {
294-
$additionalAttributes = explode(
295-
ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR,
296-
$dataRow['additional_attributes']
297-
);
293+
$additionalAttributes = $this->parseAdditionalAttributes($dataRow['additional_attributes']);
298294
$dataRow['additional_attributes'] = $this->getNotBundleAttributes($additionalAttributes);
299295
}
300296

@@ -309,17 +305,35 @@ protected function cleanNotBundleAdditionalAttributes($dataRow)
309305
*/
310306
protected function getNotBundleAttributes($additionalAttributes)
311307
{
312-
$cleanedAdditionalAttributes = '';
313-
foreach ($additionalAttributes as $attribute) {
314-
list($attributeCode, $attributeValue) = explode(ImportProductModel::PAIR_NAME_VALUE_SEPARATOR, $attribute);
315-
if (!in_array('bundle_' . $attributeCode, $this->bundleColumns)) {
316-
$cleanedAdditionalAttributes .= $attributeCode
317-
. ImportProductModel::PAIR_NAME_VALUE_SEPARATOR
318-
. $attributeValue
319-
. ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR;
308+
$filteredAttributes = [];
309+
foreach ($additionalAttributes as $code => $value) {
310+
if (!in_array('bundle_' . $code, $this->bundleColumns)) {
311+
$filteredAttributes[] = $code . ImportProductModel::PAIR_NAME_VALUE_SEPARATOR . $value;
320312
}
321313
}
314+
return implode(ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $filteredAttributes);
315+
}
322316

323-
return rtrim($cleanedAdditionalAttributes, ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR);
317+
/**
318+
* Retrieves additional attributes as array code=>value.
319+
*
320+
* @param string $additionalAttributes
321+
* @return array
322+
*/
323+
private function parseAdditionalAttributes($additionalAttributes)
324+
{
325+
$attributeNameValuePairs = explode(ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $additionalAttributes);
326+
$preparedAttributes = [];
327+
$code = '';
328+
foreach ($attributeNameValuePairs as $attributeData) {
329+
//process case when attribute has ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR inside its value
330+
if (strpos($attributeData, ImportProductModel::PAIR_NAME_VALUE_SEPARATOR) === false && $code) {
331+
$preparedAttributes[$code] .= ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR . $attributeData;
332+
} else {
333+
list($code, $value) = explode(ImportProductModel::PAIR_NAME_VALUE_SEPARATOR, $attributeData, 2);
334+
$preparedAttributes[$code] = $value;
335+
}
336+
}
337+
return $preparedAttributes;
324338
}
325339
}

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ protected function setUp()
5959
{
6060
$this->objectManagerHelper = new ObjectManagerHelper($this);
6161
$this->rowCustomizerMock = $this->objectManagerHelper->getObject(
62-
'\Magento\BundleImportExport\Model\Export\RowCustomizer'
62+
\Magento\BundleImportExport\Model\Export\RowCustomizer::class
6363
);
6464
$this->productResourceCollection = $this->getMock(
65-
'\Magento\Catalog\Model\ResourceModel\Product\Collection',
65+
\Magento\Catalog\Model\ResourceModel\Product\Collection::class,
6666
['addAttributeToFilter', 'getIterator'],
6767
[],
6868
'',
6969
false
7070
);
7171
$this->product = $this->getMock(
72-
'\Magento\Catalog\Model\Product',
72+
\Magento\Catalog\Model\Product::class,
7373
[
7474
'getId',
7575
'getPriceType',
@@ -91,7 +91,7 @@ protected function setUp()
9191
$this->product->expects($this->any())->method('getWeightType')->willReturn(1);
9292
$this->product->expects($this->any())->method('getTypeInstance')->willReturnSelf();
9393
$this->optionsCollection = $this->getMock(
94-
'\Magento\Bundle\Model\ResourceModel\Option\Collection',
94+
\Magento\Bundle\Model\ResourceModel\Option\Collection::class,
9595
['setOrder', 'getIterator'],
9696
[],
9797
'',
@@ -100,7 +100,7 @@ protected function setUp()
100100
$this->product->expects($this->any())->method('getOptionsCollection')->willReturn($this->optionsCollection);
101101
$this->optionsCollection->expects($this->any())->method('setOrder')->willReturnSelf();
102102
$this->option = $this->getMock(
103-
'\Magento\Bundle\Model\Option',
103+
\Magento\Bundle\Model\Option::class,
104104
['getId', 'getTitle', 'getType', 'getRequired'],
105105
[],
106106
'',
@@ -114,7 +114,7 @@ protected function setUp()
114114
$this->returnValue(new \ArrayIterator([$this->option]))
115115
);
116116
$this->selection = $this->getMock(
117-
'\Magento\Catalog\Model\Product',
117+
\Magento\Catalog\Model\Product::class,
118118
['getSku', 'getSelectionPriceValue', 'getIsDefault', 'getSelectionQty', 'getSelectionPriceType'],
119119
[],
120120
'',
@@ -125,7 +125,7 @@ protected function setUp()
125125
$this->selection->expects($this->any())->method('getSelectionQty')->willReturn(1);
126126
$this->selection->expects($this->any())->method('getSelectionPriceType')->willReturn(1);
127127
$this->selectionsCollection = $this->getMock(
128-
'\Magento\Bundle\Model\ResourceModel\Selection\Collection',
128+
\Magento\Bundle\Model\ResourceModel\Selection\Collection::class,
129129
['getIterator', 'addAttributeToSort'],
130130
[],
131131
'',
@@ -175,14 +175,16 @@ public function testAddHeaderColumns()
175175
public function testAddData()
176176
{
177177
$preparedData = $this->rowCustomizerMock->prepareData($this->productResourceCollection, [1]);
178+
$attributes = 'attribute=1,sku_type=1,attribute2="Text",price_type=1,price_view=1,weight_type=1,'
179+
. 'values=values,attribute3=One,Two,Three';
178180
$dataRow = [
179181
'sku' => 'sku1',
180-
'additional_attributes' => 'attribute=1,sku_type=1,price_type=1,price_view=1,weight_type=1,values=values'
182+
'additional_attributes' => $attributes
181183
];
182184
$preparedRow = $preparedData->addData($dataRow, 1);
183185
$expected = [
184186
'sku' => 'sku1',
185-
'additional_attributes' => 'attribute=1',
187+
'additional_attributes' => 'attribute=1,attribute2="Text",attribute3=One,Two,Three',
186188
'bundle_price_type' => 'fixed',
187189
'bundle_sku_type' => 'fixed',
188190
'bundle_price_view' => 'As low as',

app/code/Magento/Catalog/Controller/Adminhtml/Product/MassStatus.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
*/
77
namespace Magento\Catalog\Controller\Adminhtml\Product;
88

9-
use Magento\Backend\App\Action;
9+
use Magento\Backend\App\Action\Context;
1010
use Magento\Catalog\Controller\Adminhtml\Product;
11+
use Magento\Catalog\Model\Indexer\Product\Price\Processor;
12+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
1113
use Magento\Framework\Controller\ResultFactory;
1214
use Magento\Ui\Component\MassAction\Filter;
13-
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
1415

1516
class MassStatus extends \Magento\Catalog\Controller\Adminhtml\Product
1617
{
1718
/**
18-
* @var \Magento\Catalog\Model\Indexer\Product\Price\Processor
19+
* @var Processor
1920
*/
2021
protected $_productPriceIndexerProcessor;
2122

@@ -32,22 +33,23 @@ class MassStatus extends \Magento\Catalog\Controller\Adminhtml\Product
3233
protected $collectionFactory;
3334

3435
/**
35-
* @param Action\Context $context
36+
* @param Context $context
3637
* @param Builder $productBuilder
37-
* @param \Magento\Catalog\Model\Indexer\Product\Price\Processor $productPriceIndexerProcessor
38+
* @param Processor $productPriceIndexerProcessor
3839
* @param Filter $filter
3940
* @param CollectionFactory $collectionFactory
4041
*/
4142
public function __construct(
42-
\Magento\Backend\App\Action\Context $context,
43+
Context $context,
4344
Product\Builder $productBuilder,
44-
\Magento\Catalog\Model\Indexer\Product\Price\Processor $productPriceIndexerProcessor,
45+
Processor $productPriceIndexerProcessor,
4546
Filter $filter,
4647
CollectionFactory $collectionFactory
4748
) {
4849
$this->filter = $filter;
4950
$this->collectionFactory = $collectionFactory;
5051
$this->_productPriceIndexerProcessor = $productPriceIndexerProcessor;
52+
5153
parent::__construct($context, $productBuilder);
5254
}
5355

@@ -82,6 +84,14 @@ public function execute()
8284
$storeId = (int) $this->getRequest()->getParam('store', 0);
8385
$status = (int) $this->getRequest()->getParam('status');
8486

87+
/** @var array $filters */
88+
$filters = (array) $this->getRequest()->getParam('filters', []);
89+
90+
if (isset($filters['store_id'])) {
91+
/** @var int $storeId */
92+
$storeId = (int) $filters['store_id'];
93+
}
94+
8595
try {
8696
$this->_validateMassStatus($productIds, $status);
8797
$this->_objectManager->get('Magento\Catalog\Model\Product\Action')
@@ -96,6 +106,7 @@ public function execute()
96106

97107
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
98108
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
109+
99110
return $resultRedirect->setPath('catalog/*/', ['store' => $storeId]);
100111
}
101112
}

app/code/Magento/Catalog/Model/Product/Option/Type/File.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Catalog\Model\Product\Option\Type;
77

8+
use Magento\Framework\App\Filesystem\DirectoryList;
89
use Magento\Framework\Filesystem;
910
use Magento\Framework\Exception\LocalizedException;
1011
use Magento\Catalog\Model\Product\Exception as ProductException;
@@ -69,17 +70,23 @@ class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType
6970
*/
7071
protected $validatorFile;
7172

73+
/**
74+
* @var Filesystem
75+
*/
76+
private $filesystem;
77+
7278
/**
7379
* @param \Magento\Checkout\Model\Session $checkoutSession
7480
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
7581
* @param \Magento\Quote\Model\Quote\Item\OptionFactory $itemOptionFactory
76-
* @param \Magento\Catalog\Model\Product\Option\UrlBuilder $urlBuilder
77-
* @param \Magento\Framework\Escaper $escaper
7882
* @param \Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDatabase
7983
* @param File\ValidatorInfo $validatorInfo
8084
* @param File\ValidatorFile $validatorFile
85+
* @param \Magento\Catalog\Model\Product\Option\UrlBuilder $urlBuilder
86+
* @param \Magento\Framework\Escaper $escaper
8187
* @param array $data
82-
* @throws \Magento\Framework\Exception\FileSystemException
88+
* @param Filesystem $filesystem
89+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8390
*/
8491
public function __construct(
8592
\Magento\Checkout\Model\Session $checkoutSession,
@@ -90,12 +97,15 @@ public function __construct(
9097
\Magento\Catalog\Model\Product\Option\Type\File\ValidatorFile $validatorFile,
9198
\Magento\Catalog\Model\Product\Option\UrlBuilder $urlBuilder,
9299
\Magento\Framework\Escaper $escaper,
93-
array $data = []
100+
array $data = [],
101+
Filesystem $filesystem = null
94102
) {
95103
$this->_itemOptionFactory = $itemOptionFactory;
96104
$this->_urlBuilder = $urlBuilder;
97105
$this->_escaper = $escaper;
98106
$this->_coreFileStorageDatabase = $coreFileStorageDatabase;
107+
$this->filesystem = $filesystem ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Filesystem::class);
108+
$this->_rootDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
99109
$this->validatorInfo = $validatorInfo;
100110
$this->validatorFile = $validatorFile;
101111
parent::__construct($checkoutSession, $scopeConfig, $data);

0 commit comments

Comments
 (0)