Basically I am trying to add additional fees to subtotal of checkout/cart based on product_type. Here is what I tried but I am not able to get print_r($item->getBasePrice()); because I want to add addbaseprice of item with additionalfeesuch as finalPrice = $item->getBasePrice() + 10; and do something like below for each item in the quote based on product type. It would be great if anyone can guide me through this as it would be really great learning experience. I also looked up on web but couldn’t find anything relevant.
$quote->collectTotals();
$item
// ->setConvertedPrice($finalPrice)
// ->setCustomPrice($finalPrice)
// ->setOriginalCustomPrice($finalPrice);
// $item->calcRowTotal();
appcodeKGFCheckoutetcevents.xml
<event name="checkout_cart_save_before">
<observer name="kgf_checkout_cart_save_before" instance="KGFCheckoutObserverCartSaveBefore" />
</event>
appcodeKGFCheckoutObserverCartSaveBefore.php
<?php
namespace KGFCheckoutObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestInterface;
class CartSaveBefore implements ObserverInterface
{
public function execute(MagentoFrameworkEventObserver $observer){
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
/** @var MagentoCheckoutModelSession $checkoutSession */
$checkoutSession = $objectManager->create("MagentoCheckoutModelSession");
$quote = $checkoutSession->getQuote();
//print_r($quote->debug());//Gives information about quote but no information about its items
$quote->collectTotals();
foreach ($quote->getAllVisibleItems() as $item) {//DOES NOT EXECUTE
print_r($item->getBasePrice());
}
$cart = $observer->getCart();
$quote_cart = $cart->getQuote();
//print_r($quote_cart->debug());//Gives information about quote but no information about its items
foreach($quote_cart->getAllVisibleItems() as $item){//DOES EXECUTE BUT DOES NOT GIVE BASE PRICE
print_r($item->getBasePrice());
}
return $this;
}
}