Skip to main content
Version: 2024.1

Working with Availabilities

For availabilities there is a similar concepts like the PriceSystems for prices - which is called Availability Systems.

The Availability Systems are responsible for retrieving or calculating availabilities of a product and returning a so called AvailabilityInfo object which contains all the availability information. Each product can have its own Availability System.

Configuration of Availability Systems

An availability system is a class implementing Pimcore\Bundle\EcommerceFrameworkBundle\AvailabilitySystem\AvailabilitySystemInterface which is defined as service and registered with a name in the pimcore_ecommerce_framework.availability_systems configuration tree.

Currently, the framework ships only with a sample implementation which you can use as starting point.

There are 3 places where the configuration of Availability Systems takes place:

  • Product class: Each product has to implement the method getAvailabilitySystemName() which returns the name of its Availability System.
  • Service definition: Each Availability System must be registered as service
  • Configuration: The availability_systems section maps Availability System names to service IDs

The product class returns the name of an Availability System:

<?php

class MyProduct implements \Pimcore\Bundle\EcommerceFrameworkBundle\Model\CheckoutableInterface
{
public function getAvailabilitySystemName(): string
{
return 'myAvailabilitySystem';
}
}

Each Availability System must be defined as service (either a service defined by core configuration or your custom services):

# services.yaml
_defaults:
public: false
autowire: true
autoconfigure: true

#
# AVAILABILITY SYSTEMS
#
Pimcore\Bundle\EcommerceFrameworkBundle\AvailabilitySystem\AvailabilitySystem: ~

The availability_systems configuration maps names to service IDs:

pimcore_ecommerce_framework:
# defines 3 availability systems
availability_systems:
# the availability system is already defined in core availability_systems.yaml service definition
default:
id: Pimcore\Bundle\EcommerceFrameworkBundle\AvailabilitySystem\AvailabilitySystem

foo:
id: App\Ecommerce\AvailabilitySystem\CustomAvailabilitySystem

bar:
id: app.custom_attribute_availability_system

Getting Availabilities

Each product (if it implements CheckoutableInterface) needs to implement the method getOSAvailabilityInfo which in the default implementation gets the corresponding Availability System and calculates the availability.

The return value is an AvailabilityInterface object, which at least has one getAvailable method and can contain additional availability information (e.g. availability for different storage locations etc.).

This can be used to visualize availability on product detail pages or to check, if a product can actually be checked out.