Skip to content

Commit 9c2f3f9

Browse files
committed
Merge branch 'MAGETWO-60246' into 2.1.13-PR-0.5
2 parents accb999 + 37a364c commit 9c2f3f9

File tree

15 files changed

+606
-324
lines changed

15 files changed

+606
-324
lines changed

app/code/Magento/CatalogRule/Block/Adminhtml/Promo/Catalog/Edit/Tab/Conditions.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Magento\Backend\Block\Widget\Form;
99
use Magento\Backend\Block\Widget\Form\Generic;
1010
use Magento\Ui\Component\Layout\Tabs\TabInterface;
11+
use Magento\CatalogRule\Api\Data\RuleInterface;
12+
use Magento\Rule\Model\Condition\AbstractCondition;
1113

1214
class Conditions extends Generic implements TabInterface
1315
{
@@ -134,7 +136,7 @@ protected function _prepareForm()
134136
}
135137

136138
/**
137-
* @param \Magento\CatalogRule\Api\Data\RuleInterface $model
139+
* @param RuleInterface $model
138140
* @param string $fieldsetId
139141
* @param string $formName
140142
* @return \Magento\Framework\Data\Form
@@ -175,22 +177,30 @@ protected function addTabToForm($model, $fieldsetId = 'conditions_fieldset', $fo
175177
->setRenderer($this->_conditions);
176178

177179
$form->setValues($model->getData());
178-
$this->setConditionFormName($model->getConditions(), $formName);
180+
$this->setConditionFormName($model, $model->getConditions(), $formName);
179181
return $form;
180182
}
181183

182184
/**
183-
* @param \Magento\Rule\Model\Condition\AbstractCondition $conditions
185+
* @param RuleInterface $rule
186+
* @param AbstractCondition $conditions
184187
* @param string $formName
185188
* @return void
186189
*/
187-
private function setConditionFormName(\Magento\Rule\Model\Condition\AbstractCondition $conditions, $formName)
188-
{
190+
private function setConditionFormName(
191+
RuleInterface $rule,
192+
AbstractCondition $conditions,
193+
$formName
194+
) {
189195
$conditions->setFormName($formName);
190-
$conditions->setJsFormObject($formName);
191-
if ($conditions->getConditions() && is_array($conditions->getConditions())) {
196+
//For every fieldset there's a different form object.
197+
$conditions->setJsFormObject(
198+
$rule->getConditionsFieldSetId($formName)
199+
);
200+
$childConditions = $conditions->getCondition();
201+
if ($childConditions && is_array($childConditions)) {
192202
foreach ($conditions->getConditions() as $condition) {
193-
$this->setConditionFormName($condition, $formName);
203+
$this->setConditionFormName($rule, $condition, $formName);
194204
}
195205
}
196206
}

app/code/Magento/CatalogSearch/Model/Layer/Filter/Price.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public function getCurrencyRate()
174174
*/
175175
protected function _renderRangeLabel($fromPrice, $toPrice)
176176
{
177-
$fromPrice *= $this->getCurrencyRate();
177+
$fromPrice *= $this->getCurrencyRate();
178178
if ($toPrice) {
179179
$toPrice *= $this->getCurrencyRate();
180180
}
@@ -216,7 +216,7 @@ protected function _getItemsData()
216216
if (strpos($key, '_') === false) {
217217
continue;
218218
}
219-
$data[] = $this->prepareData($key, $count, $data);
219+
$data[] = $this->prepareData($key, $count);
220220
}
221221
}
222222

@@ -267,7 +267,7 @@ private function prepareData($key, $count)
267267
}
268268
$label = $this->_renderRangeLabel(
269269
empty($from) ? 0 : $from,
270-
empty($to) ? $to : $to
270+
$to
271271
);
272272
$value = $from . '-' . $to . $this->dataProvider->getAdditionalRequestData();
273273

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ abstract class AbstractCustomer extends \Magento\ImportExport\Model\Import\Entit
2828

2929
const COLUMN_DEFAULT_SHIPPING = 'default_shipping';
3030

31-
3231
/**#@-*/
3332

3433
/**#@+

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

Lines changed: 91 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
1313
use Magento\Store\Model\Store;
1414
use Magento\ImportExport\Model\Import;
15+
use Magento\CustomerImportExport\Model\ResourceModel\Import\Address\Storage as AddressStorage;
1516

1617
/**
1718
* @SuppressWarnings(PHPMD.TooManyFields)
@@ -100,6 +101,8 @@ class Address extends AbstractCustomer
100101
* )
101102
*
102103
* @var array
104+
* @deprected
105+
* @see $addressStorage
103106
*/
104107
protected $_addresses = [];
105108

@@ -256,6 +259,11 @@ class Address extends AbstractCustomer
256259
*/
257260
private $optionsByWebsite = [];
258261

