Skip to content

armgit / Vvveb

Public Imported from GitHub
0

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

Products filters

givanzf589b8f4af67
diff --git a/admin/sql/mysqli/product.sql b/admin/sql/mysqli/product.sql
index 7e7aea9..ffecdf7 100755
--- a/admin/sql/mysqli/product.sql
+++ b/admin/sql/mysqli/product.sql
@@ -739,12 +739,13 @@
IN admin_id INT,
IN product_id ARRAY,
IN taxonomy_item_id INT,
- IN manufacturer_id INT,
- IN vendor_id INT,
+ IN manufacturer_id ARRAY,
+ IN vendor_id ARRAY,
IN related INT,
IN variant INT,
IN status INT,
IN search CHAR,
+ IN like CHAR,
IN slug ARRAY,
-- pagination
@@ -944,74 +945,80 @@
WHERE p2s.site_id = :site_id
- -- search
- @IF isset(:search) && !empty(:search)
+ -- search
+ @IF isset(:search) && !empty(:search)
THEN
-- AND pd.name LIKE CONCAT('%',:search,'%')
AND MATCH(pd.name, pd.content) AGAINST(:search)
- END @IF
+ END @IF
+
+ -- like
+ @IF isset(:like) && !empty(:like)
+ THEN
+ AND pd.name LIKE CONCAT('%',:like,'%')
+ END @IF
@IF isset(:type) && !empty(:type)
THEN
AND products.type = :type
- END @IF
+ END @IF
@IF isset(:manufacturer_id) && !empty(:manufacturer_id)
THEN
- AND products.manufacturer_id = :manufacturer_id
- END @IF
+ AND products.manufacturer_id IN (:manufacturer_id)
+ END @IF
@IF isset(:admin_id) && !empty(:admin_id)
THEN
AND products.admin_id = :admin_id
- END @IF
+ END @IF
@IF isset(:vendor_id) && !empty(:vendor_id)
THEN
- AND products.vendor_id = :vendor_id
- END @IF
+ AND products.vendor_id IN (:vendor_id)
+ END @IF
@IF isset(:price) && :price !== ""
THEN
AND products.price = :price
- END @IF
+ END @IF
@IF isset(:quantity) && :quantity !== ""
THEN
AND products.quantity = :quantity
- END @IF
+ END @IF
@IF isset(:model) && :model !== ""
THEN
AND products.model = :model
- END @IF
+ END @IF
@IF isset(:sku) && :sku !== ""
THEN
AND products.sku = :sku
- END @IF
+ END @IF
@IF isset(:upc) && :upc !== ""
THEN
AND products.upc = :upc
- END @IF
+ END @IF
@IF isset(:ean) && :ean !== ""
THEN
AND products.ean = :ean
- END @IF
+ END @IF
@IF isset(:isbn) && :isbn !== ""
THEN
AND products.isbn = :isbn
- END @IF
+ END @IF
@IF isset(:status) && :status !== ""
THEN
AND products.status = :status
- END @IF
+ END @IF
@IF isset(:product_id) && count(:product_id) > 0
diff --git a/admin/sql/pgsql/product.sql b/admin/sql/pgsql/product.sql
index ce0a741..2692202 100755
--- a/admin/sql/pgsql/product.sql
+++ b/admin/sql/pgsql/product.sql
@@ -738,12 +738,13 @@
IN admin_id INT,
IN product_id ARRAY,
IN taxonomy_item_id INT,
- IN manufacturer_id INT,
- IN vendor_id INT,
+ IN manufacturer_id ARRAY,
+ IN vendor_id ARRAY,
IN related INT,
IN variant INT,
IN status INT,
IN search CHAR,
+ IN like CHAR,
IN slug ARRAY,
-- pagination
@@ -946,75 +947,81 @@
WHERE p2s.site_id = :site_id
- -- search
- @IF isset(:search) && !empty(:search)
+ -- search
+ @IF isset(:search) && !empty(:search)
THEN
- -- AND pd.name LIKE CONCAT('%',:search,'%')
+ -- AND pd.name ILIKE '%' || :search || '%'
-- AND MATCH(pd.name, pd.content) AGAINST(:search)
AND to_tsvector(name) || to_tsvector(content) @@ plainto_tsquery(:search)
- END @IF
+ END @IF
+
+ -- like
+ @IF isset(:like) && !empty(:like)
+ THEN
+ AND pd.name ILIKE '%' || :like || '%'
+ END @IF
@IF isset(:type) && !empty(:type)
THEN
AND products.type = :type
- END @IF
+ END @IF
@IF isset(:manufacturer_id) && !empty(:manufacturer_id)
THEN
- AND products.manufacturer_id = :manufacturer_id
- END @IF
+ AND products.manufacturer_id IN (:manufacturer_id)
+ END @IF
@IF isset(:admin_id) && !empty(:admin_id)
THEN
AND products.admin_id = :admin_id
- END @IF
+ END @IF
@IF isset(:vendor_id) && !empty(:vendor_id)
THEN
- AND products.vendor_id = :vendor_id
- END @IF
+ AND products.vendor_id IN (:vendor_id)
+ END @IF
@IF isset(:price) && :price !== ""
THEN
AND products.price = :price
- END @IF
+ END @IF
@IF isset(:quantity) && :quantity !== ""
THEN
AND products.quantity = :quantity
- END @IF
+ END @IF
@IF isset(:model) && :model !== ""
THEN
AND products.model = :model
- END @IF
+ END @IF
@IF isset(:sku) && :sku !== ""
THEN
AND products.sku = :sku
- END @IF
+ END @IF
@IF isset(:upc) && :upc !== ""
THEN
AND products.upc = :upc
- END @IF
+ END @IF
@IF isset(:ean) && :ean !== ""
THEN
AND products.ean = :ean
- END @IF
+ END @IF
@IF isset(:isbn) && :isbn !== ""
THEN
AND products.isbn = :isbn
- END @IF
+ END @IF
@IF isset(:status) && :status !== ""
THEN
AND products.status = :status
- END @IF
+ END @IF
@IF isset(:product_id) && count(:product_id) > 0
diff --git a/admin/sql/sqlite/product.sql b/admin/sql/sqlite/product.sql
index 5e204ed..2849307 100755
--- a/admin/sql/sqlite/product.sql
+++ b/admin/sql/sqlite/product.sql
@@ -743,12 +743,13 @@
IN admin_id INT,
IN product_id ARRAY,
IN taxonomy_item_id INT,
- IN manufacturer_id INT,
- IN vendor_id INT,
+ IN manufacturer_id ARRAY,
+ IN vendor_id ARRAY,
IN related INT,
IN variant INT,
IN status INT,
IN search CHAR,
+ IN like CHAR,
IN slug ARRAY,
-- pagination
@@ -947,65 +948,71 @@
WHERE p2s.site_id = :site_id
- -- search
- @IF isset(:search) && !empty(:search)
+ -- search
+ @IF isset(:search) && !empty(:search)
THEN
- -- AND pd.name LIKE CONCAT('%',:search,'%')
+ -- AND pd.name LIKE '%' || :search || '%'
-- AND MATCH(pd.name, pd.content) AGAINST(:search)
-- AND (pcs.name MATCH :search OR pcs.content MATCH :search)
AND (product_content_search MATCH :search)
- END @IF
-
+ END @IF
+
+ -- like
+ @IF isset(:like) && !empty(:like)
+ THEN
+ AND pd.name LIKE '%' || :like || '%'
+ END @IF
+
@IF isset(:type) && !empty(:type)
THEN
AND products.type = :type
- END @IF
+ END @IF
@IF isset(:manufacturer_id) && !empty(:manufacturer_id)
THEN
- AND products.manufacturer_id = :manufacturer_id
- END @IF
+ AND products.manufacturer_id IN (:manufacturer_id)
+ END @IF
@IF isset(:admin_id) && !empty(:admin_id)
THEN
AND products.admin_id = :admin_id
- END @IF
+ END @IF
@IF isset(:vendor_id) && !empty(:vendor_id)
THEN
- AND products.vendor_id = :vendor_id
- END @IF
+ AND products.vendor_id IN (:vendor_id)
+ END @IF
@IF isset(:price) && :price !== ""
THEN
AND products.price = :price
- END @IF
+ END @IF
@IF isset(:quantity) && :quantity !== ""
THEN
AND products.quantity = :quantity
- END @IF
+ END @IF
@IF isset(:model) && :model !== ""
THEN
AND products.model = :model
- END @IF
+ END @IF
@IF isset(:sku) && :sku !== ""
THEN
AND products.sku = :sku
- END @IF
+ END @IF
@IF isset(:upc) && :upc !== ""
THEN
AND products.upc = :upc
- END @IF
+ END @IF
@IF isset(:ean) && :ean !== ""
THEN
AND products.ean = :ean
- END @IF
+ END @IF
@IF isset(:isbn) && :isbn !== ""
THEN
diff --git a/app/component/breadcrumb.php b/app/component/breadcrumb.php
index f043441..3762e0a 100755
--- a/app/component/breadcrumb.php
+++ b/app/component/breadcrumb.php
@@ -46,6 +46,7 @@ class Breadcrumb extends ComponentBase {
$slug = $request->get['slug'] ?? '';
$name = $request->get['name'] ?? '';
$homeText = __('Home');
+ $shopText = __('Shop');
$breadcrumb = [
['text' => $homeText, 'url' => '/'],
@@ -89,7 +90,7 @@ class Breadcrumb extends ComponentBase {
case 'product/index':
$breadcrumb = [
['text' => $homeText, 'url' => '/'],
- ['text' => 'shop', 'url' => false],
+ ['text' => $shopText, 'url' => false],
];
break;
@@ -97,6 +98,7 @@ class Breadcrumb extends ComponentBase {
case 'product/manufacturer/index':
$breadcrumb = [
['text' => $homeText, 'url' => '/'],
+ ['text' => $shopText, 'url' => url('product/index')],
['text' => $slug, 'url' => false],
];
@@ -105,6 +107,7 @@ class Breadcrumb extends ComponentBase {
case 'product/vendor/index':
$breadcrumb = [
['text' => $homeText, 'url' => '/'],
+ ['text' => $shopText, 'url' => url('product/index')],
['text' => $slug, 'url' => false],
];
diff --git a/app/component/product/manufacturers.php b/app/component/product/manufacturers.php
index cf91202..dbe9d7c 100755
--- a/app/component/product/manufacturers.php
+++ b/app/component/product/manufacturers.php
@@ -40,13 +40,22 @@ class Manufacturers extends ComponentBase {
'parents_only' => false,
'parents_children_only' => false,
'parents_without_children' => false,
+ 'filter' => null,
];
function results() {
$category = new \Vvveb\Sql\ManufacturerSQL();
$results = $category->getAll($this->options);
+
+ $filter = [];
+ if ($this->options['filter']) {
+ $filter = $this->options['filter']['manufacturer_id'] ?? [];
+ }
foreach ($results['manufacturer'] as &$manufacturer) {
+ if ($filter) {
+ $manufacturer['active'] = in_array($manufacturer['manufacturer_id'], $filter);
+ }
$manufacturer['url'] = url('product/manufacturer/index', $manufacturer);
}
diff --git a/app/component/product/vendors.php b/app/component/product/vendors.php
index 08be212..dfc26f2 100644
--- a/app/component/product/vendors.php
+++ b/app/component/product/vendors.php
@@ -40,13 +40,22 @@ class Vendors extends ComponentBase {
'parents_only' => false,
'parents_children_only' => false,
'parents_without_children' => false,
+ 'filter' => false,
];
function results() {
$category = new \Vvveb\Sql\VendorSQL();
$results = $category->getAll($this->options);
+ $filter = [];
+ if ($this->options['filter']) {
+ $filter = $this->options['filter']['vendor_id'] ?? [];
+ }
+
foreach ($results['vendor'] as &$vendor) {
+ if ($filter) {
+ $vendor['active'] = in_array($vendor['vendor_id'], $filter);
+ }
$vendor['url'] = url('product/vendor/index', $vendor);
}
diff --git a/app/component/products.php b/app/component/products.php
index bfcbb98..46af317 100755
--- a/app/component/products.php
+++ b/app/component/products.php
@@ -52,6 +52,7 @@ class Products extends ComponentBase {
'related' => null,
'variant' => null,
'image_size' => 'medium',
+ 'filter' => null,
];
public $options = [];
@@ -62,8 +63,13 @@ class Products extends ComponentBase {
if ($page = $this->options['page']) {
$this->options['start'] = ($page - 1) * $this->options['limit'];
}
-
- if ($this->options['related']) {
+
+ if ($this->options['filter']) {
+ foreach ($this->options['filter'] as $name => $values) {
+ if ($name == 'manufacturer_id' || $name == 'vendor_id') {
+ $this->options[$name] = $values;
+ }
+ }
}
if (isset($this->options['product_id']) &&
@@ -91,6 +97,16 @@ class Products extends ComponentBase {
$this->options['slug'] = [$this->options['slug']];
}
+ //if only one manufacturer_id is provided then add it to array
+ if (isset($this->options['manufacturer_id']) && ! is_array($this->options['manufacturer_id'])) {
+ $this->options['manufacturer_id'] = [$this->options['manufacturer_id']];
+ }
+
+ //if only one vendor_id is provided then add it to array
+ if (isset($this->options['vendor_id']) && ! is_array($this->options['vendor_id'])) {
+ $this->options['vendor_id'] = [$this->options['vendor_id']];
+ }
+
$results = $products->getAll($this->options) + $this->options;
if ($results && isset($results['products'])) {
@@ -120,8 +136,8 @@ class Products extends ComponentBase {
//rfc
$product['pubDate'] = date('r', strtotime($product['created_at']));
- $url = ['slug' => $product['slug'], 'product_id' => $product['product_id']] + $language;
- $product['url'] = url('product/product/index', $url);
+ $url = ['slug' => $product['slug'], 'product_id' => $product['product_id']] + $language;
+ $product['url'] = url('product/product/index', $url);
$product['add_cart_url'] = url('cart/cart/add', ['product_id' => $product['product_id']]);
$product['buy_url'] = url('checkout/checkout/index', ['product_id' => $product['product_id']]);
$product['add_wishlist_url'] = url('user/wishlist/add', ['product_id' => $product['product_id']]);
diff --git a/app/template/components/product/manufacturers.tpl b/app/template/components/product/manufacturers.tpl
index cecb130..c06af8a 100755
--- a/app/template/components/product/manufacturers.tpl
+++ b/app/template/components/product/manufacturers.tpl
@@ -32,6 +32,11 @@ if($manufacturers && is_array($manufacturers['manufacturer'])) {
@manufacturer [data-v-manufacturer-*]|innerText = $manufacturer['@@__data-v-manufacturer-(*)__@@']
@manufacturer a[data-v-manufacturer-*]|href = $manufacturer['@@__data-v-manufacturer-(*)__@@']
+ @manufacturer input[data-v-manufacturer-manufacturer_id]|addNewAttribute = <?php
+ if (isset($manufacturer['active']) && $manufacturer['active']) {
+ echo 'checked';
+ }
+ ?>
@manufacturer|after = <?php
}
diff --git a/app/template/components/product/options.tpl b/app/template/components/product/options.tpl
index cd425a7..8da30f4 100755
--- a/app/template/components/product/options.tpl
+++ b/app/template/components/product/options.tpl
@@ -55,7 +55,7 @@ if($options && is_array($options)) {
@option [data-v-option-*]|innerText = $option['@@__data-v-option-(*)__@@']
@option [data-v-option-input]|value = $option['value']
- @option [data-v-option-input]|name = <?php echo 'option[' . $option['option_id'] . ']';?>
+ @option [data-v-option-input]|name = <?php echo 'option[' . $option['product_option_id'] . ']';?>
@option a[data-v-option-*]|href = $option['@@__data-v-option-(*)__@@']
@@ -68,7 +68,7 @@ if($options && is_array($options)) {
@value [data-v-value-*]|innerText = $value['@@__data-v-value-(*)__@@']
- @value [data-v-value-input]|name = <?php echo 'option[' . $option['option_id'] . ']';?>
+ @value [data-v-value-input]|name = <?php echo 'option[' . $option['product_option_id'] . ']';?>
@value [data-v-value-input]|addNewAttribute = <?php if ($option['required']) echo 'required';?>
@value [data-v-value-input]|value = $value['product_option_value_id']
diff --git a/app/template/components/product/vendors.tpl b/app/template/components/product/vendors.tpl
index 2280de7..2ed1899 100644
--- a/app/template/components/product/vendors.tpl
+++ b/app/template/components/product/vendors.tpl
@@ -32,6 +32,12 @@ if($vendors && is_array($vendors['vendor'])) {
@vendor [data-v-vendor-*]|innerText = $vendor['@@__data-v-vendor-(*)__@@']
@vendor a[data-v-vendor-*]|href = $vendor['@@__data-v-vendor-(*)__@@']
+
+ @vendor input[data-v-vendor-vendor_id]|addNewAttribute = <?php
+ if (isset($vendor['active']) && $vendor['active']) {
+ echo 'checked';
+ }
+ ?>
@vendor|after = <?php
}
diff --git a/app/template/components/products.tpl b/app/template/components/products.tpl
index ba28b6e..897537a 100755
--- a/app/template/components/products.tpl
+++ b/app/template/components/products.tpl
@@ -15,6 +15,7 @@
$previous_component = isset($current_component)?$current_component:null;
$products = $current_component = $this->_component['products'][$products_idx] ?? [];
+ $index = 0;
$count = $products['count'] ?? 0;
$limit = isset($products['limit'])? $products['limit'] : 5;
@@ -33,7 +34,7 @@
@product|before = <?php
if ($_products) {
- foreach ($_products as $index => $_product) { ?>
+ foreach ($_products as $index => $_product) { $index++;?>
@product [data-v-product-*]|innerText = $_product['@@__data-v-product-(*)__@@']
@product a[data-v-product-*]|href = $_product['@@__data-v-product-(*)__@@']
diff --git a/app/template/pagination.tpl b/app/template/pagination.tpl
index 7803271..183d905 100755
--- a/app/template/pagination.tpl
+++ b/app/template/pagination.tpl
@@ -5,8 +5,14 @@
$parent_component = '@@__data-v-parent-component__@@';
$parent_index = '@@__data-v-parent-index__@@';
+$query_string = '@@__data-v-query-string__@@';
$parameters = [];//@@__data-v-parameters__@@;
+if ($query_string) {
+ $query_string = ($_SERVER['QUERY_STRING'] ?? '');
+ $query_string = $query_string ? "?$query_string" : '';
+}
+
if ($parent_component) {
$component = $this->_component[$parent_component][$parent_index];
}
@@ -68,7 +74,7 @@ if ($pagecount > $maxpages)
[data-pagination] [data-pages] = $pagecount
@page [data-page-no] = $page
- @page [data-page-url]|href = <?php echo htmlentities(Vvveb\url($url, ['page' => $page] + $parameters));?>
+ @page [data-page-url]|href = <?php echo htmlentities(Vvveb\url($url, ['page' => $page] + $parameters)) . $query_string;?>
@page|addClass = <?php if ($current_page == $page) echo 'active'?>
@page|after = <?php
@@ -77,12 +83,12 @@ if ($pagecount > $maxpages)
[data-pagination] [data-count] = $component['count']
[data-pagination] [data-current-page] = $current_page
- [data-pagination] [data-current-url]|action = <?php echo htmlentities(Vvveb\url($url, ['page' => $current_page] + $parameters));?>
+ [data-pagination] [data-current-url]|action = <?php echo htmlentities(Vvveb\url($url, ['page' => $current_page] + $parameters)) . $query_string;?>
- [data-pagination] [data-first] [data-page-url]|href = <?php echo htmlentities(Vvveb\url($url, ['page' => 1] + $parameters));?>
- [data-pagination] [data-prev] [data-page-url]|href = <?php echo htmlentities(Vvveb\url($url, ['page' => max($current_page - 1, 1)] + $parameters));?>
- [data-pagination] [data-next] [data-page-url]|href = <?php echo htmlentities(Vvveb\url($url, ['page' => min($current_page + 1, $pagecount)] + $parameters));?>
- [data-pagination] [data-last] [data-page-url]|href = <?php echo htmlentities(Vvveb\url($url, ['page' => $pagecount] + $parameters));?>
+ [data-pagination] [data-first] [data-page-url]|href = <?php echo htmlentities(Vvveb\url($url, ['page' => 1] + $parameters)) . $query_string;?>
+ [data-pagination] [data-prev] [data-page-url]|href = <?php echo htmlentities(Vvveb\url($url, ['page' => max($current_page - 1, 1)] + $parameters)) . $query_string;?>
+ [data-pagination] [data-next] [data-page-url]|href = <?php echo htmlentities(Vvveb\url($url, ['page' => min($current_page + 1, $pagecount)] + $parameters)) . $query_string;?>
+ [data-pagination] [data-last] [data-page-url]|href = <?php echo htmlentities(Vvveb\url($url, ['page' => $pagecount] + $parameters)) . $query_string;?>
[data-pagination]|after = <?php
diff --git a/public/js/filter.js b/public/js/filter.js
new file mode 100644
index 0000000..4b4b56e
--- /dev/null
+++ b/public/js/filter.js
@@ -0,0 +1,52 @@
+/**
+ * Vvveb
+ *
+ * Copyright (C) 2021 Ziadin Givan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+function filterChange() {
+ let filters = {};
+ let filter_text = '';
+ let action = window.location.href;
+ let params = action.match(/\/\d+|\?/)
+ if (params) {
+ action = action.slice(0, params.index);
+ }
+
+ document.querySelectorAll('.filters input:checked').forEach(element => {
+ let name = element.name.replace('[]','');
+ if (typeof filters[name] == 'undefined') filters[name] = [];
+ filters[name].push(element.value);
+ });
+
+ for(filter_name in filters) {
+ for (filter in filters[filter_name]) {
+ filter_text += (filter_text ? '&' : '?') + "filter[" + filter_name + "][]=" + filters[filter_name][filter];
+ }
+ }
+
+ location = action + filter_text;
+}
+
+let _filter_timeout;
+
+document.querySelectorAll('.filters input').forEach(e => e.addEventListener("click", function() {
+ clearTimeout(_filter_timeout);
+ _filter_timeout = setTimeout(function () {
+ filterChange();
+ }, 1500);
+}));
\ No newline at end of file
diff --git a/public/themes/landing b/public/themes/landing
index 86e57c0..40ba1e3 160000
--- a/public/themes/landing
+++ b/public/themes/landing
@@ -1 +1 @@
-Subproject commit 86e57c06eb6732dd0feb7cf590e87b6140ea4804
+Subproject commit 40ba1e3d8933cccef65ada0b1b0bbfe754afd48f