forked from Sylius/Sylius
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature Sylius#10079 [Channel] Shop billing data (Zales0123)
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
Showing
27 changed files
with
636 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
features/channel/managing_channels/adding_channel_with_shop_billing_data.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
22 changes: 22 additions & 0 deletions
22
features/channel/managing_channels/editing_shop_billing_data_on_channel.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
77 changes: 77 additions & 0 deletions
77
src/Sylius/Behat/Context/Ui/Admin/ManagingChannelsBillingDataContext.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
60
src/Sylius/Behat/Element/Admin/Channel/ShopBillingDataElement.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
]); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Sylius/Behat/Element/Admin/Channel/ShopBillingDataElementInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.