builder = $builder; $this->deliveryCalculator = $deliveryCalculator; $this->shippingMethodRepository = $shippingMethodRepository; } public static function buildKey(string $shippingMethodId): string { return 'shipping-method-' . $shippingMethodId; } public function collect(CartDataCollection $data, Cart $original, SalesChannelContext $context, CartBehavior $behavior): void { //$original->addErrors( new ShippingMethodBlockedError((string) "Foobar collect")); /* ensure we have at least one shipping method key to avoid ShippingMethodNotFoundException */ $default_ship = $context->getShippingMethod(); $default_ship_id = $default_ship->getId(); $key = self::buildKey($default_ship_id); $data->set($key, $default_ship); } public function process(CartDataCollection $data, Cart $original, Cart $toCalculate, SalesChannelContext $context, CartBehavior $behavior): void { /* below steps 1:1 from original shopware DeliveryProcessor */ $deliveries = $this->builder->build($toCalculate, $data, $context, $behavior); $delivery = $deliveries->first(); /* custom computation of costs */ $costs = new CalculatedPrice(23, 42, new CalculatedTaxCollection(), new TaxRuleCollection()); $delivery->setShippingCosts($costs); /* below steps 1:1 from original shopware DeliveryProcessor */ $this->deliveryCalculator->calculate($data, $toCalculate, $deliveries, $context); $toCalculate->setDeliveries($deliveries); } }