262+
/**
263+
* @var AddressStorage
264+
*/
265+
private $addressStorage;
266+
259267
/**
260268
* @param \Magento\Framework\Stdlib\StringUtils $string
261269
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
@@ -276,6 +284,7 @@ class Address extends AbstractCustomer
276284
* @param \Magento\Customer\Model\Address\Validator\Postcode $postcodeValidator
277285
* @param array $data
278286
* @param Sources\CountryWithWebsites|null $countryWithWebsites
287+
* @param AddressStorage|null $addressStorage
279288
*
280289
* @SuppressWarnings(PHPMD.NPathComplexity)
281290
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -299,7 +308,8 @@ public function __construct(
299308
DateTime $dateTime,
300309
\Magento\Customer\Model\Address\Validator\Postcode $postcodeValidator,
301310
array $data = [],
302-
Sources\CountryWithWebsites $countryWithWebsites = null
311+
Sources\CountryWithWebsites $countryWithWebsites = null,
312+
AddressStorage $addressStorage = null
303313
) {
304314
$this->_customerFactory = $customerFactory;
305315
$this->_addressFactory = $addressFactory;
@@ -352,9 +362,11 @@ public function __construct(
352362
self::ERROR_DUPLICATE_PK,
353363
__('We found another row with this email, website and address ID combination.')
354364
);
365+
$this->addressStorage = $addressStorage
366+
?: ObjectManager::getInstance()->get(AddressStorage::class);
355367

356368
$this->_initAttributes();
357-
$this->_initAddresses()->_initCountryRegions();
369+
$this->_initCountryRegions();
358370
}
359371

360372
/**
@@ -455,6 +467,8 @@ protected function _getNextEntityId()
455467
* Initialize existent addresses data
456468
*
457469
* @return $this
470+
* @deprecated
471+
* @see prepareCustomerData
458472
*/
459473
protected function _initAddresses()
460474
{
@@ -472,6 +486,57 @@ protected function _initAddresses()
472486
return $this;
473487
}
474488

