Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

back-port-pull-19024 #19374

Merged
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
31 changes: 28 additions & 3 deletions app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,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 @@ -292,7 +302,8 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
ValidatorInterface::ERROR_MEDIA_PATH_NOT_ACCESSIBLE => 'Imported resource (image) does not exist in the local media storage',
ValidatorInterface::ERROR_MEDIA_URL_NOT_ACCESSIBLE => 'Imported resource (image) could not be downloaded from external resource due to timeout or access permissions',
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_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_NEW_TO_DATE => 'Make sure new_to_date is later than or the same as new_from_date',
];

/**
Expand All @@ -313,8 +324,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 @@ -2477,6 +2488,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 @@ -85,6 +85,8 @@ interface RowValidatorInterface extends \Magento\Framework\Validator\ValidatorIn

const ERROR_DUPLICATE_URL_KEY = 'duplicatedUrlKey';

const ERROR_NEW_TO_DATE = 'invalidNewToDateValue';

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