Appearance
Extending
For developers
Add slot rules: cut-off, lead time, blackouts, capacity
PickupTimeSlotService::isAllowed() is the seam. It is used by both slot generation (what the customer sees) and isBookable() (what checkout accepts), so a rule added there cannot be bypassed by posting a hand-made time.
Decorate the service and override isAllowed():
php
namespace Acme\PickupRules;
use Kommandhub\ClickAndPickSW\Entity\PickupLocation\PickupLocationEntity;
use Kommandhub\ClickAndPickSW\PickupLocation\Availability\PickupTimeSlotService;
final class LeadTimeSlotService extends PickupTimeSlotService
{
protected function isAllowed(PickupLocationEntity $location, \DateTimeImmutable $when): bool
{
// Require two hours of preparation time.
return $when >= new \DateTimeImmutable('+2 hours');
}
}xml
<service id="Acme\PickupRules\LeadTimeSlotService"
decorates="Kommandhub\ClickAndPickSW\PickupLocation\Availability\PickupTimeSlotService">
<argument type="service" id="Kommandhub\ClickAndPickSW\PickupLocation\Availability\PickupLocationAvailabilityService"/>
</service>The constructor takes the availability service and an optional int $slotStepMinutes (default 30) — pass a different value to change the slot length. Check the signatures in the version you extend; the plugin is pre-1.0.
Read an order's pickup data
The record is autoloaded on every order:
php
$pickup = $order->getExtension('kommandhubPickupLocation');
$time = $pickup?->getPickupTime();
$location = $pickup?->getPickupLocation(); // null if the location was deletedTwig: order.extensions.kommandhubPickupLocation.pickupTime.
Reuse services instead of reaching into modules
| Service | Use it to |
|---|---|
PickupLocationSelectionResolver | Turn the current context into a resolved selection (loaded location + parsed time + comment). |
PickupLocationAvailabilityService | Ask whether a location is open at a time or on a date. |
PickupContextStorage | Read, write or clear the in-progress selection. |
OrderPickupLocationWriter | Write an order's pickup record. |
Reuse the flow contracts
PickupLocationAware and OrderPickupLocationAware (with their storers) let your own pickup-related events offer the same flow data and use the plugin's actions.
Template blocks
The checkout shipping-method override and the pickup info card are wrapped in Twig blocks; extend them with sw_extends rather than copying templates. The Administration order tab uses the core sw_order_detail_content_tabs_extension block.