I have tried to set custom option price when order is placed the price should be stored in sales_order_item table in custom_option column and tried to create plugin for this but the plugin is not working. I have done debug and found that COre magento custom option data is set from this abstract class :
This is magento core function behavior of custom option.
vendor/magento/module-catalog/Model/Product/Type/AbstractType.php
/**
* Prepare additional options/information for order item which will be
* created from this product
*
* @param \Magento\Catalog\Model\Product $product
* @return array
*/
public function getOrderOptions($product)
{
$optionArr = [];
$info = $product->getCustomOption('info_buyRequest');
if ($info) {
$optionArr['info_buyRequest'] = $this->serializer->unserialize($info->getValue());
}
$optionIds = $product->getCustomOption('option_ids');
if ($optionIds) {
foreach (explode(',', $optionIds->getValue()) as $optionId) {
$option = $product->getOptionById($optionId);
if ($option) {
$confItemOption = $product->getCustomOption(self::OPTION_PREFIX . $option->getId());
$group = $option->groupFactory($option->getType())
->setOption($option)
->setProduct($product)
->setConfigurationItemOption($confItemOption);
$optionArr['options'][] = [
'label' => $option->getTitle(),
'value' => $group->getFormattedOptionValue($confItemOption->getValue()),
'print_value' => $group->getPrintableOptionValue($confItemOption->getValue()),
'option_id' => $option->getId(),
'option_type' => $option->getType(),
'option_value' => $confItemOption->getValue(),
'custom_view' => $group->isCustomizedView(), ];
}
}
}
$productTypeConfig = $product->getCustomOption('product_type');
if ($productTypeConfig) {
$optionArr['super_product_config'] = [
'product_code' => $productTypeConfig->getCode(),
'product_type' => $productTypeConfig->getValue(),
'product_id' => $productTypeConfig->getProductId(),
];
}
return $optionArr;
}
In this core file if i add this key and value in existing array then i am able to get price in transactional email.
'price' => $group->getOptionPrice($confItemOption->getValue(), 0)
Could any one suggest that how could we save custom option price in order and get it in emails.