diff --git a/pipit_catalog/admin.php b/pipit_catalog/admin.php index c672302..e88cee0 100644 --- a/pipit_catalog/admin.php +++ b/pipit_catalog/admin.php @@ -1,6 +1,6 @@ logged_in() && $CurrentUser->has_priv('pipit_catalog')) { - $this->register_app('pipit_catalog', 'Catalog', 5, 'Catalog App', '1.0.0'); + $this->register_app('pipit_catalog', 'Catalog', 5, 'Catalog App', '1.1.0'); $this->require_version('pipit_catalog', '3.0'); $this->add_setting('pipit_catalog_productsSet', 'Products Category Set', 'PerchCategories_Sets::get_settings_select_list', false); diff --git a/pipit_catalog/index.php b/pipit_catalog/index.php index c4c1898..41e34bf 100644 --- a/pipit_catalog/index.php +++ b/pipit_catalog/index.php @@ -8,7 +8,7 @@ $Paging = $API->get('Paging'); # Set the page title - $Perch->page_title = $Lang->get('Catalog app'); + $Perch->page_title = $Lang->get('Manage Products'); include('modes/_subnav.php'); diff --git a/pipit_catalog/lang/en-gb.txt b/pipit_catalog/lang/en-gb.txt index 4dc6f4a..6406ecb 100644 --- a/pipit_catalog/lang/en-gb.txt +++ b/pipit_catalog/lang/en-gb.txt @@ -4,29 +4,22 @@ "Catalog app": "Catalog app", "Add a Product": "Add a Product", "Products": "Products", - "All": "All", - "Inactive": "Inactive", - "Active": "Active", - "On Sale": "On Sale", - "Requires Shipping": "Requires Shipping", - "No Shipping": "No Shipping", - "By Category": "By Category", - "By Brand": "By Brand", + "Clear filters": "Clear filters", "Search": "Search", + "Categories": "Categories", + "Brands": "Brands", + "Status": "Status", + "On Sale": "On Sale", + "Shipping": "Shipping", "Are you sure?": "Are you sure?", "Image": "Image", "SKU": "SKU", "Title": "Title", "Stock": "Stock", "Price": "Price", + "Active": "Active", "": "", "Delete": "Delete", - "Products Category Set": "Products Category Set", - "Thumb width": "Thumb width", - "Thumb height": "Thumb height", - "Thumb density": "Thumb density", - "Thumb crop": "Thumb crop", - "Hide product images": "Hide product images", "Pagination": "Pagination", "First page": "First page", "First": "First", @@ -39,26 +32,21 @@ "Next": "Next", "Last page": "Last page", "Last": "Last", - "Save": "Save", - "or": "or", - "Cancel": "Cancel", - "Categories": "Categories", - "Brands": "Brands", - "Status": "Status", - "Shipping": "Shipping", - "Filter": "Filter", - "Clear filters": "Clear filters", - "Sale": "Sale", + "Products Category Set": "Products Category Set", + "Highlight low stock when stock": "Highlight low stock when stock", "Hide Category filter": "Hide Category filter", "Hide Brand filter": "Hide Brand filter", "Hide Status filter": "Hide Status filter", "Hide On Sale filter": "Hide On Sale filter", "Hide Shipping filter": "Hide Shipping filter", + "Hide Search Field": "Hide Search Field", + "Hide product images": "Hide product images", "Display sale prices": "Display sale prices", + "Thumb width": "Thumb width", + "Thumb height": "Thumb height", + "Thumb density": "Thumb density", + "Thumb crop": "Thumb crop", + "No matching products found.": "No matching products found.", "Sorted ascending": "Sorted ascending", - "Sorted descending": "Sorted descending", - "Hide Search Field": "Hide Search Field", - "Highlight low stock when stock": "Highlight low stock when stock", - "Add the Products Set in the %ssettings%s to enable Category filtering": "Add the Products Set in the %ssettings%s to enable Category filtering" - "No matching products found.": "No matching products found." + "Sorted descending": "Sorted descending" } \ No newline at end of file diff --git a/pipit_catalog/modes/list.post.php b/pipit_catalog/modes/list.post.php index 5e95f55..ae31c1e 100644 --- a/pipit_catalog/modes/list.post.php +++ b/pipit_catalog/modes/list.post.php @@ -1,7 +1,7 @@ title_panel([ - 'heading' => $Lang->get('Catalog'), + 'heading' => $Lang->get('Product Catalog'), 'button' => [ 'text' => $Lang->get('Add a Product'), 'link' => $productsURL.'/product/edit/', @@ -12,8 +12,6 @@ if (isset($message)) echo $message; - - $persist_args = ''; $ParentSmartbar = new PerchSmartbar($CurrentUser, $HTML, $Lang); @@ -39,7 +37,6 @@ 'arg' => 'q', 'icon' => 'core/search', 'position' => 'end', - //'persist' => ['category', 'brand', 'status', 'sale', 'shipping'], ]); } @@ -54,7 +51,7 @@ - /* Filters */ + # Filters // form->start() echo '
'; @@ -157,7 +154,7 @@ - if($products) + if($products_for_paging) { $Listing = new PerchAdminListing($CurrentUser, $HTML, $Lang, $Paging); @@ -204,7 +201,7 @@ global $API; $noImg = ''; - if($dynamic_fields['image']) + if(isset($dynamic_fields['image'])) { $image = $dynamic_fields['image']; @@ -260,13 +257,20 @@ $Listing->add_col([ 'title' => 'Stock', + 'sort' => 'stock_level', 'value' => function($Item) { - $dynamic_fields = PerchUtil::json_safe_decode($Item->productDynamicFields(), true); - + $stock_location = $stock_status = ''; + if(isset($dynamic_fields['stock_location'])) + { $stock_location = $dynamic_fields['stock_location']; + } + if(isset($dynamic_fields['stock_status'])) + { $stock_status = $dynamic_fields['stock_status']; - + } + + if($stock_location == '0') { global $productsPATH; @@ -300,30 +304,36 @@ return $stock; } }, - 'sort' => 'stock_level', ]); - + + + $sort_price = 'price'; $displaySale = false; if($Settings->get('pipit_catalog_displaySalePrices')->val()) { $displaySale = true; + if(isset($_GET['sale']) && $_GET['sale'] === 'true') + { + $sort_price = 'sale_price'; + } } $Listing->add_col([ - 'title' => 'Price', - 'value' => function($Item) use ($HTML) { + 'title' => 'Price', + 'sort' => $sort_price, + 'value' => function($Item) use ($HTML) { global $displaySale; - //$prices = $Item->price(); - $dynamic_fields = PerchUtil::json_safe_decode($Item->productDynamicFields(), true); - - $prices = $dynamic_fields['price']; - $onSale = $dynamic_fields['on_sale']; - if($onSale && $displaySale) - { - $prices = $dynamic_fields['sale_price']; - } + //$prices = $Item->price(); + $dynamic_fields = PerchUtil::json_safe_decode($Item->productDynamicFields(), true); + + $prices = $dynamic_fields['price']; + $onSale = $dynamic_fields['on_sale']; + if($onSale && $displaySale) + { + $prices = $dynamic_fields['sale_price']; + } if (PerchUtil::count($prices)) { if (isset($prices['_default'])) unset($prices['_default']); diff --git a/pipit_catalog/modes/list.pre.php b/pipit_catalog/modes/list.pre.php index 0a00bc1..a2892ec 100644 --- a/pipit_catalog/modes/list.pre.php +++ b/pipit_catalog/modes/list.pre.php @@ -15,6 +15,7 @@ $ShopAPI = new PerchAPI(1, 'perch_shop'); $ProductsAPI = new PerchAPI(1, 'perch_shop_products'); + $Products = new PerchShop_Products($ShopAPI); $Brands = new PerchShop_Brands($ShopAPI); $brands = $Brands->all(); @@ -40,7 +41,8 @@ //defaults $selected_status = $selected_shipping = $selected_sale = $selected_catID = $selected_brandID = ''; - $filter = 'products'; + $sort_id = 'title'; + $sort_order = 'ASC'; $filters = []; $listing_opts = ['return-objects' => true,]; @@ -119,6 +121,28 @@ 'value' => $selected_brandID, ]; } + + if (isset($_GET['sort']) && $_GET['sort'] != '') + { + if(substr($_GET['sort'], 0, 1) === '^') + { + $sort_id = substr($_GET['sort'], 1); + $sort_order = 'ASC'; + } + else + { + $sort_id = $_GET['sort']; + $sort_order = 'DESC'; + } + + if($sort_id === 'price' || $sort_id === 'stock') + { + $listing_opts['sort-type'] = 'numeric'; + } + } + + $listing_opts['sort'] = $sort_id; + $listing_opts['sort-order'] = $sort_order; if (isset($_GET['q']) && $_GET['q']!='') @@ -141,7 +165,6 @@ - $listing_opts['filter'] = $filters; if(count($filters) > 1) { @@ -149,28 +172,24 @@ } - //handle paging, is there a better way? - $Paging->set_total(count($Products->get_filtered_listing($listing_opts, true))); - - $listing_opts['paginate'] = true; - $listing_opts['count'] = $per_page; - //sort options - //$listing_opts['sort'] = 'sku'; - //$listing_opts['sort-order'] = 'ASC'; - - $products = $Products->get_filtered_listing($listing_opts, true); - if($products) + $where_callback = function (PerchQuery $Query) + { + $Query->where[] = 'productDeleted IS NULL'; + $Query->where[] = 'parentID IS NULL'; + return $Query; + }; + + $products_for_paging = $Products->get_filtered_listing($listing_opts, $where_callback); + if($products_for_paging) { - foreach($products as $productKey => $product) - { - if($product->productDeleted()) - { - unset($products[$productKey]); - } - } + $listing_opts['paginate'] = true; + $listing_opts['count'] = $per_page; + + + $products = $Products->get_filtered_listing($listing_opts, $where_callback, true); + $Paging->set_total(count($products_for_paging)); } else { $search_message = $HTML->warning_message('No matching products found.'); - } - + } \ No newline at end of file