Skip to content

Commit

Permalink
Merge pull request #673 from magento-nord/merchant_beta
Browse files Browse the repository at this point in the history
[Merchant beta][Nord]Bug fixes
  • Loading branch information
Onischenko, Yaroslav(yonischenko) committed Oct 5, 2015
2 parents 1351333 + 693c5d0 commit b990179
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public function prepareAttributesWithDefaultValueForSave(array $rowData, $withDe
foreach ($this->_getProductAttributes($rowData) as $attrCode => $attrParams) {
if (!$attrParams['is_static']) {
if (isset($rowData[$attrCode]) && strlen($rowData[$attrCode])) {
$resultAttrs[$attrCode] = 'select' == $attrParams['type']
$resultAttrs[$attrCode] = in_array($attrParams['type'], ['select', 'boolean'])
? $attrParams['options'][strtolower($rowData[$attrCode])]
: $rowData[$attrCode];
if ('multiselect' == $attrParams['type']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public function isAttributeValid($attrCode, array $attrParams, array $rowData)
$valid = $this->numericValidation($attrCode, $attrParams['type']);
break;
case 'select':
case 'boolean':
case 'multiselect':
$values = explode(Product::PSEUDO_MULTI_LINE_SEPARATOR, $rowData[$attrCode]);
$valid = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,40 +117,59 @@ protected function setUp()
'',
false
);

$entityAttributes = [[
'attribute_id' => 'attribute_id',
'attribute_set_name' => 'attributeSetName',
]];

$this->entityModel->expects($this->any())->method('getEntityTypeId')->willReturn(3);
$this->entityModel->expects($this->any())->method('getAttributeOptions')->willReturn(['option1', 'option2']);
$attrSetColFactory->expects($this->any())->method('create')->willReturn($attrSetCollection);
$attrSetCollection->expects($this->any())->method('setEntityTypeFilter')->willReturn([$attributeSet]);
$attrColFactory->expects($this->any())->method('create')->willReturn($attrCollection);
$attrCollection->expects($this->any())->method('setAttributeSetFilter')->willReturn([$attribute]);
$attributeSet->expects($this->any())->method('getId')->willReturn(1);
$attributeSet->expects($this->any())->method('getAttributeSetName')->willReturn('attribute_set_name');
$attribute->expects($this->any())->method('getAttributeCode')->willReturn('attr_code');
$attribute->expects($this->any())->method('getId')->willReturn('1');
$attribute->expects($this->any())->method('getIsVisible')->willReturn(true);
$attribute->expects($this->any())->method('getIsGlobal')->willReturn(true);
$attribute->expects($this->any())->method('getIsRequired')->willReturn(true);
$attribute->expects($this->any())->method('getIsUnique')->willReturn(true);
$attribute->expects($this->any())->method('getFrontendLabel')->willReturn('frontend_label');
$attribute->expects($this->any())->method('isStatic')->willReturn(true);
$attribute->expects($this->any())->method('getApplyTo')->willReturn(['simple']);
$attribute->expects($this->any())->method('getDefaultValue')->willReturn('default_value');
$attribute->expects($this->any())->method('usesSource')->willReturn(true);
$attribute->expects($this->any())->method('getFrontendInput')->willReturn('multiselect');


$entityAttributes = [
[
'attribute_id' => 'attribute_id',
'attribute_set_name' => 'attributeSetName',
],
[
'attribute_id' => 'boolean_attribute',
'attribute_set_name' => 'attributeSetName'
]
];
$attribute1 = clone $attribute;
$attribute2 = clone $attribute;

$attribute1->expects($this->any())->method('getId')->willReturn('1');
$attribute1->expects($this->any())->method('getAttributeCode')->willReturn('attr_code');
$attribute1->expects($this->any())->method('getFrontendInput')->willReturn('multiselect');
$attribute1->expects($this->any())->method('isStatic')->willReturn(true);

$attribute2->expects($this->any())->method('getId')->willReturn('2');
$attribute2->expects($this->any())->method('getAttributeCode')->willReturn('boolean_attribute');
$attribute2->expects($this->any())->method('getFrontendInput')->willReturn('boolean');
$attribute2->expects($this->any())->method('isStatic')->willReturn(false);

$this->entityModel->expects($this->any())->method('getEntityTypeId')->willReturn(3);
$this->entityModel->expects($this->any())->method('getAttributeOptions')->willReturnOnConsecutiveCalls(
['option1', 'option2'],
['yes' => 1, 'no' => 0]
);
$attrSetColFactory->expects($this->any())->method('create')->willReturn($attrSetCollection);
$attrSetCollection->expects($this->any())->method('setEntityTypeFilter')->willReturn([$attributeSet]);
$attrColFactory->expects($this->any())->method('create')->willReturn($attrCollection);
$attrCollection->expects($this->any())->method('setAttributeSetFilter')->willReturn([$attribute1, $attribute2]);
$attributeSet->expects($this->any())->method('getId')->willReturn(1);
$attributeSet->expects($this->any())->method('getAttributeSetName')->willReturn('attribute_set_name');

$attrCollection
->expects($this->any())
->method('addFieldToFilter')
->with(
'main_table.attribute_id',
['in' => ['attribute_id']]
['in' => ['attribute_id', 'boolean_attribute']]
)
->willReturn([$attribute]);
->willReturn([$attribute1, $attribute2]);

$this->connection = $this->getMock(
'Magento\Framework\DB\Adapter\Pdo\Mysql',
Expand Down Expand Up @@ -343,6 +362,7 @@ public function addAttributeOptionDataProvider()
/**
* @param $object
* @param $property
* @return mixed
*/
protected function getPropertyValue(&$object, $property)
{
Expand All @@ -366,4 +386,14 @@ protected function setPropertyValue(&$object, $property, $value)
$reflectionProperty->setValue($object, $value);
return $object;
}

public function testPrepareAttributesWithDefaultValueForSave()
{
$rowData = [
'_attribute_set' => 'attributeSetName',
'boolean_attribute' => 'Yes'
];
$result = $this->simpleType->prepareAttributesWithDefaultValueForSave($rowData);
$this->assertEquals(['boolean_attribute' => 1], $result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,25 @@ protected function setUp()
$this->validator->setContext($this->context)->init();
}

public function testIsBooleanAttributeValid()
{
$this->context->expects($this->any())->method('getBehavior')
->willReturn(\Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE);
$result = $this->validator->isAttributeValid(
'boolean_attribute',
[
'type' => 'boolean',
'apply_to' => ['simple'],
'is_required' => false
],
[
'product_type' => 'simple',
'boolean_attribute' => 'Yes'
]
);
$this->assertTrue($result);
}

public function testIsValidCorrect()
{
$value = ['product_type' => 'simple'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public function getAttributeOptions(\Magento\Eav\Model\Entity\Attribute\Abstract
foreach (is_array($option['value']) ? $option['value'] : [$option] as $innerOption) {
if (strlen($innerOption['value'])) {
// skip ' -- Please Select -- ' option
$options[$innerOption['value']] = $innerOption[$index];
$options[$innerOption['value']] = (string)$innerOption[$index];
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions app/code/Magento/ImportExport/Model/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,11 @@ public function getOperationResultMessages($validationResult)
*/
public static function getAttributeType(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute)
{
if ($attribute->usesSource() && in_array($attribute->getFrontendInput(), ['select', 'multiselect'])) {
return $attribute->getFrontendInput() == 'multiselect' ? 'multiselect' : 'select';
$frontendInput = $attribute->getFrontendInput();
if ($attribute->usesSource() && in_array($frontendInput, ['select', 'multiselect', 'boolean'])) {
return $frontendInput;
} elseif ($attribute->isStatic()) {
return $attribute->getFrontendInput() == 'date' ? 'datetime' : 'varchar';
return $frontendInput == 'date' ? 'datetime' : 'varchar';
} else {
return $attribute->getBackendType();
}
Expand Down
8 changes: 7 additions & 1 deletion app/code/Magento/ImportExport/Test/Unit/Model/ImportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,13 @@ public function testGetOperationResultMessages()
*/
public function testGetAttributeType()
{
$this->markTestIncomplete('This test has not been implemented yet.');
/** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute */
$attribute = $this->getMockBuilder('\Magento\Eav\Model\Entity\Attribute\AbstractAttribute')
->setMethods(['getFrontendInput', 'usesSource'])
->disableOriginalConstructor()->getMock();
$attribute->expects($this->any())->method('getFrontendInput')->willReturn('boolean');
$attribute->expects($this->any())->method('usesSource')->willReturn(true);
$this->assertEquals('boolean', $this->import->getAttributeType($attribute));
}

/**
Expand Down

0 comments on commit b990179

Please sign in to comment.