From 35083977312f4d424196dcc78b6164287b6d10f0 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Fri, 4 Apr 2014 12:04:42 +0200 Subject: [PATCH 1/5] Fixed updateRates() method --- core/lib/Thelia/Action/Currency.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Action/Currency.php b/core/lib/Thelia/Action/Currency.php index 5e391c2bc..2d3a70c45 100644 --- a/core/lib/Thelia/Action/Currency.php +++ b/core/lib/Thelia/Action/Currency.php @@ -26,6 +26,7 @@ namespace Thelia\Action; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Thelia\Core\Event\ActionEvent; use Thelia\Model\CurrencyQuery; use Thelia\Model\Currency as CurrencyModel; @@ -134,7 +135,7 @@ class Currency extends BaseAction implements EventSubscriberInterface } } - public function updateRates(EventDispatcherInterface $dispatcher) + public function updateRates(ActionEvent $event) { $rates_url = ConfigQuery::read('currency_rate_update_url', 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml'); @@ -148,7 +149,7 @@ class Currency extends BaseAction implements EventSubscriberInterface if (null !== $currency = CurrencyQuery::create()->findOneByCode($code)) { $currency - ->setDispatcher($dispatcher) + ->setDispatcher($event->getDispatcher()) ->setRate($rate) ->save() ; From 13cade32482ff304ea7d4f1d6d69398caa1d464e Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Wed, 9 Apr 2014 19:35:02 +0200 Subject: [PATCH 2/5] Added the getCurrentOrderTotalAmount() method to BaseModule --- core/lib/Thelia/Module/BaseModule.php | 46 +++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/core/lib/Thelia/Module/BaseModule.php b/core/lib/Thelia/Module/BaseModule.php index 92ca5458f..7445c3364 100644 --- a/core/lib/Thelia/Module/BaseModule.php +++ b/core/lib/Thelia/Module/BaseModule.php @@ -29,11 +29,15 @@ use Propel\Runtime\Propel; use Symfony\Component\DependencyInjection\ContainerAware; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; +use Thelia\Core\HttpFoundation\Session\Session; +use Thelia\Model\Cart; +use Thelia\Model\Country; use Thelia\Model\Map\ModuleTableMap; use Thelia\Model\ModuleI18nQuery; use Thelia\Model\Map\ModuleImageTableMap; use Thelia\Model\ModuleI18n; use Thelia\Model\Order; +use Thelia\TaxEngine\TaxEngine; use Thelia\Tools\Image; use Thelia\Exception\ModuleException; use Thelia\Model\Module; @@ -125,6 +129,11 @@ class BaseModule extends ContainerAware implements BaseModuleInterface $this->request = $request; } + /** + * @return \Thelia\Core\HttpFoundation\Request the request. + * + * @throws \RuntimeException + */ public function getRequest() { if ($this->hasRequest() === false) { @@ -287,6 +296,43 @@ class BaseModule extends ContainerAware implements BaseModuleInterface return $order->getDeliveryModuleId() == $model->getId(); } + /** + * A convenient method to get the current order total, with or without tax, discount or postage. + * This method operates on the order currently in the user's session, and should not be used to + * get the total amount of an order already stored in the database. For such orders, use + * Order::getTotalAmount() method. + * + * @param bool $with_tax if true, to total price will include tax amount + * @param bool $with_discount if true, the total price will include discount, if any + * @param bool $with_postage if true, the total price will include the delivery costs, if any. + * + * @return float|int the current order amount. + */ + public function getCurrentOrderTotalAmount($with_tax = true, $with_discount = true, $with_postage = true) { + + /** @var Session $session */ + $session = $this->getRequest()->getSession(); + + /** @var Cart $cart */ + $cart = $session->getCart(); + + /** @var Order $order */ + $order = $session->getOrder(); + + /** @var TaxEngine $taxEngine */ + $taxEngine = $this->container->get("thelia.taxengine"); + + /** @var Country $country */ + $country = $taxEngine->getDeliveryCountry(); + + $amount = $with_tax ? $cart->getTaxedAmount($country, $with_discount) : $cart->getTotalAmount($with_discount); + + if ($with_postage) + $$order->getPostage(); + + return $cart->getTaxedAmount($country) + $order->getPostage(); + } + /** * * This method allow adding new compilers to Thelia container From 405ab649e231066d37b6da0fdb374a6cb7d8c87c Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Thu, 10 Apr 2014 10:03:31 +0200 Subject: [PATCH 3/5] Improved comments --- core/lib/Thelia/Module/BaseModule.php | 76 ++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 7 deletions(-) diff --git a/core/lib/Thelia/Module/BaseModule.php b/core/lib/Thelia/Module/BaseModule.php index 7445c3364..1a3e54be9 100644 --- a/core/lib/Thelia/Module/BaseModule.php +++ b/core/lib/Thelia/Module/BaseModule.php @@ -136,6 +136,11 @@ class BaseModule extends ContainerAware implements BaseModuleInterface */ public function getRequest() { + if ($this->hasRequest() === false) { + // Try to get request from container. + $this->setRequest($this->container->get('request')); + } + if ($this->hasRequest() === false) { throw new \RuntimeException("Sorry, the request is not available in this context"); } @@ -162,6 +167,12 @@ class BaseModule extends ContainerAware implements BaseModuleInterface return $this->dispatcher; } + /** + * Sets a module titles for various languages + * + * @param Module $module the module. + * @param $titles an associative array of locale => title_string + */ public function setTitle(Module $module, $titles) { if (is_array($titles)) { @@ -183,6 +194,20 @@ class BaseModule extends ContainerAware implements BaseModuleInterface } } + /** + * Ensure the proper deployment of the module's images. + * + * TODO : clarify the purpose of ModuleImage. How this table will be used elswhere in Thelia ? + * TODO : this method doesn't take care of internationalization. This is a bug. + * + * @param Module $module the module + * @param string $folderPath the image folder path + * @param ConnectionInterface $con + * + * @throws \Thelia\Exception\ModuleException + * @throws \Exception + * @throws \UnexpectedValueException + */ public function deployImageFolder(Module $module, $folderPath, ConnectionInterface $con = null) { try { @@ -191,7 +216,7 @@ class BaseModule extends ContainerAware implements BaseModuleInterface throw $e; } if (null === $con) { - $con = \Propel\Runtime\Propel::getConnection( + $con = Propel::getConnection( ModuleImageTableMap::DATABASE_NAME ); } @@ -327,10 +352,11 @@ class BaseModule extends ContainerAware implements BaseModuleInterface $amount = $with_tax ? $cart->getTaxedAmount($country, $with_discount) : $cart->getTotalAmount($with_discount); - if ($with_postage) - $$order->getPostage(); + if ($with_postage) { + $amount += $order->getPostage(); + } - return $cart->getTaxedAmount($country) + $order->getPostage(); + return $amount; } /** @@ -373,33 +399,69 @@ class BaseModule extends ContainerAware implements BaseModuleInterface return array(); } + /** + * This method is called when the plugin is installed for the first time, using + * zip upload method. + * + * @param ConnectionInterface $con + */ public function install(ConnectionInterface $con = null) { // Implement this method to do something useful. } + /** + * This method is called before the module activation, and may prevent it by returning false. + * + * @param ConnectionInterface $con + * + * @return bool true to continue module activation, false to prevent it. + */ public function preActivation(ConnectionInterface $con = null) { + // Override this method to do something useful. + return true; } + /** + * This method is called just after the module was successfully activated. + * + * @param ConnectionInterface $con + */ public function postActivation(ConnectionInterface $con = null) { - // Implement this method to do something useful. + // Override this method to do something useful. } + /** + * This method is called before the module de-activation, and may prevent it by returning false. + * + * @param ConnectionInterface $con + * @return bool true to continue module de-activation, false to prevent it. + */ public function preDeactivation(ConnectionInterface $con = null) { + // Override this method to do something useful. + return true; } + public function postDeactivation(ConnectionInterface $con = null) { - // Implement this method to do something useful. + // Override this method to do something useful. } + /** + * This method is called just before the deletion of the module, giving the module an opportunity + * to delete its data. + * + * @param ConnectionInterface $con + * @param bool $deleteModuleData if true, the module should remove all its data from the system. + */ public function destroy(ConnectionInterface $con = null, $deleteModuleData = false) { - // Implement this method to do something useful. + // Override this method to do something useful. } } From 5812b08b5facdeb2686f0e982f97bc0f44c4f874 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Thu, 10 Apr 2014 10:04:47 +0200 Subject: [PATCH 4/5] Added some more output data in form_field block --- .../Core/Template/Smarty/Plugins/Form.php | 50 ++++++++++++++----- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php index 59bde6905..bac7c1624 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php @@ -127,20 +127,25 @@ class Form extends AbstractSmartyPlugin } } - protected function assignFieldValues($template, $fieldName, $fieldValue, $fieldVars, $total_value_count = 1) + protected function assignFieldValues( + $template, + $fieldName, + $fieldValue, + $fieldType, + $fieldVars, + $total_value_count = 1 + ) { $template->assign("name", $fieldName); - $template->assign("value", $fieldValue); + $template->assign("data", $fieldVars['data']); + + $template->assign("type", $fieldType); $template->assign("checked", isset($fieldVars['checked']) ? $fieldVars['checked'] : false); $template->assign("choices", isset($fieldVars['choices']) ? $fieldVars['choices'] : false); $template->assign("multiple", isset($fieldVars['multiple']) ? $fieldVars['multiple'] : false); - - //data - $template->assign("data", $fieldVars['data']); - $template->assign("label", $fieldVars["label"]); $template->assign("label_attr", $fieldVars["label_attr"]); @@ -214,6 +219,8 @@ class Form extends AbstractSmartyPlugin $formFieldView = $this->getFormFieldView($params); $formFieldConfig = $this->getFormFieldConfig($params); + $formFieldType = $formFieldConfig->getType()->getName(); + $this->assignFormTypeValues($template, $formFieldConfig, $formFieldView); $value = $formFieldView->vars["value"]; @@ -233,9 +240,22 @@ class Form extends AbstractSmartyPlugin $val = $value[$key]; - $this->assignFieldValues($template, $name, $val, $formFieldView->vars, count($formFieldView->children)); + $this->assignFieldValues( + $template, + $name, + $val, + $formFieldType, + $formFieldView->vars, + count($formFieldView->children) + ); } else { - $this->assignFieldValues($template, $formFieldView->vars["full_name"], $formFieldView->vars["value"], $formFieldView->vars); + $this->assignFieldValues( + $template, + $formFieldView->vars["full_name"], + $formFieldView->vars["value"], + $formFieldType, + $formFieldView->vars + ); } $formFieldView->setRendered(); @@ -254,16 +274,20 @@ class Form extends AbstractSmartyPlugin } if (isset(self::$taggedFieldsStack[self::$taggedFieldsStackPosition])) { + + $field = self::$taggedFieldsStack[self::$taggedFieldsStackPosition]; + $this->assignFieldValues( $template, - self::$taggedFieldsStack[self::$taggedFieldsStackPosition]['view']->vars["full_name"], - self::$taggedFieldsStack[self::$taggedFieldsStackPosition]['view']->vars["value"], - self::$taggedFieldsStack[self::$taggedFieldsStackPosition]['view']->vars + $field['view']->vars["full_name"], + $field['view']->vars["value"], + $field['config']->getType()->getName(), + $field['view']->vars ); - $this->assignFormTypeValues($template, self::$taggedFieldsStack[self::$taggedFieldsStackPosition]['config'], self::$taggedFieldsStack[self::$taggedFieldsStackPosition]['view']); + $this->assignFormTypeValues($template, $field['config'], $field['view']); - self::$taggedFieldsStack[self::$taggedFieldsStackPosition]['view']->setRendered(); + $field['view']->setRendered(); $repeat = true; } From b1c515e2a1ae2091c280b4fe53fc0d37349596ca Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Thu, 10 Apr 2014 11:10:43 +0200 Subject: [PATCH 5/5] Payment modules without image are now displayed ad text "Pay with ..." --- .../frontOffice/default/order-invoice.html | 37 ++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/templates/frontOffice/default/order-invoice.html b/templates/frontOffice/default/order-invoice.html index afe865d7f..500b14f29 100644 --- a/templates/frontOffice/default/order-invoice.html +++ b/templates/frontOffice/default/order-invoice.html @@ -173,8 +173,9 @@ {/form} + {form name="thelia.order.payment"} - {assign var="isPost" value="{$smarty.post|count}"} + {assign var="isPost" value=$smarty.post|count}
{form_hidden_fields form=$form} @@ -262,25 +263,25 @@
    - {loop type="payment" name="payments" force_return="true"} - {assign "paymentModuleId" $ID} - {loop type="image" name="paymentspicture" source="module" source_id=$ID force_return="true" width="100" height="72"} +
  • +
    +
  • -
    - -
    -
  • - - {/loop} + {loop type="image" name="paymentspicture" source="module" source_id=$ID force_return="true" width="100" height="72"} + {intl l= + {/loop} + {elseloop rel="paymentspicture"} + {intl l="Pay with %module_title" module_title=$TITLE} + {/elseloop} + +
+ {/loop} - + @@ -289,14 +290,8 @@ {intl l="Back"}
- {/form} - - - - - {/block}