I am trying to override the "configurable_item_options" of the product_options under the orders API.
I want to add a further column between the option_id and option_value.
I can see that the "product_options"/"configurable_item_options" of the order Api comes under the "items" column. I can also see that the "items" column is derived from the getItems method of the following class:
vendor/magento/module-sales/Api/Data/OrderInterface.php This is the function:
public function getItems() { if ($this->getData(OrderInterface::ITEMS) == null) { $this->searchCriteriaBuilder->addFilter(OrderItemInterface::ORDER_ID,$this->getId()); $searchCriteria = $this->searchCriteriaBuilder->create(); $this->setData( OrderInterface::ITEMS, $this->itemRepository->getList($searchCriteria)->getItems() ); } return $this->getData(OrderInterface::ITEMS); } My Question
how can I override the above section to include a new column?
i tried to override it via a plugin:
<type name="Magento\Sales\Api\OrderRepositoryInterface"> <plugin name="delivery_promise_add_custom_config_product_to_sales_order" type="Primrose\DeliveryPromise\Plugin\AddCustomAndConfigurableProductAttributes"/> </type> The Plugin Class:
public function afterGet( OrderRepositoryInterface $subject, OrderInterface $result ) { $titleName = ["title_name" => "the New title"]; $result->setItems($titleName); return $result; } UPDATE:
I tried @LitExtension solution. i.e i tried to reset the Configurable Item Options via the $extensionAttributes but got this message:
Error: Call to undefined method Magento\Sales\Api\Data\OrderExtension::setConfigurableItemOptions( This is my method:
public function afterGet( OrderRepositoryInterface $subject, OrderInterface $orderItem ){ $extensionAttributes = $orderItem->getExtensionAttributes(); $extensionAttributes = $extensionAttributes ? $extensionAttributes : $this->extensionFactory->create(); $array = ['test' => "new value"]; $extensionAttributes->setConfigurableItemOptions($array); $orderItem->setExtensionAttributes($extensionAttributes); return $orderItem; } 