0

I want to get the Full Price, including the Custom Option price on Add To Cart.

I've tested using the checkout_cart_add_product_complete event with below observer:

class CheckoutCartAddProductObserver implements ObserverInterface
{
    public function execute(EventObserver $observer)
    {
        $product = $observer->getEvent()->getQuoteItem();
        $price = $product->getPriceInfo()->getPrice('final_price')->getValue();
    }
}

Which gives me the final price of the product, but it doesn't include the price of the option. The option is of type dropdown, if that makes a difference.

1 Answer 1

0

Are you sure this isn't working?

app/code/[Vendor]/[Module]/etc/frontend/events.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
   <event name="checkout_cart_add_product_complete">
         <observer name="caraddcomplete" instance="[Vendor]\[Module]\Observer\CartAddComplete"/>
    </event>
</config>

app/code/[Vendor]/[Module]/Observer/CartAddComplete.php

<?php

namespace [Vendor]\[Module]\Observer;

use Magento\Framework\Event\ObserverInterface;

class CartAddComplete implements ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $product = $observer->getEvent()->getData('product');
        $isHasOptions = $product->getTypeInstance()->hasOptions($product);
        if ($isHasOptions) {
            $price = $product->getFinalPrice();
        }
    }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.