Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PIPRES-261: shipping option module setting #814

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 58 additions & 1 deletion src/Builder/FormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,6 +91,8 @@ class FormBuilder

/** @var Context */
private $context;
/** @var CarrierRepositoryInterface */
private $carrierRepository;

public function __construct(
Mollie $module,
Expand All @@ -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;
Expand All @@ -117,6 +121,7 @@ public function __construct(
$this->configuration = $configuration;
$this->taxRulesGroupRepository = $taxRulesGroupRepository;
$this->context = $context;
$this->carrierRepository = $carrierRepository;
}

public function buildSettingsForm()
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$mappedCarriers[] = ['id' => $carrier->id, 'name' => $carrier->name];


$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,
];
}
}
2 changes: 2 additions & 0 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_';
Expand Down
2 changes: 2 additions & 0 deletions src/Install/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions src/Install/Uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions src/Repository/CarrierRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Mollie\Repository;

class CarrierRepository extends AbstractRepository implements CarrierRepositoryInterface
{
public function __construct()
{
parent::__construct(\Carrier::class);
}
}
7 changes: 7 additions & 0 deletions src/Repository/CarrierRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Mollie\Repository;

interface CarrierRepositoryInterface extends ReadOnlyRepositoryInterface
{
}
2 changes: 2 additions & 0 deletions src/Service/ConfigFieldService.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public function getConfigFieldsValues()
Config::MOLLIE_STATUS_SHIPPING => $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) {
Expand Down
3 changes: 3 additions & 0 deletions src/Service/SettingsSaveService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down
7 changes: 7 additions & 0 deletions src/ServiceProvider/BaseServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
33 changes: 18 additions & 15 deletions subscription/Controller/Symfony/SubscriptionFAQController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]);
}
}
19 changes: 18 additions & 1 deletion views/templates/admin/Subscription/subscriptions-faq.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@
</div>
</div>

<div class="row">
<div class="col-lg-12">
<div class="card">
<h3 class="card-header">
<i class="material-icons">info_outline</i> {{ carrierInformationTitle }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems incorrect

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's copied from Presta so all good

</h3>
<div class="card-block">
<div class="card-text">
<p>{{carrierInformation1}}</p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

escape for validation

<p>{{carrierInformation2}}</p>
<p>{{carrierInformation3}}</p>
<p>{{carrierInformation4}}</p>
</div>
</div>
</div>
</div>
</div>

<div class="row">
<div class="col-lg-12">
<div class="card">
Expand All @@ -68,7 +86,6 @@
<div class="card-text">
<p>{{cartRule}}</p>
<p>{{cartRule2}}</p>
<p>{{cartRule3}}</p>
</div>
</div>
</div>
Expand Down
Loading