Skip to content

Commit ce701af

Browse files
author
Oleksii Gorbulin
committed
back-port-pull-19024
Back-port #19024 from 2.3 to 2.2
1 parent 97b98cc commit ce701af

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
129129
*/
130130
const COL_NAME = 'name';
131131

132+
/**
133+
* Column new_from_date.
134+
*/
135+
const COL_NEW_FROM_DATE = 'new_from_date';
136+
137+
/**
138+
* Column new_to_date.
139+
*/
140+
const COL_NEW_TO_DATE = 'new_to_date';
141+
132142
/**
133143
* Column product website.
134144
*/
@@ -292,7 +302,8 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
292302
ValidatorInterface::ERROR_MEDIA_PATH_NOT_ACCESSIBLE => 'Imported resource (image) does not exist in the local media storage',
293303
ValidatorInterface::ERROR_MEDIA_URL_NOT_ACCESSIBLE => 'Imported resource (image) could not be downloaded from external resource due to timeout or access permissions',
294304
ValidatorInterface::ERROR_INVALID_WEIGHT => 'Product weight is invalid',
295-
ValidatorInterface::ERROR_DUPLICATE_URL_KEY => 'Url key: \'%s\' was already generated for an item with the SKU: \'%s\'. You need to specify the unique URL key manually'
305+
ValidatorInterface::ERROR_DUPLICATE_URL_KEY => 'Url key: \'%s\' was already generated for an item with the SKU: \'%s\'. You need to specify the unique URL key manually',
306+
ValidatorInterface::ERROR_NEW_TO_DATE => 'Make sure new_to_date is later than or the same as new_from_date',
296307
];
297308

298309
/**
@@ -313,8 +324,8 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
313324
Product::COL_TYPE => 'product_type',
314325
Product::COL_PRODUCT_WEBSITES => 'product_websites',
315326
'status' => 'product_online',
316-
'news_from_date' => 'new_from_date',
317-
'news_to_date' => 'new_to_date',
327+
'news_from_date' => self::COL_NEW_FROM_DATE,
328+
'news_to_date' => self::COL_NEW_TO_DATE,
318329
'options_container' => 'display_product_options_in',
319330
'minimal_price' => 'map_price',
320331
'msrp' => 'msrp_price',
@@ -2477,6 +2488,20 @@ public function validateRow(array $rowData, $rowNum)
24772488
}
24782489
}
24792490
}
2491+
2492+
if (!empty($rowData[self::COL_NEW_FROM_DATE]) && !empty($rowData[self::COL_NEW_TO_DATE])
2493+
) {
2494+
$newFromTimestamp = strtotime($this->dateTime->formatDate($rowData[self::COL_NEW_FROM_DATE], false));
2495+
$newToTimestamp = strtotime($this->dateTime->formatDate($rowData[self::COL_NEW_TO_DATE], false));
2496+
if ($newFromTimestamp > $newToTimestamp) {
2497+
$this->addRowError(
2498+
ValidatorInterface::ERROR_NEW_TO_DATE,
2499+
$rowNum,
2500+
$rowData[self::COL_NEW_TO_DATE]
2501+
);
2502+
}
2503+
}
2504+
24802505
return !$this->getErrorAggregator()->isRowInvalid($rowNum);
24812506
}
24822507

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ interface RowValidatorInterface extends \Magento\Framework\Validator\ValidatorIn
8585

8686
const ERROR_DUPLICATE_URL_KEY = 'duplicatedUrlKey';
8787

88+
const ERROR_NEW_TO_DATE = 'invalidNewToDateValue';
89+
8890
/**
8991
* Value that means all entities (e.g. websites, groups etc.)
9092
*/

0 commit comments

Comments
 (0)