diff --git a/changelog.md b/changelog.md index bf7f3bf8f..6870d1a4f 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,12 @@ # Changelog # +## Changes in release 6.2.5 ## ++ Fixed issue with order status on multishop ++ Phone number validation improvements ++ Add to cart validation improvements on recurring orders ++ Code bawe improvements following prestashop standards + ## Changes in release 6.2.4 ## + Workflow improvements + Satispay payment method added diff --git a/controllers/admin/AdminMollieSettingsController.php b/controllers/admin/AdminMollieSettingsController.php index f27d749ed..4d7178a1b 100644 --- a/controllers/admin/AdminMollieSettingsController.php +++ b/controllers/admin/AdminMollieSettingsController.php @@ -205,9 +205,6 @@ public function postProcess() /** @var \Mollie\Builder\FormBuilder $settingsFormBuilder */ $settingsFormBuilder = $this->module->getService(\Mollie\Builder\FormBuilder::class); - /** @var Logger $logger * */ - $logger = $this->module->getService(LoggerInterface::class); - try { $html .= $settingsFormBuilder->buildSettingsForm(); } catch (PrestaShopDatabaseException $e) { diff --git a/mollie.php b/mollie.php index 23c6c6b20..97d800c3b 100755 --- a/mollie.php +++ b/mollie.php @@ -90,7 +90,7 @@ public function __construct() { $this->name = 'mollie'; $this->tab = 'payments_gateways'; - $this->version = '6.2.4'; + $this->version = '6.2.5'; $this->author = 'Mollie B.V.'; $this->need_instance = 1; $this->bootstrap = true; diff --git a/shared/Core/Shared/Repository/index.php b/shared/Core/Shared/Repository/index.php new file mode 100644 index 000000000..88355f610 --- /dev/null +++ b/shared/Core/Shared/Repository/index.php @@ -0,0 +1,11 @@ + ['type' => self::TYPE_STRING, 'validate' => 'isString'], 'method_name' => ['type' => self::TYPE_STRING, 'validate' => 'isString'], 'enabled' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'], - 'title' => ['type' => self::TYPE_STRING, 'validate' => 'isString'], 'method' => ['type' => self::TYPE_STRING, 'validate' => 'isString'], 'description' => ['type' => self::TYPE_STRING, 'validate' => 'isString'], 'is_countries_applicable' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'], diff --git a/src/Entity/MolPaymentMethodLang.php b/src/Entity/MolPaymentMethodLang.php new file mode 100644 index 000000000..c2b467ee9 --- /dev/null +++ b/src/Entity/MolPaymentMethodLang.php @@ -0,0 +1,65 @@ + + * @copyright Mollie B.V. + * @license https://github.com/mollie/PrestaShop/blob/master/LICENSE.md + * + * @see https://github.com/mollie/PrestaShop + * @codingStandardsIgnoreStart + */ +if (!defined('_PS_VERSION_')) { + exit; +} + +class MolPaymentMethodLang extends ObjectModel +{ + /** @var int */ + public $id; + + /** @var string name of the payment method */ + public $id_method; + + /** @var int */ + public $id_lang; + + /** @var int */ + public $id_shop; + + /** @var string payment title */ + public $text; + + /** + * Definition of the ObjectModel + */ + public static $definition = [ + 'table' => 'mol_payment_method_lang', + 'primary' => 'id', + 'fields' => [ + 'id_method' => [ + 'type' => self::TYPE_STRING, + 'validate' => 'isString', + 'required' => true, + 'size' => 64, + ], + 'id_lang' => [ + 'type' => self::TYPE_INT, + 'validate' => 'isUnsignedInt', + 'required' => true, + 'size' => 11, + ], + 'id_shop' => [ + 'type' => self::TYPE_INT, + 'validate' => 'isUnsignedInt', + 'required' => true, + 'size' => 11, + ], + 'text' => [ + 'type' => self::TYPE_STRING, + 'validate' => 'isString', + 'size' => 255, + ], + ], + ]; +} diff --git a/src/Install/DatabaseTableInstaller.php b/src/Install/DatabaseTableInstaller.php index 6489402c9..6679aff11 100644 --- a/src/Install/DatabaseTableInstaller.php +++ b/src/Install/DatabaseTableInstaller.php @@ -66,7 +66,6 @@ private function getCommands() `id_method` VARCHAR(64) NOT NULL, `method_name` VARCHAR(64) NOT NULL, `enabled` TINYINT(1), - `title` VARCHAR(64), `method` VARCHAR(64), `description` VARCHAR(255), `is_countries_applicable` TINYINT(1), @@ -151,6 +150,16 @@ private function getCommands() INDEX (`id_shop`) ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;'; + $sql[] = ' + CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'mol_payment_method_lang` ( + `id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, + `id_method` VARCHAR(64) NOT NULL, + `id_lang` INT(11), + `id_shop` INT(11), + `text` TINYTEXT, + INDEX (`id_method`) + ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;'; + return $sql; } diff --git a/src/Install/DatabaseTableUninstaller.php b/src/Install/DatabaseTableUninstaller.php index 2a92d160c..ddb0b0c57 100644 --- a/src/Install/DatabaseTableUninstaller.php +++ b/src/Install/DatabaseTableUninstaller.php @@ -42,6 +42,7 @@ private function getCommands(): array $sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'mol_excluded_country`;'; $sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'mol_pending_order_cart_rule`;'; $sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'mol_payment_method_order_total_restriction`;'; + $sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'mol_payment_method_lang`;'; return $sql; } diff --git a/src/Logger/LogFormatterInterface.php b/src/Logger/LogFormatterInterface.php index ae2690e24..29fc45cde 100644 --- a/src/Logger/LogFormatterInterface.php +++ b/src/Logger/LogFormatterInterface.php @@ -12,6 +12,10 @@ namespace Mollie\Logger; +if (!defined('_PS_VERSION_')) { + exit; +} + interface LogFormatterInterface { /** diff --git a/src/Logger/Logger.php b/src/Logger/Logger.php index e8c6dd505..9189faf77 100644 --- a/src/Logger/Logger.php +++ b/src/Logger/Logger.php @@ -19,6 +19,10 @@ use Mollie\Service\EntityManager\ObjectModelUnitOfWork; use Mollie\Utility\NumberIdempotencyProvider; +if (!defined('_PS_VERSION_')) { + exit; +} + class Logger implements LoggerInterface { public const FILE_NAME = 'Logger'; diff --git a/src/Logger/LoggerInterface.php b/src/Logger/LoggerInterface.php index d6230e177..747f0c3ff 100644 --- a/src/Logger/LoggerInterface.php +++ b/src/Logger/LoggerInterface.php @@ -12,6 +12,10 @@ namespace Mollie\Logger; +if (!defined('_PS_VERSION_')) { + exit; +} + interface LoggerInterface extends \Psr\Log\LoggerInterface { } diff --git a/src/Provider/PaymentOption/BancontactPaymentOptionProvider.php b/src/Provider/PaymentOption/BancontactPaymentOptionProvider.php index 9c4a0ddd2..62dd4855c 100644 --- a/src/Provider/PaymentOption/BancontactPaymentOptionProvider.php +++ b/src/Provider/PaymentOption/BancontactPaymentOptionProvider.php @@ -37,13 +37,16 @@ namespace Mollie\Provider\PaymentOption; use Mollie; +use Mollie\Adapter\Context; use Mollie\Adapter\LegacyContext; use Mollie\Api\Types\PaymentMethod; use Mollie\Provider\CreditCardLogoProvider; use Mollie\Provider\OrderTotal\OrderTotalProviderInterface; use Mollie\Provider\PaymentFeeProviderInterface; +use Mollie\Repository\PaymentMethodLangRepositoryInterface; use Mollie\Service\LanguageService; use MolPaymentMethod; +use MolPaymentMethodLang; use PrestaShop\PrestaShop\Core\Payment\PaymentOption; use Tools; @@ -79,6 +82,7 @@ class BancontactPaymentOptionProvider implements PaymentOptionProviderInterface * @var LanguageService */ private $languageService; + /** @var OrderTotalProviderInterface */ private $orderTotalProvider; @@ -105,10 +109,23 @@ public function getPaymentOption(MolPaymentMethod $paymentMethod): PaymentOption { $paymentOption = new PaymentOption(); + /** @var Context $context */ + $context = $this->module->getService(Context::class); + + /** @var PaymentMethodLangRepositoryInterface $paymentMethodLangRepository */ + $paymentMethodLangRepository = $this->module->getService(PaymentMethodLangRepositoryInterface::class); + + /** @var MolPaymentMethodLang $molPaymentMethodLang */ + $molPaymentMethodLang = $paymentMethodLangRepository->findOneBy([ + 'id_method' => $paymentMethod->id_method, + 'id_lang' => $context->getLanguageId(), + 'id_shop' => $context->getShopId(), + ]); + $paymentOption->setCallToActionText( - $paymentMethod->title ?: - $this->languageService->lang($paymentMethod->method_name) + $molPaymentMethodLang->text ?: $paymentMethod->method_name ); + $paymentOption->setModuleName($this->module->name); $paymentOption->setAction($this->context->getLink()->getModuleLink( 'mollie', diff --git a/src/Provider/PaymentOption/BasePaymentOptionProvider.php b/src/Provider/PaymentOption/BasePaymentOptionProvider.php index 4e5dcd064..b1f6d9773 100644 --- a/src/Provider/PaymentOption/BasePaymentOptionProvider.php +++ b/src/Provider/PaymentOption/BasePaymentOptionProvider.php @@ -37,12 +37,15 @@ namespace Mollie\Provider\PaymentOption; use Mollie; +use Mollie\Adapter\Context; use Mollie\Adapter\LegacyContext; use Mollie\Provider\CreditCardLogoProvider; use Mollie\Provider\OrderTotal\OrderTotalProviderInterface; use Mollie\Provider\PaymentFeeProviderInterface; +use Mollie\Repository\PaymentMethodLangRepositoryInterface; use Mollie\Service\LanguageService; use MolPaymentMethod; +use MolPaymentMethodLang; use PrestaShop\PrestaShop\Core\Payment\PaymentOption; use Tools; @@ -78,6 +81,7 @@ class BasePaymentOptionProvider implements PaymentOptionProviderInterface * @var LanguageService */ private $languageService; + /** @var OrderTotalProviderInterface */ private $orderTotalProvider; @@ -104,10 +108,23 @@ public function getPaymentOption(MolPaymentMethod $paymentMethod): PaymentOption { $paymentOption = new PaymentOption(); + /** @var Context $context */ + $context = $this->module->getService(Context::class); + + /** @var PaymentMethodLangRepositoryInterface $paymentMethodLangRepository */ + $paymentMethodLangRepository = $this->module->getService(PaymentMethodLangRepositoryInterface::class); + + /** @var MolPaymentMethodLang $molPaymentMethodLang */ + $molPaymentMethodLang = $paymentMethodLangRepository->findOneBy([ + 'id_method' => $paymentMethod->id_method, + 'id_lang' => $context->getLanguageId(), + 'id_shop' => $context->getShopId(), + ]); + $paymentOption->setCallToActionText( - $paymentMethod->title ?: - $this->languageService->lang($paymentMethod->method_name) + $molPaymentMethodLang->text ?: $paymentMethod->method_name ); + $paymentOption->setModuleName($this->module->name); $paymentOption->setAction($this->context->getLink()->getModuleLink( 'mollie', diff --git a/src/Provider/PaymentOption/CreditCardPaymentOptionProvider.php b/src/Provider/PaymentOption/CreditCardPaymentOptionProvider.php index e43a7d299..0567ebda5 100644 --- a/src/Provider/PaymentOption/CreditCardPaymentOptionProvider.php +++ b/src/Provider/PaymentOption/CreditCardPaymentOptionProvider.php @@ -39,6 +39,7 @@ use MolCustomer; use Mollie; use Mollie\Adapter\ConfigurationAdapter; +use Mollie\Adapter\Context; use Mollie\Adapter\Customer; use Mollie\Adapter\LegacyContext; use Mollie\Config\Config; @@ -46,9 +47,11 @@ use Mollie\Provider\OrderTotal\OrderTotalProviderInterface; use Mollie\Provider\PaymentFeeProviderInterface; use Mollie\Repository\MolCustomerRepository; +use Mollie\Repository\PaymentMethodLangRepositoryInterface; use Mollie\Service\LanguageService; use Mollie\Utility\CustomerUtility; use MolPaymentMethod; +use MolPaymentMethodLang; use PrestaShop\PrestaShop\Core\Payment\PaymentOption; use Tools; @@ -128,10 +131,24 @@ public function __construct( public function getPaymentOption(MolPaymentMethod $paymentMethod): PaymentOption { $paymentOption = new PaymentOption(); + + /** @var Context $context */ + $context = $this->module->getService(Context::class); + + /** @var PaymentMethodLangRepositoryInterface $paymentMethodLangRepository */ + $paymentMethodLangRepository = $this->module->getService(PaymentMethodLangRepositoryInterface::class); + + /** @var MolPaymentMethodLang $molPaymentMethodLang */ + $molPaymentMethodLang = $paymentMethodLangRepository->findOneBy([ + 'id_method' => $paymentMethod->id_method, + 'id_lang' => $context->getLanguageId(), + 'id_shop' => $context->getShopId(), + ]); + $paymentOption->setCallToActionText( - $paymentMethod->title ?: - $this->languageService->lang($paymentMethod->method_name) + $molPaymentMethodLang->text ?: $paymentMethod->method_name ); + $paymentOption->setModuleName($this->module->name); $paymentOption->setAction($this->context->getLink()->getModuleLink( 'mollie', diff --git a/src/Provider/PaymentOption/CreditCardSingleClickPaymentOptionProvider.php b/src/Provider/PaymentOption/CreditCardSingleClickPaymentOptionProvider.php index b3163165d..09d7a39a2 100644 --- a/src/Provider/PaymentOption/CreditCardSingleClickPaymentOptionProvider.php +++ b/src/Provider/PaymentOption/CreditCardSingleClickPaymentOptionProvider.php @@ -39,15 +39,18 @@ use MolCustomer; use Mollie; use Mollie\Adapter\ConfigurationAdapter; +use Mollie\Adapter\Context; use Mollie\Adapter\LegacyContext; use Mollie\Config\Config; use Mollie\Provider\CreditCardLogoProvider; use Mollie\Provider\OrderTotal\OrderTotalProviderInterface; use Mollie\Provider\PaymentFeeProviderInterface; use Mollie\Repository\MolCustomerRepository; +use Mollie\Repository\PaymentMethodLangRepositoryInterface; use Mollie\Service\LanguageService; use Mollie\Utility\CustomerUtility; use MolPaymentMethod; +use MolPaymentMethodLang; use PrestaShop\PrestaShop\Core\Payment\PaymentOption; use Tools; @@ -126,10 +129,23 @@ public function getPaymentOption(MolPaymentMethod $paymentMethod): PaymentOption { $paymentOption = new PaymentOption(); + /** @var Context $context */ + $context = $this->module->getService(Context::class); + + /** @var PaymentMethodLangRepositoryInterface $paymentMethodLangRepository */ + $paymentMethodLangRepository = $this->module->getService(PaymentMethodLangRepositoryInterface::class); + + /** @var MolPaymentMethodLang $molPaymentMethodLang */ + $molPaymentMethodLang = $paymentMethodLangRepository->findOneBy([ + 'id_method' => $paymentMethod->id_method, + 'id_lang' => $context->getLanguageId(), + 'id_shop' => $context->getShopId(), + ]); + $paymentOption->setCallToActionText( - $paymentMethod->title ?: - $this->languageService->lang($paymentMethod->method_name) + $molPaymentMethodLang->text ?: $paymentMethod->method_name ); + $paymentOption->setModuleName($this->module->name); $paymentOption->setAction($this->context->getLink()->getModuleLink( 'mollie', diff --git a/src/Provider/PaymentOption/IdealPaymentOptionProvider.php b/src/Provider/PaymentOption/IdealPaymentOptionProvider.php index 61d6ce1d9..61109894c 100644 --- a/src/Provider/PaymentOption/IdealPaymentOptionProvider.php +++ b/src/Provider/PaymentOption/IdealPaymentOptionProvider.php @@ -37,13 +37,16 @@ namespace Mollie\Provider\PaymentOption; use Mollie; +use Mollie\Adapter\Context; use Mollie\Adapter\LegacyContext; use Mollie\Provider\CreditCardLogoProvider; use Mollie\Provider\OrderTotal\OrderTotalProviderInterface; use Mollie\Provider\PaymentFeeProviderInterface; +use Mollie\Repository\PaymentMethodLangRepositoryInterface; use Mollie\Service\Content\TemplateParserInterface; use Mollie\Service\LanguageService; use MolPaymentMethod; +use MolPaymentMethodLang; use PrestaShop\PrestaShop\Core\Payment\PaymentOption; use Tools; @@ -112,10 +115,23 @@ public function getPaymentOption(MolPaymentMethod $paymentMethod): PaymentOption { $paymentOption = new PaymentOption(); + /** @var Context $context */ + $context = $this->module->getService(Context::class); + + /** @var PaymentMethodLangRepositoryInterface $paymentMethodLangRepository */ + $paymentMethodLangRepository = $this->module->getService(PaymentMethodLangRepositoryInterface::class); + + /** @var MolPaymentMethodLang $molPaymentMethodLang */ + $molPaymentMethodLang = $paymentMethodLangRepository->findOneBy([ + 'id_method' => $paymentMethod->id_method, + 'id_lang' => $context->getLanguageId(), + 'id_shop' => $context->getShopId(), + ]); + $paymentOption->setCallToActionText( - $paymentMethod->title ?: - $this->languageService->lang($paymentMethod->method_name) + $molPaymentMethodLang->text ?: $paymentMethod->method_name ); + $paymentOption->setModuleName($this->module->name); $paymentOption->setAction($this->context->getLink()->getModuleLink( 'mollie', diff --git a/src/Repository/PaymentMethodLangRepository.php b/src/Repository/PaymentMethodLangRepository.php new file mode 100644 index 000000000..223400541 --- /dev/null +++ b/src/Repository/PaymentMethodLangRepository.php @@ -0,0 +1,48 @@ + + * @copyright Mollie B.V. + * @license https://github.com/mollie/PrestaShop/blob/master/LICENSE.md + * + * @see https://github.com/mollie/PrestaShop + * @codingStandardsIgnoreStart + */ + +namespace Mollie\Repository; + +use Mollie\Shared\Infrastructure\Repository\AbstractRepository; + +if (!defined('_PS_VERSION_')) { + exit; +} + +class PaymentMethodLangRepository extends AbstractRepository implements PaymentMethodLangRepositoryInterface +{ + public function __construct() + { + parent::__construct(\MolPaymentMethodLang::class); + } + + public function savePaymentTitleTranslation(string $idPaymentMethod, int $langId, string $translation, int $idShop): bool + { + if (empty($translation)) { + return false; + } + + $paymentMethodLangObject = $this->findOneBy([ + 'id_method' => $idPaymentMethod, + 'id_lang' => $langId, + 'id_shop' => $idShop, + ]); + + $multiLangObject = new \MolPaymentMethodLang($paymentMethodLangObject->id ?? null); + $multiLangObject->id_lang = $langId; + $multiLangObject->id_method = $idPaymentMethod; + $multiLangObject->id_shop = $idShop; + $multiLangObject->text = $translation; + + return $multiLangObject->save(); + } +} diff --git a/src/Repository/PaymentMethodLangRepositoryInterface.php b/src/Repository/PaymentMethodLangRepositoryInterface.php new file mode 100644 index 000000000..a317f6fe3 --- /dev/null +++ b/src/Repository/PaymentMethodLangRepositoryInterface.php @@ -0,0 +1,24 @@ + + * @copyright Mollie B.V. + * @license https://github.com/mollie/PrestaShop/blob/master/LICENSE.md + * + * @see https://github.com/mollie/PrestaShop + * @codingStandardsIgnoreStart + */ + +namespace Mollie\Repository; + +use Mollie\Shared\Infrastructure\Repository\ReadOnlyRepositoryInterface; + +if (!defined('_PS_VERSION_')) { + exit; +} + +interface PaymentMethodLangRepositoryInterface extends ReadOnlyRepositoryInterface +{ + public function savePaymentTitleTranslation(string $idPaymentMethod, int $langId, string $translation, int $idShop): bool; +} diff --git a/src/Service/ApiService.php b/src/Service/ApiService.php index 4f557430c..77801d01f 100644 --- a/src/Service/ApiService.php +++ b/src/Service/ApiService.php @@ -28,6 +28,7 @@ use Mollie\Exception\MollieApiException; use Mollie\Provider\TaxCalculatorProvider; use Mollie\Repository\CountryRepository; +use Mollie\Repository\PaymentMethodLangRepositoryInterface; use Mollie\Repository\PaymentMethodRepository; use Mollie\Service\PaymentMethod\PaymentMethodSortProviderInterface; use Mollie\Utility\NumberUtility; @@ -81,6 +82,8 @@ class ApiService implements ApiServiceInterface private $taxProvider; /** @var Context */ private $context; + /** @var PaymentMethodLangRepositoryInterface */ + private $paymentMethodLangRepository; public function __construct( PaymentMethodRepository $methodRepository, @@ -90,7 +93,8 @@ public function __construct( TransactionService $transactionService, Shop $shop, TaxCalculatorProvider $taxProvider, - Context $context + Context $context, + PaymentMethodLangRepositoryInterface $paymentMethodLangRepository ) { $this->countryRepository = $countryRepository; $this->paymentMethodSortProvider = $paymentMethodSortProvider; @@ -101,6 +105,7 @@ public function __construct( $this->shop = $shop; $this->taxProvider = $taxProvider; $this->context = $context; + $this->paymentMethodLangRepository = $paymentMethodLangRepository; } /** @@ -193,7 +198,6 @@ private function getMethodsObjForConfig($apiMethods) $methods = []; $emptyPaymentMethod = new MolPaymentMethod(); $emptyPaymentMethod->enabled = false; - $emptyPaymentMethod->title = ''; $emptyPaymentMethod->method = 'payments'; $emptyPaymentMethod->description = ''; $emptyPaymentMethod->is_countries_applicable = false; @@ -231,6 +235,18 @@ private function getMethodsObjForConfig($apiMethods) ); } + $result = $this->paymentMethodLangRepository->findAllBy([ + 'id_method' => $apiMethod['id'], + 'id_shop' => $this->context->getShopId(), + ]); + + $mappedMethodTitles = []; + foreach ($result->getResults() as $value) { + $mappedMethodTitles[$value->id_lang] = $value->text; + } + + $paymentMethod->method_name = $apiMethod['name']; + $paymentMethod->titles = $mappedMethodTitles; $methods[$apiMethod['id']] = $apiMethod; $methods[$apiMethod['id']]['obj'] = $paymentMethod; @@ -239,8 +255,19 @@ private function getMethodsObjForConfig($apiMethods) $defaultPaymentMethod = clone $emptyPaymentMethod; + $result = $this->paymentMethodLangRepository->findAllBy([ + 'id_method' => $apiMethod['id'], + 'id_shop' => $this->context->getShopId(), + ]); + + $mappedMethodTitles = []; + foreach ($result->getResults() as $value) { + $mappedMethodTitles[$value->id_lang] = $value->text; + } + $defaultPaymentMethod->id_method = $apiMethod['id']; $defaultPaymentMethod->method_name = $apiMethod['name']; + $defaultPaymentMethod->titles = $mappedMethodTitles; $methods[$apiMethod['id']] = $apiMethod; $methods[$apiMethod['id']]['obj'] = $defaultPaymentMethod; diff --git a/src/Service/PaymentMethodService.php b/src/Service/PaymentMethodService.php index ecf936f67..601df59ad 100644 --- a/src/Service/PaymentMethodService.php +++ b/src/Service/PaymentMethodService.php @@ -40,6 +40,7 @@ use Mollie\Provider\PaymentFeeProviderInterface; use Mollie\Provider\PhoneNumberProviderInterface; use Mollie\Repository\GenderRepositoryInterface; +use Mollie\Repository\PaymentMethodLangRepositoryInterface; use Mollie\Repository\PaymentMethodRepositoryInterface; use Mollie\Service\PaymentMethod\PaymentMethodRestrictionValidationInterface; use Mollie\Service\PaymentMethod\PaymentMethodSortProviderInterface; @@ -75,11 +76,6 @@ class PaymentMethodService */ private $cartLinesService; - /** - * @var PaymentsTranslationService - */ - private $paymentsTranslationService; - /** * @var CustomerService */ @@ -116,12 +112,13 @@ class PaymentMethodService private $context; /** @var OrderTotalProviderInterface */ private $orderTotalProvider; + /** @var PaymentMethodLangRepositoryInterface */ + private $paymentMethodLangRepository; public function __construct( Mollie $module, PaymentMethodRepositoryInterface $methodRepository, CartLinesService $cartLinesService, - PaymentsTranslationService $paymentsTranslationService, CustomerService $customerService, CreditCardLogoProvider $creditCardLogoProvider, PaymentMethodSortProviderInterface $paymentMethodSortProvider, @@ -134,12 +131,12 @@ public function __construct( GenderRepositoryInterface $genderRepository, PaymentFeeProviderInterface $paymentFeeProvider, Context $context, - OrderTotalProviderInterface $orderTotalProvider + OrderTotalProviderInterface $orderTotalProvider, + PaymentMethodLangRepositoryInterface $paymentMethodLangRepository ) { $this->module = $module; $this->methodRepository = $methodRepository; $this->cartLinesService = $cartLinesService; - $this->paymentsTranslationService = $paymentsTranslationService; $this->customerService = $customerService; $this->creditCardLogoProvider = $creditCardLogoProvider; $this->paymentMethodSortProvider = $paymentMethodSortProvider; @@ -153,6 +150,7 @@ public function __construct( $this->paymentFeeProvider = $paymentFeeProvider; $this->context = $context; $this->orderTotalProvider = $orderTotalProvider; + $this->paymentMethodLangRepository = $paymentMethodLangRepository; } public function savePaymentMethod($method) @@ -167,7 +165,6 @@ public function savePaymentMethod($method) $paymentMethod->id_method = $method['id']; $paymentMethod->method_name = $method['name']; $paymentMethod->enabled = Tools::getValue(Mollie\Config\Config::MOLLIE_METHOD_ENABLED . $method['id']); - $paymentMethod->title = Tools::getValue(Mollie\Config\Config::MOLLIE_METHOD_TITLE . $method['id']); $paymentMethod->method = Tools::getValue(Mollie\Config\Config::MOLLIE_METHOD_API . $method['id']); $paymentMethod->description = Tools::getValue(Mollie\Config\Config::MOLLIE_METHOD_DESCRIPTION . $method['id']); $paymentMethod->is_countries_applicable = Tools::getValue(Mollie\Config\Config::MOLLIE_METHOD_APPLICABLE_COUNTRIES . $method['id']); @@ -188,6 +185,10 @@ public function savePaymentMethod($method) $paymentMethod->save(); + foreach (Tools::getValue(Config::MOLLIE_METHOD_TITLE . $method['id']) as $idLang => $title) { + $this->paymentMethodLangRepository->savePaymentTitleTranslation($method['id'], $idLang, $title, $this->context->getShopId()); + } + return $paymentMethod; } @@ -246,7 +247,6 @@ public function getMethodsForCheckout() } } - $methods = $this->paymentsTranslationService->getTranslatedPaymentMethods($methods); $methods = $this->paymentMethodSortProvider->getSortedInAscendingWayForCheckout($methods); return $methods; diff --git a/src/Service/PaymentsTranslationService.php b/src/Service/PaymentsTranslationService.php deleted file mode 100644 index 4fe31e854..000000000 --- a/src/Service/PaymentsTranslationService.php +++ /dev/null @@ -1,40 +0,0 @@ - - * @copyright Mollie B.V. - * @license https://github.com/mollie/PrestaShop/blob/master/LICENSE.md - * - * @see https://github.com/mollie/PrestaShop - * @codingStandardsIgnoreStart - */ - -namespace Mollie\Service; - -if (!defined('_PS_VERSION_')) { - exit; -} - -class PaymentsTranslationService -{ - /** - * @var LanguageService - */ - private $languageService; - - public function __construct( - LanguageService $languageService - ) { - $this->languageService = $languageService; - } - - public function getTranslatedPaymentMethods($paymentMethods) - { - foreach ($paymentMethods as $method) { - $method['method_name'] = $this->languageService->lang($method['method_name']); - } - - return $paymentMethods; - } -} diff --git a/src/ServiceProvider/BaseServiceProvider.php b/src/ServiceProvider/BaseServiceProvider.php index 2fd5701bf..76156e891 100644 --- a/src/ServiceProvider/BaseServiceProvider.php +++ b/src/ServiceProvider/BaseServiceProvider.php @@ -86,6 +86,8 @@ use Mollie\Repository\MolOrderPaymentFeeRepositoryInterface; use Mollie\Repository\OrderRepository; use Mollie\Repository\OrderRepositoryInterface; +use Mollie\Repository\PaymentMethodLangRepository; +use Mollie\Repository\PaymentMethodLangRepositoryInterface; use Mollie\Repository\PaymentMethodRepository; use Mollie\Repository\PaymentMethodRepositoryInterface; use Mollie\Repository\PendingOrderCartRuleRepository; @@ -215,6 +217,7 @@ public function register(Container $container) $this->addService($container, TaxRuleRepositoryInterface::class, $container->get(TaxRuleRepository::class)); $this->addService($container, TaxRepositoryInterface::class, $container->get(TaxRepository::class)); $this->addService($container, CartRepositoryInterface::class, $container->get(CartRepository::class)); + $this->addService($container, PaymentMethodLangRepositoryInterface::class, $container->get(PaymentMethodLangRepository::class)); $this->addService($container, OrderTotalProviderInterface::class, $container->get(OrderTotalProvider::class)); $this->addService($container, PaymentFeeProviderInterface::class, $container->get(PaymentFeeProvider::class)); diff --git a/src/Utility/VersionUtility.php b/src/Utility/VersionUtility.php index c3c27468f..de8d36076 100644 --- a/src/Utility/VersionUtility.php +++ b/src/Utility/VersionUtility.php @@ -12,6 +12,10 @@ namespace Mollie\Utility; +if (!defined('_PS_VERSION_')) { + exit; +} + class VersionUtility { public static function isPsVersionLessThan($version): int diff --git a/upgrade/Upgrade-6.2.5.php b/upgrade/Upgrade-6.2.5.php new file mode 100644 index 000000000..f72c25ce1 --- /dev/null +++ b/upgrade/Upgrade-6.2.5.php @@ -0,0 +1,67 @@ + + * @copyright Mollie B.V. + * @license https://github.com/mollie/PrestaShop/blob/master/LICENSE.md + * + * @see https://github.com/mollie/PrestaShop + */ + +if (!defined('_PS_VERSION_')) { + exit; +} + +function upgrade_module_6_2_5(Mollie $module): bool +{ + $sql = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'mol_payment_method_lang` ( + `id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, + `id_method` TINYTEXT, + `id_lang` INT(11), + `id_shop` INT(11), + `text` VARCHAR(64) NOT NULL, + INDEX (`id_method`) + ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;'; + + $result = Db::getInstance()->execute($sql); + + if(!$result) { + return false; + } + + try { + updatePaymentMethodTitles(); + } catch (Exception $e) { + return false; + } + + $sql = 'ALTER TABLE `' . _DB_PREFIX_ . 'mol_payment_method` DROP COLUMN `title`;'; + + return Db::getInstance()->execute($sql); +} + +function updatePaymentMethodTitles() { + $sql = 'SELECT `id_method`, `title` FROM `' . _DB_PREFIX_ . 'mol_payment_method`'; + + $methodsList = \Db::getInstance()->executeS($sql); + + foreach ($methodsList as $method) { + if (empty($method['title'])) { + continue; + } + + insertNewTitlesIntoDatabase($method); + } +} + +function insertNewTitlesIntoDatabase($method) { + foreach (\Shop::getCompleteListOfShopsID() as $idShop) { + foreach (\Language::getLanguages() as $idLang) { + $sql = 'INSERT INTO `' . _DB_PREFIX_ . 'mol_payment_method_lang` (`id_method`, `id_lang`, `id_shop`, `text`) + VALUES ("' . pSQL($method['id_method']) . '", ' . (int)$idLang['id_lang'] . ', ' . (int)$idShop . ', "' . pSQL($method['title']) . '")'; + + \Db::getInstance()->execute($sql); + } + } +} diff --git a/views/templates/admin/_configure/helpers/form/form.tpl b/views/templates/admin/_configure/helpers/form/form.tpl index c160578c6..818e40160 100644 --- a/views/templates/admin/_configure/helpers/form/form.tpl +++ b/views/templates/admin/_configure/helpers/form/form.tpl @@ -34,7 +34,7 @@
- {l s='Contact Invertus' mod='mollie'} @@ -50,7 +50,7 @@
  • + value="{$paymentMethod.obj->position|escape:'html':'UTF-8'}" class="js-payment-option-position"> - - - - - -{else} - - - - - + {else} @@ -135,7 +125,7 @@
    - Black
    - White with Outline
    - White
    {/if} +
    @@ -376,11 +389,11 @@ + min="{$paymentMethod.minimumAmount.value|escape:'html':'UTF-8'}" + {if $paymentMethod.maximumAmount != false } max="{$paymentMethod.maximumAmount.value|escape:'html':'UTF-8'}" {/if} + value="{if $methodObj->min_amount == 0}{$paymentMethod.minimumAmount.value|escape:'html':'UTF-8'}{else}{$methodObj->min_amount|escape:'html':'UTF-8'}{/if}">

    - {l s='Default min amount in mollie is: ' mod='mollie'} {$paymentMethod.minimumAmount.value}{$paymentMethod.minimumAmount.currency} + {l s='Default min amount in mollie is: ' mod='mollie'} {$paymentMethod.minimumAmount.value|escape:'html':'UTF-8'}{$paymentMethod.minimumAmount.currency|escape:'html':'UTF-8'}

    @@ -392,13 +405,13 @@ + {if $paymentMethod.maximumAmount != false } max='{$paymentMethod.maximumAmount.value|escape:'html':'UTF-8'}' {/if} + value="{if $methodObj->max_amount == 0}{($paymentMethod.maximumAmount) ? $paymentMethod.maximumAmount.value : ''}{else}{$methodObj->max_amount|escape:'html':'UTF-8'}{/if}">

    {if $paymentMethod.maximumAmount == false} {l s='Default max amount has no limitation' mod='mollie'} {else} - {l s='Default max amount in mollie is: ' mod='mollie'}{$paymentMethod.maximumAmount.value}{$paymentMethod.maximumAmount.currency} + {l s='Default max amount in mollie is: ' mod='mollie'}{$paymentMethod.maximumAmount.value|escape:'html':'UTF-8'}{$paymentMethod.maximumAmount.currency|escape:'html':'UTF-8'} {/if}

    @@ -864,7 +877,7 @@ {elseif $input.type === 'mollie-hidden-input'}
    - +
    {else} {$smarty.block.parent}