Browse Source

Merge branch 'develop' of https://forge.laclic.fr/Laclic/CaracoleBundle into develop

packProduct
Fab 3 years ago
parent
commit
6b1b637c4e
12 changed files with 311 additions and 19 deletions
  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
    -7
      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
    -12
      Solver/Product/ProductFamilySolver.php

+ 40
- 0
Container/Product/QualityLabelContainer.php View File

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

use Lc\CaracoleBundle\Container\Product\ProductContainer; use Lc\CaracoleBundle\Container\Product\ProductContainer;
use Lc\CaracoleBundle\Container\Product\ProductFamilyContainer; use Lc\CaracoleBundle\Container\Product\ProductFamilyContainer;
use Lc\CaracoleBundle\Container\Product\ProductFamilySectionPropertyContainer; use Lc\CaracoleBundle\Container\Product\ProductFamilySectionPropertyContainer;
use Lc\CaracoleBundle\Container\Product\QualityLabelContainer;
use Lc\CaracoleBundle\Container\Reduction\ReductionCartContainer; use Lc\CaracoleBundle\Container\Reduction\ReductionCartContainer;
use Lc\CaracoleBundle\Container\Reduction\ReductionCatalogContainer; use Lc\CaracoleBundle\Container\Reduction\ReductionCatalogContainer;
use Lc\CaracoleBundle\Container\Reduction\ReductionCreditContainer; use Lc\CaracoleBundle\Container\Reduction\ReductionCreditContainer;
VisitorContainer::class => VisitorContainer::class, VisitorContainer::class => VisitorContainer::class,
DistributionContainer::class => DistributionContainer::class, DistributionContainer::class => DistributionContainer::class,
ProductFamilySectionPropertyContainer::class => ProductFamilySectionPropertyContainer::class, ProductFamilySectionPropertyContainer::class => ProductFamilySectionPropertyContainer::class,
QualityLabelContainer::class => QualityLabelContainer::class,
] ]
); );
} }
{ {
return $this->get(VisitorContainer::class); return $this->get(VisitorContainer::class);
} }

public function getQualityLabelContainer(): QualityLabelContainer
{
return $this->get(QualityLabelContainer::class);
}
} }

+ 32
- 0
Controller/Product/QualityLabelAdminController.php View File

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

<?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
- 7
Model/Product/ProductFamilyModel.php View File

use Lc\CaracoleBundle\Doctrine\Extension\PriceInterface; use Lc\CaracoleBundle\Doctrine\Extension\PriceInterface;
use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyTrait; use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyTrait;
use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface; use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface;
use Gedmo\Mapping\Annotation as Gedmo;
use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface; 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\Doctrine\Pattern\AbstractFullEntity;
use Lc\SovBundle\Model\File\FileInterface; use Lc\SovBundle\Model\File\FileInterface;


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


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_DLC = 'dlc';
const TYPE_EXPIRATION_DATE_DDM = 'ddm'; const TYPE_EXPIRATION_DATE_DDM = 'ddm';
*/ */
protected $image; protected $image;


/**
* @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\Product\QualityLabelInterface", fetch="EAGER")
*/
protected $qualityLabels;

public function __construct() public function __construct()
{ {
$this->productCategories = new ArrayCollection(); $this->productCategories = new ArrayCollection();
$this->products = new ArrayCollection(); $this->products = new ArrayCollection();
$this->qualityLabels = new ArrayCollection();
} }


public function __toString() public function __toString()
return $this; 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 View File

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

<?php

namespace Lc\CaracoleBundle\Model\Product;

interface QualityLabelInterface
{

}

+ 15
- 0
Repository/Product/QualityLabelRepository.php View File

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

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

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

fields: fields:
priceWithTax: Prix de vente priceWithTax: Prix de vente
sales: Historique des ventes sales: Historique des ventes
propertyQualityLabelActive: Marquer le produit comme labellisé

QualityLabel:
label: Label de qualité
label_plurial: Labels de qualité


form: form:
user_merchant: user_merchant:

+ 46
- 12
Solver/Product/ProductFamilySolver.php View File

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\ReductionCatalogInterface; use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;


class ProductFamilySolver 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 public function getTypeExpirationDateChoices(): array
{ {
return [ return [
return $productFamily->getPrice(); 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;
}

} }



Loading…
Cancel
Save