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