From 6b78a33f974ee504addc029b1203be771ed7c1fa Mon Sep 17 00:00:00 2001
From: Franck Allimant
Date: Sat, 25 Jan 2014 19:14:57 +0100
Subject: [PATCH] Improved order management in back-office
---
.../Controller/Admin/OrderController.php | 6 +-
core/lib/Thelia/Core/Template/Loop/Order.php | 73 ++++++++++++++++++-
.../Core/Template/Smarty/Plugins/Format.php | 40 +++++++++-
.../Core/Template/Smarty/Plugins/Module.php | 3 +-
.../backOffice/default/customer-edit.html | 8 ++
templates/backOffice/default/order-edit.html | 64 +++++++++-------
templates/backOffice/default/orders.html | 73 ++++++++++++++++---
7 files changed, 219 insertions(+), 48 deletions(-)
diff --git a/core/lib/Thelia/Controller/Admin/OrderController.php b/core/lib/Thelia/Controller/Admin/OrderController.php
index c04e2c93e..97713a589 100644
--- a/core/lib/Thelia/Controller/Admin/OrderController.php
+++ b/core/lib/Thelia/Controller/Admin/OrderController.php
@@ -46,7 +46,11 @@ class OrderController extends BaseAdminController
public function indexAction()
{
if (null !== $response = $this->checkAuth(AdminResources::ORDER, array(), AccessManager::VIEW)) return $response;
- return $this->render("orders", array("display_order" => 20));
+
+ return $this->render("orders", array(
+ "display_order" => 20,
+ "orders_order" => $this->getListOrderFromSession("orders", "orders_order", "create-date-reverse")
+ ));
}
public function viewAction($order_id)
diff --git a/core/lib/Thelia/Core/Template/Loop/Order.php b/core/lib/Thelia/Core/Template/Loop/Order.php
index 3fb04d60c..c3e48dc8e 100644
--- a/core/lib/Thelia/Core/Template/Loop/Order.php
+++ b/core/lib/Thelia/Core/Template/Loop/Order.php
@@ -26,17 +26,20 @@ namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
-
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Element\SearchLoopInterface;
-use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
+use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
+use Thelia\Model\Base\Customer;
use Thelia\Model\CustomerQuery;
+use Thelia\Model\Map\CustomerTableMap;
+use Thelia\Model\Map\OrderAddressTableMap;
use Thelia\Model\OrderAddressQuery;
use Thelia\Model\OrderQuery;
-use Thelia\Type\TypeCollection;
use Thelia\Type;
+use Thelia\Type\TypeCollection;
+
/**
*
* @package Thelia\Core\Template\Loop
@@ -72,7 +75,14 @@ class Order extends BaseLoop implements SearchLoopInterface, PropelSearchLoopInt
new Argument(
'order',
new TypeCollection(
- new Type\EnumListType(array('create-date', 'create-date-reverse'))
+ new Type\EnumListType(array(
+ 'id', 'id-reverse',
+ 'reference', 'reference-reverse',
+ 'create-date', 'create-date-reverse',
+ 'company', 'company-reverse',
+ 'customer-name', 'customer-name-reverse',
+ 'status', 'status-reverse'
+ ))
),
'create-date-reverse'
)
@@ -165,12 +175,67 @@ class Order extends BaseLoop implements SearchLoopInterface, PropelSearchLoopInt
foreach ($orderers as $orderer) {
switch ($orderer) {
+ case 'id':
+ $search->orderById(Criteria::ASC);
+ break;
+ case 'id_reverse':
+ $search->orderById(Criteria::DESC);
+ break;
+
+ case 'reference':
+ $search->orderByRef(Criteria::ASC);
+ break;
+ case 'reference_reverse':
+ $search->orderByRef(Criteria::DESC);
+ break;
+
case "create-date":
$search->orderByCreatedAt(Criteria::ASC);
break;
case "create-date-reverse":
$search->orderByCreatedAt(Criteria::DESC);
break;
+
+ case "status":
+ $search->orderByStatusId(Criteria::ASC);
+ break;
+ case "status":
+ $search->orderByStatusId(Criteria::DESC);
+ break;
+
+ case 'company' :
+ $search
+ ->joinOrderAddressRelatedByDeliveryOrderAddressId()
+ ->withColumn(OrderAddressTableMap::COMPANY, 'company')
+ ->orderBy('company', Criteria::ASC)
+ ;
+ break;
+ case 'companyreverse' :
+ $search
+ ->joinOrderAddressRelatedByDeliveryOrderAddressId()
+ ->withColumn(OrderAddressTableMap::COMPANY, 'company')
+ ->orderBy('company', Criteria::DESC)
+ ;
+ break;
+
+ case 'customer-name' :
+ $search
+ ->joinCustomer()
+ ->withColumn(CustomerTableMap::FIRSTNAME, 'firstname')
+ ->withColumn(CustomerTableMap::LASTNAME, 'lastname')
+ ->orderBy('lastname', Criteria::ASC)
+ ->orderBy('firstname', Criteria::ASC)
+ ;
+ break;
+ case 'customer-name-reverse' :
+ $search
+ ->joinCustomer()
+ ->withColumn(CustomerTableMap::FIRSTNAME, 'firstname')
+ ->withColumn(CustomerTableMap::LASTNAME, 'lastname')
+ ->orderBy('lastname', Criteria::DESC)
+ ->orderBy('firstname', Criteria::DESC)
+ ;
+ break;
}
}
diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php
index d0f021ef5..f022cf0c5 100644
--- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php
+++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php
@@ -28,6 +28,7 @@ use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
use Thelia\Core\Template\Smarty\Exception\SmartyPluginException;
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
use Thelia\Tools\DateTimeFormat;
+use Thelia\Tools\MoneyFormat;
use Thelia\Tools\NumberFormat;
/**
@@ -135,6 +136,40 @@ class Format extends AbstractSmartyPlugin
$this->getParam($params, "thousands_sep", null)
);
}
+ /**
+ *
+ * display a amount in expected format
+ *
+ * available parameters :
+ * number => int or float number
+ * decimals => how many decimals format expected
+ * dec_point => separator for the decimal point
+ * thousands_sep => thousands separator
+ * symbol => Currency symbol
+ *
+ * ex : {format_money number="1246.12" decimals="1" dec_point="," thousands_sep=" " symbol="€"} will output "1 246,1 €"
+ *
+ * @param $params
+ * @param null $template
+ * @throws \Thelia\Core\Template\Smarty\Exception\SmartyPluginException
+ * @return string the expected number formatted
+ */
+ public function formatMoney($params, $template = null)
+ {
+ $number = $this->getParam($params, "number", false);
+
+ if ($number === false || $number == '') {
+ return "";
+ }
+
+ return MoneyFormat::getInstance($this->request)->format(
+ $number,
+ $this->getParam($params, "decimals", null),
+ $this->getParam($params, "dec_point", null),
+ $this->getParam($params, "thousands_sep", null),
+ $this->getParam($params, "symbol", null)
+ );
+ }
/**
* @return an array of SmartyPluginDescriptor
@@ -143,7 +178,8 @@ class Format extends AbstractSmartyPlugin
{
return array(
new SmartyPluginDescriptor("function", "format_date", $this, "formatDate"),
- new SmartyPluginDescriptor("function", "format_number", $this, "formatNumber")
- );
+ new SmartyPluginDescriptor("function", "format_number", $this, "formatNumber"),
+ new SmartyPluginDescriptor("function", "format_money", $this, "formatMoney")
+ );
}
}
diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php
index 4c92ee85c..da98ce14d 100644
--- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php
+++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php
@@ -82,8 +82,9 @@ class Module extends AbstractSmartyPlugin
}
}
- if (! empty($content))
+ if (! empty($content)) {
return $template->fetch(sprintf("string:%s", $content));
+ }
return "";
}
diff --git a/templates/backOffice/default/customer-edit.html b/templates/backOffice/default/customer-edit.html
index d5b48f3d6..9747c935c 100644
--- a/templates/backOffice/default/customer-edit.html
+++ b/templates/backOffice/default/customer-edit.html
@@ -160,6 +160,7 @@
+ {ifloop rel="address"}
+ {/ifloop}
+
+ {elseloop rel="address"}
+
+ {intl l="This customer has not defined any delivery address"}
+
+ {/elseloop}
diff --git a/templates/backOffice/default/order-edit.html b/templates/backOffice/default/order-edit.html
index fc7903e1c..12915da92 100644
--- a/templates/backOffice/default/order-edit.html
+++ b/templates/backOffice/default/order-edit.html
@@ -28,22 +28,30 @@
{loop type="order" name="the-order" id=$order_id customer="*"}
{loop type="currency" name="order-currency" id=$CURRENCY}
- {assign "orderCurrency" $SYMBOL}
+ {$orderCurrency=$SYMBOL}
{/loop}
{assign "orderStatusId" $STATUS}
-