Skip to content

Commit

Permalink
Rename Promotion entity to CatalogPromotion along with related files
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Jan 9, 2025
1 parent e279a75 commit cb1905a
Show file tree
Hide file tree
Showing 31 changed files with 124 additions and 126 deletions.
4 changes: 2 additions & 2 deletions src/Checker/PreQualification/RulesPreQualificationChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Setono\SyliusCatalogPromotionPlugin\Checker\PreQualification;

use Setono\SyliusCatalogPromotionPlugin\Checker\PreQualification\Rule\RuleCheckerInterface;
use Setono\SyliusCatalogPromotionPlugin\Model\CatalogPromotionRuleInterface;
use Setono\SyliusCatalogPromotionPlugin\Model\ProductInterface;
use Setono\SyliusCatalogPromotionPlugin\Model\PromotionInterface;
use Setono\SyliusCatalogPromotionPlugin\Model\PromotionRuleInterface;
use Sylius\Component\Registry\ServiceRegistryInterface;
use Webmozart\Assert\Assert;

Expand All @@ -32,7 +32,7 @@ public function isPreQualified(ProductInterface $product, PromotionInterface $ca
return true;
}

private function isEligibleToRule(ProductInterface $product, PromotionRuleInterface $rule): bool
private function isEligibleToRule(ProductInterface $product, CatalogPromotionRuleInterface $rule): bool
{
/** @var RuleCheckerInterface|object $checker */
$checker = $this->ruleRegistry->get((string) $rule->getType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public function process(ContainerBuilder $container): void
}
}

$container->setParameter('setono_sylius_catalog_promotion.promotion_rules', $formToLabelMap);
$container->setParameter('setono_sylius_catalog_promotion.catalog_promotion_rules', $formToLabelMap);
}
}
10 changes: 5 additions & 5 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Setono\SyliusCatalogPromotionPlugin\DependencyInjection;

use Setono\SyliusCatalogPromotionPlugin\Form\Type\PromotionRuleType;
use Setono\SyliusCatalogPromotionPlugin\Form\Type\CatalogPromotionRuleType;
use Setono\SyliusCatalogPromotionPlugin\Form\Type\PromotionType;
use Setono\SyliusCatalogPromotionPlugin\Model\CatalogPromotionRule;
use Setono\SyliusCatalogPromotionPlugin\Model\CatalogPromotionUpdate;
use Setono\SyliusCatalogPromotionPlugin\Model\Promotion;
use Setono\SyliusCatalogPromotionPlugin\Model\PromotionRule;
use Setono\SyliusCatalogPromotionPlugin\Repository\PromotionRepository;
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
use Sylius\Component\Resource\Factory\Factory;
Expand Down Expand Up @@ -69,18 +69,18 @@ private function addResourcesSection(ArrayNodeDefinition $node): void
->end()
->end()
->end()
->arrayNode('promotion_rule')
->arrayNode('catalog_promotion_rule')
->addDefaultsIfNotSet()
->children()
->variableNode('options')->end()
->arrayNode('classes')
->addDefaultsIfNotSet()
->children()
->scalarNode('model')->defaultValue(PromotionRule::class)->cannotBeEmpty()->end()
->scalarNode('model')->defaultValue(CatalogPromotionRule::class)->cannotBeEmpty()->end()
->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
->scalarNode('repository')->cannotBeEmpty()->end()
->scalarNode('factory')->defaultValue(Factory::class)->end()
->scalarNode('form')->defaultValue(PromotionRuleType::class)->cannotBeEmpty()->end()
->scalarNode('form')->defaultValue(CatalogPromotionRuleType::class)->cannotBeEmpty()->end()
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@
use Setono\SyliusCatalogPromotionPlugin\Checker\PreQualification\Rule\ContainsProductsRuleChecker;
use Setono\SyliusCatalogPromotionPlugin\Checker\PreQualification\Rule\HasNotTaxonRuleChecker;
use Setono\SyliusCatalogPromotionPlugin\Checker\PreQualification\Rule\HasTaxonRuleChecker;
use Setono\SyliusCatalogPromotionPlugin\Model\PromotionRuleInterface;
use Setono\SyliusCatalogPromotionPlugin\Model\CatalogPromotionRuleInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Webmozart\Assert\Assert;

