Merge branch 'catalog'
Conflicts: core/lib/Thelia/Config/Resources/config.xml core/lib/Thelia/Config/Resources/routing/admin.xml core/lib/Thelia/Core/Template/Loop/Country.php core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php core/lib/Thelia/Model/Country.php core/lib/Thelia/Model/Profile.php core/lib/Thelia/Model/ProfileQuery.php install/insert.sql install/thelia.sql local/config/schema.xml
This commit is contained in:
@@ -21,21 +21,24 @@
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event\Product;
|
||||
namespace Thelia\Core\Event\ProductSaleElement;
|
||||
|
||||
use Thelia\Model\Product;
|
||||
use Thelia\Core\Event\Product\ProductEvent;
|
||||
|
||||
class ProductCreateCombinationEvent extends ProductEvent
|
||||
class ProductSaleElementCreateEvent extends ProductSaleElementEvent
|
||||
{
|
||||
protected $product;
|
||||
protected $attribute_av_list;
|
||||
protected $currency_id;
|
||||
|
||||
public function __construct(Product $product, $attribute_av_list, $currency_id)
|
||||
{
|
||||
parent::__construct($product);
|
||||
parent::__construct();
|
||||
|
||||
$this->attribute_av_list = $attribute_av_list;
|
||||
$this->currency_id = $currency_id;
|
||||
$this->setAttributeAvList($attribute_av_list);
|
||||
$this->setCurrencyId($currency_id);
|
||||
$this->setProduct($product);
|
||||
}
|
||||
|
||||
public function getAttributeAvList()
|
||||
@@ -62,4 +65,15 @@ class ProductCreateCombinationEvent extends ProductEvent
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getProduct() {
|
||||
return $this->product;
|
||||
}
|
||||
|
||||
public function setProduct($product) {
|
||||
$this->product = $product;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -21,19 +21,21 @@
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event\Product;
|
||||
|
||||
namespace Thelia\Core\Event\ProductSaleElement;
|
||||
use Thelia\Model\Product;
|
||||
use Thelia\Core\Event\Product\ProductEvent;
|
||||
|
||||
class ProductDeleteCombinationEvent extends ProductEvent
|
||||
class ProductSaleElementDeleteEvent extends ProductSaleElementEvent
|
||||
{
|
||||
protected $product_sale_element_id;
|
||||
protected $currency_id;
|
||||
|
||||
public function __construct(Product $product, $product_sale_element_id)
|
||||
public function __construct($product_sale_element_id, $currency_id)
|
||||
{
|
||||
parent::__construct($product);
|
||||
parent::__construct();
|
||||
|
||||
$this->product_sale_element_id = $product_sale_element_id;
|
||||
$this->setCurrencyId($currency_id);
|
||||
}
|
||||
|
||||
public function getProductSaleElementId()
|
||||
@@ -44,5 +46,19 @@ class ProductDeleteCombinationEvent extends ProductEvent
|
||||
public function setProductSaleElementId($product_sale_element_id)
|
||||
{
|
||||
$this->product_sale_element_id = $product_sale_element_id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCurrencyId()
|
||||
{
|
||||
return $this->currency_id;
|
||||
}
|
||||
|
||||
public function setCurrencyId($currency_id)
|
||||
{
|
||||
$this->currency_id = $currency_id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?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\Event\ProductSaleElement;
|
||||
|
||||
use Thelia\Model\ProductSaleElement;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
|
||||
class ProductSaleElementEvent extends ActionEvent
|
||||
{
|
||||
public $product_sale_element = null;
|
||||
|
||||
public function __construct(ProductSaleElement $product_sale_element = null)
|
||||
{
|
||||
$this->product_sale_element = $product_sale_element;
|
||||
}
|
||||
|
||||
public function hasProductSaleElement()
|
||||
{
|
||||
return ! is_null($this->product_sale_element);
|
||||
}
|
||||
|
||||
public function getProductSaleElement()
|
||||
{
|
||||
return $this->product_sale_element;
|
||||
}
|
||||
|
||||
public function setProductSaleElement(ProductSaleElement $product_sale_element)
|
||||
{
|
||||
$this->product_sale_element = $product_sale_element;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
<?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\Event\ProductSaleElement;
|
||||
use Thelia\Core\Event\Product\ProductCreateEvent;
|
||||
use Thelia\Model\Product;
|
||||
use Thelia\Core\Event\Product\ProductEvent;
|
||||
|
||||
class ProductSaleElementUpdateEvent extends ProductSaleElementEvent
|
||||
{
|
||||
protected $product_sale_element_id;
|
||||
|
||||
protected $product;
|
||||
protected $reference;
|
||||
protected $price;
|
||||
protected $currency_id;
|
||||
protected $weight;
|
||||
protected $quantity;
|
||||
protected $sale_price;
|
||||
protected $onsale;
|
||||
protected $isnew;
|
||||
protected $isdefault;
|
||||
protected $ean_code;
|
||||
protected $taxrule;
|
||||
|
||||
public function __construct(Product $product, $product_sale_element_id)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->setProduct($product);
|
||||
|
||||
$this->setProductSaleElementId($product_sale_element_id);
|
||||
}
|
||||
|
||||
public function getProductSaleElementId()
|
||||
{
|
||||
return $this->product_sale_element_id;
|
||||
}
|
||||
|
||||
public function setProductSaleElementId($product_sale_element_id)
|
||||
{
|
||||
$this->product_sale_element_id = $product_sale_element_id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPrice()
|
||||
{
|
||||
return $this->price;
|
||||
}
|
||||
|
||||
public function setPrice($price)
|
||||
{
|
||||
$this->price = $price;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCurrencyId()
|
||||
{
|
||||
return $this->currency_id;
|
||||
}
|
||||
|
||||
public function setCurrencyId($currency_id)
|
||||
{
|
||||
$this->currency_id = $currency_id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getWeight()
|
||||
{
|
||||
return $this->weight;
|
||||
}
|
||||
|
||||
public function setWeight($weight)
|
||||
{
|
||||
$this->weight = $weight;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getQuantity()
|
||||
{
|
||||
return $this->quantity;
|
||||
}
|
||||
|
||||
public function setQuantity($quantity)
|
||||
{
|
||||
$this->quantity = $quantity;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSalePrice()
|
||||
{
|
||||
return $this->sale_price;
|
||||
}
|
||||
|
||||
public function setSalePrice($sale_price)
|
||||
{
|
||||
$this->sale_price = $sale_price;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOnsale()
|
||||
{
|
||||
return $this->onsale;
|
||||
}
|
||||
|
||||
public function setOnsale($onsale)
|
||||
{
|
||||
$this->onsale = $onsale;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIsnew()
|
||||
{
|
||||
return $this->isnew;
|
||||
}
|
||||
|
||||
public function setIsnew($isnew)
|
||||
{
|
||||
$this->isnew = $isnew;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEanCode()
|
||||
{
|
||||
return $this->ean_code;
|
||||
}
|
||||
|
||||
public function setEanCode($ean_code)
|
||||
{
|
||||
$this->ean_code = $ean_code;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIsdefault()
|
||||
{
|
||||
return $this->isdefault;
|
||||
}
|
||||
|
||||
public function setIsdefault($isdefault)
|
||||
{
|
||||
$this->isdefault = $isdefault;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getReference()
|
||||
{
|
||||
return $this->reference;
|
||||
}
|
||||
|
||||
public function setReference($reference)
|
||||
{
|
||||
$this->reference = $reference;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getProduct()
|
||||
{
|
||||
return $this->product;
|
||||
}
|
||||
|
||||
public function setProduct($product)
|
||||
{
|
||||
$this->product = $product;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTaxrule()
|
||||
{
|
||||
return $this->taxrule;
|
||||
}
|
||||
|
||||
public function setTaxrule($taxrule)
|
||||
{
|
||||
$this->taxrule = $taxrule;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -255,14 +255,14 @@ final class TheliaEvents
|
||||
|
||||
// -- Categories Associated Content ----------------------------------------
|
||||
|
||||
const BEFORE_CREATECATEGORY_ASSOCIATED_CONTENT = "action.before_createCategoryAssociatedContent";
|
||||
const AFTER_CREATECATEGORY_ASSOCIATED_CONTENT = "action.after_createCategoryAssociatedContent";
|
||||
const BEFORE_CREATECATEGORY_ASSOCIATED_CONTENT = "action.before_createCategoryAssociatedContent";
|
||||
const AFTER_CREATECATEGORY_ASSOCIATED_CONTENT = "action.after_createCategoryAssociatedContent";
|
||||
|
||||
const BEFORE_DELETECATEGORY_ASSOCIATED_CONTENT = "action.before_deleteCategoryAssociatedContent";
|
||||
const AFTER_DELETECATEGORY_ASSOCIATED_CONTENT = "action.after_deleteCategoryAssociatedContent";
|
||||
const BEFORE_DELETECATEGORY_ASSOCIATED_CONTENT = "action.before_deleteCategoryAssociatedContent";
|
||||
const AFTER_DELETECATEGORY_ASSOCIATED_CONTENT = "action.after_deleteCategoryAssociatedContent";
|
||||
|
||||
const BEFORE_UPDATECATEGORY_ASSOCIATED_CONTENT = "action.before_updateCategoryAssociatedContent";
|
||||
const AFTER_UPDATECATEGORY_ASSOCIATED_CONTENT = "action.after_updateCategoryAssociatedContent";
|
||||
const BEFORE_UPDATECATEGORY_ASSOCIATED_CONTENT = "action.before_updateCategoryAssociatedContent";
|
||||
const AFTER_UPDATECATEGORY_ASSOCIATED_CONTENT = "action.after_updateCategoryAssociatedContent";
|
||||
|
||||
// -- Product management -----------------------------------------------
|
||||
|
||||
@@ -276,8 +276,9 @@ final class TheliaEvents
|
||||
const PRODUCT_REMOVE_CONTENT = "action.productRemoveContent";
|
||||
const PRODUCT_UPDATE_CONTENT_POSITION = "action.updateProductContentPosition";
|
||||
|
||||
const PRODUCT_ADD_COMBINATION = "action.productAddCombination";
|
||||
const PRODUCT_DELETE_COMBINATION = "action.productDeleteCombination";
|
||||
const PRODUCT_ADD_PRODUCT_SALE_ELEMENT = "action.addProductSaleElement";
|
||||
const PRODUCT_DELETE_PRODUCT_SALE_ELEMENT = "action.deleteProductSaleElement";
|
||||
const PRODUCT_UPDATE_PRODUCT_SALE_ELEMENT = "action.updateProductSaleElement";
|
||||
|
||||
const PRODUCT_SET_TEMPLATE = "action.productSetTemplate";
|
||||
|
||||
|
||||
@@ -113,13 +113,13 @@ class Country extends BaseI18nLoop
|
||||
->set("CHAPO", $country->getVirtualColumn('i18n_CHAPO'))
|
||||
->set("DESCRIPTION", $country->getVirtualColumn('i18n_DESCRIPTION'))
|
||||
->set("POSTSCRIPTUM", $country->getVirtualColumn('i18n_POSTSCRIPTUM'))
|
||||
->set("IS_DEFAULT", $country->getByDefault() === 1 ? "1" : "0")
|
||||
->set("ISOCODE", $country->getIsocode())
|
||||
->set("ISOALPHA2", $country->getIsoalpha2())
|
||||
->set("ISOALPHA3", $country->getIsoalpha3())
|
||||
->set('IS_DEFAULT', $country->getByDefault())
|
||||
->set("IS_DEFAULT", $country->getByDefault() ? "1" : "0")
|
||||
->set("IS_SHOP_COUNTRY", $country->getShopCountry() ? "1" : "0")
|
||||
;
|
||||
|
||||
;
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,7 @@ class OrderProduct extends BaseLoop
|
||||
->set("TAX_RULE_TITLE", $product->getTaxRuleTitle())
|
||||
->set("TAX_RULE_DESCRIPTION", $product->getTaxRuledescription())
|
||||
->set("PARENT", $product->getParent())
|
||||
->set("EAN_CODE", $product->getEanCode())
|
||||
;
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
|
||||
@@ -177,6 +177,7 @@ class ProductSaleElements extends BaseLoop
|
||||
->set("IS_NEW" , $PSEValue->getNewness() === 1 ? 1 : 0)
|
||||
->set("IS_DEFAULT" , $PSEValue->getIsDefault() === 1 ? 1 : 0)
|
||||
->set("WEIGHT" , $PSEValue->getWeight())
|
||||
->set("EAN_CODE" , $PSEValue->getEanCode())
|
||||
->set("PRICE" , $price)
|
||||
->set("PRICE_TAX" , $taxedPrice - $price)
|
||||
->set("TAXED_PRICE" , $taxedPrice)
|
||||
|
||||
@@ -22,9 +22,6 @@
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Core\Template\Smarty\Plugins;
|
||||
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Thelia\Core\Form\Type\TheliaType;
|
||||
use Thelia\Form\BaseForm;
|
||||
@@ -33,6 +30,9 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||
use Thelia\Core\Template\ParserContext;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -78,8 +78,8 @@ class Form extends AbstractSmartyPlugin
|
||||
{
|
||||
foreach ($formDefinition as $name => $className) {
|
||||
if (array_key_exists($name, $this->formDefinition)) {
|
||||
throw new \InvalidArgumentException(sprintf("%s form name already exists for %s class", $name,
|
||||
$className));
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf("%s form name already exists for %s class", $name, $className));
|
||||
}
|
||||
|
||||
$this->formDefinition[$name] = $className;
|
||||
@@ -113,7 +113,8 @@ class Form extends AbstractSmartyPlugin
|
||||
|
||||
$template->assign("form_error", $instance->hasError() ? true : false);
|
||||
$template->assign("form_error_message", $instance->getErrorMessage());
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
@@ -139,7 +140,7 @@ class Form extends AbstractSmartyPlugin
|
||||
|
||||
$template->assign("error", empty($errors) ? false : true);
|
||||
|
||||
if (! empty($errors)) {
|
||||
if (!empty($errors)) {
|
||||
$this->assignFieldErrorVars($template, $errors);
|
||||
}
|
||||
|
||||
@@ -205,30 +206,37 @@ class Form extends AbstractSmartyPlugin
|
||||
$this->assignFormTypeValues($template, $formFieldConfig, $formFieldView);
|
||||
|
||||
$value = $formFieldView->vars["value"];
|
||||
/* FIXME: doesnt work. We got "This form should not contain extra fields." error.
|
||||
// We have a collection
|
||||
if (is_array($value)) {
|
||||
|
||||
$key = $this->getParam($params, 'value_key');
|
||||
// We have a collection
|
||||
if (count($formFieldView->children) > 0) {
|
||||
|
||||
if ($key != null) {
|
||||
$key = $this->getParam($params, 'value_key');
|
||||
|
||||
if (isset($value[$key])) {
|
||||
if ($key != null) {
|
||||
|
||||
$name = sprintf("%s[%s]", $formFieldView->vars["full_name"], $key);
|
||||
$val = $value[$key];
|
||||
if (isset($value[$key])) {
|
||||
|
||||
$this->assignFieldValues($template, $name, $val, $formFieldView->vars);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->assignFieldValues($template, $formFieldView->vars["full_name"], $fieldVars["value"], $formFieldView->vars);
|
||||
}
|
||||
*/
|
||||
$this->assignFieldValues($template, $formFieldView->vars["full_name"], $formFieldView->vars["value"], $formFieldView->vars);
|
||||
$name = sprintf("%s[%s]", $formFieldView->vars["full_name"], $key);
|
||||
|
||||
$val = $value[$key];
|
||||
|
||||
$this->assignFieldValues($template, $name, $val, $formFieldView->vars);
|
||||
}
|
||||
else {
|
||||
throw new \LogicException(sprintf("Cannot find a value for key '%s' in field '%s'", $key, $formFieldView->vars["name"]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new \InvalidArgumentException(sprintf("Missing or empty parameter 'value_key' for field '%s'", $formFieldView->vars["name"]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->assignFieldValues($template, $formFieldView->vars["full_name"], $formFieldView->vars["value"], $formFieldView->vars);
|
||||
}
|
||||
|
||||
$formFieldView->setRendered();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
@@ -300,7 +308,7 @@ $this->assignFieldValues($template, $formFieldView->vars["full_name"], $fieldVar
|
||||
$formView = $instance->getView();
|
||||
|
||||
if ($formView->vars["multipart"]) {
|
||||
return sprintf('%s="%s"',"enctype", "multipart/form-data");
|
||||
return sprintf('%s="%s"', "enctype", "multipart/form-data");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,7 +324,8 @@ $this->assignFieldValues($template, $formFieldView->vars["full_name"], $fieldVar
|
||||
|
||||
if ($repeat) {
|
||||
$this->assignFieldErrorVars($template, $errors);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
@@ -339,11 +348,10 @@ $this->assignFieldValues($template, $formFieldView->vars["full_name"], $fieldVar
|
||||
|
||||
$fieldName = $this->getParam($params, 'field');
|
||||
|
||||
if (null == $fieldName)
|
||||
throw new \InvalidArgumentException("'field' parameter is missing");
|
||||
if (null == $fieldName) throw new \InvalidArgumentException("'field' parameter is missing");
|
||||
|
||||
if (empty($instance->getView()[$fieldName]))
|
||||
throw new \InvalidArgumentException(sprintf("Field name '%s' not found in form %s", $fieldName, $instance->getName()));
|
||||
if (empty($instance->getView()[$fieldName])) throw new \InvalidArgumentException(
|
||||
sprintf("Field name '%s' not found in form %s", $fieldName, $instance->getName()));
|
||||
|
||||
return $instance->getView()[$fieldName];
|
||||
}
|
||||
@@ -398,8 +406,10 @@ $this->assignFieldValues($template, $formFieldView->vars["full_name"], $fieldVar
|
||||
throw new \InvalidArgumentException("Missing 'form' parameter in form arguments");
|
||||
}
|
||||
|
||||
if (! $instance instanceof \Thelia\Form\BaseForm) {
|
||||
throw new \InvalidArgumentException(sprintf("form parameter in form_field block must be an instance of
|
||||
if (!$instance instanceof \Thelia\Form\BaseForm) {
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf(
|
||||
"form parameter in form_field block must be an instance of
|
||||
\Thelia\Form\BaseForm, instance of %s found", get_class($instance)));
|
||||
}
|
||||
|
||||
@@ -414,10 +424,7 @@ $this->assignFieldValues($template, $formFieldView->vars["full_name"], $fieldVar
|
||||
|
||||
$class = new \ReflectionClass($this->formDefinition[$name]);
|
||||
|
||||
return $class->newInstance(
|
||||
$this->request,
|
||||
"form"
|
||||
);
|
||||
return $class->newInstance($this->request, "form");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,6 +28,7 @@ use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||
use Thelia\Core\Template\Smarty\Exception\SmartyPluginException;
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||
use Thelia\Tools\DateTimeFormat;
|
||||
use Thelia\Tools\NumberFormat;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -69,21 +70,20 @@ class Format extends AbstractSmartyPlugin
|
||||
*/
|
||||
public function formatDate($params, $template = null)
|
||||
{
|
||||
$date = $this->getParam($params, "date", false);
|
||||
|
||||
if (array_key_exists("date", $params) === false) {
|
||||
if ($date === false) {
|
||||
throw new SmartyPluginException("date is a mandatory parameter in format_date function");
|
||||
}
|
||||
|
||||
$date = $params["date"];
|
||||
|
||||
if (!$date instanceof \DateTime) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (array_key_exists("format", $params)) {
|
||||
$format = $params["format"];
|
||||
} else {
|
||||
$format = DateTimeFormat::getInstance($this->request)->getFormat(array_key_exists("output", $params) ? $params["output"] : null);
|
||||
$format = $this->getParam($params, "format", false);
|
||||
|
||||
if ($format === false) {
|
||||
$format = DateTimeFormat::getInstance($this->request)->getFormat($this->getParam($params, "output", null));
|
||||
}
|
||||
|
||||
return $date->format($format);
|
||||
@@ -109,23 +109,22 @@ class Format extends AbstractSmartyPlugin
|
||||
*/
|
||||
public function formatNumber($params, $template = null)
|
||||
{
|
||||
if (array_key_exists("number", $params) === false) {
|
||||
$number = $this->getParam($params, "number", false);
|
||||
|
||||
if ($number === false) {
|
||||
throw new SmartyPluginException("number is a mandatory parameter in format_number function");
|
||||
}
|
||||
|
||||
$number = $params["number"];
|
||||
|
||||
if (empty($number)) {
|
||||
if ($number == '') {
|
||||
return "";
|
||||
}
|
||||
|
||||
$lang = $this->request->getSession()->getLang();
|
||||
|
||||
$decimals = array_key_exists("decimals", $params) ? $params["decimals"] : $lang->getDecimals();
|
||||
$decPoint = array_key_exists("dec_point", $params) ? $params["dec_point"] : $lang->getDecimalSeparator();
|
||||
$thousandsSep = array_key_exists("thousands_sep", $params) ? $params["thousands_sep"] : $lang->getThousandsSeparator();
|
||||
|
||||
return number_format($number, $decimals, $decPoint, $thousandsSep);
|
||||
return NumberFormat::getInstance($this->request)->format(
|
||||
$number,
|
||||
$this->getParam($params, "decimals", null),
|
||||
$this->getParam($params, "dec_point", null),
|
||||
$this->getParam($params, "thousands_sep", null)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user