I know this question has been asked before:
- Add video to product programatically
- Magento 2.2.5 : Add video to product programmatically
- Importing product videos
- maybe others
but I need something different.
The answers in the questions linked above suggest using some core methods that (all of them) load the full product and save the full product, either via repository or via the load/save
deprecated methods.
I have a lot of products. Somewhere between 5k and 10k.
Going through all of them with load/save it is not really a viable option.
Any other suggestions?
Best Answer
I ended up doing it with the risky inserts directly into the tables.
the tables involved are (in this order)
Pre-explanations: This should happen inside one class.
This class has these members that are added via constructor (di will take care of instantiating them)
Let's take the tables 1 by 1:
catalog_product_entity_media_gallery
Now remember the last added increment id because it is needed in the later inserts.
catalog_product_entity_media_gallery_value
catalog_product_entity_media_gallery_value_to_entity
catalog_product_entity_media_gallery_value_video
That's it. Some reindexing may be needed.