Skip to content

Commit

Permalink
PATH: fix product filter
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnysideup committed Nov 17, 2016
1 parent 0b71cad commit 85d011e
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions code/ProductGroup.php
Expand Up @@ -787,7 +787,13 @@ public function currentInitialProducts($extraFilter = null, $alternativeFilterKe
$this->allProducts = $this->getGroupFilter();

// STANDARD FILTER (INCLUDES USER PREFERENCE)
$this->allProducts = $this->allProducts->filter($this->allowPurchaseWhereStatement());
$filterStatement = $this->allowPurchaseWhereStatement();
if($filterStatement) {
if(is_array($filterStatement)) {
$this->allProducts = $this->allProducts->filter($filterStatement);
} elseif(is_string($filterStatement)) {
$this->allProducts = $this->allProducts->where($filterStatement);
}
$this->allProducts = $this->getStandardFilter($alternativeFilterKey);

// EXTRA FILTER (ON THE FLY FROM CONTROLLER)
Expand All @@ -802,7 +808,7 @@ public function currentInitialProducts($extraFilter = null, $alternativeFilterKe

return $this->allProducts;
}

/**
* this method can be used quickly current initial products
* whenever you write:
Expand Down Expand Up @@ -868,7 +874,7 @@ protected function getGroupFilter()
{
$levelToShow = $this->MyLevelOfProductsToShow();
$cacheKey = $this->cacheKey(
'GroupFilter',
'GroupFilter',
abs(intval($levelToShow + 999))
);
if ($groupFilter = $this->retrieveObjectStore($cacheKey)) {
Expand Down Expand Up @@ -1511,7 +1517,7 @@ public function onAfterWrite()
* CACHING
*****************************************************/
/**
*
*
* @return bool
*/
public function AllowCaching()
Expand All @@ -1524,15 +1530,15 @@ public function AllowCaching()
* @var string
*/
private static $_product_group_cache_key_cache = null;

/**
*
*
* @param string $name
* @param string $filterKey
*
*
* @return string
*/
public function cacheKey($name, $filterKey = '')
public function cacheKey($name, $filterKey = '')
{
$cacheKey = 'ProductGroup_'.$name.'_'.$this->ID;
if($filterKey){
Expand All @@ -1544,19 +1550,19 @@ public function cacheKey($name, $filterKey = '')
.Product::get()->count();
self::$_product_group_cache_key_cache .= "PG_"
.strtotime(ProductGroup::get()->max('LastEdited')). "_"
.ProductGroup::get()->count();
.ProductGroup::get()->count();
if(class_exists('ProductVariation')) {
self::$_product_group_cache_key_cache .= "PV_"
.strtotime(ProductVariation::get()->max('LastEdited')). "_"
.ProductVariation::get()->count();
.ProductVariation::get()->count();

}
}
$cacheKey .= self::$_product_group_cache_key_cache;

return $cacheKey;
}

/**
* saving an object to the.
*
Expand Down Expand Up @@ -2334,7 +2340,7 @@ public function MaxNumberOfProductsPerPage()
public function FilterLinks()
{
$cacheKey = $this->cacheKey(
'FilterLinks',
'FilterLinks',
$this->filterForGroupObject ? $this->filterForGroupObject->ID : null
);
if ($list = $this->retrieveObjectStore($cacheKey)) {
Expand Down

0 comments on commit 85d011e

Please sign in to comment.