Error "option values are not specified." in script for import products
Greetings to all members of the community.
I need some advice to solve a problem. I use Magento 2.4.1 and I created a script, external to Magento, to import custom products from CSV files. The script I made works as follows:
the script lists the CSV files found within a folder. In each CSV file there are only one custom product and several simple products. The script first creates the simple products by associating them with the values of the different attributes. The script then creates a custom product and associates simple product IDs to it. In order to associate simple products with the custom product, I use the following code:
The problem I encounter is the following. Using the script a first time on a group of files (let's suppose, to fix the ideas, three files that we will call for convenience A, B and C) only the products (custom and simple) related to files A and C are created, but for file B only simple products are created, but not the custom product.
Using a second time the script on the three files A, B and C, the script, after having deleted the products created previously (phase 1), creates the products (simple and custom) related to B and C, the simple products of A, but not A's custom product; furthermore, when the custom product related to a certain CSV file is not created, the following error message is generated:
error: "option values are not specified."
It therefore seems that the error described is generated randomly; moreover, when the error occurs on the custom product, if you check the simple products generated, it turns out that they have all the attributes of the combinations correctly valued.
How can I do to correct this error? Has anyone already encountered and solved this problem or, at least, a similar one?