Browse Source

COrrectif - priorité des promotions

packProduct
Fabien Normand 2 years ago
parent
commit
79fee16e76
3 changed files with 112 additions and 94 deletions
  1. +68
    -67
      Repository/Product/ProductFamilyStore.php
  2. +31
    -27
      Repository/Reduction/ReductionCatalogRepositoryQuery.php
  3. +13
    -0
      Solver/Price/ProductPriceSolver.php

+ 68
- 67
Repository/Product/ProductFamilyStore.php View File

} }


public function getByParentCategory( public function getByParentCategory(
ProductCategoryInterface $parentCategory,
$user = null,
$query = null
) {
ProductCategoryInterface $parentCategory,
$user = null,
$query = null
)
{
$productFamiliesArray = []; $productFamiliesArray = [];


foreach ($parentCategory->getChildrens() as $i => $category) { foreach ($parentCategory->getChildrens() as $i => $category) {


// getProductFamiliesByCategory // getProductFamiliesByCategory
public function getByCategory( public function getByCategory(
ProductCategoryInterface $productCategory,
$query = null
) {
ProductCategoryInterface $productCategory,
$query = null
)
{
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);


$query $query
->filterIsOnline()
->filterByProductCategory($productCategory);
->filterIsOnline()
->filterByProductCategory($productCategory);


return $query->find(); return $query->find();
} }
public function getByCategoryOnlineAndOffline( public function getByCategoryOnlineAndOffline(
ProductCategoryInterface $productCategory, ProductCategoryInterface $productCategory,
$query = null $query = null
) {
)
{
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);


$query $query
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);


$query $query
->filterByPropertyNoveltyExpirationDate()
->filterIsOnline();
->filterByPropertyNoveltyExpirationDate()
->filterIsOnline();


$results = $query->find(); $results = $query->find();


$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);


$query $query
->filterIsOrganicLabel()
->filterIsOnline();
->filterIsOrganicLabel()
->filterIsOnline();


$results = $query->find(); $results = $query->find();


{ {
if ($user) { if ($user) {
return $this->getWithReductions( return $this->getWithReductions(
$user->getFavoriteProductFamilies(),
$user,
false,
$organizeByParentCategory
$user->getFavoriteProductFamilies(),
$user,
false,
$organizeByParentCategory
); );
} }




// findByTerms // findByTerms
public function getByTerms( public function getByTerms(
$terms,
$maxResults = false,
$organizeByParentCategory = false,
$user = null,
$query = null
) {
$terms,
$maxResults = false,
$organizeByParentCategory = false,
$user = null,
$query = null
)
{
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);


$query->filterIsOnline(); $query->filterIsOnline();
} }


public function getBestReductionCatalog( public function getBestReductionCatalog(
ProductFamilyInterface $productFamily,
ReductionCatalogInterface $reductionCatalog1,
ReductionCatalogInterface $reductionCatalog2
) {
$price1 = $this->priceSolver->applyReductionCatalog(
$productFamily,
$this->priceSolver->getPrice($productFamily),
$this->priceSolver->getPriceWithTax($productFamily),
1,
$reductionCatalog1
ProductFamilyInterface $productFamily,
ReductionCatalogInterface $reductionCatalog1,
ReductionCatalogInterface $reductionCatalog2
)
{
$price1 = $this->priceSolver->getPriceWithTaxByReduction(
$productFamily,
$reductionCatalog1
); );

$price2 = $this->priceSolver->applyReductionCatalog(
$productFamily,
$this->priceSolver->getPrice($productFamily),
$this->priceSolver->getPriceWithTax($productFamily),
1,
$reductionCatalog2
$price2 = $this->priceSolver->getPriceWithTaxByReduction(
$productFamily,
$reductionCatalog2
); );



if ($price1 > $price2) { if ($price1 > $price2) {
return $reductionCatalog2; return $reductionCatalog2;
} else { } else {


// setReductionForProductFamilies // setReductionForProductFamilies
public function getWithReductions( public function getWithReductions(
$productFamilies,
UserInterface $user = null,
$organizeByCategory = false,
$organizeByParentCategory = false,
$onlyOnDiscount = false
) {
$productFamilies,
UserInterface $user = null,
$organizeByCategory = false,
$organizeByParentCategory = false,
$onlyOnDiscount = false
)
{
$conditions = [ $conditions = [
'ids' => [],
'categories' => [],
'productFamiliesIds' => [],
'categories' => [],
'productFamilies' => [],
]; ];


foreach ($productFamilies as $productFamily) { foreach ($productFamilies as $productFamily) {
$conditions['ids'][] = $productFamily->getId();
$conditions['productFamiliesIds'][] = $productFamily->getId();
$conditions['productFamilies'][] = $productFamily;
$conditions['categories'] = array_merge( $conditions['categories'] = array_merge(
$conditions['categories'],
$productFamily->getProductCategories()->toArray()
$conditions['categories'],
$productFamily->getProductCategories()->toArray()
); );
} }


if ($productFamilies) { if ($productFamilies) {
$reductionCatalogs = $this->reductionCatalogStore->getByProductFamiliesConditions( $reductionCatalogs = $this->reductionCatalogStore->getByProductFamiliesConditions(
$conditions,
$user
$conditions,
$user
); );
} }


$conditionProductFamilies = $conditionProductFamily = $conditionProductCategory = false; $conditionProductFamilies = $conditionProductFamily = $conditionProductCategory = false;


if ($reductionCatalog->getProductFamilies()->contains( if ($reductionCatalog->getProductFamilies()->contains(
$productFamily
) || $reductionCatalog->getProductFamilies()->isEmpty()) {
$productFamily
) || $reductionCatalog->getProductFamilies()->isEmpty()) {
$conditionProductFamilies = true; $conditionProductFamilies = true;
} }


if ($reductionCatalog->getProductFamily() == $productFamily || $reductionCatalog->getProductFamily(
) === null) {
if ($reductionCatalog->getProductFamily() == $productFamily || $reductionCatalog->getProductFamily() === null) {
$conditionProductFamily = true; $conditionProductFamily = true;
} }


foreach ($productFamily->getProductCategories() as $productCategory) { foreach ($productFamily->getProductCategories() as $productCategory) {
if ($reductionCatalog->getProductCategories()->contains( if ($reductionCatalog->getProductCategories()->contains(
$productCategory
) || $reductionCatalog->getProductCategories()->isEmpty()) {
$productCategory
) || $reductionCatalog->getProductCategories()->isEmpty()) {
$conditionProductCategory = true; $conditionProductCategory = true;
} }
} }
if ($conditionProductFamilies && $conditionProductFamily && $conditionProductCategory) { if ($conditionProductFamilies && $conditionProductFamily && $conditionProductCategory) {
if ($productFamily->getReductionCatalog()) { if ($productFamily->getReductionCatalog()) {
$productFamily->setReductionCatalog( $productFamily->setReductionCatalog(
$this->getBestReductionCatalog(
$productFamily,
$reductionCatalog,
$productFamily->getReductionCatalog()
)
$this->getBestReductionCatalog(
$productFamily,
$reductionCatalog,
$productFamily->getReductionCatalog()
)
); );
} else { } else {
$productFamily->setReductionCatalog($reductionCatalog); $productFamily->setReductionCatalog($reductionCatalog);
if ($this->productCategorySolver->isDisplay($parentCategory, $user)) { if ($this->productCategorySolver->isDisplay($parentCategory, $user)) {
if (!isset($productFamiliesToReturn[$parentCategory->getId()])) { if (!isset($productFamiliesToReturn[$parentCategory->getId()])) {
$productFamiliesToReturn[$parentCategory->getId()] = [ $productFamiliesToReturn[$parentCategory->getId()] = [
'category' => $parentCategory,
'products' => []
'category' => $parentCategory,
'products' => []
]; ];
} }
$productFamiliesToReturn[$parentCategory->getId()]['products'][] = $productFamily; $productFamiliesToReturn[$parentCategory->getId()]['products'][] = $productFamily;

+ 31
- 27
Repository/Reduction/ReductionCatalogRepositoryQuery.php View File



namespace Lc\CaracoleBundle\Repository\Reduction; namespace Lc\CaracoleBundle\Repository\Reduction;


use Doctrine\Common\Collections\ArrayCollection;
use Knp\Component\Pager\PaginatorInterface; use Knp\Component\Pager\PaginatorInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait; use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait;
$this->isJoinUsers = true; $this->isJoinUsers = true;


return $this return $this
->leftJoin('.users', 'pf_users')
->addSelect('pf_users') ;
->leftJoin('.users', 'pf_users')
->addSelect('pf_users');
} }
return $this; return $this;
} }
$this->isJoinGroupUsers = true; $this->isJoinGroupUsers = true;


return $this return $this
->leftJoin('.groupUsers', 'groupUsers')
->addSelect('groupUsers') ;
->leftJoin('.groupUsers', 'groupUsers')
->addSelect('groupUsers');
} }
return $this; return $this;
} }
$this->isJoinProductFamilies = true; $this->isJoinProductFamilies = true;


return $this return $this
->leftJoin('.productFamilies', 'productFamilies')
->addSelect('productFamilies') ;
->leftJoin('.productFamilies', 'productFamilies')
->addSelect('productFamilies');
} }
return $this; return $this;
} }
$this->isJoinProductFamily = true; $this->isJoinProductFamily = true;


return $this return $this
->leftJoin('.productFamily', 'productFamily')
->addSelect('productFamily') ;
->leftJoin('.productFamily', 'productFamily')
->addSelect('productFamily');
} }


return $this; return $this;
$this->isJoinProductCategories = true; $this->isJoinProductCategories = true;


return $this return $this
->leftJoin('.productCategories', 'productCategories')
->addSelect('productCategories') ;
->leftJoin('.productCategories', 'productCategories')
->addSelect('productCategories');
} }


