From 8b766998e492d29c073bfce38786e541ade311e5 Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Fri, 22 Mar 2024 13:31:48 +0100 Subject: [PATCH] NTR: fix 6.4.20.2 --- src/Resources/config/services.xml | 2 +- src/Service/CustomerService.php | 16 ++++++++++------ tests/PHPUnit/Service/CustomerServiceTest.php | 4 +++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index d362c3068..6f13b9128 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -68,7 +68,7 @@ %kernel.shopware_version% - + diff --git a/src/Service/CustomerService.php b/src/Service/CustomerService.php index 779cd825a..81b450b4a 100644 --- a/src/Service/CustomerService.php +++ b/src/Service/CustomerService.php @@ -11,12 +11,13 @@ use Kiener\MolliePayments\Repository\Salutation\SalutationRepositoryInterface; use Kiener\MolliePayments\Service\MollieApi\Customer; use Kiener\MolliePayments\Struct\CustomerStruct; +use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; use Shopware\Core\Checkout\Customer\Aggregate\CustomerAddress\CustomerAddressEntity; use Shopware\Core\Checkout\Customer\CustomerEntity; use Shopware\Core\Checkout\Customer\Event\CustomerBeforeLoginEvent; use Shopware\Core\Checkout\Customer\Event\CustomerLoginEvent; -use Shopware\Core\Checkout\Customer\SalesChannel\AbstractRegisterRoute; +use Shopware\Core\Checkout\Customer\SalesChannel\RegisterRoute; use Shopware\Core\Checkout\Order\Aggregate\OrderAddress\OrderAddressEntity; use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenContainerEvent; @@ -76,9 +77,9 @@ class CustomerService implements CustomerServiceInterface /** - * @var AbstractRegisterRoute + * @var ContainerInterface */ - private $abstractRegisterRoute; + private $container; /** @@ -104,7 +105,7 @@ public function __construct( SettingsService $settingsService, string $shopwareVersion, ConfigService $configService, - AbstractRegisterRoute $abstractRegisterRoute + ContainerInterface $container //we have to inject the container, because in SW 6.4.20.2 we have circular injection for the register route ) { $this->countryRepository = $countryRepository; $this->customerRepository = $customerRepository; @@ -116,7 +117,7 @@ public function __construct( $this->settingsService = $settingsService; $this->shopwareVersion = $shopwareVersion; $this->configService = $configService; - $this->abstractRegisterRoute = $abstractRegisterRoute; + $this->container = $container; } /** @@ -465,8 +466,10 @@ public function getAddressArray($address, CustomerEntity $customer): array public function createApplePayDirectCustomer(string $firstname, string $lastname, string $email, string $phone, string $street, string $zipCode, string $city, string $countryISO2, SalesChannelContext $context): ?CustomerEntity { $countryId = $this->getCountryId($countryISO2, $context->getContext()); + $salutationId = $this->getSalutationId($context->getContext()); $data = new RequestDataBag(); + $data->set('salutationId', $salutationId); $data->set('guest', true); $data->set('firstName', $firstname); $data->set('lastName', $lastname); @@ -482,7 +485,8 @@ public function createApplePayDirectCustomer(string $firstname, string $lastname $data->set('billingAddress', $billingAddress); try { - $response = $this->abstractRegisterRoute->register($data, $context, false); + $abstractRegisterRoute = $this->container->get(RegisterRoute::class); + $response = $abstractRegisterRoute->register($data, $context, false); return $response->getCustomer(); } catch (ConstraintViolationException $e) { $errors = []; diff --git a/tests/PHPUnit/Service/CustomerServiceTest.php b/tests/PHPUnit/Service/CustomerServiceTest.php index 3febee1ca..5f62b13a9 100644 --- a/tests/PHPUnit/Service/CustomerServiceTest.php +++ b/tests/PHPUnit/Service/CustomerServiceTest.php @@ -11,9 +11,11 @@ use Kiener\MolliePayments\Service\MollieApi\Mandate; use Kiener\MolliePayments\Service\SettingsService; use Kiener\MolliePayments\Struct\CustomerStruct; +use MolliePayments\Tests\Fakes\FakeContainer; use MolliePayments\Tests\Fakes\FakeEntityRepository; use MolliePayments\Tests\Fakes\Repositories\FakeCustomerRepository; use PHPUnit\Framework\TestCase; +use Psr\Container\ContainerInterface; use Psr\Log\NullLogger; use Shopware\Core\Checkout\Customer\CustomerDefinition; use Shopware\Core\Checkout\Customer\CustomerEntity; @@ -53,7 +55,7 @@ public function setUp(): void $this->settingsService, 'does.not.matter.here', $this->createMock(ConfigService::class), - $this->createMock(AbstractRegisterRoute::class), + new FakeContainer(), ); }