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\EventSubscriberInterface;
use Thelia\Core\Event\ActionEvent;
use Thelia\Model\CurrencyQuery;
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');
@@ -144,7 +145,7 @@ class Currency extends BaseAction implements EventSubscriberInterface
if (null !== $currency = CurrencyQuery::create()->findOneByCode($code)) {
$currency
->setDispatcher($dispatcher)
->setDispatcher($event->getDispatcher())
->setRate($rate)
->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("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;
}

View File

@@ -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,8 +129,18 @@ 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) {
// 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");
}
@@ -153,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)) {
@@ -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)
{
try {
@@ -182,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
);
}
@@ -287,6 +321,44 @@ 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) {
$amount += $order->getPostage();
}
return $amount;
}
/**
*
* This method allow adding new compilers to Thelia container
@@ -327,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.
}
}