Skip to content

Commit a2de59c

Browse files
author
Dmitry Kologrivov
committed
MAGNIMEX-151: Fix update product and call table name
1 parent e211bb9 commit a2de59c

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\Abstract
119119
*/
120120
protected $_permanentAttributes = [self::COL_SKU];
121121

122+
/**
123+
* Catalog product entity
124+
*
125+
* @var string
126+
*/
127+
protected $_catalogProductEntity;
128+
122129
/**
123130
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
124131
* @param \Magento\Framework\Json\Helper\Data $jsonHelper
@@ -164,6 +171,7 @@ public function __construct(
164171
$this->_oldSkus = $this->retrieveOldSkus();
165172
$this->websiteValidator = $websiteValidator;
166173
$this->groupPriceValidator = $groupPriceValidator;
174+
$this->_catalogProductEntity = $this->_resourceFactory->create()->getTable('catalog_product_entity');
167175
}
168176

169177
/**
@@ -262,6 +270,7 @@ public function deleteAdvancedPricing()
262270
if ($listSku) {
263271
$this->deleteProductTierAndGroupPrices(array_unique($listSku), self::TABLE_GROUPED_PRICE);
264272
$this->deleteProductTierAndGroupPrices(array_unique($listSku), self::TABLE_TIER_PRICE);
273+
$this->setUpdatedAt($listSku);
265274
}
266275
return $this;
267276
}
@@ -298,9 +307,9 @@ protected function saveAndReplaceAdvancedPrices()
298307
continue;
299308
}
300309
$rowSku = $rowData[self::COL_SKU];
301-
if (\Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE == $behavior) {
310+
//if (\Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE == $behavior) {
302311
$listSku[] = $rowSku;
303-
}
312+
//}
304313
if (!empty($rowData[self::COL_TIER_PRICE_WEBSITE])) {
305314
$tierPrices[$rowSku][] = [
306315
'all_groups' => $rowData[self::COL_TIER_PRICE_CUSTOMER_GROUP] == self::VALUE_ALL_GROUPS,
@@ -330,6 +339,7 @@ protected function saveAndReplaceAdvancedPrices()
330339
&& $this->deleteProductTierAndGroupPrices(array_unique($listSku), self::TABLE_TIER_PRICE)) {
331340
$this->saveProductPrices($tierPrices, self::TABLE_TIER_PRICE)
332341
->saveProductPrices($groupPrices, self::TABLE_GROUPED_PRICE);
342+
$this->setUpdatedAt($listSku);
333343
}
334344
}
335345
} elseif (\Magento\ImportExport\Model\Import::BEHAVIOR_APPEND == $behavior) {
@@ -338,6 +348,9 @@ protected function saveAndReplaceAdvancedPrices()
338348
->processCountNewPrices($tierPrices, $groupPrices);
339349
$this->saveProductPrices($tierPrices, self::TABLE_TIER_PRICE)
340350
->saveProductPrices($groupPrices, self::TABLE_GROUPED_PRICE);
351+
if ($listSku) {
352+
$this->setUpdatedAt($listSku);
353+
}
341354
}
342355
}
343356
return $this;
@@ -355,12 +368,14 @@ protected function saveProductPrices(array $priceData, $table)
355368
if ($priceData) {
356369
$tableName = $this->_resourceFactory->create()->getTable($table);
357370
$priceIn = [];
371+
$entityIds = [];
358372
foreach ($priceData as $sku => $priceRows) {
359373
if (isset($this->_oldSkus[$sku])) {
360374
$productId = $this->_oldSkus[$sku];
361375
foreach ($priceRows as $row) {
362376
$row['entity_id'] = $productId;
363377
$priceIn[] = $row;
378+
$entityIds[] = $productId;
364379
}
365380
}
366381
}
@@ -384,7 +399,7 @@ protected function deleteProductTierAndGroupPrices(array $listSku, $tableName)
384399
if (!$this->_cachedSkuToDelete) {
385400
$this->_cachedSkuToDelete = $this->_connection->fetchCol(
386401
$this->_connection->select()
387-
->from($this->_connection->getTableName('catalog_product_entity'), 'entity_id')
402+
->from($this->_catalogProductEntity, 'entity_id')
388403
->where('sku IN (?)', $listSku)
389404
);
390405
}
@@ -407,6 +422,20 @@ protected function deleteProductTierAndGroupPrices(array $listSku, $tableName)
407422
}
408423
}
409424

425+
/**
426+
* Set updated_at for product
427+
*
428+
* @param $listSku
429+
*/
430+
protected function setUpdatedAt($listSku)
431+
{
432+
$this->_connection->update(
433+
$this->_catalogProductEntity,
434+
[\Magento\Catalog\Model\Category::KEY_UPDATED_AT => date('Y-m-d H:i:s')],
435+
$this->_connection->quoteInto('sku IN (?)', $listSku)
436+
);
437+
}
438+
410439
/**
411440
* Get website id by code
412441
*

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,7 @@ protected function _saveProducts()
13741374
$dispersionPath =
13751375
\Magento\Framework\File\Uploader::getDispretionPath($rowData[self::COL_MEDIA_IMAGE]);
13761376
$imageName = preg_replace('/[^a-z0-9\._-]+/i', '', $rowData[self::COL_MEDIA_IMAGE]);
1377-
$fullDispersionPath = strtolower($dispersionPath . '/' . $imageName);
1377+
$fullDispersionPath = mb_strtolower($dispersionPath . '/' . $imageName);
13781378
foreach ($this->cachedImages as $image) {
13791379
if (($image['sku'] == $rowData[self::COL_SKU])
13801380
&& ($image['value'] == $fullDispersionPath)

0 commit comments

Comments
 (0)