489+
/**
490+
* Pre-loading customers for existing customers checks in order
491+
* to perform mass validation/import efficiently.
492+
* Also loading existing addresses for requested customers.
493+
*
494+
* @param \Traversable $rows Each row must contain data from columns email
495+
* and website code.
496+
*
497+
* @return void
498+
*/
499+
public function prepareCustomerData(\Traversable $rows)
500+
{
501+
$customersPresent = [];
502+
foreach ($rows as $rowData) {
503+
$email = isset($rowData[static::COLUMN_EMAIL])
504+
? $rowData[static::COLUMN_EMAIL] : null;
505+
$websiteId = isset($rowData[static::COLUMN_WEBSITE])
506+
? $this->getWebsiteId($rowData[static::COLUMN_WEBSITE]) : false;
507+
if ($email && $websiteId !== false) {
508+
$customersPresent[] = [
509+
'email' => $email,
510+
'website_id' => $websiteId
511+
];
512+
}
513+
}
514+
$this->getCustomerStorage()->prepareCustomers($customersPresent);
515+
516+
$ids = [];
517+
foreach ($customersPresent as $customerData) {
518+
$id = $this->getCustomerStorage()->getCustomerId(
519+
$customerData['email'],
520+
$customerData['website_id']
521+
);
522+
if ($id) {
523+
$ids[] = $id;
524+
}
525+
}
526+
527+
$this->addressStorage->prepareAddresses($ids);
528+
}
529+
530+
/**
531+
* @inheritDoc
532+
*/
533+
public function validateData()
534+
{
535+
$this->prepareCustomerData($this->getSource());
536+
537+
return parent::validateData();
538+
}
539+
475540
/**
476541
* Initialize country regions hash for clever recognition
477542
*
@@ -500,6 +565,16 @@ protected function _initCountryRegions()
500565
*/
501566
protected function _importData()
502567
{
568+
//Preparing data for mass validation/import.
569+
$rows = [];
570+
while ($bunch = $this->_dataSourceModel->getNextBunch()) {
571+
$rows = array_merge($rows, $bunch);
572+
}
573+
$this->prepareCustomerData(new \ArrayObject($rows));
574+
unset($bunch, $rows);
575+
$this->_dataSourceModel->getIterator()->rewind();
576+
577+
//Importing
503578
while ($bunch = $this->_dataSourceModel->getNextBunch()) {
504579
$newRows = [];
505580
$updateRows = [];
@@ -588,9 +663,10 @@ protected function _prepareDataForUpdate(array $rowData)
588663
$defaults = [];
589664
$newAddress = true;
590665
// get address id
591-
if (isset($this->_addresses[$customerId])
592-
&& in_array($rowData[self::COLUMN_ADDRESS_ID], $this->_addresses[$customerId])
593-
) {
666+
if ($this->addressStorage->doesExist(
667+
$rowData[self::COLUMN_ADDRESS_ID],
668+
$customerId
669+
)) {
594670
$newAddress = false;
595671
$addressId = $rowData[self::COLUMN_ADDRESS_ID];
596672
} else {
@@ -845,12 +921,11 @@ protected function _validateRowForUpdate(array $rowData, $rowNumber)
845921
$rowNumber,
846922
$multiSeparator
847923
);
848-
} elseif ($attributeParams['is_required'] && (!isset(
849-
$this->_addresses[$customerId]
850-
) || !in_array(
851-
$addressId,
852-
$this->_addresses[$customerId]
853-
))
924+
} elseif ($attributeParams['is_required']
925+
&& !$this->addressStorage->doesExist(
926+
$addressId,
927+
$customerId
928+
)
854929
) {
855930
$this->addRowError(self::ERROR_VALUE_IS_REQUIRED, $rowNumber, $attributeCode);
856931
}
@@ -906,7 +981,10 @@ protected function _validateRowForDelete(array $rowData, $rowNumber)
906981
} else {
907982
if (!strlen($addressId)) {
908983
$this->addRowError(self::ERROR_ADDRESS_ID_IS_EMPTY, $rowNumber);
909-
} elseif (!in_array($addressId, $this->_addresses[$customerId])) {
984+
} elseif (!$this->addressStorage->doesExist(
985+
$addressId,
986+
$customerId
987+
)) {
910988
$this->addRowError(self::ERROR_ADDRESS_NOT_FOUND, $rowNumber);
911989
}
912990
}
@@ -922,7 +1000,7 @@ protected function _validateRowForDelete(array $rowData, $rowNumber)
9221000
*/
9231001
protected function _checkRowDuplicate($customerId, $addressId)
9241002
{
925-
if (isset($this->_addresses[$customerId]) && in_array($addressId, $this->_addresses[$customerId])) {
1003+
if ($this->addressStorage->doesExist($addressId, $customerId)) {
9261004
if (!isset($this->_importedRowPks[$customerId][$addressId])) {
9271005
$this->_importedRowPks[$customerId][$addressId] = true;
9281006
return false;

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,43 @@ protected function _getNextEntityId()
323323
return $this->_nextEntityId++;
324324
}
325325

326+
/**
327+
* Pre-loading customers for existing customers checks in order
328+
* to perform mass validation/import efficiently.
329+
*
330+
* @param \Traversable $rows Each row must contain data from columns email
331+
* and website code.
332+
*
333+
* @return void
334+
*/
335+
public function prepareCustomerData(\Traversable $rows)
336+
{
337+
$customersPresent = [];
338+
foreach ($rows as $rowData) {
339+
$email = isset($rowData[static::COLUMN_EMAIL])
340+
? $rowData[static::COLUMN_EMAIL] : null;
341+
$websiteId = isset($rowData[static::COLUMN_WEBSITE])
342+
? $this->getWebsiteId($rowData[static::COLUMN_WEBSITE]) : false;
343+
if ($email && $websiteId !== false) {
344+
$customersPresent[] = [
345+
'email' => $email,
346+
'website_id' => $websiteId
347+
];
348+
}
349+
}
350+
$this->getCustomerStorage()->prepareCustomers($customersPresent);
351+
}
352+
353+
/**
354+
* @inheritDoc
355+
*/
356+
public function validateData()
357+
{
358+
$this->prepareCustomerData($this->getSource());
359+
360+
return parent::validateData();
361+
}
362+
326363
/**
327364
* Prepare customer data for update
328365
*
@@ -428,6 +465,7 @@ protected function _prepareDataForUpdate(array $rowData)
428465
protected function _importData()
429466
{
430467
while ($bunch = $this->_dataSourceModel->getNextBunch()) {
468+
$this->prepareCustomerData(new \ArrayObject($bunch));
431469
$entitiesToCreate = [];
432470
$entitiesToUpdate = [];
433471
$entitiesToDelete = [];

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,28 @@ public function getEntityTypeCode()
287287
return 'customer_composite';
288288
}
289289

290+
/**
291+
* @inheritDoc
292+
*/
293+
public function validateData()
294+
{
295+
//Preparing both customer and address imports for mass validation.
296+
$source = $this->getSource();
297+
$this->_customerEntity->prepareCustomerData($source);
298+
$source->rewind();
299+
$rows = [];
300+
foreach ($source as $row) {
301+
$rows[] = [
302+
Address::COLUMN_EMAIL => $row[Customer::COLUMN_EMAIL],
303+
Address::COLUMN_WEBSITE => $row[Customer::COLUMN_WEBSITE]
304+
];
305+
}
306+
$source->rewind();
307+
$this->_addressEntity->prepareCustomerData(new \ArrayObject($rows));
308+
309+
return parent::validateData();
310+
}
311+
290312
/**
291313
* Validate data row
292314
*

0 commit comments

Comments
 (0)