From 51731017bd1fe3b69ae97c05f7798ec6662a07ea Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 9 Sep 2013 09:10:56 +0200 Subject: [PATCH 1/7] create customer admin controller and index controller --- .../Thelia/Config/Resources/routing/admin.xml | 8 ++++ .../Controller/Admin/CustomerController.php | 40 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 core/lib/Thelia/Controller/Admin/CustomerController.php diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index e8262117b..15dd8acd0 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -31,6 +31,14 @@ Thelia\Controller\Admin\CategoryController::defaultAction + + + + Thelia\Controller\Admin\CustomerController::indexAction + + + + diff --git a/core/lib/Thelia/Controller/Admin/CustomerController.php b/core/lib/Thelia/Controller/Admin/CustomerController.php new file mode 100644 index 000000000..eabfee0ce --- /dev/null +++ b/core/lib/Thelia/Controller/Admin/CustomerController.php @@ -0,0 +1,40 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Controller\Admin; + + +/** + * Class CustomerController + * @package Thelia\Controller\Admin + * @author Manuel Raynaud + */ +class CustomerController extends BaseAdminController +{ + public function indexAction() + { + if (null !== $response = $this->checkAuth("admin.customers.view")) return $response; + + return $this->render("customers"); + } +} \ No newline at end of file From 54dd496f5206b3465308e05f93e81c9647d0aa56 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 9 Sep 2013 11:07:14 +0200 Subject: [PATCH 2/7] update format smarty plugin --- core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php index daaff3fc1..3deffc1aa 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php @@ -113,9 +113,15 @@ class Format extends AbstractSmartyPlugin throw new SmartyPluginException("number is a mandatory parameter in format_number function"); } + $number = $params["number"]; + + if(empty($number)) { + return ""; + } + $lang = $this->request->getSession()->getLang(); - $number = $params["number"]; + $decimals = array_key_exists("decimals", $params) ? $params["decimals"] : $lang->getDecimals(); $decPoint = array_key_exists("dec_point", $params) ? $params["dec_point"] : $lang->getDecimalSeparator(); $thousandsSep = array_key_exists("thousands_sep", $params) ? $params["thousands_sep"] : $lang->getThousandsSeparator(); From 8e77e4b5303c1cdaa00ff81f3285acfdb87518ed Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 9 Sep 2013 11:07:51 +0200 Subject: [PATCH 3/7] create admin customer view and add output info in customer loop --- .../Thelia/Core/Template/Loop/Customer.php | 15 +++ core/lib/Thelia/Model/Order.php | 11 ++ templates/admin/default/customers.html | 108 ++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 templates/admin/default/customers.html diff --git a/core/lib/Thelia/Core/Template/Loop/Customer.php b/core/lib/Thelia/Core/Template/Loop/Customer.php index 1a4b84105..cbf9e4fda 100755 --- a/core/lib/Thelia/Core/Template/Loop/Customer.php +++ b/core/lib/Thelia/Core/Template/Loop/Customer.php @@ -64,6 +64,7 @@ class Customer extends BaseLoop ) ), Argument::createBooleanTypeArgument('reseller'), + Argument::createBooleanTypeArgument('last_order'), Argument::createIntTypeArgument('sponsor') ); } @@ -130,6 +131,20 @@ class Customer extends BaseLoop $loopResultRow->set("SPONSOR", $customer->getSponsor()); $loopResultRow->set("DISCOUNT", $customer->getDiscount()); + $lastOrderDate = ""; + $lastOrderAmount = ""; + + if ($this->getLastOrder()) { + $order = $customer->getOrders()->getFirst(); + if ($order) { + $lastOrderDate = $order->getCreatedAt(); + $lastOrderAmount = $order->getTotalAmount(); + } + } + + $loopResultRow->set("LASTORDER_DATE", $lastOrderDate); + $loopResultRow->set("LASTORDER_AMOUNT", $lastOrderAmount); + $loopResult->addRow($loopResultRow); } diff --git a/core/lib/Thelia/Model/Order.php b/core/lib/Thelia/Model/Order.php index 91582750a..ccdd152b5 100755 --- a/core/lib/Thelia/Model/Order.php +++ b/core/lib/Thelia/Model/Order.php @@ -6,4 +6,15 @@ use Thelia\Model\Base\Order as BaseOrder; class Order extends BaseOrder { + /** + * calculate the total amount + * + * @TODO create body method + * + * @return int + */ + public function getTotalAmount() + { + return 0; + } } diff --git a/templates/admin/default/customers.html b/templates/admin/default/customers.html new file mode 100644 index 000000000..0e68677dd --- /dev/null +++ b/templates/admin/default/customers.html @@ -0,0 +1,108 @@ +{extends file="admin-layout.tpl"} + +{block name="page-title"}{intl l='Customer'}{/block} + +{block name="check-permissions"}admin.customer.view{/block} + +{block name="main-content"} +
+
+ + + {module_include location='customer_top'} + +
+
+
+ + + + {ifloop rel="customer_list"} + + + + + + + {module_include location='category_list_header'} + + + + + + + + + + + + + {loop name="customer_list" type="customer" visible="*" last_order="1" backend_context="1"} + + + + + + + + {module_include location='customer_list_row'} + + + + + + + + {/loop} + + {/ifloop} +
+ {intl l="Customers list"} + + {module_include location='customer_list_caption'} + + {loop type="auth" name="can_create" roles="ADMIN" permissions="admin.customers.create"} + + + + {/loop} +
+ {intl l="customer ref"} + + {intl l="company"} + + {intl l="firstname & lastname"} + + {intl l="last order"} + {intl l='order amount'}{intl l='Actions'}
{#REF} + {#COMPANY} + + {#FIRSTNAME} {#LASTNAME} + + {format_date date=#LASTORDER_DATE} + + {format_number number=#LASTORDER_AMOUNT} + +
+ + {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.customer.edit"} + + {/loop} + {loop type="auth" name="can_send_mail" roles="ADMIN" permissions="admin.customer.sendMail"} + + {/loop} + {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.customer.delete"} + + {/loop} +
+
+
+
+
+ + + {module_include location='customer_bottom'} +
+
+ +{/block} \ No newline at end of file From 77fc36fc91d865b79cdd5f372939143012bde4c5 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 9 Sep 2013 12:46:27 +0200 Subject: [PATCH 4/7] escae output only if it's not an object --- .../Thelia/Core/Template/Smarty/SmartyParser.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php index 85619bc8a..a6dbf3715 100755 --- a/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php +++ b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php @@ -65,9 +65,7 @@ class SmartyParser extends Smarty implements ParserInterface $this->setTemplate($template ?: ConfigQuery::read('active-template', 'default')); $this->debugging = $debug; - - $this->escape_html = true; - + // Prevent smarty ErrorException: Notice: Undefined index bla bla bla... $this->error_reporting = E_ALL ^ E_NOTICE; @@ -86,6 +84,7 @@ class SmartyParser extends Smarty implements ParserInterface $this->registerFilter('pre', array($this, "preThelia")); $this->registerFilter('output', array($this, "removeBlankLines")); + $this->registerFilter('variable', array(__CLASS__, "theliaEscape")); } public function preThelia($tpl_source, \Smarty_Internal_Template $template) @@ -101,6 +100,15 @@ class SmartyParser extends Smarty implements ParserInterface return preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $tpl_source); } + public static function theliaEscape($content, $smarty) + { + if(!is_object($content)) { + return htmlspecialchars($content ,ENT_QUOTES, Smarty::$_CHARSET); + } else { + return $content; + } + } + public function setTemplate($template_path_from_template_base) { $this->template = $template_path_from_template_base; From d4ec36e920776a7021ec42ce45d48f0bf77788fd Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 9 Sep 2013 14:29:11 +0200 Subject: [PATCH 5/7] mock getTotalAmoutn in order class --- core/lib/Thelia/Model/Order.php | 2 +- templates/admin/default/customers.html | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/lib/Thelia/Model/Order.php b/core/lib/Thelia/Model/Order.php index ccdd152b5..f8e6db193 100755 --- a/core/lib/Thelia/Model/Order.php +++ b/core/lib/Thelia/Model/Order.php @@ -15,6 +15,6 @@ class Order extends BaseOrder { */ public function getTotalAmount() { - return 0; + return 2; } } diff --git a/templates/admin/default/customers.html b/templates/admin/default/customers.html index 0e68677dd..e49e12e29 100644 --- a/templates/admin/default/customers.html +++ b/templates/admin/default/customers.html @@ -70,11 +70,11 @@ {module_include location='customer_list_row'} - {format_date date=#LASTORDER_DATE} + {format_date date=$LASTORDER_DATE} - {format_number number=#LASTORDER_AMOUNT} + {format_number number=$LASTORDER_AMOUNT}
From 66454ef3f030332b4366b21124c9ccde6ed155a3 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 9 Sep 2013 16:03:38 +0200 Subject: [PATCH 6/7] finish simple list customer page in backoffice --- .../Controller/Admin/CustomerController.php | 2 +- templates/admin/default/customers.html | 37 +++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/core/lib/Thelia/Controller/Admin/CustomerController.php b/core/lib/Thelia/Controller/Admin/CustomerController.php index eabfee0ce..04c8842cd 100644 --- a/core/lib/Thelia/Controller/Admin/CustomerController.php +++ b/core/lib/Thelia/Controller/Admin/CustomerController.php @@ -35,6 +35,6 @@ class CustomerController extends BaseAdminController { if (null !== $response = $this->checkAuth("admin.customers.view")) return $response; - return $this->render("customers"); + return $this->render("customers", array("display_customer" => 20)); } } \ No newline at end of file diff --git a/templates/admin/default/customers.html b/templates/admin/default/customers.html index e49e12e29..e126b9f77 100644 --- a/templates/admin/default/customers.html +++ b/templates/admin/default/customers.html @@ -1,3 +1,4 @@ + {extends file="admin-layout.tpl"} {block name="page-title"}{intl l='Customer'}{/block} @@ -5,6 +6,9 @@ {block name="check-permissions"}admin.customer.view{/block} {block name="main-content"} + {assign var=customer_page value={$smarty.get.page|default:1}} + +
@@ -21,7 +25,7 @@ {module_include location='customer_list_caption'} {loop type="auth" name="can_create" roles="ADMIN" permissions="admin.customers.create"} - + {/loop} @@ -31,7 +35,7 @@ - {intl l="customer ref"} + {intl l="customer ref"} {$customer_current_page} toto @@ -55,7 +59,7 @@ - {loop name="customer_list" type="customer" visible="*" last_order="1" backend_context="1"} + {loop name="customer_list" type="customer" visible="*" last_order="1" backend_context="1" page={$customer_page} limit={$display_customer}} {#REF} @@ -102,6 +106,33 @@ {module_include location='customer_bottom'} +
+
+ +
    + {if #customer_page != 1} +
  • «
  • + {else} +
  • «
  • + {/if} + + {pageloop rel="customer_list"} + {if #PAGE != #CURRENT} +
  • #PAGE
  • + {else} +
  • #PAGE
  • + {/if} + + {if #PAGE == #LAST && #LAST != #CURRENT} +
  • »
  • + {else} +
  • »
  • + {/if} + {/pageloop} +
+
+
+
From 3618199c05e73a9a0c93e88e03074b55797f6b92 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 9 Sep 2013 16:08:42 +0200 Subject: [PATCH 7/7] remove test --- templates/admin/default/customers.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/admin/default/customers.html b/templates/admin/default/customers.html index e126b9f77..923941c4e 100644 --- a/templates/admin/default/customers.html +++ b/templates/admin/default/customers.html @@ -35,7 +35,7 @@ - {intl l="customer ref"} {$customer_current_page} toto + {intl l="customer ref"}