I want to alter product price in magento 2.4.7 To do it in catalog and single view i have plugin
<type name="MagentoCatalogModelProduct">
inside afterGetPrice
. This is wrok for me well.
However after i add product in checkout price alters. So i have another plugin
<type name="MagentoQuoteModelQuote">
, and inside
beforeCollectTotals
My problem is that i want to change price based on product id(external logic per product).
I can do
public function beforeCollectTotals(MagentoQuoteModelQuote $subject)
{
/**
* @var $item Item
*/
foreach ($subject->getAllItems() as $item) {
/**
* @var $product Product
*/
$product = $item->getProduct();
But now my if product is configurable i have id of parent not a child.
I Found that i can do
if ($product->getTypeId() === 'configurable') {
$id = array_first($item->getData()['qty_options'])->getData('product_id');
} else {
$id = $product->getId();
}
To get **child id** But i wonder is there any alternatives here ? To get this working ?