mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[Core] Move also default tax calculation strategy to channel
This commit is contained in:
parent
288ada199c
commit
a1718d8332
15 changed files with 153 additions and 3 deletions
|
|
@ -0,0 +1,36 @@
|
|||
@managing_channels
|
||||
Feature: Selecting default tax calculation strategy for a channel
|
||||
In order to use different tax strategies on different channels
|
||||
As an Administrator
|
||||
I want to be able to select default tax calculation strategy
|
||||
|
||||
Background:
|
||||
Given I am logged in as an administrator
|
||||
|
||||
@ui
|
||||
Scenario: Adding a new channel with implicitly selected default tax calculation strategy
|
||||
Given I want to create a new channel
|
||||
When I specify its code as MOBILE
|
||||
And I name it "Mobile store"
|
||||
And I add it
|
||||
Then I should be notified that it has been successfully created
|
||||
And "Order items based" should be default tax calculation strategy for the "Mobile store" channel
|
||||
|
||||
@ui
|
||||
Scenario: Adding a new channel with default tax calculation strategy
|
||||
Given I want to create a new channel
|
||||
When I specify its code as MOBILE
|
||||
And I select the "Order item units based" as default tax calculation strategy
|
||||
And I name it "Mobile store"
|
||||
And I add it
|
||||
Then I should be notified that it has been successfully created
|
||||
And "Order item units based" should be default tax calculation strategy for the "Mobile store" channel
|
||||
|
||||
@ui
|
||||
Scenario: Changing default tax calculation strategy of existing channel
|
||||
Given the store operates on a channel named "Web store"
|
||||
And I want to modify this channel
|
||||
When I select the "Order item units based" as default tax calculation strategy
|
||||
And I save my changes
|
||||
Then I should be notified that it has been successfully edited
|
||||
And "Order item units based" should be default tax calculation strategy for the "Web store" channel
|
||||
|
|
@ -106,6 +106,7 @@ final class ChannelContext implements Context
|
|||
{
|
||||
$channel = $this->channelFactory->createNamed($channelIdentifier);
|
||||
$channel->setCode($channelIdentifier);
|
||||
$channel->setDefaultTaxCalculationStrategy('Order items based');
|
||||
|
||||
$this->channelRepository->add($channel);
|
||||
$this->sharedStorage->set('channel', $channel);
|
||||
|
|
|
|||
|
|
@ -443,6 +443,16 @@ final class ManagingChannelsContext implements Context
|
|||
$currentPage->chooseDefaultTaxZone($taxZone);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I select the :taxCalculationStrategy as default tax calculation strategy
|
||||
*/
|
||||
public function iSelectDefaultTaxCalculationStrategy($taxCalculationStrategy)
|
||||
{
|
||||
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);
|
||||
|
||||
$currentPage->chooseDefaultTaxCalculationStrategy($taxCalculationStrategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the :paymentMethodName payment method should be available for the :channel channel
|
||||
*/
|
||||
|
|
@ -452,7 +462,7 @@ final class ManagingChannelsContext implements Context
|
|||
|
||||
Assert::true(
|
||||
$this->updatePage->isPaymentMethodChosen($paymentMethodName),
|
||||
sprintf('Payment method %s should be selected but it is not', $paymentMethodName)
|
||||
sprintf('Payment method %s should be selected, but it is not', $paymentMethodName)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -465,7 +475,20 @@ final class ManagingChannelsContext implements Context
|
|||
|
||||
Assert::true(
|
||||
$this->updatePage->isDefaultTaxZoneChosen($taxZone),
|
||||
sprintf('Default tax zone %s should be selected but it is not', $taxZone)
|
||||
sprintf('Default tax zone %s should be selected, but it is not', $taxZone)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then :taxCalculationStrategy should be default tax calculation strategy for the :channel channel
|
||||
*/
|
||||
public function shouldBeDefaultTaxCalculationStrategyForTheChannel($taxCalculationStrategy, ChannelInterface $channel)
|
||||
{
|
||||
$this->updatePage->open(['id' => $channel->getId()]);
|
||||
|
||||
Assert::true(
|
||||
$this->updatePage->isDefaultTaxCalculationStrategyChosen($taxCalculationStrategy),
|
||||
sprintf('Default tax calculation strategy %s should be selected, but it is not', $taxCalculationStrategy)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -83,6 +83,14 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
|
|||
$this->getDocument()->selectFieldOption('Default tax zone', $taxZone);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function chooseDefaultTaxCalculationStrategy($taxZone)
|
||||
{
|
||||
$this->getDocument()->selectFieldOption('Default tax calculation strategy', $taxZone);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -71,4 +71,9 @@ interface CreatePageInterface extends BaseCreatePageInterface
|
|||
* @param string $taxZone
|
||||
*/
|
||||
public function chooseDefaultTaxZone($taxZone);
|
||||
|
||||
/**
|
||||
* @param string $taxCalculationStrategy
|
||||
*/
|
||||
public function chooseDefaultTaxCalculationStrategy($taxCalculationStrategy);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,6 +104,14 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
|
|||
$this->getDocument()->selectFieldOption('Default tax zone', $taxZone);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function chooseDefaultTaxCalculationStrategy($taxZone)
|
||||
{
|
||||
$this->getDocument()->selectFieldOption('Default tax calculation strategy', $taxZone);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -120,6 +128,18 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
|
|||
return $this->getElement('default_tax_zone')->find('named', array('option', $taxZone))->hasAttribute('selected');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isDefaultTaxCalculationStrategyChosen($taxCalculationStrategy)
|
||||
{
|
||||
return $this
|
||||
->getElement('default_tax_calculation_strategy')
|
||||
->find('named', array('option', $taxCalculationStrategy))
|
||||
->hasAttribute('selected')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -144,6 +164,7 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
|
|||
return array_merge(parent::getDefinedElements(), [
|
||||
'code' => '#sylius_channel_code',
|
||||
'currencies' => '#sylius_channel_currencies',
|
||||
'default_tax_calculation_strategy' => '#sylius_channel_defaultTaxCalculationStrategy',
|
||||
'default_tax_zone' => '#sylius_channel_defaultTaxZone',
|
||||
'enabled' => '#sylius_channel_enabled',
|
||||
'locales' => '#sylius_channel_locales',
|
||||
|
|
|
|||
|
|
@ -84,6 +84,11 @@ interface UpdatePageInterface extends BaseUpdatePageInterface
|
|||
*/
|
||||
public function chooseDefaultTaxZone($taxZone);
|
||||
|
||||
/**
|
||||
* @param string $taxCalculationStrategy
|
||||
*/
|
||||
public function chooseDefaultTaxCalculationStrategy($taxCalculationStrategy);
|
||||
|
||||
/**
|
||||
* @param string $paymentMethod
|
||||
*
|
||||
|
|
@ -97,4 +102,11 @@ interface UpdatePageInterface extends BaseUpdatePageInterface
|
|||
* @return bool
|
||||
*/
|
||||
public function isDefaultTaxZoneChosen($taxZone);
|
||||
|
||||
/**
|
||||
* @param string $taxCalculationStrategy
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDefaultTaxCalculationStrategyChosen($taxCalculationStrategy);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
{{ form_row(form.shippingMethods) }}
|
||||
{{ form_row(form.paymentMethods) }}
|
||||
{{ form_row(form.defaultTaxZone) }}
|
||||
{{ form_row(form.defaultTaxCalculationStrategy) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ class LoadZonesData extends DataFixture
|
|||
|
||||
$settingsManager = $this->get('sylius.settings.manager');
|
||||
$settings = $settingsManager->load('sylius_taxation');
|
||||
$settings->set('default_tax_zone', $eu);
|
||||
$settingsManager->save($settings);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@ class ChannelType extends BaseChannelType
|
|||
'required' => false,
|
||||
'label' => 'sylius.form.channel.tax_zone_default',
|
||||
])
|
||||
->add('defaultTaxCalculationStrategy', 'sylius_tax_calculation_strategy_choice', [
|
||||
'label' => 'sylius.form.channel.tax_calculation_strategy_default',
|
||||
])
|
||||
->add('themeName', 'sylius_theme_name_choice', [
|
||||
'label' => 'sylius.form.channel.theme',
|
||||
'required' => false,
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
<mapped-superclass name="Sylius\Component\Core\Model\Channel" table="sylius_channel">
|
||||
<field name="themeName" column="theme_name" type="string" nullable="true" />
|
||||
<field name="defaultTaxCalculationStrategy" type="string" />
|
||||
|
||||
<many-to-one field="defaultLocale" target-entity="Sylius\Component\Locale\Model\LocaleInterface">
|
||||
<join-column name="default_locale_id" referenced-column-name="id" nullable="true" on-delete="SET NULL"/>
|
||||
|
|
|
|||
|
|
@ -24,6 +24,12 @@
|
|||
</property>
|
||||
</class>
|
||||
|
||||
<class name="Sylius\Component\Core\Model\Channel">
|
||||
<property name="defaultTaxCalculationStrategy">
|
||||
<constraint name="NotBlank" />
|
||||
</property>
|
||||
</class>
|
||||
|
||||
<class name="Sylius\Component\Core\Model\Order">
|
||||
<property name="shippingAddress">
|
||||
<constraint name="Valid" />
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ sylius:
|
|||
currencies: Currencies
|
||||
shipping_methods: Shipping Methods
|
||||
payment_methods: Payment Methods
|
||||
tax_calculation_strategy_default: Default tax calculation strategy
|
||||
tax_zone_default: Default tax zone
|
||||
theme: Theme
|
||||
hostname: Hostname
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ use Doctrine\Common\Collections\Collection;
|
|||
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
|
||||
use Sylius\Component\Addressing\Model\ZoneInterface;
|
||||
use Sylius\Component\Channel\Model\Channel as BaseChannel;
|
||||
use Sylius\Component\Core\Taxation\Strategy\TaxCalculationStrategyInterface;
|
||||
use Sylius\Component\Currency\Model\CurrencyInterface;
|
||||
use Sylius\Component\Locale\Model\LocaleInterface;
|
||||
use Sylius\Component\Payment\Model\PaymentMethodInterface;
|
||||
|
|
@ -42,6 +43,11 @@ class Channel extends BaseChannel implements ChannelInterface
|
|||
*/
|
||||
protected $defaultTaxZone;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $defaultTaxCalculationStrategy;
|
||||
|
||||
/**
|
||||
* @var CurrencyInterface[]|Collection
|
||||
*/
|
||||
|
|
@ -147,6 +153,22 @@ class Channel extends BaseChannel implements ChannelInterface
|
|||
$this->defaultTaxZone = $defaultTaxZone;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultTaxCalculationStrategy()
|
||||
{
|
||||
return $this->defaultTaxCalculationStrategy;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setDefaultTaxCalculationStrategy($taxCalculationStrategy)
|
||||
{
|
||||
$this->defaultTaxCalculationStrategy = $taxCalculationStrategy;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ namespace Sylius\Component\Core\Model;
|
|||
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
|
||||
use Sylius\Component\Addressing\Model\ZoneInterface;
|
||||
use Sylius\Component\Channel\Model\ChannelInterface as BaseChannelInterface;
|
||||
use Sylius\Component\Core\Taxation\Strategy\TaxCalculationStrategyInterface;
|
||||
use Sylius\Component\Currency\Model\CurrenciesAwareInterface;
|
||||
use Sylius\Component\Currency\Model\CurrencyInterface;
|
||||
use Sylius\Component\Locale\Model\LocaleInterface;
|
||||
|
|
@ -79,4 +80,14 @@ interface ChannelInterface extends
|
|||
* @param ZoneInterface $defaultTaxZone
|
||||
*/
|
||||
public function setDefaultTaxZone(ZoneInterface $defaultTaxZone);
|
||||
|
||||
/**
|
||||
* @return TaxCalculationStrategyInterface
|
||||
*/
|
||||
public function getDefaultTaxCalculationStrategy();
|
||||
|
||||
/**
|
||||
* @param string $taxCalculationStrategy
|
||||
*/
|
||||
public function setDefaultTaxCalculationStrategy($taxCalculationStrategy);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue