Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit ee33abb

Browse files
author
Oleksandr Gorkun
committed
MAGETWO-71549: Impossible to export Advanced Prices on a medium profile
- code style and code mess
1 parent 191fb72 commit ee33abb

File tree

1 file changed

+43
-30
lines changed

1 file changed

+43
-30
lines changed

app/code/Magento/AdvancedPricingImportExport/Model/Export/AdvancedPricing.php

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ function (array $productData) {
280280
ImportAdvancedPricing::TABLE_TIER_PRICE
281281
);
282282

283-
284283
$exportData = $this->correctExportData(
285284
$productsByStores,
286285
$tierPricesData
@@ -296,6 +295,44 @@ function (array $productData) {
296295
return $exportData;
297296
}
298297

298+
/**
299+
* @param array $tierPriceData Tier price information.
300+
*
301+
* @return array Formatted for export tier price information.
302+
*/
303+
private function createExportRow(array $tierPriceData): array
304+
{
305+
$exportRow = $this->templateExportData;
306+
foreach ($exportRow as $keyTemplate => $valueTemplate) {
307+
if (isset($row[$keyTemplate])) {
308+
if (in_array($keyTemplate, $this->_priceWebsite)) {
309+
$exportRow[$keyTemplate] = $this->_getWebsiteCode(
310+
$tierPriceData[$keyTemplate]
311+
);
312+
} elseif (in_array($keyTemplate, $this->_priceCustomerGroup)) {
313+
$exportRow[$keyTemplate] = $this->_getCustomerGroupById(
314+
$tierPriceData[$keyTemplate],
315+
$tierPriceData[ImportAdvancedPricing::VALUE_ALL_GROUPS]
316+
);
317+
unset($exportRow[ImportAdvancedPricing::VALUE_ALL_GROUPS]);
318+
} elseif ($keyTemplate
319+
=== ImportAdvancedPricing::COL_TIER_PRICE
320+
) {
321+
$exportRow[$keyTemplate]
322+
= $tierPriceData[ImportAdvancedPricing::COL_TIER_PRICE_PERCENTAGE_VALUE]
323+
? $tierPriceData[ImportAdvancedPricing::COL_TIER_PRICE_PERCENTAGE_VALUE]
324+
: $tierPriceData[ImportAdvancedPricing::COL_TIER_PRICE];
325+
$exportRow[ImportAdvancedPricing::COL_TIER_PRICE_TYPE]
326+
= $this->tierPriceTypeValue($tierPriceData);
327+
} else {
328+
$exportRow[$keyTemplate] = $tierPriceData[$keyTemplate];
329+
}
330+
}
331+
}
332+
333+
return $exportRow;
334+
}
335+
299336
/**
300337
* Correct export data.
301338
*
@@ -328,33 +365,7 @@ protected function correctExportData(
328365

329366
$customExportData = [];
330367
foreach ($linkedTierPricesData as $row) {
331-
$exportRow = $this->templateExportData;
332-
foreach ($exportRow as $keyTemplate => $valueTemplate) {
333-
if (isset($row[$keyTemplate])) {
334-
if (in_array($keyTemplate, $this->_priceWebsite)) {
335-
$exportRow[$keyTemplate] = $this->_getWebsiteCode(
336-
$row[$keyTemplate]
337-
);
338-
} elseif (in_array($keyTemplate, $this->_priceCustomerGroup)) {
339-
$exportRow[$keyTemplate] = $this->_getCustomerGroupById(
340-
$row[$keyTemplate],
341-
$row[ImportAdvancedPricing::VALUE_ALL_GROUPS]
342-
);
343-
unset($exportRow[ImportAdvancedPricing::VALUE_ALL_GROUPS]);
344-
} elseif ($keyTemplate === ImportAdvancedPricing::COL_TIER_PRICE) {
345-
$exportRow[$keyTemplate] = $row[ImportAdvancedPricing::COL_TIER_PRICE_PERCENTAGE_VALUE]
346-
? $row[ImportAdvancedPricing::COL_TIER_PRICE_PERCENTAGE_VALUE]
347-
: $row[ImportAdvancedPricing::COL_TIER_PRICE];
348-
$exportRow[ImportAdvancedPricing::COL_TIER_PRICE_TYPE]
349-
= $this->tierPriceTypeValue($row);
350-
} else {
351-
$exportRow[$keyTemplate] = $row[$keyTemplate];
352-
}
353-
}
354-
}
355-
356-
$customExportData[] = $exportRow;
357-
unset($exportRow);
368+
$customExportData[] = $this->createExportRow($row);
358369
}
359370

360371
return $customExportData;
@@ -416,8 +427,10 @@ protected function getTierPrices(array $productLinksIds, $table)
416427
['ap' => $this->_resource->getTableName($table)],
417428
$selectFields
418429
)
419-
->where('ap.'.$productEntityLinkField.' IN (?)',
420-
$productLinksIds);
430+
->where(
431+
'ap.'.$productEntityLinkField.' IN (?)',
432+
$productLinksIds
433+
);
421434

422435
if (isset($price[0]) && !empty($price[0])) {
423436
$select->where('ap.value >= ?', $price[0]);

0 commit comments

Comments
 (0)