order delivery form

This commit is contained in:
Etienne Roudeix
2013-09-16 18:55:29 +02:00
parent bf3bc02f8b
commit afa9a46abf
9 changed files with 307 additions and 19 deletions

View File

@@ -58,6 +58,8 @@
<form name="thelia.cart.add" class="Thelia\Form\CartAdd"/>
<form name="thelia.order.delivery" class="Thelia\Form\OrderDelivery"/>
<form name="thelia.admin.config.creation" class="Thelia\Form\ConfigCreationForm"/>
<form name="thelia.admin.config.modification" class="Thelia\Form\ConfigModificationForm"/>

View File

@@ -98,11 +98,6 @@
<default key="_view">cart</default>
</route>
<route id="cart.billing" path="/cart/billing">
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
<default key="_view">cart_billing</default>
</route>
<route id="cart.add.process" path="/cart/add">
<default key="_controller">Thelia\Controller\Front\CartController::addItem</default>
</route>
@@ -117,6 +112,16 @@
<default key="_view">cart</default>
</route>
<route id="cart.billing" path="/order/billing">
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
<default key="_view">cart_billing</default>
</route>
<route id="cart.update.quantity" path="/order/deliver">
<default key="_controller">Thelia\Controller\Front\OrderController::deliver</default>
<default key="_view">cart_billing</default>
</route>
<!-- end cart routes -->
<!-- order management process -->

View File

@@ -0,0 +1,79 @@
<?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\Controller\Front;
use Propel\Runtime\Exception\PropelException;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Core\Event\OrderEvent;
use Thelia\Core\Event\TheliaEvents;
use Symfony\Component\HttpFoundation\Request;
use Thelia\Model\Order;
class OrderController extends BaseFrontController
{
/**
* set billing address
* set delivery address
* set delivery module
*/
public function deliver()
{
$orderEvent = $this->getOrderEvent();
//$orderEvent->setBillingAddress($this->getRequest()->get("billing-address"));
$orderEvent->setDeliveryAddress($this->getRequest()->get("delivery-address"));
$orderEvent->setDeliveryModule($this->getRequest()->get("delivery-module"));
try {
//$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_BILLING_ADDRESS, $orderEvent);
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_ADDRESS, $orderEvent);
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_MODULE, $orderEvent);
$this->redirectSuccess();
} catch (PropelException $e) {
$this->getParserContext()->setGeneralError($e->getMessage());
}
}
protected function getOrderEvent()
{
$order = $this->getOrder($this->getRequest());
return new OrderEvent($order);
}
public function getOrder(Request $request)
{
$session = $request->getSession();
if (null !== $order = $session->getOrder()) {
return $order;
}
$order = new Order();
$session->setOrder($order);
return $order;
}
}

View File

@@ -0,0 +1,101 @@
<?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\Event;
use Thelia\Model\Address;
use Thelia\Model\AddressQuery;
use Thelia\Model\Module;
use Thelia\Model\Order;
class OrderEvent extends ActionEvent
{
protected $order = null;
protected $billingAddress = null;
protected $deliveryAddress = null;
protected $deliveryModule = null;
/**
* @param Order $order
*/
public function __construct(Order $order)
{
$this->order = $order;
}
/**
* @param Address $address
*/
public function setBillingAddress(Address $address)
{
$this->deliveryAddress = $address->getId();
}
/**
* @param Address $address
*/
public function setDeliveryAddress(Address $address)
{
$this->deliveryAddress = $address->getId();
}
/**
* @param Module $module
*/
public function setDeliveryModule(Module $module)
{
$this->deliveryModule = $module->getId();
}
/**
* @return null|Order
*/
public function getOrder()
{
return $this->order;
}
/**
* @return array|mixed|Address
*/
public function getBillingAddress()
{
return AddressQuery::create()->findPk($this->billingAddress);
}
/**
* @return array|mixed|Address
*/
public function getDeliveryAddress()
{
return AddressQuery::create()->findPk($this->deliveryAddress);
}
/**
* @return array|mixed|Address
*/
public function getDeliveryModule()
{
return AddressQuery::create()->findPk($this->deliveryModule);
}
}

View File

