Skip to content

Commit

Permalink
Merge pull request #460 from magento-nord/BUGS_PR
Browse files Browse the repository at this point in the history
[NORD] Bug fixes
  • Loading branch information
Onischenko, Yaroslav(yonischenko) committed Mar 20, 2016
2 parents 2d82d19 + c207e26 commit 03033d3
Show file tree
Hide file tree
Showing 45 changed files with 2,081 additions and 57 deletions.
45 changes: 43 additions & 2 deletions app/code/Magento/BundleImportExport/Model/Export/RowCustomizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magento\Bundle\Model\ResourceModel\Selection\Collection as SelectionCollection;
use Magento\ImportExport\Controller\Adminhtml\Import;
use Magento\ImportExport\Model\Import as ImportModel;
use \Magento\Catalog\Model\Product\Type\AbstractType;

/**
* Class RowCustomizer
Expand Down Expand Up @@ -87,6 +88,32 @@ class RowCustomizer implements RowCustomizerInterface
*/
protected $bundleData = [];

/**
* Column name for shipment_type attribute
*
* @var string
*/
private $shipmentTypeColumn = 'bundle_shipment_type';

/**
* Mapping for shipment type
*
* @var array
*/
private $shipmentTypeMapping = [
AbstractType::SHIPMENT_TOGETHER => 'together',
AbstractType::SHIPMENT_SEPARATELY => 'separately',
];

/**
* Retrieve list of bundle specific columns
* @return array
*/
private function getBundleColumns()
{
return array_merge($this->bundleColumns, [$this->shipmentTypeColumn]);
}

/**
* Prepare data for export
*
Expand Down Expand Up @@ -116,7 +143,7 @@ public function prepareData($collection, $productIds)
*/
public function addHeaderColumns($columns)
{
$columns = array_merge($columns, $this->bundleColumns);
$columns = array_merge($columns, $this->getBundleColumns());

return $columns;
}
Expand Down Expand Up @@ -161,6 +188,9 @@ protected function populateBundleData($collection)
foreach ($collection as $product) {
$id = $product->getEntityId();
$this->bundleData[$id][self::BUNDLE_PRICE_TYPE_COL] = $this->getTypeValue($product->getPriceType());
$this->bundleData[$id][$this->shipmentTypeColumn] = $this->getShipmentTypeValue(
$product->getShipmentType()
);
$this->bundleData[$id][self::BUNDLE_SKU_TYPE_COL] = $this->getTypeValue($product->getSkuType());
$this->bundleData[$id][self::BUNDLE_PRICE_VIEW_COL] = $this->getPriceViewValue($product->getPriceView());
$this->bundleData[$id][self::BUNDLE_WEIGHT_TYPE_COL] = $this->getTypeValue($product->getWeightType());
Expand Down Expand Up @@ -281,6 +311,17 @@ protected function getPriceTypeValue($type)
return isset($this->priceTypeMapping[$type]) ? $this->priceTypeMapping[$type] : null;
}

/**
* Retrieve bundle shipment type value by code
*
* @param string $type
* @return string
*/
private function getShipmentTypeValue($type)
{
return isset($this->shipmentTypeMapping[$type]) ? $this->shipmentTypeMapping[$type] : null;
}

