Skip to content

Commit ffab944

Browse files
author
a.laurowski
authored
FFWEB-2249 fix configuration subscriber does not get channel with sales channel id argument
1 parent 35e0fa1 commit ffab944

4 files changed

Lines changed: 84 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Changelog
2+
## Unreleased
3+
- Config
4+
- Configuration is not taking sales channel id argument into account when load the FACT-Finder channel
5+
26
## [v2.1.1] - 2021.10.05
37
### Fix
48
- Export

spec/Config/CommunicationSpec.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ function it_should_cast_credentials_to_string()
1717
$this->getCredentials()->shouldContainOnlyStrings();
1818
}
1919

20+
function it_should_return_factfinder_channel_configured_for_specific_saleschannel(SystemConfigService $configService)
21+
{
22+
$configService->get('OmikronFactFinder.config.channel', '1')->willReturn('channel_1');
23+
$configService->get('OmikronFactFinder.config.channel', '2')->willReturn('channel_2');
24+
25+
$this->getChannel('1')->shouldReturn('channel_1');
26+
$this->getChannel('2')->shouldReturn('channel_2');
27+
}
28+
2029
public function getMatchers(): array
2130
{
2231
return [
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace spec\Omikron\FactFinder\Shopware6\Subscriber;
6+
7+
use Omikron\FactFinder\Shopware6\Config\Communication;
8+
use PhpSpec\ObjectBehavior;
9+
use Prophecy\Argument;
10+
use Prophecy\Argument\Token\LogicalAndToken;
11+
use Prophecy\Argument\Token\TypeToken;
12+
use Shopware\Core\Checkout\Customer\CustomerEntity;
13+
use Shopware\Core\Framework\Struct\ArrayEntity;
14+
use Shopware\Core\Framework\Struct\Struct;
15+
use Shopware\Core\System\Currency\CurrencyEntity;
16+
use Shopware\Core\System\SalesChannel\SalesChannelContext;
17+
use Shopware\Core\System\SalesChannel\SalesChannelEntity;
18+
use Shopware\Storefront\Page\GenericPageLoadedEvent;
19+
use Shopware\Storefront\Page\Page;
20+
use Symfony\Component\HttpFoundation\Request;
21+
22+
class ConfigurationSubscriberSpec extends ObjectBehavior
23+
{
24+
function let(Communication $communication)
25+
{
26+
$fieldRoles = [];
27+
$communicationParameters = [];
28+
$communication->getServerUrl()->willReturn('https://factfinder.server.com');
29+
$this->beConstructedWith($communication, $fieldRoles, $communicationParameters);
30+
}
31+
32+
function it_will_return_factfinderchannel_for_specific_sales_channel_id(
33+
Communication $communication,
34+
GenericPageLoadedEvent $event,
35+
SalesChannelContext $salesChannelContext,
36+
SalesChannelEntity $salesChannel,
37+
CustomerEntity $customer,
38+
CurrencyEntity $currency,
39+
Request $request,
40+
Struct $extension,
41+
Page $page
42+
) {
43+
$event->getSalesChannelContext()->willReturn($salesChannelContext);
44+
$salesChannelContext->getCustomer()->willReturn($customer);
45+
$customer->getId()->willReturn(1);
46+
$salesChannelContext->getCurrency()->willReturn($currency);
47+
$currency->getIsoCode()->willReturn('EUR');
48+
$salesChannelContext->getSalesChannel()->willReturn($salesChannel);
49+
$salesChannel->getId()->willReturn('main_sales_channel');
50+
$communication->getChannel('main_sales_channel')->willReturn('some_ff_channel');
51+
$event->getRequest()->willReturn($request);
52+
$request->get('_route')->willReturn('factfinder');
53+
$request->getLocale()->willReturn('en');
54+
$event->getPage()->willReturn($page);
55+
56+
$page->addExtension(
57+
'factfinder',
58+
new LogicalAndToken(
59+
[
60+
new TypeToken(ArrayEntity::class),
61+
Argument::withEntry('communication', Argument::withEntry('channel', 'some_ff_channel'))
62+
]
63+
))->shouldBeCalled();
64+
65+
$this->onPageLoaded($event);
66+
}
67+
}

src/Subscriber/ConfigurationSubscriber.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ public static function getSubscribedEvents()
3131

3232
public function onPageLoaded(GenericPageLoadedEvent $event): void
3333
{
34-
$customer = $event->getSalesChannelContext()->getCustomer();
34+
$customer = $event->getSalesChannelContext()->getCustomer();
35+
$salesChannelId = $event->getSalesChannelContext()->getSalesChannel()->getId();
36+
3537
$event->getPage()->addExtension('factfinder', new ArrayEntity([
3638
'field_roles' => $this->fieldRoles,
3739
'communication' => [
3840
'url' => $this->config->getServerUrl(),
39-
'channel' => $this->config->getChannel(),
41+
'channel' => $this->config->getChannel($salesChannelId),
4042
'version' => 'ng',
4143
'api' => 'v4',
4244
'user-id' => $customer ? $customer->getId() : null,

0 commit comments

Comments
 (0)