> For the complete documentation index, see [llms.txt](https://docs.b2b-sellers.com/b2b-platform/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.b2b-sellers.com/b2b-platform/2/developer-guides/how-tos/add-or-remove-subscription-intervals.md).

# Add or remove subscription intervals

### Adding or removing intervals

Subscription intervals can be added or removed via an event subscriber that listens to the `DeliveryIntervalCollectorEvent`

```php
// <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

If you add a new subscription interval, a corresponding processor for calculating the next delivery/order date must also be available.

The processor must implement the `IntervalProcessorInterface` and must be registered as a service via the `b2b_product_subscription.interval.processor` tag.

```php
// <plugin root>/src/ProductSubscription/DeliveryInterval/Processor/CustomIntervalProcessor .php

namespace B2bSellersExample\ProductSubscription\DeliveryInterval\Processor;

class CustomIntervalProcessor implements IntervalProcessorInterface
{
    public const DELIVERY_KEY = 'custom';

    public function isSupported(string $key)
    {
        return self::DELIVERY_KEY === $key;
    }

    public function process(\DateTimeInterface $lastOrderDate, ?\DateTimeInterface $result)
    {
        $dateTime = new \DateTime($lastOrderDate->format('Y-m-d'));

        // Calculate your next delivery/order date
        // Example: $dateTime->add(new \DateInterval('P5M'));

        return $dateTime;
    }
}
```

```xml
<!-- <plugin root>/src/Resources/config/services.xml -->

<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
    <services>
           <service id="B2bSellersExample\ProductSubscription\DeliveryInterval\Processor\CustomIntervalProcessor">
            <tag name="b2b_product_subscription.interval.processor"/>
        </service>
    </services>
</container>
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.b2b-sellers.com/b2b-platform/2/developer-guides/how-tos/add-or-remove-subscription-intervals.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
