0

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.

enter image description here

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; } 

1 Answer 1

0
public function afterGet(OrderItemRepositoryInterface $subject, OrderItemInterface $orderItem) { $customAttrName = $orderItem->getData(self::CUSTOM_ATTR_NAME); $extensionAttributes = $orderItem->getExtensionAttributes(); $extensionAttributes = $extensionAttributes ? $extensionAttributes : $this->extensionFactory->create(); $extensionAttributes->setCustomAttrName($customAttrName); $orderItem->setExtensionAttributes($extensionAttributes); return $orderItem; } public function afterGetList(OrderItemRepositoryInterface $subject, OrderItemSearchResultInterface $searchResult) { $orderItems = $searchResult->getItems(); foreach ($orderItems as &$item) { $customAttrName = $item->getData(self::CUSTOM_ATTR_NAME); $extensionAttributes = $item->getExtensionAttributes(); $extensionAttributes = $extensionAttributes ? $extensionAttributes : $this->extensionFactory->create(); $extensionAttributes->setCustomAttrName($customAttrName); $item->setExtensionAttributes($extensionAttributes); } return $searchResult; } 
1
  • hello . thanks for your kind reply. i am however having problem resetting the configurableItem Options . this is the error message i received: Call to undefined method Magento\Sales\Api\Data\OrderExtension::setConfigurableItemOptions() Commented Jan 6, 2022 at 10:26

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.