diff --git a/SmcShipcloudLive/composer.json b/SmcShipcloudLive/composer.json index d972da5..730e33b 100644 --- a/SmcShipcloudLive/composer.json +++ b/SmcShipcloudLive/composer.json @@ -1,8 +1,18 @@ { - "name": "swag/plugin-skeleton", - "description": "Skeleton plugin", + "name": "sysmocom/shopware6-shipcloud-live", + "description": "shipcloud live quote pluging", + "version": "0.0.1", "type": "shopware-platform-plugin", - "license": "MIT", + "license": "AGPL-3.0-or-later", + "authors": [ + { + "name": "Harald Welte", + "role": "main developer" + } + ], + "require": { + "shopware/core": "^6." + }, "autoload": { "psr-4": { "SmcShipcloudLive\\": "src/" @@ -11,8 +21,8 @@ "extra": { "shopware-plugin-class": "SmcShipcloudLive\\SmcShipcloudLive", "label": { - "de-DE": "Skeleton plugin", - "en-GB": "Skeleton plugin" + "de-DE": "shipcloud live quote plugin", + "en-GB": "shipcloud live quote plugin" } } } diff --git a/SmcShipcloudLive/src/Core/Checkout/Cart/Delivery/SmcDeliveryCalculator.php b/SmcShipcloudLive/src/Core/Checkout/Cart/Delivery/SmcDeliveryCalculator.php new file mode 100644 index 0000000..aef257b --- /dev/null +++ b/SmcShipcloudLive/src/Core/Checkout/Cart/Delivery/SmcDeliveryCalculator.php @@ -0,0 +1,52 @@ +priceCalculator = $priceCalculator; + $this->percentageTaxRuleBuilder = $percentageTaxRuleBuilder; + } + + public function calculate(CartDataCollection $data, Cart $cart, DeliveryCollection $deliveries, SalesChannelContext $context): void + { + foreach ($deliveries as $delivery) { + //$this->calculateDelivery($data, $cart, $delivery, $context); + $costs = $this->calculateShippingCosts($delivery->getShippingMethod(), + new PriceCollection([new Price(Defaults::CURRENCY, 23, 0, false)]), + $delivery->getPositions()->getLineItems(), + $context); + $delivery->setShippingCosts($costs); + } + } +} diff --git a/SmcShipcloudLive/src/Core/Checkout/Cart/Delivery/SmcDeliveryProcessor.php b/SmcShipcloudLive/src/Core/Checkout/Cart/Delivery/SmcDeliveryProcessor.php new file mode 100644 index 0000000..17f1ec2 --- /dev/null +++ b/SmcShipcloudLive/src/Core/Checkout/Cart/Delivery/SmcDeliveryProcessor.php @@ -0,0 +1,65 @@ +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); + } +} diff --git a/SmcShipcloudLive/src/Resources/config/config.xml b/SmcShipcloudLive/src/Resources/config/config.xml index da37fea..78e03ca 100644 --- a/SmcShipcloudLive/src/Resources/config/config.xml +++ b/SmcShipcloudLive/src/Resources/config/config.xml @@ -10,5 +10,20 @@ + + + apiKey + + + + sandboxApiKey + + + + useSandbox + + true + + - \ No newline at end of file + diff --git a/SmcShipcloudLive/src/Resources/config/services.xml b/SmcShipcloudLive/src/Resources/config/services.xml index b0a1dc7..90c49ff 100644 --- a/SmcShipcloudLive/src/Resources/config/services.xml +++ b/SmcShipcloudLive/src/Resources/config/services.xml @@ -6,5 +6,37 @@ + + + + + + + + + + + + + + + + + + + + - \ No newline at end of file +