<?php declare(strict_types=1);
namespace Albis\AlbisLease\Subscriber;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Shopware\Storefront\Page\Checkout\Offcanvas\OffcanvasCartPageLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class OffcanvasCartPageSubscriber implements EventSubscriberInterface
{
/**
* @var SystemConfigService
*/
private $systemConfigService;
public function __construct(SystemConfigService $systemConfigService)
{
$this->systemConfigService = $systemConfigService;
}
public static function getSubscribedEvents()
{
return [
OffcanvasCartPageLoadedEvent::class => 'onOffcanvasCartPageLoaded',
];
}
public function onOffcanvasCartPageLoaded(OffcanvasCartPageLoadedEvent $event): void
{
$salesChannelId = $event->getContext()->getSource()->getSalesChannelId();
$pluginConfig = $this->systemConfigService->get('AlbisLease.config', $salesChannelId);
if(!$pluginConfig['offcanvasCartDisplay']) {
return;
}
$page = $event->getPage();
$cart = $page->getCart();
$cartAmountGross = $cart->getPrice()->getTotalPrice();
if($cartAmountGross > 500) {
$page->setExtensions([
'alibsPaymentAvailable' => true
]);
}
}
}