Parcourir la source

Labels de qualité

packProduct
Guillaume il y a 3 ans
Parent
révision
b2c5cbb1f0
12 fichiers modifiés avec 311 ajouts et 27 suppressions
  1. +40
    -0
      Container/Product/QualityLabelContainer.php
  2. +7
    -0
      Controller/ControllerTrait.php
  3. +32
    -0
      Controller/Product/QualityLabelAdminController.php
  4. +19
    -0
      Factory/Product/QualityLabelFactory.php
  5. +50
    -16
      Model/Product/ProductFamilyModel.php
  6. +39
    -0
      Model/Product/QualityLabel.php
  7. +8
    -0
      Model/Product/QualityLabelInterface.php
  8. +15
    -0
      Repository/Product/QualityLabelRepository.php
  9. +19
    -0
      Repository/Product/QualityLabelRepositoryQuery.php
  10. +31
    -0
      Repository/Product/QualityLabelStore.php
  11. +5
    -0
      Resources/translations/admin.fr.yaml
  12. +46
    -11
      Solver/Product/ProductFamilySolver.php

+ 40
- 0
Container/Product/QualityLabelContainer.php Voir le fichier

@@ -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;
}

}

+ 7
- 0
Controller/ControllerTrait.php Voir le fichier

@@ -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);
}
}

+ 32
- 0
Controller/Product/QualityLabelAdminController.php Voir le fichier

@@ -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'),
];
}

}

+ 19
- 0
Factory/Product/QualityLabelFactory.php Voir le fichier

@@ -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;
}

}

+ 50
- 16
Model/Product/ProductFamilyModel.php Voir le fichier

@@ -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;

@@ -100,20 +97,26 @@ abstract class ProductFamilyModel extends AbstractFullEntity implements ProductP
];
}

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';

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,
];
}
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';
@@ -319,10 +322,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()
@@ -820,4 +829,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;
}


}

+ 39
- 0
Model/Product/QualityLabel.php Voir le fichier

@@ -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;
}

}

+ 8
- 0
Model/Product/QualityLabelInterface.php Voir le fichier

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

namespace Lc\CaracoleBundle\Model\Product;

interface QualityLabelInterface
{

}

+ 15
- 0
Repository/Product/QualityLabelRepository.php Voir le fichier

@@ -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);
}
}

+ 19
- 0
Repository/Product/QualityLabelRepositoryQuery.php Voir le fichier

@@ -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');
}
}

+ 31
- 0
Repository/Product/QualityLabelStore.php Voir le fichier

@@ -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;
}
}

+ 5
- 0
Resources/translations/admin.fr.yaml Voir le fichier

@@ -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:

+ 46
- 11
Solver/Product/ProductFamilySolver.php Voir le fichier

@@ -315,17 +315,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 [
@@ -374,5 +363,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;
}

}


Chargement…
Annuler
Enregistrer