Browse Source

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

packProduct
Fabien Normand 2 years ago
parent
commit
f7894687a0
2 changed files with 68 additions and 87 deletions
  1. +0
    -19
      Model/User/UserModel.php
  2. +68
    -68
      Repository/Product/ProductFamilyStore.php

+ 0
- 19
Model/User/UserModel.php View File

*/ */
protected $isSaleAlwaysOpen; protected $isSaleAlwaysOpen;



/** /**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface") * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface")
*/ */
protected $favoriteMerchant; protected $favoriteMerchant;


/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected $lastLogin;

/** /**
* @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Address\AddressInterface", mappedBy="user", cascade={"persist"}) * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Address\AddressInterface", mappedBy="user", cascade={"persist"})
*/ */
return $this; return $this;
} }


public function getLastLogin()
{
return $this->lastLogin;
}

public function setLastLogin(\DateTime $time = null)
{
$this->lastLogin = $time;

return $this;
}


/** /**
* @return Collection|AddressInterface[] * @return Collection|AddressInterface[]
*/ */

+ 68
- 68
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) {
$productFamiliesCategory = $this->getByCategory($category, $query);
$productFamiliesCategory = $this->getByCategory($category);
foreach ($productFamiliesCategory as $productFamily) { foreach ($productFamiliesCategory as $productFamily) {
$productFamiliesArray[$productFamily->getId()] = $productFamily; $productFamiliesArray[$productFamily->getId()] = $productFamily;
} }
uasort($productFamiliesArray, array($this, 'compMethodSortProductFamiliesByPosition'));
} }


return $this->getWithReductions($productFamiliesArray, $user, true); return $this->getWithReductions($productFamiliesArray, $user, true);
} }


private function compMethodSortProductFamiliesByPosition($a, $b)
{
return $a->getPosition() > $b->getPosition();
}

// 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();
} }


//TODO ajouter status en donné de contexte pour éviter ce truc //TODO ajouter status en donné de contexte pour éviter ce truc
public function getByCategoryOnlineAndOffline( public function getByCategoryOnlineAndOffline(
ProductCategoryInterface $productCategory,
$query = null
)
{
ProductCategoryInterface $productCategory,
$query = null
) {
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);


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


return $query->find(); return $query->find();
} }
$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
)
{
ProductFamilyInterface $productFamily,
ReductionCatalogInterface $reductionCatalog1,
ReductionCatalogInterface $reductionCatalog2
) {
$price1 = $this->priceSolver->getPriceWithTaxByReduction( $price1 = $this->priceSolver->getPriceWithTaxByReduction(
$productFamily,
$reductionCatalog1
$productFamily,
$reductionCatalog1
); );
$price2 = $this->priceSolver->getPriceWithTaxByReduction( $price2 = $this->priceSolver->getPriceWithTaxByReduction(
$productFamily,
$reductionCatalog2
$productFamily,
$reductionCatalog2
); );






// 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 = [
'productFamiliesIds' => [],
'categories' => [],
'productFamilies' => [],
'productFamiliesIds' => [],
'categories' => [],
'productFamilies' => [],
]; ];


foreach ($productFamilies as $productFamily) { foreach ($productFamilies as $productFamily) {
$conditions['productFamiliesIds'][] = $productFamily->getId(); $conditions['productFamiliesIds'][] = $productFamily->getId();
$conditions['productFamilies'][] = $productFamily; $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 (($onlyOnDiscount && $productFamily->getReductionCatalog()) || !$onlyOnDiscount) { if (($onlyOnDiscount && $productFamily->getReductionCatalog()) || !$onlyOnDiscount) {
if ($organizeByParentCategory) { if ($organizeByParentCategory) {

$productCategories = $productFamily->getProductCategories(); $productCategories = $productFamily->getProductCategories();


if ($productCategories && count($productCategories) > 0) { if ($productCategories && count($productCategories) > 0) {
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;

Loading…
Cancel
Save