I understood your concern, that you want to add new products, update existing products price and product attribute value without mess up with old data.
I recommended you to create a patch command to import-products,
In this patch include below conditions
- Check Website code and Store view condition
- Whether the product has existing or not
- To update any data, include additional option in command line
**productupdate==1**
based on this condition you update the new values with old data
After checking this condition, you need to check like below sample code.
$import_file = pathinfo($import_path);
$import = $this->importFactory->create();
$import->setData(
array(
'entity' => 'catalog_product',
'behavior' => $import->getDefaultBehavior(),
'validation_strategy' => 'validation-stop-on-errors',
)
);
$read_file = $this->readFactory->create($import_file['dirname']);
$csvSource = $this->csvSourceFactory->create(
array(
'file' => $import_file['basename'],
'directory' => $read_file,
)
);
$validate = $import->validateSource($csvSource);
if (!$validate) {
$output->writeln('<error>Unable to validate the CSV.</error>');
exit;
}
$result = $import->importSource();
if ($result) {
$import->invalidateIndex();
}
if ($import->getCreatedItemsCount() > 0 && $productUpdate == 0) {
$output->writeln("<info>Finished importing products from $import_path</info>");
} else if ($import->getUpdatedItemsCount() > 0 && $productUpdate == 1) {
$output->writeln("<info>Finished Updating the products from $import_path</info>");
} else {
$output->writeln("<error> Products are not created/updated, cross check the source file from $import_path</error>");
}
Note: The CSV file should have all data of the products while import new value
Ex: If you updating price value, then the CSV file the product should have all data and include with new price value. This will avoid missing data while doing update.
I am following this and its working for me.