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

PISHPS-298: replaced SalesChannelLocale with MollieLocaleService #778

Merged
merged 3 commits into from
Jul 1, 2024
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
14 changes: 7 additions & 7 deletions src/Controller/StoreApi/Config/ConfigControllerBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Kiener\MolliePayments\Controller\StoreApi\Config\Response\ConfigResponse;
use Kiener\MolliePayments\Service\ConfigService;
use Kiener\MolliePayments\Service\SalesChannel\SalesChannelLocale;
use Kiener\MolliePayments\Service\MollieLocaleService;
use Kiener\MolliePayments\Service\SettingsService;
use Psr\Log\LoggerInterface;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
Expand All @@ -25,9 +25,9 @@ class ConfigControllerBase
private $configService;

/**
* @var SalesChannelLocale
* @var MollieLocaleService
*/
private $salesChannelLocale;
private $mollieLocaleService;

/**
* @var LoggerInterface
Expand All @@ -37,14 +37,14 @@ class ConfigControllerBase
/**
* @param SettingsService $settingsService
* @param ConfigService $configService
* @param SalesChannelLocale $salesChannelLocale
* @param MollieLocaleService $mollieLocaleService
* @param LoggerInterface $logger
*/
public function __construct(SettingsService $settingsService, ConfigService $configService, SalesChannelLocale $salesChannelLocale, LoggerInterface $logger)
public function __construct(SettingsService $settingsService, ConfigService $configService, MollieLocaleService $mollieLocaleService, LoggerInterface $logger)
{
$this->settingsService = $settingsService;
$this->configService = $configService;
$this->salesChannelLocale = $salesChannelLocale;
$this->mollieLocaleService = $mollieLocaleService;
$this->logger = $logger;
}

Expand All @@ -63,7 +63,7 @@ public function getConfig(SalesChannelContext $context): StoreApiResponse
$settings = $this->settingsService->getSettings($scId);

$profileId = (string)$settings->getProfileId();
$locale = $this->salesChannelLocale->getLocale($context);
$locale = $this->mollieLocaleService->getLocale($context);

