[UI][Channel] Add shippingAddressInCheckoutRequired field to channel entity

This commit is contained in:
Grzegorz Sadowski 2022-07-29 08:13:36 +02:00
parent b8fbd53549
commit 5d244a4994
No known key found for this signature in database
GPG key ID: EF87FF4E6E3BD364
11 changed files with 129 additions and 6 deletions

View file

@ -8,7 +8,7 @@ Feature: Choosing a required address in the checkout for a channel
Given the store operates on a single channel in "United States"
And I am logged in as an administrator
@api
@api @ui
Scenario: Adding a new channel with a required address in the checkout
When I want to create a new channel
And I specify its code as "MOBILE"
@ -19,13 +19,13 @@ Feature: Choosing a required address in the checkout for a channel
And I choose shipping address as a required address in the checkout
And I add it
Then I should be notified that it has been successfully created
And the required address in the checkout for the "Mobile Store" channel should be shipping
And the required address in the checkout for this channel should be shipping
@api
@api @ui
Scenario: Changing a required address in the checkout for an existing channel
Given the store operates on a channel named "Web Store"
When I want to modify this channel
And I choose shipping address as a required address in the checkout
And I save my changes
Then I should be notified that it has been successfully edited
And the required address in the checkout for the "Web Store" channel should be shipping
And the required address in the checkout for this channel should be shipping

View file

@ -256,9 +256,9 @@ final class ManagingChannelsContext implements Context
}
/**
* @Then /^the required address in the checkout for the ("[^"]+" channel) should be (billing|shipping)$/
* @Then /^the required address in the checkout for this channel should be (billing|shipping)$/
*/
public function theDefaultTaxZoneForTheChannelShouldBe(ChannelInterface $channel, string $type): void
public function theRequiredAddressInTheCheckoutForTheChannelShouldBe(string $type): void
{
Assert::true($this->responseChecker->hasValue(
$this->client->getLastResponse(),

View file

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Sylius\Behat\Context\Ui\Admin;
use Behat\Behat\Context\Context;
use Sylius\Behat\Element\Admin\Channel\ShippingAddressInCheckoutRequiredElementInterface;
use Sylius\Behat\NotificationType;
use Sylius\Behat\Page\Admin\Channel\CreatePageInterface;
use Sylius\Behat\Page\Admin\Channel\IndexPageInterface;
@ -31,6 +32,7 @@ final class ManagingChannelsContext implements Context
private IndexPageInterface $indexPage,
private CreatePageInterface $createPage,
private UpdatePageInterface $updatePage,
private ShippingAddressInCheckoutRequiredElementInterface $shippingAddressInCheckoutRequiredElement,
private CurrentPageResolverInterface $currentPageResolver,
private NotificationCheckerInterface $notificationChecker,
) {
@ -131,6 +133,20 @@ final class ManagingChannelsContext implements Context
$this->createPage->create();
}
/**
* @When /^I choose (billing|shipping) address as a required address in the checkout$/
*/
public function iChooseAddressAsARequiredAddressInTheCheckout(string $type): void
{
if ($type === 'shipping') {
$this->shippingAddressInCheckoutRequiredElement->requireShippingAddressInCheckout();
return;
}
$this->shippingAddressInCheckoutRequiredElement->requireBillingAddressInCheckout();
}
/**
* @Then I should see the channel :channelName in the list
* @Then the channel :channelName should appear in the registry
@ -519,6 +535,20 @@ final class ManagingChannelsContext implements Context
Assert::same($this->updatePage->getMenuTaxon(), $menuTaxon);
}
/**
* @Then /^the required address in the checkout for this channel should be (billing|shipping)$/
*/
public function theRequiredAddressInTheCheckoutForThisChannelShouldBe(string $type): void
{
if ($type === 'shipping') {
Assert::true($this->shippingAddressInCheckoutRequiredElement->isShippingAddressInCheckoutRequired());
return;
}
Assert::false($this->shippingAddressInCheckoutRequiredElement->isShippingAddressInCheckoutRequired());
}
private function assertChannelState(ChannelInterface $channel, bool $state): void
{
$this->iWantToBrowseChannels();

View file

@ -0,0 +1,41 @@
<?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\Element\Admin\Channel;
use FriendsOfBehat\PageObjectExtension\Element\Element;
final class ShippingAddressInCheckoutRequiredElement extends Element implements ShippingAddressInCheckoutRequiredElementInterface
{
public function requireShippingAddressInCheckout(): void
{
$this->getElement('shipping_address_in_checkout_required')->check();
}
public function requireBillingAddressInCheckout(): void
{
$this->getElement('shipping_address_in_checkout_required')->uncheck();
}
public function isShippingAddressInCheckoutRequired(): bool
{
return $this->getElement('shipping_address_in_checkout_required')->isChecked();
}
protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
'shipping_address_in_checkout_required' => '#sylius_channel_shippingAddressInCheckoutRequired',
]);
}
}

