Skip to content

Commit

Permalink
Products filters
Browse files Browse the repository at this point in the history
  • Loading branch information
givanz committed Mar 31, 2024
1 parent f4bfaf4 commit f589b8f
Show file tree
Hide file tree
Showing 14 changed files with 201 additions and 73 deletions.
45 changes: 26 additions & 19 deletions admin/sql/mysqli/product.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
47 changes: 27 additions & 20 deletions admin/sql/pgsql/product.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
45 changes: 26 additions & 19 deletions admin/sql/sqlite/product.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion app/component/breadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function results() {
$slug = $request->get['slug'] ?? '';
$name = $request->get['name'] ?? '';
$homeText = __('Home');
$shopText = __('Shop');

$breadcrumb = [
['text' => $homeText, 'url' => '/'],
Expand Down Expand Up @@ -89,14 +90,15 @@ function results() {
case 'product/index':
$breadcrumb = [
['text' => $homeText, 'url' => '/'],
['text' => 'shop', 'url' => false],
['text' => $shopText, 'url' => false],
];

break;
//manufacturer page
case 'product/manufacturer/index':
$breadcrumb = [
['text' => $homeText, 'url' => '/'],
['text' => $shopText, 'url' => url('product/index')],
['text' => $slug, 'url' => false],
];

Expand All @@ -105,6 +107,7 @@ function results() {
case 'product/vendor/index':
$breadcrumb = [
['text' => $homeText, 'url' => '/'],
['text' => $shopText, 'url' => url('product/index')],
['text' => $slug, 'url' => false],
];

Expand Down
9 changes: 9 additions & 0 deletions app/component/product/manufacturers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Loading

0 comments on commit f589b8f

Please sign in to comment.