if (empty($profileId)) {
# if its somehow not yet loaded (plugin config in admin when clicking save)
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
<argument type="service" id="Kiener\MolliePayments\Service\SettingsService"/>
<argument type="service" id="Kiener\MolliePayments\Service\MandateService"/>
<argument type="service" id="Kiener\MolliePayments\Gateway\Mollie\MollieGateway"/>
<argument type="service" id="Kiener\MolliePayments\Service\SalesChannel\SalesChannelLocale"/>
<argument type="service" id="Kiener\MolliePayments\Service\MollieLocaleService"/>
<tag name="kernel.event_subscriber"/>
</service>

Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services/builder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<argument type="service" id="Kiener\MolliePayments\Service\MollieApi\Builder\MollieOrderAddressBuilder"/>
<argument type="service" id="Kiener\MolliePayments\Service\MollieApi\MollieOrderCustomerEnricher"/>
<argument type="service" id="Kiener\MolliePayments\Service\Router\RoutingBuilder"/>
<argument type="service" id="Kiener\MolliePayments\Service\MollieLocaleService"/>
<argument type="service" id="event_dispatcher"/>
<argument type="service" id="mollie_payments.logger"/>
</service>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/services/controller.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
<service id="Kiener\MolliePayments\Controller\StoreApi\Config\ConfigControllerBase">
<argument type="service" id="Kiener\MolliePayments\Service\SettingsService"/>
<argument type="service" id="Kiener\MolliePayments\Service\ConfigService"/>
<argument type="service" id="Kiener\MolliePayments\Service\SalesChannel\SalesChannelLocale"/>
<argument type="service" id="Kiener\MolliePayments\Service\MollieLocaleService"/>
<argument type="service" id="mollie_payments.logger"/>
<tag name="controller.service_arguments"/>
</service>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/services/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
<service id="Kiener\MolliePayments\Service\SalesChannel\SalesChannelDataExtractor">
</service>

<service id="Kiener\MolliePayments\Service\SalesChannel\SalesChannelLocale">
<service id="Kiener\MolliePayments\Service\MollieLocaleService">
<argument type="service" id="Kiener\MolliePayments\Repository\Language\LanguageRepository"/>
</service>

Expand Down
11 changes: 10 additions & 1 deletion src/Service/MollieApi/Builder/MollieOrderBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Kiener\MolliePayments\Handler\PaymentHandler;
use Kiener\MolliePayments\Service\MollieApi\MollieOrderCustomerEnricher;
use Kiener\MolliePayments\Service\MollieApi\OrderDataExtractor;
use Kiener\MolliePayments\Service\MollieLocaleService;
use Kiener\MolliePayments\Service\Router\RoutingBuilder;
use Kiener\MolliePayments\Service\SettingsService;
use Kiener\MolliePayments\Setting\MollieSettingStruct;
Expand Down Expand Up @@ -62,6 +63,11 @@ class MollieOrderBuilder
*/
private $urlBuilder;

/**
* @var MollieLocaleService
*/
private $mollieLocaleService;

/**
* @var EventDispatcherInterface
*/
Expand All @@ -81,10 +87,11 @@ class MollieOrderBuilder
* @param MollieOrderAddressBuilder $addressBuilder
* @param MollieOrderCustomerEnricher $customerEnricher
* @param RoutingBuilder $urlBuilder
* @param MollieLocaleService $mollieLocaleService
* @param EventDispatcherInterface $eventDispatcher
* @param LoggerInterface $logger
*/
public function __construct(SettingsService $settingsService, OrderDataExtractor $extractor, MollieOrderPriceBuilder $priceBuilder, MollieLineItemBuilder $lineItemBuilder, MollieOrderAddressBuilder $addressBuilder, MollieOrderCustomerEnricher $customerEnricher, RoutingBuilder $urlBuilder, EventDispatcherInterface $eventDispatcher, LoggerInterface $logger)
public function __construct(SettingsService $settingsService, OrderDataExtractor $extractor, MollieOrderPriceBuilder $priceBuilder, MollieLineItemBuilder $lineItemBuilder, MollieOrderAddressBuilder $addressBuilder, MollieOrderCustomerEnricher $customerEnricher, RoutingBuilder $urlBuilder, MollieLocaleService $mollieLocaleService, EventDispatcherInterface $eventDispatcher, LoggerInterface $logger)
{
$this->settingsService = $settingsService;
$this->extractor = $extractor;
Expand All @@ -93,6 +100,7 @@ public function __construct(SettingsService $settingsService, OrderDataExtractor
$this->addressBuilder = $addressBuilder;
$this->customerEnricher = $customerEnricher;
$this->urlBuilder = $urlBuilder;
$this->mollieLocaleService = $mollieLocaleService;
$this->eventDispatcher = $eventDispatcher;
$this->logger = $logger;
}
Expand Down Expand Up @@ -141,6 +149,7 @@ public function buildOrderPayload(OrderEntity $order, string $transactionId, str
$currency = $this->extractor->extractCurrency($order, $salesChannelContext);
$locale = $this->extractor->extractLocale($order, $salesChannelContext);
$localeCode = ($locale instanceof LocaleEntity) ? $locale->getCode() : self::MOLLIE_DEFAULT_LOCALE_CODE;
$localeCode = $this->mollieLocaleService->getMollieLocale($localeCode);
$lineItems = $order->getLineItems();
$isVerticalTaxCalculation = $this->isVerticalTaxCalculation($salesChannelContext);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php
declare(strict_types=1);

namespace Kiener\MolliePayments\Service\SalesChannel;
namespace Kiener\MolliePayments\Service;

use Kiener\MolliePayments\Repository\Language\LanguageRepositoryInterface;
use Shopware\Core\System\SalesChannel\SalesChannelContext;

class SalesChannelLocale
class MollieLocaleService
{
public const AVAILABLE_LOCALES = [
'en_US',
Expand All @@ -30,22 +31,16 @@ class SalesChannelLocale
'lt_LT'
];


/**
* @var LanguageRepositoryInterface
*/
private $repoLanguages;


/**
* @param LanguageRepositoryInterface $repoLanguages
*/
public function __construct(LanguageRepositoryInterface $repoLanguages)
{
$this->repoLanguages = $repoLanguages;
}


/**
* @param SalesChannelContext $salesChannelContext
* @return string
Expand All @@ -64,6 +59,11 @@ public function getLocale(SalesChannelContext $salesChannelContext): string
$locale = $language->getLocale()->getCode();
}

return $this->getMollieLocale($locale);
}

public function getMollieLocale(?string $locale): string
{
# Set the locale based on the current storefront.
if ($locale !== null && $locale !== '') {
$locale = str_replace('-', '_', $locale);
Expand Down
13 changes: 7 additions & 6 deletions src/Subscriber/CheckoutConfirmPageSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Kiener\MolliePayments\Service\CustomerService;
use Kiener\MolliePayments\Service\CustomFieldService;
use Kiener\MolliePayments\Service\MandateServiceInterface;
use Kiener\MolliePayments\Service\MollieLocaleService;
use Kiener\MolliePayments\Service\SalesChannel\SalesChannelLocale;
use Kiener\MolliePayments\Service\SettingsService;
use Kiener\MolliePayments\Setting\MollieSettingStruct;
Expand Down Expand Up @@ -45,9 +46,9 @@ class CheckoutConfirmPageSubscriber implements EventSubscriberInterface
private $settings;

/**
* @var SalesChannelLocale
* @var MollieLocaleService
*/
private $salesChannelLocale;
private $mollieLocaleService;

/**
* @var MandateServiceInterface
Expand Down Expand Up @@ -82,15 +83,15 @@ public static function getSubscribedEvents(): array
* @param SettingsService $settingsService
* @param MandateServiceInterface $mandateService
* @param MollieGatewayInterface $mollieGateway
* @param SalesChannelLocale $salesChannelLocale
* @param MollieLocaleService $mollieLocaleService
*/
public function __construct(MollieApiFactory $apiFactory, SettingsService $settingsService, MandateServiceInterface $mandateService, MollieGatewayInterface $mollieGateway, SalesChannelLocale $salesChannelLocale)
public function __construct(MollieApiFactory $apiFactory, SettingsService $settingsService, MandateServiceInterface $mandateService, MollieGatewayInterface $mollieGateway, MollieLocaleService $mollieLocaleService)
{
$this->apiFactory = $apiFactory;
$this->settingsService = $settingsService;
$this->mandateService = $mandateService;
$this->mollieGateway = $mollieGateway;
$this->salesChannelLocale = $salesChannelLocale;
$this->mollieLocaleService = $mollieLocaleService;
}


Expand Down Expand Up @@ -137,7 +138,7 @@ private function addMollieLocaleVariableToPage($args): void
{
$salesChannelContext = $args->getSalesChannelContext();

$locale = $this->salesChannelLocale->getLocale($salesChannelContext);
$locale = $this->mollieLocaleService->getLocale($salesChannelContext);

$args->getPage()->assign([
'mollie_locale' => $locale,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Kiener\MolliePayments\Facade\MolliePaymentFinalize;
use Kiener\MolliePayments\Handler\PaymentHandler;
use Kiener\MolliePayments\Hydrator\MollieLineItemHydrator;
use Kiener\MolliePayments\Repository\Language\LanguageRepositoryInterface;
use Kiener\MolliePayments\Service\CustomerService;
use Kiener\MolliePayments\Service\MollieApi\Builder\MollieLineItemBuilder;
use Kiener\MolliePayments\Service\MollieApi\Builder\MollieOrderAddressBuilder;
Expand All @@ -17,6 +18,7 @@
use Kiener\MolliePayments\Service\MollieApi\MollieOrderCustomerEnricher;
use Kiener\MolliePayments\Service\MollieApi\OrderDataExtractor;
use Kiener\MolliePayments\Service\MollieApi\PriceCalculator;
use Kiener\MolliePayments\Service\MollieLocaleService;
use Kiener\MolliePayments\Service\Router\RoutingBuilder;
use Kiener\MolliePayments\Service\Router\RoutingDetector;
use Kiener\MolliePayments\Service\SettingsService;
Expand All @@ -26,8 +28,10 @@
use MolliePayments\Tests\Fakes\FakeCompatibilityGateway;
use MolliePayments\Tests\Fakes\FakeEventDispatcher;
use MolliePayments\Tests\Fakes\FakePluginSettings;
use MolliePayments\Tests\Fakes\Repositories\FakeLanguageRepository;
use MolliePayments\Tests\Traits\OrderTrait;
use MolliePayments\Tests\Utils\Traits\PaymentBuilderTrait;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
Expand All @@ -47,27 +51,27 @@ abstract class AbstractMollieOrderBuilder extends TestCase
use PaymentBuilderTrait;

/**
* @var \PHPUnit\Framework\MockObject\MockObject|SettingsService
* @var MockObject|SettingsService
*/
protected $settingsService;
/**
* @var LoggerInterface
*/
protected $loggerService;
/**
* @var OrderDataExtractor|\PHPUnit\Framework\MockObject\MockObject
* @var OrderDataExtractor|MockObject
*/
protected $orderDataExtractor;
/**
* @var \PHPUnit\Framework\MockObject\MockObject|RouterInterface
* @var MockObject|RouterInterface
*/
protected $router;
/**
* @var MollieOrderBuilder
*/
protected $builder;
/**
* @var \PHPUnit\Framework\MockObject\MockObject|SalesChannelContext
* @var MockObject|SalesChannelContext
*/
protected $salesChannelContext;
/**
Expand Down Expand Up @@ -95,22 +99,27 @@ abstract class AbstractMollieOrderBuilder extends TestCase
*/
protected $localeCode;
/**
* @var MolliePaymentDoPay|\PHPUnit\Framework\MockObject\MockObject
* @var MolliePaymentDoPay|MockObject
*/
protected $mollieDoPaymentFacade;
/**
* @var MolliePaymentFinalize|\PHPUnit\Framework\MockObject\MockObject
* @var MolliePaymentFinalize|MockObject
*/
protected $molliePaymentFinalize;
/**
* @var \PHPUnit\Framework\MockObject\MockObject|TransactionTransitionServiceInterface
* @var MockObject|TransactionTransitionServiceInterface
*/
protected $transitionService;
/**
* @var MollieSettingStruct
*/
protected $settingStruct;

/**
* @var MollieLocaleService|MockObject
*/
private $mollieLocaleService;

public function setUp(): void
{
$this->address = $this->getDummyAddress();
Expand Down Expand Up @@ -160,7 +169,9 @@ public function setUp(): void
$routingDetector,
new FakePluginSettings(''),
''
);
);;

$this->mollieLocaleService = new MollieLocaleService($this->createMock(LanguageRepositoryInterface::class));

$this->builder = new MollieOrderBuilder(
$this->settingsService,
Expand All @@ -178,6 +189,7 @@ public function setUp(): void
new MollieOrderAddressBuilder(),
new MollieOrderCustomerEnricher($this->createMock(CustomerService::class)),
$routingBuilder,
$this->mollieLocaleService,
new FakeEventDispatcher(),
$this->loggerService
);
Expand Down
Loading
Loading