Skip to content

Commit 5c0c0b0

Browse files
Merge branch 'MAGNIMEX-151-Update-products' into 'master'
Magnimex 151 update products See merge request !162
2 parents 87f9cdf + cbc14bc commit 5c0c0b0

File tree

3 files changed

+54
-12
lines changed

3 files changed

+54
-12
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class AdvancedPricing extends \Magento\CatalogImportExport\Model\Export\Product
3838
protected $_entityTypeCode;
3939

4040
/**
41-
* @var
41+
* @var \Magento\Framework\App\Resource
4242
*/
4343
protected $_resource;
4444

@@ -72,6 +72,11 @@ class AdvancedPricing extends \Magento\CatalogImportExport\Model\Export\Product
7272
ImportAdvancedPricing::COL_GROUP_PRICE_CUSTOMER_GROUP,
7373
];
7474

75+
/**
76+
* Template array for export data
77+
*
78+
* @var array
79+
*/
7580
protected $templateExportData = [
7681
ImportAdvancedPricing::COL_SKU => '',
7782
ImportAdvancedPricing::COL_GROUP_PRICE_WEBSITE => '',
@@ -298,7 +303,7 @@ protected function getExportData()
298303
}
299304

300305
/**
301-
* @param $exportData
306+
* @param array $exportData
302307
* @return array
303308
*/
304309
protected function correctExportData($exportData)
@@ -336,7 +341,7 @@ protected function correctExportData($exportData)
336341
* Get Tier and Group Pricing
337342
*
338343
* @param array $listSku
339-
* @param $table
344+
* @param string $table
340345
* @return array|bool
341346
*/
342347
protected function getTierAndGroupPrices(array $listSku, $table)
@@ -413,7 +418,7 @@ protected function getTierAndGroupPrices(array $listSku, $table)
413418
/**
414419
* Get Website code
415420
*
416-
* @param $websiteId
421+
* @param int $websiteId
417422
* @return string
418423
*/
419424
protected function _getWebsiteCode($websiteId)
@@ -434,7 +439,7 @@ protected function _getWebsiteCode($websiteId)
434439
/**
435440
* Get Customer Group By Id
436441
*
437-
* @param $customerGroupId
442+
* @param int $customerGroupId
438443
* @param null $allGroups
439444
* @return string
440445
*/

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

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,18 @@ 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+
129+
/**
130+
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
131+
*/
132+
protected $_localeDate;
133+
122134
/**
123135
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
124136
* @param \Magento\Framework\Json\Helper\Data $jsonHelper
@@ -136,6 +148,7 @@ class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\Abstract
136148
* @param AdvancedPricing\Validator\GroupPrice $groupPriceValidator
137149
*/
138150
public function __construct(
151+
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
139152
\Magento\Framework\Json\Helper\Data $jsonHelper,
140153
\Magento\ImportExport\Helper\Data $importExportData,
141154
\Magento\ImportExport\Model\Resource\Helper $resourceHelper,
@@ -150,6 +163,7 @@ public function __construct(
150163
AdvancedPricing\Validator\Website $websiteValidator,
151164
AdvancedPricing\Validator\GroupPrice $groupPriceValidator
152165
) {
166+
$this->_localeDate = $localeDate;
153167
$this->jsonHelper = $jsonHelper;
154168
$this->_importExportData = $importExportData;
155169
$this->_resourceHelper = $resourceHelper;
@@ -164,6 +178,7 @@ public function __construct(
164178
$this->_oldSkus = $this->retrieveOldSkus();
165179
$this->websiteValidator = $websiteValidator;
166180
$this->groupPriceValidator = $groupPriceValidator;
181+
$this->_catalogProductEntity = $this->_resourceFactory->create()->getTable('catalog_product_entity');
167182
}
168183

169184
/**
@@ -262,6 +277,7 @@ public function deleteAdvancedPricing()
262277
if ($listSku) {
263278
$this->deleteProductTierAndGroupPrices(array_unique($listSku), self::TABLE_GROUPED_PRICE);
264279
$this->deleteProductTierAndGroupPrices(array_unique($listSku), self::TABLE_TIER_PRICE);
280+
$this->setUpdatedAt($listSku);
265281
}
266282
return $this;
267283
}
@@ -287,8 +303,8 @@ protected function saveAndReplaceAdvancedPrices()
287303
$behavior = $this->getBehavior();
288304
if (\Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE == $behavior) {
289305
$this->_cachedSkuToDelete = null;
290-
$listSku = [];
291306
}
307+
$listSku = [];
292308
while ($bunch = $this->_dataSourceModel->getNextBunch()) {
293309
$tierPrices = [];
294310
$groupPrices = [];
@@ -298,9 +314,7 @@ protected function saveAndReplaceAdvancedPrices()
298314
continue;
299315
}
300316
$rowSku = $rowData[self::COL_SKU];
301-
if (\Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE == $behavior) {
302-
$listSku[] = $rowSku;
303-
}
317+
$listSku[] = $rowSku;
304318
if (!empty($rowData[self::COL_TIER_PRICE_WEBSITE])) {
305319
$tierPrices[$rowSku][] = [
306320
'all_groups' => $rowData[self::COL_TIER_PRICE_CUSTOMER_GROUP] == self::VALUE_ALL_GROUPS,
@@ -330,6 +344,7 @@ protected function saveAndReplaceAdvancedPrices()
330344
&& $this->deleteProductTierAndGroupPrices(array_unique($listSku), self::TABLE_TIER_PRICE)) {
331345
$this->saveProductPrices($tierPrices, self::TABLE_TIER_PRICE)
332346
->saveProductPrices($groupPrices, self::TABLE_GROUPED_PRICE);
347+
$this->setUpdatedAt($listSku);
333348
}
334349
}
335350
} elseif (\Magento\ImportExport\Model\Import::BEHAVIOR_APPEND == $behavior) {
@@ -338,6 +353,9 @@ protected function saveAndReplaceAdvancedPrices()
338353
->processCountNewPrices($tierPrices, $groupPrices);
339354
$this->saveProductPrices($tierPrices, self::TABLE_TIER_PRICE)
340355
->saveProductPrices($groupPrices, self::TABLE_GROUPED_PRICE);
356+
if ($listSku) {
357+
$this->setUpdatedAt($listSku);
358+
}
341359
}
342360
}
343361
return $this;
@@ -355,12 +373,14 @@ protected function saveProductPrices(array $priceData, $table)
355373
if ($priceData) {
356374
$tableName = $this->_resourceFactory->create()->getTable($table);
357375
$priceIn = [];
376+
$entityIds = [];
358377
foreach ($priceData as $sku => $priceRows) {
359378
if (isset($this->_oldSkus[$sku])) {
360379
$productId = $this->_oldSkus[$sku];
361380
foreach ($priceRows as $row) {
362381
$row['entity_id'] = $productId;
363382
$priceIn[] = $row;
383+
$entityIds[] = $productId;
364384
}
365385
}
366386
}
@@ -384,8 +404,8 @@ protected function deleteProductTierAndGroupPrices(array $listSku, $tableName)
384404
if (!$this->_cachedSkuToDelete) {
385405
$this->_cachedSkuToDelete = $this->_connection->fetchCol(
386406
$this->_connection->select()
387-
->from($this->_connection->getTableName('catalog_product_entity'), 'entity_id')
388-
->where('sku IN (?)', $listSku)
407+
->from($this->_catalogProductEntity, 'entity_id')
408+
->where('sku IN (?)', $listSku)
389409
);
390410
}
391411
if ($this->_cachedSkuToDelete) {
@@ -407,6 +427,23 @@ protected function deleteProductTierAndGroupPrices(array $listSku, $tableName)
407427
}
408428
}
409429

430+
/**
431+
* Set updated_at for product
432+
*
433+
* @param array $listSku
434+
* @return $this
435+
*/
436+
protected function setUpdatedAt(array $listSku)
437+
{
438+
$updatedAt = $this->_localeDate->date(null, null, false)->format('Y-m-d H:i:s');
439+
$this->_connection->update(
440+
$this->_catalogProductEntity,
441+
[\Magento\Catalog\Model\Category::KEY_UPDATED_AT => $updatedAt],
442+
$this->_connection->quoteInto('sku IN (?)', $listSku)
443+
);
444+
return $this;
445+
}
446+
410447
/**
411448
* Get website id by code
412449
*

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

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

0 commit comments

Comments
 (0)