@@ -218,13 +218,20 @@ final class TheliaEvents
const CART_DELETEITEM = "action.deleteArticle";
/**
* Order linked event
*/
const ORDER_SET_BILLING_ADDRESS = "action.order.setBillingAddress";
const ORDER_SET_DELIVERY_ADDRESS = "action.order.setDeliveryAddress";
const ORDER_SET_DELIVERY_MODULE = "action.order.setDeliveryModule";
/**
* Sent on image processing
*/
const IMAGE_PROCESS = "action.processImage";
/**
* Sent on cimage cache clear request
* Sent on image cache clear request
*/
const IMAGE_CLEAR_CACHE = "action.clearImageCache";

View File

@@ -29,6 +29,7 @@ use Thelia\Exception\InvalidCartException;
use Thelia\Model\CartQuery;
use Thelia\Model\Cart;
use Thelia\Model\Currency;
use Thelia\Model\Order;
use Thelia\Tools\URL;
use Thelia\Model\Lang;
@@ -43,6 +44,8 @@ use Thelia\Model\Lang;
class Session extends BaseSession
{
/**
* @param bool $forceDefault
*
* @return \Thelia\Model\Lang|null
*/
public function getLang($forceDefault = true)
@@ -205,22 +208,19 @@ class Session extends BaseSession
return $this;
}
/**
* assign delivery id in session
*
* @param $delivery_id
* @return $this
*/
public function setDelivery($delivery_id)
// -- Order ------------------------------------------------------------------
public function setOrder(Order $order)
{
$this->set("thelia.delivery_id", $delivery_id);
$this->set("thelia.order", $order);
return $this;
}
public function getDelivery()
public function getOrder()
{
return $this->get("thelia.delivery_id");
return $this->get("thelia.order");
}

View File

@@ -0,0 +1,94 @@
<?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\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Model\AddressQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Core\Translation\Translator;
use Thelia\Model\ModuleQuery;
use Thelia\Module\BaseModule;
/**
* Class OrderDelivery
* @package Thelia\Form
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*/
class OrderDelivery extends BaseForm
{
protected function buildForm()
{
$this->formBuilder
->add("delivery-address", "integer", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Callback(array(
"methods" => array(
array($this, "verifyDeliveryAddress")
)
))
)
))
->add("delivery-module", "integer", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Callback(array(
"methods" => array(
array($this, "verifyDeliveryModule")
)
))
)
));
}
public function verifyDeliveryAddress($value, ExecutionContextInterface $context)
{
$address = AddressQuery::create()
->findPk($value);
if(null === $address) {
$context->addViolation("Address ID not found");
} elseif($address->getCustomerId() !== $this->request->getSession()->getCustomerUser()->getId()) {
$context->addViolation("Address does not belong to you");
}
}
public function verifyDeliveryModule($value, ExecutionContextInterface $context)
{
$module = ModuleQuery::create()
->filterByType(BaseModule::DELIVERY_MODULE_TYPE)
->filterByActivate(1)
->filterById($value)
->find();
if(null === $module) {
$context->addViolation("Delivery module ID not found");
}
}
public function getName()
{
return "thelia_order_delivery";
}
}

View File

@@ -133,7 +133,7 @@
</table>
<a href="{navigate to="index"}" role="button" class="btn btn-continue-shopping"><span>Continue Shopping</span></a>
<a href="{url path="/cart/billing"}" class="btn btn-checkout">Proceed checkout</a>
<a href="{url path="/order/billing"}" class="btn btn-checkout">Proceed checkout</a>
</article>

View File

@@ -24,7 +24,7 @@
<a href="cart-step4.php" role="button" class="btn btn-step disabled"><span class="step-nb">4</span> <span class="step-label">Secure payment</span></a>
</div>
<form id="form-cart-delivery" action="cart-step3.php" method="post" role="form">
<form id="form-cart-delivery" action="{url path="/order/deliver"}" method="post" role="form">
<div id="billing-address" class="panel">
<div class="panel-heading clearfix">
@@ -164,7 +164,7 @@
{loop type="delivery" name="deliveries" force_return="true"}
<div class="radio">
<label for="delivery-method_1">
<input type="radio" name="delivery-method" id="delivery-method_1" value="1">
<input type="radio" name="delivery-module" value="{$ID}">
<strong>{$TITLE}</strong> / {currency attr="symbol"} {$PRICE}
</label>
</div>