Merge pull request #279 from roadster31/labels

Labels
This commit is contained in:
Manuel Raynaud
2014-04-10 12:04:36 +02:00
4 changed files with 168 additions and 40 deletions

View File

@@ -26,6 +26,7 @@ namespace Thelia\Action;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\ActionEvent;
use Thelia\Model\CurrencyQuery; use Thelia\Model\CurrencyQuery;
use Thelia\Model\Currency as CurrencyModel; use Thelia\Model\Currency as CurrencyModel;
@@ -130,7 +131,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'); $rates_url = ConfigQuery::read('currency_rate_update_url', 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml');
@@ -144,7 +145,7 @@ class Currency extends BaseAction implements EventSubscriberInterface
if (null !== $currency = CurrencyQuery::create()->findOneByCode($code)) { if (null !== $currency = CurrencyQuery::create()->findOneByCode($code)) {
$currency $currency
->setDispatcher($dispatcher) ->setDispatcher($event->getDispatcher())
->setRate($rate) ->setRate($rate)
->save() ->save()
; ;

View File

@@ -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("name", $fieldName);
$template->assign("value", $fieldValue); $template->assign("value", $fieldValue);
$template->assign("data", $fieldVars['data']);
$template->assign("type", $fieldType);
$template->assign("checked", isset($fieldVars['checked']) ? $fieldVars['checked'] : false); $template->assign("checked", isset($fieldVars['checked']) ? $fieldVars['checked'] : false);
$template->assign("choices", isset($fieldVars['choices']) ? $fieldVars['choices'] : false); $template->assign("choices", isset($fieldVars['choices']) ? $fieldVars['choices'] : false);
$template->assign("multiple", isset($fieldVars['multiple']) ? $fieldVars['multiple'] : false); $template->assign("multiple", isset($fieldVars['multiple']) ? $fieldVars['multiple'] : false);
//data
$template->assign("data", $fieldVars['data']);
$template->assign("label", $fieldVars["label"]); $template->assign("label", $fieldVars["label"]);
$template->assign("label_attr", $fieldVars["label_attr"]); $template->assign("label_attr", $fieldVars["label_attr"]);
@@ -214,6 +219,8 @@ class Form extends AbstractSmartyPlugin
$formFieldView = $this->getFormFieldView($params); $formFieldView = $this->getFormFieldView($params);
$formFieldConfig = $this->getFormFieldConfig($params); $formFieldConfig = $this->getFormFieldConfig($params);
$formFieldType = $formFieldConfig->getType()->getName();
$this->assignFormTypeValues($template, $formFieldConfig, $formFieldView); $this->assignFormTypeValues($template, $formFieldConfig, $formFieldView);
$value = $formFieldView->vars["value"]; $value = $formFieldView->vars["value"];
@@ -233,9 +240,22 @@ class Form extends AbstractSmartyPlugin
$val = $value[$key]; $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 { } 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(); $formFieldView->setRendered();
@@ -254,16 +274,20 @@ class Form extends AbstractSmartyPlugin
} }
if (isset(self::$taggedFieldsStack[self::$taggedFieldsStackPosition])) { if (isset(self::$taggedFieldsStack[self::$taggedFieldsStackPosition])) {
$field = self::$taggedFieldsStack[self::$taggedFieldsStackPosition];
$this->assignFieldValues( $this->assignFieldValues(
$template, $template,
self::$taggedFieldsStack[self::$taggedFieldsStackPosition]['view']->vars["full_name"], $field['view']->vars["full_name"],
self::$taggedFieldsStack[self::$taggedFieldsStackPosition]['view']->vars["value"], $field['view']->vars["value"],
self::$taggedFieldsStack[self::$taggedFieldsStackPosition]['view']->vars $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; $repeat = true;
} }

View File

@@ -29,11 +29,15 @@ use Propel\Runtime\Propel;
use Symfony\Component\DependencyInjection\ContainerAware; use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request; 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\Map\ModuleTableMap;
use Thelia\Model\ModuleI18nQuery; use Thelia\Model\ModuleI18nQuery;
use Thelia\Model\Map\ModuleImageTableMap; use Thelia\Model\Map\ModuleImageTableMap;
use Thelia\Model\ModuleI18n; use Thelia\Model\ModuleI18n;
use Thelia\Model\Order; use Thelia\Model\Order;
use Thelia\TaxEngine\TaxEngine;
use Thelia\Tools\Image; use Thelia\Tools\Image;
use Thelia\Exception\ModuleException; use Thelia\Exception\ModuleException;
use Thelia\Model\Module; use Thelia\Model\Module;
@@ -125,8 +129,18 @@ class BaseModule extends ContainerAware implements BaseModuleInterface
$this->request = $request; $this->request = $request;
} }
/**
* @return \Thelia\Core\HttpFoundation\Request the request.
*
* @throws \RuntimeException
*/
public function getRequest() public function getRequest()
{ {
if ($this->hasRequest() === false) {
// Try to get request from container.
$this->setRequest($this->container->get('request'));
}
if ($this->hasRequest() === false) { if ($this->hasRequest() === false) {
throw new \RuntimeException("Sorry, the request is not available in this context"); throw new \RuntimeException("Sorry, the request is not available in this context");
} }
@@ -153,6 +167,12 @@ class BaseModule extends ContainerAware implements BaseModuleInterface
return $this->dispatcher; 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) public function setTitle(Module $module, $titles)
{ {
if (is_array($titles)) { if (is_array($titles)) {
@@ -174,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) public function deployImageFolder(Module $module, $folderPath, ConnectionInterface $con = null)
{ {
try { try {
@@ -182,7 +216,7 @@ class BaseModule extends ContainerAware implements BaseModuleInterface
throw $e; throw $e;
} }
if (null === $con) { if (null === $con) {
$con = \Propel\Runtime\Propel::getConnection( $con = Propel::getConnection(
ModuleImageTableMap::DATABASE_NAME ModuleImageTableMap::DATABASE_NAME
); );
} }
@@ -287,6 +321,44 @@ class BaseModule extends ContainerAware implements BaseModuleInterface
return $order->getDeliveryModuleId() == $model->getId(); 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) {
$amount += $order->getPostage();
}
return $amount;
}
/** /**
* *
* This method allow adding new compilers to Thelia container * This method allow adding new compilers to Thelia container
@@ -327,33 +399,69 @@ class BaseModule extends ContainerAware implements BaseModuleInterface
return array(); 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) public function install(ConnectionInterface $con = null)
{ {
// Implement this method to do something useful. // 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) public function preActivation(ConnectionInterface $con = null)
{ {
// Override this method to do something useful.
return true; return true;
} }
/**
* This method is called just after the module was successfully activated.
*
* @param ConnectionInterface $con
*/
public function postActivation(ConnectionInterface $con = null) 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) public function preDeactivation(ConnectionInterface $con = null)
{ {
// Override this method to do something useful.
return true; return true;
} }
public function postDeactivation(ConnectionInterface $con = null) 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) public function destroy(ConnectionInterface $con = null, $deleteModuleData = false)
{ {
// Implement this method to do something useful. // Override this method to do something useful.
} }
} }

