diff --git a/etc/behat/services/contexts/ui.xml b/etc/behat/services/contexts/ui.xml index 61ce38308f..bdf7079f2a 100644 --- a/etc/behat/services/contexts/ui.xml +++ b/etc/behat/services/contexts/ui.xml @@ -23,6 +23,8 @@ Sylius\Behat\Context\Ui\Admin\ManagingProductOptionsContext Sylius\Behat\Context\Ui\Admin\ManagingPromotionsContext Sylius\Behat\Context\Ui\Admin\ManagingShippingMethodsContext + Sylius\Behat\Context\Ui\Admin\ManagingTaxonsContext + Sylius\Behat\Context\Ui\Admin\ManagingTaxCategoryContext Sylius\Behat\Context\Ui\Admin\ManagingTaxCategoriesContext Sylius\Behat\Context\Ui\Admin\ManagingTaxRateContext Sylius\Behat\Context\Ui\Admin\ManagingZonesContext @@ -128,6 +130,14 @@ + + + + + + + + diff --git a/etc/behat/services/pages.xml b/etc/behat/services/pages.xml index 369e928e6d..7366142147 100644 --- a/etc/behat/services/pages.xml +++ b/etc/behat/services/pages.xml @@ -67,6 +67,9 @@ Sylius\Behat\Page\Admin\ShippingMethod\CreatePage %sylius.behat.page.admin.crud.index.class% Sylius\Behat\Page\Admin\ShippingMethod\UpdatePage + Sylius\Behat\Page\Admin\Taxon\CreatePage + %sylius.behat.page.admin.crud.index.class% + Sylius\Behat\Page\Admin\Taxon\UpdatePage Sylius\Behat\Page\Admin\TaxCategory\CreatePage %sylius.behat.page.admin.crud.index.class% Sylius\Behat\Page\Admin\TaxCategory\UpdatePage @@ -169,6 +172,15 @@ shipping_method + + taxon + + + taxon + + + taxon + tax_category diff --git a/etc/behat/suites.yml b/etc/behat/suites.yml index 70cc518d51..c72593c9ef 100644 --- a/etc/behat/suites.yml +++ b/etc/behat/suites.yml @@ -57,6 +57,7 @@ imports: - suites/ui/taxation/applying_taxes.yml - suites/ui/taxation/managing_tax_categories.yml - suites/ui/taxation/managing_tax_rates.yml + - suites/ui/taxonomy/managing_taxons.yml - suites/ui/user/managing_customers.yml - suites/ui/user/managing_users.yml - suites/ui/user/registering.yml diff --git a/etc/behat/suites/ui/taxonomy/managing_taxons.yml b/etc/behat/suites/ui/taxonomy/managing_taxons.yml new file mode 100644 index 0000000000..f38eb7eca5 --- /dev/null +++ b/etc/behat/suites/ui/taxonomy/managing_taxons.yml @@ -0,0 +1,19 @@ +# This file is part of the Sylius package. +# (c) Paweł Jędrzejewski + +default: + suites: + ui_managing_taxons: + contexts_as_services: + - sylius.behat.context.hook.doctrine_orm + + - sylius.behat.context.transform.locale + - sylius.behat.context.transform.taxon + + - sylius.behat.context.setup.channel + - sylius.behat.context.setup.security + - sylius.behat.context.setup.taxonomy + + - sylius.behat.context.ui.admin.managing_taxons + filters: + tags: "@managing_taxons && @ui" diff --git a/features/taxonomy/managing_taxons/adding_taxon.feature b/features/taxonomy/managing_taxons/adding_taxon.feature index 26da091dad..d8d29f97d6 100644 --- a/features/taxonomy/managing_taxons/adding_taxon.feature +++ b/features/taxonomy/managing_taxons/adding_taxon.feature @@ -1,4 +1,4 @@ -@managing_taxonomy +@managing_taxons Feature: Adding a new taxon In order to categorize my merchandise As an Administrator @@ -6,11 +6,35 @@ Feature: Adding a new taxon Background: Given the store operates on a single channel in "France" + And I am logged in as an administrator + @ui Scenario: Adding a new taxon Given I want to create a new taxon - When I specify its code as "CATEGORY" - And I name it "Category" in "English (United States)" + When I specify its code as "t-shirts" + And I name it "T-Shirts" in "English (United States)" And I add it Then I should be notified that it has been successfully created - And the "Category" taxon should appear in the registry + And the "T-Shirts" taxon should appear in the registry + + @ui + Scenario: Adding a new taxon with permalink and description + Given I want to create a new taxon + When I specify its code as "category" + And I name it "Category" in "English (United States)" + And I specify its permalink as "category" in "English (United States)" + And I describe it as "Main taxonomy for products." in "English (United States)" + And I add it + Then I should be notified that it has been successfully created + And the "Category" taxon with "category" permalink and "Main taxonomy for products." description should appear in the registry + + @ui + Scenario: Adding a new taxon with parent taxon + Given the store classifies its products as "Category" + And I want to create a new taxon + When I specify its code as "stickers" + And I name it "Stickers" in "English (United States)" + And I choose "Category" as a parent taxon + And I add it + Then I should be notified that it has been successfully created + And the "Stickers" taxon with "Category" parent taxon should appear in the registry diff --git a/src/Sylius/Behat/Context/Transform/TaxonContext.php b/src/Sylius/Behat/Context/Transform/TaxonContext.php index 8fb57ca4a1..8351b4a782 100644 --- a/src/Sylius/Behat/Context/Transform/TaxonContext.php +++ b/src/Sylius/Behat/Context/Transform/TaxonContext.php @@ -35,6 +35,9 @@ final class TaxonContext implements Context /** * @Transform /^classified as "([^"]+)"$/ * @Transform /^belongs to "([^"]+)"$/ + * @Transform /^"([^"]+)" taxon$/ + * @Transform /^"([^"]+)" as a parent taxon$/ + * @Transform /^"([^"]+)" parent taxon$/ */ public function getTaxonByName($taxonName) { diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingTaxonsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingTaxonsContext.php new file mode 100644 index 0000000000..180411d432 --- /dev/null +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingTaxonsContext.php @@ -0,0 +1,168 @@ + + */ +final class ManagingTaxonsContext implements Context +{ + const RESOURCE_NAME = 'taxon'; + + /** + * @var CreatePageInterface + */ + private $createPage; + + /** + * @var IndexPageInterface + */ + private $indexPage; + + /** + * @var UpdatePageInterface + */ + private $updatePage; + + /** + * @var NotificationCheckerInterface + */ + private $notificationChecker; + + /** + * @param CreatePageInterface $createPage + * @param IndexPageInterface $indexPage + * @param UpdatePageInterface $updatePage + * @param NotificationCheckerInterface $notificationChecker + */ + public function __construct( + CreatePageInterface $createPage, + IndexPageInterface $indexPage, + UpdatePageInterface $updatePage, + NotificationCheckerInterface $notificationChecker + ) { + $this->createPage = $createPage; + $this->indexPage = $indexPage; + $this->updatePage = $updatePage; + $this->notificationChecker = $notificationChecker; + } + + /** + * @Given I want to create a new taxon + */ + public function iWantToCreateANewTaxon() + { + $this->createPage->open(); + } + + /** + * @When I specify its code as :code + */ + public function iSpecifyItsCodeAs($code) + { + $this->createPage->specifyCode($code); + } + + /** + * @When I name it :name in :language + * @When I rename it to :name in :language + */ + public function iNameItIn($name, $language) + { + $this->createPage->nameIt($name, $language); + } + + /** + * @When I specify its permalink as :permalink in :language + */ + public function iSpecifyItsPermalinkAs($permalink, $language) + { + $this->createPage->specifyPermalink($permalink, $language); + } + + /** + * @When I describe it as :description in :language + */ + public function iDescribeItAs($description, $language) + { + $this->createPage->describeItAs($description, $language); + } + + /** + * @Given /^I choose ("[^"]+" as a parent taxon)$/ + */ + public function iChooseAsAParentTaxon(TaxonInterface $taxon) + { + $this->createPage->chooseParent($taxon); + } + + /** + * @When I add it + * @When I try to add it + */ + public function iAddIt() + { + $this->createPage->create(); + } + + /** + * @Then I should be notified that it has been successfully created + */ + public function iShouldBeNotifiedItHasBeenSuccessfullyCreated() + { + $this->notificationChecker->checkCreationNotification(self::RESOURCE_NAME); + } + + /** + * @Then /^the ("[^"]+" taxon) should appear in the registry$/ + */ + public function theTaxonShouldAppearInTheRegistry(TaxonInterface $taxon) + { + $this->indexPage->open(); + Assert::true( + $this->indexPage->isResourceOnPage(['code' => $taxon->getCode()]), + sprintf('Taxon %s should be in the registry', $taxon->getName()) + ); + } + + /** + * @Then /^the ("[^"]+" taxon) with "([^"]*)" permalink and "([^"]*)" description should appear in the registry$/ + */ + public function theTaxonWithPermalinkAndDescriptionShouldAppearInTheRegistry(TaxonInterface $taxon, $permalink, $description) + { + $this->updatePage->open(['id' => $taxon->getId()]); + Assert::true( + $this->updatePage->hasResourceValues(['code' => $taxon->getCode(), 'permalink' => $permalink, 'description' => $description]), + sprintf('Taxon %s should have %s permalink and %s description.', $taxon->getName(), $permalink, $description) + ); + } + + /** + * @Then /^the ("[^"]+" taxon) with ("[^"]+" parent taxon) should appear in the registry$/ + */ + public function theTaxonWithParentTaxonShouldAppearInTheRegistry(TaxonInterface $taxon, TaxonInterface $parentTaxon) + { + $this->updatePage->open(['id' => $taxon->getId()]); + Assert::true( + $this->updatePage->hasResourceValues(['parent' => $parentTaxon->getId()]), + sprintf('Taxon %s should have %s parent taxon', $taxon->getName(), $parentTaxon->getName()) + ); + } +} diff --git a/src/Sylius/Behat/Page/Admin/Taxon/CreatePage.php b/src/Sylius/Behat/Page/Admin/Taxon/CreatePage.php new file mode 100644 index 0000000000..697ef686b5 --- /dev/null +++ b/src/Sylius/Behat/Page/Admin/Taxon/CreatePage.php @@ -0,0 +1,70 @@ + + */ +class CreatePage extends BaseCreatePage implements CreatePageInterface +{ + use SpecifiesItsCode; + + /** + * {@inheritdoc} + */ + public function chooseParent(TaxonInterface $taxon) + { + $this->getElement('parent')->selectOption($taxon->getName(), false); + } + + /** + * {@inheritdoc} + */ + public function describeItAs($description, $languageCode) + { + $this->getDocument()->fillField(sprintf('sylius_taxon_translations_%s_description', $languageCode), $description); + } + + /** + * {@inheritdoc} + */ + public function nameIt($name, $languageCode) + { + $this->getDocument()->fillField(sprintf('sylius_taxon_translations_%s_name', $languageCode), $name); + } + + /** + * {@inheritdoc} + */ + public function specifyPermalink($permalink, $languageCode) + { + $this->getDocument()->fillField(sprintf('sylius_taxon_translations_%s_permalink', $languageCode), $permalink); + } + + /** + * {@inheritdoc} + */ + protected function getDefinedElements() + { + return array_merge(parent::getDefinedElements(), [ + 'code' => '#sylius_taxon_code', + 'name' => '#sylius_taxon_translations_en_US_name', + 'parent' => '#sylius_taxon_parent', + 'permalink' => '#sylius_taxon_translations_en_US_permalink', + 'description' => '#sylius_taxon_translations_en_US_description', + ]); + } +} diff --git a/src/Sylius/Behat/Page/Admin/Taxon/CreatePageInterface.php b/src/Sylius/Behat/Page/Admin/Taxon/CreatePageInterface.php new file mode 100644 index 0000000000..45c7065357 --- /dev/null +++ b/src/Sylius/Behat/Page/Admin/Taxon/CreatePageInterface.php @@ -0,0 +1,49 @@ + + */ +interface CreatePageInterface extends BaseCreatePageInterface +{ + /** + * @param string $description + * @param string $languageCode + */ + public function describeItAs($description, $languageCode); + + /** + * @param TaxonInterface $taxon + */ + public function chooseParent(TaxonInterface $taxon); + + /** + * @param string $name + * @param string $languageCode + */ + public function nameIt($name, $languageCode); + + /** + * @param string $code + */ + public function specifyCode($code); + + /** + * @param string $permalink + * @param string $languageCode + */ + public function specifyPermalink($permalink, $languageCode); +} diff --git a/src/Sylius/Behat/Page/Admin/Taxon/UpdatePage.php b/src/Sylius/Behat/Page/Admin/Taxon/UpdatePage.php new file mode 100644 index 0000000000..b4d7de1435 --- /dev/null +++ b/src/Sylius/Behat/Page/Admin/Taxon/UpdatePage.php @@ -0,0 +1,34 @@ + + */ +class UpdatePage extends BaseUpdatePage implements UpdatePageInterface +{ + /** + * {@inheritdoc} + */ + protected function getDefinedElements() + { + return array_merge(parent::getDefinedElements(), [ + 'code' => '#sylius_taxon_code', + 'name' => '#sylius_taxon_translations_en_US_name', + 'parent' => '#sylius_taxon_parent', + 'permalink' => '#sylius_taxon_translations_en_US_permalink', + 'description' => '#sylius_taxon_translations_en_US_description', + ]); + } +} diff --git a/src/Sylius/Behat/Page/Admin/Taxon/UpdatePageInterface.php b/src/Sylius/Behat/Page/Admin/Taxon/UpdatePageInterface.php new file mode 100644 index 0000000000..7568b004ab --- /dev/null +++ b/src/Sylius/Behat/Page/Admin/Taxon/UpdatePageInterface.php @@ -0,0 +1,22 @@ + + */ +interface UpdatePageInterface extends BaseUpdatePageInterface +{ + +} diff --git a/src/Sylius/Bundle/AdminBundle/Menu/MainMenuBuilder.php b/src/Sylius/Bundle/AdminBundle/Menu/MainMenuBuilder.php index 1508c13cc2..2771c15a0e 100644 --- a/src/Sylius/Bundle/AdminBundle/Menu/MainMenuBuilder.php +++ b/src/Sylius/Bundle/AdminBundle/Menu/MainMenuBuilder.php @@ -166,5 +166,11 @@ final class MainMenuBuilder extends AbstractAdminMenuBuilder ->setLabel('sylius.menu.admin.main.catalog.product_options') ->setLabelAttribute('icon', 'options') ; + + $catalogSubMenu + ->addChild('taxons', ['route' => 'sylius_admin_taxon_create']) + ->setLabel('sylius.menu.admin.main.assortment.taxons') + ->setLabelAttribute('icon', 'folder') + ; } } diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/grids.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/grids.yml index 10de4d4ebd..f82ac7c4b7 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/grids.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/grids.yml @@ -9,6 +9,7 @@ imports: - { resource: "@SyliusAdminBundle/Resources/config/grids/product_option.yml" } - { resource: "@SyliusAdminBundle/Resources/config/grids/promotion.yml" } - { resource: "@SyliusAdminBundle/Resources/config/grids/shipping_method.yml" } + - { resource: "@SyliusAdminBundle/Resources/config/grids/taxon.yml" } - { resource: "@SyliusAdminBundle/Resources/config/grids/tax_category.yml" } - { resource: "@SyliusAdminBundle/Resources/config/grids/tax_rate.yml" } - { resource: "@SyliusAdminBundle/Resources/config/grids/zone.yml" } diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/taxon.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/taxon.yml new file mode 100644 index 0000000000..cb79932e5a --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/taxon.yml @@ -0,0 +1,21 @@ +sylius_grid: + grids: + sylius_admin_taxon: + driver: + name: doctrine/orm + options: + class: "%sylius.model.taxon.class%" + fields: + code: + type: string + label: sylius.ui.code + name: + type: string + label: sylius.ui.name + actions: + main: + create: + type: create + item: + update: + type: update diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/routing.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/routing.yml index 3353bba7c1..e0b92c8c90 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/routing.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/routing.yml @@ -43,6 +43,9 @@ sylius_admin_security: sylius_admin_shipping_method: resource: "@SyliusAdminBundle/Resources/config/routing/shipping_method.yml" +sylius_admin_taxon: + resource: "@SyliusAdminBundle/Resources/config/routing/taxon.yml" + sylius_admin_tax_category: resource: "@SyliusAdminBundle/Resources/config/routing/tax_category.yml" diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/routing/taxon.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/routing/taxon.yml new file mode 100644 index 0000000000..312471335a --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/routing/taxon.yml @@ -0,0 +1,16 @@ +sylius_admin_taxon: + resource: | + alias: sylius.taxon + section: admin + templates: SyliusAdminBundle:Crud + except: ['show', 'delete'] + redirect: update + grid: sylius_admin_taxon + vars: + all: + subheader: sylius.ui.manage_taxons + templates: + form: SyliusAdminBundle:Taxon:_form.html.twig + index: + icon: folder + type: sylius.resource diff --git a/src/Sylius/Bundle/AdminBundle/Resources/translations/messages.en.yml b/src/Sylius/Bundle/AdminBundle/Resources/translations/messages.en.yml index dd75027578..c491c96cdf 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/translations/messages.en.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/translations/messages.en.yml @@ -5,6 +5,7 @@ sylius: catalog: header: Catalog product_options: Product options + taxons: Taxons configuration: channels: Channels countries: Countries diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Taxon/_form.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Taxon/_form.html.twig new file mode 100644 index 0000000000..6f9bc0a694 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Taxon/_form.html.twig @@ -0,0 +1,23 @@ +
+
+
+ {{ form_errors(form) }} +
+ {{ form_row(form.code) }} +
+
+ {{ form_row(form.parent) }} +
+
+
+
+
+ {% for locale, translationForm in form.translations %} +

{{ locale|sylius_locale_name }}

+ {{ form_row(translationForm.name) }} + {{ form_row(translationForm.permalink) }} + {{ form_row(translationForm.description) }} + {% endfor %} +
+
+
\ No newline at end of file diff --git a/src/Sylius/Bundle/UiBundle/Resources/translations/messages.en.yml b/src/Sylius/Bundle/UiBundle/Resources/translations/messages.en.yml index 886904513c..7d572ffd91 100644 --- a/src/Sylius/Bundle/UiBundle/Resources/translations/messages.en.yml +++ b/src/Sylius/Bundle/UiBundle/Resources/translations/messages.en.yml @@ -58,6 +58,8 @@ sylius: manage_payment_method: Manage payment methods manage_product_option: Manage product option manage_shipping_destinations: Manage shipping destinations + manage_taxons: Manage taxons of your products + manage_taxation_of_your_products: Manage taxation of your products manage_shipping_methods_for_your_store: Manage shipping methods for your store manage_taxation_of_your_products: Manage taxation of your products new: New