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

Hotfix-6.0.4 #811

Merged
merged 1 commit into from
Sep 18, 2023
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
8 changes: 7 additions & 1 deletion mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,13 @@ public function install()

$subscriptionInstaller = new Installer(
new DatabaseTableInstaller(),
new AttributeInstaller(new NullLogger(), new ConfigurationAdapter(), $this, new LanguageAdapter(), new ProductAttributeAdapter()),
new AttributeInstaller(
new NullLogger(),
$this->getService(ConfigurationAdapter::class),
$this,
new LanguageAdapter(),
new ProductAttributeAdapter()
),
new HookInstaller($this)
);

Expand Down
70 changes: 35 additions & 35 deletions src/Adapter/ConfigurationAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,59 +12,51 @@

namespace Mollie\Adapter;

use Context;
use Mollie\Config\Config;
use Shop;

class ConfigurationAdapter
{
public function get($key, $idShop = null, $idLang = null, $idShopGroup = null)
/** @var Context */
private $context;

public function __construct(Context $context)
{
if (is_array($key)) {
if ((int) $this->get(Config::MOLLIE_ENVIRONMENT)) {
$key = $key['production'];
} else {
$key = $key['sandbox'];
}
}
$this->context = $context;
}

/**
* @param string|array{production: string, sandbox: string} $key
*/
public function get($key, $idShop = null, $idLang = null, $idShopGroup = null): ?string
{
$key = $this->parseKeyByEnvironment($key);

if (!$idShop) {
$idShop = Context::getContext()->shop->id;
$idShop = $this->context->getShopId();
}

if (!$idShopGroup) {
$idShopGroup = Context::getContext()->shop->id_shop_group;
$idShopGroup = $this->context->getShopGroupId();
}

return \Configuration::get($key, $idLang, $idShopGroup, $idShop);
$result = \Configuration::get($key, $idLang, $idShopGroup, $idShop);

return !empty($result) ? $result : null;
}

/**
* @param string|array{production: string, sandbox: string} $key
* @param mixed $value
* @param ?int $idShop
* @param bool $html
* @param ?int $idShopGroup
*
* @return void
*/
public function updateValue($key, $value, $idShop = null, $html = false, $idShopGroup = null)
public function updateValue($key, $value, $idShop = null, $html = false, $idShopGroup = null): void
{
if (is_array($key)) {
if ((int) $this->get(Config::MOLLIE_ENVIRONMENT)) {
$key = $key['production'];
} else {
$key = $key['sandbox'];
}
}
$key = $this->parseKeyByEnvironment($key);

if ($idShop === null) {
$shops = Shop::getShops(true);
foreach ($shops as $shop) {
\Configuration::updateValue($key, $value, $html, $shop['id_shop_group'], $shop['id_shop']);
}
if (!$idShop) {
$idShop = $this->context->getShopId();
}

return;
if (!$idShopGroup) {
$idShopGroup = $this->context->getShopGroupId();
}

\Configuration::updateValue($key, $value, $html, $idShopGroup, $idShop);
Expand All @@ -73,7 +65,15 @@ public function updateValue($key, $value, $idShop = null, $html = false, $idShop
/**
* @param string|array{production: string, sandbox: string} $key
*/
public function delete($key)
public function delete($key): void
{
\Configuration::deleteByName($this->parseKeyByEnvironment($key));
}

/**
* @param string|array{production: string, sandbox: string} $key
*/
private function parseKeyByEnvironment($key): string
{
if (is_array($key)) {
if ((int) $this->get(Config::MOLLIE_ENVIRONMENT)) {
Expand All @@ -83,6 +83,6 @@ public function delete($key)
}
}

\Configuration::deleteByName($key);
return $key;
}
}
5 changes: 5 additions & 0 deletions src/Adapter/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,9 @@ public function getCountryId(): int
{
return (int) PrestashopContext::getContext()->country->id;
}

public function getShopGroupId(): int
{
return (int) PrestashopContext::getContext()->shop->id_shop_group;
}
}
14 changes: 8 additions & 6 deletions src/Adapter/ToolsAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@

class ToolsAdapter
{
public function strtoupper($str): string
{
return Tools::strtoupper($str);
}

public function strlen($str): string
{
return Tools::strlen($str);
Expand All @@ -39,6 +34,13 @@ public function displayPrice($price, $currency): string

public function getValue(string $key, string $defaultValue = null)
{
return Tools::getValue($key, $defaultValue);
$result = Tools::getValue($key, $defaultValue);

return !empty($result) ? $result : null;
}

public function isSubmit(string $string): bool
{
return (bool) Tools::isSubmit($string);
}
}
2 changes: 1 addition & 1 deletion src/Service/CartLinesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ private function convertToLineArray(array $newItems, $currencyIsoCode, $apiRound
$line->setQuantity((int) $item['quantity']);
$line->setSku(isset($item['sku']) ? $item['sku'] : '');

$currency = $this->tools->strtoupper($currencyIsoCode);
$currency = strtoupper(strtolower($currencyIsoCode));

if (isset($item['discount'])) {
$line->setDiscountAmount(new Amount(
Expand Down
Loading
Loading