Browse Source

[Backend] Réductions : ajouter possibilité d'afficher ou non une réduction catalogue #109

packProduct
Fabien Normand 2 years ago
parent
commit
d1841cfc5f
7 changed files with 188 additions and 41 deletions
  1. +5
    -8
      Container/Reduction/ReductionCatalogContainer.php
  2. +156
    -7
      Definition/Field/Reduction/ReductionCatalogFieldDefinition.php
  3. +1
    -0
      Factory/Reduction/ReductionCatalogFactory.php
  4. +23
    -0
      Model/Reduction/ReductionCatalogModel.php
  5. +2
    -7
      Repository/Product/ProductFamilyStore.php
  6. +1
    -5
      Solver/Product/ProductFamilySolver.php
  7. +0
    -14
      Solver/Reduction/ReductionCatalogSolver.php

+ 5
- 8
Container/Reduction/ReductionCatalogContainer.php View File

@@ -15,20 +15,17 @@ class ReductionCatalogContainer
protected ReductionCatalogRepositoryQuery $repositoryQuery;
protected ReductionCatalogStore $store;
protected ReductionCatalogFieldDefinition $fieldDefinition;
protected ReductionCatalogSolver $solver;

public function __construct(
ReductionCatalogFactory $factory,
ReductionCatalogRepositoryQuery $repositoryQuery,
ReductionCatalogStore $store,
ReductionCatalogFieldDefinition $fieldDefinition,
ReductionCatalogSolver $solver
ReductionCatalogFieldDefinition $fieldDefinition
) {
$this->factory = $factory;
$this->repositoryQuery = $repositoryQuery;
$this->store = $store;
$this->fieldDefinition = $fieldDefinition;
$this->solver = $solver;
}

public static function getEntityFqcn()
@@ -58,9 +55,9 @@ class ReductionCatalogContainer
return $this->fieldDefinition;
}

public function getSolver(): ReductionCatalogSolver
{
return $this->solver;
}
// public function getSolver(): ReductionCatalogSolver
// {
// return $this->solver;
// }

}

+ 156
- 7
Definition/Field/Reduction/ReductionCatalogFieldDefinition.php View File

@@ -2,26 +2,175 @@

namespace Lc\CaracoleBundle\Definition\Field\Reduction;

use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\CaracoleBundle\Definition\Field\AbstractFieldDefinition;
use Lc\CaracoleBundle\Repository\Section\SectionStore;
use Lc\CaracoleBundle\Context\MerchantContextTrait;
use Lc\SovBundle\Definition\Field\AbstractFieldDefinition;
use Lc\CaracoleBundle\Field\AssociationField;
use Lc\CaracoleBundle\Model\Config\TaxRateModel;
use Lc\CaracoleBundle\Model\Config\UnitModel;
use Lc\CaracoleBundle\Repository\Product\ProductCategoryStore;
use Lc\CaracoleBundle\Repository\Product\ProductFamilyStore;
use Lc\CaracoleBundle\Repository\User\GroupUserStore;
use Lc\CaracoleBundle\Repository\User\UserStore;
use Lc\SovBundle\Field\BooleanField;
use Lc\SovBundle\Translation\TranslatorAdmin;

