I am following the tutorial Create a custom import entity . However, instead of importing learning courses as shown in the tutorial, I’m attempting to import orders.
To adapt the tutorial for orders, I made the following changes:
- const TABLE = 'learning_courses';
+ const TABLE = 'sales_order';
and
- protected $validColumnNames = [
'entity_id',
'name',
'duration'
];
+ protected $validColumnNames = [
'entity_id',
'state',
'status',
'coupon_code',...];
After making these changes, I encountered an issue where the $bunch variable still holds the old CSV data, even when using a CSV file adapted to the sales_order attributes:
$bunch = $this->_dataSourceModel->getNextBunch()
i tried adding $this->_dataSourceModel->cleanProcessedBunches();
before the while loop, this change successfully updates the data for the first iteration, but subsequently, the back office freezes.
I would appreciate any insights or suggestions on how to resolve this issue.
2
Answers
You can try deleting the data in the importexport_importdata table.
The issue will be resolved.
Instead of
$bunch = $this->_dataSourceModel->getNextBunch()
you can usegetNextUniqueBunch($ids = null)
. This method will only retrieve the next unique bunch of validated rows. All you have to do is pass the ids of the validated rows to this method. You can get them by executinggetIds()
method on the import class.It should look something like this:
$bunch = $this->_dataSourceModel->getNextUniqueBunch($this->getIds())
. In my case it solved the problem completely.