mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
Add toggleable to taxon and first behat scenario
This commit is contained in:
parent
57a58fa20c
commit
19e7e26ee2
11 changed files with 103 additions and 1 deletions
35
app/migrations/Version20200325075815.php
Normal file
35
app/migrations/Version20200325075815.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?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 Version20200325075815 extends AbstractMigration
|
||||
{
|
||||
public function getDescription() : string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
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('ALTER TABLE sylius_taxon ADD enabled TINYINT(1) NOT NULL');
|
||||
}
|
||||
|
||||
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_taxon DROP enabled');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
@managing_taxons
|
||||
Feature: Toggle the taxon
|
||||
In order to associate products to a taxon while it isn't published to customers
|
||||
As an Administrator
|
||||
I want to create a disabled taxon and toggle the taxon later
|
||||
|
||||
Background:
|
||||
Given the store is available in "English (United States)"
|
||||
And the store classifies its products as "T-Shirts" and "Accessories"
|
||||
And I am logged in as an administrator
|
||||
|
||||
@ui
|
||||
Scenario: Adding a disabled taxon
|
||||
Given I want to create a new taxon
|
||||
When I specify its code as "jeans"
|
||||
And I name it "Jeans" in "English (United States)"
|
||||
And I set its slug to "jeans" in "English (United States)"
|
||||
And I disable it
|
||||
And I add it
|
||||
Then I should be notified that it has been successfully created
|
||||
And the "Jeans" taxon should appear in the registry
|
||||
And it should be marked as disabled
|
||||
|
|
@ -422,6 +422,22 @@ final class ManagingTaxonsContext implements Context
|
|||
Assert::same($this->createPage->getFirstTaxonOnTheList(), $taxonName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^I disable it$/
|
||||
*/
|
||||
public function iDisableIt(): void
|
||||
{
|
||||
$this->updatePage->disable();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^it should be marked as disabled$/
|
||||
*/
|
||||
public function itShouldBeMarkedAsDisabled(): void
|
||||
{
|
||||
Assert::false($this->updatePage->isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CreatePageInterface|CreateForParentPageInterface|UpdatePageInterface
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -205,6 +205,16 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
|
|||
});
|
||||
}
|
||||
|
||||
public function disable(): void
|
||||
{
|
||||
$this->getElement('enabled')->uncheck();
|
||||
}
|
||||
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return $this->getElement('enabled')->isChecked();
|
||||
}
|
||||
|
||||
protected function getElement(string $name, array $parameters = []): NodeElement
|
||||
{
|
||||
if (!isset($parameters['%language%'])) {
|
||||
|
|
@ -230,6 +240,7 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
|
|||
'parent' => '#sylius_taxon_parent',
|
||||
'slug' => '#sylius_taxon_translations_%language%_slug',
|
||||
'toggle_taxon_slug_modification_button' => '[data-locale="%locale%"] .toggle-taxon-slug-modification',
|
||||
'enabled' => '#sylius_taxon_enabled',
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,4 +65,8 @@ interface UpdatePageInterface extends BaseUpdatePageInterface
|
|||
public function getValidationMessageForImageAtPlace(int $place): string;
|
||||
|
||||
public function activateLanguageTab(string $locale): void;
|
||||
|
||||
public function disable(): void;
|
||||
|
||||
public function isEnabled(): bool;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@
|
|||
{{ form_widget(form.parent, {'attr': {'style': 'display: none;'}}) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="fields">
|
||||
{{ form_row(form.enabled) }}
|
||||
</div>
|
||||
</div>
|
||||
{{ translationFormWithSlug(form.translations, '@SyliusAdmin/Taxon/_slugField.html.twig', taxon) }}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ namespace Sylius\Bundle\TaxonomyBundle\Form\Type;
|
|||
use Sylius\Bundle\ResourceBundle\Form\EventSubscriber\AddCodeFormSubscriber;
|
||||
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
|
||||
use Sylius\Bundle\ResourceBundle\Form\Type\ResourceTranslationsType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
|
|
@ -29,6 +30,10 @@ final class TaxonType extends AbstractResourceType
|
|||
'entry_type' => TaxonTranslationType::class,
|
||||
'label' => 'sylius.form.taxon.name',
|
||||
])
|
||||
->add('enabled', CheckboxType::class, [
|
||||
'required' => false,
|
||||
'label' => 'sylius.form.taxon.enabled',
|
||||
])
|
||||
->addEventSubscriber(new AddCodeFormSubscriber())
|
||||
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event): void {
|
||||
if (null === $event->getData()) {
|
||||
|
|
|
|||
|
|
@ -56,6 +56,8 @@
|
|||
</field>
|
||||
|
||||
<gedmo:tree type="nested" />
|
||||
|
||||
<field name="enabled" column="enabled" type="boolean" />
|
||||
</mapped-superclass>
|
||||
|
||||
</doctrine-mapping>
|
||||
|
|
|
|||
|
|
@ -8,5 +8,6 @@ sylius:
|
|||
name: Name
|
||||
parent: Parent
|
||||
slug: Slug
|
||||
enabled: Enabled
|
||||
taxonomy:
|
||||
name: Name
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ namespace Sylius\Component\Taxonomy\Model;
|
|||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Sylius\Component\Resource\Model\ToggleableTrait;
|
||||
use Sylius\Component\Resource\Model\TranslatableTrait;
|
||||
use Sylius\Component\Resource\Model\TranslationInterface;
|
||||
|
||||
|
|
@ -24,6 +25,7 @@ class Taxon implements TaxonInterface
|
|||
__construct as private initializeTranslationsCollection;
|
||||
getTranslation as private doGetTranslation;
|
||||
}
|
||||
use ToggleableTrait;
|
||||
|
||||
/** @var mixed */
|
||||
protected $id;
|
||||
|
|
|
|||
|
|
@ -17,10 +17,11 @@ use Doctrine\Common\Collections\Collection;
|
|||
use Sylius\Component\Resource\Model\CodeAwareInterface;
|
||||
use Sylius\Component\Resource\Model\ResourceInterface;
|
||||
use Sylius\Component\Resource\Model\SlugAwareInterface;
|
||||
use Sylius\Component\Resource\Model\ToggleableInterface;
|
||||
use Sylius\Component\Resource\Model\TranslatableInterface;
|
||||
use Sylius\Component\Resource\Model\TranslationInterface;
|
||||
|
||||
interface TaxonInterface extends CodeAwareInterface, TranslatableInterface, ResourceInterface, SlugAwareInterface
|
||||
interface TaxonInterface extends CodeAwareInterface, TranslatableInterface, ResourceInterface, SlugAwareInterface, ToggleableInterface
|
||||
{
|
||||
public function isRoot(): bool;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue