mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
Switch channel in API basing on hostname
This commit is contained in:
parent
e31de1fe6f
commit
b3bd616bb3
7 changed files with 53 additions and 4 deletions
|
|
@ -26,9 +26,9 @@ Feature: Viewing only taxons from the menu taxon
|
|||
And I should not see "T-Shirts" and "Guns" in the menu
|
||||
And I should not see "Rifles" and "Revolvers" in the menu
|
||||
|
||||
@ui
|
||||
@ui @api
|
||||
Scenario: Seeing correct taxons after switching the channel
|
||||
Given the store operates on another channel named "Poland"
|
||||
Given the store also operates on a channel named "Poland" with hostname "pl.store.com"
|
||||
And channel "United States" has menu taxon "Guns"
|
||||
And channel "Poland" has menu taxon "Clothes"
|
||||
When I change my current channel to "Poland"
|
||||
|
|
|
|||
|
|
@ -174,6 +174,11 @@ final class ApiPlatformClient implements ApiClientInterface
|
|||
|
||||
private function request(RequestInterface $request): Response
|
||||
{
|
||||
try {
|
||||
$this->client->setServerParameter('HTTP_HOST', $this->sharedStorage->get('hostname'));
|
||||
} catch (\InvalidArgumentException $exception) {
|
||||
}
|
||||
|
||||
$this->client->request(
|
||||
$request->method(),
|
||||
$request->url(),
|
||||
|
|
|
|||
37
src/Sylius/Behat/Context/Api/Shop/ChannelContext.php
Normal file
37
src/Sylius/Behat/Context/Api/Shop/ChannelContext.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Behat\Context\Api\Shop;
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use Sylius\Behat\Service\SharedStorageInterface;
|
||||
use Sylius\Component\Core\Model\ChannelInterface;
|
||||
|
||||
final class ChannelContext implements Context
|
||||
{
|
||||
/** @var SharedStorageInterface */
|
||||
private $sharedStorage;
|
||||
|
||||
public function __construct(SharedStorageInterface $sharedStorage)
|
||||
{
|
||||
$this->sharedStorage = $sharedStorage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^I change my current (channel to "([^"]+)")$/
|
||||
*/
|
||||
public function iChangeMyCurrentChannelTo(ChannelInterface $channel): void
|
||||
{
|
||||
$this->sharedStorage->set('hostname', $channel->getHostname());
|
||||
}
|
||||
}
|
||||
|
|
@ -18,8 +18,8 @@
|
|||
<services>
|
||||
<defaults public="true" />
|
||||
|
||||
<service id="sylius.behat.context.api.shop.login" class="Sylius\Behat\Context\Api\Shop\LoginContext">
|
||||
<argument type="service" id="sylius.behat.client.shop_api_platform_security_client" />
|
||||
<service id="sylius.behat.context.api.shop.channel" class="Sylius\Behat\Context\Api\Shop\ChannelContext">
|
||||
<argument type="service" id="sylius.behat.shared_storage" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.behat.context.api.shop.homepage" class="Sylius\Behat\Context\Api\Shop\HomepageContext">
|
||||
|
|
@ -29,6 +29,10 @@
|
|||
<argument type="service" id="sylius.behat.shared_storage" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.behat.context.api.shop.login" class="Sylius\Behat\Context\Api\Shop\LoginContext">
|
||||
<argument type="service" id="sylius.behat.client.shop_api_platform_security_client" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.behat.context.api.shop.registration" class="Sylius\Behat\Context\Api\Shop\RegistrationContext">
|
||||
<argument type="service" id="test.client" />
|
||||
</service>
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ default:
|
|||
- sylius.behat.context.setup.product
|
||||
- sylius.behat.context.setup.taxonomy
|
||||
|
||||
- sylius.behat.context.api.shop.channel
|
||||
- sylius.behat.context.api.shop.homepage
|
||||
|
||||
filters:
|
||||
|
|
|
|||
|
|
@ -110,6 +110,7 @@ final class DefaultUnitedStatesChannelFactory implements DefaultChannelFactoryIn
|
|||
$channel->addLocale($locale);
|
||||
$channel->setDefaultLocale($locale);
|
||||
$channel->setTaxCalculationStrategy('order_items_based');
|
||||
$channel->setHostname('us.store.com');
|
||||
|
||||
$defaultData = [
|
||||
'channel' => $channel,
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ final class DefaultUnitedStatesChannelFactorySpec extends ObjectBehavior
|
|||
$channel->addCurrency($currency)->shouldBeCalled();
|
||||
$channel->setDefaultLocale($locale)->shouldBeCalled();
|
||||
$channel->addLocale($locale)->shouldBeCalled();
|
||||
$channel->setHostname('us.store.com')->shouldBeCalled();
|
||||
|
||||
$currencyRepository->findOneBy(['code' => 'USD'])->willReturn(null);
|
||||
$localeRepository->findOneBy(['code' => 'en_US'])->willReturn(null);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue