-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[CatalogPromotions] Manage rules and actions from UI #13052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
810b647
Move variant-related CatalogPromotionRule contant to Core
Zales0123 bad8bfb
Rework current Catalog Promotions form
Zales0123 4839a9b
[Behat] Describe adding rule and action during CP creation
Zales0123 a5cba56
Manage rules on CP form
Zales0123 0892704
Manage actions on CatalogPromotion form
Zales0123 877d011
Fix Behat scenarios and improve CP variants provider
Zales0123 558cd11
Improve Behat and remove uneeded class
Zales0123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -18,7 +18,9 @@ | |||||
| use Sylius\Behat\Page\Admin\CatalogPromotion\CreatePageInterface; | ||||||
| use Sylius\Behat\Page\Admin\CatalogPromotion\UpdatePageInterface; | ||||||
| use Sylius\Behat\Page\Admin\Crud\IndexPageInterface; | ||||||
| use Sylius\Behat\Service\SharedStorageInterface; | ||||||
| use Sylius\Component\Core\Model\CatalogPromotionInterface; | ||||||
| use Sylius\Component\Core\Model\ProductVariantInterface; | ||||||
| use Webmozart\Assert\Assert; | ||||||
|
|
||||||
| final class ManagingCatalogPromotionsContext implements Context | ||||||
|
|
@@ -31,16 +33,20 @@ final class ManagingCatalogPromotionsContext implements Context | |||||
|
|
||||||
| private FormElementInterface $formElement; | ||||||
|
|
||||||
| private SharedStorageInterface $sharedStorage; | ||||||
|
|
||||||
| public function __construct( | ||||||
| IndexPageInterface $indexPage, | ||||||
| CreatePageInterface $createPage, | ||||||
| UpdatePageInterface $updatePage, | ||||||
| FormElementInterface $formElement | ||||||
| FormElementInterface $formElement, | ||||||
| SharedStorageInterface $sharedStorage | ||||||
| ) { | ||||||
| $this->indexPage = $indexPage; | ||||||
| $this->createPage = $createPage; | ||||||
| $this->updatePage = $updatePage; | ||||||
| $this->formElement = $formElement; | ||||||
| $this->sharedStorage = $sharedStorage; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
|
|
@@ -127,6 +133,28 @@ public function iMakeItUnavailableInChannel(string $channelName): void | |||||
| $this->formElement->uncheckChannel($channelName); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * @When /^it applies on variants ("[^"]+" variant) and ("[^"]+" variant)$/ | ||||||
| */ | ||||||
| public function itAppliesOnVariants(...$variants): void | ||||||
| { | ||||||
| $variantCodes = array_map(function(ProductVariantInterface $variant) { | ||||||
| return $variant->getCode(); | ||||||
| }, $variants); | ||||||
|
|
||||||
| $this->formElement->addRule(); | ||||||
| $this->formElement->chooseLastRuleVariants($variantCodes); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * @When /^it gives the "([^"]+)%" percentage discount$/ | ||||||
| */ | ||||||
| public function catalogPromotionGivesDiscount(string $discount): void | ||||||
| { | ||||||
| $this->formElement->addAction(); | ||||||
| $this->formElement->specifyLastActionDiscount($discount); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * @When I add it | ||||||
| */ | ||||||
|
|
@@ -194,6 +222,28 @@ public function itShouldHaveCodeAndName(string $code, string $name): void | |||||
| $this->indexPage->isSingleResourceOnPage(['name' => $name, 'code' => $code]), | ||||||
| sprintf('Cannot find catalog promotions with code "%s" and name "%s" in the list', $code, $name) | ||||||
| ); | ||||||
|
|
||||||
| $actions = $this->indexPage->getActionsForResource(['name' => $name]); | ||||||
| $actions->clickLink('Edit'); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * @Then /^it should apply to ("[^"]+" variant) and ("[^"]+" variant)$/ | ||||||
| */ | ||||||
| public function itShouldHaveRule(ProductVariantInterface $firstVariant, ProductVariantInterface $secondVariant): void | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
and of course adjust the content of this method |
||||||
| { | ||||||
| $selectedVariants = $this->formElement->getLastRuleVariantCodes(); | ||||||
|
|
||||||
| Assert::inArray($firstVariant->getCode(), $selectedVariants); | ||||||
| Assert::inArray($secondVariant->getCode(), $selectedVariants); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * @Then /^it should have "([^"]+)%" discount$/ | ||||||
| */ | ||||||
| public function itShouldHaveDiscount(string $amount): void | ||||||
| { | ||||||
| Assert::same($this->formElement->getLastActionDiscount(), $amount); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
|
|
||||||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
24 changes: 18 additions & 6 deletions
24
src/Sylius/Bundle/AdminBundle/Resources/views/CatalogPromotion/_form.html.twig
This file contains hidden or 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 |
|---|---|---|
| @@ -1,11 +1,23 @@ | ||
| {% from '@SyliusAdmin/Macro/translationForm.html.twig' import translationForm %} | ||
|
|
||
| <div class="ui segment"> | ||
| {% form_theme form '@SyliusAdmin/CatalogPromotion/theme.html.twig' %} | ||
|
|
||
| <div class="ui two column stackable grid"> | ||
| {{ form_errors(form) }} | ||
| <div class="three fields"> | ||
| {{ form_row(form.code) }} | ||
| {{ form_row(form.name) }} | ||
| {{ form_row(form.channels) }} | ||
| <div class="column"> | ||
| <div class="ui segment"> | ||
| {{ form_row(form.code) }} | ||
| {{ form_row(form.name) }} | ||
| {{ form_row(form.channels) }} | ||
| </div> | ||
| <div class="ui segment" id="rules"> | ||
| {{ form_row(form.rules) }} | ||
| </div> | ||
| <div class="ui segment" id="actions"> | ||
| {{ form_row(form.actions) }} | ||
| </div> | ||
| </div> | ||
| <div class="column"> | ||
| {{ translationForm(form.translations) }} | ||
| </div> | ||
| {{ translationForm(form.translations) }} | ||
| </div> |
6 changes: 6 additions & 0 deletions
6
src/Sylius/Bundle/AdminBundle/Resources/views/CatalogPromotion/theme.html.twig
This file contains hidden or 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,6 @@ | ||
| {% extends '@SyliusAdmin/Form/theme.html.twig' %} | ||
|
|
||
| {% block sylius_catalog_promotion_rule_widget %} | ||
| {{ form_row(form.type) }} | ||
| {{ form_row(form.configuration, {'remote_url': path('sylius_admin_ajax_all_product_variants_by_phrase'), 'remote_criteria_type': 'contains', 'remote_criteria_name': 'phrase', 'load_edit_url': path('sylius_admin_ajax_all_product_variants_by_codes')}) }} | ||
| {% endblock %} |
55 changes: 55 additions & 0 deletions
55
src/Sylius/Bundle/CoreBundle/Form/DataTransformer/ProductVariantsToCodesTransformer.php
This file contains hidden or 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,55 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the Sylius package. | ||
| * | ||
| * (c) Paweł Jędrzejewski | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Sylius\Bundle\CoreBundle\Form\DataTransformer; | ||
|
|
||
| use Doctrine\Common\Collections\ArrayCollection; | ||
| use Doctrine\Common\Collections\Collection; | ||
| use Sylius\Component\Core\Model\ProductVariantInterface; | ||
| use Sylius\Component\Core\Model\TaxonInterface; | ||
| use Sylius\Component\Core\Repository\ProductVariantRepositoryInterface; | ||
| use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface; | ||
| use Symfony\Component\Form\DataTransformerInterface; | ||
| use Webmozart\Assert\Assert; | ||
|
|
||
| final class ProductVariantsToCodesTransformer implements DataTransformerInterface | ||
| { | ||
| private ProductVariantRepositoryInterface $productVariantRepository; | ||
|
|
||
| public function __construct(ProductVariantRepositoryInterface $productVariantRepository) | ||
| { | ||
| $this->productVariantRepository = $productVariantRepository; | ||
| } | ||
|
|
||
| /** @throws \InvalidArgumentException */ | ||
| public function transform($value): Collection | ||
| { | ||
| Assert::nullOrIsArray($value); | ||
|
|
||
| if (empty($value)) { | ||
| return new ArrayCollection(); | ||
| } | ||
|
|
||
| return new ArrayCollection($this->productVariantRepository->findBy(['code' => $value])); | ||
| } | ||
|
|
||
| /** @throws \InvalidArgumentException */ | ||
| public function reverseTransform($productVariants): array | ||
| { | ||
| Assert::isInstanceOf($productVariants, Collection::class); | ||
|
|
||
| return array_map(function (ProductVariantInterface $productVariant) { | ||
| return $productVariant->getCode(); | ||
| }, $productVariants->toArray()); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.