Additional Options to quote item REST API
-
15-04-2021 - |
Question
I'm trying to add additional options to the product, it is working fine to add attributes programmatically on the website but how to add these additional attributes to the REST API.
public function aroundConvert(
\Magento\Quote\Model\Quote\Item\ToOrderItem $subject,
Closure $proceed,
\Magento\Quote\Model\Quote\Item\AbstractItem $item,
$additional = []
) {
/** @var $orderItem \Magento\Sales\Model\Order\Item */
$orderItem = $proceed($item, $additional);//result of function 'convert' in class 'Magento\Quote\Model\Quote\Item\ToOrderItem'
if ($additionalOptions = $item->getOptionByCode('additional_options')) {
$options = $orderItem->getProductOptions();
$options['additional_options'] = $this->serialize->unserialize($additionalOptions->getValue());
$orderItem->setProductOptions($options);
return $orderItem;
}
return $orderItem;
}
When I try to add an additional option to REST API: V1/carts/mine/items
I'm getting the following error.
"Property "AdditionalOptions" does not have accessor method "getAdditionalOptions" in class "Magento\Catalog\Api\Data\CustomOptionInterface"."
Below is my request packet:
{
"cartItem": {
"sku": "MEW001",
"qty": 1,
"quote_id": "126252",
"product_option": {
"extension_attributes": {
"custom_options": [
{
"additional_options":
{
"price":"200.000000",
"send_friend":"1",
"customer_name":"Sender Name",
"recipient_name":"Friend",
"recipient_email":"sendto@email.com",
"message":"xyz"
}
}
]
}
}
}
}
And the screenshot.
Pas de solution correcte
Autres conseils
Please check below array with your rest api.
Array
(
[cartItem] => Array
(
[quote_id] => 463
[sku] =>
[qty] => 2
[product_option] => Magento\Framework\DataObject Object
(
[_data:protected] => Array
(
[extension_attributes] => Magento\Framework\DataObject Object
(
[_data:protected] => Array
(
[custom_options] => Array
(
[0] => Magento\Framework\DataObject Object
(
[_data:protected] => Array
(
[option_id] => 50
[option_value] => 149
)
)
)
)
)
)
)
)
)
Let me know still if you face any issues. Thanks
Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange