From eb895bc5445f6a1a83ff69b9c46b4e35cc1ab904 Mon Sep 17 00:00:00 2001 From: Guillaume Barral Date: Tue, 3 Jun 2014 12:35:52 +0200 Subject: [PATCH] Add pagination to the product list (backOffice) --- .../Controller/Admin/CategoryController.php | 12 ++++++--- .../Controller/Admin/ProductController.php | 23 ++++++----------- templates/backOffice/default/categories.html | 25 +++++++++++++++---- .../backOffice/default/configs/variables.conf | 1 + .../default/includes/product-general-tab.html | 3 ++- 5 files changed, 39 insertions(+), 25 deletions(-) diff --git a/core/lib/Thelia/Controller/Admin/CategoryController.php b/core/lib/Thelia/Controller/Admin/CategoryController.php index ad5b2bd36..c4604c990 100644 --- a/core/lib/Thelia/Controller/Admin/CategoryController.php +++ b/core/lib/Thelia/Controller/Admin/CategoryController.php @@ -169,7 +169,8 @@ class CategoryController extends AbstractSeoCrudController return array( 'category_id' => $this->getRequest()->get('category_id', 0), 'folder_id' => $this->getRequest()->get('folder_id', 0), - 'current_tab' => $this->getRequest()->get('current_tab', 'general') + 'current_tab' => $this->getRequest()->get('current_tab', 'general'), + 'page' => $this->getRequest()->get('page', 1) ); } @@ -182,14 +183,17 @@ class CategoryController extends AbstractSeoCrudController array( 'category_order' => $currentOrder, 'product_order' => $product_order, - 'category_id' => $this->getRequest()->get('category_id', 0) + 'category_id' => $this->getRequest()->get('category_id', 0), + 'page' => $this->getRequest()->get('page', 1) )); } protected function redirectToListTemplate() { - $category_id = $this->getRequest()->get('category_id', 0); - $this->redirectToListTemplateWithId($category_id); + $this->redirectToRoute('admin.categories', array( + 'category_id' => $this->getRequest()->get('category_id', 0), + 'page' => $this->getRequest()->get('page', 1)) + ); } protected function redirectToListTemplateWithId($category_id) diff --git a/core/lib/Thelia/Controller/Admin/ProductController.php b/core/lib/Thelia/Controller/Admin/ProductController.php index f4bfb095f..4cbfbad42 100644 --- a/core/lib/Thelia/Controller/Admin/ProductController.php +++ b/core/lib/Thelia/Controller/Admin/ProductController.php @@ -361,7 +361,8 @@ class ProductController extends AbstractSeoCrudController 'product_id' => $this->getRequest()->get('product_id', 0), 'folder_id' => $this->getRequest()->get('folder_id', 0), 'accessory_category_id' => $this->getRequest()->get('accessory_category_id', 0), - 'current_tab' => $this->getRequest()->get('current_tab', 'general') + 'current_tab' => $this->getRequest()->get('current_tab', 'general'), + 'page' => $this->getRequest()->get('page', 1) ); } @@ -386,7 +387,8 @@ class ProductController extends AbstractSeoCrudController return $this->render('categories', array( 'product_order' => $currentOrder, - 'category_id' => $this->getCategoryId() + 'category_id' => $this->getCategoryId(), + 'page' => $this->getRequest()->get('page', 1) )); } @@ -394,7 +396,10 @@ class ProductController extends AbstractSeoCrudController { $this->redirectToRoute( 'admin.products.default', - array('category_id' => $this->getCategoryId()) + array( + 'category_id' => $this->getCategoryId(), + 'page' => $this->getRequest()->get('page', 1) + ) ); } @@ -438,18 +443,6 @@ class ProductController extends AbstractSeoCrudController ); } - protected function performAdditionalUpdateAction($updateEvent) - { - if ($this->getRequest()->get('save_mode') != 'stay') { - - // Redirect to parent product list - $this->redirectToRoute( - 'admin.categories.default', - array('category_id' => $this->getCategoryId()) - ); - } - } - protected function performAdditionalUpdatePositionAction($positionEvent) { // Redirect to parent product list diff --git a/templates/backOffice/default/categories.html b/templates/backOffice/default/categories.html index 5239efaa4..af5f4897f 100644 --- a/templates/backOffice/default/categories.html +++ b/templates/backOffice/default/categories.html @@ -270,20 +270,20 @@ - {loop name="product_list" type="product" visible="*" category_default=$category_id order=$product_order} + {loop name="product_list" type="product" visible="*" category_default=$category_id order=$product_order page=$page limit=#max_displayed_products#} {$ID} {loop type="image" name="cat_image" source="product" source_id="$ID" limit="1" width="50" height="50" resize_mode="crop" backend_context="1"} - + {$TITLE} {/loop} - {$REF} + {$REF} - {$TITLE} + {$TITLE} {module_include location='product_list_row'} @@ -316,7 +316,7 @@
{loop type="auth" name="can_change" role="ADMIN" resource="admin.product" access="UPDATE"} - + {/loop} {loop type="auth" name="can_delete" role="ADMIN" resource="admin.product" access="DELETE"} @@ -327,6 +327,20 @@ {/loop} + + + + {include + file = "includes/pagination.html" + + loop_ref = "product_list" + max_page_count = 10 + page_url = "{url path="/admin/categories" category_id=$category_id product_order=$product_order}" + } + + + + {/ifloop} {elseloop rel="product_list"} @@ -610,6 +624,7 @@ {capture "product_delete_dialog"} + {module_include location='product_delete_form'} diff --git a/templates/backOffice/default/configs/variables.conf b/templates/backOffice/default/configs/variables.conf index c2c81c01d..0a40df3a1 100644 --- a/templates/backOffice/default/configs/variables.conf +++ b/templates/backOffice/default/configs/variables.conf @@ -2,6 +2,7 @@ # -------------------------------- max_displayed_orders = 20 max_displayed_customers = 20 +max_displayed_products = 20 # order status - seems ununsed ? # ------------------------------ diff --git a/templates/backOffice/default/includes/product-general-tab.html b/templates/backOffice/default/includes/product-general-tab.html index 9cc34c815..eab5f1e44 100644 --- a/templates/backOffice/default/includes/product-general-tab.html +++ b/templates/backOffice/default/includes/product-general-tab.html @@ -12,6 +12,7 @@ } {* Be sure to get the product ID, even if the form could not be validated*} + @@ -22,7 +23,7 @@ {/form_field} {form_field form=$form field='success_url'} - + {/form_field} {form_field form=$form field='locale'}