order admin

This commit is contained in:
Etienne Roudeix
2013-09-25 13:26:12 +02:00
parent 7bd511c420
commit d967242a59
15 changed files with 278 additions and 71 deletions

View File

@@ -287,6 +287,19 @@ class Order extends BaseAction implements EventSubscriberInterface
/* @todo */
}
/**
* @param OrderEvent $event
*/
public function updateStatus(OrderEvent $event)
{
$order = $event->getOrder();
$order->setStatusId($event->getStatus());
$order->save();
$event->setOrder($order);
}
/**
* Returns an array of event names this subscriber wants to listen to.
*
@@ -316,6 +329,7 @@ class Order extends BaseAction implements EventSubscriberInterface
TheliaEvents::ORDER_SET_PAYMENT_MODULE => array("setPaymentModule", 128),
TheliaEvents::ORDER_PAY => array("create", 128),
TheliaEvents::ORDER_BEFORE_PAYMENT => array("sendOrderEmail", 128),
TheliaEvents::ORDER_UPDATE_STATUS => array("updateStatus", 128),
);
}

View File

@@ -198,6 +198,10 @@
</call>
</service>
<service id="smarty.plugin.type" class="Thelia\Core\Template\Smarty\Plugins\Type" scope="request">
<tag name="thelia.parser.register_plugin"/>
</service>
<service id="smart.plugin.form" class="Thelia\Core\Template\Smarty\Plugins\Form" scope="request">
<tag name="thelia.parser.register_plugin"/>

View File

@@ -59,9 +59,9 @@
<!-- end Customer rule management -->
<!-- Order rule management -->
<!-- order management -->
<route id="admin.order" path="/admin/order">
<route id="admin.order.list" path="/admin/orders">
<default key="_controller">Thelia\Controller\Admin\OrderController::indexAction</default>
</route>
@@ -70,7 +70,11 @@
<requirement key="order_id">\d+</requirement>
</route>
<!-- end Customer rule management -->
<route id="admin.order.update.status" path="/admin/order/update/status">
<default key="_controller">Thelia\Controller\Admin\OrderController::updateStatus</default>
</route>
<!-- end order management -->
<!-- Categories management -->

View File

@@ -72,7 +72,7 @@ class CustomerController extends BaseAdminController
$customer = CustomerQuery::create()->findPk($customer_id);
if(null === $customer) {
throw new \InvalidArgumentException(sprintf("%d customer id does not exists", $customer_id));
throw new \InvalidArgumentException(sprintf("%d customer id does not exist", $customer_id));
}
$form = $this->validateForm($customerModification);
@@ -127,7 +127,7 @@ class CustomerController extends BaseAdminController
$customer = CustomerQuery::create()->findPk($customer_id);
if(null === $customer) {
throw new \InvalidArgumentException(Translator::getInstance("The customer you want to delete does not exists"));
throw new \InvalidArgumentException(Translator::getInstance("The customer you want to delete does not exist"));
}
$event = new CustomerEvent($customer);

View File

@@ -23,6 +23,12 @@
namespace Thelia\Controller\Admin;
use Thelia\Core\Event\OrderEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Translation\Translator;
use Thelia\Model\OrderQuery;
use Thelia\Model\OrderStatusQuery;
/**
* Class OrderController
* @package Thelia\Controller\Admin
@@ -44,4 +50,52 @@ class OrderController extends BaseAdminController
));
}
public function updateStatus()
{
if (null !== $response = $this->checkAuth("admin.order.update")) return $response;
$message = null;
try {
$orderId = $this->getRequest()->get("order_id");
$order = OrderQuery::create()->findPk($orderId);
$statusId = $this->getRequest()->get("status_id");
$status = OrderStatusQuery::create()->findPk($statusId);
if(null === $order) {
throw new \InvalidArgumentException("The order you want to update status does not exist");
}
if(null === $status) {
throw new \InvalidArgumentException("The status you want to set to the order does not exist");
}
$event = new OrderEvent($order);
$event->setStatus($statusId);
$this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
} catch(\Exception $e) {
$message = $e->getMessage();
}
$params = array();
if ($message) {
$params["update_status_error_message"] = $message;
}
$browsedPage = $this->getRequest()->get("order_page");
if($browsedPage) {
$params["order_page"] = $browsedPage;
$this->redirectToRoute("admin.order.list", $params);
} else {
$params["order_id"] = $orderId;
$this->redirectToRoute("admin.order.update.view", $params);
}
}
}

View File

@@ -35,6 +35,7 @@ class OrderEvent extends ActionEvent
protected $paymentModule = null;
protected $postage = null;
protected $ref = null;
protected $status = null;
/**
* @param Order $order
@@ -108,6 +109,14 @@ class OrderEvent extends ActionEvent
$this->ref = $ref;
}
/**
* @param $status
*/
public function setStatus($status)
{
$this->status = $status;
}
/**
* @return null|Order
*/
@@ -171,4 +180,12 @@ class OrderEvent extends ActionEvent
{
return $this->ref;
}
/**
* @return null|int
*/
public function getStatus()
{
return $this->status;
}
}

