From 93e7a4dc90b899d86015dfc8971410feeb478505 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Tue, 24 Sep 2013 09:44:59 +0200 Subject: [PATCH] order admin integration --- core/lib/Thelia/Config/Resources/config.xml | 1 + core/lib/Thelia/Core/Template/Loop/Order.php | 26 ++- .../Core/Template/Loop/OrderAddress.php | 155 ++++++++++++++++++ templates/admin/default/orders.html | 60 ++----- 4 files changed, 190 insertions(+), 52 deletions(-) create mode 100755 core/lib/Thelia/Core/Template/Loop/OrderAddress.php diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 809c62a33..0421f4ef6 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -23,6 +23,7 @@ + diff --git a/core/lib/Thelia/Core/Template/Loop/Order.php b/core/lib/Thelia/Core/Template/Loop/Order.php index 41d49c4f8..25e12fec8 100755 --- a/core/lib/Thelia/Core/Template/Loop/Order.php +++ b/core/lib/Thelia/Core/Template/Loop/Order.php @@ -53,11 +53,18 @@ class Order extends BaseLoop 'customer', new TypeCollection( new Type\IntType(), - new Type\EnumType(array('current')) + new Type\EnumType(array('current', '*')) ), 'current' ), - Argument::createIntListTypeArgument('status') + Argument::createIntListTypeArgument('status'), + new Argument( + 'order', + new TypeCollection( + new Type\EnumListType(array('create-date', 'create-date-reverse')) + ), + 'create-date-reverse' + ) ); } @@ -85,7 +92,7 @@ class Order extends BaseLoop } else { $search->filterByCustomerId($currentCustomer->getId(), Criteria::EQUAL); } - } else { + } elseif ($customer !== '*') { $search->filterByCustomerId($customer, Criteria::EQUAL); } @@ -95,6 +102,19 @@ class Order extends BaseLoop $search->filterByStatusId($status, Criteria::IN); } + $orderers = $this->getOrder(); + + foreach ($orderers as $orderer) { + switch ($orderer) { + case "create-date": + $search->orderByCreatedAt(Criteria::ASC); + break; + case "create-date-reverse": + $search->orderByCreatedAt(Criteria::DESC); + break; + } + } + $orders = $this->search($search, $pagination); $loopResult = new LoopResult($orders); diff --git a/core/lib/Thelia/Core/Template/Loop/OrderAddress.php b/core/lib/Thelia/Core/Template/Loop/OrderAddress.php new file mode 100755 index 000000000..cb0cbd5b5 --- /dev/null +++ b/core/lib/Thelia/Core/Template/Loop/OrderAddress.php @@ -0,0 +1,155 @@ +. */ +/* */ +/*************************************************************************************/ + +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\Loop\Argument\ArgumentCollection; +use Thelia\Core\Template\Loop\Argument\Argument; + +use Thelia\Model\AddressQuery; +use Thelia\Type\TypeCollection; +use Thelia\Type; + +/** + * + * OrderAddress loop + * + * + * Class OrderAddress + * @package Thelia\Core\Template\Loop + * @author Etienne Roudeix + */ +class OrderAddress extends BaseLoop +{ + public $timestampable = true; + + /** + * @return ArgumentCollection + */ + protected function getArgDefinitions() + { + return new ArgumentCollection( + new Argument( + 'id', + new TypeCollection( + new Type\IntListType(), + new Type\EnumType(array('*', 'any')) + ) + ), + new Argument( + 'customer', + new TypeCollection( + new Type\IntType(), + new Type\EnumType(array('current')) + ), + 'current' + ), + Argument::createBooleanOrBothTypeArgument('default'), + new Argument( + 'exclude', + new TypeCollection( + new Type\IntListType(), + new Type\EnumType(array('none')) + ) + ) + ); + } + + /** + * @param $pagination + * + * @return \Thelia\Core\Template\Element\LoopResult + */ + public function exec(&$pagination) + { + $search = OrderAddressQuery::create(); + + $id = $this->getId(); + + if (null !== $id && !in_array($id, array('*', 'any'))) { + $search->filterById($id, Criteria::IN); + } + + $customer = $this->getCustomer(); + + if ($customer === 'current') { + $currentCustomer = $this->securityContext->getCustomerUser(); + if ($currentCustomer === null) { + return new LoopResult(); + } else { + $search->filterByCustomerId($currentCustomer->getId(), Criteria::EQUAL); + } + } else { + $search->filterByCustomerId($customer, Criteria::EQUAL); + } + + $default = $this->getDefault(); + + if ($default === true) { + $search->filterByIsDefault(1, Criteria::EQUAL); + } else if($default === false) { + $search->filterByIsDefault(0, Criteria::EQUAL); + } + + $exclude = $this->getExclude(); + + if (null !== $exclude && 'none' !== $exclude) { + $search->filterById($exclude, Criteria::NOT_IN); + } + + $addresses = $this->search($search, $pagination); + + $loopResult = new LoopResult($addresses); + + foreach ($addresses as $address) { + $loopResultRow = new LoopResultRow($loopResult, $address, $this->versionable, $this->timestampable, $this->countable); + $loopResultRow + ->set("ID", $address->getId()) + ->set("LABEL", $address->getLabel()) + ->set("CUSTOMER", $address->getCustomerId()) + ->set("TITLE", $address->getTitleId()) + ->set("COMPANY", $address->getCompany()) + ->set("FIRSTNAME", $address->getFirstname()) + ->set("LASTNAME", $address->getLastname()) + ->set("ADDRESS1", $address->getAddress1()) + ->set("ADDRESS2", $address->getAddress2()) + ->set("ADDRESS3", $address->getAddress3()) + ->set("ZIPCODE", $address->getZipcode()) + ->set("CITY", $address->getCity()) + ->set("COUNTRY", $address->getCountryId()) + ->set("PHONE", $address->getPhone()) + ->set("CELLPHONE", $address->getCellphone()) + ->set("DEFAULT", $address->getIsDefault()) + ; + + $loopResult->addRow($loopResultRow); + } + + return $loopResult; + } +} diff --git a/templates/admin/default/orders.html b/templates/admin/default/orders.html index 02bbea458..2cb8517ea 100644 --- a/templates/admin/default/orders.html +++ b/templates/admin/default/orders.html @@ -45,10 +45,18 @@ + {loop type="order" name="order-list" customer="*"} + + {loop type="customer" name="order-customer"} + {/loop} + + {loop type="order_address" name="order-invoice-address"} + {/loop} + - 01230450123045 - 11/09/2013 10:24:31 + {$REF} + {format_date date=$CREATE_DATE} Thelia Dupont 251 € @@ -69,54 +77,8 @@ - - 01230450123045 - 11/09/2013 10:24:31 - Thelia - Dupont - 251 € - Canceled - - {module_include location='orders_table_row'} - - -
- - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.orders.edit"} - - {/loop} - - {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.orders.delete"} - - {/loop} -
- - - - - 01230450123045 - 11/09/2013 10:24:31 - Thelia - Dupont - 251 € - Current - - {module_include location='orders_table_row'} - - -
- - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.orders.edit"} - - {/loop} - - {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.orders.delete"} - - {/loop} -
- - + {/loop}