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

protected ReductionCatalogRepositoryQuery $repositoryQuery; protected ReductionCatalogRepositoryQuery $repositoryQuery;
protected ReductionCatalogStore $store; protected ReductionCatalogStore $store;
protected ReductionCatalogFieldDefinition $fieldDefinition; protected ReductionCatalogFieldDefinition $fieldDefinition;
protected ReductionCatalogSolver $solver;


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


public static function getEntityFqcn() public static function getEntityFqcn()
return $this->fieldDefinition; 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



namespace Lc\CaracoleBundle\Definition\Field\Reduction; 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 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; use Lc\SovBundle\Translation\TranslatorAdmin;


class ReductionCatalogFieldDefinition extends AbstractFieldDefinition 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); 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 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 [ 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

$class = ReductionCatalogContainer::getEntityFqcn(); $class = ReductionCatalogContainer::getEntityFqcn();
$reductionCatalog = new $class; $reductionCatalog = new $class;


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



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

*/ */
protected $productCategories; protected $productCategories;


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

public function __construct() public function __construct()
{ {
$this->__reductionPropertyConstruct(); $this->__reductionPropertyConstruct();
return $this; 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

use Lc\CaracoleBundle\Repository\MerchantStoreTrait; use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
use Lc\CaracoleBundle\Repository\SectionStoreTrait; use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\CaracoleBundle\Solver\Price\PriceSolver; use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\CaracoleBundle\Solver\Reduction\ReductionCatalogSolver;
use Lc\SovBundle\Model\User\UserInterface; use Lc\SovBundle\Model\User\UserInterface;
use Lc\CaracoleBundle\Repository\AbstractStore; use Lc\CaracoleBundle\Repository\AbstractStore;
use Lc\SovBundle\Repository\RepositoryQueryInterface; use Lc\SovBundle\Repository\RepositoryQueryInterface;


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


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


public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
$reductionCatalog = $this->reductionCatalogStore->setMerchant($this->merchant) $reductionCatalog = $this->reductionCatalogStore->setMerchant($this->merchant)
->getByProductFamily($productFamily); ->getByProductFamily($productFamily);


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


public function hasReductionCatalog(ProductFamilyInterface $productFamily): bool public function hasReductionCatalog(ProductFamilyInterface $productFamily): bool

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

use Lc\CaracoleBundle\Model\Product\ProductInterface; use Lc\CaracoleBundle\Model\Product\ProductInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface; use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface; use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Solver\Reduction\ReductionCatalogSolver;


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


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


public static function getBehaviorCountStockChoices(): array public static function getBehaviorCountStockChoices(): array

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

<?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