View File

@@ -301,9 +301,12 @@ final class TheliaEvents
const ORDER_AFTER_CREATE = "action.order.afterCreate";
const ORDER_BEFORE_PAYMENT = "action.order.beforePayment";
const ORDER_UPDATE_STATUS = "action.order.updateStatus";
const ORDER_PRODUCT_BEFORE_CREATE = "action.orderProduct.beforeCreate";
const ORDER_PRODUCT_AFTER_CREATE = "action.orderProduct.afterCreate";
/**
* Sent on image processing
*/

View File

@@ -57,7 +57,13 @@ class Order extends BaseLoop
),
'current'
),
Argument::createIntListTypeArgument('status'),
new Argument(
'status',
new TypeCollection(
new Type\IntListType(),
new Type\EnumType(array('*'))
)
),
new Argument(
'order',
new TypeCollection(
@@ -98,7 +104,7 @@ class Order extends BaseLoop
$status = $this->getStatus();
if (null !== $status) {
if (null !== $status && $status != '*') {
$search->filterByStatusId($status, Criteria::IN);
}

View File

@@ -0,0 +1,63 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Template\Smarty\Plugins;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
use Thelia\Core\Security\SecurityContext;
use Thelia\Core\Security\Exception\AuthenticationException;
use Thelia\Exception\OrderException;
use Thelia\Model\AddressQuery;
use Thelia\Model\ModuleQuery;
class Type extends AbstractSmartyPlugin
{
public function assertTypeModifier($value, $option)
{
$typeClass = "\\Thelia\\Type\\$option";
if(!class_exists($typeClass)) {
throw new \InvalidArgumentException(sprintf("Invalid type name `%s` in `assertType` modifier", $option));
}
$typeInstance = new $typeClass();
if(!$typeInstance->isValid($value)) {
return '';
}
return $value;
}
/**
* Define the various smarty plugins handled by this class
*
* @return an array of smarty plugin descriptors
*/
public function getPluginDescriptors()
{
return array(
new SmartyPluginDescriptor('modifier', 'assertType', $this, 'assertTypeModifier'),
);
}
}

View File

@@ -105,6 +105,10 @@ class SmartyParser extends Smarty implements ParserInterface
$this->template = $template_path_from_template_base;
$this->setTemplateDir(THELIA_TEMPLATE_DIR.$this->template);
$config_dir = THELIA_TEMPLATE_DIR.$this->template.'/configs';
$this->setConfigDir($config_dir);
}
public function getTemplate()

View File

@@ -5,11 +5,7 @@
{/block}
{* -- Define some stuff for Smarty ----------------------------------------- *}
{assign 'order-not-paid' 'warning'}
{assign 'order-paid' 'success'}
{assign 'order-processing' 'primary'}
{assign 'order-sent' 'info'}
{assign 'order-canceled' 'danger'}
{config_load file='variables.conf'}
<!DOCTYPE html>
<html lang="{$lang_code}">
@@ -118,21 +114,25 @@
{/loop}
{loop name="menu-auth-order" type="auth" roles="ADMIN" permissions="admin.orders.view"}
<li class="dropdown {if $admin_current_location == 'customer'}active{/if}" id="orders_menu">
<li class="dropdown {if $admin_current_location == 'order'}active{/if}" id="orders_menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">{intl l="Orders"} <span class="caret"></span></a>
<ul class="dropdown-menu config_menu" role="menu">
<li role="menuitem"><a data-target="{url path='admin/orders'}" href="{url path='admin/orders'}">
<li role="menuitem">
<a data-target="{url path='admin/orders'}" href="{url path='admin/orders'}">
{intl l="All orders"}
<span class="badge">{count type="order"}</span></a>
<span class="label label-default pull-right">{count type="order" customer="*" backend_context="1"}</span>
</a>
</li>
{loop name="order-status-list" type="order-status"}
{assign "orderStatusLabel" "order_$CODE"}
<li role="menuitem">
<a data-target="{url path='admin/orders/$LABEL'}" href="{url path='admin/orders/$LABEL'}">
{$LABEL} <span class="badge">{count type="order" status="{$ID}"}</span>
<a data-target="{url path='admin/orders/$LABEL'}" href="{url path="admin/orders" status=$ID}">
{$TITLE}
<span class="label label-{#$orderStatusLabel#} pull-right">{count type="order" customer="*" backend_context="1" status=$ID}</span>
</a>
</li>
{/loop}

View File

@@ -192,6 +192,11 @@
padding: 1em;
margin-bottom: 20px;
.select-fixed-width {
width: 120px;
}
// The block title
.title {
color: #5A6876;

View File

@@ -0,0 +1,9 @@
#order
max_displayed_orders = 20
#order status
order_not_paid = 'warning'
order_paid = 'success'
order_processing = 'primary'
order_sent = 'info'
order_canceled = 'danger'

View File

@@ -11,7 +11,7 @@
<ul class="breadcrumb">
<li><a href="{url path='/admin/home'}">{intl l="Home"}</a></li>
<li><a href="{url path='/admin/order'}">{intl l="Orders"}</a></li>
<li><a href="{url path='/admin/orders'}">{intl l="Orders"}</a></li>
</ul>
<div class="row">
@@ -27,14 +27,18 @@
{assign "orderCurrency" $SYMBOL}
{/loop}
{assign "orderStatusId" $STATUS}
<ul class="nav nav-tabs clearfix">
<li class="active"><a href="#cart" data-toggle="tab"><span class="glyphicon glyphicon-shopping-cart"></span> {intl l="Ordered products"}</a></li>
<li><a href="#bill" data-toggle="tab"><span class="glyphicon glyphicon-list-alt"></span> {intl l="Invoice and Delivery"}</a></li>
<li><a href="#supplements" data-toggle="tab"><span class="glyphicon glyphicon-info-sign"></span> {intl l="Further information"}</a></li>
<li class="pull-right">
<li class="pull-right select-fixed-width">
<select name="order-status" data-toggle="selectpicker">
<option data-content="<span class='label label-success'>Foo</span>">Foo</option>
<option data-content="<span class='label label-danger'>Bar</span>">Bar</option>
{loop type="order-status" name="all-status"}
{assign "orderStatusLabel" "order_$CODE"}
<option {if $ID == $orderStatusId}selected="selected" {/if} value="{$ID}" data-content="<span class='label label-{#$orderStatusLabel#}'>{$TITLE}</span>">{$TITLE}</option>
{/loop}
</select>
</li>
</ul>

View File

@@ -5,13 +5,15 @@
{block name="check-permissions"}admin.orders.view{/block}
{block name="main-content"}
{assign order_page {$smarty.get.page|default:1}}
{assign status_filter {$smarty.get.status|assertType:'IntListType'}}
<div class="orders">
<div id="wrapper" class="container">
<ul class="breadcrumb">
<li><a href="{url path='/admin/home'}">{intl l="Home"}</a></li>
<li><a href="{url path='/admin/orders'}">{intl l="Orders"}</a></li>
<li><a href="#">{intl l="Orders"}</a></li>
</ul>
{module_include location='orders_top'}
@@ -23,12 +25,10 @@
<table class="table table-striped table-condensed table-left-aligned">
<caption class="clearfix">
{intl l='Orders'}
{loop type="auth" name="can_create" roles="ADMIN" permissions="admin.orders.create"}
<a class="btn btn-default btn-primary pull-right" title="{intl l='Create an order'}" href="#creation_dialog">
<span class="glyphicon glyphicon-plus-sign"></span>
</a>
{/loop}
</caption>
{ifloop rel="order-list"}
<thead>
<tr>
<th>{intl l="Order n°"}</th>
@@ -46,7 +46,7 @@
<tbody>
{loop type="order" name="order-list" customer="*"}
{loop type="order" name="order-list" customer="*" backend_context="1" page={$order_page} limit={#max_displayed_orders#} status=$status_filter|default:'*'}
{loop type="order_address" name="order-invoice-address" id=$INVOICE_ADDRESS}
{assign "orderInvoiceFirstName" $FIRSTNAME}
@@ -56,48 +56,28 @@
{loop type="order-status" name="order-status" id=$STATUS}
{assign "orderStatus" $TITLE}
{if $CODE == 'not_paid'}
{assign "orderStatusLabel" "warning"}
{else}
{if $CODE == 'paid'}
{assign "orderStatusLabel" "success"}
{else}
{if $CODE == 'processing'}
{assign "orderStatusLabel" "primary"}
{else}
{if $CODE == 'sent'}
{assign "orderStatusLabel" "info"}
{else}
{if $CODE == 'canceled'}
{assign "orderStatusLabel" "danger"}
{else}
{/if}
{/if}
{/if}
{/if}
{/if}
{assign "orderStatusLabel" "order_$CODE"}
{/loop}
<tr>
<td><a href="{url path="/admin/order/update/$ID"}">01230450123045</a></td>
<td><a href="{url path="/admin/order/update/$ID"}">{$REF}</a></td>
<td>{format_date date=$CREATE_DATE}</td>
<td>{$orderInvoiceCompany}</td>
<td><a href="{url path="/admin/customer/update/$CUSTOMER"}">{$orderInvoiceFirstName|ucwords} {$orderInvoiceLastName|upper}</a></td>
<td>{$TOTAL_TAXED_AMOUNT}</td>
<td><span class="label label-{$order-processing}">{$orderStatus}</span></td>
<td><span class="label label-{#$orderStatusLabel#}">{$orderStatus}</span></td>
{module_include location='orders_table_row'}
<td>
<div class="btn-group">
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.orders.edit"}
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.orders.update"}
<a class="btn btn-default btn-xs" title="{intl l='Edit this order'}" href="{url path="/admin/order/update/$ID"}"><span class="glyphicon glyphicon-edit"></span></a>
{/loop}
{loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.orders.delete"}
<a class="btn btn-default btn-xs" title="{intl l='Delete this order'}" href="#delete_order_dialog" data-id="{$ID}" data-toggle="modal"><span class="glyphicon glyphicon-trash"></span></a>
{if $STATUS !== 5}
<a class="btn btn-default btn-xs order-cancel" title="{intl l='Cancel this order'}" href="#cancel_order_dialog" data-id="{$ID}" data-toggle="modal"><span class="glyphicon glyphicon-remove-sign"></span></a>
{/if}
{/loop}
</div>
</td>
@@ -105,15 +85,43 @@
{/loop}
<!-- <tr>
<td colspan="3">
<div class="alert alert-info">
{intl l="No mailing template has been created yet. Click the + button to create one."}
</div>
</td>
</tr> -->
</tbody>
<tfoot>
<tr>
<td colspan="7">
<div class="text-center">
<ul class="pagination pagination-centered">
{if $order_page != 1}
<li><a href="{url path="/admin/orders" page="1"}">&laquo;</a></li>
{else}
<li class="disabled"><a href="#">&laquo;</a></li>
{/if}
{pageloop rel="order-list"}
{if $PAGE != $CURRENT}
<li><a href="{url path="/admin/orders" page=$PAGE}">{$PAGE}</a></li>
{else}
<li class="active"><a href="#">{$PAGE}</a></li>
{/if}
{/pageloop}
{if $PAGE == $LAST && $LAST != $CURRENT}
<li><a href="{url path="/admin/orders" page="$PAGE"}">&raquo;</a></li>
{else}
<li class="disabled"><a href="#">&raquo;</a></li>
{/if}
</ul>
</div>
</td>
</tr>
</tfoot>
{/ifloop}
</table>
</div>
</div>
@@ -125,22 +133,34 @@
</div>
</div>
{* Delete order confirmation dialog *}
{* Cancel order confirmation dialog *}
{capture "delete_order_dialog"}
<input type="hidden" name="current_order_id" value="{$current_order_id}" />
<input type="hidden" name="order_id" id="delete_order_id" value"" />
{capture "cancel_order_dialog"}
<input type="hidden" name="order_page" value="{$order_page}">
<input type="hidden" name="order_id" id="cancel_order_id" />
<input type="hidden" name="status_id" value="5" />
{/capture}
{include
file = "includes/generic-confirm-dialog.html"
dialog_id = "delete_order_dialog"
dialog_id = "cancel_order_dialog"
dialog_title = {intl l="Delete an order"}
dialog_message = {intl l="Do you really want to delete this order ?"}
dialog_message = {intl l="Do you really want to cancel this order ?"}
form_action = {url path='/admin/orders/delete'}
form_content = {$smarty.capture.delete_order_dialog nofilter}
form_action = {url path='/admin/order/update/status'}
form_content = {$smarty.capture.cancel_order_dialog nofilter}
form_id = "cancel-order-form"
}
{/block}
{block name="javascript-initialization"}
<script type="text/javascript">
$(".order-cancel").click(function(){
$("#cancel_order_id").val($(this).attr("data-id"));
});
</script>
{/block}