I have a product which is affected by a catalog price rule and nothing else. The regular price is 14.99. The final price is 3.0
Now I want to export this product with the final price. I build a Plugin which is supposed to add the final price of the product.
public function afterGetExportData(FirebearProduct $subject, array $result)
{
foreach ($result as $item) {
/** @var MagentoCatalogModelProduct; $product */
$product = $this->productFactory->create();
$productId = $item['product_id'];
$this->resourceModel->load($product, $productId, ['final_price']);
$price = $product->getPriceInfo()->getPrice('final_price')->getValue();
$result['final_price_export'] = $price;
}
return $result;
}
But the expression $product->getPriceInfo()->getPrice('final_price')->getValue();
returns the regular price 14.99. Which is weird because in a different context (with a Collection) I get the correct final price:
public function after_prepareEntityCollection(FirebearProduct $subject, MagentoCatalogModelResourceModelProductCollection $result, AbstractCollection $collection)
{
foreach ($result as $item) {
$finalPrice = $item->getPriceInfo()->getPrice('final_price')->getValue();
$item->setData('final_price_value', $finalPrice);
}
return $result;
}
$finalPrice = 3.0
Why is the final price loaded in scenario B but not in scenario A? Both are working with the Product entities. But one is using a collection and the other is loading the Product entities separately.