Merge branches 'catalog' and 'upload_management' of https://github.com/thelia/thelia into catalog
# By franck # Via franck * 'catalog' of https://github.com/thelia/thelia: Impemented combination creation # By Manuel Raynaud (29) and others # Via gmorel (6) and others * 'upload_management' of https://github.com/thelia/thelia: (52 commits) Working : Upload image : Fix upload validation - Image format allowed - manual-reverse order on image loop Upload allow only for images Hide upload zone during upload Working : Upload image : Fix unit tests Working : Upload image : set product image form loaded via ajax, fix category, folder, content WIP : Upload image : set product image form loaded via ajax Setting tinymce Update uploader view Update image edit view Working : Upload management : on content Working : Upload management : on folder, category, product cache dataccessfunctions Working : Upload management : fix e.preventDefault in chrome and safari Working : Image management set on Category fire event on insert content in createmethod fix issue, default foler is set on content creation allow to create new content update default param of content model create content listener for crud management dispatch event in pre/post crud method for content model ... Conflicts: templates/admin/default/product-edit.html
This commit is contained in:
@@ -527,9 +527,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) {
|
||||
@@ -537,7 +534,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
|
||||
$this->redirectToListTemplate();
|
||||
return $this->nullResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,10 +23,13 @@
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Thelia\Core\Event\CategoryDeleteEvent;
|
||||
use Thelia\Core\Event\ImageCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\CategoryUpdateEvent;
|
||||
use Thelia\Core\Event\CategoryCreateEvent;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Model\CategoryQuery;
|
||||
use Thelia\Form\CategoryModificationForm;
|
||||
use Thelia\Form\CategoryCreationForm;
|
||||
@@ -34,7 +37,6 @@ use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Core\Event\CategoryToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\CategoryDeleteContentEvent;
|
||||
use Thelia\Core\Event\CategoryAddContentEvent;
|
||||
use Thelia\Model\CategoryAssociatedContent;
|
||||
use Thelia\Model\FolderQuery;
|
||||
use Thelia\Model\ContentQuery;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
@@ -306,6 +308,39 @@ class CategoryController extends AbstractCrudController
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add category pictures
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function addRelatedPictureAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.categories.update")) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
// $content_id = intval($this->getRequest()->get('content_id'));
|
||||
//
|
||||
// if ($content_id > 0) {
|
||||
//
|
||||
// $event = new CategoryAddContentEvent(
|
||||
// $this->getExistingObject(),
|
||||
// $content_id
|
||||
// );
|
||||
//
|
||||
// try {
|
||||
// $this->dispatch(TheliaEvents::CATEGORY_ADD_CONTENT, $event);
|
||||
// }
|
||||
// catch (\Exception $ex) {
|
||||
// // Any error
|
||||
// return $this->errorPage($ex);
|
||||
// }
|
||||
// }
|
||||
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
public function deleteRelatedContentAction() {
|
||||
|
||||
// Check current user authorization
|
||||
@@ -331,4 +366,5 @@ class CategoryController extends AbstractCrudController
|
||||
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
289
core/lib/Thelia/Controller/Admin/ContentController.php
Normal file
289
core/lib/Thelia/Controller/Admin/ContentController.php
Normal file
@@ -0,0 +1,289 @@
|
||||
<?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\Content\ContentCreateEvent;
|
||||
use Thelia\Core\Event\Content\ContentUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Form\ContentCreationForm;
|
||||
use Thelia\Form\ContentModificationForm;
|
||||
use Thelia\Model\ContentQuery;
|
||||
|
||||
|
||||
/**
|
||||
* Class ContentController
|
||||
* @package Thelia\Controller\Admin
|
||||
* @author manuel raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class ContentController extends AbstractCrudController
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
'content',
|
||||
'manual',
|
||||
'content_order',
|
||||
|
||||
'admin.content.default',
|
||||
'admin.content.create',
|
||||
'admin.content.update',
|
||||
'admin.content.delete',
|
||||
|
||||
TheliaEvents::CONTENT_CREATE,
|
||||
TheliaEvents::CONTENT_UPDATE,
|
||||
TheliaEvents::CONTENT_DELETE,
|
||||
TheliaEvents::CONTENT_TOGGLE_VISIBILITY,
|
||||
TheliaEvents::CONTENT_UPDATE_POSITION
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the creation form for this object
|
||||
*/
|
||||
protected function getCreationForm()
|
||||
{
|
||||
return new ContentCreationForm($this->getRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the update form for this object
|
||||
*/
|
||||
protected function getUpdateForm()
|
||||
{
|
||||
return new ContentModificationForm($this->getRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* Hydrate the update form for this object, before passing it to the update template
|
||||
*
|
||||
* @param \Thelia\Form\ContentModificationForm $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()),
|
||||
);
|
||||
|
||||
// Setup the object form
|
||||
return new ContentModificationForm($this->getRequest(), "form", $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the creation event with the provided form data
|
||||
*
|
||||
* @param unknown $formData
|
||||
*/
|
||||
protected function getCreationEvent($formData)
|
||||
{
|
||||
$contentCreateEvent = new ContentCreateEvent();
|
||||
|
||||
$contentCreateEvent
|
||||
->setLocale($formData['locale'])
|
||||
->setDefaultFolder($formData['default_folder'])
|
||||
->setTitle($formData['title'])
|
||||
->setVisible($formData['visible'])
|
||||
;
|
||||
|
||||
return $contentCreateEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the update event with the provided form data
|
||||
*
|
||||
* @param unknown $formData
|
||||
*/
|
||||
protected function getUpdateEvent($formData)
|
||||
{
|
||||
$contentUpdateEvent = new ContentUpdateEvent($formData['id']);
|
||||
|
||||
$contentUpdateEvent
|
||||
->setLocale($formData['locale'])
|
||||
->setTitle($formData['title'])
|
||||
->setChapo($formData['chapo'])
|
||||
->setDescription($formData['description'])
|
||||
->setPostscriptum($formData['postscriptum'])
|
||||
->setVisible($formData['visible'])
|
||||
->setUrl($formData['url'])
|
||||
->setDefaultFolder($formData['default_folder']);
|
||||
|
||||
return $contentUpdateEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the delete event with the provided form data
|
||||
*/
|
||||
protected function getDeleteEvent()
|
||||
{
|
||||
// TODO: Implement getDeleteEvent() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the event contains the object, e.g. the action has updated the object in the event.
|
||||
*
|
||||
* @param \Thelia\Core\Event\Content\ContentEvent $event
|
||||
*/
|
||||
protected function eventContainsObject($event)
|
||||
{
|
||||
return $event->hasContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the created object from an event.
|
||||
*
|
||||
* @param $event \Thelia\Core\Event\Content\ContentEvent
|
||||
*
|
||||
* @return null|\Thelia\Model\Content
|
||||
*/
|
||||
protected function getObjectFromEvent($event)
|
||||
{
|
||||
return $event->getContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load an existing object from the database
|
||||
*
|
||||
* @return \Thelia\Model\Content
|
||||
*/
|
||||
protected function getExistingObject()
|
||||
{
|
||||
return ContentQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->findOneById($this->getRequest()->get('content_id', 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object label form the object event (name, title, etc.)
|
||||
*
|
||||
* @param $object \Thelia\Model\Content
|
||||
*
|
||||
* @return string content title
|
||||
*
|
||||
*/
|
||||
protected function getObjectLabel($object)
|
||||
{
|
||||
return $object->getTitle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object ID from the object
|
||||
*
|
||||
* @param $object \Thelia\Model\Content
|
||||
*
|
||||
* @return int content id
|
||||
*/
|
||||
protected function getObjectId($object)
|
||||
{
|
||||
return $object->getId();
|
||||
}
|
||||
|
||||
protected function getFolderId()
|
||||
{
|
||||
$folderId = $this->getRequest()->get('folder_id', null);
|
||||
|
||||
if(null === $folderId) {
|
||||
$content = $this->getExistingObject();
|
||||
|
||||
if($content) {
|
||||
$folderId = $content->getDefaultFolderId();
|
||||
}
|
||||
}
|
||||
|
||||
return $folderId ?: 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the main list template
|
||||
*
|
||||
* @param unknown $currentOrder, if any, null otherwise.
|
||||
*/
|
||||
protected function renderListTemplate($currentOrder)
|
||||
{
|
||||
$this->getListOrderFromSession('content', 'content_order', 'manual');
|
||||
|
||||
return $this->render('folders',
|
||||
array(
|
||||
'content_order' => $currentOrder,
|
||||
'parent' => $this->getFolderId()
|
||||
));
|
||||
}
|
||||
|
||||
protected function getEditionArguments()
|
||||
{
|
||||
return array(
|
||||
'content_id' => $this->getRequest()->get('content_id', 0),
|
||||
'current_tab' => $this->getRequest()->get('current_tab', 'general')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the edition template
|
||||
*/
|
||||
protected function renderEditionTemplate()
|
||||
{
|
||||
return $this->render('content-edit', $this->getEditionArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to the edition template
|
||||
*/
|
||||
protected function redirectToEditionTemplate()
|
||||
{
|
||||
$this->redirect($this->getRoute('admin.content.update', $this->getEditionArguments()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to the list template
|
||||
*/
|
||||
protected function redirectToListTemplate()
|
||||
{
|
||||
$this->redirectToRoute(
|
||||
'admin.content.default',
|
||||
array('parent' => $this->getFolderId())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Thelia\Core\Event\Content\ContentUpdateEvent $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('parent' => $this->getFolderId())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
403
core/lib/Thelia/Controller/Admin/FileController.php
Executable file
403
core/lib/Thelia/Controller/Admin/FileController.php
Executable file
@@ -0,0 +1,403 @@
|
||||
<?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 Propel\Runtime\Exception\PropelException;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Router;
|
||||
use Symfony\Component\Validator\Constraints\Image;
|
||||
use Symfony\Component\Validator\Constraints\ImageValidator;
|
||||
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
|
||||
use Thelia\Core\Event\ImageCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\ImagesCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\ImageDeleteEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Model\CategoryImage;
|
||||
use Thelia\Model\ContentImage;
|
||||
use Thelia\Model\FolderImage;
|
||||
use Thelia\Model\ProductImage;
|
||||
use Thelia\Tools\FileManager;
|
||||
use Thelia\Tools\Rest\ResponseRest;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Control View and Action (Model) via Events
|
||||
* Control Files and Images
|
||||
*
|
||||
* @package File
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class FileController extends BaseAdminController
|
||||
{
|
||||
/**
|
||||
* Manage how a file collection has to be saved
|
||||
*
|
||||
* @param int $parentId Parent id owning files being saved
|
||||
* @param string $parentType Parent Type owning files being saved
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function saveFilesAction($parentId, $parentType)
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage how a image collection has to be saved
|
||||
*
|
||||
* @param int $parentId Parent id owning images being saved
|
||||
* @param string $parentType Parent Type owning images being saved
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function saveImageAjaxAction($parentId, $parentType)
|
||||
{
|
||||
$this->checkAuth('ADMIN', 'admin.image.save');
|
||||
$this->checkXmlHttpRequest();
|
||||
|
||||
if ($this->isParentTypeValid($parentType)) {
|
||||
if ($this->getRequest()->isMethod('POST')) {
|
||||
|
||||
/** @var UploadedFile $fileBeingUploaded */
|
||||
$fileBeingUploaded = $this->getRequest()->files->get('file');
|
||||
|
||||
$fileManager = new FileManager($this->container);
|
||||
|
||||
// Validate if file is too big
|
||||
if ($fileBeingUploaded->getError() == 1) {
|
||||
$message = $this->getTranslator()
|
||||
->trans(
|
||||
'File is too heavy, please retry with a file having a size less than %size%.',
|
||||
array('%size%' => ini_get('post_max_size')),
|
||||
'image'
|
||||
);
|
||||
|
||||
return new ResponseRest($message, 'text', 403);
|
||||
}
|
||||
// Validate if it is a image or file
|
||||
if (!$fileManager->isImage($fileBeingUploaded->getMimeType())) {
|
||||
$message = $this->getTranslator()
|
||||
->trans(
|
||||
'You can only upload images (.png, .jpg, .jpeg, .gif)',
|
||||
array(),
|
||||
'image'
|
||||
);
|
||||
|
||||
return new ResponseRest($message, 'text', 415);
|
||||
}
|
||||
|
||||
$parentModel = $fileManager->getParentImageModel($parentType, $parentId);
|
||||
$imageModel = $fileManager->getImageModel($parentType);
|
||||
|
||||
if ($parentModel === null || $imageModel === null || $fileBeingUploaded === null) {
|
||||
return new Response('', 404);
|
||||
}
|
||||
|
||||
$defaultTitle = $parentModel->getTitle();
|
||||
$imageModel->setParentId($parentId);
|
||||
$imageModel->setTitle($defaultTitle);
|
||||
|
||||
$imageCreateOrUpdateEvent = new ImageCreateOrUpdateEvent(
|
||||
$parentType,
|
||||
$parentId
|
||||
);
|
||||
$imageCreateOrUpdateEvent->setModelImage($imageModel);
|
||||
$imageCreateOrUpdateEvent->setUploadedFile($fileBeingUploaded);
|
||||
$imageCreateOrUpdateEvent->setParentName($parentModel->getTitle());
|
||||
|
||||
|
||||
// Dispatch Event to the Action
|
||||
$this->dispatch(
|
||||
TheliaEvents::IMAGE_SAVE,
|
||||
$imageCreateOrUpdateEvent
|
||||
);
|
||||
|
||||
|
||||
return new ResponseRest(array('status' => true, 'message' => ''));
|
||||
}
|
||||
}
|
||||
|
||||
return new Response('', 404);
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage how a image list will be displayed in AJAX
|
||||
*
|
||||
* @param int $parentId Parent id owning images being saved
|
||||
* @param string $parentType Parent Type owning images being saved
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function getImageListAjaxAction($parentId, $parentType)
|
||||
{
|
||||
$this->checkAuth('ADMIN', 'admin.image.save');
|
||||
$this->checkXmlHttpRequest();
|
||||
$args = array('imageType' => $parentType, 'parentId' => $parentId);
|
||||
|
||||
return $this->render('includes/image-upload-list-ajax', $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage how an image list will be uploaded in AJAX
|
||||
*
|
||||
* @param int $parentId Parent id owning images being saved
|
||||
* @param string $parentType Parent Type owning images being saved
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function getImageFormAjaxAction($parentId, $parentType)
|
||||
{
|
||||
$this->checkAuth('ADMIN', 'admin.image.save');
|
||||
$this->checkXmlHttpRequest();
|
||||
$args = array('imageType' => $parentType, 'parentId' => $parentId);
|
||||
|
||||
return $this->render('includes/image-upload-form', $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage how an image is viewed
|
||||
*
|
||||
* @param int $imageId Parent id owning images being saved
|
||||
* @param string $parentType Parent Type owning images being saved
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewImageAction($imageId, $parentType)
|
||||
{
|
||||
if (null !== $response = $this->checkAuth('admin.image.view')) {
|
||||
return $response;
|
||||
}
|
||||
try {
|
||||
$fileManager = new FileManager($this->container);
|
||||
$image = $fileManager->getImageModelQuery($parentType)->findPk($imageId);
|
||||
$redirectUrl = $fileManager->getRedirectionUrl($parentType, $image->getParentId());
|
||||
|
||||
return $this->render('image-edit', array(
|
||||
'imageId' => $imageId,
|
||||
'imageType' => $parentType,
|
||||
'redirectUrl' => $redirectUrl
|
||||
));
|
||||
} catch (Exception $e) {
|
||||
$this->pageNotFound();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage how an image is updated
|
||||
*
|
||||
* @param int $imageId Parent id owning images being saved
|
||||
* @param string $parentType Parent Type owning images being saved
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function updateImageAction($imageId, $parentType)
|
||||
{
|
||||
if (null !== $response = $this->checkAuth('admin.image.update')) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$message = false;
|
||||
|
||||
$fileManager = new FileManager($this->container);
|
||||
$imageModification = $fileManager->getImageForm($parentType, $this->getRequest());
|
||||
|
||||
try {
|
||||
$image = $fileManager->getImageModelQuery($parentType)->findPk($imageId);
|
||||
$oldImage = clone $image;
|
||||
if (null === $image) {
|
||||
throw new \InvalidArgumentException(sprintf('%d image id does not exists', $imageId));
|
||||
}
|
||||
|
||||
$form = $this->validateForm($imageModification);
|
||||
|
||||
$event = $this->createEventInstance($parentType, $image, $form->getData());
|
||||
$event->setOldModelImage($oldImage);
|
||||
|
||||
$files = $this->getRequest()->files;
|
||||
$fileForm = $files->get($imageModification->getName());
|
||||
if (isset($fileForm['file'])) {
|
||||
$event->setUploadedFile($fileForm['file']);
|
||||
}
|
||||
|
||||
$this->dispatch(TheliaEvents::IMAGE_UPDATE, $event);
|
||||
|
||||
$imageUpdated = $event->getModelImage();
|
||||
|
||||
$this->adminLogAppend(sprintf('Image with Ref %s (ID %d) modified', $imageUpdated->getTitle(), $imageUpdated->getId()));
|
||||
|
||||
if ($this->getRequest()->get('save_mode') == 'close') {
|
||||
$this->redirectToRoute('admin.images');
|
||||
} else {
|
||||
$this->redirectSuccess($imageModification);
|
||||
}
|
||||
|
||||
} catch (FormValidationException $e) {
|
||||
$message = sprintf('Please check your input: %s', $e->getMessage());
|
||||
} catch (PropelException $e) {
|
||||
$message = $e->getMessage();
|
||||
} catch (\Exception $e) {
|
||||
$message = sprintf('Sorry, an error occurred: %s', $e->getMessage().' '.$e->getFile());
|
||||
}
|
||||
|
||||
if ($message !== false) {
|
||||
Tlog::getInstance()->error(sprintf('Error during image editing : %s.', $message));
|
||||
|
||||
$imageModification->setErrorMessage($message);
|
||||
|
||||
$this->getParserContext()
|
||||
->addForm($imageModification)
|
||||
->setGeneralError($message);
|
||||
}
|
||||
|
||||
return $this->render('image-edit', array(
|
||||
'imageId' => $imageId,
|
||||
'imageType' => $parentType
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage how a image has to be deleted (AJAX)
|
||||
*
|
||||
* @param int $imageId Parent id owning images being saved
|
||||
* @param string $parentType Parent Type owning images being saved
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function deleteImagesAction($imageId, $parentType)
|
||||
{
|
||||
$this->checkAuth('ADMIN', 'admin.image.delete');
|
||||
$this->checkXmlHttpRequest();
|
||||
|
||||
$fileManager = new FileManager($this->container);
|
||||
$imageModelQuery = $fileManager->getImageModelQuery($parentType);
|
||||
$model = $imageModelQuery->findPk($imageId);
|
||||
|
||||
if ($model == null) {
|
||||
return $this->pageNotFound();
|
||||
}
|
||||
|
||||
// Feed event
|
||||
$imageDeleteEvent = new ImageDeleteEvent(
|
||||
$model,
|
||||
$parentType
|
||||
);
|
||||
|
||||
// Dispatch Event to the Action
|
||||
$this->dispatch(
|
||||
TheliaEvents::IMAGE_DELETE,
|
||||
$imageDeleteEvent
|
||||
);
|
||||
|
||||
$message = $this->getTranslator()
|
||||
->trans(
|
||||
'Images deleted successfully',
|
||||
array(),
|
||||
'image'
|
||||
);
|
||||
|
||||
return new Response($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log error message
|
||||
*
|
||||
* @param string $parentType Parent type
|
||||
* @param string $action Creation|Update|Delete
|
||||
* @param string $message Message to log
|
||||
* @param \Exception $e Exception to log
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function logError($parentType, $action, $message, $e)
|
||||
{
|
||||
Tlog::getInstance()->error(
|
||||
sprintf(
|
||||
'Error during ' . $parentType . ' ' . $action . ' process : %s. Exception was %s',
|
||||
$message,
|
||||
$e->getMessage()
|
||||
)
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if parent type is valid or not
|
||||
*
|
||||
* @param string $parentType Parent type
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isParentTypeValid($parentType)
|
||||
{
|
||||
return (in_array($parentType, ImagesCreateOrUpdateEvent::getAvailableType()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Event instance
|
||||
*
|
||||
* @param string $parentType Parent Type owning images being saved
|
||||
* @param CategoryImage|ProductImage|ContentImage|FolderImage $model Image model
|
||||
* @param array $data Post data
|
||||
*
|
||||
* @return ImageCreateOrUpdateEvent
|
||||
*/
|
||||
private function createEventInstance($parentType, $model, $data)
|
||||
{
|
||||
$imageCreateEvent = new ImageCreateOrUpdateEvent($parentType, null);
|
||||
|
||||
if (isset($data['title'])) {
|
||||
$model->setTitle($data['title']);
|
||||
}
|
||||
if (isset($data['chapo'])) {
|
||||
$model->setChapo($data['chapo']);
|
||||
}
|
||||
if (isset($data['description'])) {
|
||||
$model->setDescription($data['description']);
|
||||
}
|
||||
if (isset($data['file'])) {
|
||||
$model->setFile($data['file']);
|
||||
}
|
||||
if (isset($data['postscriptum'])) {
|
||||
$model->setPostscriptum($data['postscriptum']);
|
||||
}
|
||||
|
||||
$imageCreateEvent->setModelImage($model);
|
||||
|
||||
return $imageCreateEvent;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -22,25 +22,307 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
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 BaseAdminController
|
||||
class FolderController extends AbstractCrudController
|
||||
{
|
||||
public function indexAction()
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.folder.view")) return $response;
|
||||
return $this->render("folders", array("display_folder" => 20));
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
public function updateAction($folder_id)
|
||||
|
||||
/**
|
||||
* 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 \Thelia\Core\Event\FolderEvent $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 content order
|
||||
$content_order = $this->getListOrderFromSession('content', 'content_order', 'manual');
|
||||
|
||||
return $this->render('folders',
|
||||
array(
|
||||
'folder_order' => $currentOrder,
|
||||
'content_order' => $content_order,
|
||||
'parent' => $this->getRequest()->get('parent', 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('parent' => $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('parent' => $deleteEvent->getFolder()->getParent())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $event \Thelia\Core\Event\UpdatePositionEvent
|
||||
* @return null|Response
|
||||
*/
|
||||
protected function performAdditionalUpdatePositionAction($event)
|
||||
{
|
||||
|
||||
return $this->render("folder-edit", array(
|
||||
"folder_id" => $folder_id
|
||||
));
|
||||
$folder = FolderQuery::create()->findPk($event->getObjectId());
|
||||
|
||||
if ($folder != null) {
|
||||
// Redirect to parent category list
|
||||
$this->redirectToRoute(
|
||||
'admin.folders.default',
|
||||
array('parent' => $folder->getParent())
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to the edition template
|
||||
*/
|
||||
protected function redirectToEditionTemplate()
|
||||
{
|
||||
$this->redirect($this->getRoute('admin.folders.update', $this->getEditionArguments()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to the list template
|
||||
*/
|
||||
protected function redirectToListTemplate()
|
||||
{
|
||||
$this->redirectToRoute(
|
||||
'admin.folders.default',
|
||||
array('parent' => $this->getRequest()->get('parent', 0))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -48,11 +48,14 @@ use Thelia\Model\FeatureQuery;
|
||||
use Thelia\Core\Event\FeatureProductDeleteEvent;
|
||||
use Thelia\Model\FeatureTemplateQuery;
|
||||
use Thelia\Core\Event\ProductSetTemplateEvent;
|
||||
use Thelia\Model\Base\ProductSaleElementsQuery;
|
||||
use Thelia\Core\Event\ProductAddCategoryEvent;
|
||||
use Thelia\Core\Event\ProductDeleteCategoryEvent;
|
||||
use Thelia\Model\AttributeQuery;
|
||||
use Thelia\Model\AttributeAvQuery;
|
||||
use Thelia\Model\ProductSaleElementsQuery;
|
||||
use Thelia\Model\AttributeCombination;
|
||||
use Thelia\Model\AttributeAv;
|
||||
use Thelia\Core\Event\ProductCreateCombinationEvent;
|
||||
|
||||
/**
|
||||
* Manages products
|
||||
@@ -699,6 +702,7 @@ class ProductController extends AbstractCrudController
|
||||
}
|
||||
|
||||
public function addAttributeValueToCombinationAction($productId, $attributeAvId, $combination) {
|
||||
|
||||
$result = array();
|
||||
|
||||
// Get attribute for this product
|
||||
@@ -708,6 +712,8 @@ class ProductController extends AbstractCrudController
|
||||
|
||||
$addIt = true;
|
||||
|
||||
$attribute = $attributeAv->getAttribute();
|
||||
|
||||
// Check if this attribute is not already present
|
||||
$combinationArray = explode(',', $combination);
|
||||
|
||||
@@ -717,9 +723,7 @@ class ProductController extends AbstractCrudController
|
||||
|
||||
if ($attrAv !== null) {
|
||||
|
||||
if ($attrAv->getAttributeId() == $attributeAv->getAttributeId()) {
|
||||
|
||||
$attribute = AttributeQuery::create()->joinWithI18n($this->getCurrentEditionLocale())->findPk($attributeAv->getAttributeId());
|
||||
if ($attrAv->getAttributeId() == $attribute->getId()) {
|
||||
|
||||
$result['error'] = $this->getTranslator()->trans(
|
||||
'A value for attribute "%name" is already present in the combination',
|
||||
@@ -729,13 +733,39 @@ class ProductController extends AbstractCrudController
|
||||
$addIt = false;
|
||||
}
|
||||
|
||||
$result[] = array('id' => $attrAv->getId(), 'title' => $attrAv->getTitle());
|
||||
$result[] = array('id' => $attrAv->getId(), 'title' => $attrAv->getAttribute()->getTitle() . " : " . $attrAv->getTitle());
|
||||
}
|
||||
}
|
||||
|
||||
if ($addIt) $result[] = array('id' => $attributeAv->getId(), 'title' => $attributeAv->getTitle());
|
||||
if ($addIt) $result[] = array('id' => $attributeAv->getId(), 'title' => $attribute->getTitle() . " : " . $attributeAv->getTitle());
|
||||
}
|
||||
|
||||
return $this->jsonResponse(json_encode($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* A a new combination to a product
|
||||
*/
|
||||
public function addCombinationAction() {
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.products.update")) return $response;
|
||||
|
||||
$event = new ProductCreateCombinationEvent(
|
||||
$this->getExistingObject(),
|
||||
$this->getRequest()->get('use_default_princing', 0),
|
||||
$this->getRequest()->get('combination_attributes', array())
|
||||
);
|
||||
|
||||
try {
|
||||
$this->dispatch(TheliaEvents::PRODUCT_ADD_COMBINATION, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
echo "done!";
|
||||
exit;
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -69,7 +71,7 @@ class BaseFrontController extends BaseController
|
||||
protected function checkValidDelivery()
|
||||
{
|
||||
$order = $this->getSession()->getOrder();
|
||||
if(null === $order || null === $order->chosenDeliveryAddress || null === $order->getDeliveryModuleId()) {
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -77,7 +79,7 @@ class BaseFrontController extends BaseController
|
||||
protected function checkValidInvoice()
|
||||
{
|
||||
$order = $this->getSession()->getOrder();
|
||||
if(null === $order || null === $order->chosenInvoiceAddress || null === $order->getPaymentModuleId()) {
|
||||
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,6 +23,7 @@
|
||||
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;
|
||||
@@ -32,9 +33,11 @@ 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
|
||||
@@ -78,11 +81,8 @@ class OrderController extends BaseFrontController
|
||||
throw new \Exception("Delivery module cannot be use with selected delivery address");
|
||||
}
|
||||
|
||||
/* try to get postage amount */
|
||||
/* get postage amount */
|
||||
$moduleReflection = new \ReflectionClass($deliveryModule->getFullNamespace());
|
||||
if ($moduleReflection->isSubclassOf("Thelia\Module\DeliveryModuleInterface") === false) {
|
||||
throw new \RuntimeException(sprintf("delivery module %s is not a Thelia\Module\DeliveryModuleInterface", $deliveryModule->getCode()));
|
||||
}
|
||||
$moduleInstance = $moduleReflection->newInstance();
|
||||
$postage = $moduleInstance->getPostage($deliveryAddress->getCountry());
|
||||
|
||||
@@ -190,6 +190,36 @@ class OrderController extends BaseFrontController
|
||||
$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()
|
||||
|
||||
Reference in New Issue
Block a user