postage + invoice step

This commit is contained in:
Etienne Roudeix
2013-09-17 19:47:10 +02:00
parent 21df630d27
commit 0d1c6cf8cb
18 changed files with 455 additions and 48 deletions

View File

@@ -23,17 +23,16 @@
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 $invoiceAddress = null;
protected $deliveryAddress = null;
protected $deliveryModule = null;
protected $paymentModule = null;
protected $postage = null;
/**
* @param Order $order
@@ -54,7 +53,7 @@ class OrderEvent extends ActionEvent
/**
* @param $address
*/
public function setBillingAddress($address)
public function setInvoiceAddress($address)
{
$this->deliveryAddress = $address;
}
@@ -75,6 +74,22 @@ class OrderEvent extends ActionEvent
$this->deliveryModule = $module;
}
/**
* @param $module
*/
public function setPaymentModule($module)
{
$this->paymentModule = $module;
}
/**
* @param $postage
*/
public function setPostage($postage)
{
$this->postage = $postage;
}
/**
* @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()
{
@@ -100,10 +115,26 @@ class OrderEvent extends ActionEvent
}
/**
* @return array|mixed|Address
* @return null|int
*/
public function getDeliveryModule()
{
return $this->deliveryModule;
}
/**
* @return null|int
*/
public function getPaymentModule()
{
return $this->paymentModule;
}
/**
* @return null|int
*/
public function getPostage()
{
return $this->postage;
}
}

View File

@@ -54,7 +54,13 @@ class Address extends BaseLoop
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntListTypeArgument('id'),
new Argument(
'id',
new TypeCollection(
new Type\IntListType(),
new Type\EnumType(array('*', 'any'))
)
),
new Argument(
'customer',
new TypeCollection(
@@ -63,8 +69,14 @@ class Address extends BaseLoop
),
'current'
),
Argument::createBooleanTypeArgument('default'),
Argument::createIntListTypeArgument('exclude')
Argument::createBooleanOrBothTypeArgument('default'),
new Argument(
'exclude',
new TypeCollection(
new Type\IntListType(),
new Type\EnumType(array('none'))
)
)
);
}
@@ -79,7 +91,7 @@ class Address extends BaseLoop
$id = $this->getId();
if (null !== $id) {
if (null !== $id && !in_array($id, array('*', 'any'))) {
$search->filterById($id, Criteria::IN);
}
@@ -106,7 +118,7 @@ class Address extends BaseLoop
$exclude = $this->getExclude();
if (!is_null($exclude)) {
if (null !== $exclude && 'none' !== $exclude) {
$search->filterById($exclude, Criteria::NOT_IN);
}

View File

@@ -29,7 +29,6 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Model\ModuleQuery;
/**
* Class Delivery
* @package Thelia\Core\Template\Loop
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
@@ -93,6 +92,8 @@ class BaseSpecificModule extends BaseI18nLoop
{
$search = ModuleQuery::create();
$search->filterByActivate(1);
if (null !== $id = $this->getId()) {
$search->filterById($id);
}

View File

@@ -87,7 +87,7 @@ class Country extends BaseI18nLoop
if (true === $withArea) {
$search->filterByAreaId(null, Criteria::ISNOTNULL);
} elseif (false == $withArea) {
} elseif (false === $withArea) {
$search->filterByAreaId(null, Criteria::ISNULL);
}

View File

@@ -89,7 +89,7 @@ class Delivery extends BaseSpecificModule
->set('CHAPO', $deliveryModule->getVirtualColumn('i18n_CHAPO'))
->set('DESCRIPTION', $deliveryModule->getVirtualColumn('i18n_DESCRIPTION'))
->set('POSTSCRIPTUM', $deliveryModule->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set('PRICE', $moduleInstance->calculate($country))
->set('POSTAGE', $moduleInstance->getPostage($country))
;
$loopResult->addRow($loopResultRow);

View 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;
}
}

View File

@@ -188,7 +188,16 @@ class DataAccessFunctions extends AbstractSmartyPlugin
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 $smarty
*
* @return string
*/
public function langDataAccess($params, $smarty)
{
@@ -294,6 +305,7 @@ class DataAccessFunctions extends AbstractSmartyPlugin
*/
public function getPluginDescriptors()
{
return array(
new SmartyPluginDescriptor('function', 'admin', $this, 'adminDataAccess'),
new SmartyPluginDescriptor('function', 'customer', $this, 'customerDataAccess'),