final class PromotionRuleFactory implements PromotionRuleFactoryInterface
final class CatalogPromotionRuleFactory implements CatalogPromotionRuleFactoryInterface
{
public function __construct(private readonly FactoryInterface $decoratedFactory, private readonly array $rules)
{
}

public function createNew(): PromotionRuleInterface
public function createNew(): CatalogPromotionRuleInterface
{
$obj = $this->decoratedFactory->createNew();
Assert::isInstanceOf($obj, PromotionRuleInterface::class);
Assert::isInstanceOf($obj, CatalogPromotionRuleInterface::class);

return $obj;
}

public function createByType(string $type, array $configuration, bool $strict = false): PromotionRuleInterface
public function createByType(string $type, array $configuration, bool $strict = false): CatalogPromotionRuleInterface
{
switch ($type) {
case HasTaxonRuleChecker::TYPE:
Expand Down Expand Up @@ -62,7 +62,7 @@ public function createByType(string $type, array $configuration, bool $strict =
return $this->createPromotionRule($type, $configuration);
}

public function createHasTaxon(array $taxonCodes): PromotionRuleInterface
public function createHasTaxon(array $taxonCodes): CatalogPromotionRuleInterface
{
Assert::allString($taxonCodes);

Expand All @@ -72,7 +72,7 @@ public function createHasTaxon(array $taxonCodes): PromotionRuleInterface
);
}

public function createHasNotTaxon(array $taxonCodes): PromotionRuleInterface
public function createHasNotTaxon(array $taxonCodes): CatalogPromotionRuleInterface
{
Assert::allString($taxonCodes);

Expand All @@ -82,15 +82,15 @@ public function createHasNotTaxon(array $taxonCodes): PromotionRuleInterface
);
}

public function createContainsProduct(string $productCode): PromotionRuleInterface
public function createContainsProduct(string $productCode): CatalogPromotionRuleInterface
{
return $this->createPromotionRule(
ContainsProductRuleChecker::TYPE,
['product' => $productCode],
);
}

public function createContainsProducts(array $productCodes): PromotionRuleInterface
public function createContainsProducts(array $productCodes): CatalogPromotionRuleInterface
{
Assert::allString($productCodes);

Expand All @@ -100,7 +100,7 @@ public function createContainsProducts(array $productCodes): PromotionRuleInterf
);
}