View File

@@ -173,8 +173,9 @@
</table> </table>
</form> </form>
{/form} {/form}
{form name="thelia.order.payment"} {form name="thelia.order.payment"}
{assign var="isPost" value="{$smarty.post|count}"} {assign var="isPost" value=$smarty.post|count}
<form id="form-cart-payment" action="{url path="/order/invoice"}" method="post" {form_enctype form=$form}> <form id="form-cart-payment" action="{url path="/order/invoice"}" method="post" {form_enctype form=$form}>
{form_hidden_fields form=$form} {form_hidden_fields form=$form}
@@ -262,25 +263,25 @@
<div class="panel-body"> <div class="panel-body">
<ul class="list-payment"> <ul class="list-payment">
{loop type="payment" name="payments" force_return="true"} {loop type="payment" name="payments" force_return="true"}
{assign "paymentModuleId" $ID} {assign "paymentModuleId" $ID}
{loop type="image" name="paymentspicture" source="module" source_id=$ID force_return="true" width="100" height="72"} <li>
<div class="radio">
<label for="payment_{$paymentModuleId}">
<input type="radio" name="{$name}" id="payment_{$paymentModuleId}" value="{$paymentModuleId}">
<li> {loop type="image" name="paymentspicture" source="module" source_id=$ID force_return="true" width="100" height="72"}
<div class="radio"> <img src="{$IMAGE_URL}" alt="{intl l="Pay with %module_title" module_title=$TITLE}">
<label for="payment_{$paymentModuleId}_{$ID}"> {/loop}
<input type="radio" name="{$name}" id="payment_{$paymentModuleId}_{$ID}" value="{$paymentModuleId}">
<img src="{$IMAGE_URL}">
</label>
</div>
</li>
{/loop}
{elseloop rel="paymentspicture"}
{intl l="Pay with %module_title" module_title=$TITLE}
{/elseloop}
</label>
</div>
</li>
{/loop} {/loop}
</ul>
</div> </div>
</div> </div>
@@ -289,14 +290,8 @@
<a href="{url path="/order/delivery"}" role="button" class="btn btn-back"><span>{intl l="Back"}</span></a> <a href="{url path="/order/delivery"}" role="button" class="btn btn-back"><span>{intl l="Back"}</span></a>
<button type="submit" class="btn btn-checkout-next"><span>{intl l="Next Step"}</span></button> <button type="submit" class="btn btn-checkout-next"><span>{intl l="Next Step"}</span></button>
</form> </form>
{/form} {/form}
</article> </article>
</div> </div>
{/block} {/block}