Skip to content

Commit

Permalink
feature Sylius#10079 [Channel] Shop billing data (Zales0123)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.4-dev branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | master
| Bug fix?        | no
| New feature?    | yes
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | associated with Sylius/RefundPlugin#106, Sylius/InvoicingPlugin#52
| License         | MIT

During the development of `InvoicingPlugin`, we introduced a concept of shop billing data (set per channel) that is required to be displayed on an invoice. On the other hand, we also should have it in a `RefundPlugin` to generate a credit memo properly.

We considered a few options, but in the end, it's quite a common use case to have such a bunch of data manageable in Admin panel.

<img width="563" alt="zrzut ekranu 2019-01-9 o 11 04 31" src="https://user-images.githubusercontent.com/6212718/50892815-a35ed480-13ff-11e9-81e7-d5a96c6f8e28.png">


Commits
-------

f7cdb55 Shop billing data on channel tests
ea37635 ShopBillingData entity and Channel relation
1185ef8 Shop billing data in channel form
0848c16 Tests fixes and nullable fields
801247a PR review changes
cfdca1e Change column names to fulfill conventions
  • Loading branch information
pamil authored Jan 10, 2019
2 parents d0e9edd + cfdca1e commit 400cba3
Show file tree
Hide file tree
Showing 27 changed files with 636 additions and 25 deletions.
34 changes: 34 additions & 0 deletions app/migrations/Version20190109095211.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types=1);

namespace Sylius\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
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) 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)');
}

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');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@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 the store operates in "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
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

declare(strict_types=1);

namespace Sylius\Behat\Context\Ui\Admin;

use Behat\Behat\Context\Context;
use Sylius\Behat\Element\Admin\Channel\ShopBillingDataElementInterface;
use Sylius\Component\Addressing\Model\CountryInterface;
use Webmozart\Assert\Assert;

final class ManagingChannelsBillingDataContext implements Context
{
/** @var ShopBillingDataElementInterface */
private $shopBillingDataElement;

public function __construct(ShopBillingDataElementInterface $shopBillingDataElement)
{
$this->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()));
}
}
60 changes: 60 additions & 0 deletions src/Sylius/Behat/Element/Admin/Channel/ShopBillingDataElement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

namespace Sylius\Behat\Element\Admin\Channel;

use FriendsOfBehat\PageObjectExtension\Element\Element;

final class ShopBillingDataElement extends Element implements ShopBillingDataElementInterface
{
public function specifyCompany(string $company): void
{
$this->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_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',
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Sylius\Behat\Element\Admin\Channel;

interface ShopBillingDataElementInterface
{
public function specifyCompany(string $company): void;

public function specifyTaxId(string $taxId): void;

public function specifyBillingAddress(string $street, string $postcode, string $city, string $countryCode): void;

public function hasCompany(string $company): bool;

public function hasTaxId(string $taxId): bool;

public function hasBillingAddress(string $street, string $postcode, string $city, string $countryCode): bool;
}
20 changes: 10 additions & 10 deletions src/Sylius/Behat/Page/Admin/Channel/UpdatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,11 @@ public function chooseLocale(string $language): void
$this->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);
Expand All @@ -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');
Expand Down
12 changes: 6 additions & 6 deletions src/Sylius/Behat/Page/Admin/Channel/UpdatePageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/Sylius/Behat/Resources/config/services/contexts/ui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
<tag name="fob.context_service" />
</service>

<service id="sylius.behat.context.ui.admin.managing_channels_billing_data" class="Sylius\Behat\Context\Ui\Admin\ManagingChannelsBillingDataContext">
<argument type="service" id="sylius.behat.element.admin.channel.shop_billing_data" />
<tag name="fob.context_service" />
</service>

<service id="sylius.behat.context.ui.admin.managing_countries" class="Sylius\Behat\Context\Ui\Admin\ManagingCountriesContext">
<argument type="service" id="sylius.behat.page.admin.country.index" />
<argument type="service" id="sylius.behat.page.admin.country.create" />
Expand Down
7 changes: 7 additions & 0 deletions src/Sylius/Behat/Resources/config/services/elements.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"
>
<imports>
<import resource="elements/admin.xml" />
<import resource="elements/shop.xml" />
</imports>
<services>
<service id="sylius.behat.element" class="FriendsOfBehat\PageObjectExtension\Element\Element" abstract="true" public="false">
<argument type="service" id="mink.default_session" />
<argument>%__behat__.mink.parameters%</argument>
</service>
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
<parameters>
<parameter key="sylius.behat.element.shop.account.register.class">Sylius\Behat\Element\Shop\Account\RegisterElement</parameter>
</parameters>

<services>
<defaults public="true" />

<service id="sylius.behat.element.shop.account.register" class="%sylius.behat.element.shop.account.register.class%" parent="sylius.behat.symfony_page" public="false" />
<service id="sylius.behat.element.admin.channel.shop_billing_data" class="Sylius\Behat\Element\Admin\Channel\ShopBillingDataElement" parent="sylius.behat.element" public="false" />
</services>
</container>
8 changes: 5 additions & 3 deletions src/Sylius/Behat/Resources/config/services/elements/shop.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
<imports>
<import resource="shop/account.xml" />
</imports>
<services>
<defaults public="true" />

<service id="sylius.behat.element.shop.account.register" class="Sylius\Behat\Element\Shop\Account\RegisterElement" parent="sylius.behat.element" public="false" />
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@ 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
- sylius.behat.context.transform.zone

- 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
- sylius.behat.context.setup.shipping
- 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"
Loading

0 comments on commit 400cba3

Please sign in to comment.