Add or remove subscription intervals
Subscription intervals can be added and removed by using the DeliveryIntervalCollectorEvent.
Adding or removing intervals
// <plugin root>/src/Subscriber/DeliveryIntervalSubscriber.php
namespace B2bSellersExample\Subscriber;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use B2bProductSubscription\Components\ProductSubscription\Events\DeliveryIntervalCollectorEvent;
use Symfony\Contracts\Translation\TranslatorInterface;
class DeliveryIntervalSubscriber implements EventSubscriberInterface
{
public function __construct(
private readonly TranslatorInterface $translator
)
{}
public static function getSubscribedEvents(): array
{
return [
DeliveryIntervalCollectorEvent::class=> 'onChangeDeliveryIntervals'
];
}
public function onChangeDeliveryIntervals(DeliveryIntervalCollectorEvent $event)
{
$collection = $event->getCollection();
// removing the weekly interval option
$collection->remove('weekly');
// Adding your custom interval
$key = 'custom';
$collection->set($key, new DeliveryIntervalStruct(
$key,
$this->translator->trans('b2bProductSubscription.interval.' . $key),
'b2bProductSubscription.interval.' . $key
));
}
}Providing a processor for custom intervals
Last updated
Was this helpful?