return $this; return $this;
public function filterProductFamily(ProductFamilyInterface $productFamily) public function filterProductFamily(ProductFamilyInterface $productFamily)
{ {
return $this return $this
->andWhere('.productFamily = :productFamily')
->setParameter(':productFamily', $productFamily);
->andWhere('.productFamily = :productFamily')
->setParameter(':productFamily', $productFamily);
} }


public function filterConditionDate() public function filterConditionDate()
{ {
return $this return $this
->andWhere('.permanent = 1 OR ( .dateStart <= :now AND .dateEnd >= :now)')
->setParameter(':now', new \DateTime());
->andWhere('.permanent = 1 OR ( .dateStart <= :now AND .dateEnd >= :now)')
->setParameter(':now', new \DateTime());
} }


public function filterConditionUser(UserInterface $user = null) public function filterConditionUser(UserInterface $user = null)


if ($user) { if ($user) {
return $this return $this
->andWhere(':user MEMBER OF .users OR .users is empty')
->setParameter('user', $user);
->andWhere(':user MEMBER OF .users OR .users is empty')
->setParameter('user', $user);
} else { } else {
return $this return $this
->andWhere('.users is empty');
->andWhere('.users is empty');
} }
} }




if ($user) { if ($user) {
return $this return $this
->andWhere(':groupUser MEMBER OF .groupUsers OR .groupUsers is empty')
->setParameter('groupUser', $user->getGroupUsers());
->andWhere(':groupUser MEMBER OF .groupUsers OR .groupUsers is empty')
->setParameter('groupUser', $user->getGroupUsers());
} else { } else {
return $this return $this
->andWhere('.groupUsers is empty');
->andWhere('.groupUsers is empty');
} }
} }


