Browse Source

[Frontend] Réductions : gérer affichage réduction (affichée ou non)

packProduct
Guillaume 2 years ago
parent
commit
47d90efbe1
4 changed files with 67 additions and 19 deletions
  1. +10
    -2
      Container/Reduction/ReductionCatalogContainer.php
  2. +25
    -2
      Repository/Product/ProductFamilyStore.php
  3. +18
    -15
      Solver/Product/ProductFamilySolver.php
  4. +14
    -0
      Solver/Reduction/ReductionCatalogSolver.php

+ 10
- 2
Container/Reduction/ReductionCatalogContainer.php View File

@@ -7,6 +7,7 @@ use Lc\CaracoleBundle\Definition\Field\Reduction\ReductionCatalogFieldDefinition
use Lc\CaracoleBundle\Factory\Reduction\ReductionCatalogFactory;
use Lc\CaracoleBundle\Repository\Reduction\ReductionCatalogRepositoryQuery;
use Lc\CaracoleBundle\Repository\Reduction\ReductionCatalogStore;
use Lc\CaracoleBundle\Solver\Reduction\ReductionCatalogSolver;

class ReductionCatalogContainer
{
@@ -14,20 +15,22 @@ class ReductionCatalogContainer
protected ReductionCatalogRepositoryQuery $repositoryQuery;
protected ReductionCatalogStore $store;
protected ReductionCatalogFieldDefinition $fieldDefinition;
protected ReductionCatalogSolver $solver;

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


public static function getEntityFqcn()
{
return ReductionCatalog::class;
@@ -55,4 +58,9 @@ class ReductionCatalogContainer
return $this->fieldDefinition;
}

public function getSolver(): ReductionCatalogSolver
{
return $this->solver;
}

}

+ 25
- 2
Repository/Product/ProductFamilyStore.php View File

@@ -8,6 +8,7 @@ use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface;
use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\CaracoleBundle\Solver\Reduction\ReductionCatalogSolver;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\CaracoleBundle\Repository\AbstractStore;
use Lc\SovBundle\Repository\RepositoryQueryInterface;
@@ -19,11 +20,16 @@ class ProductFamilyStore extends AbstractStore

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

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

public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
@@ -50,6 +56,23 @@ class ProductFamilyStore extends AbstractStore
return $query;
}

public function isReductionCatalogDisplayed(ProductFamilyInterface $productFamily): bool
{
$reductionCatalog = $this->reductionCatalogStore->setMerchant($this->merchant)
->getByProductFamily($productFamily);

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

public function hasReductionCatalog(ProductFamilyInterface $productFamily): bool
{
$reductionCatalog = $this->reductionCatalogStore->setMerchant($this->merchant)
->getByProductFamily($productFamily);

return (bool)$reductionCatalog;
}

public function getByParentCategory(
ProductCategoryInterface $parentCategory,
$user = null,

+ 18
- 15
Solver/Product/ProductFamilySolver.php View File

@@ -7,22 +7,28 @@ use Doctrine\Common\Collections\Collection;
use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
use Lc\CaracoleBundle\Model\Product\ProductFamilySectionPropertyInterface;
use Lc\CaracoleBundle\Model\Product\ProductInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Solver\Reduction\ReductionCatalogSolver;

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

public function __construct(ProductSolver $productSolver, ProductFamilySectionPropertySolver $productFamilySectionPropertySolver, ProductCategorySolver $productCategorySolver)
{
protected ReductionCatalogSolver $reductionCatalogSolver;

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

public static function getBehaviorCountStockChoices(): array
@@ -87,7 +93,6 @@ class ProductFamilySolver
];
}


public function countProductFamiliesOrganizedByParentCategory(array $categories): int
{
$count = 0;
@@ -178,11 +183,9 @@ class ProductFamilySolver
$productCategories = $productFamily->getProductCategories();

if (count($productCategories) > 0) {

foreach ($productCategories as $productCategory) {
if($productCategory->getSection()->getId() == $section->getId()
if ($productCategory->getSection()->getId() == $section->getId()
&& $productCategory->getParent() !== null) {

return $productCategory->getParent();
}
}
@@ -372,9 +375,9 @@ class ProductFamilySolver

public function getQuantityInherited(ProductFamilyInterface $productFamily): ?float
{
if($productFamily->getQuantity()){
if ($productFamily->getQuantity()) {
return $productFamily->getQuantity();
}else{
} else {
return 1;
}
}
@@ -394,7 +397,7 @@ class ProductFamilySolver
$strLabels = '';
$qualityLabelArray = $productFamily->getQualityLabels()->toArray();

foreach($qualityLabelArray as $index => $qualityLabel) {
foreach ($qualityLabelArray as $index => $qualityLabel) {
$strLabels .= $qualityLabel->getTitle();

if ($index !== array_key_last($qualityLabelArray)) {
@@ -481,11 +484,11 @@ class ProductFamilySolver
}


public function isCategoriesOnlineInSection(ProductFamilyInterface $productFamily, SectionInterface $section):bool
public function isCategoriesOnlineInSection(ProductFamilyInterface $productFamily, SectionInterface $section): bool
{
$isCategoriesOnlineInSection =false;
foreach ($productFamily->getProductCategories() as $productCatgory){
if($productCatgory->getSection() === $section && $this->productCategorySolver->isOnline($productCatgory)){
$isCategoriesOnlineInSection = false;
foreach ($productFamily->getProductCategories() as $productCatgory) {
if ($productCatgory->getSection() === $section && $this->productCategorySolver->isOnline($productCatgory)) {
$isCategoriesOnlineInSection = true;
}
}

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

@@ -0,0 +1,14 @@
<?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