I have implemented a BeforeLineItemAddedEvent subscriber event, but it’s not getting called. ProductPageLoadedEvent is called properly but BeforeLineItemAddedEvent or AfterLineItemAddedEvent is not called Can anyone let me know what’s wrong with this
here is my Subscriber class:
<?php
namespace KiranPlugin\Subscriber;
use Shopware\Core\Checkout\Cart\Event\BeforeLineItemAddedEvent;
use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
use Shopware\Core\Checkout\Cart\Event\AfterLineItemAddedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class KiranSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
BeforeLineItemAddedEvent::class => 'beforeLineItemAdded',
ProductPageLoadedEvent::class => 'onProductPageLoaded',
AfterLineItemAddedEvent::class => 'onLineItemAdded',
];
}
public function onLineItemAdded(AfterLineItemAddedEvent $event)
{
echo 1;
error_log('onLineItemAdded');
}
public function beforeLineItemAdded(BeforeLineItemAddedEvent $event)
{
echo 'test';
$mylineitems = $event->getCart()->getLineItems();
error_log('beforeLineItemAdded');
}
/**
* Handles the stuff, that happens on the product detail page
*
* @param ProductPageLoadedEvent $event
*/
public function onProductPageLoaded (ProductPageLoadedEvent $event)
{
echo $sqlQuery = "SELECT * FROM `product`";