From f7cdb5522feec956a5964dbd97b444e89ea11448 Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Tue, 8 Jan 2019 15:45:03 +0100 Subject: [PATCH 1/6] Shop billing data on channel tests --- ...ing_channel_with_shop_billing_data.feature | 24 ++++++ ...iting_shop_billing_data_on_channel.feature | 22 ++++++ .../ManagingChannelsBillingDataContext.php | 79 +++++++++++++++++++ .../Admin/Channel/ShopBillingDataElement.php | 60 ++++++++++++++ .../ShopBillingDataElementInterface.php | 20 +++++ .../Behat/Page/Admin/Channel/UpdatePage.php | 20 ++--- .../Admin/Channel/UpdatePageInterface.php | 12 +-- .../Resources/config/services/contexts/ui.xml | 5 ++ .../Resources/config/services/elements.xml | 7 ++ .../elements/{shop/account.xml => admin.xml} | 6 +- .../config/services/elements/shop.xml | 8 +- .../suites/ui/channel/managing_channels.yml | 1 + 12 files changed, 240 insertions(+), 24 deletions(-) create mode 100644 features/channel/managing_channels/adding_channel_with_shop_billing_data.feature create mode 100644 features/channel/managing_channels/editing_shop_billing_data_on_channel.feature create mode 100644 src/Sylius/Behat/Context/Ui/Admin/ManagingChannelsBillingDataContext.php create mode 100644 src/Sylius/Behat/Element/Admin/Channel/ShopBillingDataElement.php create mode 100644 src/Sylius/Behat/Element/Admin/Channel/ShopBillingDataElementInterface.php rename src/Sylius/Behat/Resources/config/services/elements/{shop/account.xml => admin.xml} (62%) diff --git a/features/channel/managing_channels/adding_channel_with_shop_billing_data.feature b/features/channel/managing_channels/adding_channel_with_shop_billing_data.feature new file mode 100644 index 00000000000..9fa0eef7ff9 --- /dev/null +++ b/features/channel/managing_channels/adding_channel_with_shop_billing_data.feature @@ -0,0 +1,24 @@ +@managing_channels +Feature: Adding a new channel with shop billing data + In order to sell through multiple channels of distributions with specific billing data + As an Administrator + I want to add a new channel with shop billing data to the registry + + Background: + Given the store has currency "Euro" + And the store has locale "English (United States)" + And I am logged in as an administrator + + @ui + Scenario: Adding a new channel with shop billing data + Given I want to create a new channel + When I specify its code as "MOBILE" + And I name it "Mobile channel" + And I choose "Euro" as the base currency + And I choose "English (United States)" as a default locale + And I specify company as "Ragnarok" + And I specify tax ID as "1100110011" + And I specify shop billing address as "Pacific Coast Hwy", "90806" "Los Angeles", "United States" + And I add it + Then I should be notified that it has been successfully created + And the channel "Mobile channel" should appear in the registry diff --git a/features/channel/managing_channels/editing_shop_billing_data_on_channel.feature b/features/channel/managing_channels/editing_shop_billing_data_on_channel.feature new file mode 100644 index 00000000000..c4a8d4e9010 --- /dev/null +++ b/features/channel/managing_channels/editing_shop_billing_data_on_channel.feature @@ -0,0 +1,22 @@ +@managing_channels +Feature: Editing shop billing data on channel + In order to have proper shop billing data on shop-related documents + As an Administrator + I want to be able to edit shop billing data on a channel + + Background: + Given the store operates on a channel named "Web Store" + And the store ships to "United States" + And I am logged in as an administrator + + @ui + Scenario: Editing shop billing data on channel + When I want to modify a channel "Web Store" + And I specify company as "Ragnarok" + And I specify tax ID as "1100110011" + And I specify shop billing address as "Pacific Coast Hwy", "90806" "Los Angeles", "United States" + And I save my changes + Then I should be notified that it has been successfully edited + And this channel company should be "Ragnarok" + And this channel tax ID should be "1100110011" + And this channel shop billing address should be "Pacific Coast Hwy", "90806" "Los Angeles", "United States" diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingChannelsBillingDataContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingChannelsBillingDataContext.php new file mode 100644 index 00000000000..5f79ad787ad --- /dev/null +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingChannelsBillingDataContext.php @@ -0,0 +1,79 @@ +shopBillingDataElement = $shopBillingDataElement; + } + + /** + * @When I specify company as :company + */ + public function specifyCompanyAs(string $company): void + { + $this->shopBillingDataElement->specifyCompany($company); + } + + /** + * @When I specify tax ID as :taxId + */ + public function specifyTaxIdAs(string $taxId): void + { + $this->shopBillingDataElement->specifyTaxId($taxId); + } + + /** + * @When I specify shop billing address as :street, :postcode :city, :country + */ + public function specifyShopBillingAddressAs( + string $street, + string $postcode, + string $city, + CountryInterface $country + ): void + { + $this->shopBillingDataElement->specifyBillingAddress($street, $postcode, $city, $country->getCode()); + } + + /** + * @Then this channel company should be :company + */ + public function thisChannelCompanyShouldBe(string $company): void + { + Assert::true($this->shopBillingDataElement->hasCompany($company)); + } + + /** + * @Then this channel tax ID should be :taxId + */ + public function thisChanneTaxIdShouldBe(string $taxId): void + { + Assert::true($this->shopBillingDataElement->hasTaxId($taxId)); + } + + /** + * @Then this channel shop billing address should be :street, :postcode :city, :country + */ + public function thisChannelShopBillingAddressShouldBe( + string $street, + string $postcode, + string $city, + CountryInterface $country + ): void + { + Assert::true($this->shopBillingDataElement->hasBillingAddress($street, $postcode, $city, $country->getCode())); + } +} diff --git a/src/Sylius/Behat/Element/Admin/Channel/ShopBillingDataElement.php b/src/Sylius/Behat/Element/Admin/Channel/ShopBillingDataElement.php new file mode 100644 index 00000000000..a464e7589f0 --- /dev/null +++ b/src/Sylius/Behat/Element/Admin/Channel/ShopBillingDataElement.php @@ -0,0 +1,60 @@ +getElement('company')->setValue($company); + } + + public function specifyTaxId(string $taxId): void + { + $this->getElement('tax_id')->setValue($taxId); + } + + public function specifyBillingAddress(string $street, string $postcode, string $city, string $countryCode): void + { + $this->getElement('street')->setValue($street); + $this->getElement('postcode')->setValue($postcode); + $this->getElement('city')->setValue($city); + $this->getElement('country_code')->setValue($countryCode); + } + + public function hasCompany(string $company): bool + { + return $company === $this->getElement('company')->getValue(); + } + + public function hasTaxId(string $taxId): bool + { + return $taxId === $this->getElement('tax_id')->getValue(); + } + + public function hasBillingAddress(string $street, string $postcode, string $city, string $countryCode): bool + { + return + $street === $this->getElement('street')->getValue() && + $postcode === $this->getElement('postcode')->getValue() && + $city === $this->getElement('city')->getValue() && + $countryCode === $this->getElement('country_code')->getValue() + ; + } + + protected function getDefinedElements(): array + { + return array_merge(parent::getDefinedElements(), [ + 'city' => '#sylius_channel_billingData_city', + 'company' => '#sylius_channel_billingData_company', + 'country_code' => '#sylius_channel_billingData_countryCode', + 'postcode' => '#sylius_channel_billingData_postcode', + 'street' => '#sylius_channel_billingData_street', + 'tax_id' => '#sylius_channel_billingData_taxId', + ]); + } +} diff --git a/src/Sylius/Behat/Element/Admin/Channel/ShopBillingDataElementInterface.php b/src/Sylius/Behat/Element/Admin/Channel/ShopBillingDataElementInterface.php new file mode 100644 index 00000000000..8ffbd894d9c --- /dev/null +++ b/src/Sylius/Behat/Element/Admin/Channel/ShopBillingDataElementInterface.php @@ -0,0 +1,20 @@ +getDocument()->selectFieldOption('Locales', $language); } - public function isLocaleChosen(string $language): bool - { - return $this->getElement('locales')->find('named', ['option', $language])->hasAttribute('selected'); - } - public function chooseCurrency(string $currencyCode): void { $this->getDocument()->selectFieldOption('Currencies', $currencyCode); } - public function isCurrencyChosen(string $currencyCode): bool - { - return $this->getElement('currencies')->find('named', ['option', $currencyCode])->hasAttribute('selected'); - } - public function chooseDefaultTaxZone(string $taxZone): void { $this->getDocument()->selectFieldOption('Default tax zone', $taxZone); @@ -63,6 +53,16 @@ public function chooseTaxCalculationStrategy(string $taxZone): void $this->getDocument()->selectFieldOption('Tax calculation strategy', $taxZone); } + public function isLocaleChosen(string $language): bool + { + return $this->getElement('locales')->find('named', ['option', $language])->hasAttribute('selected'); + } + + public function isCurrencyChosen(string $currencyCode): bool + { + return $this->getElement('currencies')->find('named', ['option', $currencyCode])->hasAttribute('selected'); + } + public function isDefaultTaxZoneChosen(string $taxZone): bool { return $this->getElement('default_tax_zone')->find('named', ['option', $taxZone])->hasAttribute('selected'); diff --git a/src/Sylius/Behat/Page/Admin/Channel/UpdatePageInterface.php b/src/Sylius/Behat/Page/Admin/Channel/UpdatePageInterface.php index 118e37852cc..46e4f7f2d47 100644 --- a/src/Sylius/Behat/Page/Admin/Channel/UpdatePageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Channel/UpdatePageInterface.php @@ -29,20 +29,20 @@ public function setTheme(string $themeName): void; */ public function unsetTheme(): void; - public function isCodeDisabled(): bool; - public function chooseLocale(string $language): void; - public function isLocaleChosen(string $language): bool; - public function chooseCurrency(string $currencyCode): void; - public function isCurrencyChosen(string $currencyCode): bool; - public function chooseDefaultTaxZone(string $taxZone): void; public function chooseTaxCalculationStrategy(string $taxCalculationStrategy): void; + public function isCodeDisabled(): bool; + + public function isLocaleChosen(string $language): bool; + + public function isCurrencyChosen(string $currencyCode): bool; + public function isDefaultTaxZoneChosen(string $taxZone): bool; public function isAnyDefaultTaxZoneChosen(): bool; diff --git a/src/Sylius/Behat/Resources/config/services/contexts/ui.xml b/src/Sylius/Behat/Resources/config/services/contexts/ui.xml index 14186ef775d..4534276a3d3 100644 --- a/src/Sylius/Behat/Resources/config/services/contexts/ui.xml +++ b/src/Sylius/Behat/Resources/config/services/contexts/ui.xml @@ -49,6 +49,11 @@ + + + + + diff --git a/src/Sylius/Behat/Resources/config/services/elements.xml b/src/Sylius/Behat/Resources/config/services/elements.xml index cfafbe56339..9acb9ed3ddf 100644 --- a/src/Sylius/Behat/Resources/config/services/elements.xml +++ b/src/Sylius/Behat/Resources/config/services/elements.xml @@ -16,6 +16,13 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" > + + + + + %__behat__.mink.parameters% + + diff --git a/src/Sylius/Behat/Resources/config/services/elements/shop/account.xml b/src/Sylius/Behat/Resources/config/services/elements/admin.xml similarity index 62% rename from src/Sylius/Behat/Resources/config/services/elements/shop/account.xml rename to src/Sylius/Behat/Resources/config/services/elements/admin.xml index 19238829095..5fb4e7869a9 100644 --- a/src/Sylius/Behat/Resources/config/services/elements/shop/account.xml +++ b/src/Sylius/Behat/Resources/config/services/elements/admin.xml @@ -15,13 +15,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" > - - Sylius\Behat\Element\Shop\Account\RegisterElement - - - + diff --git a/src/Sylius/Behat/Resources/config/services/elements/shop.xml b/src/Sylius/Behat/Resources/config/services/elements/shop.xml index 9fb30a43182..369333fc170 100644 --- a/src/Sylius/Behat/Resources/config/services/elements/shop.xml +++ b/src/Sylius/Behat/Resources/config/services/elements/shop.xml @@ -15,7 +15,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" > - - - + + + + + diff --git a/src/Sylius/Behat/Resources/config/suites/ui/channel/managing_channels.yml b/src/Sylius/Behat/Resources/config/suites/ui/channel/managing_channels.yml index c563c0e1cd9..addac3aaa19 100644 --- a/src/Sylius/Behat/Resources/config/suites/ui/channel/managing_channels.yml +++ b/src/Sylius/Behat/Resources/config/suites/ui/channel/managing_channels.yml @@ -22,6 +22,7 @@ default: - sylius.behat.context.setup.zone - sylius.behat.context.ui.admin.managing_channels + - sylius.behat.context.ui.admin.managing_channels_billing_data - sylius.behat.context.ui.admin.notification filters: tags: "@managing_channels && @ui" From ea37635e60d9ff0bd47273978bbc6a3f3652cc75 Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Wed, 9 Jan 2019 10:04:25 +0100 Subject: [PATCH 2/6] ShopBillingData entity and Channel relation --- app/migrations/Version20190109091323.php | 34 ++++++ .../config/doctrine/model/Channel.orm.xml | 8 +- .../doctrine/model/ShopBillingData.orm.xml | 31 ++++++ src/Sylius/Component/Core/Model/Channel.php | 13 +++ .../Component/Core/Model/ChannelInterface.php | 4 + .../Component/Core/Model/ShopBillingData.php | 104 ++++++++++++++++++ .../Core/Model/ShopBillingDataInterface.php | 43 ++++++++ .../Core/spec/Model/ShopBillingDataSpec.php | 52 +++++++++ 8 files changed, 288 insertions(+), 1 deletion(-) create mode 100644 app/migrations/Version20190109091323.php create mode 100644 src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/ShopBillingData.orm.xml create mode 100644 src/Sylius/Component/Core/Model/ShopBillingData.php create mode 100644 src/Sylius/Component/Core/Model/ShopBillingDataInterface.php create mode 100644 src/Sylius/Component/Core/spec/Model/ShopBillingDataSpec.php diff --git a/app/migrations/Version20190109091323.php b/app/migrations/Version20190109091323.php new file mode 100644 index 00000000000..5516f10de7a --- /dev/null +++ b/app/migrations/Version20190109091323.php @@ -0,0 +1,34 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('CREATE TABLE sylius_shop_billing_data (id INT AUTO_INCREMENT NOT NULL, company VARCHAR(255) NOT NULL, taxId VARCHAR(255) NOT NULL, countryCode VARCHAR(255) NOT NULL, street VARCHAR(255) NOT NULL, city VARCHAR(255) NOT NULL, postcode VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 COLLATE UTF8_unicode_ci ENGINE = InnoDB'); + $this->addSql('ALTER TABLE sylius_channel ADD shop_billing_data_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE sylius_channel ADD CONSTRAINT FK_16C8119EB5282EDF FOREIGN KEY (shop_billing_data_id) REFERENCES sylius_shop_billing_data (id) ON DELETE CASCADE'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_16C8119EB5282EDF ON sylius_channel (shop_billing_data_id)'); + } + + public function down(Schema $schema) : void + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('ALTER TABLE sylius_channel DROP FOREIGN KEY FK_16C8119EB5282EDF'); + $this->addSql('DROP TABLE sylius_shop_billing_data'); + $this->addSql('DROP INDEX UNIQ_16C8119EB5282EDF ON sylius_channel'); + $this->addSql('ALTER TABLE sylius_channel DROP shop_billing_data_id'); + } +} diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/Channel.orm.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/Channel.orm.xml index 56ccb710218..e37f4de29e2 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/Channel.orm.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/Channel.orm.xml @@ -53,6 +53,12 @@ - + + + + + + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/ShopBillingData.orm.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/ShopBillingData.orm.xml new file mode 100644 index 00000000000..ab0f2f94fdf --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/ShopBillingData.orm.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/Sylius/Component/Core/Model/Channel.php b/src/Sylius/Component/Core/Model/Channel.php index 441fb134685..e37f022872c 100644 --- a/src/Sylius/Component/Core/Model/Channel.php +++ b/src/Sylius/Component/Core/Model/Channel.php @@ -55,6 +55,9 @@ class Channel extends BaseChannel implements ChannelInterface /** @var bool */ protected $accountVerificationRequired = true; + /** @var ShopBillingDataInterface|null */ + protected $shopBillingData; + public function __construct() { parent::__construct(); @@ -278,4 +281,14 @@ public function setAccountVerificationRequired(bool $accountVerificationRequired { $this->accountVerificationRequired = $accountVerificationRequired; } + + public function getShopBillingData(): ?ShopBillingDataInterface + { + return $this->shopBillingData; + } + + public function setShopBillingData(?ShopBillingDataInterface $shopBillingData): void + { + $this->shopBillingData = $shopBillingData; + } } diff --git a/src/Sylius/Component/Core/Model/ChannelInterface.php b/src/Sylius/Component/Core/Model/ChannelInterface.php index db2867c74db..1451e2c31a7 100644 --- a/src/Sylius/Component/Core/Model/ChannelInterface.php +++ b/src/Sylius/Component/Core/Model/ChannelInterface.php @@ -60,4 +60,8 @@ public function setSkippingPaymentStepAllowed(bool $skippingPaymentStepAllowed): public function isAccountVerificationRequired(): bool; public function setAccountVerificationRequired(bool $accountVerificationRequired): void; + + public function getShopBillingData(): ?ShopBillingDataInterface; + + public function setShopBillingData(?ShopBillingDataInterface $shopBillingData): void; } diff --git a/src/Sylius/Component/Core/Model/ShopBillingData.php b/src/Sylius/Component/Core/Model/ShopBillingData.php new file mode 100644 index 00000000000..3c02ec0e0e6 --- /dev/null +++ b/src/Sylius/Component/Core/Model/ShopBillingData.php @@ -0,0 +1,104 @@ +id; + } + + public function getCompany(): ?string + { + return $this->company; + } + + public function setCompany(?string $company): void + { + $this->company = $company; + } + + public function getTaxId(): ?string + { + return $this->taxId; + } + + public function setTaxId(?string $taxId): void + { + $this->taxId = $taxId; + } + + public function getCountryCode(): ?string + { + return $this->countryCode; + } + + public function setCountryCode(?string $countryCode): void + { + $this->countryCode = $countryCode; + } + + public function getStreet(): ?string + { + return $this->street; + } + + public function setStreet(?string $street): void + { + $this->street = $street; + } + + public function getCity(): ?string + { + return $this->city; + } + + public function setCity(?string $city): void + { + $this->city = $city; + } + + public function getPostcode(): ?string + { + return $this->postcode; + } + + public function setPostcode(?string $postcode): void + { + $this->postcode = $postcode; + } +} diff --git a/src/Sylius/Component/Core/Model/ShopBillingDataInterface.php b/src/Sylius/Component/Core/Model/ShopBillingDataInterface.php new file mode 100644 index 00000000000..4aa76a9185b --- /dev/null +++ b/src/Sylius/Component/Core/Model/ShopBillingDataInterface.php @@ -0,0 +1,43 @@ +shouldImplement(ShopBillingDataInterface::class); + } + + function its_company_is_mutable(): void + { + $this->setCompany('Ragnarok'); + $this->getCompany()->shouldReturn('Ragnarok'); + } + + function its_tax_id_is_mutable(): void + { + $this->setTaxId('1100110011'); + $this->getTaxId()->shouldReturn('1100110011'); + } + + function its_country_code_is_mutable(): void + { + $this->setCountryCode('US'); + $this->getCountryCode()->shouldReturn('US'); + } + + function its_street_is_mutable(): void + { + $this->setStreet('Blue Street'); + $this->getStreet()->shouldReturn('Blue Street'); + } + + function its_city_is_mutable(): void + { + $this->setCity('New York'); + $this->getCity()->shouldReturn('New York'); + } + + function its_postcode_is_mutable(): void + { + $this->setPostcode('94111'); + $this->getPostcode()->shouldReturn('94111'); + } +} From 1185ef8657c327190004e297be93e52c1ca05235 Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Wed, 9 Jan 2019 10:36:23 +0100 Subject: [PATCH 3/6] Shop billing data in channel form --- .../Resources/views/Channel/_form.html.twig | 15 ++++++ .../Form/Extension/ChannelTypeExtension.php | 4 ++ .../Form/Type/ShopBillingDataType.php | 47 +++++++++++++++++++ .../Resources/config/services/form.xml | 4 ++ .../Resources/translations/messages.en.yml | 8 ++++ 5 files changed, 78 insertions(+) create mode 100644 src/Sylius/Bundle/CoreBundle/Form/Type/ShopBillingDataType.php diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Channel/_form.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Channel/_form.html.twig index bcae809ff3d..cc49c904196 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Channel/_form.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Channel/_form.html.twig @@ -25,6 +25,21 @@ {{ form_row(form.themeName) }} +
+

{{ form_label(form.shopBillingData) }}

+
+ {{ form_row(form.shopBillingData.company) }} + {{ form_row(form.shopBillingData.taxId) }} +
+
+ {{ form_row(form.shopBillingData.countryCode) }} + {{ form_row(form.shopBillingData.street) }} +
+
+ {{ form_row(form.shopBillingData.city) }} + {{ form_row(form.shopBillingData.postcode) }} +
+
diff --git a/src/Sylius/Bundle/CoreBundle/Form/Extension/ChannelTypeExtension.php b/src/Sylius/Bundle/CoreBundle/Form/Extension/ChannelTypeExtension.php index 5d0ae50824b..4aeb887c3b2 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Extension/ChannelTypeExtension.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Extension/ChannelTypeExtension.php @@ -17,6 +17,7 @@ use Sylius\Bundle\ChannelBundle\Form\Type\ChannelType; use Sylius\Bundle\CoreBundle\Form\EventSubscriber\AddBaseCurrencySubscriber; use Sylius\Bundle\CoreBundle\Form\EventSubscriber\ChannelFormSubscriber; +use Sylius\Bundle\CoreBundle\Form\Type\ShopBillingDataType; use Sylius\Bundle\CoreBundle\Form\Type\TaxCalculationStrategyChoiceType; use Sylius\Bundle\CurrencyBundle\Form\Type\CurrencyChoiceType; use Sylius\Bundle\LocaleBundle\Form\Type\LocaleChoiceType; @@ -80,6 +81,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'label' => 'sylius.form.channel.account_verification_required', 'required' => false, ]) + ->add('shopBillingData', ShopBillingDataType::class, [ + 'label' => 'sylius.form.channel.shop_billing_data', + ]) ->addEventSubscriber(new AddBaseCurrencySubscriber()) ->addEventSubscriber(new ChannelFormSubscriber()) ; diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/ShopBillingDataType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/ShopBillingDataType.php new file mode 100644 index 00000000000..781d86c1b25 --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/ShopBillingDataType.php @@ -0,0 +1,47 @@ +add('taxId', TextType::class, [ + 'label' => 'sylius.form.channel.billing_data.tax_id', + 'required' => false, + ]) + ->add('company', TextType::class, [ + 'required' => false, + 'label' => 'sylius.form.channel.billing_data.company', + ]) + ->add('countryCode', CountryCodeChoiceType::class, [ + 'label' => 'sylius.form.channel.billing_data.country', + 'enabled' => true, + ]) + ->add('street', TextType::class, [ + 'label' => 'sylius.form.channel.billing_data.street', + ]) + ->add('city', TextType::class, [ + 'label' => 'sylius.form.channel.billing_data.city', + ]) + ->add('postcode', TextType::class, [ + 'label' => 'sylius.form.channel.billing_data.postcode', + ]) + ; + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefault('data_class', ShopBillingData::class); + } +} diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/form.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/form.xml index de59fb4e37b..0aca1d0b92c 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/form.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/form.xml @@ -241,6 +241,10 @@ + + + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/translations/messages.en.yml b/src/Sylius/Bundle/CoreBundle/Resources/translations/messages.en.yml index 7f87f59cb44..2c56f1e0f88 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Sylius/Bundle/CoreBundle/Resources/translations/messages.en.yml @@ -22,6 +22,13 @@ sylius: name: Name roles: Roles channel: + billing_data: + city: City + company: Company + country: Country + postcode: Postcode + street: Street + tax_id: Tax ID contact_email: Contact email currencies: Currencies currency_base: Base currency @@ -31,6 +38,7 @@ sylius: locales: Locales payment_methods: Payment Methods shipping_methods: Shipping Methods + shop_billing_data: Shop billing data skipping_shipping_step_allowed: Skip shipping step if only one shipping method is available? skipping_payment_step_allowed: Skip payment step if only one payment method is available? tax_calculation_strategy: Tax calculation strategy From 0848c16074c707e57fa981fe7ae838c820e0f731 Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Wed, 9 Jan 2019 10:57:17 +0100 Subject: [PATCH 4/6] Tests fixes and nullable fields --- ...0190109091323.php => Version20190109095211.php} | 4 ++-- .../adding_channel_with_shop_billing_data.feature | 1 + .../Admin/Channel/ShopBillingDataElement.php | 12 ++++++------ .../config/suites/ui/channel/managing_channels.yml | 3 +++ .../CoreBundle/Form/Type/ShopBillingDataType.php | 14 +++++++++++++- .../config/doctrine/model/ShopBillingData.orm.xml | 12 ++++++------ .../CoreBundle/Resources/config/services/form.xml | 2 ++ .../channel/create_validation_fail_response.json | 10 ++++++++++ .../channel/update_validation_fail_response.json | 10 ++++++++++ 9 files changed, 53 insertions(+), 15 deletions(-) rename app/migrations/{Version20190109091323.php => Version20190109095211.php} (79%) diff --git a/app/migrations/Version20190109091323.php b/app/migrations/Version20190109095211.php similarity index 79% rename from app/migrations/Version20190109091323.php rename to app/migrations/Version20190109095211.php index 5516f10de7a..14f74ca9310 100644 --- a/app/migrations/Version20190109091323.php +++ b/app/migrations/Version20190109095211.php @@ -8,14 +8,14 @@ /** * Auto-generated Migration: Please modify to your needs! */ -final class Version20190109091323 extends AbstractMigration +final class Version20190109095211 extends AbstractMigration { public function up(Schema $schema) : void { // this up() migration is auto-generated, please modify it to your needs $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); - $this->addSql('CREATE TABLE sylius_shop_billing_data (id INT AUTO_INCREMENT NOT NULL, company VARCHAR(255) NOT NULL, taxId VARCHAR(255) NOT NULL, countryCode VARCHAR(255) NOT NULL, street VARCHAR(255) NOT NULL, city VARCHAR(255) NOT NULL, postcode VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 COLLATE UTF8_unicode_ci ENGINE = InnoDB'); + $this->addSql('CREATE TABLE sylius_shop_billing_data (id INT AUTO_INCREMENT NOT NULL, company VARCHAR(255) DEFAULT NULL, taxId VARCHAR(255) DEFAULT NULL, countryCode VARCHAR(255) DEFAULT NULL, street VARCHAR(255) DEFAULT NULL, city VARCHAR(255) DEFAULT NULL, postcode VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 COLLATE UTF8_unicode_ci ENGINE = InnoDB'); $this->addSql('ALTER TABLE sylius_channel ADD shop_billing_data_id INT DEFAULT NULL'); $this->addSql('ALTER TABLE sylius_channel ADD CONSTRAINT FK_16C8119EB5282EDF FOREIGN KEY (shop_billing_data_id) REFERENCES sylius_shop_billing_data (id) ON DELETE CASCADE'); $this->addSql('CREATE UNIQUE INDEX UNIQ_16C8119EB5282EDF ON sylius_channel (shop_billing_data_id)'); diff --git a/features/channel/managing_channels/adding_channel_with_shop_billing_data.feature b/features/channel/managing_channels/adding_channel_with_shop_billing_data.feature index 9fa0eef7ff9..cd188fc7992 100644 --- a/features/channel/managing_channels/adding_channel_with_shop_billing_data.feature +++ b/features/channel/managing_channels/adding_channel_with_shop_billing_data.feature @@ -7,6 +7,7 @@ Feature: Adding a new channel with shop billing data Background: Given the store has currency "Euro" And the store has locale "English (United States)" + And the store operates in "United States" And I am logged in as an administrator @ui diff --git a/src/Sylius/Behat/Element/Admin/Channel/ShopBillingDataElement.php b/src/Sylius/Behat/Element/Admin/Channel/ShopBillingDataElement.php index a464e7589f0..7209c8c993d 100644 --- a/src/Sylius/Behat/Element/Admin/Channel/ShopBillingDataElement.php +++ b/src/Sylius/Behat/Element/Admin/Channel/ShopBillingDataElement.php @@ -49,12 +49,12 @@ public function hasBillingAddress(string $street, string $postcode, string $city protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ - 'city' => '#sylius_channel_billingData_city', - 'company' => '#sylius_channel_billingData_company', - 'country_code' => '#sylius_channel_billingData_countryCode', - 'postcode' => '#sylius_channel_billingData_postcode', - 'street' => '#sylius_channel_billingData_street', - 'tax_id' => '#sylius_channel_billingData_taxId', + 'city' => '#sylius_channel_shopBillingData_city', + 'company' => '#sylius_channel_shopBillingData_company', + 'country_code' => '#sylius_channel_shopBillingData_countryCode', + 'postcode' => '#sylius_channel_shopBillingData_postcode', + 'street' => '#sylius_channel_shopBillingData_street', + 'tax_id' => '#sylius_channel_shopBillingData_taxId', ]); } } diff --git a/src/Sylius/Behat/Resources/config/suites/ui/channel/managing_channels.yml b/src/Sylius/Behat/Resources/config/suites/ui/channel/managing_channels.yml index addac3aaa19..77c981a0482 100644 --- a/src/Sylius/Behat/Resources/config/suites/ui/channel/managing_channels.yml +++ b/src/Sylius/Behat/Resources/config/suites/ui/channel/managing_channels.yml @@ -7,7 +7,9 @@ default: contexts_services: - sylius.behat.context.hook.doctrine_orm + - sylius.behat.context.transform.address - sylius.behat.context.transform.channel + - sylius.behat.context.transform.country - sylius.behat.context.transform.currency - sylius.behat.context.transform.locale - sylius.behat.context.transform.shared_storage @@ -15,6 +17,7 @@ default: - sylius.behat.context.setup.channel - sylius.behat.context.setup.currency + - sylius.behat.context.setup.geographical - sylius.behat.context.setup.locale - sylius.behat.context.setup.payment - sylius.behat.context.setup.admin_security diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/ShopBillingDataType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/ShopBillingDataType.php index 781d86c1b25..cb98bab3dec 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Type/ShopBillingDataType.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/ShopBillingDataType.php @@ -13,6 +13,14 @@ final class ShopBillingDataType extends AbstractType { + /** @var string */ + private $dataClass; + + public function __construct(string $dataClass) + { + $this->dataClass = $dataClass; + } + public function buildForm(FormBuilderInterface $builder, array $options): void { $builder @@ -27,21 +35,25 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('countryCode', CountryCodeChoiceType::class, [ 'label' => 'sylius.form.channel.billing_data.country', 'enabled' => true, + 'required' => false, ]) ->add('street', TextType::class, [ 'label' => 'sylius.form.channel.billing_data.street', + 'required' => false, ]) ->add('city', TextType::class, [ 'label' => 'sylius.form.channel.billing_data.city', + 'required' => false, ]) ->add('postcode', TextType::class, [ 'label' => 'sylius.form.channel.billing_data.postcode', + 'required' => false, ]) ; } public function configureOptions(OptionsResolver $resolver) { - $resolver->setDefault('data_class', ShopBillingData::class); + $resolver->setDefault('data_class', $this->dataClass); } } diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/ShopBillingData.orm.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/ShopBillingData.orm.xml index ab0f2f94fdf..7b5286a647d 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/ShopBillingData.orm.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/ShopBillingData.orm.xml @@ -21,11 +21,11 @@ - - - - - - + + + + + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/form.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/form.xml index 0aca1d0b92c..4a5e4dc13c0 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/form.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/form.xml @@ -48,6 +48,7 @@ sylius + Sylius\Component\Core\Model\ShopBillingData @@ -242,6 +243,7 @@ + %sylius.model.shop_billing_data.class% diff --git a/tests/Responses/Expected/channel/create_validation_fail_response.json b/tests/Responses/Expected/channel/create_validation_fail_response.json index f135f8e205a..837984a1a9d 100644 --- a/tests/Responses/Expected/channel/create_validation_fail_response.json +++ b/tests/Responses/Expected/channel/create_validation_fail_response.json @@ -34,6 +34,16 @@ "skippingShippingStepAllowed": {}, "skippingPaymentStepAllowed": {}, "accountVerificationRequired": {}, + "shopBillingData": { + "children": { + "taxId": {}, + "company": {}, + "countryCode": {}, + "street": {}, + "city": {}, + "postcode": {} + } + }, "code": { "errors": [ "Please enter channel code." diff --git a/tests/Responses/Expected/channel/update_validation_fail_response.json b/tests/Responses/Expected/channel/update_validation_fail_response.json index a945736d1ad..6a80359e715 100644 --- a/tests/Responses/Expected/channel/update_validation_fail_response.json +++ b/tests/Responses/Expected/channel/update_validation_fail_response.json @@ -26,6 +26,16 @@ "skippingShippingStepAllowed": {}, "skippingPaymentStepAllowed": {}, "accountVerificationRequired": {}, + "shopBillingData": { + "children": { + "taxId": {}, + "company": {}, + "countryCode": {}, + "street": {}, + "city": {}, + "postcode": {} + } + }, "code": {}, "baseCurrency": {} } From 801247abb80c5feaa357073987beb770a9a6eada Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Thu, 10 Jan 2019 09:28:53 +0100 Subject: [PATCH 5/6] PR review changes --- .../Context/Ui/Admin/ManagingChannelsBillingDataContext.php | 6 ++---- .../Resources/config/doctrine/model/Channel.orm.xml | 2 +- src/Sylius/Component/Core/Model/Channel.php | 5 +++-- src/Sylius/Component/Core/Model/ChannelInterface.php | 4 ++-- .../Component/Core/Model/ShopBillingDataInterface.php | 2 -- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingChannelsBillingDataContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingChannelsBillingDataContext.php index 5f79ad787ad..5509e784de7 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingChannelsBillingDataContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingChannelsBillingDataContext.php @@ -43,8 +43,7 @@ public function specifyShopBillingAddressAs( string $postcode, string $city, CountryInterface $country - ): void - { + ): void { $this->shopBillingDataElement->specifyBillingAddress($street, $postcode, $city, $country->getCode()); } @@ -72,8 +71,7 @@ public function thisChannelShopBillingAddressShouldBe( string $postcode, string $city, CountryInterface $country - ): void - { + ): void { Assert::true($this->shopBillingDataElement->hasBillingAddress($street, $postcode, $city, $country->getCode())); } } diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/Channel.orm.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/Channel.orm.xml index e37f4de29e2..ac02d81001b 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/Channel.orm.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/Channel.orm.xml @@ -57,7 +57,7 @@ - + diff --git a/src/Sylius/Component/Core/Model/Channel.php b/src/Sylius/Component/Core/Model/Channel.php index e37f022872c..a6624b51dd6 100644 --- a/src/Sylius/Component/Core/Model/Channel.php +++ b/src/Sylius/Component/Core/Model/Channel.php @@ -64,6 +64,7 @@ public function __construct() $this->currencies = new ArrayCollection(); $this->locales = new ArrayCollection(); + $this->shopBillingData = new ShopBillingData(); } /** @@ -282,12 +283,12 @@ public function setAccountVerificationRequired(bool $accountVerificationRequired $this->accountVerificationRequired = $accountVerificationRequired; } - public function getShopBillingData(): ?ShopBillingDataInterface + public function getShopBillingData(): ShopBillingDataInterface { return $this->shopBillingData; } - public function setShopBillingData(?ShopBillingDataInterface $shopBillingData): void + public function setShopBillingData(ShopBillingDataInterface $shopBillingData): void { $this->shopBillingData = $shopBillingData; } diff --git a/src/Sylius/Component/Core/Model/ChannelInterface.php b/src/Sylius/Component/Core/Model/ChannelInterface.php index 1451e2c31a7..439ae2a91cf 100644 --- a/src/Sylius/Component/Core/Model/ChannelInterface.php +++ b/src/Sylius/Component/Core/Model/ChannelInterface.php @@ -61,7 +61,7 @@ public function isAccountVerificationRequired(): bool; public function setAccountVerificationRequired(bool $accountVerificationRequired): void; - public function getShopBillingData(): ?ShopBillingDataInterface; + public function getShopBillingData(): ShopBillingDataInterface; - public function setShopBillingData(?ShopBillingDataInterface $shopBillingData): void; + public function setShopBillingData(ShopBillingDataInterface $shopBillingData): void; } diff --git a/src/Sylius/Component/Core/Model/ShopBillingDataInterface.php b/src/Sylius/Component/Core/Model/ShopBillingDataInterface.php index 4aa76a9185b..42424f66d01 100644 --- a/src/Sylius/Component/Core/Model/ShopBillingDataInterface.php +++ b/src/Sylius/Component/Core/Model/ShopBillingDataInterface.php @@ -15,8 +15,6 @@ interface ShopBillingDataInterface { - public function getId(): ?int; - public function getTaxId(): ?string; public function setTaxId(?string $taxId): void; From cfdca1e8363abf739f2a601021171d6f6a1d7dd1 Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Thu, 10 Jan 2019 12:27:34 +0100 Subject: [PATCH 6/6] Change column names to fulfill conventions --- app/migrations/Version20190109095211.php | 2 +- .../doctrine/model/ShopBillingData.orm.xml | 4 ++-- .../Component/Core/Model/ShopBillingData.php | 19 +++++++------------ 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/app/migrations/Version20190109095211.php b/app/migrations/Version20190109095211.php index 14f74ca9310..c6a637bb742 100644 --- a/app/migrations/Version20190109095211.php +++ b/app/migrations/Version20190109095211.php @@ -15,7 +15,7 @@ public function up(Schema $schema) : void // this up() migration is auto-generated, please modify it to your needs $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); - $this->addSql('CREATE TABLE sylius_shop_billing_data (id INT AUTO_INCREMENT NOT NULL, company VARCHAR(255) DEFAULT NULL, taxId VARCHAR(255) DEFAULT NULL, countryCode VARCHAR(255) DEFAULT NULL, street VARCHAR(255) DEFAULT NULL, city VARCHAR(255) DEFAULT NULL, postcode VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 COLLATE UTF8_unicode_ci ENGINE = InnoDB'); + $this->addSql('CREATE TABLE sylius_shop_billing_data (id INT AUTO_INCREMENT NOT NULL, company VARCHAR(255) DEFAULT NULL, tax_id VARCHAR(255) DEFAULT NULL, country_code VARCHAR(255) DEFAULT NULL, street VARCHAR(255) DEFAULT NULL, city VARCHAR(255) DEFAULT NULL, postcode VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 COLLATE UTF8_unicode_ci ENGINE = InnoDB'); $this->addSql('ALTER TABLE sylius_channel ADD shop_billing_data_id INT DEFAULT NULL'); $this->addSql('ALTER TABLE sylius_channel ADD CONSTRAINT FK_16C8119EB5282EDF FOREIGN KEY (shop_billing_data_id) REFERENCES sylius_shop_billing_data (id) ON DELETE CASCADE'); $this->addSql('CREATE UNIQUE INDEX UNIQ_16C8119EB5282EDF ON sylius_channel (shop_billing_data_id)'); diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/ShopBillingData.orm.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/ShopBillingData.orm.xml index 7b5286a647d..7eb88cc76df 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/ShopBillingData.orm.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/ShopBillingData.orm.xml @@ -22,8 +22,8 @@ - - + + diff --git a/src/Sylius/Component/Core/Model/ShopBillingData.php b/src/Sylius/Component/Core/Model/ShopBillingData.php index 3c02ec0e0e6..064ed9be888 100644 --- a/src/Sylius/Component/Core/Model/ShopBillingData.php +++ b/src/Sylius/Component/Core/Model/ShopBillingData.php @@ -17,30 +17,25 @@ class ShopBillingData implements ShopBillingDataInterface { /** @var int|null */ - private $id; + protected $id; /** @var string|null */ - private $company; + protected $company; /** @var string|null */ - private $taxId; + protected $taxId; /** @var string|null */ - private $countryCode; + protected $countryCode; /** @var string|null */ - private $street; + protected $street; /** @var string|null */ - private $city; + protected $city; /** @var string|null */ - private $postcode; - - public function getId(): ?int - { - return $this->id; - } + protected $postcode; public function getCompany(): ?string {