PHP code example of thelia / order-minimum-amount-module
1. Go to this page and download the library: Download thelia/order-minimum-amount-module 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/ */
thelia / order-minimum-amount-module example snippets
namespace MyModule\EventListener;
use OrderMinimumAmount\Event\CustomerMinimumAmountEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
final readonly class CustomerMinimumAmountListener implements EventSubscriberInterface
{
public function __construct(private CustomerMinimumRepository $repository)
{
}
public static function getSubscribedEvents(): array
{
return [CustomerMinimumAmountEvent::NAME => ['onCustomerMinimumAmount', 128]];
}
public function onCustomerMinimumAmount(CustomerMinimumAmountEvent $event): void
{
// $event->customer, $event->cart, $event->globalMinimumAmount ("250.00")
$minimumAmount = $this->repository->minimumOf($event->customer->getId()); // "180.50" or null
if (null !== $minimumAmount) {
$event->setMinimumAmount($minimumAmount);
}
}
}
php bin/console order-minimum-amount:configure --amount=250 --taxes=excluded
php bin/console order-minimum-amount:configure # prints the current settings