Merge branch 'master' of https://github.com/thelia/thelia into coupon
# By Manuel Raynaud (8) and franck (2) # Via franck * 'master' of https://github.com/thelia/thelia: en_EN -> en_UK, the "en_EN" locale does not exists. Smarty inheritance in admin template. fix typo in phpdoc complete test for foramt_number smarty function test foramt_date without datetime object create foramt_number smarty function remove sqlmap file add some phpdoc complete test for format_date smarty function create new smarty function for displaying date in expected format Conflicts: reset_install.sh
This commit is contained in:
@@ -71,6 +71,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
||||
$event
|
||||
);
|
||||
|
||||
$couponModel = CouponQuery::create();
|
||||
$event->getCreatedCoupon()->save();
|
||||
|
||||
$this->dispatch(
|
||||
|
||||
120
core/lib/Thelia/Action/Currency.php
Normal file
120
core/lib/Thelia/Action/Currency.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?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\Action;
|
||||
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Model\Currency as CurrencyModel;
|
||||
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
|
||||
use Thelia\Core\Event\CurrencyChangeEvent;
|
||||
use Thelia\Core\Event\CurrencyCreateEvent;
|
||||
use Thelia\Core\Event\CurrencyDeleteEvent;
|
||||
|
||||
class Currency extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* Create a new currencyuration entry
|
||||
*
|
||||
* @param CurrencyCreateEvent $event
|
||||
*/
|
||||
public function create(CurrencyCreateEvent $event)
|
||||
{
|
||||
$currency = new CurrencyModel();
|
||||
|
||||
$currency
|
||||
->setDispatcher($this->getDispatcher())
|
||||
|
||||
->setLocale($event->getLocale())
|
||||
->setName($event->getCurrencyName())
|
||||
->setSymbol($event->getSymbol())
|
||||
->setRate($event->getRate())
|
||||
->setCode($event->getCode())
|
||||
|
||||
->save()
|
||||
;
|
||||
|
||||
$event->setCurrency($currency);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change a currency
|
||||
*
|
||||
* @param CurrencyChangeEvent $event
|
||||
*/
|
||||
public function modify(CurrencyChangeEvent $event)
|
||||
{
|
||||
$search = CurrencyQuery::create();
|
||||
|
||||
if (null !== $currency = CurrencyQuery::create()->findOneById($event->getCurrencyId())) {
|
||||
|
||||
$currency
|
||||
->setDispatcher($this->getDispatcher())
|
||||
|
||||
->setLocale($event->getLocale())
|
||||
->setName($event->getCurrencyName())
|
||||
->setSymbol($event->getSymbol())
|
||||
->setRate($event->getRate())
|
||||
->setCode($event->getCode())
|
||||
|
||||
->save();
|
||||
|
||||
$event->setCurrency($currency);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a currencyuration entry
|
||||
*
|
||||
* @param CurrencyDeleteEvent $event
|
||||
*/
|
||||
public function delete(CurrencyDeleteEvent $event)
|
||||
{
|
||||
|
||||
if (null !== ($currency = CurrencyQuery::create()->findOneById($event->getCurrencyId()))) {
|
||||
|
||||
$currency
|
||||
->setDispatcher($this->getDispatcher())
|
||||
->delete()
|
||||
;
|
||||
|
||||
$event->setCurrency($currency);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
TheliaEvents::CURRENCY_CREATE => array("create", 128),
|
||||
TheliaEvents::CURRENCY_MODIFY => array("modify", 128),
|
||||
TheliaEvents::CURRENCY_DELETE => array("delete", 128),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -32,12 +32,17 @@
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
</service>
|
||||
|
||||
<service id="thelia.action.category" class="Thelia\Action\Config">
|
||||
<service id="thelia.action.config" class="Thelia\Action\Config">
|
||||
<argument type="service" id="service_container"/>
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
</service>
|
||||
|
||||
<service id="thelia.action.messages" class="Thelia\Action\Message">
|
||||
<service id="thelia.action.message" class="Thelia\Action\Message">
|
||||
<argument type="service" id="service_container"/>
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
</service>
|
||||
|
||||
<service id="thelia.action.currency" class="Thelia\Action\Currency">
|
||||
<argument type="service" id="service_container"/>
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
</service>
|
||||
|
||||
@@ -54,6 +54,11 @@
|
||||
|
||||
<form name="thelia.admin.message.creation" class="Thelia\Form\MessageCreationForm"/>
|
||||
<form name="thelia.admin.message.modification" class="Thelia\Form\MessageModificationForm"/>
|
||||
|
||||
<form name="thelia.admin.currency.creation" class="Thelia\Form\CurrencyCreationForm"/>
|
||||
<form name="thelia.admin.currency.modification" class="Thelia\Form\CurrencyModificationForm"/>
|
||||
|
||||
<form name="thelia.admin.coupon.creation" class="Thelia\Form\CouponCreationForm"/>
|
||||
</forms>
|
||||
|
||||
|
||||
@@ -122,6 +127,11 @@
|
||||
<tag name="thelia.parser.register_plugin"/>
|
||||
</service>
|
||||
|
||||
<service id="smarty.plugin.format" class="Thelia\Core\Template\Smarty\Plugins\Format" scope="request">
|
||||
<argument type="service" id="request"/>
|
||||
<tag name="thelia.parser.register_plugin"/>
|
||||
</service>
|
||||
|
||||
<service id="smarty.plugin.thelialoop" class="Thelia\Core\Template\Smarty\Plugins\TheliaLoop" scope="request">
|
||||
<tag name="thelia.parser.register_plugin"/>
|
||||
|
||||
|
||||
@@ -47,18 +47,15 @@
|
||||
|
||||
<!-- Route to the Coupon controller (process Coupon browsing) -->
|
||||
<route id="admin.coupon.list" path="/admin/coupon">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::processAction</default>
|
||||
<default key="action">browse</default>
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::browseAction</default>
|
||||
</route>
|
||||
<route id="admin.coupon.create" path="/admin/coupon/create">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::processAction</default>
|
||||
<default key="action">create</default>
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::createAction</default>
|
||||
</route>
|
||||
<route id="admin.coupon.edit" path="/admin/coupon/edit/{id}">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::processAction</default>
|
||||
<default key="action">edit</default>
|
||||
<route id="admin.coupon.edit" path="/admin/coupon/edit/{couponId}">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::editAction</default>
|
||||
</route>
|
||||
<route id="admin.coupon.read" path="/admin/coupon/read/{id}">
|
||||
<route id="admin.coupon.read" path="/admin/coupon/read/{couponId}">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::readAction</default>
|
||||
</route>
|
||||
|
||||
@@ -115,6 +112,28 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\MessageController::deleteAction</default>
|
||||
</route>
|
||||
|
||||
<!-- Routes to the Currencies controller -->
|
||||
|
||||
<route id="admin.configuration.currencies.default" path="/admin/configuration/currencies">
|
||||
<default key="_controller">Thelia\Controller\Admin\CurrencyController::defaultAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.currencies.create" path="/admin/configuration/currencies/create">
|
||||
<default key="_controller">Thelia\Controller\Admin\CurrencyController::createAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.currencies.change" path="/admin/configuration/currencies/change">
|
||||
<default key="_controller">Thelia\Controller\Admin\CurrencyController::changeAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.currencies.save-change" path="/admin/configuration/currencies/save-change">
|
||||
<default key="_controller">Thelia\Controller\Admin\CurrencyController::saveChangeAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.currencies.delete" path="/admin/configuration/currencies/delete">
|
||||
<default key="_controller">Thelia\Controller\Admin\CurrencyController::deleteAction</default>
|
||||
</route>
|
||||
|
||||
<!-- The default route, to display a template -->
|
||||
|
||||
<route id="admin.processTemplate" path="/admin/{template}">
|
||||
|
||||
@@ -199,12 +199,21 @@ class BaseAdminController extends BaseController
|
||||
// Find the current edit language ID
|
||||
$edition_language = $this->getCurrentEditionLangId();
|
||||
|
||||
// Current back-office (not edition) language
|
||||
$current_lang = LangQuery::create()->findOneById($session->getLangId());
|
||||
|
||||
// Prepare common template variables
|
||||
$args = array_merge($args, array(
|
||||
'locale' => $session->getLocale(),
|
||||
'lang_code' => $session->getLang(),
|
||||
'lang_id' => $session->getLangId(),
|
||||
|
||||
'datetime_format' => $current_lang->getDateTimeFormat(),
|
||||
'date_format' => $current_lang->getDateFormat(),
|
||||
'time_format' => $current_lang->getTimeFormat(),
|
||||
|
||||
'edition_language' => $edition_language,
|
||||
|
||||
'current_url' => htmlspecialchars($this->getRequest()->getUri())
|
||||
));
|
||||
|
||||
|
||||
@@ -25,12 +25,14 @@ namespace Thelia\Controller\Admin;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Thelia\Core\Event\Coupon\CouponCreateEvent;
|
||||
use Thelia\Core\Event\Coupon\CouponEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Security\Exception\AuthenticationException;
|
||||
use Thelia\Core\Security\Exception\AuthorizationException;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
use Thelia\Form\CouponCreationForm;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Model\Coupon;
|
||||
use Thelia\Model\CouponQuery;
|
||||
|
||||
@@ -47,28 +49,16 @@ use Thelia\Model\CouponQuery;
|
||||
*/
|
||||
class CouponController extends BaseAdminController
|
||||
{
|
||||
/**
|
||||
* List all Coupons Action
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
return $this->process();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage Coupons list display
|
||||
*
|
||||
* @param array $args GET arguments
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
protected function browseCoupons($args)
|
||||
public function browseAction()
|
||||
{
|
||||
$this->checkAuth("ADMIN", "admin.coupon.view");
|
||||
|
||||
return $this->render('coupon/list', $args);
|
||||
return $this->render('coupon-list');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,74 +68,89 @@ class CouponController extends BaseAdminController
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function createAction($args)
|
||||
public function createAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.coupon.create")) return $response;
|
||||
$response = $this->checkAuth("admin.coupon.create");
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$message = false;
|
||||
|
||||
// Create the form from the request
|
||||
$creationForm = new CouponCreationForm($this->getRequest());
|
||||
|
||||
if ($this->getRequest()->isMethod('POST')) {
|
||||
try {
|
||||
// Create the form from the request
|
||||
$creationForm = new CouponCreationForm(Form($this->getRequest()));
|
||||
|
||||
// Check the form against constraints violations
|
||||
$form = $this->validateForm($creationForm, "POST");
|
||||
|
||||
// Get the form field values
|
||||
$data = $form->getData();
|
||||
|
||||
var_dump($data);
|
||||
|
||||
$couponCreateEvent = new CouponCreateEvent();
|
||||
$couponCreateEvent->setTitle($data['title']);
|
||||
$couponCreateEvent->setShortDescription($data['shortDescription']);
|
||||
$couponCreateEvent->setDescription($data['longDescription']);
|
||||
$couponCreateEvent->setCode($data['code']);
|
||||
$couponCreateEvent->setAmount($data['amount']);
|
||||
|
||||
$couponCreateEvent->setExpirationDate(
|
||||
new \DateTime($data['expirationDate'])
|
||||
$couponEvent = new CouponEvent(
|
||||
$data['code'],
|
||||
$data['title'],
|
||||
$data['amount'],
|
||||
$data['effect'],
|
||||
$data['shortDescription'],
|
||||
$data['description'],
|
||||
$data['isEnabled'],
|
||||
new \DateTime($data['expirationDate']),
|
||||
$data['isAvailableOnSpecialOffers'],
|
||||
$data['isCumulative'],
|
||||
$data['isRemovingPostage'],
|
||||
$data['maxUsage'],
|
||||
array()
|
||||
);
|
||||
$couponCreateEvent->setMaxUsage($data['maxUsage']);
|
||||
$couponCreateEvent->setIsCumulative($data['isCumulative']);
|
||||
$couponCreateEvent->setIsRemovingPostage($data['isRemovingPostage']);
|
||||
$couponCreateEvent->setIsAvailableOnSpecialOffers($data['isAvailableOnSpecialOffers']);
|
||||
|
||||
$couponCreateEvent->setIsEnabled($data['isEnabled']);
|
||||
|
||||
// $couponCreateEvent->setRules($data['rules']);
|
||||
|
||||
$this->dispatch(
|
||||
TheliaEvents::CREATE_COUPON,
|
||||
$couponCreateEvent
|
||||
TheliaEvents::COUPON_CREATE,
|
||||
$couponEvent
|
||||
);
|
||||
$this->adminLogAppend(
|
||||
sprintf(
|
||||
'Coupon %s (ID %s) created',
|
||||
$couponCreateEvent->getTitle(),
|
||||
$couponCreateEvent->getId()
|
||||
$couponEvent->getTitle(),
|
||||
$couponEvent->getId()
|
||||
)
|
||||
);
|
||||
// @todo redirect if successful
|
||||
} catch (FormValidationException $e) {
|
||||
$creationForm->setErrorMessage($e->getMessage());
|
||||
$this->getParserContext()->setErrorForm($creationForm);
|
||||
// Invalid data entered
|
||||
$message = 'Please check your input:';
|
||||
} catch (\Exception $e) {
|
||||
// Any other error
|
||||
$message = 'Sorry, an error occured:';
|
||||
}
|
||||
|
||||
if ($message !== false) {
|
||||
// Log error message
|
||||
Tlog::getInstance()->error(
|
||||
sprintf(
|
||||
"Failed to create coupon: %s",
|
||||
$e->getMessage()
|
||||
"Error during variable modification process : %s. Exception was %s",
|
||||
$message, $e->getMessage()
|
||||
)
|
||||
);
|
||||
$this->getParserContext()->setGeneralError($e->getMessage());
|
||||
}
|
||||
} else {
|
||||
|
||||
// Mark the form as errored
|
||||
$creationForm->setErrorMessage($message);
|
||||
|
||||
// Pas the form and the error to the parser
|
||||
$this->getParserContext()
|
||||
->addForm($creationForm)
|
||||
->setGeneralError($message)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('coupon/create', array('action' => 'create'));
|
||||
$formAction = 'admin/coupon/create';
|
||||
return $this->render(
|
||||
'coupon-create',
|
||||
array(
|
||||
'formAction' => $formAction
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,74 +160,35 @@ class CouponController extends BaseAdminController
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
protected function editCoupon($args)
|
||||
public function editAction($couponId)
|
||||
{
|
||||
$this->checkAuth("ADMIN", "admin.coupon.view");
|
||||
$this->checkAuth("ADMIN", "admin.coupon.edit");
|
||||
|
||||
return $this->render('coupon/update', $args);
|
||||
$formAction = 'admin/coupon/edit/' . $couponId;
|
||||
|
||||
return $this->render('coupon-edit', array('formAction' => $formAction));
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage Coupons read display
|
||||
*
|
||||
* @param int $id Coupon Id
|
||||
* @param int $couponId Coupon Id
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function readAction($id)
|
||||
public function readAction($couponId)
|
||||
{
|
||||
$this->checkAuth("ADMIN", "admin.coupon.read");
|
||||
|
||||
// Database request repeated in the loop but cached
|
||||
$search = CouponQuery::create();
|
||||
$coupon = $search->findOneById($id);
|
||||
$coupon = $search->findOneById($couponId);
|
||||
|
||||
if ($coupon === null) {
|
||||
return $this->pageNotFound();
|
||||
}
|
||||
|
||||
return $this->render('coupon/read', array('couponId' => $id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Process all Actions
|
||||
*
|
||||
* @param string $action Action to process
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function processAction()
|
||||
{
|
||||
// Get the current action
|
||||
$action = $this->getRequest()->get('action', 'browse');
|
||||
|
||||
// Get the category ID
|
||||
// $id = $this->getRequest()->get('id', 0);
|
||||
|
||||
$args = array(
|
||||
'action' => $action,
|
||||
// 'current_coupon_id' => $id
|
||||
);
|
||||
|
||||
try {
|
||||
switch ($action) {
|
||||
case 'browse' : // Browse coupon
|
||||
return $this->browseCoupons($args);
|
||||
case 'create' : // Create a new coupon
|
||||
// return $this->createCoupon($args);
|
||||
case 'edit' : // Edit an existing coupon
|
||||
return $this->editCoupon($args);
|
||||
case 'read' : // Read an existing coupon
|
||||
return $this->readCoupon($args);
|
||||
}
|
||||
} catch (AuthorizationException $ex) {
|
||||
return $this->errorPage($ex->getMessage());
|
||||
} catch (AuthenticationException $ex) {
|
||||
return $this->errorPage($ex->getMessage());
|
||||
}
|
||||
|
||||
// We did not recognized the action -> return a 404 page
|
||||
return $this->pageNotFound();
|
||||
return $this->render('coupon-read', array('couponId' => $couponId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
284
core/lib/Thelia/Controller/Admin/CurrencyController.php
Normal file
284
core/lib/Thelia/Controller/Admin/CurrencyController.php
Normal file
@@ -0,0 +1,284 @@
|
||||
<?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\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Event\CurrencyDeleteEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Tools\URL;
|
||||
use Thelia\Core\Event\CurrencyChangeEvent;
|
||||
use Thelia\Core\Event\CurrencyCreateEvent;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Core\Security\Exception\AuthorizationException;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Form\CurrencyModificationForm;
|
||||
use Thelia\Form\CurrencyCreationForm;
|
||||
|
||||
/**
|
||||
* Manages currencies sent by mail
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class CurrencyController extends BaseAdminController
|
||||
{
|
||||
/**
|
||||
* Render the currencies list, ensuring the sort order is set.
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
protected function renderList() {
|
||||
|
||||
// Find the current order
|
||||
$order = $this->getRequest()->get(
|
||||
'order',
|
||||
$this->getSession()->get('admin.currency_order', 'manual')
|
||||
);
|
||||
|
||||
// Store the current sort order in session
|
||||
$this->getSession()->set('admin.currency_order', $order);
|
||||
|
||||
return $this->render('currencies', array('order' => $order));
|
||||
}
|
||||
|
||||
/**
|
||||
* The default action is displaying the currencies list.
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
public function defaultAction() {
|
||||
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.currencies.view")) return $response;
|
||||
|
||||
return $this->renderList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new currency object
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
public function createAction() {
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.currencies.create")) return $response;
|
||||
|
||||
$currency = false;
|
||||
|
||||
// Create the Creation Form
|
||||
$creationForm = new CurrencyCreationForm($this->getRequest());
|
||||
|
||||
try {
|
||||
|
||||
// Validate the form, create the CurrencyCreation event and dispatch it.
|
||||
$form = $this->validateForm($creationForm, "POST");
|
||||
|
||||
$data = $form->getData();
|
||||
|
||||
$createEvent = new CurrencyCreateEvent();
|
||||
|
||||
$createEvent
|
||||
->setCurrencyName($data['name'])
|
||||
->setLocale($data["locale"])
|
||||
->setSymbol($data['symbol'])
|
||||
;
|
||||
|
||||
$this->dispatch(TheliaEvents::CURRENCY_CREATE, $createEvent);
|
||||
|
||||
$createdObject = $createEvent->getCurrency();
|
||||
|
||||
// Log currency creation
|
||||
$this->adminLogAppend(sprintf("Variable %s (ID %s) created", $createdObject->getName(), $createdObject->getId()));
|
||||
|
||||
// Substitute _ID_ in the URL with the ID of the created object
|
||||
$successUrl = str_replace('_ID_', $createdObject->getId(), $creationForm->getSuccessUrl());
|
||||
|
||||
// Redirect to the success URL
|
||||
$this->redirect($successUrl);
|
||||
}
|
||||
catch (FormValidationException $ex) {
|
||||
// Form cannot be validated
|
||||
$currency = sprintf("Please check your input: %s", $ex->getCurrency());
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$currency = sprintf("Sorry, an error occured: %s", $ex->getCurrency());
|
||||
}
|
||||
|
||||
if ($currency !== false) {
|
||||
// An error has been detected: log it
|
||||
Tlog::getInstance()->error(sprintf("Error during currency creation process : %s. Exception was %s", $currency, $ex->getCurrency()));
|
||||
|
||||
// Mark the form as errored
|
||||
$creationForm->setErrorCurrency($currency);
|
||||
|
||||
// Pass it to the parser, along with the error currency
|
||||
$this->getParserContext()
|
||||
->addForm($creationForm)
|
||||
->setGeneralError($currency)
|
||||
;
|
||||
}
|
||||
|
||||
// At this point, the form has error, and should be redisplayed.
|
||||
return $this->renderList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a currency object for modification, and display the edit template.
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
public function changeAction() {
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.currencies.change")) return $response;
|
||||
|
||||
// Load the currency object
|
||||
$currency = CurrencyQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->findOneById($this->getRequest()->get('currency_id'));
|
||||
|
||||
if ($currency != null) {
|
||||
|
||||
// Prepare the data that will hydrate the form
|
||||
$data = array(
|
||||
'id' => $currency->getId(),
|
||||
'name' => $currency->getName(),
|
||||
'locale' => $currency->getLocale(),
|
||||
'code' => $currency->getCode(),
|
||||
'symbol' => $currency->getSymbol(),
|
||||
'rate' => $currency->getSubject()
|
||||
);
|
||||
|
||||
// Setup the object form
|
||||
$changeForm = new CurrencyModificationForm($this->getRequest(), "form", $data);
|
||||
|
||||
// Pass it to the parser
|
||||
$this->getParserContext()->addForm($changeForm);
|
||||
}
|
||||
|
||||
// Render the edition template.
|
||||
return $this->render('currency-edit', array('currency_id' => $this->getRequest()->get('currency_id')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save changes on a modified currency object, and either go back to the currency list, or stay on the edition page.
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
public function saveChangeAction() {
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.currencies.change")) return $response;
|
||||
|
||||
$currency = false;
|
||||
|
||||
// Create the form from the request
|
||||
$changeForm = new CurrencyModificationForm($this->getRequest());
|
||||
|
||||
// Get the currency ID
|
||||
$currency_id = $this->getRequest()->get('currency_id');
|
||||
|
||||
try {
|
||||
|
||||
// Check the form against constraints violations
|
||||
$form = $this->validateForm($changeForm, "POST");
|
||||
|
||||
// Get the form field values
|
||||
$data = $form->getData();
|
||||
|
||||
$changeEvent = new CurrencyChangeEvent($data['id']);
|
||||
|
||||
// Create and dispatch the change event
|
||||
$changeEvent
|
||||
->setCurrencyName($data['name'])
|
||||
->setLocale($data["locale"])
|
||||
->setSymbol($data['symbol'])
|
||||
->setCode($data['code'])
|
||||
->setRate($data['rate'])
|
||||
;
|
||||
|
||||
$this->dispatch(TheliaEvents::CURRENCY_MODIFY, $changeEvent);
|
||||
|
||||
// Log currency modification
|
||||
$changedObject = $changeEvent->getCurrency();
|
||||
|
||||
$this->adminLogAppend(sprintf("Variable %s (ID %s) modified", $changedObject->getName(), $changedObject->getId()));
|
||||
|
||||
// If we have to stay on the same page, do not redirect to the succesUrl,
|
||||
// just redirect to the edit page again.
|
||||
if ($this->getRequest()->get('save_mode') == 'stay') {
|
||||
$this->redirect(URL::absoluteUrl(
|
||||
"admin/configuration/currencies/change",
|
||||
array('currency_id' => $currency_id)
|
||||
));
|
||||
}
|
||||
|
||||
// Redirect to the success URL
|
||||
$this->redirect($changeForm->getSuccessUrl());
|
||||
}
|
||||
catch (FormValidationException $ex) {
|
||||
// Invalid data entered
|
||||
$currency = sprintf("Please check your input: %s", $ex->getCurrency());
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$currency = sprintf("Sorry, an error occured: %s", $ex->getCurrency());
|
||||
}
|
||||
|
||||
if ($currency !== false) {
|
||||
// Log error currency
|
||||
Tlog::getInstance()->error(sprintf("Error during currency modification process : %s. Exception was %s", $currency, $ex->getCurrency()));
|
||||
|
||||
// Mark the form as errored
|
||||
$changeForm->setErrorCurrency($currency);
|
||||
|
||||
// Pas the form and the error to the parser
|
||||
$this->getParserContext()
|
||||
->addForm($changeForm)
|
||||
->setGeneralError($currency)
|
||||
;
|
||||
}
|
||||
|
||||
// At this point, the form has errors, and should be redisplayed.
|
||||
return $this->render('currency-edit', array('currency_id' => $currency_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a currency object
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
public function deleteAction() {
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.currencies.delete")) return $response;
|
||||
|
||||
// Get the currency id, and dispatch the delet request
|
||||
$event = new CurrencyDeleteEvent($this->getRequest()->get('currency_id'));
|
||||
|
||||
$this->dispatch(TheliaEvents::CURRENCY_DELETE, $event);
|
||||
|
||||
$this->redirect(URL::adminViewUrl('currencies'));
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
<?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\Coupon;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Thelia\Model\Coupon;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/29/13
|
||||
* Time: 3:45 PM
|
||||
*
|
||||
* Occurring when a Coupon is edited
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CouponEditEvent extends ActionEvent
|
||||
{
|
||||
/** @var int Coupon being edited id */
|
||||
protected $couponId;
|
||||
|
||||
/** @var Coupon Coupon being created */
|
||||
protected $editedCoupon;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Coupon $coupon Coupon being edited
|
||||
*/
|
||||
public function __construct(Coupon $coupon)
|
||||
{
|
||||
$this->created_coupon = $coupon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify Coupon being created
|
||||
*
|
||||
* @param Coupon $editedCoupon Coupon being created
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setCreatedCoupon(Coupon $editedCoupon)
|
||||
{
|
||||
$this->editedCoupon = $editedCoupon;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Coupon being created
|
||||
*
|
||||
* @return Coupon
|
||||
*/
|
||||
public function getCreatedCoupon()
|
||||
{
|
||||
return clone $this->editedCoupon;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -22,8 +22,10 @@
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event\Coupon;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
use Thelia\Model\Coupon;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -36,8 +38,11 @@ use Thelia\Coupon\CouponRuleCollection;
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CouponCreateEvent extends ActionEvent
|
||||
class CouponEvent extends ActionEvent
|
||||
{
|
||||
/** @var int Coupon Id */
|
||||
protected $id = null;
|
||||
|
||||
/** @var CouponRuleCollection Array of CouponRuleInterface */
|
||||
protected $rules = null;
|
||||
|
||||
@@ -74,6 +79,72 @@ class CouponCreateEvent extends ActionEvent
|
||||
/** @var bool if Coupon is available for Products already on special offers */
|
||||
protected $isAvailableOnSpecialOffers = false;
|
||||
|
||||
/** @var Coupon Coupon model */
|
||||
protected $coupon = null;
|
||||
|
||||
/** @var string Coupon effect */
|
||||
protected $effect;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $code Coupon Code
|
||||
* @param string $title Coupon title
|
||||
* @param float $amount Amount removed from the Total Checkout
|
||||
* @param string $effect Coupon effect
|
||||
* @param string $shortDescription Coupon short description
|
||||
* @param string $description Coupon description
|
||||
* @param boolean $isEnabled Enable/Disable
|
||||
* @param \DateTime $expirationDate Coupon expiration date
|
||||
* @param boolean $isAvailableOnSpecialOffers Is available on special offers
|
||||
* @param boolean $isCumulative Is cumulative
|
||||
* @param boolean $isRemovingPostage Is removing Postage
|
||||
* @param int $maxUsage Coupon quantity
|
||||
* @param CouponRuleCollection $rules CouponRuleInterface to add
|
||||
* @param int $id Coupon id
|
||||
*/
|
||||
function __construct(
|
||||
$code,
|
||||
$title,
|
||||
$amount,
|
||||
$effect,
|
||||
$shortDescription,
|
||||
$description,
|
||||
$isEnabled,
|
||||
$expirationDate,
|
||||
$isAvailableOnSpecialOffers,
|
||||
$isCumulative,
|
||||
$isRemovingPostage,
|
||||
$maxUsage,
|
||||
$rules,
|
||||
$id = null
|
||||
) {
|
||||
$this->amount = $amount;
|
||||
$this->code = $code;
|
||||
$this->description = $description;
|
||||
$this->expirationDate = $expirationDate;
|
||||
$this->id = $id;
|
||||
$this->isAvailableOnSpecialOffers = $isAvailableOnSpecialOffers;
|
||||
$this->isCumulative = $isCumulative;
|
||||
$this->isEnabled = $isEnabled;
|
||||
$this->isRemovingPostage = $isRemovingPostage;
|
||||
$this->maxUsage = $maxUsage;
|
||||
$this->rules = $rules;
|
||||
$this->shortDescription = $shortDescription;
|
||||
$this->title = $title;
|
||||
$this->effect = $effect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Coupon Id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Coupon code (ex: XMAS)
|
||||
*
|
||||
@@ -156,62 +227,6 @@ class CouponCreateEvent extends ActionEvent
|
||||
return clone $this->rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set effects generated by the coupon
|
||||
*
|
||||
* @param float $amount Amount removed from the Total Checkout
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAmount($amount)
|
||||
{
|
||||
$this->amount = $amount;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Coupon Code
|
||||
*
|
||||
* @param string $code Coupon Code
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setCode($code)
|
||||
{
|
||||
$this->code = $code;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Coupon description
|
||||
*
|
||||
* @param string $description Coupon description
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Coupon expiration date (date given considered as expired)
|
||||
*
|
||||
* @param \DateTime $expirationDate Coupon expiration date
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setExpirationDate($expirationDate)
|
||||
{
|
||||
$this->expirationDate = $expirationDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Coupon expiration date
|
||||
*
|
||||
@@ -222,20 +237,6 @@ class CouponCreateEvent extends ActionEvent
|
||||
return clone $this->expirationDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if Coupon is available on special offers
|
||||
*
|
||||
* @param boolean $isAvailableOnSpecialOffers is available on special offers
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setIsAvailableOnSpecialOffers($isAvailableOnSpecialOffers)
|
||||
{
|
||||
$this->isAvailableOnSpecialOffers = $isAvailableOnSpecialOffers;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* If Coupon is available on special offers
|
||||
*
|
||||
@@ -246,34 +247,6 @@ class CouponCreateEvent extends ActionEvent
|
||||
return $this->isAvailableOnSpecialOffers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the Coupon is cumulative with other Coupons or not
|
||||
*
|
||||
* @param boolean $isCumulative is cumulative
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setIsCumulative($isCumulative)
|
||||
{
|
||||
$this->isCumulative = $isCumulative;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/Disable the Coupon
|
||||
*
|
||||
* @param boolean $isEnabled Enable/Disable
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setIsEnabled($isEnabled)
|
||||
{
|
||||
$this->isEnabled = $isEnabled;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if Coupon is enabled or not
|
||||
*
|
||||
@@ -284,34 +257,6 @@ class CouponCreateEvent extends ActionEvent
|
||||
return $this->isEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if Coupon is removing Postage
|
||||
*
|
||||
* @param boolean $isRemovingPostage is removing Postage
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setIsRemovingPostage($isRemovingPostage)
|
||||
{
|
||||
$this->isRemovingPostage = $isRemovingPostage;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set how many time a coupon can be used (-1 : unlimited)
|
||||
*
|
||||
* @param int $maxUsage Coupon quantity
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setMaxUsage($maxUsage)
|
||||
{
|
||||
$this->maxUsage = $maxUsage;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return how many time the Coupon can be used again
|
||||
* Ex : -1 unlimited
|
||||
@@ -324,51 +269,33 @@ class CouponCreateEvent extends ActionEvent
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the existing Rules by those given in parameter
|
||||
* If one Rule is badly implemented, no Rule will be added
|
||||
* Get Coupon effect
|
||||
*
|
||||
* @param CouponRuleCollection $rules CouponRuleInterface to add
|
||||
*
|
||||
* @return $this
|
||||
* @throws \Thelia\Exception\InvalidRuleException
|
||||
* @return string
|
||||
*/
|
||||
public function setRules(CouponRuleCollection $rules)
|
||||
public function getEffect()
|
||||
{
|
||||
$this->rules = $rules;
|
||||
$this->constraintManager = new ConstraintManager(
|
||||
$this->adapter,
|
||||
$this->rules
|
||||
);
|
||||
return $this->effect;
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
||||
|
||||
/**
|
||||
* @param \Thelia\Model\Coupon $coupon
|
||||
*/
|
||||
public function setCoupon($coupon)
|
||||
{
|
||||
$this->coupon = $coupon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Coupon short description
|
||||
*
|
||||
* @param string $shortDescription Coupon short description
|
||||
*
|
||||
* @return $this
|
||||
* @return \Thelia\Model\Coupon
|
||||
*/
|
||||
public function setShortDescription($shortDescription)
|
||||
public function getCoupon()
|
||||
{
|
||||
$this->shortDescription = $shortDescription;
|
||||
|
||||
return $this;
|
||||
return $this->coupon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Coupon title
|
||||
*
|
||||
* @param string $title Coupon title
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
47
core/lib/Thelia/Core/Event/CurrencyChangeEvent.php
Normal file
47
core/lib/Thelia/Core/Event/CurrencyChangeEvent.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?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;
|
||||
use Thelia\Model\Currency;
|
||||
|
||||
class CurrencyChangeEvent extends CurrencyCreateEvent
|
||||
{
|
||||
protected $currency_id;
|
||||
|
||||
public function __construct($currency_id)
|
||||
{
|
||||
$this->setCurrencyId($currency_id);
|
||||
}
|
||||
|
||||
public function getCurrencyId()
|
||||
{
|
||||
return $this->currency_id;
|
||||
}
|
||||
|
||||
public function setCurrencyId($currency_id)
|
||||
{
|
||||
$this->currency_id = $currency_id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
93
core/lib/Thelia/Core/Event/CurrencyCreateEvent.php
Normal file
93
core/lib/Thelia/Core/Event/CurrencyCreateEvent.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?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;
|
||||
use Thelia\Model\Currency;
|
||||
|
||||
class CurrencyCreateEvent extends CurrencyEvent
|
||||
{
|
||||
protected $currency_name;
|
||||
protected $locale;
|
||||
protected $symbol;
|
||||
protected $code;
|
||||
protected $rate;
|
||||
|
||||
// Use currency_name to prevent conflict with Event::name property.
|
||||
public function getCurrencyName()
|
||||
{
|
||||
return $this->currency_name;
|
||||
}
|
||||
|
||||
public function setCurrencyName($currency_name)
|
||||
{
|
||||
$this->currency_name = $currency_name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLocale()
|
||||
{
|
||||
return $this->locale;
|
||||
}
|
||||
|
||||
public function setLocale($locale)
|
||||
{
|
||||
$this->locale = $locale;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSymbol()
|
||||
{
|
||||
return $this->symbol;
|
||||
}
|
||||
|
||||
public function setSymbol($symbol)
|
||||
{
|
||||
$this->symbol = $symbol;
|
||||
}
|
||||
|
||||
public function getCode()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
public function setCode($code)
|
||||
{
|
||||
$this->code = $code;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRate()
|
||||
{
|
||||
return $this->rate;
|
||||
}
|
||||
|
||||
public function setRate($rate)
|
||||
{
|
||||
$this->rate = $rate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
48
core/lib/Thelia/Core/Event/CurrencyDeleteEvent.php
Normal file
48
core/lib/Thelia/Core/Event/CurrencyDeleteEvent.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?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;
|
||||
|
||||
use Thelia\Model\Currency;
|
||||
|
||||
class CurrencyDeleteEvent extends CurrencyEvent
|
||||
{
|
||||
protected $currency_id;
|
||||
|
||||
public function __construct($currency_id)
|
||||
{
|
||||
$this->setCurrencyId($currency_id);
|
||||
}
|
||||
|
||||
public function getCurrencyId()
|
||||
{
|
||||
return $this->currency_id;
|
||||
}
|
||||
|
||||
public function setCurrencyId($currency_id)
|
||||
{
|
||||
$this->currency_id = $currency_id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
47
core/lib/Thelia/Core/Event/CurrencyEvent.php
Normal file
47
core/lib/Thelia/Core/Event/CurrencyEvent.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?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;
|
||||
use Thelia\Model\Currency;
|
||||
|
||||
class CurrencyEvent extends ActionEvent
|
||||
{
|
||||
protected $currency;
|
||||
|
||||
public function __construct(Currency $currency = null)
|
||||
{
|
||||
$this->currency = $currency;
|
||||
}
|
||||
|
||||
public function getCurrency()
|
||||
{
|
||||
return $this->currency;
|
||||
}
|
||||
|
||||
public function setCurrency($currency)
|
||||
{
|
||||
$this->currency = $currency;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -266,7 +266,6 @@ final class TheliaEvents
|
||||
const BEFORE_DELETECONFIG = "action.before_deleteConfig";
|
||||
const AFTER_DELETECONFIG = "action.after_deleteConfig";
|
||||
|
||||
|
||||
// -- Messages management ---------------------------------------------
|
||||
|
||||
const MESSAGE_CREATE = "action.createMessage";
|
||||
@@ -282,4 +281,18 @@ final class TheliaEvents
|
||||
const BEFORE_DELETEMESSAGE = "action.before_deleteMessage";
|
||||
const AFTER_DELETEMESSAGE = "action.after_deleteMessage";
|
||||
|
||||
// -- Currencies management ---------------------------------------------
|
||||
|
||||
const CURRENCY_CREATE = "action.createCurrency";
|
||||
const CURRENCY_MODIFY = "action.changeCurrency";
|
||||
const CURRENCY_DELETE = "action.deleteCurrency";
|
||||
|
||||
const BEFORE_CREATECURRENCY = "action.before_createCurrency";
|
||||
const AFTER_CREATECURRENCY = "action.after_createCurrency";
|
||||
|
||||
const BEFORE_CHANGECURRENCY = "action.before_changeCurrency";
|
||||
const AFTER_CHANGECURRENCY = "action.after_changeCurrency";
|
||||
|
||||
const BEFORE_DELETECURRENCY = "action.before_deleteCurrency";
|
||||
const AFTER_DELETECURRENCY = "action.after_deleteCurrency";
|
||||
}
|
||||
|
||||
@@ -55,12 +55,15 @@ class Session extends BaseSession
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Model\Lang|null
|
||||
*/
|
||||
public function getLang()
|
||||
{
|
||||
return $this->get("lang", substr($this->getLocale(), 0, 2));
|
||||
return $this->get("lang");
|
||||
}
|
||||
|
||||
public function setLang($lang)
|
||||
public function setLang(Lang $lang)
|
||||
{
|
||||
$this->set("lang", $lang);
|
||||
|
||||
|
||||
@@ -109,13 +109,13 @@ class Config extends BaseI18nLoop
|
||||
->set("NAME" , $result->getName())
|
||||
->set("VALUE" , $result->getValue())
|
||||
->set("IS_TRANSLATED", $result->getVirtualColumn('IS_TRANSLATED'))
|
||||
->set("LOCALE",$locale)
|
||||
->set("LOCALE" , $locale)
|
||||
->set("TITLE" , $result->getVirtualColumn('i18n_TITLE'))
|
||||
->set("CHAPO" , $result->getVirtualColumn('i18n_CHAPO'))
|
||||
->set("DESCRIPTION" , $result->getVirtualColumn('i18n_DESCRIPTION'))
|
||||
->set("POSTSCRIPTUM" , $result->getVirtualColumn('i18n_POSTSCRIPTUM'))
|
||||
->set("HIDDEN" , $result->getHidden())
|
||||
->set("SECURED" , $result->getSecured())
|
||||
->set("SECURED" , $result->getSecured())
|
||||
->set("CREATE_DATE" , $result->getCreatedAt())
|
||||
->set("UPDATE_DATE" , $result->getUpdatedAt())
|
||||
;
|
||||
|
||||
@@ -33,6 +33,8 @@ use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Type\TypeCollection;
|
||||
use Thelia\Type\EnumListType;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -53,7 +55,22 @@ class Currency extends BaseI18nLoop
|
||||
return new ArgumentCollection(
|
||||
Argument::createIntListTypeArgument('id'),
|
||||
Argument::createIntListTypeArgument('exclude'),
|
||||
Argument::createBooleanTypeArgument('default_only', false)
|
||||
Argument::createBooleanTypeArgument('default_only', false),
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
new EnumListType(
|
||||
array(
|
||||
'id', 'id_reverse',
|
||||
'name', 'name_reverse',
|
||||
'code', 'code_reverse',
|
||||
'symbol', 'symbol_reverse',
|
||||
'rate', 'rate_reverse',
|
||||
'manual', 'manual_reverse')
|
||||
)
|
||||
),
|
||||
'manual'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -87,7 +104,53 @@ class Currency extends BaseI18nLoop
|
||||
$search->filterByByDefault(true);
|
||||
}
|
||||
|
||||
$search->orderByPosition();
|
||||
$orders = $this->getOrder();
|
||||
|
||||
foreach($orders as $order) {
|
||||
switch ($order) {
|
||||
case 'id':
|
||||
$search->orderById(Criteria::ASC);
|
||||
break;
|
||||
case 'id_reverse':
|
||||
$search->orderById(Criteria::DESC);
|
||||
break;
|
||||
|
||||
case 'name':
|
||||
$search->addAscendingOrderByColumn('i18n_NAME');
|
||||
break;
|
||||
case 'name_reverse':
|
||||
$search->addDescendingOrderByColumn('i18n_NAME');
|
||||
break;
|
||||
|
||||
case 'code':
|
||||
$search->orderByCode(Criteria::ASC);
|
||||
break;
|
||||
case 'code_reverse':
|
||||
$search->orderByCode(Criteria::DESC);
|
||||
break;
|
||||
|
||||
case 'symbol':
|
||||
$search->orderBySymbol(Criteria::ASC);
|
||||
break;
|
||||
case 'symbol_reverse':
|
||||
$search->orderBySymbol(Criteria::DESC);
|
||||
break;
|
||||
|
||||
case 'rate':
|
||||
$search->orderByRate(Criteria::ASC);
|
||||
break;
|
||||
case 'rate_reverse':
|
||||
$search->orderByRate(Criteria::DESC);
|
||||
break;
|
||||
|
||||
case 'manual':
|
||||
$search->orderByPosition(Criteria::ASC);
|
||||
break;
|
||||
case 'manual_reverse':
|
||||
$search->orderByPosition(Criteria::DESC);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* perform search */
|
||||
$currencies = $this->search($search, $pagination);
|
||||
@@ -95,15 +158,18 @@ class Currency extends BaseI18nLoop
|
||||
$loopResult = new LoopResult();
|
||||
|
||||
foreach ($currencies as $currency) {
|
||||
|
||||
$loopResultRow = new LoopResultRow();
|
||||
$loopResultRow->set("ID", $currency->getId())
|
||||
->set("IS_TRANSLATED",$currency->getVirtualColumn('IS_TRANSLATED'))
|
||||
->set("LOCALE",$locale)
|
||||
->set("NAME",$currency->getVirtualColumn('i18n_NAME'))
|
||||
->set("ISOCODE", $currency->getCode())
|
||||
->set("SYMBOL", $currency->getSymbol())
|
||||
->set("RATE", $currency->getRate())
|
||||
->set("IS_DEFAULT", $currency->getByDefault());
|
||||
$loopResultRow
|
||||
->set("ID" , $currency->getId())
|
||||
->set("IS_TRANSLATED" , $currency->getVirtualColumn('IS_TRANSLATED'))
|
||||
->set("LOCALE" , $locale)
|
||||
->set("NAME" , $currency->getVirtualColumn('i18n_NAME'))
|
||||
->set("ISOCODE" , $currency->getCode())
|
||||
->set("SYMBOL" , $currency->getSymbol())
|
||||
->set("RATE" , $currency->getRate())
|
||||
->set("POSITION" , $currency->getPosition())
|
||||
->set("IS_DEFAULT" , $currency->getByDefault());
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
|
||||
@@ -50,6 +50,60 @@ class Image extends BaseI18nLoop
|
||||
*/
|
||||
protected $possible_sources = array('category', 'product', 'folder', 'content');
|
||||
|
||||
/**
|
||||
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
|
||||
*/
|
||||
protected function getArgDefinitions()
|
||||
{
|
||||
$collection = new ArgumentCollection(
|
||||
|
||||
Argument::createIntListTypeArgument('id'),
|
||||
Argument::createIntListTypeArgument('exclude'),
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
new EnumListType(array('alpha', 'alpha-reverse', 'manual', 'manual-reverse', 'random'))
|
||||
),
|
||||
'manual'
|
||||
),
|
||||
Argument::createIntTypeArgument('lang'),
|
||||
|
||||
Argument::createIntTypeArgument('width'),
|
||||
Argument::createIntTypeArgument('height'),
|
||||
Argument::createIntTypeArgument('rotation', 0),
|
||||
Argument::createAnyTypeArgument('background_color'),
|
||||
Argument::createIntTypeArgument('quality'),
|
||||
new Argument(
|
||||
'resize_mode',
|
||||
new TypeCollection(
|
||||
new EnumType(array('crop', 'borders', 'none'))
|
||||
),
|
||||
'none'
|
||||
),
|
||||
Argument::createAnyTypeArgument('effects'),
|
||||
|
||||
Argument::createIntTypeArgument('category'),
|
||||
Argument::createIntTypeArgument('product'),
|
||||
Argument::createIntTypeArgument('folder'),
|
||||
Argument::createIntTypeArgument('content'),
|
||||
|
||||
new Argument(
|
||||
'source',
|
||||
new TypeCollection(
|
||||
new EnumType($this->possible_sources)
|
||||
)
|
||||
),
|
||||
Argument::createIntTypeArgument('source_id')
|
||||
);
|
||||
|
||||
// Add possible image sources
|
||||
foreach($this->possible_sources as $source) {
|
||||
$collection->addArgument(Argument::createIntTypeArgument($source));
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically create the search query, and set the proper filter and order
|
||||
*
|
||||
@@ -244,19 +298,19 @@ class Image extends BaseI18nLoop
|
||||
$loopResultRow = new LoopResultRow();
|
||||
|
||||
$loopResultRow
|
||||
->set("ID", $result->getId())
|
||||
->set("LOCALE",$locale)
|
||||
->set("IMAGE_URL", $event->getFileUrl())
|
||||
->set("ORIGINAL_IMAGE_URL", $event->getOriginalFileUrl())
|
||||
->set("IMAGE_PATH", $event->getCacheFilepath())
|
||||
->set("ORIGINAL_IMAGE_PATH", $source_filepath)
|
||||
->set("TITLE",$folder->getVirtualColumn('i18n_TITLE'))
|
||||
->set("CHAPO", $folder->getVirtualColumn('i18n_CHAPO'))
|
||||
->set("DESCRIPTION", $folder->getVirtualColumn('i18n_DESCRIPTION'))
|
||||
->set("POSTSCRIPTUM", $folder->getVirtualColumn('i18n_POSTSCRIPTUM'))
|
||||
->set("POSITION", $result->getPosition())
|
||||
->set("OBJECT_TYPE", $object_type)
|
||||
->set("OBJECT_ID", $object_id)
|
||||
->set("ID" , $result->getId())
|
||||
->set("LOCALE" ,$locale)
|
||||
->set("IMAGE_URL" , $event->getFileUrl())
|
||||
->set("ORIGINAL_IMAGE_URL" , $event->getOriginalFileUrl())
|
||||
->set("IMAGE_PATH" , $event->getCacheFilepath())
|
||||
->set("ORIGINAL_IMAGE_PATH" , $source_filepath)
|
||||
->set("TITLE" , $result->getVirtualColumn('i18n_TITLE'))
|
||||
->set("CHAPO" , $result->getVirtualColumn('i18n_CHAPO'))
|
||||
->set("DESCRIPTION" , $result->getVirtualColumn('i18n_DESCRIPTION'))
|
||||
->set("POSTSCRIPTUM" , $result->getVirtualColumn('i18n_POSTSCRIPTUM'))
|
||||
->set("POSITION" , $result->getPosition())
|
||||
->set("OBJECT_TYPE" , $object_type)
|
||||
->set("OBJECT_ID" , $object_id)
|
||||
;
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
@@ -269,58 +323,4 @@ class Image extends BaseI18nLoop
|
||||
|
||||
return $loopResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
|
||||
*/
|
||||
protected function getArgDefinitions()
|
||||
{
|
||||
$collection = new ArgumentCollection(
|
||||
|
||||
Argument::createIntListTypeArgument('id'),
|
||||
Argument::createIntListTypeArgument('exclude'),
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
new EnumListType(array('alpha', 'alpha-reverse', 'manual', 'manual-reverse', 'random'))
|
||||
),
|
||||
'manual'
|
||||
),
|
||||
Argument::createIntTypeArgument('lang'),
|
||||
|
||||
Argument::createIntTypeArgument('width'),
|
||||
Argument::createIntTypeArgument('height'),
|
||||
Argument::createIntTypeArgument('rotation', 0),
|
||||
Argument::createAnyTypeArgument('background_color'),
|
||||
Argument::createIntTypeArgument('quality'),
|
||||
new Argument(
|
||||
'resize_mode',
|
||||
new TypeCollection(
|
||||
new EnumType(array('crop', 'borders', 'none'))
|
||||
),
|
||||
'none'
|
||||
),
|
||||
Argument::createAnyTypeArgument('effects'),
|
||||
|
||||
Argument::createIntTypeArgument('category'),
|
||||
Argument::createIntTypeArgument('product'),
|
||||
Argument::createIntTypeArgument('folder'),
|
||||
Argument::createIntTypeArgument('content'),
|
||||
|
||||
new Argument(
|
||||
'source',
|
||||
new TypeCollection(
|
||||
new EnumType($this->possible_sources)
|
||||
)
|
||||
),
|
||||
Argument::createIntTypeArgument('source_id')
|
||||
);
|
||||
|
||||
// Add possible image sources
|
||||
foreach($this->possible_sources as $source) {
|
||||
$collection->addArgument(Argument::createIntTypeArgument($source));
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?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\Smarty\Exception;
|
||||
|
||||
|
||||
/**
|
||||
* Class SmartyPluginException
|
||||
* @package Thelia\Core\Template\Smarty\Exception
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class SmartyPluginException extends \SmartyException
|
||||
{}
|
||||
154
core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php
Normal file
154
core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?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\Smarty\Plugins;
|
||||
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||
use Thelia\Core\Template\Smarty\Exception\SmartyPluginException;
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||
|
||||
/**
|
||||
*
|
||||
* format_date and format_date smarty function.
|
||||
*
|
||||
* Class Format
|
||||
* @package Thelia\Core\Template\Smarty\Plugins
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class Format extends AbstractSmartyPlugin
|
||||
{
|
||||
protected $request;
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* return date in expected format
|
||||
*
|
||||
* available parameters :
|
||||
* date => DateTime object (mandatory)
|
||||
* format => expected format
|
||||
* output => list of default system format. Values available :
|
||||
* date => date format
|
||||
* time => time format
|
||||
* datetime => datetime format (default)
|
||||
*
|
||||
* ex :
|
||||
* {format_date date=$dateTimeObject format="Y-m-d H:i:s"} will output the format with specific format
|
||||
* {format_date date=$dateTimeObject output="date"} will output the date using the default date system format
|
||||
* {format_date date=$dateTimeObject} will output with the default datetime system format
|
||||
*
|
||||
* @param array $params
|
||||
* @param null $template
|
||||
* @throws \Thelia\Core\Template\Smarty\Exception\SmartyPluginException
|
||||
* @return string
|
||||
*/
|
||||
public function formatDate($params, $template = null)
|
||||
{
|
||||
|
||||
if (array_key_exists("date", $params) === false) {
|
||||
throw new SmartyPluginException("date is a mandatory parameter in format_date function");
|
||||
}
|
||||
|
||||
$date = $params["date"];
|
||||
|
||||
if(!$date instanceof \DateTime) {
|
||||
return "";
|
||||
}
|
||||
|
||||
$format = null;
|
||||
$output = array_key_exists("output", $params) ? $params["output"] : null;
|
||||
|
||||
if (array_key_exists("format", $params)) {
|
||||
$format = $params["format"];
|
||||
} else {
|
||||
$session = $this->request->getSession();
|
||||
$lang = $session->getLang();
|
||||
|
||||
if($lang) {
|
||||
switch ($output) {
|
||||
case "date" :
|
||||
$format = $lang->getDateFormat();
|
||||
break;
|
||||
case "time" :
|
||||
$format = $lang->getTimeFormat();
|
||||
break;
|
||||
default:
|
||||
case "datetime" :
|
||||
$format = $lang->getDateTimeFormat();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $date->format($format);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* display numbers in expected format
|
||||
*
|
||||
* available parameters :
|
||||
* number => int or float number
|
||||
* decimals => how many decimals format expected
|
||||
* dec_point => separator for the decimal point
|
||||
* thousands_sep => thousands separator
|
||||
*
|
||||
* ex : {format_number number="1246.12" decimals="1" dec_point="," thousands_sep=" "} will output "1 246,1"
|
||||
*
|
||||
* @param $params
|
||||
* @param null $template
|
||||
* @throws \Thelia\Core\Template\Smarty\Exception\SmartyPluginException
|
||||
* @return string the expected number formatted
|
||||
*/
|
||||
public function formatNumber($params, $template = null)
|
||||
{
|
||||
if (array_key_exists("number", $params) === false) {
|
||||
throw new SmartyPluginException("number is a mandatory parameter in format_number function");
|
||||
}
|
||||
|
||||
$lang = $this->request->getSession()->getLang();
|
||||
|
||||
$number = $params["number"];
|
||||
$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 an array of SmartyPluginDescriptor
|
||||
*/
|
||||
public function getPluginDescriptors()
|
||||
{
|
||||
return array(
|
||||
new SmartyPluginDescriptor("function", "format_date", $this, "formatDate"),
|
||||
new SmartyPluginDescriptor("function", "format_number", $this, "formatNumber")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -126,7 +126,7 @@ class TheliaHttpKernel extends HttpKernel
|
||||
|
||||
if ($lang) {
|
||||
$request->getSession()
|
||||
->setLang($lang->getCode())
|
||||
->setLang($lang)
|
||||
->setLocale($lang->getLocale())
|
||||
;
|
||||
}
|
||||
|
||||
@@ -47,109 +47,92 @@ class CouponCreationForm extends BaseForm
|
||||
{
|
||||
$this->formBuilder
|
||||
->add(
|
||||
"code",
|
||||
"text",
|
||||
'code',
|
||||
'text',
|
||||
array(
|
||||
"constraints" => array(
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
"type",
|
||||
"text",
|
||||
'title',
|
||||
'text',
|
||||
array(
|
||||
"constraints" => array(
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
"title",
|
||||
"text",
|
||||
'shortDescription',
|
||||
'text',
|
||||
array(
|
||||
"constraints" => array(
|
||||
'invalid_message' => 'test',
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
"shortDescription",
|
||||
"text",
|
||||
'description',
|
||||
'textarea',
|
||||
array(
|
||||
"constraints" => array(
|
||||
'invalid_message' => 'test',
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
"description",
|
||||
"text",
|
||||
'effect',
|
||||
'text',
|
||||
array(
|
||||
"constraints" => array(
|
||||
'invalid_message' => 'test',
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
"amount",
|
||||
"text",
|
||||
'amount',
|
||||
'money',
|
||||
array()
|
||||
)
|
||||
->add(
|
||||
'isEnabled',
|
||||
'checkbox',
|
||||
array()
|
||||
)
|
||||
->add(
|
||||
'expirationDate',
|
||||
'text',
|
||||
array(
|
||||
"constraints" => array(
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
"isEnabled",
|
||||
"text",
|
||||
array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
'isCumulative',
|
||||
'checkbox',
|
||||
array()
|
||||
)
|
||||
->add(
|
||||
"expirationDate",
|
||||
"text",
|
||||
array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
'isRemovingPostage',
|
||||
'checkbox',
|
||||
array()
|
||||
)
|
||||
->add(
|
||||
"isCumulative",
|
||||
"text",
|
||||
array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
'isAvailableOnSpecialOffers',
|
||||
'checkbox',
|
||||
array()
|
||||
)
|
||||
->add(
|
||||
"isRemovingPostage",
|
||||
"text",
|
||||
'maxUsage',
|
||||
'text',
|
||||
array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
"maxUsage",
|
||||
"text",
|
||||
array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
"isAvailableOnSpecialOffers",
|
||||
"text",
|
||||
array(
|
||||
"constraints" => array(
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
@@ -163,6 +146,6 @@ class CouponCreationForm extends BaseForm
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return "thelia_coupon_creation";
|
||||
return 'thelia_coupon_creation';
|
||||
}
|
||||
}
|
||||
|
||||
65
core/lib/Thelia/Form/CurrencyCreationForm.php
Normal file
65
core/lib/Thelia/Form/CurrencyCreationForm.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?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\Form;
|
||||
|
||||
use Symfony\Component\Validator\Constraints;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
|
||||
class CurrencyCreationForm extends BaseForm
|
||||
{
|
||||
protected function buildForm($change_mode = false)
|
||||
{
|
||||
$name_constraints = array(new Constraints\NotBlank());
|
||||
|
||||
if (!$change_mode) {
|
||||
$name_constraints[] = new Constraints\Callback(array(
|
||||
"methods" => array(array($this, "checkDuplicateName"))
|
||||
));
|
||||
}
|
||||
|
||||
$this->formBuilder
|
||||
->add("name" , "text" , array("constraints" => array($name_constraints)))
|
||||
->add("locale" , "text" , array())
|
||||
->add("symbol" , "text" , array("constraints" => array(new NotBlank())))
|
||||
->add("rate" , "text" , array("constraints" => array(new NotBlank())))
|
||||
->add("code" , "text" , array("constraints" => array(new NotBlank())))
|
||||
;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return "thelia_currency_creation";
|
||||
}
|
||||
|
||||
public function checkDuplicateName($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$currency = CurrencyQuery::create()->findOneByName($value);
|
||||
|
||||
if ($currency) {
|
||||
$context->addViolation(sprintf("A currency with name \"%s\" already exists.", $value));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
45
core/lib/Thelia/Form/CurrencyModificationForm.php
Normal file
45
core/lib/Thelia/Form/CurrencyModificationForm.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?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\Form;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Thelia\Model\LangQuery;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Symfony\Component\Validator\Constraints\GreaterThan;
|
||||
|
||||
class CurrencyModificationForm extends CurrencyCreationForm
|
||||
{
|
||||
protected function buildForm()
|
||||
{
|
||||
parent::buildForm(true);
|
||||
|
||||
$this->formBuilder
|
||||
->add("id" , "hidden", array("constraints" => array(new GreaterThan(array('value' => 0)))))
|
||||
;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return "thelia_currency_modification";
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,65 @@
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Thelia\Model\Base\Currency as BaseCurrency;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
use Thelia\Core\Event\CurrencyEvent;
|
||||
|
||||
class Currency extends BaseCurrency {
|
||||
|
||||
}
|
||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_CREATECURRENCY, new CurrencyEvent($this));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function postInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::AFTER_CREATECURRENCY, new CurrencyEvent($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preUpdate(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_CHANGECURRENCY, new CurrencyEvent($this));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function postUpdate(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::AFTER_CHANGECURRENCY, new CurrencyEvent($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preDelete(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_DELETECURRENCY, new CurrencyEvent($this));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function postDelete(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::AFTER_DELETECURRENCY, new CurrencyEvent($this));
|
||||
}
|
||||
}
|
||||
@@ -24,15 +24,33 @@ class Lang extends BaseLang {
|
||||
return $default_lang;
|
||||
}
|
||||
|
||||
public function getDateFormat() {
|
||||
public function getDateFormat()
|
||||
{
|
||||
return "d/m/Y";
|
||||
}
|
||||
|
||||
public function getTimeFormat() {
|
||||
public function getTimeFormat()
|
||||
{
|
||||
return "H:i:s";
|
||||
}
|
||||
|
||||
public function getDateTimeFormat() {
|
||||
public function getDateTimeFormat()
|
||||
{
|
||||
return "d/m/Y H:i:s";
|
||||
}
|
||||
|
||||
public function getDecimalSeparator()
|
||||
{
|
||||
return ".";
|
||||
}
|
||||
|
||||
public function getThousandsSeparator()
|
||||
{
|
||||
return " ";
|
||||
}
|
||||
|
||||
public function getDecimals()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,274 @@
|
||||
<?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\Tests\Core\Smarty\Plugins;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Core\Template\Smarty\Plugins\Format;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Thelia\Core\Template\Smarty\Plugins\Format
|
||||
*/
|
||||
class FormatTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $request;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->request = new Request();
|
||||
|
||||
$this->request->setSession(new Session(new MockArraySessionStorage()));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* test formatDate method with expected format
|
||||
*
|
||||
* @covers ::formatDate
|
||||
*/
|
||||
public function testFormatDateWithSpecificFormat()
|
||||
{
|
||||
$dateTime = new \DateTime();
|
||||
$format = "Y-m-d H:i:s";
|
||||
|
||||
$formatClass = new Format($this->request);
|
||||
|
||||
$render = $formatClass->formatDate(array(
|
||||
"date" => $dateTime,
|
||||
"format" => $format
|
||||
));
|
||||
|
||||
$this->assertEquals($dateTime->format($format), $render);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* test formatDate method with date default format
|
||||
*
|
||||
* @covers ::formatDate
|
||||
*/
|
||||
public function testFormatDateWithDefaultSessionParam()
|
||||
{
|
||||
$dateTime = new \DateTime();
|
||||
|
||||
$langMock = $this->getLangMock();
|
||||
$this->request->getSession()->setLang($langMock);
|
||||
|
||||
$formatClass = new Format($this->request);
|
||||
|
||||
$render = $formatClass->formatDate(array("date" => $dateTime));
|
||||
|
||||
$this->assertEquals($dateTime->format("Y-m-d H:i:s"), $render);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* test formatDate method with time default format
|
||||
*
|
||||
* @covers ::formatDate
|
||||
*/
|
||||
public function testFormatDateWithDateSessionParam()
|
||||
{
|
||||
$dateTime = new \DateTime();
|
||||
|
||||
$langMock = $this->getLangMock();
|
||||
$this->request->getSession()->setLang($langMock);
|
||||
|
||||
$formatClass = new Format($this->request);
|
||||
|
||||
$render = $formatClass->formatDate(array(
|
||||
"date" => $dateTime,
|
||||
"output" => "date"
|
||||
));
|
||||
|
||||
$this->assertEquals($dateTime->format("Y-m-d"), $render);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* test formatDate method with datetime default format
|
||||
*
|
||||
* @covers ::formatDate
|
||||
*/
|
||||
public function testFormatDateWithTimeSessionParam()
|
||||
{
|
||||
$dateTime = new \DateTime();
|
||||
|
||||
$langMock = $this->getLangMock();
|
||||
$this->request->getSession()->setLang($langMock);
|
||||
|
||||
$formatClass = new Format($this->request);
|
||||
|
||||
$render = $formatClass->formatDate(array(
|
||||
"date" => $dateTime,
|
||||
"output" => "time"
|
||||
));
|
||||
|
||||
$this->assertEquals($dateTime->format("H:i:s"), $render);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* test formatDate method without output or expected format. datetime format must be return
|
||||
*
|
||||
* @covers ::formatDate
|
||||
*/
|
||||
public function testFormatDateWithDateTimeSessionParam()
|
||||
{
|
||||
$dateTime = new \DateTime();
|
||||
|
||||
$langMock = $this->getLangMock();
|
||||
$this->request->getSession()->setLang($langMock);
|
||||
|
||||
$formatClass = new Format($this->request);
|
||||
|
||||
$render = $formatClass->formatDate(array(
|
||||
"date" => $dateTime,
|
||||
"output" => "datetime"
|
||||
));
|
||||
|
||||
$this->assertEquals($dateTime->format("Y-m-d H:i:s"), $render);
|
||||
}
|
||||
|
||||
/**
|
||||
* test formatDate without mandatory parameters
|
||||
*
|
||||
* @covers ::formatDate
|
||||
* @expectedException \Thelia\Core\Template\Smarty\Exception\SmartyPluginException
|
||||
*/
|
||||
public function testFormatDateWithoutDate()
|
||||
{
|
||||
$dateTime = new \DateTime();
|
||||
|
||||
$formatClass = new Format($this->request);
|
||||
|
||||
$render = $formatClass->formatDate(array());
|
||||
|
||||
$this->assertEquals($dateTime->format("Y-m-d H:i:s"), $render);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test formatNumber without mandatory parameters
|
||||
*
|
||||
* @covers ::formatNumber
|
||||
* @expectedException \Thelia\Core\Template\Smarty\Exception\SmartyPluginException
|
||||
*/
|
||||
public function testFormatNumberWithoutParams()
|
||||
{
|
||||
$formatClass = new Format($this->request);
|
||||
|
||||
$render = $formatClass->formatNumber(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* test formatDate specifying all parameters
|
||||
*
|
||||
* @covers ::formatNumber
|
||||
*/
|
||||
public function testFormatNumberWithAllParams()
|
||||
{
|
||||
$formatClass = new Format($this->request);
|
||||
|
||||
$number = 1256.12;
|
||||
$decimals = 1;
|
||||
$decPoint = ",";
|
||||
$thousandsSep = " ";
|
||||
|
||||
$render = $formatClass->formatNumber(array(
|
||||
"number" => $number,
|
||||
"decimals" => $decimals,
|
||||
"dec_point" => $decPoint,
|
||||
"thousands_sep" => $thousandsSep
|
||||
));
|
||||
|
||||
$this->assertEquals($render, "1 256,1");
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::formatNumber
|
||||
*/
|
||||
public function testFormatNumberWithDefaultParameters()
|
||||
{
|
||||
$number = 1234.56;
|
||||
$langMock = $this->getLangMock();
|
||||
$this->request->getSession()->setLang($langMock);
|
||||
|
||||
$formatClass = new Format($this->request);
|
||||
|
||||
$render = $formatClass->formatNumber(array(
|
||||
"number" => $number
|
||||
));
|
||||
|
||||
$this->assertEquals( $render, number_format($number, 2, ",", " "));
|
||||
}
|
||||
|
||||
/**
|
||||
* create a mock for Thelia\Model\Lang class
|
||||
* @return \Thelia\Model\Lang instance
|
||||
*/
|
||||
public function getLangMock()
|
||||
{
|
||||
$mock = $this->getMock(
|
||||
"Thelia\Model\Lang",
|
||||
array(
|
||||
"getDateFormat",
|
||||
"getTimeFormat",
|
||||
"getDateTimeFormat",
|
||||
"getDecimalSeparator",
|
||||
"getThousandsSeparator",
|
||||
"getDecimals"
|
||||
)
|
||||
);
|
||||
|
||||
$mock->expects($this->any())
|
||||
->method("getDateFormat")
|
||||
->will($this->returnValue("Y-m-d"));
|
||||
|
||||
$mock->expects($this->any())
|
||||
->method("getTimeFormat")
|
||||
->will($this->returnValue("H:i:s"));
|
||||
|
||||
$mock->expects($this->any())
|
||||
->method("getDateTimeFormat")
|
||||
->will($this->returnValue("Y-m-d H:i:s"));
|
||||
|
||||
$mock->expects($this->any())
|
||||
->method("getDecimals")
|
||||
->will($this->returnValue(2));
|
||||
|
||||
$mock->expects($this->any())
|
||||
->method("getDecimalSeparator")
|
||||
->will($this->returnValue(","));
|
||||
|
||||
$mock->expects($this->any())
|
||||
->method("getThousandsSeparator")
|
||||
->will($this->returnValue(" "));
|
||||
|
||||
return $mock;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user