PHP code example of setono / sylius-abandoned-cart-plugin

1. Go to this page and download the library: Download setono/sylius-abandoned-cart-plugin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

setono / sylius-abandoned-cart-plugin example snippets



// config/bundles.php

return [
    // ...
    Setono\SyliusAbandonedCartPlugin\SetonoSyliusAbandonedCartPlugin::class => ['all' => true],
    Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
    // ...
];



declare(strict_types=1);

namespace App\EligibilityChecker;

use Setono\SyliusAbandonedCartPlugin\EligibilityChecker\EligibilityCheck;
use Setono\SyliusAbandonedCartPlugin\EligibilityChecker\NotificationEligibilityCheckerInterface;
use Setono\SyliusAbandonedCartPlugin\Model\NotificationInterface;

final class MinimumCartTotalEligibilityChecker implements NotificationEligibilityCheckerInterface
{
    public function check(NotificationInterface $notification): EligibilityCheck
    {
        $cart = $notification->getCart();

        if (null === $cart || $cart->getTotal() < 5000) {
            // The reason is stored on the notification for debugging.
            return new EligibilityCheck(false, 'Cart total is below the minimum');
        }

        return new EligibilityCheck(true);
    }
}



declare(strict_types=1);

namespace App\EventListener;

use Setono\SyliusAbandonedCartPlugin\Event\QueryBuilderForIdleCartsCreated;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

#[AsEventListener]
final class OnlyNotifyMainChannelListener
{
    public function __invoke(QueryBuilderForIdleCartsCreated $event): void
    {
        $event->queryBuilder
            ->andWhere('o.channel = :channel')
            ->setParameter('channel', 1);
    }
}