Skip to content

Commit 67caf84

Browse files
author
Melnikov, Igor(imelnikov)
committed
Merge pull request #412 from magento-extensibility/MAGETWO-47449-product-import-export
[Extensibility] Magetwo 47449 product import export
2 parents 9e78b20 + ff553b8 commit 67caf84

File tree

50 files changed

+3346
-615
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3346
-615
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ public function __construct(
142142
$attributeColFactory,
143143
$_typeFactory,
144144
$linkTypeProvider,
145-
$rowCustomizer,
146-
$metadataPool
145+
$rowCustomizer
147146
);
148147
}
149148

@@ -356,14 +355,15 @@ protected function getTierPrices(array $listSku, $table)
356355
}
357356
}
358357
try {
358+
$productEntityLinkField = $this->getProductEntityLinkField();
359359
$select = $this->_connection->select()
360360
->from(
361361
['cpe' => $this->_resource->getTableName('catalog_product_entity')],
362362
$selectFields
363363
)
364364
->joinInner(
365365
['ap' => $this->_resource->getTableName($table)],
366-
'ap.entity_id = cpe.entity_id',
366+
'ap.' . $productEntityLinkField . ' = cpe.' . $productEntityLinkField,
367367
[]
368368
)
369369
->where('cpe.entity_id IN (?)', $listSku);

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

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*
1616
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
1717
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
18+
* @SuppressWarnings(PHPMD.TooManyFields)
1819
*/
1920
class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
2021
{
@@ -126,7 +127,7 @@ class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\Abstract
126127
/**
127128
* @var array
128129
*/
129-
protected $_oldSkus;
130+
protected $_oldSkus = null;
130131

131132
/**
132133
* Permanent entity columns.
@@ -147,6 +148,13 @@ class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\Abstract
147148
*/
148149
protected $dateTime;
149150

151+
/**
152+
* Product entity link field
153+
*
154+
* @var string
155+
*/
156+
private $productEntityLinkField;
157+
150158
/**
151159
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
152160
* @param \Magento\Framework\Json\Helper\Data $jsonHelper
@@ -199,11 +207,11 @@ public function __construct(
199207
$this->_storeResolver = $storeResolver;
200208
$this->_importProduct = $importProduct;
201209
$this->_validators[self::VALIDATOR_MAIN] = $validator->init($this);
210+
$this->_catalogProductEntity = $this->_resourceFactory->create()->getTable('catalog_product_entity');
202211
$this->_oldSkus = $this->retrieveOldSkus();
203212
$this->_validators[self::VALIDATOR_WEBSITE] = $websiteValidator;
204213
$this->_validators[self::VALIDATOR_TEAR_PRICE] = $tierPriceValidator;
205214
$this->errorAggregator = $errorAggregator;
206-
$this->_catalogProductEntity = $this->_resourceFactory->create()->getTable('catalog_product_entity');
207215

208216
foreach (array_merge($this->errorMessageTemplates, $this->_messageTemplates) as $errorCode => $message) {
209217
$this->getErrorAggregator()->addErrorMessageTemplate($errorCode, $message);
@@ -409,11 +417,12 @@ protected function saveProductPrices(array $priceData, $table)
409417
$tableName = $this->_resourceFactory->create()->getTable($table);
410418
$priceIn = [];
411419
$entityIds = [];
420+
$oldSkus = $this->retrieveOldSkus();
412421
foreach ($priceData as $sku => $priceRows) {
413-
if (isset($this->_oldSkus[$sku])) {
414-
$productId = $this->_oldSkus[$sku];
422+
if (isset($oldSkus[$sku])) {
423+
$productId = $oldSkus[$sku];
415424
foreach ($priceRows as $row) {
416-
$row['entity_id'] = $productId;
425+
$row[$this->getProductEntityLinkField()] = $productId;
417426
$priceIn[] = $row;
418427
$entityIds[] = $productId;
419428
}
@@ -430,24 +439,26 @@ protected function saveProductPrices(array $priceData, $table)
430439
* Deletes tier prices prices.
431440
*
432441
* @param array $listSku
433-
* @param string $tableName
434-
* @return bool
442+
* @param string $table
443+
* @return boolean
435444
*/
436-
protected function deleteProductTierPrices(array $listSku, $tableName)
445+
protected function deleteProductTierPrices(array $listSku, $table)
437446
{
447+
$tableName = $this->_resourceFactory->create()->getTable($table);
448+
$productEntityLinkField = $this->getProductEntityLinkField();
438449
if ($tableName && $listSku) {
439450
if (!$this->_cachedSkuToDelete) {
440451
$this->_cachedSkuToDelete = $this->_connection->fetchCol(
441452
$this->_connection->select()
442-
->from($this->_catalogProductEntity, 'entity_id')
453+
->from($this->_catalogProductEntity, $productEntityLinkField)
443454
->where('sku IN (?)', $listSku)
444455
);
445456
}
446457
if ($this->_cachedSkuToDelete) {
447458
try {
448459
$this->countItemsDeleted += $this->_connection->delete(
449460
$tableName,
450-
$this->_connection->quoteInto('entity_id IN (?)', $this->_cachedSkuToDelete)
461+
$this->_connection->quoteInto($productEntityLinkField . ' IN (?)', $this->_cachedSkuToDelete)
451462
);
452463
return true;
453464
} catch (\Exception $e) {
@@ -511,13 +522,15 @@ protected function getCustomerGroupId($customerGroup)
511522
*/
512523
protected function retrieveOldSkus()
513524
{
514-
$oldSkus = $this->_connection->fetchPairs(
515-
$this->_connection->select()->from(
516-
$this->_connection->getTableName('catalog_product_entity'),
517-
['sku', 'entity_id']
518-
)
519-
);
520-
return $oldSkus;
525+
if ($this->_oldSkus === null) {
526+
$this->_oldSkus = $this->_connection->fetchPairs(
527+
$this->_connection->select()->from(
528+
$this->_catalogProductEntity,
529+
['sku', $this->getProductEntityLinkField()]
530+
)
531+
);
532+
}
533+
return $this->_oldSkus;
521534
}
522535

523536
/**
@@ -529,15 +542,18 @@ protected function retrieveOldSkus()
529542
*/
530543
protected function processCountExistingPrices($prices, $table)
531544
{
545+
$tableName = $this->_resourceFactory->create()->getTable($table);
546+
$productEntityLinkField = $this->getProductEntityLinkField();
532547
$existingPrices = $this->_connection->fetchAssoc(
533548
$this->_connection->select()->from(
534-
$this->_connection->getTableName($table),
535-
['value_id', 'entity_id', 'all_groups', 'customer_group_id']
549+
$tableName,
550+
['value_id', $productEntityLinkField, 'all_groups', 'customer_group_id']
536551
)
537552
);
553+
$oldSkus = $this->retrieveOldSkus();
538554
foreach ($existingPrices as $existingPrice) {
539-
foreach ($this->_oldSkus as $sku => $productId) {
540-
if ($existingPrice['entity_id'] == $productId && isset($prices[$sku])) {
555+
foreach ($oldSkus as $sku => $productId) {
556+
if ($existingPrice[$productEntityLinkField] == $productId && isset($prices[$sku])) {
541557
$this->incrementCounterUpdated($prices[$sku], $existingPrice);
542558
}
543559
}
@@ -579,4 +595,19 @@ protected function processCountNewPrices(array $tierPrices)
579595

580596
return $this;
581597
}
598+
599+
/**
600+
* Get product entity link field
601+
*
602+
* @return string
603+
*/
604+
private function getProductEntityLinkField()
605+
{
606+
if (!$this->productEntityLinkField) {
607+
$this->productEntityLinkField = $this->getMetadataPool()
608+
->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class)
609+
->getLinkField();
610+
}
611+
return $this->productEntityLinkField;
612+
}
582613
}

0 commit comments

Comments
 (0)