Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/v1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
husseinalhammad committed Dec 13, 2017
2 parents 5c49c18 + b6c2756 commit 66c84e4
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 76 deletions.
2 changes: 1 addition & 1 deletion pipit_catalog/admin.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
if ($CurrentUser->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);
Expand Down
2 changes: 1 addition & 1 deletion pipit_catalog/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
46 changes: 17 additions & 29 deletions pipit_catalog/lang/en-gb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
56 changes: 33 additions & 23 deletions pipit_catalog/modes/list.post.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
# Main panel
echo $HTML->title_panel([
'heading' => $Lang->get('Catalog'),
'heading' => $Lang->get('Product Catalog'),
'button' => [
'text' => $Lang->get('Add a Product'),
'link' => $productsURL.'/product/edit/',
Expand All @@ -12,8 +12,6 @@

if (isset($message)) echo $message;




$persist_args = '';
$ParentSmartbar = new PerchSmartbar($CurrentUser, $HTML, $Lang);
Expand All @@ -39,7 +37,6 @@
'arg' => 'q',
'icon' => 'core/search',
'position' => 'end',
//'persist' => ['category', 'brand', 'status', 'sale', 'shipping'],
]);
}

Expand All @@ -54,7 +51,7 @@



/* Filters */
# Filters
// form->start()
echo '<form method="get" action="'.$API->app_path().'" class="app form-simple pipit-filters">';

Expand Down Expand Up @@ -157,7 +154,7 @@



if($products)
if($products_for_paging)
{
$Listing = new PerchAdminListing($CurrentUser, $HTML, $Lang, $Paging);

Expand Down Expand Up @@ -204,7 +201,7 @@
global $API;
$noImg = '<img class="listing__thumb" src="'.$API->app_path().'/assets/images/no-image.png'.'" />';

if($dynamic_fields['image'])
if(isset($dynamic_fields['image']))
{
$image = $dynamic_fields['image'];

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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']);
Expand Down
63 changes: 41 additions & 22 deletions pipit_catalog/modes/list.pre.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand 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,];

Expand Down Expand Up @@ -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']!='')
Expand All @@ -141,36 +165,31 @@




$listing_opts['filter'] = $filters;
if(count($filters) > 1)
{
$listing_opts['filter-mode'] = 'ungrouped';
}


//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.');
}

}

0 comments on commit 66c84e4

Please sign in to comment.