Showing results for 
Search instead for 
Did you mean: 

How to create OptionInterface from variable for $configurable->setUsedProductOptions()

How to create OptionInterface from variable for $configurable->setUsedProductOptions()

I have written a module for an additional API endpoint with the purpose of adding simple SKUs to configurable SKUs. Example:

POST /rest/V1/configurable-products/:sku/children


Before the module, I had written a PHP script which uses a mixture of Magento API endpoints to achieve the desired effect. This includes:


 - adding the attributes to the configurable

 - pulling the attribute values from the simple SKUs

 - setting the simples attribute values as options to the configurable

 - setting the simples as associated products to the configurable


This works as expected and since writing the script I have now developed a module to achieve all this in 1 API call as the example I initially shown above.


Currently, the module achieves everything the script did except for setting the simple attribute values as options to the configurable. The only reason I cannot do this is because I cannot figure out how I create an OptionInterface from my $simpleOptions variable for use with the function:


Below is a json_encoded dump of the $simpleOptions variable that is populated by the module during processing. The data matches the structure used in my previous script which used the following API endpoint to set the options.

POST /rest/V1/configurable-products/:sku/options


How do I create an OptionInterface object from my $simpleOptions variable?

* @param \Magento\ConfigurableProduct\Api\Data\OptionInterface[] $configurableProductOptions
* @return $this
public function setConfigurableProductOptions($configurableProductOptions);

Many thanks in advance!