From 5e098a62e6574af477fbc5c5944c1d1ad44af218 Mon Sep 17 00:00:00 2001 From: mandan2 Date: Mon, 25 Sep 2023 17:47:28 +0300 Subject: [PATCH 1/3] PIPRES-261: Get carrier price to create subscription --- .../CouldNotProvideCarrierDeliveryPrice.php | 62 +++++++ .../Provider/CarrierDeliveryPriceProvider.php | 122 ++++++++++++++ .../CarrierDeliveryPriceProviderTest.php | 159 ++++++++++++++++++ 3 files changed, 343 insertions(+) create mode 100644 subscription/Exception/CouldNotProvideCarrierDeliveryPrice.php create mode 100644 subscription/Provider/CarrierDeliveryPriceProvider.php create mode 100644 tests/Integration/Subscription/Provider/CarrierDeliveryPriceProviderTest.php diff --git a/subscription/Exception/CouldNotProvideCarrierDeliveryPrice.php b/subscription/Exception/CouldNotProvideCarrierDeliveryPrice.php new file mode 100644 index 000000000..c6f20a9e4 --- /dev/null +++ b/subscription/Exception/CouldNotProvideCarrierDeliveryPrice.php @@ -0,0 +1,62 @@ +configuration = $configuration; + $this->carrierRepository = $carrierRepository; + $this->addressRepository = $addressRepository; + $this->customerRepository = $customerRepository; + $this->cartRepository = $cartRepository; + $this->countryRepository = $countryRepository; + } + + /** + * @throws CouldNotProvideCarrierDeliveryPrice + */ + public function getPrice(int $addressDeliveryId, int $cartId, int $customerId, array $subscriptionProduct): float + { + $subscriptionCarrierId = (int) $this->configuration->get(Config::MOLLIE_SUBSCRIPTION_ORDER_CARRIER_ID); + + /** @var \Carrier|null $carrier */ + $carrier = $this->carrierRepository->findOneBy([ + 'id_carrier' => $subscriptionCarrierId, + ]); + + if (!$carrier) { + throw CouldNotProvideCarrierDeliveryPrice::failedToFindSelectedCarrierForSubscriptionOrder(); + } + + /** @var \Cart|null $cart */ + $cart = $this->cartRepository->findOneBy([ + 'id_cart' => $cartId, + ]); + + if (!$cart) { + throw CouldNotProvideCarrierDeliveryPrice::failedToFindOrderCart(); + } + + /** @var \Customer|null $customer */ + $customer = $this->customerRepository->findOneBy([ + 'id_customer' => $customerId, + ]); + + if (!$customer) { + throw CouldNotProvideCarrierDeliveryPrice::failedToFindOrderCustomer(); + } + + $getAvailableOrderCarriers = $this->carrierRepository->getCarriersForOrder( + $this->addressRepository->getZoneById($addressDeliveryId), + $customer->getGroups(), + $cart + ); + + if (!in_array($subscriptionCarrierId, array_column($getAvailableOrderCarriers, 'id_carrier'), false)) { + throw CouldNotProvideCarrierDeliveryPrice::failedToApplySelectedCarrierForSubscriptionOrder(); + } + + /** @var \Address|bool $address */ + $address = $this->addressRepository->findOneBy([ + 'id_address' => $addressDeliveryId, + ]); + + if (!$address) { + throw CouldNotProvideCarrierDeliveryPrice::failedToFindOrderDeliveryAddress(); + } + + /** @var \Country|bool $country */ + $country = $this->countryRepository->findOneBy([ + 'id_country' => $address->id_country, + ]); + + if (!$country) { + throw CouldNotProvideCarrierDeliveryPrice::failedToFindOrderDeliveryCountry(); + } + + /** @var float|bool $deliveryPrice */ + $deliveryPrice = $cart->getPackageShippingCost( + $subscriptionCarrierId, + true, + $country, + [$subscriptionProduct], + $this->addressRepository->getZoneById($addressDeliveryId) + ); + + if (is_bool($deliveryPrice) && !$deliveryPrice) { + throw CouldNotProvideCarrierDeliveryPrice::failedToGetSelectedCarrierPriceForSubscriptionOrder(); + } + + return (float) $deliveryPrice; + } +} diff --git a/tests/Integration/Subscription/Provider/CarrierDeliveryPriceProviderTest.php b/tests/Integration/Subscription/Provider/CarrierDeliveryPriceProviderTest.php new file mode 100644 index 000000000..bf8e5416c --- /dev/null +++ b/tests/Integration/Subscription/Provider/CarrierDeliveryPriceProviderTest.php @@ -0,0 +1,159 @@ +getService(ConfigurationAdapter::class); + + $this->subscriptionOrderCarrierId = $configuration->get(Config::MOLLIE_SUBSCRIPTION_ORDER_CARRIER_ID); + + parent::setUp(); + } + + public function tearDown(): void + { + /** @var ConfigurationAdapter $configuration */ + $configuration = $this->getService(ConfigurationAdapter::class); + + $configuration->updateValue(Config::MOLLIE_SUBSCRIPTION_ORDER_CARRIER_ID, $this->subscriptionOrderCarrierId); + + parent::tearDown(); + } + + public function testItSuccessfullyProvidesCarrierDeliveryPrice(): void + { + $address = AddressFactory::create(); + $carrier = CarrierFactory::create([ + 'price' => 999.00, + ]); + $cart = CartFactory::create([ + 'id_carrier' => $carrier->id, + ]); + + /** @var ConfigurationAdapter $configuration */ + $configuration = $this->getService(ConfigurationAdapter::class); + + $configuration->updateValue(Config::MOLLIE_SUBSCRIPTION_ORDER_CARRIER_ID, $carrier->id); + + $targetProduct = ProductFactory::create([ + 'quantity' => 10, + ]); + $product1 = ProductFactory::create([ + 'quantity' => 10, + ]); + $product2 = ProductFactory::create([ + 'quantity' => 10, + ]); + + $cart->updateQty(2, $targetProduct->id); + + $targetProductArray = $cart->getProducts()[0]; + + $cart->updateQty(2, $product1->id); + $cart->updateQty(3, $product2->id); + + /** @var CarrierDeliveryPriceProvider $carrierDeliveryPriceProvider */ + $carrierDeliveryPriceProvider = $this->getService(CarrierDeliveryPriceProvider::class); + + $result = $carrierDeliveryPriceProvider->getPrice( + $address->id, + $cart->id, + $cart->id_customer, + $targetProductArray + ); + + $this->assertEquals(999.00, $result); + + $this->removeFactories([ + $carrier, + $address, + $cart, + $targetProduct, + $product1, + $product2, + ]); + } + + public function testItUnsuccessfullyProvidesCarrierDeliveryPriceCarrierIsOutOfZone(): void + { + $address = AddressFactory::create(); + $carrier = CarrierFactory::create([ + 'price' => 999.00, + 'id_zones_to_delete' => [ + $address::getZoneById($address->id), + ], + ]); + $cart = CartFactory::create([ + 'id_carrier' => $carrier->id, + ]); + + /** @var ConfigurationAdapter $configuration */ + $configuration = $this->getService(ConfigurationAdapter::class); + + $configuration->updateValue(Config::MOLLIE_SUBSCRIPTION_ORDER_CARRIER_ID, $carrier->id); + + $targetProduct = ProductFactory::create([ + 'quantity' => 10, + ]); + $product1 = ProductFactory::create([ + 'quantity' => 10, + ]); + $product2 = ProductFactory::create([ + 'quantity' => 10, + ]); + + $cart->updateQty(2, $targetProduct->id); + + $targetProductArray = $cart->getProducts()[0]; + + $cart->updateQty(2, $product1->id); + $cart->updateQty(3, $product2->id); + + $this->expectException(CouldNotProvideCarrierDeliveryPrice::class); + $this->expectExceptionCode(ExceptionCode::ORDER_FAILED_TO_APPLY_SELECTED_CARRIER_FOR_SUBSCRIPTION_ORDER); + + /** @var CarrierDeliveryPriceProvider $carrierDeliveryPriceProvider */ + $carrierDeliveryPriceProvider = $this->getService(CarrierDeliveryPriceProvider::class); + + $carrierDeliveryPriceProvider->getPrice( + $address->id, + $cart->id, + $cart->id_customer, + $targetProductArray + ); + + $this->removeFactories([ + $carrier, + $address, + $cart, + $targetProduct, + $product1, + $product2, + ]); + } + + /** + * @param \ObjectModel[] $objects + */ + private function removeFactories(array $objects): void + { + foreach ($objects as $object) { + $object->delete(); + } + } +} From 96041d935ecb3caf2beeadab83824b61d7aa2a4a Mon Sep 17 00:00:00 2001 From: mandan2 Date: Tue, 26 Sep 2023 13:45:46 +0300 Subject: [PATCH 2/3] renamed some services and added additional conditions for carrier retrieve --- .../CouldNotProvideCarrierDeliveryPrice.php | 62 ------- .../Provider/CarrierDeliveryPriceProvider.php | 122 -------------- .../CarrierDeliveryPriceProviderTest.php | 159 ------------------ 3 files changed, 343 deletions(-) delete mode 100644 subscription/Exception/CouldNotProvideCarrierDeliveryPrice.php delete mode 100644 subscription/Provider/CarrierDeliveryPriceProvider.php delete mode 100644 tests/Integration/Subscription/Provider/CarrierDeliveryPriceProviderTest.php diff --git a/subscription/Exception/CouldNotProvideCarrierDeliveryPrice.php b/subscription/Exception/CouldNotProvideCarrierDeliveryPrice.php deleted file mode 100644 index c6f20a9e4..000000000 --- a/subscription/Exception/CouldNotProvideCarrierDeliveryPrice.php +++ /dev/null @@ -1,62 +0,0 @@ -configuration = $configuration; - $this->carrierRepository = $carrierRepository; - $this->addressRepository = $addressRepository; - $this->customerRepository = $customerRepository; - $this->cartRepository = $cartRepository; - $this->countryRepository = $countryRepository; - } - - /** - * @throws CouldNotProvideCarrierDeliveryPrice - */ - public function getPrice(int $addressDeliveryId, int $cartId, int $customerId, array $subscriptionProduct): float - { - $subscriptionCarrierId = (int) $this->configuration->get(Config::MOLLIE_SUBSCRIPTION_ORDER_CARRIER_ID); - - /** @var \Carrier|null $carrier */ - $carrier = $this->carrierRepository->findOneBy([ - 'id_carrier' => $subscriptionCarrierId, - ]); - - if (!$carrier) { - throw CouldNotProvideCarrierDeliveryPrice::failedToFindSelectedCarrierForSubscriptionOrder(); - } - - /** @var \Cart|null $cart */ - $cart = $this->cartRepository->findOneBy([ - 'id_cart' => $cartId, - ]); - - if (!$cart) { - throw CouldNotProvideCarrierDeliveryPrice::failedToFindOrderCart(); - } - - /** @var \Customer|null $customer */ - $customer = $this->customerRepository->findOneBy([ - 'id_customer' => $customerId, - ]); - - if (!$customer) { - throw CouldNotProvideCarrierDeliveryPrice::failedToFindOrderCustomer(); - } - - $getAvailableOrderCarriers = $this->carrierRepository->getCarriersForOrder( - $this->addressRepository->getZoneById($addressDeliveryId), - $customer->getGroups(), - $cart - ); - - if (!in_array($subscriptionCarrierId, array_column($getAvailableOrderCarriers, 'id_carrier'), false)) { - throw CouldNotProvideCarrierDeliveryPrice::failedToApplySelectedCarrierForSubscriptionOrder(); - } - - /** @var \Address|bool $address */ - $address = $this->addressRepository->findOneBy([ - 'id_address' => $addressDeliveryId, - ]); - - if (!$address) { - throw CouldNotProvideCarrierDeliveryPrice::failedToFindOrderDeliveryAddress(); - } - - /** @var \Country|bool $country */ - $country = $this->countryRepository->findOneBy([ - 'id_country' => $address->id_country, - ]); - - if (!$country) { - throw CouldNotProvideCarrierDeliveryPrice::failedToFindOrderDeliveryCountry(); - } - - /** @var float|bool $deliveryPrice */ - $deliveryPrice = $cart->getPackageShippingCost( - $subscriptionCarrierId, - true, - $country, - [$subscriptionProduct], - $this->addressRepository->getZoneById($addressDeliveryId) - ); - - if (is_bool($deliveryPrice) && !$deliveryPrice) { - throw CouldNotProvideCarrierDeliveryPrice::failedToGetSelectedCarrierPriceForSubscriptionOrder(); - } - - return (float) $deliveryPrice; - } -} diff --git a/tests/Integration/Subscription/Provider/CarrierDeliveryPriceProviderTest.php b/tests/Integration/Subscription/Provider/CarrierDeliveryPriceProviderTest.php deleted file mode 100644 index bf8e5416c..000000000 --- a/tests/Integration/Subscription/Provider/CarrierDeliveryPriceProviderTest.php +++ /dev/null @@ -1,159 +0,0 @@ -getService(ConfigurationAdapter::class); - - $this->subscriptionOrderCarrierId = $configuration->get(Config::MOLLIE_SUBSCRIPTION_ORDER_CARRIER_ID); - - parent::setUp(); - } - - public function tearDown(): void - { - /** @var ConfigurationAdapter $configuration */ - $configuration = $this->getService(ConfigurationAdapter::class); - - $configuration->updateValue(Config::MOLLIE_SUBSCRIPTION_ORDER_CARRIER_ID, $this->subscriptionOrderCarrierId); - - parent::tearDown(); - } - - public function testItSuccessfullyProvidesCarrierDeliveryPrice(): void - { - $address = AddressFactory::create(); - $carrier = CarrierFactory::create([ - 'price' => 999.00, - ]); - $cart = CartFactory::create([ - 'id_carrier' => $carrier->id, - ]); - - /** @var ConfigurationAdapter $configuration */ - $configuration = $this->getService(ConfigurationAdapter::class); - - $configuration->updateValue(Config::MOLLIE_SUBSCRIPTION_ORDER_CARRIER_ID, $carrier->id); - - $targetProduct = ProductFactory::create([ - 'quantity' => 10, - ]); - $product1 = ProductFactory::create([ - 'quantity' => 10, - ]); - $product2 = ProductFactory::create([ - 'quantity' => 10, - ]); - - $cart->updateQty(2, $targetProduct->id); - - $targetProductArray = $cart->getProducts()[0]; - - $cart->updateQty(2, $product1->id); - $cart->updateQty(3, $product2->id); - - /** @var CarrierDeliveryPriceProvider $carrierDeliveryPriceProvider */ - $carrierDeliveryPriceProvider = $this->getService(CarrierDeliveryPriceProvider::class); - - $result = $carrierDeliveryPriceProvider->getPrice( - $address->id, - $cart->id, - $cart->id_customer, - $targetProductArray - ); - - $this->assertEquals(999.00, $result); - - $this->removeFactories([ - $carrier, - $address, - $cart, - $targetProduct, - $product1, - $product2, - ]); - } - - public function testItUnsuccessfullyProvidesCarrierDeliveryPriceCarrierIsOutOfZone(): void - { - $address = AddressFactory::create(); - $carrier = CarrierFactory::create([ - 'price' => 999.00, - 'id_zones_to_delete' => [ - $address::getZoneById($address->id), - ], - ]); - $cart = CartFactory::create([ - 'id_carrier' => $carrier->id, - ]); - - /** @var ConfigurationAdapter $configuration */ - $configuration = $this->getService(ConfigurationAdapter::class); - - $configuration->updateValue(Config::MOLLIE_SUBSCRIPTION_ORDER_CARRIER_ID, $carrier->id); - - $targetProduct = ProductFactory::create([ - 'quantity' => 10, - ]); - $product1 = ProductFactory::create([ - 'quantity' => 10, - ]); - $product2 = ProductFactory::create([ - 'quantity' => 10, - ]); - - $cart->updateQty(2, $targetProduct->id); - - $targetProductArray = $cart->getProducts()[0]; - - $cart->updateQty(2, $product1->id); - $cart->updateQty(3, $product2->id); - - $this->expectException(CouldNotProvideCarrierDeliveryPrice::class); - $this->expectExceptionCode(ExceptionCode::ORDER_FAILED_TO_APPLY_SELECTED_CARRIER_FOR_SUBSCRIPTION_ORDER); - - /** @var CarrierDeliveryPriceProvider $carrierDeliveryPriceProvider */ - $carrierDeliveryPriceProvider = $this->getService(CarrierDeliveryPriceProvider::class); - - $carrierDeliveryPriceProvider->getPrice( - $address->id, - $cart->id, - $cart->id_customer, - $targetProductArray - ); - - $this->removeFactories([ - $carrier, - $address, - $cart, - $targetProduct, - $product1, - $product2, - ]); - } - - /** - * @param \ObjectModel[] $objects - */ - private function removeFactories(array $objects): void - { - foreach ($objects as $object) { - $object->delete(); - } - } -} From cc45938fe119a52836b6718423211ef0389aca3c Mon Sep 17 00:00:00 2001 From: mandan2 Date: Mon, 2 Oct 2023 13:34:30 +0300 Subject: [PATCH 3/3] PIPRES-261: Minor improvements --- src/Builder/FormBuilder.php | 10 +++--- .../CouldNotCreateOrderPaymentFee.php | 2 +- src/Exception/CouldNotInstallModule.php | 2 +- src/Exception/CouldNotUpdateOrderTotals.php | 2 +- .../CouldNotHandleOrderPaymentFee.php | 8 ++--- .../CouldNotHandleRecurringOrder.php | 4 +-- .../Exception/CouldNotPresentOrderDetail.php | 8 ++--- ...rovideSubscriptionCarrierDeliveryPrice.php | 14 ++++---- .../Handler/RecurringOrderHandler.php | 6 ++-- .../Subscription/subscriptions-faq.html.twig | 36 +++++++++---------- .../customerRecurringOrderDetailProduct.tpl | 18 +++++----- 11 files changed, 54 insertions(+), 56 deletions(-) diff --git a/src/Builder/FormBuilder.php b/src/Builder/FormBuilder.php index 5f77b946b..111c9f83f 100644 --- a/src/Builder/FormBuilder.php +++ b/src/Builder/FormBuilder.php @@ -845,12 +845,10 @@ private function getShippingOptions(string $tab): array ]; foreach ($carriers as $carrier) { - $mappedCarrier = []; - - $mappedCarrier['id'] = $carrier->id; - $mappedCarrier['name'] = $carrier->name; - - $mappedCarriers[] = $mappedCarrier; + $mappedCarriers[] = [ + 'id' => $carrier->id, + 'name' => $carrier->name, + ]; } $header = [ diff --git a/src/Exception/CouldNotCreateOrderPaymentFee.php b/src/Exception/CouldNotCreateOrderPaymentFee.php index dd7919550..0ac620f71 100644 --- a/src/Exception/CouldNotCreateOrderPaymentFee.php +++ b/src/Exception/CouldNotCreateOrderPaymentFee.php @@ -7,7 +7,7 @@ class CouldNotCreateOrderPaymentFee extends MollieException { - public static function failedToInsertOrderPaymentFee(Exception $exception): CouldNotCreateOrderPaymentFee + public static function failedToInsertOrderPaymentFee(Exception $exception): self { return new self( 'Failed to insert order payment fee.', diff --git a/src/Exception/CouldNotInstallModule.php b/src/Exception/CouldNotInstallModule.php index 9ff488ae8..c9fd4b06c 100644 --- a/src/Exception/CouldNotInstallModule.php +++ b/src/Exception/CouldNotInstallModule.php @@ -6,7 +6,7 @@ class CouldNotInstallModule extends MollieException { - public static function failedToInstallOrderState(string $orderStateName, \Exception $exception): CouldNotInstallModule + public static function failedToInstallOrderState(string $orderStateName, \Exception $exception): self { return new self( sprintf('Failed to install order state (%s).', $orderStateName), diff --git a/src/Exception/CouldNotUpdateOrderTotals.php b/src/Exception/CouldNotUpdateOrderTotals.php index 6c8625bbc..69bda3404 100644 --- a/src/Exception/CouldNotUpdateOrderTotals.php +++ b/src/Exception/CouldNotUpdateOrderTotals.php @@ -7,7 +7,7 @@ class CouldNotUpdateOrderTotals extends MollieException { - public static function failedToUpdateOrderTotals(Exception $exception): CouldNotUpdateOrderTotals + public static function failedToUpdateOrderTotals(Exception $exception): self { return new self( 'Failed to update order totals.', diff --git a/src/Handler/Exception/CouldNotHandleOrderPaymentFee.php b/src/Handler/Exception/CouldNotHandleOrderPaymentFee.php index cab968358..077c1f55a 100644 --- a/src/Handler/Exception/CouldNotHandleOrderPaymentFee.php +++ b/src/Handler/Exception/CouldNotHandleOrderPaymentFee.php @@ -8,7 +8,7 @@ class CouldNotHandleOrderPaymentFee extends MollieException { - public static function failedToRetrievePaymentMethod(Throwable $exception): CouldNotHandleOrderPaymentFee + public static function failedToRetrievePaymentMethod(Throwable $exception): self { return new self( 'Failed to retrieve payment method', @@ -17,7 +17,7 @@ public static function failedToRetrievePaymentMethod(Throwable $exception): Coul ); } - public static function failedToRetrievePaymentFee(Throwable $exception): CouldNotHandleOrderPaymentFee + public static function failedToRetrievePaymentFee(Throwable $exception): self { return new self( 'Failed to retrieve payment fee', @@ -26,7 +26,7 @@ public static function failedToRetrievePaymentFee(Throwable $exception): CouldNo ); } - public static function failedToCreateOrderPaymentFee(Throwable $exception): CouldNotHandleOrderPaymentFee + public static function failedToCreateOrderPaymentFee(Throwable $exception): self { return new self( 'Failed to create order payment fee', @@ -35,7 +35,7 @@ public static function failedToCreateOrderPaymentFee(Throwable $exception): Coul ); } - public static function failedToUpdateOrderTotalWithPaymentFee(Throwable $exception): CouldNotHandleOrderPaymentFee + public static function failedToUpdateOrderTotalWithPaymentFee(Throwable $exception): self { return new self( 'Failed to update order total with payment fee.', diff --git a/subscription/Exception/CouldNotHandleRecurringOrder.php b/subscription/Exception/CouldNotHandleRecurringOrder.php index e1dbc95e1..88c00de19 100644 --- a/subscription/Exception/CouldNotHandleRecurringOrder.php +++ b/subscription/Exception/CouldNotHandleRecurringOrder.php @@ -4,7 +4,7 @@ class CouldNotHandleRecurringOrder extends MollieSubscriptionException { - public static function failedToFindSelectedCarrier(): CouldNotHandleRecurringOrder + public static function failedToFindSelectedCarrier(): self { return new self( 'Failed to find selected carrier', @@ -12,7 +12,7 @@ public static function failedToFindSelectedCarrier(): CouldNotHandleRecurringOrd ); } - public static function failedToApplySelectedCarrier(): CouldNotHandleRecurringOrder + public static function failedToApplySelectedCarrier(): self { return new self( 'Failed to apply selected carrier', diff --git a/subscription/Exception/CouldNotPresentOrderDetail.php b/subscription/Exception/CouldNotPresentOrderDetail.php index 2b07862b9..8ed1c4c34 100644 --- a/subscription/Exception/CouldNotPresentOrderDetail.php +++ b/subscription/Exception/CouldNotPresentOrderDetail.php @@ -4,7 +4,7 @@ class CouldNotPresentOrderDetail extends MollieSubscriptionException { - public static function failedToFindOrder(): CouldNotPresentOrderDetail + public static function failedToFindOrder(): self { return new self( 'Failed to find order', @@ -12,7 +12,7 @@ public static function failedToFindOrder(): CouldNotPresentOrderDetail ); } - public static function failedToFindOrderDetail(): CouldNotPresentOrderDetail + public static function failedToFindOrderDetail(): self { return new self( 'Failed to find order detail', @@ -20,7 +20,7 @@ public static function failedToFindOrderDetail(): CouldNotPresentOrderDetail ); } - public static function failedToFindProduct(): CouldNotPresentOrderDetail + public static function failedToFindProduct(): self { return new self( 'Failed to find product', @@ -28,7 +28,7 @@ public static function failedToFindProduct(): CouldNotPresentOrderDetail ); } - public static function failedToFindCurrency(): CouldNotPresentOrderDetail + public static function failedToFindCurrency(): self { return new self( 'Failed to find currency', diff --git a/subscription/Exception/CouldNotProvideSubscriptionCarrierDeliveryPrice.php b/subscription/Exception/CouldNotProvideSubscriptionCarrierDeliveryPrice.php index 6c9709b7f..9d2f5fafb 100644 --- a/subscription/Exception/CouldNotProvideSubscriptionCarrierDeliveryPrice.php +++ b/subscription/Exception/CouldNotProvideSubscriptionCarrierDeliveryPrice.php @@ -4,7 +4,7 @@ class CouldNotProvideSubscriptionCarrierDeliveryPrice extends MollieSubscriptionException { - public static function failedToFindSelectedCarrier(): CouldNotProvideSubscriptionCarrierDeliveryPrice + public static function failedToFindSelectedCarrier(): self { return new self( 'Failed to find selected carrier', @@ -12,7 +12,7 @@ public static function failedToFindSelectedCarrier(): CouldNotProvideSubscriptio ); } - public static function failedToFindOrderCart(): CouldNotProvideSubscriptionCarrierDeliveryPrice + public static function failedToFindOrderCart(): self { return new self( 'Failed to find order cart', @@ -20,7 +20,7 @@ public static function failedToFindOrderCart(): CouldNotProvideSubscriptionCarri ); } - public static function failedToFindOrderCustomer(): CouldNotProvideSubscriptionCarrierDeliveryPrice + public static function failedToFindOrderCustomer(): self { return new self( 'Failed to find order customer', @@ -28,7 +28,7 @@ public static function failedToFindOrderCustomer(): CouldNotProvideSubscriptionC ); } - public static function failedToApplySelectedCarrier(): CouldNotProvideSubscriptionCarrierDeliveryPrice + public static function failedToApplySelectedCarrier(): self { return new self( 'Failed to apply selected carrier', @@ -36,7 +36,7 @@ public static function failedToApplySelectedCarrier(): CouldNotProvideSubscripti ); } - public static function failedToFindOrderDeliveryAddress(): CouldNotProvideSubscriptionCarrierDeliveryPrice + public static function failedToFindOrderDeliveryAddress(): self { return new self( 'Failed to find order delivery address', @@ -44,7 +44,7 @@ public static function failedToFindOrderDeliveryAddress(): CouldNotProvideSubscr ); } - public static function failedToFindOrderDeliveryCountry(): CouldNotProvideSubscriptionCarrierDeliveryPrice + public static function failedToFindOrderDeliveryCountry(): self { return new self( 'Failed to find order delivery country', @@ -52,7 +52,7 @@ public static function failedToFindOrderDeliveryCountry(): CouldNotProvideSubscr ); } - public static function failedToGetSelectedCarrierPrice(): CouldNotProvideSubscriptionCarrierDeliveryPrice + public static function failedToGetSelectedCarrierPrice(): self { return new self( 'Failed to get selected carrier price', diff --git a/subscription/Handler/RecurringOrderHandler.php b/subscription/Handler/RecurringOrderHandler.php index 60d919792..c7cfb4b0e 100644 --- a/subscription/Handler/RecurringOrderHandler.php +++ b/subscription/Handler/RecurringOrderHandler.php @@ -203,9 +203,9 @@ private function createSubscription(Payment $transaction, MolRecurringOrder $rec $newCart->update(); - if (sprintf('%d,', (int) $carrier->id) !== - $newCart->getDeliveryOption(null, false, false)[$newCart->id_address_delivery] - ) { + $cartCarrier = (int) ($newCart->getDeliveryOption(null, false, false)[$newCart->id_address_delivery] ?? 0); + + if ((int) $carrier->id !== $cartCarrier) { throw CouldNotHandleRecurringOrder::failedToApplySelectedCarrier(); } diff --git a/views/templates/admin/Subscription/subscriptions-faq.html.twig b/views/templates/admin/Subscription/subscriptions-faq.html.twig index 07bcc9659..45db6380e 100644 --- a/views/templates/admin/Subscription/subscriptions-faq.html.twig +++ b/views/templates/admin/Subscription/subscriptions-faq.html.twig @@ -32,11 +32,11 @@

- info_outline {{ subscriptionCreationTittle }} + info_outline {{ subscriptionCreationTittle|escape }}

-

{{subscriptionCreation}}

+

{{ subscriptionCreation|escape }}

@@ -47,11 +47,11 @@

- info_outline {{ importantInformationTittle }} + info_outline {{ importantInformationTittle|escape }}

-

{{importantInformation}}

+

{{ importantInformation|escape }}

@@ -62,14 +62,14 @@

- info_outline {{ carrierInformationTitle }} + info_outline {{ carrierInformationTitle|escape }}

-

{{carrierInformation1}}

-

{{carrierInformation2}}

-

{{carrierInformation3}}

-

{{carrierInformation4}}

+

{{ carrierInformation1|escape }}

+

{{ carrierInformation2|escape }}

+

{{ carrierInformation3|escape }}

+

{{ carrierInformation4|escape }}

@@ -80,12 +80,12 @@

- info_outline {{ cartRuleTitle }} + info_outline {{ cartRuleTitle|escape }}

-

{{cartRule}}

-

{{cartRule2}}

+

{{ cartRule|escape }}

+

{{ cartRule2|escape }}

@@ -96,11 +96,11 @@

- info_outline {{ giftWrappingTitle }} + info_outline {{ giftWrappingTitle|escape }}

-

{{giftWrapping1}}

+

{{ giftWrapping1|escape }}

@@ -111,13 +111,13 @@

- info_outline {{ subscriptionOrderLogicTitle }} + info_outline {{ subscriptionOrderLogicTitle|escape }}

-

{{recurringOrderCreation}}

-

{{recurringOrderPrice}}

-

{{recurringOrderAPIChanges}}

+

{{ recurringOrderCreation|escape }}

+

{{ recurringOrderPrice|escape }}

+

{{ recurringOrderAPIChanges|escape }}

diff --git a/views/templates/front/subscription/customerRecurringOrderDetailProduct.tpl b/views/templates/front/subscription/customerRecurringOrderDetailProduct.tpl index 1d071ee68..73a902eb7 100644 --- a/views/templates/front/subscription/customerRecurringOrderDetailProduct.tpl +++ b/views/templates/front/subscription/customerRecurringOrderDetailProduct.tpl @@ -4,27 +4,27 @@
-

{l s='Product:' mod='mollie'} {$order.name}

-

{l s='Quantity:' mod='mollie'} {$order.quantity}

-

{l s='Unit price:' mod='mollie'} {$order.unit_price}

+

{l s='Product:' mod='mollie'} {$order.name|escape:'htmlall':'UTF-8'}

+

{l s='Quantity:' mod='mollie'} {$order.quantity|escape:'htmlall':'UTF-8'}

+

{l s='Unit price:' mod='mollie'} {$order.unit_price|escape:'htmlall':'UTF-8'}

-

{l s='Total:' mod='mollie'} {$order.total}

-

{l s='Subscription status:' mod='mollie'} {$order.status}

-

{l s='Subscription start date:' mod='mollie'} {$order.start_date}

+

{l s='Total:' mod='mollie'} {$order.total|escape:'htmlall':'UTF-8'}

+

{l s='Subscription status:' mod='mollie'} {$order.status|escape:'htmlall':'UTF-8'}

+

{l s='Subscription start date:' mod='mollie'} {$order.start_date|escape:'htmlall':'UTF-8'}

{if isset($order.next_payment_date)} -

{l s='Next payment date:' mod='mollie'} {$order.next_payment_date}

+

{l s='Next payment date:' mod='mollie'} {$order.next_payment_date|escape:'htmlall':'UTF-8'}

{/if} {if isset($order.cancelled_date)} -

{l s='Cancelled date:' mod='mollie'} {$order.cancelled_date}

+

{l s='Cancelled date:' mod='mollie'} {$order.cancelled_date|escape:'htmlall':'UTF-8'}

{/if}