Skip to content

Commit 495d0c4

Browse files
authored
Merge pull request #1334 from magento-okapis/Okapis-PR
[Okapis] PR
2 parents 70c8334 + 6af00d1 commit 495d0c4

File tree

15 files changed

+644
-33
lines changed

15 files changed

+644
-33
lines changed

app/code/Magento/CustomerImportExport/Model/Import/Address.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\CustomerImportExport\Model\Import;
77

8+
use Magento\ImportExport\Model\Import;
89
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
910

1011
/**
@@ -491,15 +492,13 @@ protected function _prepareDataForUpdate(array $rowData)
491492
{
492493
$email = strtolower($rowData[self::COLUMN_EMAIL]);
493494
$customerId = $this->_getCustomerId($email, $rowData[self::COLUMN_WEBSITE]);
494-
495495
// entity table data
496496
$entityRowNew = [];
497497
$entityRowUpdate = [];
498498
// attribute values
499499
$attributes = [];
500500
// customer default addresses
501501
$defaults = [];
502-
503502
$newAddress = true;
504503
// get address id
505504
if (isset(
@@ -519,7 +518,6 @@ protected function _prepareDataForUpdate(array $rowData)
519518
'parent_id' => $customerId,
520519
'updated_at' => (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT),
521520
];
522-
523521
foreach ($this->_attributes as $attributeAlias => $attributeParams) {
524522
if (array_key_exists($attributeAlias, $rowData)) {
525523
if (!strlen($rowData[$attributeAlias])) {
@@ -534,6 +532,15 @@ protected function _prepareDataForUpdate(array $rowData)
534532
} elseif ('datetime' == $attributeParams['type']) {
535533
$value = (new \DateTime())->setTimestamp(strtotime($rowData[$attributeAlias]));
536534
$value = $value->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
535+
} elseif ('multiselect' == $attributeParams['type']) {
536+
$separator = isset($this->_parameters[Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR]) ?
537+
$this->_parameters[Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR] :
538+
Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR;
539+
$value = str_replace(
540+
$separator,
541+
Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR,
542+
$rowData[$attributeAlias]
543+
);
537544
} else {
538545
$value = $rowData[$attributeAlias];
539546
}
@@ -544,15 +551,13 @@ protected function _prepareDataForUpdate(array $rowData)
544551
}
545552
}
546553
}
547-
548554
foreach (self::getDefaultAddressAttributeMapping() as $columnName => $attributeCode) {
549555
if (!empty($rowData[$columnName])) {
550556
/** @var $attribute \Magento\Eav\Model\Entity\Attribute\AbstractAttribute */
551557
$table = $this->_getCustomerEntity()->getResource()->getTable('customer_entity');
552558
$defaults[$table][$customerId][$attributeCode] = $addressId;
553559
}
554560
}
555-
556561
// let's try to find region ID
557562
$entityRow['region_id'] = null;
558563
if (!empty($rowData[self::COLUMN_REGION])) {
@@ -565,7 +570,6 @@ protected function _prepareDataForUpdate(array $rowData)
565570
$entityRow['region_id'] = $regionId;
566571
}
567572
}
568-
569573
if ($newAddress) {
570574
$entityRowNew = $entityRow;
571575
$entityRowNew['created_at'] =
@@ -740,7 +744,16 @@ protected function _validateRowForUpdate(array $rowData, $rowNumber)
740744
continue;
741745
}
742746
if (isset($rowData[$attributeCode]) && strlen($rowData[$attributeCode])) {
743-
$this->isAttributeValid($attributeCode, $attributeParams, $rowData, $rowNumber);
747+
$multiSeparator = isset($this->_parameters[Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR]) ?
748+
$this->_parameters[Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR] :
749+
Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR;
750+
$this->isAttributeValid(
751+
$attributeCode,
752+
$attributeParams,
753+
$rowData,
754+
$rowNumber,
755+
$multiSeparator
756+
);
744757
} elseif ($attributeParams['is_required'] && (!isset(
745758
$this->_addresses[$customerId]
746759
) || !in_array(

app/code/Magento/ImportExport/Model/Import/AbstractEntity.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Framework\App\ObjectManager;
99
use Magento\Framework\App\ResourceConnection;
1010
use Magento\Framework\Serialize\Serializer\Json;
11+
use Magento\ImportExport\Model\Import;
1112
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingError;
1213
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
1314

@@ -74,8 +75,8 @@ abstract class AbstractEntity
7475
self::ERROR_CODE_COLUMNS_NUMBER => "Number of columns does not correspond to the number of rows in the header",
7576
self::ERROR_EXCEEDED_MAX_LENGTH => 'Attribute %s exceeded max length',
7677
self::ERROR_INVALID_ATTRIBUTE_TYPE => 'Value for \'%s\' attribute contains incorrect value',
77-
self::ERROR_INVALID_ATTRIBUTE_OPTION =>
78-
"Value for %s attribute contains incorrect value, see acceptable values on settings specified for Admin",
78+
self::ERROR_INVALID_ATTRIBUTE_OPTION => "Value for %s attribute contains incorrect value"
79+
. ", see acceptable values on settings specified for Admin",
7980
];
8081

8182
/**#@-*/
@@ -665,11 +666,17 @@ public function getMasterAttributeCode()
665666
* @param array $attributeParams Attribute params
666667
* @param array $rowData Row data
667668
* @param int $rowNumber
669+
* @param string $multiSeparator
668670
* @return bool
669671
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
670672
*/
671-
public function isAttributeValid($attributeCode, array $attributeParams, array $rowData, $rowNumber)
672-
{
673+
public function isAttributeValid(
674+
$attributeCode,
675+
array $attributeParams,
676+
array $rowData,
677+
$rowNumber,
678+
$multiSeparator = Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR
679+
) {
673680
$message = '';
674681
switch ($attributeParams['type']) {
675682
case 'varchar':
@@ -684,7 +691,13 @@ public function isAttributeValid($attributeCode, array $attributeParams, array $
684691
break;
685692
case 'select':
686693
case 'multiselect':
687-
$valid = isset($attributeParams['options'][strtolower($rowData[$attributeCode])]);
694+
$valid = true;
695+
foreach (explode($multiSeparator, strtolower($rowData[$attributeCode])) as $value) {
696+
$valid = isset($attributeParams['options'][$value]);
697+
if (!$valid) {
698+
break;
699+
}
700+
}
688701
$message = self::ERROR_INVALID_ATTRIBUTE_OPTION;
689702
break;
690703
case 'int':

app/code/Magento/ImportExport/Model/Import/Entity/AbstractEav.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,14 @@ public function getAttributeOptions(
225225
foreach ($attribute->getSource()->getAllOptions(false) as $option) {
226226
$value = is_array($option['value']) ? $option['value'] : [$option];
227227
foreach ($value as $innerOption) {
228+
// skip ' -- Please Select -- ' option
228229
if (strlen($innerOption['value'])) {
229-
// skip ' -- Please Select -- ' option
230-
$options[strtolower($innerOption[$index])] = $innerOption['value'];
230+
if ($attribute->isStatic()) {
231+
$options[strtolower($innerOption[$index])] = $innerOption['value'];
232+
} else {
233+
// Non-static attributes flip keys an values
234+
$options[$innerOption['value']] = $innerOption[$index];
235+
}
231236
}
232237
}
233238
}

app/code/Magento/Sales/Test/Unit/Model/Order/Email/Stub/TransportInterfaceMock.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,14 @@ public function sendMessage()
1818
{
1919
return;
2020
}
21+
22+
/**
23+
* Get message
24+
*
25+
* @return string
26+
*/
27+
public function getMessage()
28+
{
29+
return '';
30+
}
2131
}

dev/tests/integration/framework/Magento/TestFramework/Mail/TransportInterfaceMock.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,14 @@ public function sendMessage()
1717
{
1818
return;
1919
}
20+
21+
/**
22+
* Get message
23+
*
24+
* @return string
25+
*/
26+
public function getMessage()
27+
{
28+
return '';
29+
}
2030
}

dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/IndexTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,8 +762,7 @@ protected function prepareEmailMock($occurrenceNumber, $templateId, $sender, $cu
762762
$storeId = $customer->getStoreId();
763763
$name = $this->customerViewHelper->getCustomerName($customer);
764764
$transportMock = $this->getMock(
765-
\Magento\Framework\Mail\TransportInterface::class,
766-
['sendMessage']
765+
\Magento\Framework\Mail\TransportInterface::class
767766
);
768767
$transportMock->expects($this->exactly($occurrenceNumber))
769768
->method('sendMessage');

dev/tests/integration/testsuite/Magento/Framework/Search/Adapter/Mysql/AdapterTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,20 @@ private function assertProductIds($queryResponse, $expectedIds)
123123
$this->assertEquals($expectedIds, $actualIds);
124124
}
125125

126+
/**
127+
* @param \Magento\Framework\Search\Response\QueryResponse $queryResponse
128+
* @param array $expectedIds
129+
*/
130+
private function assertOrderedProductIds($queryResponse, $expectedIds)
131+
{
132+
$actualIds = [];
133+
foreach ($queryResponse as $document) {
134+
/** @var \Magento\Framework\Api\Search\Document $document */
135+
$actualIds[] = $document->getId();
136+
}
137+
$this->assertEquals($expectedIds, $actualIds);
138+
}
139+
126140
/**
127141
* @magentoConfigFixture current_store catalog/search/engine mysql
128142
*/
@@ -136,6 +150,24 @@ public function testMatchQuery()
136150
$this->assertEquals(1, $queryResponse->count());
137151
}
138152

153+
/**
154+
* @magentoDataFixture Magento/Framework/Search/_files/products_multi_option.php
155+
* @magentoConfigFixture current_store catalog/search/engine mysql
156+
*/
157+
public function testMatchOrderedQuery()
158+
{
159+
$expectedIds = [8, 7, 6, 5, 2];
160+
161+
//Verify that MySql randomized result of equal-weighted results
162+
//consistently ordered by entity_id after multiple calls
163+
$this->requestBuilder->bind('fulltext_search_query', 'shorts');
164+
$this->requestBuilder->setRequestName('one_match');
165+
$queryResponse = $this->executeQuery();
166+
167+
$this->assertEquals(5, $queryResponse->count());
168+
$this->assertOrderedProductIds($queryResponse, $expectedIds);
169+
}
170+
139171
/**
140172
* @magentoConfigFixture current_store catalog/search/engine mysql
141173
*/

0 commit comments

Comments
 (0)