/**
* Remove bundle specified additional attributes as now they are stored in specified columns
*
Expand Down Expand Up @@ -311,7 +352,7 @@ 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)) {
if (!in_array('bundle_' . $attributeCode, $this->getBundleColumns())) {
$cleanedAdditionalAttributes .= $attributeCode
. ImportProductModel::PAIR_NAME_VALUE_SEPARATOR
. $attributeValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
namespace Magento\BundleImportExport\Model\Import\Product\Type;

use \Magento\Bundle\Model\Product\Price as BundlePrice;
use \Magento\BundleImportExport\Model\Export\RowCustomizer;
use \Magento\Catalog\Model\Product\Type\AbstractType;

/**
* Class Bundle
Expand Down Expand Up @@ -113,6 +115,7 @@ class Bundle extends \Magento\CatalogImportExport\Model\Import\Product\Type\Abst
*/
protected $_customFieldsMapping = [
'price_type' => 'bundle_price_type',
'shipment_type' => 'bundle_shipment_type',
'price_view' => 'bundle_price_view',
'weight_type' => 'bundle_weight_type',
'sku_type' => 'bundle_sku_type',
Expand Down Expand Up @@ -413,13 +416,20 @@ public function prepareAttributesWithDefaultValueForSave(array $rowData, $withDe
protected function transformBundleCustomAttributes($rowData)
{
$resultAttrs = [];

foreach (array_keys($this->_customFieldsMapping) as $oldKey) {
foreach ($this->_customFieldsMapping as $oldKey => $newKey) {
if (isset($rowData[$oldKey])) {
if ($oldKey != self::NOT_FIXED_DYNAMIC_ATTRIBUTE) {
$resultAttrs[$oldKey] = (($rowData[$oldKey] == self::VALUE_FIXED) ?
BundlePrice::PRICE_TYPE_FIXED :
BundlePrice::PRICE_TYPE_DYNAMIC);
switch ($newKey) {
case $this->_customFieldsMapping['price_view']:
break;
case $this->_customFieldsMapping['shipment_type']:
$resultAttrs[$oldKey] = (($rowData[$oldKey] == 'separately') ?
AbstractType::SHIPMENT_SEPARATELY :
AbstractType::SHIPMENT_TOGETHER);
break;
default:
$resultAttrs[$oldKey] = (($rowData[$oldKey] == self::VALUE_FIXED) ?
BundlePrice::PRICE_TYPE_FIXED :
BundlePrice::PRICE_TYPE_DYNAMIC);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ protected function setUp()
[
'getEntityId',
'getPriceType',
'getShipmentType',
'getSkuType',
'getPriceView',
'getWeightType',
Expand All @@ -86,6 +87,7 @@ protected function setUp()
);
$this->product->expects($this->any())->method('getEntityId')->willReturn(1);
$this->product->expects($this->any())->method('getPriceType')->willReturn(1);
$this->product->expects($this->any())->method('getShipmentType')->willReturn(1);
$this->product->expects($this->any())->method('getSkuType')->willReturn(1);
$this->product->expects($this->any())->method('getPriceView')->willReturn(1);
$this->product->expects($this->any())->method('getWeightType')->willReturn(1);
Expand Down Expand Up @@ -159,12 +161,13 @@ public function testAddHeaderColumns()
{
$productData = [0 => 'sku'];
$expectedData = [
0 => 'sku',
1 => 'bundle_price_type',
2 => 'bundle_sku_type',
3 => 'bundle_price_view',
4 => 'bundle_weight_type',
5 => 'bundle_values'
'sku',
'bundle_price_type',
'bundle_sku_type',
'bundle_price_view',
'bundle_weight_type',
'bundle_values',
'bundle_shipment_type'
];
$this->assertEquals($expectedData, $this->rowCustomizerMock->addHeaderColumns($productData));
}
Expand All @@ -175,15 +178,17 @@ public function testAddHeaderColumns()
public function testAddData()
{
$preparedData = $this->rowCustomizerMock->prepareData($this->productResourceCollection, [1]);
$attributes = 'attribute=1,sku_type=1,price_type=1,price_view=1,weight_type=1,values=values,shipment_type=1';
$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',
'bundle_price_type' => 'fixed',
'bundle_shipment_type' => 'separately',
'bundle_sku_type' => 'fixed',
'bundle_price_view' => 'As low as',
'bundle_weight_type' => 'fixed',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ public function testSaveData($skus, $bunch, $allowImport)
'sku' => '1',
'price' => '10',
'price_type' => 'fixed',
'shipment_type' => '1',
'default_qty' => '1',
'is_defaul' => '1',
'position' => '1',
Expand All @@ -274,6 +275,7 @@ public function testSaveData($skus, $bunch, $allowImport)
'sku' => '222',
'price' => '10',
'price_type' => 'percent',
'shipment_type' => 0,
'default_qty' => '2',
'is_defaul' => '1',
'position' => '6',
Expand Down Expand Up @@ -323,6 +325,7 @@ public function testSaveDataProvider()
. 'sku=1,'
. 'price=10,'
. 'price_type=fixed,'
. 'shipment_type=separately,'
. 'default_qty=1,'
. 'is_defaul=1,'
. 'position=1,'
Expand Down Expand Up @@ -403,6 +406,7 @@ public function testIsRowValid()
$this->entityModel->expects($this->any())->method('getRowScope')->will($this->returnValue(-1));
$rowData = [
'bundle_price_type' => 'dynamic',
'bundle_shipment_type' => 'separately',
'bundle_price_view' => 'bundle_price_view'
];
$this->assertEquals($this->bundle->isRowValid($rowData, 0), true);
Expand Down
28 changes: 28 additions & 0 deletions app/code/Magento/Catalog/Helper/DefaultCategory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Catalog\Helper;

/**
* Default Category helper
*/
class DefaultCategory
{
/**
* Default Category ID
*
* @var int
*/
private $defaultCategoryId = 2;

/**
* @return int
*/
public function getId()
{
return $this->defaultCategoryId;
}
}
36 changes: 29 additions & 7 deletions app/code/Magento/Catalog/Setup/InstallData.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Catalog\Helper\DefaultCategory;

/**
* @codeCoverageIgnore
Expand All @@ -22,6 +23,24 @@ class InstallData implements InstallDataInterface
*/
private $categorySetupFactory;

/**
* @var DefaultCategory
*/
private $defaultCategory;

/**
* @deprecated
* @return DefaultCategory
*/
private function getDefaultCategory()
{
if ($this->defaultCategory === null) {
$this->defaultCategory = \Magento\Framework\App\ObjectManager::getInstance()
->get(DefaultCategory::class);
}
return $this->defaultCategory;
}

/**
* Init
*
Expand All @@ -42,32 +61,35 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface
{
/** @var \Magento\Catalog\Setup\CategorySetup $categorySetup */
$categorySetup = $this->categorySetupFactory->create(['setup' => $setup]);
$rootCategoryId = \Magento\Catalog\Model\Category::TREE_ROOT_ID;
$defaultCategoryId = $this->getDefaultCategory()->getId();

$categorySetup->installEntities();
// Create Root Catalog Node
$categorySetup->createCategory()
->load(1)
->setId(1)
->load($rootCategoryId)
->setId($rootCategoryId)
->setStoreId(0)
->setPath('1')
->setPath($rootCategoryId)
->setLevel(0)
->setPosition(0)
->setChildrenCount(0)
->setName('Root Catalog')
->setInitialSetupFlag(true)
->save();

// Create Default Catalog Node
$category = $categorySetup->createCategory();

$categorySetup->createCategory()
$category->load($defaultCategoryId)
->setId($defaultCategoryId)
->setStoreId(0)
->setPath('1')
->setPath($rootCategoryId . '/' . $defaultCategoryId)
->setName('Default Category')
->setDisplayMode('PRODUCTS')
->setAttributeSetId($category->getDefaultAttributeSetId())
->setIsActive(1)
->setLevel(1)
->setInitialSetupFlag(true)
->setAttributeSetId($category->getDefaultAttributeSetId())
->save();

$data = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ protected function customizeNameListeners(array $meta)
'imports' => [
'handleChanges' => '${$.provider}:data.product.name',
],
'autoImportIfEmpty' => true,
'allowImport' => $this->locator->getProduct()->getId() ? false : true,
],
],
],
Expand All @@ -358,22 +360,6 @@ protected function customizeNameListeners(array $meta)
$meta = $this->arrayManager->merge($listenerPath, $meta, $importsConfig);
}

$skuPath = $this->arrayManager->findPath(ProductAttributeInterface::CODE_SKU, $meta, null, 'children');
$meta = $this->arrayManager->merge(
$skuPath,
$meta,
[
'arguments' => [
'data' => [
'config' => [
'autoImportIfEmpty' => true,
'allowImport' => $this->locator->getProduct()->getId() ? false : true,
],
],
],
]
);

$namePath = $this->arrayManager->findPath(ProductAttributeInterface::CODE_NAME, $meta, null, 'children');

return $this->arrayManager->merge(
Expand Down
9 changes: 7 additions & 2 deletions app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -2365,8 +2365,13 @@ private function _setStockUseConfigFieldsValues($rowData)
{
$useConfigFields = array();
foreach ($rowData as $key => $value) {
if (isset($this->defaultStockData[$key]) && isset($this->defaultStockData[self::INVENTORY_USE_CONFIG_PREFIX . $key]) && !empty($value)) {
$useConfigFields[self::INVENTORY_USE_CONFIG_PREFIX . $key] = ($value == self::INVENTORY_USE_CONFIG) ? 1 : 0;
$useConfigName = self::INVENTORY_USE_CONFIG_PREFIX . $key;
if (isset($this->defaultStockData[$key])
&& isset($this->defaultStockData[$useConfigName])
&& !empty($value)
&& empty($rowData[$useConfigName])
) {
$useConfigFields[$useConfigName] = ($value == self::INVENTORY_USE_CONFIG) ? 1 : 0;
}
}
$rowData = array_merge($rowData, $useConfigFields);
Expand Down
Loading

0 comments on commit 03033d3

Please sign in to comment.