diff --git a/src/Builder/FormBuilder.php b/src/Builder/FormBuilder.php index eacef51b6..5f77b946b 100644 --- a/src/Builder/FormBuilder.php +++ b/src/Builder/FormBuilder.php @@ -24,6 +24,7 @@ use Mollie\Api\Types\RefundStatus; use Mollie\Config\Config; use Mollie\Provider\CustomLogoProviderInterface; +use Mollie\Repository\CarrierRepositoryInterface; use Mollie\Repository\TaxRulesGroupRepositoryInterface; use Mollie\Service\ApiService; use Mollie\Service\ConfigFieldService; @@ -90,6 +91,8 @@ class FormBuilder /** @var Context */ private $context; + /** @var CarrierRepositoryInterface */ + private $carrierRepository; public function __construct( Mollie $module, @@ -103,7 +106,8 @@ public function __construct( CustomLogoProviderInterface $creditCardLogoProvider, ConfigurationAdapter $configuration, TaxRulesGroupRepositoryInterface $taxRulesGroupRepository, - Context $context + Context $context, + CarrierRepositoryInterface $carrierRepository ) { $this->module = $module; $this->apiService = $apiService; @@ -117,6 +121,7 @@ public function __construct( $this->configuration = $configuration; $this->taxRulesGroupRepository = $taxRulesGroupRepository; $this->context = $context; + $this->carrierRepository = $carrierRepository; } public function buildSettingsForm() @@ -527,6 +532,8 @@ protected function getAdvancedSettingsSection() ], ]; + $input = array_merge($input, $this->getShippingOptions($advancedSettings)); + $messageStatus = $this->module->l('Status for %s payments', self::FILE_NAME); $descriptionStatus = $this->module->l('`%s` payments get `%s` status', self::FILE_NAME); $messageMail = $this->module->l('Send email when %s', self::FILE_NAME); @@ -821,4 +828,54 @@ private function getSettingTabs($isApiKeyProvided) return $tabs; } + + private function getShippingOptions(string $tab): array + { + /** @var \Carrier[] $carriers */ + $carriers = $this->carrierRepository->findAllBy([ + 'active' => 1, + 'deleted' => 0, + ]); + + $mappedCarriers = []; + + $mappedCarriers[] = [ + 'id' => 0, + 'name' => $this->module->l('Not selected', self::FILE_NAME), + ]; + + foreach ($carriers as $carrier) { + $mappedCarrier = []; + + $mappedCarrier['id'] = $carrier->id; + $mappedCarrier['name'] = $carrier->name; + + $mappedCarriers[] = $mappedCarrier; + } + + $header = [ + 'type' => 'mollie-h2', + 'name' => '', + 'tab' => $tab, + 'title' => $this->module->l('Subscriptions', self::FILE_NAME), + ]; + + $options = [ + 'type' => 'select', + 'label' => $this->module->l('Select shipping option to use in subscription orders', self::FILE_NAME), + 'desc' => $this->module->l('WARNING: do not change selection after getting first subscription order.', self::FILE_NAME), + 'tab' => $tab, + 'name' => Config::MOLLIE_SUBSCRIPTION_ORDER_CARRIER_ID, + 'options' => [ + 'query' => $mappedCarriers, + 'id' => 'id', + 'name' => 'name', + ], + ]; + + return [ + $header, + $options, + ]; + } } diff --git a/src/Config/Config.php b/src/Config/Config.php index b08d3a074..1509c77ba 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -157,6 +157,8 @@ class Config const MOLLIE_CARRIER_URL_SOURCE = 'MOLLIE_CARRIER_URL_SOURCE_'; const MOLLIE_CARRIER_CUSTOM_URL = 'MOLLIE_CARRIER_CUSTOM_URL_'; + const MOLLIE_SUBSCRIPTION_ORDER_CARRIER_ID = 'MOLLIE_SUBSCRIPTION_ORDER_CARRIER_ID'; + const MOLLIE_METHOD_ENABLED = 'MOLLIE_METHOD_ENABLED_'; const MOLLIE_METHOD_TITLE = 'MOLLIE_METHOD_TITLE_'; const MOLLIE_METHOD_API = 'MOLLIE_METHOD_API_'; diff --git a/src/Install/Installer.php b/src/Install/Installer.php index 9455cc6ab..72a3eb6d8 100644 --- a/src/Install/Installer.php +++ b/src/Install/Installer.php @@ -209,6 +209,8 @@ protected function initConfig() $this->configurationAdapter->updateValue(Config::MOLLIE_API, Config::MOLLIE_ORDERS_API); $this->configurationAdapter->updateValue(Config::MOLLIE_APPLE_PAY_DIRECT_STYLE, 0); $this->configurationAdapter->updateValue(Config::MOLLIE_BANCONTACT_QR_CODE_ENABLED, 0); + + $this->configurationAdapter->updateValue(Config::MOLLIE_SUBSCRIPTION_ORDER_CARRIER_ID, 0); } public function setDefaultCarrierStatuses() diff --git a/src/Install/Uninstall.php b/src/Install/Uninstall.php index a6f7c1fff..c89dd7073 100644 --- a/src/Install/Uninstall.php +++ b/src/Install/Uninstall.php @@ -92,6 +92,7 @@ private function deleteConfig() Config::METHODS_CONFIG, Config::MOLLIE_MAIL_WHEN_COMPLETED, Config::MOLLIE_API_KEY_TEST, + Config::MOLLIE_SUBSCRIPTION_ORDER_CARRIER_ID, ]; $this->deleteConfigurations($configurations); diff --git a/src/Repository/CarrierRepository.php b/src/Repository/CarrierRepository.php new file mode 100644 index 000000000..c35fa9f05 --- /dev/null +++ b/src/Repository/CarrierRepository.php @@ -0,0 +1,11 @@ + $this->configurationAdapter->get(Config::MOLLIE_STATUS_SHIPPING), Config::MOLLIE_MAIL_WHEN_SHIPPING => $this->configurationAdapter->get(Config::MOLLIE_MAIL_WHEN_SHIPPING), Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS => $this->configurationAdapter->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS), + + Config::MOLLIE_SUBSCRIPTION_ORDER_CARRIER_ID => $this->configurationAdapter->get(Config::MOLLIE_SUBSCRIPTION_ORDER_CARRIER_ID), ]; if (EnvironmentUtility::getApiKey() && $this->module->getApiClient() !== null) { diff --git a/src/Service/SettingsSaveService.php b/src/Service/SettingsSaveService.php index 3b69b5c89..53cb5e89a 100644 --- a/src/Service/SettingsSaveService.php +++ b/src/Service/SettingsSaveService.php @@ -257,6 +257,8 @@ public function saveSettings(&$errors = []) $applePayDirectStyle = $this->tools->getValue(Config::MOLLIE_APPLE_PAY_DIRECT_STYLE); $isBancontactQrCodeEnabled = $this->tools->getValue(Config::MOLLIE_BANCONTACT_QR_CODE_ENABLED); + $subscriptionsShippingOption = (int) $this->tools->getValue(Config::MOLLIE_SUBSCRIPTION_ORDER_CARRIER_ID); + $mollieShipMain = $this->tools->getValue(Config::MOLLIE_AUTO_SHIP_MAIN); if (!isset($mollieErrors)) { $mollieErrors = false; @@ -311,6 +313,7 @@ public function saveSettings(&$errors = []) $this->configurationAdapter->updateValue(Config::MOLLIE_DEBUG_LOG, (int) $mollieLogger); $this->configurationAdapter->updateValue(Config::MOLLIE_API, $mollieApi); $this->configurationAdapter->updateValue(Config::MOLLIE_VOUCHER_CATEGORY, $voucherCategory); + $this->configurationAdapter->updateValue(Config::MOLLIE_SUBSCRIPTION_ORDER_CARRIER_ID, $subscriptionsShippingOption); $this->configurationAdapter->updateValue( Config::MOLLIE_AUTO_SHIP_STATUSES, json_encode($this->getStatusesValue(Config::MOLLIE_AUTO_SHIP_STATUSES)) diff --git a/src/ServiceProvider/BaseServiceProvider.php b/src/ServiceProvider/BaseServiceProvider.php index d50746b53..4b34b2783 100644 --- a/src/ServiceProvider/BaseServiceProvider.php +++ b/src/ServiceProvider/BaseServiceProvider.php @@ -16,6 +16,8 @@ use Mollie\Handler\Certificate\CertificateHandlerInterface; use Mollie\Handler\PaymentOption\PaymentOptionHandler; use Mollie\Handler\PaymentOption\PaymentOptionHandlerInterface; +use Mollie\Handler\RetryHandler; +use Mollie\Handler\RetryHandlerInterface; use Mollie\Handler\Settings\PaymentMethodPositionHandler; use Mollie\Handler\Settings\PaymentMethodPositionHandlerInterface; use Mollie\Handler\Shipment\ShipmentSenderHandler; @@ -45,6 +47,8 @@ use Mollie\Repository\AddressFormatRepositoryInterface; use Mollie\Repository\AddressRepository; use Mollie\Repository\AddressRepositoryInterface; +use Mollie\Repository\CarrierRepository; +use Mollie\Repository\CarrierRepositoryInterface; use Mollie\Repository\CartRepository; use Mollie\Repository\CartRepositoryInterface; use Mollie\Repository\CartRuleRepository; @@ -127,6 +131,8 @@ public function register(Container $container) /* Utility */ $this->addService($container, ClockInterface::class, $container->get(Clock::class)); + $this->addService($container, RetryHandlerInterface::class, $container->get(RetryHandler::class)); + $this->addService($container, PaymentMethodRepositoryInterface::class, $container->get(PaymentMethodRepository::class)); $this->addService($container, GenderRepositoryInterface::class, $container->get(GenderRepository::class)); $this->addService($container, MolCustomerRepository::class, MolCustomerRepository::class) @@ -179,6 +185,7 @@ public function register(Container $container) $this->addService($container, CurrencyRepositoryInterface::class, $container->get(CurrencyRepository::class)); $this->addService($container, CustomerRepositoryInterface::class, $container->get(CustomerRepository::class)); $this->addService($container, MolOrderPaymentFeeRepositoryInterface::class, $container->get(MolOrderPaymentFeeRepository::class)); + $this->addService($container, CarrierRepositoryInterface::class, $container->get(CarrierRepository::class)); $this->addService($container, CartRuleQuantityChangeHandlerInterface::class, $container->get(CartRuleQuantityChangeHandler::class)); $this->addService($container, RecurringOrderRepositoryInterface::class, RecurringOrderRepository::class) diff --git a/subscription/Controller/Symfony/SubscriptionFAQController.php b/subscription/Controller/Symfony/SubscriptionFAQController.php index c6ebbc227..a99fdce50 100644 --- a/subscription/Controller/Symfony/SubscriptionFAQController.php +++ b/subscription/Controller/Symfony/SubscriptionFAQController.php @@ -18,20 +18,23 @@ class SubscriptionFAQController extends AbstractSymfonyController */ public function indexAction() { - return $this->render('@Modules/mollie/views/templates/admin/Subscription/subscriptions-faq.html.twig', - [ - 'subscriptionCreationTittle' => $this->module->l('Subscription creation', self::FILE_NAME), - 'subscriptionCreation' => $this->module->l('To create a subscription option for a product variation, assign it a Mollie subscription attribute.', self::FILE_NAME), - 'importantInformationTittle' => $this->module->l('IMPORTANT points', self::FILE_NAME), - 'importantInformation' => $this->module->l('When you add Mollie subscription attributes, make sure you always include \'none\' as a fallback.', self::FILE_NAME), - 'cartRuleTitle' => $this->module->l('Cart rules', self::FILE_NAME), - 'cartRule' => $this->module->l('A customer can\'t add a subscription item to the shopping cart if it already contains a non-subscription item.', self::FILE_NAME), - 'cartRule2' => $this->module->l('A customer can\'t add subscription items with different recurring periods to the same shopping cart.', self::FILE_NAME), - 'cartRule3' => $this->module->l('Do not use cart rules with subscription products as this will cause errors due to incorrect pricing.', self::FILE_NAME), - 'subscriptionOrderLogicTitle' => $this->module->l('Recurring order creation', self::FILE_NAME), - 'recurringOrderCreation' => $this->module->l('Mollie for Prestashop automatically creates a new order when the previous order is paid for.', self::FILE_NAME), - 'recurringOrderPrice' => $this->module->l('Recurring orders always use the product price that was specified when the related subscription was created.', self::FILE_NAME), - 'recurringOrderAPIChanges' => $this->module->l('Recurring order will override the “Method” payment setting and will be using Mollie’s Payment API.', self::FILE_NAME), - ]); + return $this->render('@Modules/mollie/views/templates/admin/Subscription/subscriptions-faq.html.twig', [ + 'subscriptionCreationTittle' => $this->module->l('Subscription creation', self::FILE_NAME), + 'subscriptionCreation' => $this->module->l('To create a subscription option for a product variation, assign it a Mollie subscription attribute.', self::FILE_NAME), + 'importantInformationTittle' => $this->module->l('IMPORTANT points', self::FILE_NAME), + 'importantInformation' => $this->module->l('When you add Mollie subscription attributes, make sure you always include \'none\' as a fallback.', self::FILE_NAME), + 'carrierInformationTitle' => $this->module->l('IMPORTANT subscription carrier points', self::FILE_NAME), + 'carrierInformation1' => $this->module->l('Make sure to select default carrier for recurring orders in advanced settings.', self::FILE_NAME), + 'carrierInformation2' => $this->module->l('Carrier should cover all supported shop regions.', self::FILE_NAME), + 'carrierInformation3' => $this->module->l('Carrier cannot be changed after first subscription order is placed.', self::FILE_NAME), + 'carrierInformation4' => $this->module->l('Selected carrier pricing/weight settings or carrier selection in Mollie should not change. If they do, subscription orders must be cancelled.', self::FILE_NAME), + 'cartRuleTitle' => $this->module->l('Cart rules', self::FILE_NAME), + 'cartRule' => $this->module->l('A customer can\'t add subscription items with different recurring periods to the same shopping cart.', self::FILE_NAME), + 'cartRule2' => $this->module->l('Do not use cart rules with subscription products as this will cause errors due to incorrect pricing.', self::FILE_NAME), + 'subscriptionOrderLogicTitle' => $this->module->l('Recurring order creation', self::FILE_NAME), + 'recurringOrderCreation' => $this->module->l('Mollie for Prestashop automatically creates a new order when the previous order is paid for.', self::FILE_NAME), + 'recurringOrderPrice' => $this->module->l('Recurring orders always use the product price that was specified when the related subscription was created.', self::FILE_NAME), + 'recurringOrderAPIChanges' => $this->module->l('Recurring order will override the “Method” payment setting and will be using Mollie’s Payment API.', self::FILE_NAME), + ]); } } diff --git a/views/templates/admin/Subscription/subscriptions-faq.html.twig b/views/templates/admin/Subscription/subscriptions-faq.html.twig index 3e39f4538..6e9dab85e 100644 --- a/views/templates/admin/Subscription/subscriptions-faq.html.twig +++ b/views/templates/admin/Subscription/subscriptions-faq.html.twig @@ -58,6 +58,24 @@ +
{{carrierInformation1}}
+{{carrierInformation2}}
+{{carrierInformation3}}
+{{carrierInformation4}}
+{{cartRule}}
{{cartRule2}}
-{{cartRule3}}