Skip to content

armgit / Vvveb

Public Imported from GitHub
0

Powerful and easy to use cms to build websites, blogs or ecommerce stores.

Don't cache component if search parameter is provided

givanz5bdd7de22834
diff --git a/app/component/posts.php b/app/component/posts.php
index 5e87cdb..fbb261b 100755
--- a/app/component/posts.php
+++ b/app/component/posts.php
@@ -75,11 +75,11 @@ class Posts extends ComponentBase {
break;
case 'content/category':
- if ($this->options['taxonomy_item_id'] == 'page') {
- $this->options['taxonomy_item_id'] = 54;
+ if (isset($this->options['taxonomy_item_id']) && $this->options['taxonomy_item_id'] == 'page') {
+ $this->options['taxonomy_item_id'] = get('taxonomy_item_id');
}
- if ($this->options['taxonomy_item_slug'] == 'page') {
+ if (isset($this->options['taxonomy_item_slug']) && $this->options['taxonomy_item_slug'] == 'page') {
$this->options['taxonomy_item_slug'] = get('slug');
}
@@ -87,14 +87,22 @@ class Posts extends ComponentBase {
}
}
+ function cacheKey() {
+ if (isset($this->options['search'])) {
+ return false;
+ }
+
+ return parent::cacheKey();
+ }
+
function results() {
$posts = new PostSQL();
- if (! $this->options['page'] && ! $this->options['start']) {
+ if (! isset($this->options['page']) && ! isset($this->options['start'])) {
$this->options['page'] = 1;
}
- if ($page = $this->options['page']) {
+ if ($page = ($this->options['page'] ?? false)) {
$this->options['start'] = ($page - 1) * ((int) ($this->options['limit'] ?? 4));
}
/*
@@ -118,7 +126,7 @@ class Posts extends ComponentBase {
unset($this->options['direction']);
}
- if ($this->options['search'] && $this->options['search_boolean']) {
+ if (isset($this->options['search']) && isset($this->options['search_boolean'])) {
$this->options['search'] .= '*';
}
@@ -146,7 +154,7 @@ class Posts extends ComponentBase {
$results['limit'] = $this->options['limit'];
$results['start'] = $this->options['start'];
- $results['search'] = $this->options['search'];
+ $results['search'] = $this->options['search'] ?? '';
list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);
diff --git a/app/component/products.php b/app/component/products.php
index 41eb6e1..03495aa 100755
--- a/app/component/products.php
+++ b/app/component/products.php
@@ -74,14 +74,22 @@ class Products extends ComponentBase {
public $options = [];
+ function cacheKey() {
+ if (isset($this->options['search'])) {
+ return false;
+ }
+
+ return parent::cacheKey();
+ }
+
function results() {
$products = new \Vvveb\Sql\ProductSQL();
- if (($page = $this->options['page']) && is_numeric($page)) {
+ if (($page = $this->options['page'] ?? false) && is_numeric($page)) {
$this->options['start'] = ($page - 1) * ((int) ($this->options['limit'] ?? 4));
}
- if ($this->options['filter']) {
+ if ($this->options['filter'] ?? false) {
foreach ($this->options['filter'] as $name => $values) {
if ($name == 'manufacturer_id' || $name == 'vendor_id') {
$this->options[$name] = $values;
@@ -90,7 +98,7 @@ class Products extends ComponentBase {
}
if (isset($this->options['product_id']) &&
- ($this->options['related'] || $this->options['variant'] || $this->options['source'] == 'autocomplete')) {
+ (isset($this->options['related']) || isset($this->options['variant']) || ($this->options['source'] ?? '' == 'autocomplete'))) {
if (! is_array($this->options['product_id'])) {
$this->options['product_id'] = [$this->options['product_id'] => 1];
}
@@ -129,7 +137,7 @@ class Products extends ComponentBase {
$this->options['taxonomy_item_id'] = [$this->options['taxonomy_item_id']];
}
- if ($this->options['search'] && $this->options['search_boolean']) {
+ if (isset($this->options['search']) && isset($this->options['search_boolean'])) {
$this->options['search'] .= '*';
}
@@ -143,7 +151,7 @@ class Products extends ComponentBase {
$results['limit'] = $this->options['limit'];
$results['start'] = $this->options['start'];
- $results['search'] = $this->options['search'];
+ $results['search'] = $this->options['search'] ?? '';
list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);