Skip to content

Commit

Permalink
Merge pull request #997 from MarijusCoding/PIPRES-468/fork-title-mult…
Browse files Browse the repository at this point in the history
…ilang

PIPRES-468 "Title" multilanguage functionality
  • Loading branch information
GytisZum authored Dec 10, 2024
2 parents 4ec585c + 19cdf48 commit b0d8416
Show file tree
Hide file tree
Showing 24 changed files with 405 additions and 100 deletions.
2 changes: 1 addition & 1 deletion mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,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;
Expand Down
11 changes: 11 additions & 0 deletions shared/Core/Shared/Repository/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');

header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

header('Location: ../');
exit;
4 changes: 4 additions & 0 deletions shared/Infrastructure/Exception/MollieDatabaseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
use Mollie\Exception\Code\ExceptionCode;
use Mollie\Exception\MollieException;

if (!defined('_PS_VERSION_')) {
exit;
}

class MollieDatabaseException extends MollieException
{
public static function failedToFindRecord(string $className, array $keyValues): self
Expand Down
6 changes: 0 additions & 6 deletions src/Entity/MolPaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ class MolPaymentMethod extends ObjectModel
*/
public $method_name;

/**
* @var string
*/
public $title;

/**
* @var string
*/
Expand Down Expand Up @@ -123,7 +118,6 @@ class MolPaymentMethod extends ObjectModel
'id_method' => ['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'],
Expand Down
66 changes: 66 additions & 0 deletions src/Entity/MolPaymentMethodLang.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* Mollie https://www.mollie.nl
*
* @author Mollie B.V. <[email protected]>
* @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,
],
],
];
}
11 changes: 10 additions & 1 deletion src/Install/DatabaseTableInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/Install/DatabaseTableUninstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Logger/LogFormatterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

namespace Mollie\Logger;

if (!defined('_PS_VERSION_')) {
exit;
}

interface LogFormatterInterface
{
/**
Expand Down
4 changes: 4 additions & 0 deletions src/Logger/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 4 additions & 0 deletions src/Logger/LoggerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

namespace Mollie\Logger;

if (!defined('_PS_VERSION_')) {
exit;
}

interface LoggerInterface extends \Psr\Log\LoggerInterface
{
}
19 changes: 17 additions & 2 deletions src/Provider/PaymentOption/BancontactPaymentOptionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@
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 PrestaShop\PrestaShop\Core\Payment\PaymentOption;
Expand Down Expand Up @@ -79,6 +81,7 @@ class BancontactPaymentOptionProvider implements PaymentOptionProviderInterface
* @var LanguageService
*/
private $languageService;

/** @var OrderTotalProviderInterface */
private $orderTotalProvider;

Expand All @@ -105,10 +108,22 @@ 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);

$paymentMethodLangObject = $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)
$paymentMethodLangObject->text ?: $paymentMethod->method_name

Check failure on line 124 in src/Provider/PaymentOption/BancontactPaymentOptionProvider.php

View workflow job for this annotation

GitHub Actions / PHPStan (1.7.6.8)

Access to an undefined property ObjectModel::$text.

Check failure on line 124 in src/Provider/PaymentOption/BancontactPaymentOptionProvider.php

View workflow job for this annotation

GitHub Actions / PHPStan (1.7.7.0)

Access to an undefined property ObjectModel::$text.
);

$paymentOption->setModuleName($this->module->name);
$paymentOption->setAction($this->context->getLink()->getModuleLink(
'mollie',
Expand Down
19 changes: 17 additions & 2 deletions src/Provider/PaymentOption/BasePaymentOptionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@
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 PrestaShop\PrestaShop\Core\Payment\PaymentOption;
Expand Down Expand Up @@ -78,6 +80,7 @@ class BasePaymentOptionProvider implements PaymentOptionProviderInterface
* @var LanguageService
*/
private $languageService;

/** @var OrderTotalProviderInterface */
private $orderTotalProvider;

Expand All @@ -104,10 +107,22 @@ 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);

$paymentMethodLangObject = $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)
$paymentMethodLangObject->text ?: $paymentMethod->method_name

Check failure on line 123 in src/Provider/PaymentOption/BasePaymentOptionProvider.php

View workflow job for this annotation

GitHub Actions / PHPStan (1.7.6.8)

Access to an undefined property ObjectModel::$text.

Check failure on line 123 in src/Provider/PaymentOption/BasePaymentOptionProvider.php

View workflow job for this annotation

GitHub Actions / PHPStan (1.7.7.0)

Access to an undefined property ObjectModel::$text.
);

$paymentOption->setModuleName($this->module->name);
$paymentOption->setAction($this->context->getLink()->getModuleLink(
'mollie',
Expand Down
19 changes: 17 additions & 2 deletions src/Provider/PaymentOption/CreditCardPaymentOptionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@
use MolCustomer;
use Mollie;
use Mollie\Adapter\ConfigurationAdapter;
use Mollie\Adapter\Context;
use Mollie\Adapter\Customer;
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;
Expand Down Expand Up @@ -128,10 +130,23 @@ 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);

$paymentMethodLangObject = $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)
$paymentMethodLangObject->text ?: $paymentMethod->method_name

Check failure on line 147 in src/Provider/PaymentOption/CreditCardPaymentOptionProvider.php

View workflow job for this annotation

GitHub Actions / PHPStan (1.7.6.8)

Access to an undefined property ObjectModel::$text.

Check failure on line 147 in src/Provider/PaymentOption/CreditCardPaymentOptionProvider.php

View workflow job for this annotation

GitHub Actions / PHPStan (1.7.7.0)

Access to an undefined property ObjectModel::$text.
);

$paymentOption->setModuleName($this->module->name);
$paymentOption->setAction($this->context->getLink()->getModuleLink(
'mollie',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@
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;
Expand Down Expand Up @@ -126,10 +128,22 @@ 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);

$paymentMethodLangObject = $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)
$paymentMethodLangObject->text ?: $paymentMethod->method_name

Check failure on line 144 in src/Provider/PaymentOption/CreditCardSingleClickPaymentOptionProvider.php

View workflow job for this annotation

GitHub Actions / PHPStan (1.7.6.8)

Access to an undefined property ObjectModel::$text.

Check failure on line 144 in src/Provider/PaymentOption/CreditCardSingleClickPaymentOptionProvider.php

View workflow job for this annotation

GitHub Actions / PHPStan (1.7.7.0)

Access to an undefined property ObjectModel::$text.
);

$paymentOption->setModuleName($this->module->name);
$paymentOption->setAction($this->context->getLink()->getModuleLink(
'mollie',
Expand Down
18 changes: 16 additions & 2 deletions src/Provider/PaymentOption/IdealPaymentOptionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@
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;
Expand Down Expand Up @@ -112,10 +114,22 @@ 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);

$paymentMethodLangObject = $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)
$paymentMethodLangObject->text ?: $paymentMethod->method_name

Check failure on line 130 in src/Provider/PaymentOption/IdealPaymentOptionProvider.php

View workflow job for this annotation

GitHub Actions / PHPStan (1.7.6.8)

Access to an undefined property ObjectModel::$text.

Check failure on line 130 in src/Provider/PaymentOption/IdealPaymentOptionProvider.php

View workflow job for this annotation

GitHub Actions / PHPStan (1.7.7.0)

Access to an undefined property ObjectModel::$text.
);

$paymentOption->setModuleName($this->module->name);
$paymentOption->setAction($this->context->getLink()->getModuleLink(
'mollie',
Expand Down
Loading

0 comments on commit b0d8416

Please sign in to comment.