private function createPromotionRule(string $type, array $configuration): PromotionRuleInterface
private function createPromotionRule(string $type, array $configuration): CatalogPromotionRuleInterface
{
$rule = $this->createNew();
$rule->setType($type);
Expand Down
21 changes: 21 additions & 0 deletions src/Factory/CatalogPromotionRuleFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusCatalogPromotionPlugin\Factory;

use Setono\SyliusCatalogPromotionPlugin\Model\CatalogPromotionRuleInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;

interface CatalogPromotionRuleFactoryInterface extends FactoryInterface
{
public function createByType(string $type, array $configuration, bool $strict = false): CatalogPromotionRuleInterface;

public function createHasTaxon(array $taxonCodes): CatalogPromotionRuleInterface;

public function createHasNotTaxon(array $taxonCodes): CatalogPromotionRuleInterface;

public function createContainsProduct(string $productCode): CatalogPromotionRuleInterface;

public function createContainsProducts(array $productCodes): CatalogPromotionRuleInterface;
}
21 changes: 0 additions & 21 deletions src/Factory/PromotionRuleFactoryInterface.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,29 @@

namespace Setono\SyliusCatalogPromotionPlugin\Fixture\Factory;

use Setono\SyliusCatalogPromotionPlugin\Factory\PromotionRuleFactoryInterface;
use Setono\SyliusCatalogPromotionPlugin\Model\PromotionRuleInterface;
use Setono\SyliusCatalogPromotionPlugin\Factory\CatalogPromotionRuleFactoryInterface;
use Setono\SyliusCatalogPromotionPlugin\Model\CatalogPromotionRuleInterface;
use Sylius\Bundle\CoreBundle\Fixture\Factory\AbstractExampleFactory;
use Symfony\Component\OptionsResolver\OptionsResolver;

class PromotionRuleExampleFactory extends AbstractExampleFactory
class CatalogPromotionRuleExampleFactory extends AbstractExampleFactory
{
protected PromotionRuleFactoryInterface $promotionRuleFactory;

protected array $promotionRules;

protected OptionsResolver $optionsResolver;

public function __construct(PromotionRuleFactoryInterface $promotionRuleFactory, array $promotionRules)
{
$this->promotionRuleFactory = $promotionRuleFactory;
$this->promotionRules = $promotionRules;

public function __construct(
protected readonly CatalogPromotionRuleFactoryInterface $catalogPromotionRuleFactory,
protected readonly array $catalogPromotionRules,
) {
$this->optionsResolver = new OptionsResolver();

$this->configureOptions($this->optionsResolver);
}

public function create(array $options = []): PromotionRuleInterface
public function create(array $options = []): CatalogPromotionRuleInterface
{
$options = $this->optionsResolver->resolve($options);

return $this->promotionRuleFactory->createByType(
return $this->catalogPromotionRuleFactory->createByType(
$options['type'],
$options['configuration'],
);
Expand All @@ -41,9 +36,9 @@ protected function configureOptions(OptionsResolver $resolver): void
{
$resolver
->setDefault('type', function (): string {
$promotionRuleCodes = array_keys($this->promotionRules);
$codes = array_keys($this->catalogPromotionRules);

return $promotionRuleCodes[array_rand($promotionRuleCodes)];
return $codes[array_rand($codes)];
})
->setDefined('configuration')
->setAllowedTypes('configuration', ['string', 'array'])
Expand Down
8 changes: 4 additions & 4 deletions src/Fixture/Factory/PromotionExampleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use DateTime;
use DateTimeInterface;
use Faker\Generator;
use Setono\SyliusCatalogPromotionPlugin\Model\CatalogPromotionRuleInterface;
use Setono\SyliusCatalogPromotionPlugin\Model\PromotionInterface;
use Setono\SyliusCatalogPromotionPlugin\Model\PromotionRuleInterface;
use Setono\SyliusCatalogPromotionPlugin\Repository\PromotionRepositoryInterface;
use Sylius\Bundle\CoreBundle\Fixture\Factory\AbstractExampleFactory;
use Sylius\Bundle\CoreBundle\Fixture\OptionsResolver\LazyOption;
Expand All @@ -27,7 +27,7 @@ class PromotionExampleFactory extends AbstractExampleFactory

protected Factory $promotionFactory;

protected PromotionRuleExampleFactory $promotionRuleExampleFactory;
protected CatalogPromotionRuleExampleFactory $promotionRuleExampleFactory;

Check failure on line 30 in src/Fixture/Factory/PromotionExampleFactory.php

View workflow job for this annotation

GitHub Actions / Backwards Compatibility Check

Type of property Setono\SyliusCatalogPromotionPlugin\Fixture\Factory\PromotionExampleFactory#$promotionRuleExampleFactory changed from Setono\SyliusCatalogPromotionPlugin\Fixture\Factory\PromotionRuleExampleFactory to Setono\SyliusCatalogPromotionPlugin\Fixture\Factory\CatalogPromotionRuleExampleFactory

protected Generator $faker;

Expand All @@ -37,7 +37,7 @@ public function __construct(
ChannelRepositoryInterface $channelRepository,
PromotionRepositoryInterface $promotionRepository,
Factory $promotionFactory,
PromotionRuleExampleFactory $promotionRuleExampleFactory,
CatalogPromotionRuleExampleFactory $promotionRuleExampleFactory,
) {
$this->channelRepository = $channelRepository;
$this->promotionRepository = $promotionRepository;
Expand Down Expand Up @@ -82,7 +82,7 @@ public function create(array $options = []): PromotionInterface
}

foreach ($options['rules'] as $ruleOptions) {
/** @var PromotionRuleInterface $promotionRule */
/** @var CatalogPromotionRuleInterface $promotionRule */
$promotionRule = $this->promotionRuleExampleFactory->create($ruleOptions);
$promotion->addRule($promotionRule);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class PromotionRuleChoiceType extends AbstractType
final class CatalogPromotionRuleChoiceType extends AbstractType
{
private array $rules;

Expand All @@ -32,6 +32,6 @@ public function getParent(): string

public function getBlockPrefix(): string
{
return 'setono_sylius_catalog_promotion_promotion_rule_choice';
return 'setono_sylius_catalog_promotion__catalog_promotion_rule_choice';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
use Sylius\Bundle\PromotionBundle\Form\Type\Core\AbstractConfigurationCollectionType;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class PromotionRuleCollectionType extends AbstractConfigurationCollectionType
final class CatalogPromotionRuleCollectionType extends AbstractConfigurationCollectionType
{
public function configureOptions(OptionsResolver $resolver): void
{
parent::configureOptions($resolver);

$resolver->setDefault('entry_type', PromotionRuleType::class);
$resolver->setDefault('entry_type', CatalogPromotionRuleType::class);
}

public function getBlockPrefix(): string
{
return 'setono_sylius_catalog_promotion_promotion_rule_collection';
return 'setono_sylius_catalog_promotion__catalog_promotion_rule_collection';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Setono\SyliusCatalogPromotionPlugin\Form\Type;

use Setono\SyliusCatalogPromotionPlugin\Model\PromotionRuleInterface;
use Setono\SyliusCatalogPromotionPlugin\Model\CatalogPromotionRuleInterface;
use Sylius\Bundle\ResourceBundle\Form\Registry\FormTypeRegistryInterface;
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Symfony\Component\Form\FormBuilderInterface;
Expand All @@ -14,7 +14,7 @@
use Symfony\Component\OptionsResolver\OptionsResolver;
use Webmozart\Assert\Assert;

final class PromotionRuleType extends AbstractResourceType
final class CatalogPromotionRuleType extends AbstractResourceType
{
/**
* @param array<array-key, string> $validationGroups
Expand All @@ -27,8 +27,8 @@ public function __construct(private readonly FormTypeRegistryInterface $formType
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('type', PromotionRuleChoiceType::class, [
'label' => 'setono_sylius_catalog_promotion.form.promotion_rule.type',
->add('type', CatalogPromotionRuleChoiceType::class, [
'label' => 'setono_sylius_catalog_promotion.form.catalog_promotion_rule.type',
'attr' => [
'data-form-collection' => 'update',
],
Expand Down Expand Up @@ -77,7 +77,7 @@ public function configureOptions(OptionsResolver $resolver): void

public function getBlockPrefix(): string
{
return 'setono_sylius_catalog_promotion_promotion_rule';
return 'setono_sylius_catalog_promotion__catalog_promotion_rule';
}

protected function addConfigurationFields(FormInterface $form, string $configurationType): void
Expand All @@ -92,7 +92,7 @@ protected function addConfigurationFields(FormInterface $form, string $configura
*/
protected function getRegistryIdentifier(FormInterface $form, $data = null): ?string
{
if ($data instanceof PromotionRuleInterface && null !== $data->getType()) {
if ($data instanceof CatalogPromotionRuleInterface && null !== $data->getType()) {
return $data->getType();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Form/Type/PromotionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'label' => 'setono_sylius_catalog_promotion.form.promotion.priority',
'required' => false,
])
->add('rules', PromotionRuleCollectionType::class, [
->add('rules', CatalogPromotionRuleCollectionType::class, [
'label' => 'setono_sylius_catalog_promotion.form.promotion.rules',
'button_add_label' => 'setono_sylius_catalog_promotion.form.promotion.add_rule',
'required' => false,
Expand Down
4 changes: 2 additions & 2 deletions src/Form/Type/Rule/ContainsProductConfigurationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('product', ProductAutocompleteChoiceType::class, [
'label' => 'setono_sylius_catalog_promotion.form.promotion_rule.contains_product_configuration.product',
'label' => 'setono_sylius_catalog_promotion.form.catalog_promotion_rule.contains_product_configuration.product',
])
;

Expand All @@ -35,6 +35,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void

public function getBlockPrefix(): string
{
return 'setono_sylius_catalog_promotion_promotion_rule_contains_product_configuration';
return 'setono_sylius_catalog_promotion__catalog_promotion_rule_contains_product_configuration';
}
}
Loading

0 comments on commit cb1905a

Please sign in to comment.