namespace Lc\CaracoleBundle\Controller\Product; | namespace Lc\CaracoleBundle\Controller\Product; | ||||
use Doctrine\ORM\QueryBuilder; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore; | use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext; | use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; | |||||
use Lc\CaracoleBundle\Container\Order\OrderShopContainer; | use Lc\CaracoleBundle\Container\Order\OrderShopContainer; | ||||
use Lc\CaracoleBundle\Container\Product\ProductFamilyContainer; | use Lc\CaracoleBundle\Container\Product\ProductFamilyContainer; | ||||
use Lc\CaracoleBundle\Controller\AdminControllerTrait; | use Lc\CaracoleBundle\Controller\AdminControllerTrait; | ||||
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface; | |||||
use Lc\CaracoleBundle\Field\Address\AddressField; | |||||
use Lc\CaracoleBundle\Resolver\SectionResolver; | use Lc\CaracoleBundle\Resolver\SectionResolver; | ||||
use Lc\SovBundle\Controller\AbstractAdminController; | use Lc\SovBundle\Controller\AbstractAdminController; | ||||
use Lc\SovBundle\Field\BooleanField; | |||||
use Lc\SovBundle\Field\CKEditorField; | |||||
use Lc\SovBundle\Field\StatusField; | |||||
use Lc\SovBundle\Repository\RepositoryQueryInterface; | use Lc\SovBundle\Repository\RepositoryQueryInterface; | ||||
use Symfony\Component\HttpFoundation\RequestStack; | |||||
use Symfony\Component\HttpFoundation\Response; | use Symfony\Component\HttpFoundation\Response; | ||||
abstract class ProductFamilyAdminController extends AbstractAdminController | abstract class ProductFamilyAdminController extends AbstractAdminController | ||||
return $this->get(ProductFamilyContainer::class)->getRepositoryQuery(); | return $this->get(ProductFamilyContainer::class)->getRepositoryQuery(); | ||||
} | } | ||||
// public function createIndexQueryBuilder(SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters): QueryBuilder | |||||
// { | |||||
// $queryBuilder = parent::createIndexQueryBuilder($searchDto, $entityDto, $fields, $filters); | |||||
// | |||||
// $queryBuilder->leftJoin('entity.productFamilySectionProperties', 'pfsp'); | |||||
// $queryBuilder->andWhereSection('pfsp', $this->getSectionCurrent()); | |||||
// $queryBuilder->addOrderBy('entity.id'); | |||||
// return $queryBuilder; | |||||
// } | |||||
public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore | public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore | ||||
{ | { | ||||
$responseParameters = parent::configureResponseParameters($responseParameters); | $responseParameters = parent::configureResponseParameters($responseParameters); |
{ | { | ||||
use ProductPropertyTrait; | use ProductPropertyTrait; | ||||
const BEHAVIOR_COUNT_STOCK_UNLIMITED = 'unlimited'; | |||||
const BEHAVIOR_COUNT_STOCK_BY_MEASURE = 'by-measure'; | const BEHAVIOR_COUNT_STOCK_BY_MEASURE = 'by-measure'; | ||||
const BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY = 'by-product-family'; | const BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY = 'by-product-family'; | ||||
const BEHAVIOR_COUNT_STOCK_BY_PRODUCT = 'by-product'; | const BEHAVIOR_COUNT_STOCK_BY_PRODUCT = 'by-product'; | ||||
public function getBehaviorCountStockChoices(): array | |||||
{ | |||||
return [ | |||||
self::BEHAVIOR_COUNT_STOCK_BY_MEASURE, | |||||
self::BEHAVIOR_COUNT_STOCK_BY_PRODUCT, | |||||
self::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY, | |||||
self::BEHAVIOR_COUNT_STOCK_UNLIMITED, | |||||
]; | |||||
} | |||||
const BEHAVIOR_DISPLAY_SALE_BY_MEASURE = 'by-measure'; | const BEHAVIOR_DISPLAY_SALE_BY_MEASURE = 'by-measure'; | ||||
const BEHAVIOR_DISPLAY_SALE_BY_QUANTITY = 'by-quantity'; | const BEHAVIOR_DISPLAY_SALE_BY_QUANTITY = 'by-quantity'; | ||||
public function getBehaviorDisplaySaleChoices(): array | |||||
{ | |||||
return [ | |||||
self::BEHAVIOR_DISPLAY_SALE_BY_MEASURE, | |||||
self::BEHAVIOR_DISPLAY_SALE_BY_QUANTITY, | |||||
]; | |||||
} | |||||
const BEHAVIOR_STOCK_CYCLE_RENEWABLE = 'renewable'; | |||||
const BEHAVIOR_STOCK_CYCLE_RENEWABLE_VALIDATION = 'renewable-with-validation'; | |||||
const BEHAVIOR_STOCK_CYCLE_NON_RENEWABLE = 'non-renewable'; | |||||
public function getBehaviorStockCycleChoices(): array | |||||
{ | |||||
return [ | |||||
self::BEHAVIOR_STOCK_CYCLE_NON_RENEWABLE, | |||||
self::BEHAVIOR_STOCK_CYCLE_RENEWABLE, | |||||
self::BEHAVIOR_STOCK_CYCLE_RENEWABLE_VALIDATION, | |||||
]; | |||||
} | |||||
const WARNING_MESSAGE_TYPE_SUCCESS = 'success'; | const WARNING_MESSAGE_TYPE_SUCCESS = 'success'; | ||||
const WARNING_MESSAGE_TYPE_ERROR = 'error'; | const WARNING_MESSAGE_TYPE_ERROR = 'error'; | ||||
const WARNING_MESSAGE_TYPE_WARNING = 'warning'; | const WARNING_MESSAGE_TYPE_WARNING = 'warning'; | ||||
const WARNING_MESSAGE_TYPE_INFO = 'info'; | const WARNING_MESSAGE_TYPE_INFO = 'info'; | ||||
public function getWaringMessageTypeChoices(): array | |||||
{ | |||||
return [ | |||||
self::WARNING_MESSAGE_TYPE_ERROR, | |||||
self::WARNING_MESSAGE_TYPE_INFO, | |||||
self::WARNING_MESSAGE_TYPE_SUCCESS, | |||||
self::WARNING_MESSAGE_TYPE_WARNING, | |||||
]; | |||||
} | |||||
const BEHAVIOR_ADD_TO_CART_SIMPLE = 'simple'; | const BEHAVIOR_ADD_TO_CART_SIMPLE = 'simple'; | ||||
const BEHAVIOR_ADD_TO_CART_MULTIPLE = 'multiple'; | const BEHAVIOR_ADD_TO_CART_MULTIPLE = 'multiple'; | ||||
public function getBehaviorAddToCartChoices(): array | |||||
{ | |||||
return [ | |||||
self::BEHAVIOR_ADD_TO_CART_MULTIPLE, | |||||
self::BEHAVIOR_ADD_TO_CART_SIMPLE, | |||||
]; | |||||
} | |||||
const BEHAVIOR_PRICE_BY_PIECE = 'by-piece'; | const BEHAVIOR_PRICE_BY_PIECE = 'by-piece'; | ||||
const BEHAVIOR_PRICE_BY_REFERENCE_UNIT = 'by-reference-unit'; | const BEHAVIOR_PRICE_BY_REFERENCE_UNIT = 'by-reference-unit'; | ||||
public function getBehaviorPriceChoices(): array | |||||
{ | |||||
return [ | |||||
self::BEHAVIOR_PRICE_BY_PIECE, | |||||
self::BEHAVIOR_PRICE_BY_REFERENCE_UNIT, | |||||
]; | |||||
} | |||||
const PROPERTY_ORGANIC_LABEL_AB = 'ab'; | const PROPERTY_ORGANIC_LABEL_AB = 'ab'; | ||||
const PROPERTY_ORGANIC_LABEL_NP = 'nature-progres'; | const PROPERTY_ORGANIC_LABEL_NP = 'nature-progres'; | ||||
const PROPERTY_ORGANIC_LABEL_HVE = 'hve'; | const PROPERTY_ORGANIC_LABEL_HVE = 'hve'; | ||||
const PROPERTY_ORGANIC_LABEL_TVVR = 'tvvr'; | const PROPERTY_ORGANIC_LABEL_TVVR = 'tvvr'; | ||||
public function getPropertyOrganicLabelChoices(): array | |||||
{ | |||||
return [ | |||||
self::PROPERTY_ORGANIC_LABEL_AB, | |||||
self::PROPERTY_ORGANIC_LABEL_NP, | |||||
self::PROPERTY_ORGANIC_LABEL_HVE, | |||||
self::PROPERTY_ORGANIC_LABEL_TVVR, | |||||
]; | |||||
} | |||||
const TYPE_EXPIRATION_DATE_DLC = 'dlc'; | const TYPE_EXPIRATION_DATE_DLC = 'dlc'; | ||||
const TYPE_EXPIRATION_DATE_DDM = 'ddm'; | const TYPE_EXPIRATION_DATE_DDM = 'ddm'; | ||||
const TYPE_EXPIRATION_DATE_DLUO = 'dluo'; | const TYPE_EXPIRATION_DATE_DLUO = 'dluo'; | ||||
public function getTypeExpirationDateChoices(): array | |||||
{ | |||||
return [ | |||||
self::TYPE_EXPIRATION_DATE_DLC, | |||||
self::TYPE_EXPIRATION_DATE_DDM, | |||||
self::TYPE_EXPIRATION_DATE_DLUO, | |||||
]; | |||||
} | |||||
const BEHAVIOR_EXPIRATION_DATE_BY_PRODUCT_FAMILY = 'by-product-family'; | const BEHAVIOR_EXPIRATION_DATE_BY_PRODUCT_FAMILY = 'by-product-family'; | ||||
const BEHAVIOR_EXPIRATION_DATE_BY_PRODUCT = 'by-product'; | const BEHAVIOR_EXPIRATION_DATE_BY_PRODUCT = 'by-product'; | ||||
public function getBehaviorExpirationDateChoices(): array | |||||
{ | |||||
return [ | |||||
self::BEHAVIOR_EXPIRATION_DATE_BY_PRODUCT_FAMILY, | |||||
self::BEHAVIOR_EXPIRATION_DATE_BY_PRODUCT | |||||
]; | |||||
} | |||||
// @TODO : Champ hydraté par ProductFamilyBuilder ? | // @TODO : Champ hydraté par ProductFamilyBuilder ? | ||||
protected $reductionCatalog; | protected $reductionCatalog; | ||||
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel; | use Lc\CaracoleBundle\Model\Product\ProductFamilyModel; | ||||
use Lc\CaracoleBundle\Model\Product\ProductInterface; | use Lc\CaracoleBundle\Model\Product\ProductInterface; | ||||
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface; | use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface; | ||||
use Lc\CaracoleBundle\Solver\Product\ProductFamilySectionPropertySolver; | |||||
use Lc\CaracoleBundle\Solver\Product\ProductSolver; | use Lc\CaracoleBundle\Solver\Product\ProductSolver; | ||||
class OrderShopSolver | class OrderShopSolver |
namespace Lc\CaracoleBundle\Solver\Product; | namespace Lc\CaracoleBundle\Solver\Product; | ||||
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | |||||
use Lc\CaracoleBundle\Model\Product\ProductFamilySectionPropertyInterface; | |||||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | |||||
class ProductFamilySectionPropertySolver | class ProductFamilySectionPropertySolver | ||||
{ | { | ||||
public function getProductFamilySectionProperty(ProductFamilyInterface $productFamily, SectionInterface $section):? ProductFamilySectionPropertyInterface | |||||
{ | |||||
foreach ($productFamily->getProductFamilySectionProperties() as $productFamilySectionProperty) { | |||||
if ($productFamilySectionProperty->getSection() == $section) { | |||||
return $productFamilySectionProperty; | |||||
} | |||||
} | |||||
return null; | |||||
} | |||||
} | } | ||||
$this->productSolver = $productSolver; | $this->productSolver = $productSolver; | ||||
} | } | ||||
public function getBehaviorCountStockChoices(): array | |||||
{ | |||||
return [ | |||||
ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE, | |||||
ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT, | |||||
ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY, | |||||
]; | |||||
} | |||||
public function getWaringMessageTypeChoices(): array | |||||
{ | |||||
return [ | |||||
ProductFamilyModel::WARNING_MESSAGE_TYPE_ERROR, | |||||
ProductFamilyModel::WARNING_MESSAGE_TYPE_INFO, | |||||
ProductFamilyModel::WARNING_MESSAGE_TYPE_SUCCESS, | |||||
ProductFamilyModel::WARNING_MESSAGE_TYPE_WARNING, | |||||
]; | |||||
} | |||||
public function getBehaviorAddToCartChoices(): array | |||||
{ | |||||
return [ | |||||
ProductFamilyModel::BEHAVIOR_ADD_TO_CART_MULTIPLE, | |||||
ProductFamilyModel::BEHAVIOR_ADD_TO_CART_SIMPLE, | |||||
]; | |||||
} | |||||
public function getBehaviorPriceChoices(): array | |||||
{ | |||||
return [ | |||||
ProductFamilyModel::BEHAVIOR_PRICE_BY_PIECE, | |||||
ProductFamilyModel::BEHAVIOR_PRICE_BY_REFERENCE_UNIT, | |||||
]; | |||||
} | |||||
public function getPropertyOrganicLabelChoices(): array | |||||
{ | |||||
return [ | |||||
ProductFamilyModel::PROPERTY_ORGANIC_LABEL_AB, | |||||
ProductFamilyModel::PROPERTY_ORGANIC_LABEL_NP, | |||||
ProductFamilyModel::PROPERTY_ORGANIC_LABEL_HVE, | |||||
ProductFamilyModel::PROPERTY_ORGANIC_LABEL_TVVR, | |||||
]; | |||||
} | |||||
public function getTypeExpirationDateChoices(): array | |||||
{ | |||||
return [ | |||||
ProductFamilyModel::TYPE_EXPIRATION_DATE_DLC, | |||||
ProductFamilyModel::TYPE_EXPIRATION_DATE_DDM, | |||||
ProductFamilyModel::TYPE_EXPIRATION_DATE_DLUO, | |||||
]; | |||||
} | |||||
public function getBehaviorExpirationDateChoices(): array | |||||
{ | |||||
return [ | |||||
ProductFamilyModel::BEHAVIOR_EXPIRATION_DATE_BY_PRODUCT_FAMILY, | |||||
ProductFamilyModel::BEHAVIOR_EXPIRATION_DATE_BY_PRODUCT, | |||||
]; | |||||
} | |||||
public function getBehaviorDisplaySaleChoices(): array | |||||
{ | |||||
return [ | |||||
ProductFamilyModel::BEHAVIOR_DISPLAY_SALE_BY_MEASURE, | |||||
ProductFamilyModel::BEHAVIOR_DISPLAY_SALE_BY_QUANTITY, | |||||
]; | |||||
} | |||||
public function countProductFamiliesOrganizedByParentCategory(array $categories): int | public function countProductFamiliesOrganizedByParentCategory(array $categories): int | ||||
{ | { | ||||
$count = 0; | $count = 0; | ||||
return $productFamily->getBehaviorPrice(); | return $productFamily->getBehaviorPrice(); | ||||
} | } | ||||
public function getBehaviorCountStockChoices(): array | |||||
{ | |||||
return [ | |||||
ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE, | |||||
ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT, | |||||
ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY, | |||||
ProductFamilyModel::BEHAVIOR_COUNT_STOCK_UNLIMITED, | |||||
]; | |||||
} | |||||
public function getBehaviorDisplaySaleChoices(): array | |||||
{ | |||||
return [ | |||||
ProductFamilyModel::BEHAVIOR_DISPLAY_SALE_BY_MEASURE, | |||||
ProductFamilyModel::BEHAVIOR_DISPLAY_SALE_BY_QUANTITY, | |||||
]; | |||||
} | |||||
public function getBehaviorStockCycleChoices(): array | |||||
{ | |||||
return [ | |||||
ProductFamilyModel::BEHAVIOR_STOCK_CYCLE_NON_RENEWABLE, | |||||
ProductFamilyModel::BEHAVIOR_STOCK_CYCLE_RENEWABLE, | |||||
ProductFamilyModel::BEHAVIOR_STOCK_CYCLE_RENEWABLE_VALIDATION, | |||||
]; | |||||
} | |||||
public function getWaringMessageTypeChoices(): array | |||||
{ | |||||
return [ | |||||
ProductFamilyModel::WARNING_MESSAGE_TYPE_ERROR, | |||||
ProductFamilyModel::WARNING_MESSAGE_TYPE_INFO, | |||||
ProductFamilyModel::WARNING_MESSAGE_TYPE_SUCCESS, | |||||
ProductFamilyModel::WARNING_MESSAGE_TYPE_WARNING, | |||||
]; | |||||
} | |||||
public function getBehaviorAddToCartChoices(): array | |||||
{ | |||||
return [ | |||||
ProductFamilyModel::BEHAVIOR_ADD_TO_CART_MULTIPLE, | |||||
ProductFamilyModel::BEHAVIOR_ADD_TO_CART_SIMPLE, | |||||
]; | |||||
} | |||||
public function getBehaviorPriceChoices(): array | |||||
{ | |||||
return [ | |||||
ProductFamilyModel::BEHAVIOR_PRICE_BY_PIECE, | |||||
ProductFamilyModel::BEHAVIOR_PRICE_BY_REFERENCE_UNIT, | |||||
]; | |||||
} | |||||
public function getPropertyOrganicLabelChoices(): array | |||||
{ | |||||
return [ | |||||
ProductFamilyModel::PROPERTY_ORGANIC_LABEL_AB, | |||||
ProductFamilyModel::PROPERTY_ORGANIC_LABEL_NP, | |||||
ProductFamilyModel::PROPERTY_ORGANIC_LABEL_HVE, | |||||
ProductFamilyModel::PROPERTY_ORGANIC_LABEL_TVVR, | |||||
]; | |||||
} | |||||
public function getTypeExpirationDateChoices(): array | |||||
{ | |||||
return [ | |||||
ProductFamilyModel::TYPE_EXPIRATION_DATE_DLC, | |||||
ProductFamilyModel::TYPE_EXPIRATION_DATE_DDM, | |||||
ProductFamilyModel::TYPE_EXPIRATION_DATE_DLUO, | |||||
]; | |||||
} | |||||
public function getBehaviorExpirationDateChoices(): array | |||||
{ | |||||
return [ | |||||
ProductFamilyModel::BEHAVIOR_EXPIRATION_DATE_BY_PRODUCT_FAMILY, | |||||
ProductFamilyModel::BEHAVIOR_EXPIRATION_DATE_BY_PRODUCT, | |||||
]; | |||||
} | |||||
public function getBuyingPriceByRefUnitInherited(ProductFamilyInterface $productFamily): ?float | public function getBuyingPriceByRefUnitInherited(ProductFamilyInterface $productFamily): ?float | ||||
{ | { | ||||
return $productFamily->getBuyingPriceByRefUnit(); | return $productFamily->getBuyingPriceByRefUnit(); |
return $product->getProductFamily()->getAvailableQuantity(); | return $product->getProductFamily()->getAvailableQuantity(); | ||||
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT : | case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT : | ||||
return $product->getAvailableQuantity(); | return $product->getAvailableQuantity(); | ||||
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_UNLIMITED : | |||||
return false; | |||||
} | } | ||||
} | } | ||||
public function getAvailableQuantitySupplierInherited(ProductInterface $product) | |||||
{ | |||||
switch ($product->getProductFamily()->getBehaviorCountStock()) { | |||||
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY : | |||||
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE : | |||||
return $product->getProductFamily()->getAvailableQuantitySupplier(); | |||||
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT : | |||||
return $product->getAvailableQuantitySupplier(); | |||||
} | |||||
} | |||||
/*public function getTaxRateInherited(ProductInterface $product) | /*public function getTaxRateInherited(ProductInterface $product) | ||||
{ | { | ||||
return $product->getProductFamily()->getTaxRateInherited(); | return $product->getProductFamily()->getTaxRateInherited(); |