postage + invoice step
This commit is contained in:
@@ -61,9 +61,8 @@ class Order extends BaseAction implements EventSubscriberInterface
|
|||||||
{
|
{
|
||||||
$order = $event->getOrder();
|
$order = $event->getOrder();
|
||||||
|
|
||||||
$deliveryAddress = $event->getDeliveryAddress();
|
|
||||||
|
|
||||||
$order->setDeliveryModuleId($event->getDeliveryModule());
|
$order->setDeliveryModuleId($event->getDeliveryModule());
|
||||||
|
$order->setPostage($event->getPostage());
|
||||||
|
|
||||||
$event->setOrder($order);
|
$event->setOrder($order);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,7 @@
|
|||||||
<form name="thelia.cart.add" class="Thelia\Form\CartAdd"/>
|
<form name="thelia.cart.add" class="Thelia\Form\CartAdd"/>
|
||||||
|
|
||||||
<form name="thelia.order.delivery" class="Thelia\Form\OrderDelivery"/>
|
<form name="thelia.order.delivery" class="Thelia\Form\OrderDelivery"/>
|
||||||
|
<form name="thelia.order.payment" class="Thelia\Form\OrderPayment"/>
|
||||||
|
|
||||||
<form name="thelia.admin.config.creation" class="Thelia\Form\ConfigCreationForm"/>
|
<form name="thelia.admin.config.creation" class="Thelia\Form\ConfigCreationForm"/>
|
||||||
<form name="thelia.admin.config.modification" class="Thelia\Form\ConfigModificationForm"/>
|
<form name="thelia.admin.config.modification" class="Thelia\Form\ConfigModificationForm"/>
|
||||||
|
|||||||
@@ -122,6 +122,11 @@
|
|||||||
<default key="_view">order_delivery</default>
|
<default key="_view">order_delivery</default>
|
||||||
</route>
|
</route>
|
||||||
|
|
||||||
|
<route id="order.invoice.process" path="/order/invoice" methods="post">
|
||||||
|
<default key="_controller">Thelia\Controller\Front\OrderController::pay</default>
|
||||||
|
<default key="_view">order_invoice</default>
|
||||||
|
</route>
|
||||||
|
|
||||||
<route id="order.invoice" path="/order/invoice">
|
<route id="order.invoice" path="/order/invoice">
|
||||||
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
|
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
|
||||||
<default key="_view">order_invoice</default>
|
<default key="_view">order_invoice</default>
|
||||||
|
|||||||
@@ -65,4 +65,14 @@ class BaseFrontController extends BaseController
|
|||||||
$this->redirectToRoute("cart.view");
|
$this->redirectToRoute("cart.view");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function checkValidDelivery()
|
||||||
|
{
|
||||||
|
$order = $this->getSession()->getOrder();
|
||||||
|
if(null === $order || null === $order->chosenDeliveryAddress || null === $order->getDeliveryModuleId()) {
|
||||||
|
$this->redirectToRoute("order.delivery");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,9 +28,12 @@ use Thelia\Core\Event\OrderEvent;
|
|||||||
use Thelia\Core\Event\TheliaEvents;
|
use Thelia\Core\Event\TheliaEvents;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Thelia\Form\OrderDelivery;
|
use Thelia\Form\OrderDelivery;
|
||||||
|
use Thelia\Form\OrderPayment;
|
||||||
use Thelia\Log\Tlog;
|
use Thelia\Log\Tlog;
|
||||||
use Thelia\Model\AddressQuery;
|
use Thelia\Model\AddressQuery;
|
||||||
use Thelia\Model\AreaDeliveryModuleQuery;
|
use Thelia\Model\AreaDeliveryModuleQuery;
|
||||||
|
use Thelia\Model\CountryQuery;
|
||||||
|
use Thelia\Model\ModuleQuery;
|
||||||
use Thelia\Model\Order;
|
use Thelia\Model\Order;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,7 +44,6 @@ use Thelia\Model\Order;
|
|||||||
class OrderController extends BaseFrontController
|
class OrderController extends BaseFrontController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* set billing address
|
|
||||||
* set delivery address
|
* set delivery address
|
||||||
* set delivery module
|
* set delivery module
|
||||||
*/
|
*/
|
||||||
@@ -59,14 +61,16 @@ class OrderController extends BaseFrontController
|
|||||||
|
|
||||||
$deliveryAddressId = $form->get("delivery-address")->getData();
|
$deliveryAddressId = $form->get("delivery-address")->getData();
|
||||||
$deliveryModuleId = $form->get("delivery-module")->getData();
|
$deliveryModuleId = $form->get("delivery-module")->getData();
|
||||||
|
$deliveryAddress = AddressQuery::create()->findPk($deliveryAddressId);
|
||||||
|
$deliveryModule = ModuleQuery::create()->findPk($deliveryModuleId);
|
||||||
|
|
||||||
/* check that the delivery address belong to the current customer */
|
/* check that the delivery address belongs to the current customer */
|
||||||
$deliveryAddress = AddressQuery::create()->findPk($deliveryAddressId);
|
$deliveryAddress = AddressQuery::create()->findPk($deliveryAddressId);
|
||||||
if($deliveryAddress->getCustomerId() !== $this->getSecurityContext()->getCustomerUser()->getId()) {
|
if($deliveryAddress->getCustomerId() !== $this->getSecurityContext()->getCustomerUser()->getId()) {
|
||||||
throw new \Exception("Address does not belong to the current customer");
|
throw new \Exception("Delivery address does not belong to the current customer");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check that the delivery module fetch the delivery address area */
|
/* check that the delivery module fetches the delivery address area */
|
||||||
if(AreaDeliveryModuleQuery::create()
|
if(AreaDeliveryModuleQuery::create()
|
||||||
->filterByAreaId($deliveryAddress->getCountry()->getAreaId())
|
->filterByAreaId($deliveryAddress->getCountry()->getAreaId())
|
||||||
->filterByDeliveryModuleId($deliveryModuleId)
|
->filterByDeliveryModuleId($deliveryModuleId)
|
||||||
@@ -74,10 +78,18 @@ class OrderController extends BaseFrontController
|
|||||||
throw new \Exception("Delivery module cannot be use with selected delivery address");
|
throw new \Exception("Delivery module cannot be use with selected delivery address");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* try to get postage amount */
|
||||||
|
$moduleReflection = new \ReflectionClass($deliveryModule->getFullNamespace());
|
||||||
|
if ($moduleReflection->isSubclassOf("Thelia\Module\DeliveryModuleInterface") === false) {
|
||||||
|
throw new \RuntimeException(sprintf("delivery module %s is not a Thelia\Module\DeliveryModuleInterface", $deliveryModule->getCode()));
|
||||||
|
}
|
||||||
|
$moduleInstance = $moduleReflection->newInstance();
|
||||||
|
$postage = $moduleInstance->getPostage($deliveryAddress->getCountry());
|
||||||
|
|
||||||
$orderEvent = $this->getOrderEvent();
|
$orderEvent = $this->getOrderEvent();
|
||||||
$orderEvent->setDeliveryAddress($deliveryAddressId);
|
$orderEvent->setDeliveryAddress($deliveryAddressId);
|
||||||
$orderEvent->setDeliveryModule($deliveryModuleId);
|
$orderEvent->setDeliveryModule($deliveryModuleId);
|
||||||
|
$orderEvent->setPostage($postage);
|
||||||
|
|
||||||
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_ADDRESS, $orderEvent);
|
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_ADDRESS, $orderEvent);
|
||||||
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_MODULE, $orderEvent);
|
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_MODULE, $orderEvent);
|
||||||
@@ -105,6 +117,62 @@ class OrderController extends BaseFrontController
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set invoice address
|
||||||
|
* set payment module
|
||||||
|
*/
|
||||||
|
public function pay()
|
||||||
|
{
|
||||||
|
$this->checkAuth();
|
||||||
|
$this->checkCartNotEmpty();
|
||||||
|
$this->checkValidDelivery();
|
||||||
|
|
||||||
|
$message = false;
|
||||||
|
|
||||||
|
$orderPayment = new OrderPayment($this->getRequest());
|
||||||
|
|
||||||
|
try {
|
||||||
|
$form = $this->validateForm($orderPayment, "post");
|
||||||
|
|
||||||
|
$deliveryAddressId = $form->get("delivery-address")->getData();
|
||||||
|
$deliveryModuleId = $form->get("delivery-module")->getData();
|
||||||
|
|
||||||
|
/* check that the invoice address belongs to the current customer */
|
||||||
|
$deliveryAddress = AddressQuery::create()->findPk($deliveryAddressId);
|
||||||
|
if($deliveryAddress->getCustomerId() !== $this->getSecurityContext()->getCustomerUser()->getId()) {
|
||||||
|
throw new \Exception("Invoice address does not belong to the current customer");
|
||||||
|
}
|
||||||
|
|
||||||
|
$orderEvent = $this->getOrderEvent();
|
||||||
|
$orderEvent->setInvoiceAddress($deliveryAddressId);
|
||||||
|
$orderEvent->setPaymentModule($deliveryModuleId);
|
||||||
|
|
||||||
|
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_ADDRESS, $orderEvent);
|
||||||
|
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_MODULE, $orderEvent);
|
||||||
|
|
||||||
|
$this->redirectToRoute("order.invoice");
|
||||||
|
|
||||||
|
} catch (FormValidationException $e) {
|
||||||
|
$message = sprintf("Please check your input: %s", $e->getMessage());
|
||||||
|
} catch (PropelException $e) {
|
||||||
|
$this->getParserContext()->setGeneralError($e->getMessage());
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$message = sprintf("Sorry, an error occured: %s", $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($message !== false) {
|
||||||
|
Tlog::getInstance()->error(sprintf("Error during order delivery process : %s. Exception was %s", $message, $e->getMessage()));
|
||||||
|
|
||||||
|
$orderPayment->setErrorMessage($message);
|
||||||
|
|
||||||
|
$this->getParserContext()
|
||||||
|
->addForm($orderPayment)
|
||||||
|
->setGeneralError($message)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected function getOrderEvent()
|
protected function getOrderEvent()
|
||||||
{
|
{
|
||||||
$order = $this->getOrder($this->getRequest());
|
$order = $this->getOrder($this->getRequest());
|
||||||
|
|||||||
@@ -23,17 +23,16 @@
|
|||||||
|
|
||||||
namespace Thelia\Core\Event;
|
namespace Thelia\Core\Event;
|
||||||
|
|
||||||
use Thelia\Model\Address;
|
|
||||||
use Thelia\Model\AddressQuery;
|
|
||||||
use Thelia\Model\Module;
|
|
||||||
use Thelia\Model\Order;
|
use Thelia\Model\Order;
|
||||||
|
|
||||||
class OrderEvent extends ActionEvent
|
class OrderEvent extends ActionEvent
|
||||||
{
|
{
|
||||||
protected $order = null;
|
protected $order = null;
|
||||||
protected $billingAddress = null;
|
protected $invoiceAddress = null;
|
||||||
protected $deliveryAddress = null;
|
protected $deliveryAddress = null;
|
||||||
protected $deliveryModule = null;
|
protected $deliveryModule = null;
|
||||||
|
protected $paymentModule = null;
|
||||||
|
protected $postage = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Order $order
|
* @param Order $order
|
||||||
@@ -54,7 +53,7 @@ class OrderEvent extends ActionEvent
|
|||||||
/**
|
/**
|
||||||
* @param $address
|
* @param $address
|
||||||
*/
|
*/
|
||||||
public function setBillingAddress($address)
|
public function setInvoiceAddress($address)
|
||||||
{
|
{
|
||||||
$this->deliveryAddress = $address;
|
$this->deliveryAddress = $address;
|
||||||
}
|
}
|
||||||
@@ -75,6 +74,22 @@ class OrderEvent extends ActionEvent
|
|||||||
$this->deliveryModule = $module;
|
$this->deliveryModule = $module;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $module
|
||||||
|
*/
|
||||||
|
public function setPaymentModule($module)
|
||||||
|
{
|
||||||
|
$this->paymentModule = $module;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $postage
|
||||||
|
*/
|
||||||
|
public function setPostage($postage)
|
||||||
|
{
|
||||||
|
$this->postage = $postage;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return null|Order
|
* @return null|Order
|
||||||
*/
|
*/
|
||||||
@@ -84,15 +99,15 @@ class OrderEvent extends ActionEvent
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array|mixed|Address
|
* @return null|int
|
||||||
*/
|
*/
|
||||||
public function getBillingAddress()
|
public function getInvoiceAddress()
|
||||||
{
|
{
|
||||||
return $this->billingAddress;
|
return $this->invoiceAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array|mixed|Address
|
* @return null|int
|
||||||
*/
|
*/
|
||||||
public function getDeliveryAddress()
|
public function getDeliveryAddress()
|
||||||
{
|
{
|
||||||
@@ -100,10 +115,26 @@ class OrderEvent extends ActionEvent
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array|mixed|Address
|
* @return null|int
|
||||||
*/
|
*/
|
||||||
public function getDeliveryModule()
|
public function getDeliveryModule()
|
||||||
{
|
{
|
||||||
return $this->deliveryModule;
|
return $this->deliveryModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return null|int
|
||||||
|
*/
|
||||||
|
public function getPaymentModule()
|
||||||
|
{
|
||||||
|
return $this->paymentModule;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return null|int
|
||||||
|
*/
|
||||||
|
public function getPostage()
|
||||||
|
{
|
||||||
|
return $this->postage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,13 @@ class Address extends BaseLoop
|
|||||||
protected function getArgDefinitions()
|
protected function getArgDefinitions()
|
||||||
{
|
{
|
||||||
return new ArgumentCollection(
|
return new ArgumentCollection(
|
||||||
Argument::createIntListTypeArgument('id'),
|
new Argument(
|
||||||
|
'id',
|
||||||
|
new TypeCollection(
|
||||||
|
new Type\IntListType(),
|
||||||
|
new Type\EnumType(array('*', 'any'))
|
||||||
|
)
|
||||||
|
),
|
||||||
new Argument(
|
new Argument(
|
||||||
'customer',
|
'customer',
|
||||||
new TypeCollection(
|
new TypeCollection(
|
||||||
@@ -63,8 +69,14 @@ class Address extends BaseLoop
|
|||||||
),
|
),
|
||||||
'current'
|
'current'
|
||||||
),
|
),
|
||||||
Argument::createBooleanTypeArgument('default'),
|
Argument::createBooleanOrBothTypeArgument('default'),
|
||||||
Argument::createIntListTypeArgument('exclude')
|
new Argument(
|
||||||
|
'exclude',
|
||||||
|
new TypeCollection(
|
||||||
|
new Type\IntListType(),
|
||||||
|
new Type\EnumType(array('none'))
|
||||||
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +91,7 @@ class Address extends BaseLoop
|
|||||||
|
|
||||||
$id = $this->getId();
|
$id = $this->getId();
|
||||||
|
|
||||||
if (null !== $id) {
|
if (null !== $id && !in_array($id, array('*', 'any'))) {
|
||||||
$search->filterById($id, Criteria::IN);
|
$search->filterById($id, Criteria::IN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +118,7 @@ class Address extends BaseLoop
|
|||||||
|
|
||||||
$exclude = $this->getExclude();
|
$exclude = $this->getExclude();
|
||||||
|
|
||||||
if (!is_null($exclude)) {
|
if (null !== $exclude && 'none' !== $exclude) {
|
||||||
$search->filterById($exclude, Criteria::NOT_IN);
|
$search->filterById($exclude, Criteria::NOT_IN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
|||||||
use Thelia\Model\ModuleQuery;
|
use Thelia\Model\ModuleQuery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Delivery
|
|
||||||
* @package Thelia\Core\Template\Loop
|
* @package Thelia\Core\Template\Loop
|
||||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||||
*/
|
*/
|
||||||
@@ -93,6 +92,8 @@ class BaseSpecificModule extends BaseI18nLoop
|
|||||||
{
|
{
|
||||||
$search = ModuleQuery::create();
|
$search = ModuleQuery::create();
|
||||||
|
|
||||||
|
$search->filterByActivate(1);
|
||||||
|
|
||||||
if (null !== $id = $this->getId()) {
|
if (null !== $id = $this->getId()) {
|
||||||
$search->filterById($id);
|
$search->filterById($id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class Country extends BaseI18nLoop
|
|||||||
|
|
||||||
if (true === $withArea) {
|
if (true === $withArea) {
|
||||||
$search->filterByAreaId(null, Criteria::ISNOTNULL);
|
$search->filterByAreaId(null, Criteria::ISNOTNULL);
|
||||||
} elseif (false == $withArea) {
|
} elseif (false === $withArea) {
|
||||||
$search->filterByAreaId(null, Criteria::ISNULL);
|
$search->filterByAreaId(null, Criteria::ISNULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ class Delivery extends BaseSpecificModule
|
|||||||
->set('CHAPO', $deliveryModule->getVirtualColumn('i18n_CHAPO'))
|
->set('CHAPO', $deliveryModule->getVirtualColumn('i18n_CHAPO'))
|
||||||
->set('DESCRIPTION', $deliveryModule->getVirtualColumn('i18n_DESCRIPTION'))
|
->set('DESCRIPTION', $deliveryModule->getVirtualColumn('i18n_DESCRIPTION'))
|
||||||
->set('POSTSCRIPTUM', $deliveryModule->getVirtualColumn('i18n_POSTSCRIPTUM'))
|
->set('POSTSCRIPTUM', $deliveryModule->getVirtualColumn('i18n_POSTSCRIPTUM'))
|
||||||
->set('PRICE', $moduleInstance->calculate($country))
|
->set('POSTAGE', $moduleInstance->getPostage($country))
|
||||||
;
|
;
|
||||||
|
|
||||||
$loopResult->addRow($loopResultRow);
|
$loopResult->addRow($loopResultRow);
|
||||||
|
|||||||
84
core/lib/Thelia/Core/Template/Loop/Payment.php
Normal file
84
core/lib/Thelia/Core/Template/Loop/Payment.php
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
<?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\Loop;
|
||||||
|
use Propel\Runtime\ActiveQuery\Criteria;
|
||||||
|
use Thelia\Core\Template\Element\LoopResult;
|
||||||
|
use Thelia\Core\Template\Element\LoopResultRow;
|
||||||
|
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||||
|
use Thelia\Module\BaseModule;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Payment
|
||||||
|
* @package Thelia\Core\Template\Loop
|
||||||
|
* @author Etienne Roudeix <eroudeix@gmail.com>
|
||||||
|
*/
|
||||||
|
class Payment extends BaseSpecificModule
|
||||||
|
{
|
||||||
|
|
||||||
|
public function getArgDefinitions()
|
||||||
|
{
|
||||||
|
$collection = parent::getArgDefinitions();
|
||||||
|
|
||||||
|
return $collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function exec(&$pagination)
|
||||||
|
{
|
||||||
|
$search = parent::exec($pagination);
|
||||||
|
/* manage translations */
|
||||||
|
$locale = $this->configureI18nProcessing($search);
|
||||||
|
|
||||||
|
$search->filterByType(BaseModule::PAYMENT_MODULE_TYPE, Criteria::EQUAL);
|
||||||
|
|
||||||
|
/* perform search */
|
||||||
|
$paymentModules = $this->search($search, $pagination);
|
||||||
|
|
||||||
|
$loopResult = new LoopResult($paymentModules);
|
||||||
|
|
||||||
|
foreach ($paymentModules as $paymentModule) {
|
||||||
|
$loopResultRow = new LoopResultRow($loopResult, $paymentModule, $this->versionable, $this->timestampable, $this->countable);
|
||||||
|
|
||||||
|
$moduleReflection = new \ReflectionClass($paymentModule->getFullNamespace());
|
||||||
|
if ($moduleReflection->isSubclassOf("Thelia\Module\PaymentModuleInterface") === false) {
|
||||||
|
throw new \RuntimeException(sprintf("payment module %s is not a Thelia\Module\PaymentModuleInterface", $paymentModule->getCode()));
|
||||||
|
}
|
||||||
|
$moduleInstance = $moduleReflection->newInstance();
|
||||||
|
|
||||||
|
$moduleInstance->setRequest($this->request);
|
||||||
|
$moduleInstance->setDispatcher($this->dispatcher);
|
||||||
|
|
||||||
|
$loopResultRow
|
||||||
|
->set('ID', $paymentModule->getId())
|
||||||
|
->set('TITLE', $paymentModule->getVirtualColumn('i18n_TITLE'))
|
||||||
|
->set('CHAPO', $paymentModule->getVirtualColumn('i18n_CHAPO'))
|
||||||
|
->set('DESCRIPTION', $paymentModule->getVirtualColumn('i18n_DESCRIPTION'))
|
||||||
|
->set('POSTSCRIPTUM', $paymentModule->getVirtualColumn('i18n_POSTSCRIPTUM'))
|
||||||
|
;
|
||||||
|
|
||||||
|
$loopResult->addRow($loopResultRow);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $loopResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -188,7 +188,16 @@ class DataAccessFunctions extends AbstractSmartyPlugin
|
|||||||
|
|
||||||
public function orderDataAccess($params, &$smarty)
|
public function orderDataAccess($params, &$smarty)
|
||||||
{
|
{
|
||||||
return $this->dataAccess("Order", $params, $this->request->getSession()->getOrder());
|
$order = $this->request->getSession()->getOrder();
|
||||||
|
$attribute = $this->getNormalizedParam($params, array('attribute', 'attrib', 'attr'));
|
||||||
|
switch($attribute) {
|
||||||
|
case 'postage':
|
||||||
|
return $order->getPostage();
|
||||||
|
case 'delivery_address':
|
||||||
|
return $order->chosenDeliveryAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new \InvalidArgumentException(sprintf("%s has no '%s' attribute", 'Order', $attribute));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -196,6 +205,8 @@ class DataAccessFunctions extends AbstractSmartyPlugin
|
|||||||
*
|
*
|
||||||
* @param $params
|
* @param $params
|
||||||
* @param $smarty
|
* @param $smarty
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function langDataAccess($params, $smarty)
|
public function langDataAccess($params, $smarty)
|
||||||
{
|
{
|
||||||
@@ -294,6 +305,7 @@ class DataAccessFunctions extends AbstractSmartyPlugin
|
|||||||
*/
|
*/
|
||||||
public function getPluginDescriptors()
|
public function getPluginDescriptors()
|
||||||
{
|
{
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
new SmartyPluginDescriptor('function', 'admin', $this, 'adminDataAccess'),
|
new SmartyPluginDescriptor('function', 'admin', $this, 'adminDataAccess'),
|
||||||
new SmartyPluginDescriptor('function', 'customer', $this, 'customerDataAccess'),
|
new SmartyPluginDescriptor('function', 'customer', $this, 'customerDataAccess'),
|
||||||
|
|||||||
94
core/lib/Thelia/Form/OrderPayment.php
Executable file
94
core/lib/Thelia/Form/OrderPayment.php
Executable 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 OrderPayment
|
||||||
|
* @package Thelia\Form
|
||||||
|
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||||
|
*/
|
||||||
|
class OrderPayment extends BaseForm
|
||||||
|
{
|
||||||
|
protected function buildForm()
|
||||||
|
{
|
||||||
|
$this->formBuilder
|
||||||
|
->add("invoice-address", "integer", array(
|
||||||
|
"required" => true,
|
||||||
|
"constraints" => array(
|
||||||
|
new Constraints\NotBlank(),
|
||||||
|
new Constraints\Callback(array(
|
||||||
|
"methods" => array(
|
||||||
|
array($this, "verifyInvoiceAddress")
|
||||||
|
)
|
||||||
|
))
|
||||||
|
)
|
||||||
|
))
|
||||||
|
->add("payment-module", "integer", array(
|
||||||
|
"required" => true,
|
||||||
|
"constraints" => array(
|
||||||
|
new Constraints\NotBlank(),
|
||||||
|
new Constraints\Callback(array(
|
||||||
|
"methods" => array(
|
||||||
|
array($this, "verifyPaymentModule")
|
||||||
|
)
|
||||||
|
))
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function verifyInvoiceAddress($value, ExecutionContextInterface $context)
|
||||||
|
{
|
||||||
|
$address = AddressQuery::create()
|
||||||
|
->findPk($value);
|
||||||
|
|
||||||
|
if(null === $address) {
|
||||||
|
$context->addViolation("Address ID not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function verifyPaymentModule($value, ExecutionContextInterface $context)
|
||||||
|
{
|
||||||
|
$module = ModuleQuery::create()
|
||||||
|
->filterByType(BaseModule::PAYMENT_MODULE_TYPE)
|
||||||
|
->filterByActivate(1)
|
||||||
|
->filterById($value)
|
||||||
|
->find();
|
||||||
|
|
||||||
|
if(null === $module) {
|
||||||
|
$context->addViolation("Payment module ID not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return "thelia_order_payment";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ use Thelia\Model\Base\Order as BaseOrder;
|
|||||||
class Order extends BaseOrder
|
class Order extends BaseOrder
|
||||||
{
|
{
|
||||||
public $chosenDeliveryAddress = null;
|
public $chosenDeliveryAddress = null;
|
||||||
public $chosenInvoiceModule = null;
|
public $chosenInvoiceAddress = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* calculate the total amount
|
* calculate the total amount
|
||||||
|
|||||||
@@ -34,5 +34,5 @@ interface DeliveryModuleInterface extends BaseModuleInterface
|
|||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function calculate(Country $country);
|
public function getPostage(Country $country);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class Colissimo extends BaseModule implements DeliveryModuleInterface
|
|||||||
* @param Country $country
|
* @param Country $country
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function calculate(Country $country)
|
public function getPostage(Country $country)
|
||||||
{
|
{
|
||||||
// TODO: Implement calculate() method.
|
// TODO: Implement calculate() method.
|
||||||
return 2;
|
return 2;
|
||||||
|
|||||||
@@ -128,7 +128,7 @@
|
|||||||
{form_field form=$form field='delivery-module'}
|
{form_field form=$form field='delivery-module'}
|
||||||
<input type="radio" name="{$name}" {if $value == $ID}checked="checked"{/if} value="{$ID}">
|
<input type="radio" name="{$name}" {if $value == $ID}checked="checked"{/if} value="{$ID}">
|
||||||
{/form_field}
|
{/form_field}
|
||||||
<strong>{$TITLE}</strong> / {currency attr="symbol"} {$PRICE}
|
<strong>{$TITLE}</strong> / {currency attr="symbol"} {$POSTAGE}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
{/loop}
|
{/loop}
|
||||||
|
|||||||
@@ -25,12 +25,19 @@
|
|||||||
|
|
||||||
<div class="btn-group checkout-progress">
|
<div class="btn-group checkout-progress">
|
||||||
<a href="{url path="/cart"}" role="button" class="btn btn-step"><span class="step-nb">1</span> <span class="step-label"> <span>Your Cart</span></a>
|
<a href="{url path="/cart"}" role="button" class="btn btn-step"><span class="step-nb">1</span> <span class="step-label"> <span>Your Cart</span></a>
|
||||||
<a href="{url path="/cart/delivery"}" role="button" class="btn btn-step"><span class="step-nb">2</span> <span class="step-label">Billing and delivery</span></a>
|
<a href="{url path="/order/delivery"}" role="button" class="btn btn-step"><span class="step-nb">2</span> <span class="step-label">Billing and delivery</span></a>
|
||||||
<a href="#" role="button" class="btn btn-step active"><span class="step-nb">3</span> <span class="step-label">Check my order</span></a>
|
<a href="#" role="button" class="btn btn-step active"><span class="step-nb">3</span> <span class="step-label">Check my order</span></a>
|
||||||
<a href="#" role="button" class="btn btn-step disabled"><span class="step-nb">4</span> <span class="step-label">Secure payment</span></a>
|
<a href="#" role="button" class="btn btn-step disabled"><span class="step-nb">4</span> <span class="step-label">Secure payment</span></a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form id="form-cart" action="cart-step4.php" method="post" role="form">
|
{form name="thelia.order.payment"}
|
||||||
|
|
||||||
|
<form id="form-cart-payment" action="{url path="/order/invoice"}" method="post" role="form" {form_enctype form=$form}>
|
||||||
|
|
||||||
|
{form_hidden_fields form=$form}
|
||||||
|
|
||||||
|
{if $form_error}<div class="alert alert-danger">{$form_error_message}</div>{/if}
|
||||||
|
|
||||||
<table class="table table-cart">
|
<table class="table table-cart">
|
||||||
<colgroup>
|
<colgroup>
|
||||||
<col width="150">
|
<col width="150">
|
||||||
@@ -123,7 +130,7 @@
|
|||||||
<th class="shipping">Shipping Tax</th>
|
<th class="shipping">Shipping Tax</th>
|
||||||
<td class="shipping">
|
<td class="shipping">
|
||||||
<div class="shipping-price">
|
<div class="shipping-price">
|
||||||
<span class="price">{order attr="postage"}</span>
|
<span class="price">{currency attr="symbol"} {order attr="postage"}</span>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -151,32 +158,105 @@
|
|||||||
|
|
||||||
<div id="cart-address">
|
<div id="cart-address">
|
||||||
<div class="panel">
|
<div class="panel">
|
||||||
|
{loop type="address" name="delivery-address" id="{order attr="delivery_address"}"}
|
||||||
<div class="panel-heading">Delivery address</div>
|
<div class="panel-heading">Delivery address</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<span class="fn">M. DUPONT Jean</span>
|
<span class="fn">{loop type="title" name="customer.title.info" id=$TITLE}{$SHORT}{/loop} {$LASTNAME|upper} {$FIRSTNAME|ucwords}</span>
|
||||||
<span class="org">Agency XY</span>
|
<span class="org">{$COMPANY}</span>
|
||||||
<address class="adr">
|
<address class="adr">
|
||||||
<span class="street-address">street name of my business</span><br>
|
<span class="street-address">{$ADDRESS1}</span><br>
|
||||||
<span class="postal-code">75000</span>
|
{if $ADDRESS2 != ""}
|
||||||
<span class="locality">City, <span class="country-name">Country</span></span>
|
<span class="street-address">{$ADDRESS2}</span><br>
|
||||||
|
{/if}
|
||||||
|
{if $ADDRESS3 != ""}
|
||||||
|
<span class="street-address">{$ADDRESS3}</span><br>
|
||||||
|
{/if}
|
||||||
|
<span class="postal-code">{$ZIPCODE}</span>
|
||||||
|
<span class="locality">{$CITY}, <span class="country-name">{loop type="country" name="customer.country.info" id=$COUNTRY}{$TITLE}{/loop}</span></span>
|
||||||
</address>
|
</address>
|
||||||
</div>
|
</div>
|
||||||
|
{/loop}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{form_field form=$form field='invoice-address'}
|
||||||
|
|
||||||
<div class="panel">
|
<div class="panel">
|
||||||
<div class="panel-heading">Billing address</div>
|
<div class="panel-heading">Billing address</div>
|
||||||
|
|
||||||
|
{if $error}
|
||||||
|
<span class="help-block"><span class="icon-remove"></span> {$message}</span>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<span class="fn">M. DUPONT Jean</span>
|
|
||||||
<span class="org">Agency XY</span>
|
<table class="col-md-12">
|
||||||
<address class="adr">
|
|
||||||
<span class="street-address">street name of my business</span><br>
|
{loop type="address" name="invoice-address" default="{if !$error && $value}*{else}true{/if}" id="{if !$error && $value}{$value}{else}*{/if}"}
|
||||||
<span class="postal-code">75000</span>
|
|
||||||
<span class="locality">City, <span class="country-name">Country</span></span>
|
<tr>
|
||||||
</address>
|
<td>
|
||||||
<a href="address.php" class="btn btn-change-address">Change address</a>
|
<span class="fn">{loop type="title" name="customer.title.info" id=$TITLE}{$SHORT}{/loop} {$LASTNAME|upper} {$FIRSTNAME|ucwords}</span>
|
||||||
|
<span class="org">{$COMPANY}</span>
|
||||||
|
<address class="adr">
|
||||||
|
<span class="street-address">{$ADDRESS1}</span><br>
|
||||||
|
{if $ADDRESS2 != ""}
|
||||||
|
<span class="street-address">{$ADDRESS2}</span><br>
|
||||||
|
{/if}
|
||||||
|
{if $ADDRESS3 != ""}
|
||||||
|
<span class="street-address">{$ADDRESS3}</span><br>
|
||||||
|
{/if}
|
||||||
|
<span class="postal-code">{$ZIPCODE}</span>
|
||||||
|
<span class="locality">{$CITY}, <span class="country-name">{loop type="country" name="customer.country.info" id=$COUNTRY}{$TITLE}{/loop}</span></span>
|
||||||
|
</address>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input class="js-invoice-address-selector {if !$error}hidden{/if}" type="radio" name="{$name}" value="{$ID}" {if $value == $ID OR !$error}checked="checked"{/if}>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
{if !$error}
|
||||||
|
<tr class="js-change-invoice-address">
|
||||||
|
<td colspan="2">
|
||||||
|
<a href="#" class="btn btn-change-address">Change address</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{/loop}
|
||||||
|
|
||||||
|
{loop type="address" name="invoice-address" default="{if !$error && $value}*{else}false{/if}" exclude="{if !$error && $value}{$value}{else}none{/if}"}
|
||||||
|
|
||||||
|
<tr class="js-other-invoice-address {if !$error}hidden{/if}">
|
||||||
|
<td>
|
||||||
|
<span class="fn">{loop type="title" name="customer.title.info" id=$TITLE}{$SHORT}{/loop} {$LASTNAME|upper} {$FIRSTNAME|ucwords}</span>
|
||||||
|
<span class="org">{$COMPANY}</span>
|
||||||
|
<address class="adr">
|
||||||
|
<span class="street-address">{$ADDRESS1}</span><br>
|
||||||
|
{if $ADDRESS2 != ""}
|
||||||
|
<span class="street-address">{$ADDRESS2}</span><br>
|
||||||
|
{/if}
|
||||||
|
{if $ADDRESS3 != ""}
|
||||||
|
<span class="street-address">{$ADDRESS3}</span><br>
|
||||||
|
{/if}
|
||||||
|
<span class="postal-code">{$ZIPCODE}</span>
|
||||||
|
<span class="locality">{$CITY}, <span class="country-name">{loop type="country" name="customer.country.info" id=$COUNTRY}{$TITLE}{/loop}</span></span>
|
||||||
|
</address>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input class="js-invoice-address-selector {if !$error}hidden{/if}" type="radio" name="{$name}" value="{$ID}" {if $value == $ID}checked="checked"{/if}>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
{/loop}
|
||||||
|
|
||||||
|
</table>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/form_field}
|
||||||
|
|
||||||
<div id="payment-method" class="panel">
|
<div id="payment-method" class="panel">
|
||||||
<div class="panel-heading">Choose your payment method</div>
|
<div class="panel-heading">Choose your payment method</div>
|
||||||
@@ -195,10 +275,12 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<a href="cart-step2.php" role="button" class="btn btn-back"><span>Back</span></a>
|
<a href="{url path="/order/delivery"}" role="button" class="btn btn-back"><span>Back</span></a>
|
||||||
<button type="submit" class="btn btn-checkout-next"><span>Next Step</span></button>
|
<button type="submit" class="btn btn-checkout-next"><span>TO REMOVE</span></button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
{/form}
|
||||||
|
|
||||||
|
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
@@ -209,8 +291,16 @@
|
|||||||
|
|
||||||
{block name="javascript-initialization"}
|
{block name="javascript-initialization"}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
jQuery(function($cart) {
|
jQuery(function($order) {
|
||||||
|
$order('.js-change-invoice-address').on('click', 'a', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
$order('.js-other-invoice-address').removeClass('hidden');
|
||||||
|
$order('.js-invoice-address-selector').removeClass('hidden');
|
||||||
|
|
||||||
|
$order('#js-invoice-address-default-selector').unbind().remove();
|
||||||
|
$order('.js-change-invoice-address').unbind().remove();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{/block}
|
{/block}
|
||||||
Reference in New Issue
Block a user