Merge branch 'master' of https://github.com/thelia/thelia into upload_management
# By Manuel Raynaud (60) and others # Via Manuel Raynaud (16) and others * 'master' of https://github.com/thelia/thelia: (113 commits) implement process for changing folder position allow possibility to change folder visibility allow to create folder add dispatcher before/after for folder crud management icreate folder delete event process folder update action create folder events display info in folders edition template push model re-add home link in menu comment dev menu in layout translate some missing string fixes order integration order process change some informations in layou fix query in Thelia\Model\Folder::countAllContents allow to order products on category page Add default language & editing language default field Vertical align middle tables Fixed translations ... Conflicts: core/lib/Thelia/Tools/I18n.php templates/admin/default/category-edit.html
This commit is contained in:
@@ -492,9 +492,6 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
|
||||
$changeEvent = $this->createToggleVisibilityEvent($this->getRequest());
|
||||
|
||||
// Create and dispatch the change event
|
||||
$changeEvent->setIsDefault(true);
|
||||
|
||||
try {
|
||||
$this->dispatch($this->visibilityToggleEventIdentifier, $changeEvent);
|
||||
} catch (\Exception $ex) {
|
||||
@@ -502,7 +499,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
|
||||
$this->redirectToListTemplate();
|
||||
return $this->nullResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,4 +33,9 @@ class AdminController extends BaseAdminController
|
||||
{
|
||||
return $this->render("home");
|
||||
}
|
||||
|
||||
public function updateAction()
|
||||
{
|
||||
return $this->render("profile-edit");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ class CategoryController extends AbstractCrudController
|
||||
'description' => $object->getDescription(),
|
||||
'postscriptum' => $object->getPostscriptum(),
|
||||
'visible' => $object->getVisible(),
|
||||
'url' => $object->getRewritenUrl($this->getCurrentEditionLocale()),
|
||||
'url' => $object->getRewrittenUrl($this->getCurrentEditionLocale()),
|
||||
'parent' => $object->getParent()
|
||||
);
|
||||
|
||||
|
||||
328
core/lib/Thelia/Controller/Admin/FolderController.php
Normal file
328
core/lib/Thelia/Controller/Admin/FolderController.php
Normal file
@@ -0,0 +1,328 @@
|
||||
<?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\FolderCreateEvent;
|
||||
use Thelia\Core\Event\FolderDeleteEvent;
|
||||
use Thelia\Core\Event\FolderToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\FolderUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Form\FolderCreationForm;
|
||||
use Thelia\Form\FolderModificationForm;
|
||||
use Thelia\Model\FolderQuery;
|
||||
|
||||
/**
|
||||
* Class FolderController
|
||||
* @package Thelia\Controller\Admin
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class FolderController extends AbstractCrudController
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
'folder',
|
||||
'manual',
|
||||
'folder_order',
|
||||
|
||||
'admin.folder.default',
|
||||
'admin.folder.create',
|
||||
'admin.folder.update',
|
||||
'admin.folder.delete',
|
||||
|
||||
TheliaEvents::FOLDER_CREATE,
|
||||
TheliaEvents::FOLDER_UPDATE,
|
||||
TheliaEvents::FOLDER_DELETE,
|
||||
TheliaEvents::FOLDER_TOGGLE_VISIBILITY,
|
||||
TheliaEvents::FOLDER_UPDATE_POSITION
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the creation form for this object
|
||||
*/
|
||||
protected function getCreationForm()
|
||||
{
|
||||
return new FolderCreationForm($this->getRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the update form for this object
|
||||
*/
|
||||
protected function getUpdateForm()
|
||||
{
|
||||
return new FolderModificationForm($this->getRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* Hydrate the update form for this object, before passing it to the update template
|
||||
*
|
||||
* @param \Thelia\Model\Folder $object
|
||||
*/
|
||||
protected function hydrateObjectForm($object) {
|
||||
|
||||
// Prepare the data that will hydrate the form
|
||||
$data = array(
|
||||
'id' => $object->getId(),
|
||||
'locale' => $object->getLocale(),
|
||||
'title' => $object->getTitle(),
|
||||
'chapo' => $object->getChapo(),
|
||||
'description' => $object->getDescription(),
|
||||
'postscriptum' => $object->getPostscriptum(),
|
||||
'visible' => $object->getVisible(),
|
||||
'url' => $object->getRewrittenUrl($this->getCurrentEditionLocale()),
|
||||
'parent' => $object->getParent()
|
||||
);
|
||||
|
||||
// Setup the object form
|
||||
return new FolderModificationForm($this->getRequest(), "form", $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the creation event with the provided form data
|
||||
*
|
||||
* @param unknown $formData
|
||||
*/
|
||||
protected function getCreationEvent($formData)
|
||||
{
|
||||
$creationEvent = new FolderCreateEvent();
|
||||
|
||||
$creationEvent
|
||||
->setLocale($formData['locale'])
|
||||
->setTitle($formData['title'])
|
||||
->setVisible($formData['visible'])
|
||||
->setParent($formData['parent']);
|
||||
|
||||
return $creationEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the update event with the provided form data
|
||||
*
|
||||
* @param unknown $formData
|
||||
*/
|
||||
protected function getUpdateEvent($formData)
|
||||
{
|
||||
$updateEvent = new FolderUpdateEvent($formData['id']);
|
||||
|
||||
$updateEvent
|
||||
->setLocale($formData['locale'])
|
||||
->setTitle($formData['title'])
|
||||
->setChapo($formData['chapo'])
|
||||
->setDescription($formData['description'])
|
||||
->setPostscriptum($formData['postscriptum'])
|
||||
->setVisible($formData['visible'])
|
||||
->setUrl($formData['url'])
|
||||
->setParent($formData['parent'])
|
||||
;
|
||||
|
||||
return $updateEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the delete event with the provided form data
|
||||
*/
|
||||
protected function getDeleteEvent()
|
||||
{
|
||||
return new FolderDeleteEvent($this->getRequest()->get('folder_id'), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FolderToggleVisibilityEvent|void
|
||||
*/
|
||||
protected function createToggleVisibilityEvent()
|
||||
{
|
||||
return new FolderToggleVisibilityEvent($this->getExistingObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $positionChangeMode
|
||||
* @param $positionValue
|
||||
* @return UpdatePositionEvent|void
|
||||
*/
|
||||
protected function createUpdatePositionEvent($positionChangeMode, $positionValue) {
|
||||
|
||||
return new UpdatePositionEvent(
|
||||
$this->getRequest()->get('folder_id', null),
|
||||
$positionChangeMode,
|
||||
$positionValue
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the event contains the object, e.g. the action has updated the object in the event.
|
||||
*
|
||||
* @param unknown $event
|
||||
*/
|
||||
protected function eventContainsObject($event)
|
||||
{
|
||||
return $event->hasFolder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the created object from an event.
|
||||
*
|
||||
* @param $event \Thelia\Core\Event\FolderEvent $event
|
||||
*
|
||||
* @return null|\Thelia\Model\Folder
|
||||
*/
|
||||
protected function getObjectFromEvent($event)
|
||||
{
|
||||
return $event->hasFolder() ? $event->getFolder() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load an existing object from the database
|
||||
*/
|
||||
protected function getExistingObject() {
|
||||
return FolderQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->findOneById($this->getRequest()->get('folder_id', 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object label form the object event (name, title, etc.)
|
||||
*
|
||||
* @param unknown $object
|
||||
*/
|
||||
protected function getObjectLabel($object) {
|
||||
return $object->getTitle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object ID from the object
|
||||
*
|
||||
* @param unknown $object
|
||||
*/
|
||||
protected function getObjectId($object)
|
||||
{
|
||||
return $object->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the main list template
|
||||
*
|
||||
* @param unknown $currentOrder, if any, null otherwise.
|
||||
*/
|
||||
protected function renderListTemplate($currentOrder) {
|
||||
|
||||
// Get product order
|
||||
$product_order = $this->getListOrderFromSession('content', 'content_order', 'manual');
|
||||
|
||||
return $this->render('folders',
|
||||
array(
|
||||
'folder_order' => $currentOrder,
|
||||
'content_order' => $product_order,
|
||||
'folder_id' => $this->getRequest()->get('folder_id', 0)
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render the edition template
|
||||
*/
|
||||
protected function renderEditionTemplate() {
|
||||
|
||||
return $this->render('folder-edit', $this->getEditionArguments());
|
||||
}
|
||||
|
||||
protected function getEditionArguments()
|
||||
{
|
||||
return array(
|
||||
'folder_id' => $this->getRequest()->get('folder_id', 0),
|
||||
'current_tab' => $this->getRequest()->get('current_tab', 'general')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Thelia\Core\Event\FolderUpdateEvent $updateEvent
|
||||
* @return Response|void
|
||||
*/
|
||||
protected function performAdditionalUpdateAction($updateEvent)
|
||||
{
|
||||
if ($this->getRequest()->get('save_mode') != 'stay') {
|
||||
|
||||
// Redirect to parent category list
|
||||
$this->redirectToRoute(
|
||||
'admin.folders.default',
|
||||
array('folder_id' => $updateEvent->getFolder()->getParent())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Put in this method post object delete processing if required.
|
||||
*
|
||||
* @param \Thelia\Core\Event\FolderDeleteEvent $deleteEvent the delete event
|
||||
* @return Response a response, or null to continue normal processing
|
||||
*/
|
||||
protected function performAdditionalDeleteAction($deleteEvent)
|
||||
{
|
||||
// Redirect to parent category list
|
||||
$this->redirectToRoute(
|
||||
'admin.folders.default',
|
||||
array('folder_id' => $deleteEvent->getFolder()->getParent())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $event \Thelia\Core\Event\UpdatePositionEvent
|
||||
* @return null|Response
|
||||
*/
|
||||
protected function performAdditionalUpdatePositionAction($event)
|
||||
{
|
||||
|
||||
$folder = FolderQuery::create()->findPk($event->getObjectId());
|
||||
|
||||
if ($folder != null) {
|
||||
// Redirect to parent category list
|
||||
$this->redirectToRoute(
|
||||
'admin.folders.default',
|
||||
array('folder_id' => $folder->getParent())
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to the edition template
|
||||
*/
|
||||
protected function redirectToEditionTemplate()
|
||||
{
|
||||
$this->redirectToRoute("admin.folders.update", $this->getEditionArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to the list template
|
||||
*/
|
||||
protected function redirectToListTemplate()
|
||||
{
|
||||
$this->redirectToRoute(
|
||||
'admin.folders.default',
|
||||
array('folder_id' => $this->getRequest()->get('folder_id', 0))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -21,35 +21,26 @@
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Front;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
use Thelia\Tools\URL;
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
/**
|
||||
* Class DeliveryController
|
||||
* @package Thelia\Controller\Front
|
||||
* Class ModuleController
|
||||
* @package Thelia\Controller\Admin
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class DeliveryController extends BaseFrontController
|
||||
class ModuleController extends BaseAdminController
|
||||
{
|
||||
public function select($delivery_id)
|
||||
public function indexAction()
|
||||
{
|
||||
if ($this->getSecurityContext()->hasCustomerUser() === false) {
|
||||
$this->redirect(URL::getInstance()->getIndexPage());
|
||||
}
|
||||
|
||||
$request = $this->getRequest();
|
||||
|
||||
$deliveryModule = ModuleQuery::create()
|
||||
->filterById($delivery_id)
|
||||
->filterByActivate(1)
|
||||
->findOne()
|
||||
;
|
||||
|
||||
if ($deliveryModule) {
|
||||
$request->getSession()->setDelivery($delivery_id);
|
||||
} else {
|
||||
$this->pageNotFound();
|
||||
}
|
||||
if (null !== $response = $this->checkAuth("admin.module.view")) return $response;
|
||||
return $this->render("modules", array("display_module" => 20));
|
||||
}
|
||||
}
|
||||
|
||||
public function updateAction($module_id)
|
||||
{
|
||||
|
||||
return $this->render("module-edit", array(
|
||||
"module_id" => $module_id
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,10 @@ use Thelia\Model\FolderQuery;
|
||||
use Thelia\Model\ContentQuery;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Thelia\Model\ProductAssociatedContentQuery;
|
||||
use Thelia\Model\AccessoryQuery;
|
||||
use Thelia\Model\CategoryQuery;
|
||||
use Thelia\Core\Event\ProductAddAccessoryEvent;
|
||||
use Thelia\Core\Event\ProductDeleteAccessoryEvent;
|
||||
|
||||
/**
|
||||
* Manages products
|
||||
@@ -83,9 +87,10 @@ class ProductController extends AbstractCrudController
|
||||
$createEvent = new ProductCreateEvent();
|
||||
|
||||
$createEvent
|
||||
->setRef($formData['ref'])
|
||||
->setTitle($formData['title'])
|
||||
->setLocale($formData["locale"])
|
||||
->setParent($formData['parent'])
|
||||
->setLocale($formData['locale'])
|
||||
->setDefaultCategory($formData['default_category'])
|
||||
->setVisible($formData['visible'])
|
||||
;
|
||||
|
||||
@@ -134,15 +139,15 @@ class ProductController extends AbstractCrudController
|
||||
{
|
||||
// Prepare the data that will hydrate the form
|
||||
$data = array(
|
||||
'id' => $object->getId(),
|
||||
'locale' => $object->getLocale(),
|
||||
'title' => $object->getTitle(),
|
||||
'chapo' => $object->getChapo(),
|
||||
'description' => $object->getDescription(),
|
||||
'postscriptum' => $object->getPostscriptum(),
|
||||
'visible' => $object->getVisible(),
|
||||
'url' => $object->getRewritenUrl($this->getCurrentEditionLocale()),
|
||||
'parent' => $object->getParent()
|
||||
'id' => $object->getId(),
|
||||
'locale' => $object->getLocale(),
|
||||
'title' => $object->getTitle(),
|
||||
'chapo' => $object->getChapo(),
|
||||
'description' => $object->getDescription(),
|
||||
'postscriptum' => $object->getPostscriptum(),
|
||||
'visible' => $object->getVisible(),
|
||||
'url' => $object->getRewrittenUrl($this->getCurrentEditionLocale()),
|
||||
'default_category' => $object->getDefaultCategoryId()
|
||||
);
|
||||
|
||||
// Setup the object form
|
||||
@@ -174,12 +179,27 @@ class ProductController extends AbstractCrudController
|
||||
protected function getEditionArguments()
|
||||
{
|
||||
return array(
|
||||
'product_id' => $this->getRequest()->get('product_id', 0),
|
||||
'folder_id' => $this->getRequest()->get('folder_id', 0),
|
||||
'current_tab' => $this->getRequest()->get('current_tab', 'general')
|
||||
'category_id' => $this->getCategoryId(),
|
||||
'product_id' => $this->getRequest()->get('product_id', 0),
|
||||
'folder_id' => $this->getRequest()->get('folder_id', 0),
|
||||
'accessory_category_id'=> $this->getRequest()->get('accessory_category_id', 0),
|
||||
'current_tab' => $this->getRequest()->get('current_tab', 'general')
|
||||
);
|
||||
}
|
||||
|
||||
protected function getCategoryId() {
|
||||
// Trouver le category_id, soit depuis la reques, souit depuis le produit courant
|
||||
$category_id = $this->getRequest()->get('category_id', null);
|
||||
|
||||
if ($category_id == null) {
|
||||
$product = $this->getExistingObject();
|
||||
|
||||
if ($product !== null) $category_id = $product->getDefaultCategoryId();
|
||||
}
|
||||
|
||||
return $category_id != null ? $category_id : 0;
|
||||
}
|
||||
|
||||
protected function renderListTemplate($currentOrder)
|
||||
{
|
||||
$this->getListOrderFromSession('product', 'product_order', 'manual');
|
||||
@@ -187,18 +207,15 @@ class ProductController extends AbstractCrudController
|
||||
return $this->render('categories',
|
||||
array(
|
||||
'product_order' => $currentOrder,
|
||||
'product_id' => $this->getRequest()->get('product_id', 0)
|
||||
'category_id' => $this->getCategoryId()
|
||||
));
|
||||
}
|
||||
|
||||
protected function redirectToListTemplate()
|
||||
{
|
||||
// Redirect to the product default category list
|
||||
$product = $this->getExistingObject();
|
||||
|
||||
$this->redirectToRoute(
|
||||
'admin.products.default',
|
||||
array('category_id' => $product != null ? $product->getDefaultCategory() : 0)
|
||||
array('category_id' => $this->getCategoryId())
|
||||
);
|
||||
}
|
||||
|
||||
@@ -238,7 +255,7 @@ class ProductController extends AbstractCrudController
|
||||
// Redirect to parent product list
|
||||
$this->redirectToRoute(
|
||||
'admin.products.default',
|
||||
array('category_id' => $deleteEvent->getProduct()->getDefaultCategory())
|
||||
array('category_id' => $this->getCategoryId())
|
||||
);
|
||||
}
|
||||
|
||||
@@ -249,26 +266,22 @@ class ProductController extends AbstractCrudController
|
||||
// Redirect to parent product list
|
||||
$this->redirectToRoute(
|
||||
'admin.categories.default',
|
||||
array('category_id' => $product->getDefaultCategory())
|
||||
array('category_id' => $this->getCategoryId())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function performAdditionalUpdatePositionAction($event)
|
||||
protected function performAdditionalUpdatePositionAction($positionEvent)
|
||||
{
|
||||
$product = ProductQuery::create()->findPk($event->getObjectId());
|
||||
|
||||
if ($product != null) {
|
||||
// Redirect to parent product list
|
||||
$this->redirectToRoute(
|
||||
'admin.categories.default',
|
||||
array('category_id' => $product->getDefaultCategory())
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
// Redirect to parent product list
|
||||
$this->redirectToRoute(
|
||||
'admin.categories.default',
|
||||
array('category_id' => $this->getCategoryId())
|
||||
);
|
||||
}
|
||||
|
||||
// -- Related content management -------------------------------------------
|
||||
|
||||
public function getAvailableRelatedContentAction($productId, $folderId)
|
||||
{
|
||||
$result = array();
|
||||
@@ -347,4 +360,118 @@ class ProductController extends AbstractCrudController
|
||||
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
|
||||
// -- Accessories management ----------------------------------------------
|
||||
|
||||
public function getAvailableAccessoriesAction($productId, $categoryId)
|
||||
{
|
||||
$result = array();
|
||||
|
||||
$categories = CategoryQuery::create()->filterById($categoryId)->find();
|
||||
|
||||
if ($categories !== null) {
|
||||
|
||||
$list = ProductQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->filterByCategory($categories, Criteria::IN)
|
||||
->filterById(AccessoryQuery::create()->select('accessory')->findByProductId($productId), Criteria::NOT_IN)
|
||||
->find();
|
||||
;
|
||||
|
||||
if ($list !== null) {
|
||||
foreach($list as $item) {
|
||||
$result[] = array('id' => $item->getId(), 'title' => $item->getTitle());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->jsonResponse(json_encode($result));
|
||||
}
|
||||
|
||||
public function addAccessoryAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.products.update")) return $response;
|
||||
|
||||
$accessory_id = intval($this->getRequest()->get('accessory_id'));
|
||||
|
||||
if ($accessory_id > 0) {
|
||||
|
||||
$event = new ProductAddAccessoryEvent(
|
||||
$this->getExistingObject(),
|
||||
$accessory_id
|
||||
);
|
||||
|
||||
try {
|
||||
$this->dispatch(TheliaEvents::PRODUCT_ADD_ACCESSORY, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
}
|
||||
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
public function deleteAccessoryAction()
|
||||
{
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.products.update")) return $response;
|
||||
|
||||
$accessory_id = intval($this->getRequest()->get('accessory_id'));
|
||||
|
||||
if ($accessory_id > 0) {
|
||||
|
||||
$event = new ProductDeleteAccessoryEvent(
|
||||
$this->getExistingObject(),
|
||||
$accessory_id
|
||||
);
|
||||
|
||||
try {
|
||||
$this->dispatch(TheliaEvents::PRODUCT_REMOVE_ACCESSORY, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
}
|
||||
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update accessory position (only for objects whichsupport that)
|
||||
*/
|
||||
public function updateAccessoryPositionAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth('admin.products.update')) return $response;
|
||||
|
||||
try {
|
||||
$mode = $this->getRequest()->get('mode', null);
|
||||
|
||||
if ($mode == 'up')
|
||||
$mode = UpdatePositionEvent::POSITION_UP;
|
||||
else if ($mode == 'down')
|
||||
$mode = UpdatePositionEvent::POSITION_DOWN;
|
||||
else
|
||||
$mode = UpdatePositionEvent::POSITION_ABSOLUTE;
|
||||
|
||||
$position = $this->getRequest()->get('position', null);
|
||||
|
||||
$event = new UpdatePositionEvent($mode, $position);
|
||||
|
||||
$this->dispatch(TheliaEvents::PRODUCT_UPDATE_ACCESSORY_POSITION, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Class ShippingConfigurationController
|
||||
* @package Thelia\Controller\Admin
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class ShippingConfigurationController extends BaseAdminController
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.shipping-configuration.view")) return $response;
|
||||
return $this->render("shipping-configuration", array("display_shipping_configuration" => 20));
|
||||
}
|
||||
|
||||
public function updateAction($shipping_configuration_id)
|
||||
{
|
||||
|
||||
return $this->render("shipping-configuration-edit", array(
|
||||
"shipping_configuration_id" => $shipping_configuration_id
|
||||
));
|
||||
}
|
||||
}
|
||||
46
core/lib/Thelia/Controller/Admin/ShippingZoneController.php
Normal file
46
core/lib/Thelia/Controller/Admin/ShippingZoneController.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Class ShippingZoneController
|
||||
* @package Thelia\Controller\Admin
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class ShippingZoneController extends BaseAdminController
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.shipping-zones.view")) return $response;
|
||||
return $this->render("shipping-zones", array("display_shipping_zone" => 20));
|
||||
}
|
||||
|
||||
public function updateAction($shipping_zones_id)
|
||||
{
|
||||
|
||||
return $this->render("shipping-zones-edit", array(
|
||||
"shipping_zones_id" => $shipping_zones_id
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,8 @@ namespace Thelia\Controller\Front;
|
||||
|
||||
use Symfony\Component\Routing\Router;
|
||||
use Thelia\Controller\BaseController;
|
||||
use Thelia\Model\AddressQuery;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
class BaseFrontController extends BaseController
|
||||
@@ -65,4 +67,20 @@ class BaseFrontController extends BaseController
|
||||
$this->redirectToRoute("cart.view");
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkValidDelivery()
|
||||
{
|
||||
$order = $this->getSession()->getOrder();
|
||||
if(null === $order || null === $order->chosenDeliveryAddress || null === $order->getDeliveryModuleId() || null === AddressQuery::create()->findPk($order->chosenDeliveryAddress) || null === ModuleQuery::create()->findPk($order->getDeliveryModuleId())) {
|
||||
$this->redirectToRoute("order.delivery");
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkValidInvoice()
|
||||
{
|
||||
$order = $this->getSession()->getOrder();
|
||||
if(null === $order || null === $order->chosenInvoiceAddress || null === $order->getPaymentModuleId() || null === AddressQuery::create()->findPk($order->chosenInvoiceAddress) || null === ModuleQuery::create()->findPk($order->getPaymentModuleId())) {
|
||||
$this->redirectToRoute("order.invoice");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,15 +23,21 @@
|
||||
namespace Thelia\Controller\Front;
|
||||
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Thelia\Exception\TheliaProcessException;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Core\Event\OrderEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Thelia\Form\OrderDelivery;
|
||||
use Thelia\Form\OrderPayment;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Model\AddressQuery;
|
||||
use Thelia\Model\AreaDeliveryModuleQuery;
|
||||
use Thelia\Model\Base\OrderQuery;
|
||||
use Thelia\Model\CountryQuery;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
use Thelia\Model\Order;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
/**
|
||||
* Class OrderController
|
||||
@@ -41,7 +47,6 @@ use Thelia\Model\Order;
|
||||
class OrderController extends BaseFrontController
|
||||
{
|
||||
/**
|
||||
* set billing address
|
||||
* set delivery address
|
||||
* set delivery module
|
||||
*/
|
||||
@@ -59,25 +64,32 @@ class OrderController extends BaseFrontController
|
||||
|
||||
$deliveryAddressId = $form->get("delivery-address")->getData();
|
||||
$deliveryModuleId = $form->get("delivery-module")->getData();
|
||||
$deliveryAddress = AddressQuery::create()->findPk($deliveryAddressId);
|
||||
$deliveryModule = ModuleQuery::create()->findPk($deliveryModuleId);
|
||||
|
||||
/* check that the delivery address belong to the current customer */
|
||||
/* check that the delivery address belongs to the current customer */
|
||||
$deliveryAddress = AddressQuery::create()->findPk($deliveryAddressId);
|
||||
if($deliveryAddress->getCustomerId() !== $this->getSecurityContext()->getCustomerUser()->getId()) {
|
||||
throw new \Exception("Address does not belong to the current customer");
|
||||
throw new \Exception("Delivery address does not belong to the current customer");
|
||||
}
|
||||
|
||||
/* check that the delivery module fetch the delivery address area */
|
||||
/* check that the delivery module fetches the delivery address area */
|
||||
if(AreaDeliveryModuleQuery::create()
|
||||
->filterByAreaId($deliveryAddress->getCountry()->getAreaId())
|
||||
->filterByDeliveryModuleId()
|
||||
->filterByDeliveryModuleId($deliveryModuleId)
|
||||
->count() == 0) {
|
||||
throw new \Exception("PUKE");
|
||||
throw new \Exception("Delivery module cannot be use with selected delivery address");
|
||||
}
|
||||
|
||||
/* get postage amount */
|
||||
$moduleReflection = new \ReflectionClass($deliveryModule->getFullNamespace());
|
||||
$moduleInstance = $moduleReflection->newInstance();
|
||||
$postage = $moduleInstance->getPostage($deliveryAddress->getCountry());
|
||||
|
||||
$orderEvent = $this->getOrderEvent();
|
||||
$orderEvent->setDeliveryAddress($deliveryAddressId);
|
||||
$orderEvent->setDeliveryModule($deliveryModuleId);
|
||||
$orderEvent->setPostage($postage);
|
||||
|
||||
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_ADDRESS, $orderEvent);
|
||||
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_MODULE, $orderEvent);
|
||||
@@ -105,6 +117,111 @@ class OrderController extends BaseFrontController
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* set invoice address
|
||||
* set payment module
|
||||
*/
|
||||
public function invoice()
|
||||
{
|
||||
$this->checkAuth();
|
||||
$this->checkCartNotEmpty();
|
||||
$this->checkValidDelivery();
|
||||
|
||||
$message = false;
|
||||
|
||||
$orderPayment = new OrderPayment($this->getRequest());
|
||||
|
||||
try {
|
||||
$form = $this->validateForm($orderPayment, "post");
|
||||
|
||||
$invoiceAddressId = $form->get("invoice-address")->getData();
|
||||
$paymentModuleId = $form->get("payment-module")->getData();
|
||||
|
||||
/* check that the invoice address belongs to the current customer */
|
||||
$invoiceAddress = AddressQuery::create()->findPk($invoiceAddressId);
|
||||
if($invoiceAddress->getCustomerId() !== $this->getSecurityContext()->getCustomerUser()->getId()) {
|
||||
throw new \Exception("Invoice address does not belong to the current customer");
|
||||
}
|
||||
|
||||
$orderEvent = $this->getOrderEvent();
|
||||
$orderEvent->setInvoiceAddress($invoiceAddressId);
|
||||
$orderEvent->setPaymentModule($paymentModuleId);
|
||||
|
||||
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_INVOICE_ADDRESS, $orderEvent);
|
||||
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_PAYMENT_MODULE, $orderEvent);
|
||||
|
||||
$this->redirectToRoute("order.payment.process");
|
||||
|
||||
} catch (FormValidationException $e) {
|
||||
$message = sprintf("Please check your input: %s", $e->getMessage());
|
||||
} catch (PropelException $e) {
|
||||
$this->getParserContext()->setGeneralError($e->getMessage());
|
||||
} catch (\Exception $e) {
|
||||
$message = sprintf("Sorry, an error occured: %s", $e->getMessage());
|
||||
}
|
||||
|
||||
if ($message !== false) {
|
||||
Tlog::getInstance()->error(sprintf("Error during order payment process : %s. Exception was %s", $message, $e->getMessage()));
|
||||
|
||||
$orderPayment->setErrorMessage($message);
|
||||
|
||||
$this->getParserContext()
|
||||
->addForm($orderPayment)
|
||||
->setGeneralError($message)
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function pay()
|
||||
{
|
||||
/* check customer */
|
||||
$this->checkAuth();
|
||||
|
||||
/* check cart count */
|
||||
$this->checkCartNotEmpty();
|
||||
|
||||
/* check delivery address and module */
|
||||
$this->checkValidDelivery();
|
||||
|
||||
/* check invoice address and payment module */
|
||||
$this->checkValidInvoice();
|
||||
|
||||
$orderEvent = $this->getOrderEvent();
|
||||
|
||||
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_PAY, $orderEvent);
|
||||
|
||||
$placedOrder = $orderEvent->getPlacedOrder();
|
||||
|
||||
if(null !== $placedOrder && null !== $placedOrder->getId()) {
|
||||
/* order has been placed */
|
||||
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute('order.placed', array('order_id' => $orderEvent->getPlacedOrder()->getId()))));
|
||||
} else {
|
||||
/* order has not been placed */
|
||||
$this->redirectToRoute("cart.view");
|
||||
}
|
||||
}
|
||||
|
||||
public function orderPlaced($order_id)
|
||||
{
|
||||
/* check if the placed order matched the customer */
|
||||
$placedOrder = OrderQuery::create()->findPk(
|
||||
$this->getRequest()->attributes->get('order_id')
|
||||
);
|
||||
|
||||
if(null === $placedOrder) {
|
||||
throw new TheliaProcessException("No placed order", TheliaProcessException::NO_PLACED_ORDER, $placedOrder);
|
||||
}
|
||||
|
||||
$customer = $this->getSecurityContext()->getCustomerUser();
|
||||
|
||||
if(null === $customer || $placedOrder->getCustomerId() !== $customer->getId()) {
|
||||
throw new TheliaProcessException("Received placed order id does not belong to the current customer", TheliaProcessException::PLACED_ORDER_ID_BAD_CURRENT_CUSTOMER, $placedOrder);
|
||||
}
|
||||
|
||||
$this->getParserContext()->set("placed_order_id", $placedOrder->getId());
|
||||
}
|
||||
|
||||
protected function getOrderEvent()
|
||||
{
|
||||
$order = $this->getOrder($this->getRequest());
|
||||
|
||||
Reference in New Issue
Block a user