Skip to content

Quote item in checkout_cart_product_add_after contains incorrect values #3531

Closed
@katesuykovskaya

Description

@katesuykovskaya

I've created observer for event checkout_cart_product_add_after to set custom price for quote item. But $observer->getEvent()->getData('quote_item') shows me old data, for ex. - I have product with base price=100$, and tier price (qty>=2) = 50$. When I add product to cart in the first time, quote price = 0, in the 2nd time - 100$ (but should be 50$), in the 3rd time - 50$.
My events.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <event name="checkout_cart_product_add_after"> <observer name="my" instance="My\ProductDesigner\Observer\Frontend\AddProductAfterObserver"/> </event> </config>
Code of observer:
`namespace My\ProductDesigner\Observer\Frontend;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Registry;

class AddProductAfterObserver implements ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
$item = $observer->getEvent()->getData('quote_item');
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
$item->getPrice(); // here I got old value
}
}`

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions