Merge branch 'master' of https://github.com/thelia/thelia into coupon
# By Manuel Raynaud (22) and others # Via Manuel Raynaud (7) and others * 'master' of https://github.com/thelia/thelia: (32 commits) refactor name for updating actions choose UPDATE word for name actions add update address action and create tests 404 not found management Working Fix unset namespace modify travis script test rewriting exception Fixed minor bug in Currencies Finished currency edition Added route methods address action implementation hot fix rewriting add address create controller and event Added AdminUtilities Smarty plugin, optimized templates update customer model createOrUpdate method update address model fix redirect process in viewListener refactor reset_install script refactor install process, database management in dedicated class ... Conflicts: local/config/schema.xml reset_install.sh
This commit is contained in:
108
core/lib/Thelia/Action/Address.php
Normal file
108
core/lib/Thelia/Action/Address.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?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\Core\Event\AddressCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Model\Address as AddressModel;
|
||||
|
||||
|
||||
/**
|
||||
* Class Address
|
||||
* @package Thelia\Action
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class Address extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
|
||||
public function create(AddressCreateOrUpdateEvent $event)
|
||||
{
|
||||
$address = new AddressModel();
|
||||
$address->setCustomer($event->getCustomer());
|
||||
$this->createOrUpdate($address, $event);
|
||||
}
|
||||
|
||||
public function update(AddressCreateOrUpdateEvent $event)
|
||||
{
|
||||
$addressModel = $event->getAddress();
|
||||
|
||||
$this->createOrUpdate($addressModel, $event);
|
||||
}
|
||||
|
||||
|
||||
protected function createOrUpdate(AddressModel $addressModel, AddressCreateOrUpdateEvent $event)
|
||||
{
|
||||
$addressModel->setDispatcher($this->getDispatcher());
|
||||
|
||||
if ($addressModel->isNew()) {
|
||||
$addressModel->setLabel($event->getLabel());
|
||||
}
|
||||
|
||||
$addressModel
|
||||
->setTitleId($event->getTitle())
|
||||
->setFirstname($event->getFirstname())
|
||||
->setLastname($event->getLastname())
|
||||
->setAddress1($event->getAddress1())
|
||||
->setAddress2($event->getAddress2())
|
||||
->setAddress3($event->getAddress3())
|
||||
->setZipcode($event->getZipcode())
|
||||
->setCity($event->getCity())
|
||||
->setCountryId($event->getCountry())
|
||||
->setCellphone($event->getCellphone())
|
||||
->setPhone($event->getPhone())
|
||||
->setCompany($event->getCompany())
|
||||
->save()
|
||||
;
|
||||
|
||||
$event->setAddress($addressModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of event names this subscriber wants to listen to.
|
||||
*
|
||||
* The array keys are event names and the value can be:
|
||||
*
|
||||
* * The method name to call (priority defaults to 0)
|
||||
* * An array composed of the method name to call and the priority
|
||||
* * An array of arrays composed of the method names to call and respective
|
||||
* priorities, or 0 if unset
|
||||
*
|
||||
* For instance:
|
||||
*
|
||||
* * array('eventName' => 'methodName')
|
||||
* * array('eventName' => array('methodName', $priority))
|
||||
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
|
||||
*
|
||||
* @return array The event names to listen to
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
TheliaEvents::ADDRESS_CREATE => array("create", 128),
|
||||
TheliaEvents::ADDRESS_UPDATE => array("update", 128)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,7 @@ class Category extends BaseAction implements EventSubscriberInterface
|
||||
);
|
||||
}
|
||||
|
||||
public function modify(CategoryChangeEvent $event)
|
||||
public function update(CategoryChangeEvent $event)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@ class Category extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
return array(
|
||||
TheliaEvents::CATEGORY_CREATE => array("create", 128),
|
||||
TheliaEvents::CATEGORY_MODIFY => array("modify", 128),
|
||||
TheliaEvents::CATEGORY_UPDATE => array("update", 128),
|
||||
TheliaEvents::CATEGORY_DELETE => array("delete", 128),
|
||||
|
||||
TheliaEvents::CATEGORY_TOGGLE_VISIBILITY => array("toggleVisibility", 128),
|
||||
|
||||
@@ -148,7 +148,7 @@ class Config extends BaseAction implements EventSubscriberInterface
|
||||
return array(
|
||||
TheliaEvents::CONFIG_CREATE => array("create", 128),
|
||||
TheliaEvents::CONFIG_SETVALUE => array("setValue", 128),
|
||||
TheliaEvents::CONFIG_MODIFY => array("modify", 128),
|
||||
TheliaEvents::CONFIG_UPDATE => array("modify", 128),
|
||||
TheliaEvents::CONFIG_DELETE => array("delete", 128),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -24,25 +24,12 @@
|
||||
namespace Thelia\Action;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Thelia\Core\Event\Coupon\CouponCreateEvent;
|
||||
use Thelia\Core\Event\Coupon\CouponDisableEvent;
|
||||
use Thelia\Core\Event\Coupon\CouponEnableEvent;
|
||||
use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Model\Category as CategoryModel;
|
||||
use Thelia\Form\CategoryCreationForm;
|
||||
use Thelia\Core\Event\CategoryEvent;
|
||||
use Thelia\Model\CouponQuery;
|
||||
use Thelia\Tools\Redirect;
|
||||
use Thelia\Model\CategoryQuery;
|
||||
use Thelia\Model\AdminLog;
|
||||
use Thelia\Form\CategoryDeletionForm;
|
||||
use Thelia\Action\Exception\FormValidationException;
|
||||
|
||||
use Thelia\Model\Coupon as CouponModel;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Propel\Runtime\Propel;
|
||||
use Thelia\Model\Map\CategoryTableMap;
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -58,102 +45,57 @@ use Propel\Runtime\Exception\PropelException;
|
||||
class Coupon extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* Create a Coupon if a Coupon creation attempt is found
|
||||
* Occurring when a Coupon is about to be created
|
||||
*
|
||||
* @param CouponCreateEvent $event Coupon creation Event
|
||||
* @param CouponCreateOrUpdateEvent $event Event creation or update Event
|
||||
*/
|
||||
public function create(CouponCreateEvent $event)
|
||||
public function create(CouponCreateOrUpdateEvent $event)
|
||||
{
|
||||
$this->checkAuth("ADMIN", "admin.coupon.create");
|
||||
$coupon = new CouponModel();
|
||||
|
||||
$this->dispatch(
|
||||
TheliaEvents::BEFORE_CREATE_COUPON,
|
||||
$event
|
||||
);
|
||||
|
||||
$couponModel = CouponQuery::create();
|
||||
$event->getCreatedCoupon()->save();
|
||||
|
||||
$this->dispatch(
|
||||
TheliaEvents::AFTER_CREATE_COUPON,
|
||||
$event
|
||||
);
|
||||
$this->createOrUpdate($coupon, $event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit a Coupon if a Coupon edition attempt is found
|
||||
* Occurring when a Coupon is about to be updated
|
||||
*
|
||||
* @param CouponEditEvent $event Coupon edition Event
|
||||
* @param CouponCreateOrUpdateEvent $event Event creation or update Event
|
||||
*/
|
||||
public function edit(CouponEditEvent $event)
|
||||
public function update(CouponCreateOrUpdateEvent $event)
|
||||
{
|
||||
$this->checkAuth("ADMIN", "admin.coupon.edit");
|
||||
$coupon = $event->getCoupon();
|
||||
|
||||
$this->dispatch(
|
||||
TheliaEvents::BEFORE_EDIT_COUPON,
|
||||
$event
|
||||
);
|
||||
|
||||
$couponToUpdate = CouponQuery::create()->findPk($event->getId());
|
||||
|
||||
if ($couponToUpdate !== null) {
|
||||
$event->getCreatedCoupon()->save();
|
||||
}
|
||||
|
||||
$this->dispatch(
|
||||
TheliaEvents::AFTER_EDIT_COUPON,
|
||||
$event
|
||||
);
|
||||
$this->createOrUpdate($coupon, $event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable a Coupon if a Coupon disable attempt is found
|
||||
* Call the Model and delegate the create or delete action
|
||||
* Feed the Event with the updated model
|
||||
*
|
||||
* @param CouponDisableEvent $event Coupon disable Event
|
||||
* @param CouponModel $coupon Model to save
|
||||
* @param CouponCreateOrUpdateEvent $event Event containing data
|
||||
*/
|
||||
public function disable(CouponDisableEvent $event)
|
||||
protected function createOrUpdate(CouponModel $coupon, CouponCreateOrUpdateEvent $event)
|
||||
{
|
||||
$this->checkAuth("ADMIN", "admin.coupon.disable");
|
||||
$coupon->setDispatcher($this->getDispatcher());
|
||||
|
||||
$couponToUpdate = CouponQuery::create()->findPk($event->getId());
|
||||
$coupon->createOrUpdate(
|
||||
$event->getCode(),
|
||||
$event->getTitle(),
|
||||
$event->getAmount(),
|
||||
$event->getEffect(),
|
||||
$event->getShortDescription(),
|
||||
$event->getDescription(),
|
||||
$event->isEnabled(),
|
||||
$event->getExpirationDate(),
|
||||
$event->isAvailableOnSpecialOffers(),
|
||||
$event->isCumulative(),
|
||||
$event->getMaxUsage(),
|
||||
$event->getRules(),
|
||||
$event->getLang()
|
||||
);
|
||||
|
||||
if ($couponToUpdate !== null) {
|
||||
$couponToUpdate->setIsEnabled(0);
|
||||
$event->getDispatcher()->dispatch(
|
||||
TheliaEvents::BEFORE_DISABLE_COUPON, $event
|
||||
);
|
||||
|
||||
$couponToUpdate->save();
|
||||
|
||||
$event->getDispatcher()->dispatch(
|
||||
TheliaEvents::AFTER_DISABLE_COUPON, $event
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable a Coupon if a Coupon enable attempt is found
|
||||
*
|
||||
* @param CouponEnableEvent $event Coupon enable Event
|
||||
*/
|
||||
public function enable(CouponEnableEvent $event)
|
||||
{
|
||||
$this->checkAuth("ADMIN", "admin.coupon.enable");
|
||||
|
||||
$couponToUpdate = CouponQuery::create()->findPk($event->getId());
|
||||
|
||||
if ($couponToUpdate !== null) {
|
||||
$couponToUpdate->setIsEnabled(1);
|
||||
$event->getDispatcher()->dispatch(
|
||||
TheliaEvents::BEFORE_ENABLE_COUPON, $event
|
||||
);
|
||||
|
||||
$couponToUpdate->save();
|
||||
|
||||
$event->getDispatcher()->dispatch(
|
||||
TheliaEvents::AFTER_ENABLE_COUPON, $event
|
||||
);
|
||||
}
|
||||
$event->setCoupon($coupon);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,14 +121,8 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
// "action.createCategory" => array("create", 128),
|
||||
// "action.modifyCategory" => array("modify", 128),
|
||||
// "action.deleteCategory" => array("delete", 128),
|
||||
//
|
||||
// "action.toggleCategoryVisibility" => array("toggleVisibility", 128),
|
||||
// "action.changeCategoryPositionUp" => array("changePositionUp", 128),
|
||||
// "action.changeCategoryPositionDown" => array("changePositionDown", 128),
|
||||
// "action.changeCategoryPosition" => array("changePosition", 128),
|
||||
TheliaEvents::COUPON_CREATE => array("create", 128),
|
||||
TheliaEvents::COUPON_UPDATE => array("update", 128),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\CurrencyChangeEvent;
|
||||
use Thelia\Core\Event\CurrencyCreateEvent;
|
||||
use Thelia\Core\Event\CurrencyDeleteEvent;
|
||||
use Thelia\Model\Map\CurrencyTableMap;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
class Currency extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
@@ -53,11 +55,12 @@ class Currency extends BaseAction implements EventSubscriberInterface
|
||||
->setName($event->getCurrencyName())
|
||||
->setSymbol($event->getSymbol())
|
||||
->setRate($event->getRate())
|
||||
->setCode($event->getCode())
|
||||
->setCode(strtoupper($event->getCode()))
|
||||
|
||||
->save()
|
||||
;
|
||||
|
||||
|
||||
$event->setCurrency($currency);
|
||||
}
|
||||
|
||||
@@ -66,7 +69,7 @@ class Currency extends BaseAction implements EventSubscriberInterface
|
||||
*
|
||||
* @param CurrencyChangeEvent $event
|
||||
*/
|
||||
public function modify(CurrencyChangeEvent $event)
|
||||
public function update(CurrencyChangeEvent $event)
|
||||
{
|
||||
$search = CurrencyQuery::create();
|
||||
|
||||
@@ -79,7 +82,7 @@ class Currency extends BaseAction implements EventSubscriberInterface
|
||||
->setName($event->getCurrencyName())
|
||||
->setSymbol($event->getSymbol())
|
||||
->setRate($event->getRate())
|
||||
->setCode($event->getCode())
|
||||
->setCode(strtoupper($event->getCode()))
|
||||
|
||||
->save();
|
||||
|
||||
@@ -87,6 +90,32 @@ class Currency extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default currency
|
||||
*
|
||||
* @param CurrencyChangeEvent $event
|
||||
*/
|
||||
public function setDefault(CurrencyChangeEvent $event)
|
||||
{
|
||||
$search = CurrencyQuery::create();
|
||||
|
||||
if (null !== $currency = CurrencyQuery::create()->findOneById($event->getCurrencyId())) {
|
||||
|
||||
if ($currency->getByDefault() != $event->getIsDefault()) {
|
||||
|
||||
// Reset default status
|
||||
CurrencyQuery::create()->filterByByDefault(true)->update(array('ByDefault' => false));
|
||||
|
||||
$currency
|
||||
->setByDefault($event->getIsDefault())
|
||||
->save()
|
||||
;
|
||||
}
|
||||
|
||||
$event->setCurrency($currency);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a currencyuration entry
|
||||
*
|
||||
@@ -106,15 +135,41 @@ class Currency extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function updateRates() {
|
||||
|
||||
$rates_url = ConfigQuery::read('currency_rate_update_url', 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml');
|
||||
|
||||
$rate_data = file_get_contents($rates_url);
|
||||
|
||||
if ($rate_data && $sxe = new \SimpleXMLElement($rate_data)) {
|
||||
|
||||
foreach ($sxe->Cube[0]->Cube[0]->Cube as $last)
|
||||
{
|
||||
$code = strtoupper($last["currency"]);
|
||||
$rate = floatval($last['rate']);
|
||||
|
||||
if (null !== $currency = CurrencyQuery::create()->findOneByCode($code)) {
|
||||
$currency->setRate($rate)->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new \RuntimeException(sprintf("Failed to get currency rates data from URL %s", $url));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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),
|
||||
TheliaEvents::CURRENCY_CREATE => array("create", 128),
|
||||
TheliaEvents::CURRENCY_UPDATE => array("update", 128),
|
||||
TheliaEvents::CURRENCY_DELETE => array("delete", 128),
|
||||
TheliaEvents::CURRENCY_SET_DEFAULT => array("setDefault", 128),
|
||||
TheliaEvents::CURRENCY_UPDATE_RATES => array("updateRates", 128),
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ class Message extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
return array(
|
||||
TheliaEvents::MESSAGE_CREATE => array("create", 128),
|
||||
TheliaEvents::MESSAGE_MODIFY => array("modify", 128),
|
||||
TheliaEvents::MESSAGE_UPDATE => array("modify", 128),
|
||||
TheliaEvents::MESSAGE_DELETE => array("delete", 128),
|
||||
);
|
||||
}
|
||||
|
||||
84
core/lib/Thelia/Action/PageNotFound.php
Executable file
84
core/lib/Thelia/Action/PageNotFound.php
Executable file
@@ -0,0 +1,84 @@
|
||||
<?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\HttpFoundation\Request;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class PageNotFound
|
||||
* @package Thelia\Action
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*/
|
||||
class PageNotFound extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
public function display404(GetResponseForExceptionEvent $event)
|
||||
{
|
||||
if(is_a($event->getException(), 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException')) {
|
||||
|
||||
$parser = $this->container->get("thelia.parser");
|
||||
|
||||
// Define the template thant shoud be used
|
||||
$parser->setTemplate(ConfigQuery::getActiveTemplate());
|
||||
|
||||
//$event->getRequest()->attributes->set('_view', ConfigQuery::getPageNotFoundView());
|
||||
|
||||
$response = new Response($parser->render(ConfigQuery::getPageNotFoundView()), 404);
|
||||
|
||||
$event->setResponse($response);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of event names this subscriber wants to listen to.
|
||||
*
|
||||
* The array keys are event names and the value can be:
|
||||
*
|
||||
* * The method name to call (priority defaults to 0)
|
||||
* * An array composed of the method name to call and the priority
|
||||
* * An array of arrays composed of the method names to call and respective
|
||||
* priorities, or 0 if unset
|
||||
*
|
||||
* For instance:
|
||||
*
|
||||
* * array('eventName' => 'methodName')
|
||||
* * array('eventName' => array('methodName', $priority))
|
||||
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
|
||||
*
|
||||
* @return array The event names to listen to
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
KernelEvents::EXCEPTION => array("display404", 128),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user