Skip to content

Commit

Permalink
Merge pull request #580 from magento-east/pr-2.0
Browse files Browse the repository at this point in the history
[EAST] Bugfixes 2.0.11
  • Loading branch information
Volodymyr Klymenko authored Nov 11, 2016
2 parents 0d31c3e + 6aa98c0 commit ca68e6e
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 53 deletions.
42 changes: 28 additions & 14 deletions app/code/Magento/BundleImportExport/Model/Export/RowCustomizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Magento\CatalogImportExport\Model\Export\RowCustomizerInterface;
use Magento\CatalogImportExport\Model\Import\Product as ImportProductModel;
use Magento\Bundle\Model\ResourceModel\Selection\Collection as SelectionCollection;
use Magento\ImportExport\Controller\Adminhtml\Import;
use Magento\ImportExport\Model\Import as ImportModel;

/**
Expand Down Expand Up @@ -291,10 +290,7 @@ protected function getPriceTypeValue($type)
protected function cleanNotBundleAdditionalAttributes($dataRow)
{
if (!empty($dataRow['additional_attributes'])) {
$additionalAttributes = explode(
ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR,
$dataRow['additional_attributes']
);
$additionalAttributes = $this->parseAdditionalAttributes($dataRow['additional_attributes']);
$dataRow['additional_attributes'] = $this->getNotBundleAttributes($additionalAttributes);
}

Expand All @@ -309,17 +305,35 @@ protected function cleanNotBundleAdditionalAttributes($dataRow)
*/
protected function getNotBundleAttributes($additionalAttributes)
{
$cleanedAdditionalAttributes = '';
foreach ($additionalAttributes as $attribute) {
list($attributeCode, $attributeValue) = explode(ImportProductModel::PAIR_NAME_VALUE_SEPARATOR, $attribute);
if (!in_array('bundle_' . $attributeCode, $this->bundleColumns)) {
$cleanedAdditionalAttributes .= $attributeCode
. ImportProductModel::PAIR_NAME_VALUE_SEPARATOR
. $attributeValue
. ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR;
$filteredAttributes = [];
foreach ($additionalAttributes as $code => $value) {
if (!in_array('bundle_' . $code, $this->bundleColumns)) {
$filteredAttributes[] = $code . ImportProductModel::PAIR_NAME_VALUE_SEPARATOR . $value;
}
}
return implode(ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $filteredAttributes);
}

return rtrim($cleanedAdditionalAttributes, ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR);
/**
* Retrieves additional attributes as array code=>value.
*
* @param string $additionalAttributes
* @return array
*/
private function parseAdditionalAttributes($additionalAttributes)
{
$attributeNameValuePairs = explode(ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $additionalAttributes);
$preparedAttributes = [];
$code = '';
foreach ($attributeNameValuePairs as $attributeData) {
//process case when attribute has ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR inside its value
if (strpos($attributeData, ImportProductModel::PAIR_NAME_VALUE_SEPARATOR) === false && $code) {
$preparedAttributes[$code] .= ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR . $attributeData;
} else {
list($code, $value) = explode(ImportProductModel::PAIR_NAME_VALUE_SEPARATOR, $attributeData, 2);
$preparedAttributes[$code] = $value;
}
}
return $preparedAttributes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ protected function setUp()
{
$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->rowCustomizerMock = $this->objectManagerHelper->getObject(
'\Magento\BundleImportExport\Model\Export\RowCustomizer'
\Magento\BundleImportExport\Model\Export\RowCustomizer::class
);
$this->productResourceCollection = $this->getMock(
'\Magento\Catalog\Model\ResourceModel\Product\Collection',
\Magento\Catalog\Model\ResourceModel\Product\Collection::class,
['addAttributeToFilter', 'getIterator'],
[],
'',
false
);
$this->product = $this->getMock(
'\Magento\Catalog\Model\Product',
\Magento\Catalog\Model\Product::class,
[
'getId',
'getPriceType',
Expand All @@ -91,7 +91,7 @@ protected function setUp()
$this->product->expects($this->any())->method('getWeightType')->willReturn(1);
$this->product->expects($this->any())->method('getTypeInstance')->willReturnSelf();
$this->optionsCollection = $this->getMock(
'\Magento\Bundle\Model\ResourceModel\Option\Collection',
\Magento\Bundle\Model\ResourceModel\Option\Collection::class,
['setOrder', 'getIterator'],
[],
'',
Expand All @@ -100,7 +100,7 @@ protected function setUp()
$this->product->expects($this->any())->method('getOptionsCollection')->willReturn($this->optionsCollection);
$this->optionsCollection->expects($this->any())->method('setOrder')->willReturnSelf();
$this->option = $this->getMock(
'\Magento\Bundle\Model\Option',
\Magento\Bundle\Model\Option::class,
['getId', 'getTitle', 'getType', 'getRequired'],
[],
'',
Expand All @@ -114,7 +114,7 @@ protected function setUp()
$this->returnValue(new \ArrayIterator([$this->option]))
);
$this->selection = $this->getMock(
'\Magento\Catalog\Model\Product',
\Magento\Catalog\Model\Product::class,
['getSku', 'getSelectionPriceValue', 'getIsDefault', 'getSelectionQty', 'getSelectionPriceType'],
[],
'',
Expand All @@ -125,7 +125,7 @@ protected function setUp()
$this->selection->expects($this->any())->method('getSelectionQty')->willReturn(1);
$this->selection->expects($this->any())->method('getSelectionPriceType')->willReturn(1);
$this->selectionsCollection = $this->getMock(
'\Magento\Bundle\Model\ResourceModel\Selection\Collection',
\Magento\Bundle\Model\ResourceModel\Selection\Collection::class,
['getIterator', 'addAttributeToSort'],
[],
'',
Expand Down Expand Up @@ -175,14 +175,16 @@ public function testAddHeaderColumns()
public function testAddData()
{
$preparedData = $this->rowCustomizerMock->prepareData($this->productResourceCollection, [1]);
$attributes = 'attribute=1,sku_type=1,attribute2="Text",price_type=1,price_view=1,weight_type=1,'
. 'values=values,attribute3=One,Two,Three';
$dataRow = [
'sku' => 'sku1',
'additional_attributes' => 'attribute=1,sku_type=1,price_type=1,price_view=1,weight_type=1,values=values'
'additional_attributes' => $attributes
];
$preparedRow = $preparedData->addData($dataRow, 1);
$expected = [
'sku' => 'sku1',
'additional_attributes' => 'attribute=1',
'additional_attributes' => 'attribute=1,attribute2="Text",attribute3=One,Two,Three',
'bundle_price_type' => 'fixed',
'bundle_sku_type' => 'fixed',
'bundle_price_view' => 'As low as',
Expand Down
11 changes: 4 additions & 7 deletions app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -2394,15 +2394,12 @@ private function parseAttributesWithoutWrappedValues($attributesData)
$code = '';
foreach ($attributeNameValuePairs as $attributeData) {
//process case when attribute has ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR inside its value
if (strpos($attributeData, self::PAIR_NAME_VALUE_SEPARATOR) === false) {
if (!$code) {
continue;
}
if (strpos($attributeData, self::PAIR_NAME_VALUE_SEPARATOR) === false && $code) {
$preparedAttributes[$code] .= $this->getMultipleValueSeparator() . $attributeData;
continue;
} else {
list($code, $value) = explode(self::PAIR_NAME_VALUE_SEPARATOR, $attributeData, 2);
$preparedAttributes[$code] = $value;
}
list($code, $value) = explode(self::PAIR_NAME_VALUE_SEPARATOR, $attributeData, 2);
$preparedAttributes[$code] = $value;
}
return $preparedAttributes;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "magento/module-sample-test",
"description": "test sample module",
"require": {
"php": "~5.5.0|~5.6.0|~7.0.0",
"magento/framework": "100.0.*",
"magento/module-integration": "100.0.*"
},
"type": "magento2-module",
"version": "1.0",
"extra": {
"map": [
[
"*",
"Magento/TestModuleSample"
]
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_TestModuleSample" setup_version="0.0.1" active="true">
</module>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

use Magento\Framework\Component\ComponentRegistrar;

$registrar = new ComponentRegistrar();
if ($registrar->getPath(ComponentRegistrar::MODULE, 'Magento_TestModuleSample') === null) {
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestModuleSample', __DIR__);
}
3 changes: 3 additions & 0 deletions dev/tests/integration/framework/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
define('TESTS_TEMP_DIR', $testsBaseDir . '/tmp');
}

$testFrameworkDir = __DIR__;
require_once __DIR__ . '/deployTestModules.php';

try {
/* Bootstrap the application */
$settings = new \Magento\TestFramework\Bootstrap\Settings($testsBaseDir, get_defined_constants());
Expand Down
40 changes: 40 additions & 0 deletions dev/tests/integration/framework/deployTestModules.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

/**
* @var $testFrameworkDir string - Must be defined in parent script.
*/

/** Copy test modules to app/code/Magento to make them visible for Magento instance */
$pathToCommittedTestModules = $testFrameworkDir . '/../_files/Magento';
$pathToInstalledMagentoInstanceModules = $testFrameworkDir . '/../../../../app/code/Magento';
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($pathToCommittedTestModules, RecursiveDirectoryIterator::FOLLOW_SYMLINKS)
);
/** @var SplFileInfo $file */
foreach ($iterator as $file) {
if (!$file->isDir()) {
$source = $file->getPathname();
$relativePath = substr($source, strlen($pathToCommittedTestModules));
$destination = $pathToInstalledMagentoInstanceModules . $relativePath;
$targetDir = dirname($destination);
if (!is_dir($targetDir)) {
mkdir($targetDir, 0755, true);
}
copy($source, $destination);
}
}
unset($iterator, $file);

// Register the modules under '_files/'
$pathPattern = $pathToInstalledMagentoInstanceModules . '/TestModule*/registration.php';
$files = glob($pathPattern, GLOB_NOSORT);
if ($files === false) {
throw new \RuntimeException('glob() returned error while searching in \'' . $pathPattern . '\'');
}
foreach ($files as $file) {
include $file;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function setUp()
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->model = $this->objectManager->create(
'Magento\BundleImportExport\Model\Export\RowCustomizer'
\Magento\BundleImportExport\Model\Export\RowCustomizer::class
);
}

Expand All @@ -33,16 +33,26 @@ protected function setUp()
*/
public function testPrepareData()
{
$collection = $this->objectManager->get('Magento\Catalog\Model\ResourceModel\Product\Collection');
$parsedAdditionalAttributes = 'text_attribute=!@#$%^&*()_+1234567890-=|\\:;"\'<,>.?/'
. ',text_attribute2=,';
$allAdditionalAttributes = $parsedAdditionalAttributes . ',weight_type=0,price_type=1';
/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection */
$collection = $this->objectManager->get(\Magento\Catalog\Model\ResourceModel\Product\Collection::class);
$select = $collection->getConnection()->select()
->from(['p' => $collection->getTable('catalog_product_entity')], ['sku', 'entity_id'])
->where('sku IN(?)', ['simple', 'custom-design-simple-product', 'bundle-product']);
$ids = $collection->getConnection()->fetchPairs($select);
$select = (string)$collection->getSelect();
$this->model->prepareData($collection, [1, 2, 3, 4]);
$this->assertEquals($select, (string)$collection->getSelect());
$result = $this->model->addData([], 3);
$result = $this->model->addData(['additional_attributes' => $allAdditionalAttributes], $ids['bundle-product']);
$this->assertArrayHasKey('bundle_price_type', $result);
$this->assertArrayHasKey('bundle_sku_type', $result);
$this->assertArrayHasKey('bundle_price_view', $result);
$this->assertArrayHasKey('bundle_weight_type', $result);
$this->assertArrayHasKey('bundle_values', $result);
$this->assertContains('sku=simple,', $result['bundle_values']);
$this->assertEquals([], $this->model->addData([], $ids['simple']));
$this->assertEquals($parsedAdditionalAttributes, $result['additional_attributes']);
}
}
Loading

0 comments on commit ca68e6e

Please sign in to comment.