Skip to content

Commit 3a643ce

Browse files
author
Stanislav Idolov
authored
ENGCOM-3406: Add-validation-new-from-date-less-than-new-to-date-in-SCV-product-import #19024
2 parents 74549e7 + 54bf314 commit 3a643ce

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
132132
*/
133133
const COL_NAME = 'name';
134134

135+
/**
136+
* Column new_from_date.
137+
*/
138+
const COL_NEW_FROM_DATE = 'new_from_date';
139+
140+
/**
141+
* Column new_to_date.
142+
*/
143+
const COL_NEW_TO_DATE = 'new_to_date';
144+
135145
/**
136146
* Column product website.
137147
*/
@@ -298,6 +308,7 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
298308
ValidatorInterface::ERROR_INVALID_WEIGHT => 'Product weight is invalid',
299309
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',
300310
ValidatorInterface::ERROR_DUPLICATE_MULTISELECT_VALUES => "Value for multiselect attribute %s contains duplicated values",
311+
ValidatorInterface::ERROR_NEW_TO_DATE => 'Make sure new_to_date is later than or the same as new_from_date',
301312
];
302313
//@codingStandardsIgnoreEnd
303314

@@ -319,8 +330,8 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
319330
Product::COL_TYPE => 'product_type',
320331
Product::COL_PRODUCT_WEBSITES => 'product_websites',
321332
'status' => 'product_online',
322-
'news_from_date' => 'new_from_date',
323-
'news_to_date' => 'new_to_date',
333+
'news_from_date' => self::COL_NEW_FROM_DATE,
334+
'news_to_date' => self::COL_NEW_TO_DATE,
324335
'options_container' => 'display_product_options_in',
325336
'minimal_price' => 'map_price',
326337
'msrp' => 'msrp_price',
@@ -2549,6 +2560,20 @@ public function validateRow(array $rowData, $rowNum)
25492560
}
25502561
}
25512562
}
2563+
2564+
if (!empty($rowData[self::COL_NEW_FROM_DATE]) && !empty($rowData[self::COL_NEW_TO_DATE])
2565+
) {
2566+
$newFromTimestamp = strtotime($this->dateTime->formatDate($rowData[self::COL_NEW_FROM_DATE], false));
2567+
$newToTimestamp = strtotime($this->dateTime->formatDate($rowData[self::COL_NEW_TO_DATE], false));
2568+
if ($newFromTimestamp > $newToTimestamp) {
2569+
$this->addRowError(
2570+
ValidatorInterface::ERROR_NEW_TO_DATE,
2571+
$rowNum,
2572+
$rowData[self::COL_NEW_TO_DATE]
2573+
);
2574+
}
2575+
}
2576+
25522577
return !$this->getErrorAggregator()->isRowInvalid($rowNum);
25532578
}
25542579

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

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

8888
const ERROR_DUPLICATE_MULTISELECT_VALUES = 'duplicatedMultiselectValues';
8989

90+
const ERROR_NEW_TO_DATE = 'invalidNewToDateValue';
91+
9092
/**
9193
* Value that means all entities (e.g. websites, groups etc.)
9294
*/

0 commit comments

Comments
 (0)