@@ -0,0 +1,40 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Container\Product; | |||
use Lc\CaracoleBundle\Factory\Product\QualityLabelFactory; | |||
use Lc\CaracoleBundle\Repository\Product\QualityLabelRepositoryQuery; | |||
use Lc\CaracoleBundle\Repository\Product\QualityLabelStore; | |||
class QualityLabelContainer | |||
{ | |||
protected QualityLabelFactory $factory; | |||
protected QualityLabelRepositoryQuery $repositoryQuery; | |||
protected QualityLabelStore $store; | |||
public function __construct( | |||
QualityLabelFactory $factory, | |||
QualityLabelRepositoryQuery $repositoryQuery, | |||
QualityLabelStore $store | |||
) { | |||
$this->factory = $factory; | |||
$this->repositoryQuery = $repositoryQuery; | |||
$this->store = $store; | |||
} | |||
public function getFactory(): QualityLabelFactory | |||
{ | |||
return $this->factory; | |||
} | |||
public function getRepositoryQuery(): QualityLabelRepositoryQuery | |||
{ | |||
return $this->repositoryQuery; | |||
} | |||
public function getStore(): QualityLabelStore | |||
{ | |||
return $this->store; | |||
} | |||
} |
@@ -24,6 +24,7 @@ use Lc\CaracoleBundle\Container\Product\ProductCategoryContainer; | |||
use Lc\CaracoleBundle\Container\Product\ProductContainer; | |||
use Lc\CaracoleBundle\Container\Product\ProductFamilyContainer; | |||
use Lc\CaracoleBundle\Container\Product\ProductFamilySectionPropertyContainer; | |||
use Lc\CaracoleBundle\Container\Product\QualityLabelContainer; | |||
use Lc\CaracoleBundle\Container\Reduction\ReductionCartContainer; | |||
use Lc\CaracoleBundle\Container\Reduction\ReductionCatalogContainer; | |||
use Lc\CaracoleBundle\Container\Reduction\ReductionCreditContainer; | |||
@@ -88,6 +89,7 @@ trait ControllerTrait | |||
VisitorContainer::class => VisitorContainer::class, | |||
DistributionContainer::class => DistributionContainer::class, | |||
ProductFamilySectionPropertyContainer::class => ProductFamilySectionPropertyContainer::class, | |||
QualityLabelContainer::class => QualityLabelContainer::class, | |||
] | |||
); | |||
} | |||
@@ -313,4 +315,9 @@ trait ControllerTrait | |||
{ | |||
return $this->get(VisitorContainer::class); | |||
} | |||
public function getQualityLabelContainer(): QualityLabelContainer | |||
{ | |||
return $this->get(QualityLabelContainer::class); | |||
} | |||
} |
@@ -0,0 +1,32 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Controller\Product; | |||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; | |||
use Lc\CaracoleBundle\Controller\AbstractAdminController; | |||
use Lc\SovBundle\Field\ImageManagerField; | |||
use Lc\SovBundle\Repository\RepositoryQueryInterface; | |||
abstract class QualityLabelAdminController extends AbstractAdminController | |||
{ | |||
public function getRepositoryQuery() :RepositoryQueryInterface | |||
{ | |||
return $this->getQualityLabelContainer()->getRepositoryQuery(); | |||
} | |||
public function createEntity(string $entityFqcn) | |||
{ | |||
return $this->getQualityLabelContainer()->getFactory()->create(); | |||
} | |||
public function configureFields(string $pageName): iterable | |||
{ | |||
return [ | |||
TextField::new('title'), | |||
ImageManagerField::new('image'), | |||
TextField::new('devAlias'), | |||
]; | |||
} | |||
} |
@@ -0,0 +1,19 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Factory\Product; | |||
use App\Entity\Product\QualityLabel; | |||
use Lc\CaracoleBundle\Model\Product\QualityLabelInterface; | |||
use Lc\SovBundle\Factory\AbstractFactory; | |||
class QualityLabelFactory extends AbstractFactory | |||
{ | |||
public function create(): QualityLabelInterface | |||
{ | |||
$qualityLabel = new QualityLabel(); | |||
$qualityLabel->setStatus(1); | |||
return $qualityLabel; | |||
} | |||
} |
@@ -9,10 +9,7 @@ use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface; | |||
use Lc\CaracoleBundle\Doctrine\Extension\PriceInterface; | |||
use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyTrait; | |||
use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface; | |||
use Gedmo\Mapping\Annotation as Gedmo; | |||
use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface; | |||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | |||
use Lc\SovBundle\Doctrine\Extension\BlameableNullableTrait; | |||
use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity; | |||
use Lc\SovBundle\Model\File\FileInterface; | |||
@@ -42,10 +39,25 @@ abstract class ProductFamilyModel extends AbstractFullEntity implements ProductP | |||
const BEHAVIOR_PRICE_BY_PIECE = 'by-piece'; | |||
const BEHAVIOR_PRICE_BY_REFERENCE_UNIT = 'by-reference-unit'; | |||
const PROPERTY_ORGANIC_LABEL_AB = 'ab'; | |||
const PROPERTY_ORGANIC_LABEL_NP = 'nature-progres'; | |||
const PROPERTY_ORGANIC_LABEL_HVE = 'hve'; | |||
const PROPERTY_ORGANIC_LABEL_TVVR = 'tvvr'; | |||
const QUALITY_LABEL_AB = 'ab'; | |||
const QUALITY_LABEL_NP = 'nature-progres'; | |||
const QUALITY_LABEL_HVE = 'hve'; | |||
const QUALITY_LABEL_TVVR = 'tvvr'; | |||
const QUALITY_LABEL_AOC = 'aoc'; | |||
const QUALITY_LABEL_AOP = 'aop'; | |||
const QUALITY_LABEL_IGP = 'igp'; | |||
static $organicLabels = [ | |||
self::QUALITY_LABEL_AB, | |||
self::QUALITY_LABEL_NP, | |||
self::QUALITY_LABEL_HVE, | |||
self::QUALITY_LABEL_TVVR | |||
]; | |||
static $geographicLabels = [ | |||
self::QUALITY_LABEL_AOC, | |||
self::QUALITY_LABEL_AOP, | |||
self::QUALITY_LABEL_IGP, | |||
]; | |||
const TYPE_EXPIRATION_DATE_DLC = 'dlc'; | |||
const TYPE_EXPIRATION_DATE_DDM = 'ddm'; | |||
@@ -234,10 +246,16 @@ abstract class ProductFamilyModel extends AbstractFullEntity implements ProductP | |||
*/ | |||
protected $image; | |||
/** | |||
* @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\Product\QualityLabelInterface", fetch="EAGER") | |||
*/ | |||
protected $qualityLabels; | |||
public function __construct() | |||
{ | |||
$this->productCategories = new ArrayCollection(); | |||
$this->products = new ArrayCollection(); | |||
$this->qualityLabels = new ArrayCollection(); | |||
} | |||
public function __toString() | |||
@@ -735,4 +753,29 @@ abstract class ProductFamilyModel extends AbstractFullEntity implements ProductP | |||
return $this; | |||
} | |||
/** | |||
* @return Collection|QualityLabelInterface[] | |||
*/ | |||
public function getQualityLabels(): Collection | |||
{ | |||
return $this->qualityLabels; | |||
} | |||
public function addQualityLabel(QualityLabelInterface $qualityLabel): self | |||
{ | |||
if (!$this->qualityLabels->contains($qualityLabel)) { | |||
$this->qualityLabels[] = $qualityLabel; | |||
} | |||
return $this; | |||
} | |||
public function removeQualityLabel(QualityLabelInterface $qualityLabel): self | |||
{ | |||
$this->qualityLabels->removeElement($qualityLabel); | |||
return $this; | |||
} | |||
} |
@@ -0,0 +1,39 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Model\Product; | |||
use Doctrine\ORM\Mapping as ORM; | |||
use Lc\SovBundle\Doctrine\EntityInterface; | |||
use Lc\SovBundle\Doctrine\Extension\SortableInterface; | |||
use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity; | |||
use Lc\SovBundle\Model\File\FileInterface; | |||
/** | |||
* @ORM\MappedSuperclass() | |||
*/ | |||
abstract class QualityLabel extends AbstractFullEntity implements EntityInterface, SortableInterface, | |||
QualityLabelInterface | |||
{ | |||
/** | |||
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\File\FileInterface", cascade={"persist", "remove"}) | |||
*/ | |||
protected $image; | |||
public function __toString() | |||
{ | |||
return $this->getTitle(); | |||
} | |||
public function getImage(): ?FileInterface | |||
{ | |||
return $this->image; | |||
} | |||
public function setImage(?FileInterface $image): self | |||
{ | |||
$this->image = $image; | |||
return $this; | |||
} | |||
} |
@@ -0,0 +1,8 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Model\Product; | |||
interface QualityLabelInterface | |||
{ | |||
} |
@@ -0,0 +1,15 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Repository\Product; | |||
use App\Entity\Product\QualityLabel; | |||
use Doctrine\Persistence\ManagerRegistry; | |||
use Lc\SovBundle\Repository\AbstractRepository; | |||
class QualityLabelRepository extends AbstractRepository | |||
{ | |||
public function __construct(ManagerRegistry $registry) | |||
{ | |||
parent::__construct($registry, QualityLabel::class); | |||
} | |||
} |
@@ -0,0 +1,19 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Repository\Product; | |||
use Knp\Component\Pager\PaginatorInterface; | |||
use Lc\SovBundle\Repository\AbstractRepositoryQuery; | |||
class QualityLabelRepositoryQuery extends AbstractRepositoryQuery | |||
{ | |||
public function __construct(QualityLabelRepository $repository, PaginatorInterface $paginator) | |||
{ | |||
parent::__construct($repository, 'r', $paginator); | |||
} | |||
public function orderByDefault(): AbstractRepositoryQuery | |||
{ | |||
return $this->orderBy('position', 'ASC'); | |||
} | |||
} |
@@ -0,0 +1,31 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Repository\Product; | |||
use Lc\SovBundle\Repository\AbstractStore; | |||
use Lc\SovBundle\Repository\RepositoryQueryInterface; | |||
class QualityLabelStore extends AbstractStore | |||
{ | |||
protected QualityLabelRepositoryQuery $query; | |||
public function __construct(QualityLabelRepositoryQuery $query) | |||
{ | |||
$this->query = $query; | |||
} | |||
public function orderByDefault(RepositoryQueryInterface $query) :RepositoryQueryInterface | |||
{ | |||
return $query; | |||
} | |||
public function filtersDefault($query):RepositoryQueryInterface | |||
{ | |||
return $query; | |||
} | |||
public function relationsDefault($query):RepositoryQueryInterface | |||
{ | |||
return $query; | |||
} | |||
} |
@@ -174,6 +174,11 @@ entity: | |||
fields: | |||
priceWithTax: Prix de vente | |||
sales: Historique des ventes | |||
propertyQualityLabelActive: Marquer le produit comme labellisé | |||
QualityLabel: | |||
label: Label de qualité | |||
label_plurial: Labels de qualité | |||
form: | |||
user_merchant: |
@@ -9,7 +9,6 @@ use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | |||
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel; | |||
use Lc\CaracoleBundle\Model\Product\ProductInterface; | |||
use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface; | |||
use Lc\CaracoleBundle\Solver\Price\PriceSolver; | |||
class ProductFamilySolver | |||
{ | |||
@@ -57,17 +56,6 @@ class ProductFamilySolver | |||
]; | |||
} | |||
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 [ | |||
@@ -385,5 +373,51 @@ class ProductFamilySolver | |||
return $productFamily->getPrice(); | |||
} | |||
public function getOrganicLabel(ProductFamilyInterface $productFamily) | |||
{ | |||
return $this->getQualityLabelByArray($productFamily, ProductFamilyModel::$organicLabels); | |||
} | |||
public function getGeographicLabel(ProductFamilyInterface $productFamily) | |||
{ | |||
return $this->getQualityLabelByArray($productFamily, ProductFamilyModel::$geographicLabels); | |||
} | |||
public function getQualityLabelByArray(ProductFamilyInterface $productFamily, array $labelArray) | |||
{ | |||
$qualityLabelArray = $productFamily->getQualityLabels(); | |||
foreach($qualityLabelArray as $qualityLabel) { | |||
if(in_array($qualityLabel->getDevAlias(), $labelArray)) { | |||
return $qualityLabel; | |||
} | |||
} | |||
return false; | |||
} | |||
public function hasOrganicLabel(ProductFamilyInterface $productFamily) | |||
{ | |||
return $this->hasQualityLabelByArray($productFamily, ProductFamilyModel::$organicLabels); | |||
} | |||
public function hasGeographicLabel(ProductFamilyInterface $productFamily) | |||
{ | |||
return $this->hasQualityLabelByArray($productFamily, ProductFamilyModel::$geographicLabels); | |||
} | |||
public function hasQualityLabelByArray(ProductFamilyInterface $productFamily, array $labelArray) | |||
{ | |||
$qualityLabelArray = $productFamily->getQualityLabels(); | |||
foreach($qualityLabelArray as $qualityLabel) { | |||
if(in_array($qualityLabel->getDevAlias(), $labelArray)) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
} | |||