class ReductionCatalogFieldDefinition extends AbstractFieldDefinition
{
protected SectionStore $sectionStore;
use MerchantContextTrait;

public function __construct(TranslatorAdmin $translatorAdmin, SectionStore $sectionStore)
protected GroupUserStore $groupUserStore;
protected UserStore $userStore;
protected ProductFamilyStore $productFamilyStore;
protected ProductCategoryStore $productCategoryStore;

public function __construct(
TranslatorAdmin $translatorAdmin,
GroupUserStore $groupUserStore,
UserStore $userStore,
ProductFamilyStore $productFamilyStore,
ProductCategoryStore $productCategoryStore
)
{
parent::__construct($translatorAdmin);
$this->sectionStore = $sectionStore;
$this->groupUserStore = $groupUserStore;
$this->userStore = $userStore;
$this->productFamilyStore = $productFamilyStore;
$this->productCategoryStore = $productCategoryStore;
}

public function configureIndex(): array
{

return [
'id',
'title',
'value',
'status',
'isDisplayed'

];
}

public function configureForm(): array
{
return [
'title',
'behaviorTaxRate',
'unit',
'value',
'permanent',
'dateStart',
'dateEnd',
'usersActive',
'users',
'groupUsersActive',
'groupUsers',
'productCategoriesActive',
'productCategories',
'productFamiliesActive',
'productFamilies',
'status',
'isDisplayed'

];
}

public function configureFields(): array
{
$groupUserArray = $this->groupUserStore->setMerchant($this->merchant)->get();
$usersArray = $this->userStore->setMerchant($this->merchant)->getJoinGroupUsers();
$productFamilyArray = $this->productFamilyStore->setMerchant($this->merchant)->get();
$productCategoryArray = $this->productCategoryStore->setMerchant($this->merchant)->get();

return [
'title' => TextField::new('title')->setSortable(true)
// @TODO : à faire
'title' => TextField::new('title')->setSortable(true),
'behaviorTaxRate' => ChoiceField::new('behaviorTaxRate')
->setFormTypeOption('required', true)
->setFormTypeOption('empty_data', TaxRateModel::BEHAVIOR_TAX_RATE_INCLUDED)
->setChoices(
$this->translatorAdmin->transChoices(
TaxRateModel::getBehaviorTaxRateChoices(),
'TaxRate',
'behaviorTaxRate'
)
),
'unit' => ChoiceField::new('unit')
->setFormTypeOption('expanded', true)
->setFormTypeOption('required', true)
->setChoices(
$this->translatorAdmin->transChoices(
UnitModel::getUnitAmountChoices(),
'Unit',
'unit'
)
),
'value' => NumberField::new('value')->setTemplatePath('@LcCaracole/admin/reduction/field/amount.html.twig'),
'permanent' => BooleanField::new('permanent'),
'dateStart' => DateTimeField::new('dateStart'),
'dateEnd' => DateTimeField::new('dateEnd'),
'isDisplayed'=> BooleanField::new('isDisplayed'),
'groupUsersActive' => BooleanField::new('groupUsersActive')->setFormTypeOption('mapped', false),
'groupUsers' => AssociationField::new('groupUsers')
->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig')
->setFormTypeOption('choices', $groupUserArray),

'usersActive' => BooleanField::new('usersActive')->setFormTypeOption('mapped', false),

'users' => AssociationField::new('users')
->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig')
->setFormTypeOption('choices', $usersArray)
->setFormTypeOption(
'choice_attr',
function ($choice, $key, $value) {
$data = array();
foreach ($choice->getGroupUsers() as $groupUser) {
$data[] = '_' . $groupUser->getId() . '_';
}

return ['data-group-users' => json_encode($data)];
},
),


'productCategoriesActive' => BooleanField::new('productCategoriesActive')->setFormTypeOption('mapped', false),
'productCategories' => AssociationField::new('productCategories')
->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig')
->setFormTypeOption('choice_label',
// @TODO : attention, code dupliqué de ProductCategoriesFilter
function ($category) {
$isOffline = '';
if ($category->getStatus() != 1) {
$isOffline = " [Hors ligne]";
}
$section = ' [' . $category->getSection()->getTitle() . ']';;
return $category . $section . $isOffline;
})
->setFormTypeOption('choices', $productCategoryArray),


'productFamiliesActive' => BooleanField::new('productFamiliesActive')->setFormTypeOption('mapped', false),
'productFamilies' => AssociationField::new('productFamilies')
->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig')
->setFormTypeOption('choices', $productFamilyArray)
->setFormTypeOption(
'choice_attr',
function ($choice, $key, $value) {
$data = array();
foreach ($choice->getProductCategories() as $category) {
$data[] = '_' . $category->getId() . '_';
}
return [
'data-product-categories' => json_encode($data),
'data-supplier' => $choice->getSupplier()->getId()
];
}
),
'productFamily' => AssociationField::new('productFamily')
->setFormTypeOption('choices', $productFamilyArray)
];
}
}

+ 1
- 0
Factory/Reduction/ReductionCatalogFactory.php View File