public function filterConditionProductFamilies(array $productFamilies)
public function filterConditionProductFamilies(array $productFamiliesIds, array $productFamilies)
{ {
$this->joinProductFamilies(); $this->joinProductFamilies();
$this->joinProductFamily();


return $this return $this
->andWhere(':productFamilies MEMBER OF .productFamilies OR .productFamilies is empty')
->setParameter('productFamilies', $productFamilies);
->andWhere(':productFamiliesIds MEMBER OF .productFamilies OR .productFamilies is empty')
->andWhere('.productFamily IN (:productFamilies) OR .productFamily is null')
->setParameter('productFamiliesIds', $productFamiliesIds)
->setParameter('productFamilies', $productFamilies);
} }


public function filterConditionProductFamily(ProductFamilyInterface $productFamily) public function filterConditionProductFamily(ProductFamilyInterface $productFamily)
$this->joinProductFamily(); $this->joinProductFamily();


return $this return $this
->andWhere(':productFamily MEMBER OF .productFamily OR .productFamily is empty')
->setParameter('productFamily', $productFamily);
->andWhere(':productFamily MEMBER OF .productFamily OR .productFamily is empty')
->setParameter('productFamily', $productFamily);
} }


public function filterConditionProductCategories(array $productCategories) public function filterConditionProductCategories(array $productCategories)
$this->joinProductCategories(); $this->joinProductCategories();


return $this return $this
->andWhere(':productCategory MEMBER OF .productCategories OR .productCategories is empty')
->setParameter('productCategory', $productCategories);
->andWhere(':productCategory MEMBER OF .productCategories OR .productCategories is empty')
->setParameter('productCategory', $productCategories);
} }





+ 13
- 0
Solver/Price/ProductPriceSolver.php View File

use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface; use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductInterface; use Lc\CaracoleBundle\Model\Product\ProductInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface;
use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver; use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver;
use Lc\CaracoleBundle\Solver\Product\ProductSolver; use Lc\CaracoleBundle\Solver\Product\ProductSolver;


); );
} }


//Bridge pour applyReductionCatalog qui ne peut pas être appeler à cause du call
public function getPriceWithTaxByReduction(ProductPropertyInterface $product, ReductionCatalogInterface $reductionCatalog)
{
return $this->applyReductionCatalog(
$product,
$this->getPrice($product),
$this->getPriceWithTax($product),
1,
$reductionCatalog
);
}

public function getPriceByRefUnitWithTaxAndReduction(ProductPropertyInterface $product) public function getPriceByRefUnitWithTaxAndReduction(ProductPropertyInterface $product)
{ {
return ($this->getPriceByRefUnitWithTax($product) * $this->getPriceWithTaxAndReduction($product)) return ($this->getPriceByRefUnitWithTax($product) * $this->getPriceWithTaxAndReduction($product))

Loading…
Cancel
Save