View file

@ -0,0 +1,23 @@
<?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\Element\Admin\Channel;
interface ShippingAddressInCheckoutRequiredElementInterface
{
public function requireShippingAddressInCheckout(): void;
public function requireBillingAddressInCheckout(): void;
public function isShippingAddressInCheckoutRequired(): bool;
}

View file

@ -59,6 +59,7 @@
<argument type="service" id="sylius.behat.page.admin.channel.index" />
<argument type="service" id="sylius.behat.page.admin.channel.create" />
<argument type="service" id="sylius.behat.page.admin.channel.update" />
<argument type="service" id="sylius.behat.element.admin.channel.shipping_address_in_checkout_required" />
<argument type="service" id="sylius.behat.current_page_resolver" />
<argument type="service" id="sylius.behat.notification_checker" />
</service>

View file

@ -18,6 +18,8 @@
<services>
<service id="sylius.behat.element.admin.account.reset" class="Sylius\Behat\Element\Admin\Account\ResetElement" parent="sylius.behat.element" />
<service id="sylius.behat.element.admin.channel.shipping_address_in_checkout_required" class="Sylius\Behat\Element\Admin\Channel\ShippingAddressInCheckoutRequiredElement" parent="sylius.behat.element" />
<service id="sylius.behat.element.admin.channel.shop_billing_data" class="Sylius\Behat\Element\Admin\Channel\ShopBillingDataElement" parent="sylius.behat.element" />
<service id="sylius.behat.element.admin.top_bar" class="Sylius\Behat\Element\Admin\TopBarElement" parent="sylius.behat.element" />

View file

@ -1077,6 +1077,9 @@ sylius_ui:
countries:
template: '@SyliusAdmin/Channel/Form/_countries.html.twig'
priority: 20
required_address_in_checkout:
template: '@SyliusAdmin/Channel/Form/_shippingAddressInCheckoutRequired.html.twig'
priority: 15
money:
template: '@SyliusAdmin/Channel/Form/_money.html.twig'
priority: 10

View file

@ -0,0 +1,18 @@
<div class="ui attached segment">
<div style="padding-bottom: 0.8rem; font-size: 0.93rem">
{{ form_label(form.shippingAddressInCheckoutRequired) }}
</div>
<div style="display: flex">
<div style="padding-right: 0.8rem">
<label for="{{ form.shippingAddressInCheckoutRequired.vars.id }}">{{ 'sylius.ui.billing_address'|trans }}</label>
</div>
<div>
<div class="ui toggle checkbox">
{{ form_widget(form.shippingAddressInCheckoutRequired) }}
</div>
</div>
<div>
<label for="{{ form.shippingAddressInCheckoutRequired.vars.id }}">{{ 'sylius.ui.shipping_address'|trans }}</label>
</div>
</div>
</div>

View file

@ -92,6 +92,10 @@ final class ChannelTypeExtension extends AbstractTypeExtension
'label' => 'sylius.form.channel.account_verification_required',
'required' => false,
])
->add('shippingAddressInCheckoutRequired', CheckboxType::class, [
'label' => 'sylius.form.channel.shipping_address_in_checkout_required',
'required' => false,
])
->add('shopBillingData', ShopBillingDataType::class, [
'label' => 'sylius.form.channel.shop_billing_data',
])

View file

@ -90,6 +90,7 @@ sylius:
locales: Locales
menu_taxon: Menu taxon
payment_methods: Payment Methods
shipping_address_in_checkout_required: Address required in checkout
shipping_methods: Shipping Methods
shop_billing_data: Shop billing data
skipping_shipping_step_allowed: Skip shipping step if only one shipping method is available?