@@ -16,6 +16,7 @@ class ReductionCatalogFactory extends AbstractFactory
$class = ReductionCatalogContainer::getEntityFqcn();
$reductionCatalog = new $class;

$reductionCatalog->setIsDisplayed(true);
$reductionCatalog->setMerchant($merchant);
$reductionCatalog->setStatus($status);


+ 23
- 0
Model/Reduction/ReductionCatalogModel.php View File

@@ -56,6 +56,11 @@ abstract class ReductionCatalogModel extends AbstractLightEntity implements Redu
*/
protected $productCategories;

/**
* @ORM\Column(type="boolean", nullable=false)
*/
protected $isDisplayed;

public function __construct()
{
$this->__reductionPropertyConstruct();
@@ -151,4 +156,22 @@ abstract class ReductionCatalogModel extends AbstractLightEntity implements Redu
return $this;
}


public function getIsDisplayed(): bool
{
return $this->isDisplayed;
}

public function isDisplayed(): bool
{
return $this->isDisplayed;
}

public function setIsDisplayed(bool $isDisplayed): self
{
$this->isDisplayed = $isDisplayed;

return $this;
}

}

+ 2
- 7
Repository/Product/ProductFamilyStore.php View File

@@ -8,7 +8,6 @@ use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface;
use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\CaracoleBundle\Solver\Reduction\ReductionCatalogSolver;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\CaracoleBundle\Repository\AbstractStore;
use Lc\SovBundle\Repository\RepositoryQueryInterface;
@@ -20,16 +19,13 @@ class ProductFamilyStore extends AbstractStore

protected ProductFamilyRepositoryQuery $query;
protected PriceSolver $priceSolver;
protected ReductionCatalogSolver $reductionCatalogSolver;

public function __construct(
ProductFamilyRepositoryQuery $query,
PriceSolver $priceSolver,
ReductionCatalogSolver $reductionCatalogSolver
PriceSolver $priceSolver
) {
$this->query = $query;
$this->priceSolver = $priceSolver;
$this->reductionCatalogSolver = $reductionCatalogSolver;
}

public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
@@ -61,8 +57,7 @@ class ProductFamilyStore extends AbstractStore
$reductionCatalog = $this->reductionCatalogStore->setMerchant($this->merchant)
->getByProductFamily($productFamily);

return $this->hasReductionCatalog($productFamily)
&& $this->reductionCatalogSolver->isDisplayed($reductionCatalog);
return $this->hasReductionCatalog($productFamily) && $reductionCatalog->isDisplayed();
}

public function hasReductionCatalog(ProductFamilyInterface $productFamily): bool

+ 1
- 5
Solver/Product/ProductFamilySolver.php View File

@@ -10,25 +10,21 @@ use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
use Lc\CaracoleBundle\Model\Product\ProductInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Solver\Reduction\ReductionCatalogSolver;

class ProductFamilySolver
{
protected ProductSolver $productSolver;
protected ProductFamilySectionPropertySolver $productFamilySectionPropertySolver;
protected ProductCategorySolver $productCategorySolver;
protected ReductionCatalogSolver $reductionCatalogSolver;

public function __construct(
ProductSolver $productSolver,
ProductFamilySectionPropertySolver $productFamilySectionPropertySolver,
ProductCategorySolver $productCategorySolver,
ReductionCatalogSolver $reductionCatalogSolver
ProductCategorySolver $productCategorySolver
) {
$this->productSolver = $productSolver;
$this->productFamilySectionPropertySolver = $productFamilySectionPropertySolver;
$this->productCategorySolver = $productCategorySolver;
$this->reductionCatalogSolver = $reductionCatalogSolver;
}

public static function getBehaviorCountStockChoices(): array

+ 0
- 14
Solver/Reduction/ReductionCatalogSolver.php View File

@@ -1,14 +0,0 @@
<?php

namespace Lc\CaracoleBundle\Solver\Reduction;

use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface;

class ReductionCatalogSolver
{
public function isDisplayed(ReductionCatalogInterface $reductionCatalog): bool
{
// @TODO : à finaliser
return false;
}
}

Loading…
Cancel
Save