B2Bsellers Suite
API Referenceswww.b2b-sellers.comPublic demoshopRoadmap
v2.X.X+v3.X.X (Shopware 6.5/6.6)
v2.X.X+v3.X.X (Shopware 6.5/6.6)
  • Home
  • Product Tour
    • Plans & Plugin Concept
    • Public Demoshops
    • Get a personal B2B demo store?
    • Changes Made to Customers - What Are Companies, Employees and Sales Representatives
  • User Guide
    • Installation, Setup & Upgrade
      • Installation
      • Upgrade
      • Requirements
      • Easy activate all Addons and Features
      • Use Test-Customers
      • License Settings
      • Common Installation and Upgrade Errors
    • User Documentation (Alpha)
    • Configuration
      • Shop Admin Configurations
      • License, purchaseable Addons and Features configuration
      • E-Mail Templates
      • B2B Flow/Business Events
      • Registration process
      • PDP variant list
    • Configuration of purchasable Addons
      • E-Procurement (OCI-Punchout)
      • E-Procurement (cXML Purchase Order / Ariba)
      • Register Requests (wip)
      • Order Lists
      • URL Authentication
    • Performance
    • FAQs
    • Support Lifecycle & Release Strategy
    • Customer Support
  • Using HTTP Cache for Logged-In Users
  • Developer Guides
    • First Steps
      • Getting Started
      • Concept of Extensions
      • Dockware Setup (Docker)
      • How to start the b2b-platform vue.js watcher
      • How to build the b2b-platform (vue.js)
      • How to extend the B2B Platform (Storefront Vue.js)
      • Protection of the Store-API
      • How to develop your first extensions
      • CLI-Commands
        • Migration of existing Shopware Customers
      • Frosh Shopware-CLI Admin-Watcher
      • Cronjobs
      • Development Helpers
      • Example Plugins
    • Smart developer helpers
      • B2bPlatformContext
      • B2bContextTrait
      • EmployeePermissionTrait
      • B2B Body Classes
      • UseCustomer URL Parameter
      • Useful Vue.js Components for the B2B Platform
      • Useful Storefront Shopping World Elements
      • How to import external orders and offers?
    • How to's
      • Using B2Bsellers Suite with Shopware frontends
      • Add or remove subscription intervals
      • Add additional data to the order confirmation mail
    • Guides for ERP-Interface
      • Overview - Full integrated ERP-Systems
      • Integration of ERP orders to Shopware 6
      • Integration Customers and Employees from ERP
    • Tips for Deployment / Continuous Integration
    • Typical errors
  • API-References
    • Database Schema
    • Entities
      • Custom Fields for existing Shopware Entities
      • Budget
      • BudgetEmployee
      • CollectionAccount
      • CustomerPrice
      • Employee
        • EmployeeCustomer
        • EmployeePermission
        • EmployeeRole
      • CustomerActivity
        • CustomerActivityType
      • Offer
        • OfferAddress
        • OfferCustomer
        • OfferItem
        • OfferStatus
      • ProductSubscription
      • ProductSubscriptionOrder
      • PasswordlessLogin
      • PaymentCondition
      • ProductExplodedView
      • B2bProductList
        • B2bProductListItem
        • B2bProductListType
      • RegisterRequest
        • RegisterRequestStatus
        • RegisterRequestActivity
      • SalesRepresentativeCustomer
    • Store API
    • Store-API
      • Account Request
      • Customer Activity
      • Customer Activity Type
      • Customer Last Orders
      • Customer List
      • Customer Price
      • Customer Sales Ranking
      • Customer Search
      • Delivery Interval
      • Delete Product Subscription
      • Document
      • Employee
      • Employee Permission
      • Employee Role
      • Employee Order
      • Login Target List
      • Offer Document
      • Offer
      • Offer Mail
      • Offer Order
      • Offer Status
      • Ordered Products
      • Platform Cms
      • Product List
      • Product Table Listing
      • Product Subscription
      • Product Subscription List
      • Sales Statistic
      • Snippet
    • Admin API
      • General Admin-API Info
      • Order Extension
  • Release Notes
    • B2BsellersCore
      • Version v3.x.x
        • Version v3.3.2
        • Version v3.3.1
        • Version v3.3.0
        • Version v3.2.2
        • Version v3.2.1
        • Version v3.2.0
        • Version v3.1.6
        • Version v3.1.5
        • Version v3.1.4
        • Version v3.1.3
        • Version v3.1.2
        • Version v3.1.1
        • Version v3.1.0
        • Version v3.0.3
        • Version v3.0.2
        • Version v3.0.1
        • Version v3.0.0
      • Version v2.x.x
        • Version v2.4.2
        • Version v2.4.1
        • Version v2.4.0
        • Version v2.3.6
        • Version v2.3.5
        • Version v2.3.4
        • Version v2.3.3
        • Version v2.3.2
        • Version v2.3.1
        • Version v2.3.0
        • Version v2.2.6
        • Version v2.2.5
        • Version v2.2.4
        • Version v2.2.3
        • Version v2.2.2
        • Version v2.2.1
        • Version v2.2.0
        • Version v2.1.2
        • Version v2.1.1
        • Version v2.1.0
        • Version v2.0.2
        • Version v2.0.1
        • Version v2.0.0
      • Version v1.x.x
        • Version v1.1.8
        • Version v1.1.7
        • Version v1.1.6
        • Version v1.1.5
        • Version v1.1.4 - security update
        • Version v1.1.3
        • Version v1.1.2
        • Version v1.1.1
        • Version v1.1.0
        • Version v1.0.4
        • Version v1.0.3
        • Version v1.0.2
        • Version v1.0.1 - Hotfix
        • Version v1.0.0
      • Version v0.x.x (beta)
        • Version v0.9.6
        • Version v0.9.5
        • Version v0.9.4
        • Version v0.9.3
        • Version v0.9.2
        • Version v0.9.1
  • Help
    • Core Settings
      • Permanent Shopping Cart Settings Changes April 2024
Powered by GitBook
On this page
  • Adding or removing intervals
  • Providing a processor for custom intervals

Was this helpful?

  1. Developer Guides
  2. How to's

Add or remove subscription intervals

Subscription intervals can be added and removed by using the DeliveryIntervalCollectorEvent.

Adding or removing intervals

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

// <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.

// <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;
    }
}
<!-- <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>

Last updated 1 year ago

Was this helpful?