Fabien Normand пре 2 година
родитељ
комит
f7894687a0
2 измењених фајлова са 68 додато и 87 уклоњено
  1. +0
    -19
      Model/User/UserModel.php
  2. +68
    -68
      Repository/Product/ProductFamilyStore.php

+ 0
- 19
Model/User/UserModel.php Прегледај датотеку

@@ -29,17 +29,11 @@ abstract class UserModel extends SovUserModel
*/
protected $isSaleAlwaysOpen;


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

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

/**
* @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Address\AddressInterface", mappedBy="user", cascade={"persist"})
*/
@@ -124,19 +118,6 @@ abstract class UserModel extends SovUserModel
return $this;
}

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

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

return $this;
}


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

+ 68
- 68
Repository/Product/ProductFamilyStore.php Прегледај датотеку

@@ -51,48 +51,51 @@ class ProductFamilyStore extends AbstractStore
}

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

foreach ($parentCategory->getChildrens() as $i => $category) {
$productFamiliesCategory = $this->getByCategory($category, $query);
$productFamiliesCategory = $this->getByCategory($category);
foreach ($productFamiliesCategory as $productFamily) {
$productFamiliesArray[$productFamily->getId()] = $productFamily;
}
uasort($productFamiliesArray, array($this, 'compMethodSortProductFamiliesByPosition'));
}

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

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

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

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

return $query->find();
}

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

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

return $query->find();
}
@@ -103,8 +106,8 @@ class ProductFamilyStore extends AbstractStore
$query = $this->createDefaultQuery($query);

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

$results = $query->find();

@@ -117,8 +120,8 @@ class ProductFamilyStore extends AbstractStore
$query = $this->createDefaultQuery($query);

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

$results = $query->find();

@@ -136,10 +139,10 @@ class ProductFamilyStore extends AbstractStore
{
if ($user) {
return $this->getWithReductions(
$user->getFavoriteProductFamilies(),
$user,
false,
$organizeByParentCategory
$user->getFavoriteProductFamilies(),
$user,
false,
$organizeByParentCategory
);
}

@@ -149,13 +152,12 @@ class ProductFamilyStore extends AbstractStore

// findByTerms
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->filterIsOnline();
@@ -173,18 +175,17 @@ class ProductFamilyStore extends AbstractStore
}

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


@@ -197,32 +198,31 @@ class ProductFamilyStore extends AbstractStore

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

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

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

@@ -232,19 +232,20 @@ class ProductFamilyStore extends AbstractStore
$conditionProductFamilies = $conditionProductFamily = $conditionProductCategory = false;

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

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

foreach ($productFamily->getProductCategories() as $productCategory) {
if ($reductionCatalog->getProductCategories()->contains(
$productCategory
) || $reductionCatalog->getProductCategories()->isEmpty()) {
$productCategory
) || $reductionCatalog->getProductCategories()->isEmpty()) {
$conditionProductCategory = true;
}
}
@@ -252,11 +253,11 @@ class ProductFamilyStore extends AbstractStore
if ($conditionProductFamilies && $conditionProductFamily && $conditionProductCategory) {
if ($productFamily->getReductionCatalog()) {
$productFamily->setReductionCatalog(
$this->getBestReductionCatalog(
$productFamily,
$reductionCatalog,
$productFamily->getReductionCatalog()
)
$this->getBestReductionCatalog(
$productFamily,
$reductionCatalog,
$productFamily->getReductionCatalog()
)
);
} else {
$productFamily->setReductionCatalog($reductionCatalog);
@@ -266,7 +267,6 @@ class ProductFamilyStore extends AbstractStore

if (($onlyOnDiscount && $productFamily->getReductionCatalog()) || !$onlyOnDiscount) {
if ($organizeByParentCategory) {

$productCategories = $productFamily->getProductCategories();

if ($productCategories && count($productCategories) > 0) {
@@ -274,8 +274,8 @@ class ProductFamilyStore extends AbstractStore
if ($this->productCategorySolver->isDisplay($parentCategory, $user)) {
if (!isset($productFamiliesToReturn[$parentCategory->getId()])) {
$productFamiliesToReturn[$parentCategory->getId()] = [
'category' => $parentCategory,
'products' => []
'category' => $parentCategory,
'products' => []
];
}
$productFamiliesToReturn[$parentCategory->getId()]['products'][] = $productFamily;

Loading…
Откажи
Сачувај