Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
*/
const COL_NAME = 'name';

/**
* Column new_from_date.
*/
const COL_NEW_FROM_DATE = 'new_from_date';

/**
* Column new_to_date.
*/
const COL_NEW_TO_DATE = 'new_to_date';

/**
* Column product website.
*/
Expand Down Expand Up @@ -298,6 +308,7 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
ValidatorInterface::ERROR_INVALID_WEIGHT => 'Product weight is invalid',
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',
ValidatorInterface::ERROR_DUPLICATE_MULTISELECT_VALUES => "Value for multiselect attribute %s contains duplicated values",
ValidatorInterface::ERROR_NEW_TO_DATE => 'Make sure new_to_date is later than or the same as new_from_date',
];
//@codingStandardsIgnoreEnd

Expand All @@ -319,8 +330,8 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
Product::COL_TYPE => 'product_type',
Product::COL_PRODUCT_WEBSITES => 'product_websites',
'status' => 'product_online',
'news_from_date' => 'new_from_date',
'news_to_date' => 'new_to_date',
'news_from_date' => self::COL_NEW_FROM_DATE,
'news_to_date' => self::COL_NEW_TO_DATE,
'options_container' => 'display_product_options_in',
'minimal_price' => 'map_price',
'msrp' => 'msrp_price',
Expand Down Expand Up @@ -2546,6 +2557,20 @@ public function validateRow(array $rowData, $rowNum)
}
}
}

if (!empty($rowData[self::COL_NEW_FROM_DATE]) && !empty($rowData[self::COL_NEW_TO_DATE])
) {
$newFromTimestamp = strtotime($this->dateTime->formatDate($rowData[self::COL_NEW_FROM_DATE], false));
$newToTimestamp = strtotime($this->dateTime->formatDate($rowData[self::COL_NEW_TO_DATE], false));
if ($newFromTimestamp > $newToTimestamp) {
$this->addRowError(
ValidatorInterface::ERROR_NEW_TO_DATE,
$rowNum,
$rowData[self::COL_NEW_TO_DATE]
);
}
}

return !$this->getErrorAggregator()->isRowInvalid($rowNum);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ interface RowValidatorInterface extends \Magento\Framework\Validator\ValidatorIn

const ERROR_DUPLICATE_MULTISELECT_VALUES = 'duplicatedMultiselectValues';

const ERROR_NEW_TO_DATE = 'invalidNewToDateValue';

/**
* Value that means all entities (e.g. websites, groups etc.)
*/
Expand Down