Inital commit

This commit is contained in:
2020-11-19 15:36:28 +01:00
parent 71f32f83d3
commit 66ce4ee218
18077 changed files with 2166122 additions and 35184 deletions

View File

@@ -1,227 +1,273 @@
<?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 Front\Controller;
use Front\Front;
use Thelia\Controller\Front\BaseFrontController;
use Thelia\Core\Event\Address\AddressCreateOrUpdateEvent;
use Thelia\Core\Event\Address\AddressEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Translation\Translator;
use Thelia\Form\AddressCreateForm;
use Thelia\Form\AddressUpdateForm;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\AddressQuery;
use Thelia\Model\Customer;
/**
* Class AddressController
* @package Thelia\Controller\Front
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class AddressController extends BaseFrontController
{
/**
* Controller for generate modal containing update form
* Check if request is a XmlHttpRequest and address owner is the current customer
* @param $address_id
*/
public function generateModalAction($address_id)
{
$this->checkAuth();
$this->checkXmlHttpRequest();
}
/**
* Create controller.
* Check if customer is logged in
*
* Dispatch TheliaEvents::ADDRESS_CREATE event
*/
public function createAction()
{
$this->checkAuth();
$addressCreate = new AddressCreateForm($this->getRequest());
try {
$customer = $this->getSecurityContext()->getCustomerUser();
$form = $this->validateForm($addressCreate, "post");
$event = $this->createAddressEvent($form);
$event->setCustomer($customer);
$this->dispatch(TheliaEvents::ADDRESS_CREATE, $event);
$this->redirectSuccess($addressCreate);
} catch (FormValidationException $e) {
$message = Translator::getInstance()->trans("Please check your input: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
} catch (\Exception $e) {
$message = Translator::getInstance()->trans("Sorry, an error occured: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
}
if ($message !== false) {
\Thelia\Log\Tlog::getInstance()->error(sprintf("Error during address creation process : %s", $message));
$addressCreate->setErrorMessage($message);
$this->getParserContext()
->addForm($addressCreate)
->setGeneralError($message)
;
}
}
public function updateViewAction($address_id)
{
$this->checkAuth();
$customer = $this->getSecurityContext()->getCustomerUser();
$address = AddressQuery::create()->findPk($address_id);
if (!$address || $customer->getId() != $address->getCustomerId()) {
$this->redirectToRoute('default');
}
$this->getParserContext()->set("address_id", $address_id);
}
public function processUpdateAction($address_id)
{
$this->checkAuth();
$request = $this->getRequest();
$addressUpdate = new AddressUpdateForm($request);
try {
$customer = $this->getSecurityContext()->getCustomerUser();
$form = $this->validateForm($addressUpdate);
$address = AddressQuery::create()->findPk($address_id);
if (null === $address) {
$this->redirectToRoute('default');
}
if ($address->getCustomer()->getId() != $customer->getId()) {
$this->redirectToRoute('default');
}
$event = $this->createAddressEvent($form);
$event->setAddress($address);
$this->dispatch(TheliaEvents::ADDRESS_UPDATE, $event);
$this->redirectSuccess($addressUpdate);
} catch (FormValidationException $e) {
$message = Translator::getInstance()->trans("Please check your input: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
} catch (\Exception $e) {
$message = Translator::getInstance()->trans("Sorry, an error occured: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
}
$this->getParserContext()->set("address_id", $address_id);
if ($message !== false) {
\Thelia\Log\Tlog::getInstance()->error(sprintf("Error during address creation process : %s", $message));
$addressUpdate->setErrorMessage($message);
$this->getParserContext()
->addForm($addressUpdate)
->setGeneralError($message)
;
}
}
public function deleteAction($address_id)
{
$this->checkAuth();
$error_message = false;
$customer = $this->getSecurityContext()->getCustomerUser();
$address = AddressQuery::create()->findPk($address_id);
if (!$address || $customer->getId() != $address->getCustomerId()) {
// If Ajax Request
if ($this->getRequest()->isXmlHttpRequest()) {
return $this->jsonResponse(json_encode(array(
"success" => false,
"message" => "Error during address deletion process"
)));
} else {
$this->redirectToRoute('default');
}
}
try {
$this->dispatch(TheliaEvents::ADDRESS_DELETE, new AddressEvent($address));
} catch (\Exception $e) {
$error_message = $e->getMessage();
}
\Thelia\Log\Tlog::getInstance()->error(sprintf('Error during address deletion : %s', $error_message));
// If Ajax Request
if ($this->getRequest()->isXmlHttpRequest()) {
if ($error_message) {
$response = $this->jsonResponse(json_encode(array(
"success" => false,
"message" => $error_message
)));
} else {
$response = $this->jsonResponse(json_encode(array(
"success" => true,
"message" => ""
)));;
}
return $response;
} else {
$this->redirectToRoute('default', array('view'=>'account'));
}
}
protected function createAddressEvent($form)
{
return new AddressCreateOrUpdateEvent(
$form->get("label")->getData(),
$form->get("title")->getData(),
$form->get("firstname")->getData(),
$form->get("lastname")->getData(),
$form->get("address1")->getData(),
$form->get("address2")->getData(),
$form->get("address3")->getData(),
$form->get("zipcode")->getData(),
$form->get("city")->getData(),
$form->get("country")->getData(),
$form->get("cellphone")->getData(),
$form->get("phone")->getData(),
$form->get("company")->getData(),
$form->get("is_default")->getData()
);
}
}
<?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 Front\Controller;
use Front\Front;
use Symfony\Component\Form\Form;
use Thelia\Controller\Front\BaseFrontController;
use Thelia\Core\Event\Address\AddressCreateOrUpdateEvent;
use Thelia\Core\Event\Address\AddressEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\Definition\FrontForm;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Log\Tlog;
use Thelia\Model\AddressQuery;
use Thelia\Model\Customer;
/**
* Class AddressController
* @package Thelia\Controller\Front
* @author Manuel Raynaud <manu@raynaud.io>
*/
class AddressController extends BaseFrontController
{
/**
* Controller for generate modal containing update form
* Check if request is a XmlHttpRequest and address owner is the current customer
*
* @param $address_id
*/
public function generateModalAction($address_id)
{
$this->checkAuth();
$this->checkXmlHttpRequest();
}
/**
* Create controller.
* Check if customer is logged in
*
* Dispatch TheliaEvents::ADDRESS_CREATE event
*/
public function createAction()
{
$this->checkAuth();
$addressCreate = $this->createForm(FrontForm::ADDRESS_CREATE);
try {
/** @var Customer $customer */
$customer = $this->getSecurityContext()->getCustomerUser();
$form = $this->validateForm($addressCreate, "post");
$event = $this->createAddressEvent($form);
$event->setCustomer($customer);
$this->dispatch(TheliaEvents::ADDRESS_CREATE, $event);
return $this->generateSuccessRedirect($addressCreate);
} catch (FormValidationException $e) {
$message = $this->getTranslator()->trans("Please check your input: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
} catch (\Exception $e) {
$message = $this->getTranslator()->trans("Sorry, an error occured: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
}
Tlog::getInstance()->error(sprintf("Error during address creation process : %s", $message));
$addressCreate->setErrorMessage($message);
$this->getParserContext()
->addForm($addressCreate)
->setGeneralError($message)
;
// Redirect to error URL if defined
if ($addressCreate->hasErrorUrl()) {
return $this->generateErrorRedirect($addressCreate);
}
}
protected function createAddressEvent(Form $form)
{
return new AddressCreateOrUpdateEvent(
$form->get("label")->getData(),
$form->get("title")->getData(),
$form->get("firstname")->getData(),
$form->get("lastname")->getData(),
$form->get("address1")->getData(),
$form->get("address2")->getData(),
$form->get("address3")->getData(),
$form->get("zipcode")->getData(),
$form->get("city")->getData(),
$form->get("country")->getData(),
$form->get("cellphone")->getData(),
$form->get("phone")->getData(),
$form->get("company")->getData(),
$form->get("is_default")->getData(),
$form->get("state")->getData()
);
}
public function updateViewAction($address_id)
{
$this->checkAuth();
$customer = $this->getSecurityContext()->getCustomerUser();
$address = AddressQuery::create()->findPk($address_id);
if (!$address || $customer->getId() != $address->getCustomerId()) {
return $this->generateRedirectFromRoute('default');
}
$this->getParserContext()->set("address_id", $address_id);
}
public function processUpdateAction($address_id)
{
$this->checkAuth();
$addressUpdate = $this->createForm(FrontForm::ADDRESS_UPDATE);
try {
$customer = $this->getSecurityContext()->getCustomerUser();
$form = $this->validateForm($addressUpdate);
$address = AddressQuery::create()->findPk($address_id);
if (null === $address) {
return $this->generateRedirectFromRoute('default');
}
if ($address->getCustomer()->getId() != $customer->getId()) {
return $this->generateRedirectFromRoute('default');
}
$event = $this->createAddressEvent($form);
$event->setAddress($address);
$this->dispatch(TheliaEvents::ADDRESS_UPDATE, $event);
return $this->generateSuccessRedirect($addressUpdate);
} catch (FormValidationException $e) {
$message = $this->getTranslator()->trans("Please check your input: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
} catch (\Exception $e) {
$message = $this->getTranslator()->trans("Sorry, an error occured: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
}
$this->getParserContext()->set("address_id", $address_id);
Tlog::getInstance()->error(sprintf("Error during address creation process : %s", $message));
$addressUpdate->setErrorMessage($message);
$this->getParserContext()
->addForm($addressUpdate)
->setGeneralError($message)
;
if ($addressUpdate->hasErrorUrl()) {
return $this->generateErrorRedirect($addressUpdate);
}
}
public function deleteAction($address_id)
{
$this->checkAuth();
$error_message = false;
$customer = $this->getSecurityContext()->getCustomerUser();
$address = AddressQuery::create()->findPk($address_id);
if (!$address || $customer->getId() != $address->getCustomerId()) {
// If Ajax Request
if ($this->getRequest()->isXmlHttpRequest()) {
return $this->jsonResponse(
json_encode(
array(
"success" => false,
"message" => $this->getTranslator()->trans(
"Error during address deletion process",
[],
Front::MESSAGE_DOMAIN
)
)
)
);
} else {
return $this->generateRedirectFromRoute('default');
}
}
try {
$this->dispatch(TheliaEvents::ADDRESS_DELETE, new AddressEvent($address));
} catch (\Exception $e) {
$error_message = $e->getMessage();
}
Tlog::getInstance()->error(sprintf('Error during address deletion : %s', $error_message));
// If Ajax Request
if ($this->getRequest()->isXmlHttpRequest()) {
if ($error_message) {
$response = $this->jsonResponse(json_encode(array(
"success" => false,
"message" => $error_message
)));
} else {
$response = $this->jsonResponse(
json_encode([
"success" => true,
"message" => ""
])
);
}
return $response;
} else {
return $this->generateRedirectFromRoute('default', array('view'=>'account'));
}
}
public function makeAddressDefaultAction($addressId)
{
$this->checkAuth();
$address = AddressQuery::create()
->filterByCustomerId($this->getSecurityContext()->getCustomerUser()->getId())
->findPk($addressId)
;
if (null === $address) {
$this->pageNotFound();
}
try {
$event = new AddressEvent($address);
$this->dispatch(TheliaEvents::ADDRESS_DEFAULT, $event);
} catch (\Exception $e) {
$this->getParserContext()
->setGeneralError($e->getMessage())
;
return $this->render("account");
}
return $this->generateRedirectFromRoute('default', array('view'=>'account'));
}
}

View File

@@ -22,6 +22,7 @@
/*************************************************************************************/
namespace Front\Controller;
use Front\Front;
use Propel\Runtime\Exception\PropelException;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Request;
@@ -30,17 +31,17 @@ use Thelia\Core\Event\Cart\CartEvent;
use Thelia\Core\Event\Order\OrderEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\CartAdd;
use Thelia\Form\Definition\FrontForm;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Log\Tlog;
use Thelia\Model\AddressQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Model\OrderPostage;
use Thelia\Module\Exception\DeliveryException;
use Thelia\Tools\URL;
class CartController extends BaseFrontController
{
use \Thelia\Cart\CartTrait;
public function addItem()
{
$request = $this->getRequest();
@@ -52,31 +53,31 @@ class CartController extends BaseFrontController
$form = $this->validateForm($cartAdd);
$cartEvent = $this->getCartEvent();
$cartEvent->setNewness($form->get("newness")->getData());
$cartEvent->setAppend($form->get("append")->getData());
$cartEvent->setQuantity($form->get("quantity")->getData());
$cartEvent->setProductSaleElementsId($form->get("product_sale_elements_id")->getData());
$cartEvent->setProduct($form->get("product")->getData());
$cartEvent->bindForm($form);
$this->getDispatcher()->dispatch(TheliaEvents::CART_ADDITEM, $cartEvent);
$this->afterModifyCart();
$this->redirectSuccess();
if ($this->getRequest()->isXmlHttpRequest()) {
$this->changeViewForAjax();
} elseif (null !== $response = $this->generateSuccessRedirect($cartAdd)) {
return $response;
}
} catch (PropelException $e) {
Tlog::getInstance()->error(sprintf("Failed to add item to cart with message : %s", $e->getMessage()));
$message = "Failed to add this article to your cart, please try again";
$message = $this->getTranslator()->trans(
"Failed to add this article to your cart, please try again",
[],
Front::MESSAGE_DOMAIN
);
} catch (FormValidationException $e) {
$message = $e->getMessage();
}
// If Ajax Request
if ($this->getRequest()->isXmlHttpRequest()) {
$request = $this->getRequest();
$request->attributes->set('_view', "includes/mini-cart");
}
if ($message) {
$cartAdd->setErrorMessage($message);
$this->getParserContext()->addForm($cartAdd);
@@ -86,37 +87,67 @@ class CartController extends BaseFrontController
public function changeItem()
{
$cartEvent = $this->getCartEvent();
$cartEvent->setCartItem($this->getRequest()->get("cart_item"));
$cartEvent->setCartItemId($this->getRequest()->get("cart_item"));
$cartEvent->setQuantity($this->getRequest()->get("quantity"));
try {
$this->getTokenProvider()->checkToken(
$this->getRequest()->query->get('_token')
);
$this->dispatch(TheliaEvents::CART_UPDATEITEM, $cartEvent);
$this->afterModifyCart();
$this->redirectSuccess();
} catch (PropelException $e) {
if ($this->getRequest()->isXmlHttpRequest()) {
$this->changeViewForAjax();
}
} catch (\Exception $e) {
Tlog::getInstance()->error(sprintf("Failed to change cart item quantity: %s", $e->getMessage()));
$this->getParserContext()->setGeneralError($e->getMessage());
}
}
public function deleteItem()
{
$cartEvent = $this->getCartEvent();
$cartEvent->setCartItem($this->getRequest()->get("cart_item"));
$cartEvent->setCartItemId($this->getRequest()->get("cart_item"));
try {
$this->getTokenProvider()->checkToken(
$this->getRequest()->query->get('_token')
);
$this->getDispatcher()->dispatch(TheliaEvents::CART_DELETEITEM, $cartEvent);
$this->afterModifyCart();
$this->redirectSuccess();
} catch (PropelException $e) {
} catch (\Exception $e) {
Tlog::getInstance()->error(sprintf("error during deleting cartItem with message : %s", $e->getMessage()));
$this->getParserContext()->setGeneralError($e->getMessage());
}
$this->changeViewForAjax();
if (null != $successUrl = $this->getRequest()->query->get('success_url')) {
$response = $this->generateRedirect(
URL::getInstance()->absoluteUrl($successUrl)
);
return $response;
}
}
protected function changeViewForAjax()
{
// If Ajax Request
if ($this->getRequest()->isXmlHttpRequest()) {
$request = $this->getRequest();
$view = $request->get('ajax-view', "includes/mini-cart");
$request->attributes->set('_view', $view);
}
}
public function changeCountry()
@@ -129,17 +160,18 @@ class CartController extends BaseFrontController
$cookie = new Cookie($cookieName, $deliveryId, time() + $cookieExpires, '/');
$this->redirect($redirectUrl, 302, array($cookie));
$response = $this->generateRedirect($redirectUrl);
$response->headers->setCookie($cookie);
return $response;
}
/**
* use Thelia\Cart\CartTrait for searching current cart or create a new one
*
* @return \Thelia\Core\Event\Cart\CartEvent
*/
protected function getCartEvent()
{
$cart = $this->getCart($this->getDispatcher(), $this->getRequest());
$cart = $this->getSession()->getSessionCart($this->getDispatcher());
return new CartEvent($cart);
}
@@ -153,15 +185,16 @@ class CartController extends BaseFrontController
private function getAddCartForm(Request $request)
{
if ($request->isMethod("post")) {
$cartAdd = new CartAdd($request);
$cartAdd = $this->createForm(FrontForm::CART_ADD);
} else {
$cartAdd = new CartAdd(
$request,
$cartAdd = $this->createForm(
FrontForm::CART_ADD,
"form",
array(),
array(
'csrf_protection' => false,
)
),
$this->container
);
}
@@ -177,18 +210,21 @@ class CartController extends BaseFrontController
$deliveryAddress = AddressQuery::create()->findPk($order->getChoosenDeliveryAddress());
if (null !== $deliveryModule && null !== $deliveryAddress) {
$moduleInstance = $deliveryModule->getModuleInstance($this->container);
$moduleInstance = $deliveryModule->getDeliveryModuleInstance($this->container);
$orderEvent = new OrderEvent($order);
try {
$postage = $moduleInstance->getPostage($deliveryAddress->getCountry());
$postage = OrderPostage::loadFromPostage(
$moduleInstance->getPostage($deliveryAddress->getCountry())
);
$orderEvent->setPostage($postage);
$orderEvent->setPostage($postage->getAmount());
$orderEvent->setPostageTax($postage->getAmountTax());
$orderEvent->setPostageTaxRuleTitle($postage->getTaxRuleTitle());
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_POSTAGE, $orderEvent);
}
catch (DeliveryException $ex) {
} catch (DeliveryException $ex) {
// The postage has been chosen, but changes in the cart causes an exception.
// Reset the postage data in the order
$orderEvent->setDeliveryModule(0);

View File

@@ -22,15 +22,17 @@
/*************************************************************************************/
namespace Front\Controller;
use Thelia\Controller\Front\BaseFrontController;
use Thelia\Form\ContactForm;
use Thelia\Form\Definition\FrontForm;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Log\Tlog;
use Thelia\Model\ConfigQuery;
/**
* Class ContactController
* @package Thelia\Controller\Front
* @author Manuel Raynaud <mraynaud@openstudio.fr>
* @author Manuel Raynaud <manu@raynaud.io>
*/
class ContactController extends BaseFrontController
{
@@ -39,36 +41,44 @@ class ContactController extends BaseFrontController
*/
public function sendAction()
{
$error_message = false;
$contactForm = new ContactForm($this->getRequest());
$contactForm = $this->createForm(FrontForm::CONTACT);
try {
$form = $this->validateForm($contactForm);
$message = \Swift_Message::newInstance($form->get('subject')->getData())
->addFrom(ConfigQuery::read("store_email"), $form->get('name')->getData())
->addReplyTo($form->get('email')->getData(), $form->get('name')->getData())
->addTo(ConfigQuery::read('store_email'), ConfigQuery::read('store_name'))
->setBody($form->get('message')->getData())
;
$this->getMailer()->send($message);
$this->getMailer()->sendSimpleEmailMessage(
[ ConfigQuery::getStoreEmail() => $form->get('name')->getData() ],
[ ConfigQuery::getStoreEmail() => ConfigQuery::getStoreName() ],
$form->get('subject')->getData(),
'',
$form->get('message')->getData(),
[],
[],
[ $form->get('email')->getData() => $form->get('name')->getData() ]
);
if ($contactForm->hasSuccessUrl()) {
return $this->generateSuccessRedirect($contactForm);
}
return $this->generateRedirectFromRoute('contact.success');
} catch (FormValidationException $e) {
$error_message = $e->getMessage();
}
if ($error_message !== false) {
\Thelia\Log\Tlog::getInstance()->error(sprintf('Error during sending contact mail : %s', $error_message));
$contactForm->setErrorMessage($error_message);
$this->getParserContext()
->addForm($contactForm)
->setGeneralError($error_message)
;
} else {
$this->redirectToRoute('contact.success');
Tlog::getInstance()->error(sprintf('Error during sending contact mail : %s', $error_message));
$contactForm->setErrorMessage($error_message);
$this->getParserContext()
->addForm($contactForm)
->setGeneralError($error_message)
;
// Redirect to error URL if defined
if ($contactForm->hasErrorUrl()) {
return $this->generateErrorRedirect($contactForm);
}
}
}

View File

@@ -22,15 +22,18 @@
/*************************************************************************************/
namespace Front\Controller;
use Front\Front;
use Propel\Runtime\Exception\PropelException;
use Thelia\Controller\Front\BaseFrontController;
use Thelia\Core\Event\Coupon\CouponConsumeEvent;
use Thelia\Core\Event\Order\OrderEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\CouponCode;
use Thelia\Exception\UnmatchableConditionException;
use Thelia\Form\Definition\FrontForm;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Log\Tlog;
use Thelia\Model\AddressQuery;
use Thelia\Model\OrderPostage;
use Thelia\Module\Exception\DeliveryException;
/**
@@ -43,7 +46,8 @@ class CouponController extends BaseFrontController
/**
* Clear all coupons.
*/
public function clearAllCouponsAction() {
public function clearAllCouponsAction()
{
// Dispatch Event to the Action
$this->getDispatcher()->dispatch(TheliaEvents::COUPON_CLEAR_ALL);
}
@@ -53,11 +57,10 @@ class CouponController extends BaseFrontController
*/
public function consumeAction()
{
$this->checkAuth();
$this->checkCartNotEmpty();
$message = false;
$couponCodeForm = new CouponCode($this->getRequest());
$couponCodeForm = $this->createForm(FrontForm::COUPON_CONSUME);
try {
$form = $this->validateForm($couponCodeForm, 'post');
@@ -66,7 +69,13 @@ class CouponController extends BaseFrontController
if (null === $couponCode || empty($couponCode)) {
$message = true;
throw new \Exception('Coupon code can\'t be empty');
throw new \Exception(
$this->getTranslator()->trans(
'Coupon code can\'t be empty',
[],
Front::MESSAGE_DOMAIN
)
);
}
$couponConsumeEvent = new CouponConsumeEvent($couponCode);
@@ -82,19 +91,21 @@ class CouponController extends BaseFrontController
$deliveryAddress = AddressQuery::create()->findPk($order->getChoosenDeliveryAddress());
if (null !== $deliveryModule && null !== $deliveryAddress) {
$moduleInstance = $deliveryModule->getModuleInstance($this->container);
$moduleInstance = $deliveryModule->getDeliveryModuleInstance($this->container);
$orderEvent = new OrderEvent($order);
try {
$postage = $moduleInstance->getPostage($deliveryAddress->getCountry());
$postage = OrderPostage::loadFromPostage(
$moduleInstance->getPostage($deliveryAddress->getCountry())
);
$orderEvent->setPostage($postage);
$orderEvent->setPostage($postage->getAmount());
$orderEvent->setPostageTax($postage->getAmountTax());
$orderEvent->setPostageTaxRuleTitle($postage->getTaxRuleTitle());
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_POSTAGE, $orderEvent);
}
catch (DeliveryException $ex) {
} catch (DeliveryException $ex) {
// The postage has been chosen, but changes dues to coupon causes an exception.
// Reset the postage data in the order
$orderEvent->setDeliveryModule(0);
@@ -104,18 +115,37 @@ class CouponController extends BaseFrontController
}
}
$this->redirect($couponCodeForm->getSuccessUrl());
return $this->generateSuccessRedirect($couponCodeForm);
} catch (FormValidationException $e) {
$message = sprintf('Please check your coupon code: %s', $e->getMessage());
$message = $this->getTranslator()->trans(
'Please check your coupon code: %message',
["%message" => $e->getMessage()],
Front::MESSAGE_DOMAIN
);
} catch (UnmatchableConditionException $e) {
$message = $this->getTranslator()->trans(
'You should <a href="%sign">sign in</a> or <a href="%register">register</a> to use this coupon',
[
'%sign' => $this->retrieveUrlFromRouteId('customer.login.view'),
'%register' => $this->retrieveUrlFromRouteId('customer.create.view'),
],
Front::MESSAGE_DOMAIN
);
} catch (PropelException $e) {
$this->getParserContext()->setGeneralError($e->getMessage());
} catch (\Exception $e) {
$message = sprintf('Sorry, an error occurred: %s', $e->getMessage());
$message = $this->getTranslator()->trans(
'Sorry, an error occurred: %message',
["%message" => $e->getMessage()],
Front::MESSAGE_DOMAIN
);
}
if ($message !== false) {
Tlog::getInstance()->error(sprintf("Error during order delivery process : %s. Exception was %s", $message, $e->getMessage()));
Tlog::getInstance()->error(
sprintf("Error during order delivery process : %s. Exception was %s", $message, $e->getMessage())
);
$couponCodeForm->setErrorMessage($message);
@@ -123,5 +153,7 @@ class CouponController extends BaseFrontController
->addForm($couponCodeForm)
->setGeneralError($message);
}
return $this->generateErrorRedirect($couponCodeForm);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -17,12 +17,10 @@ use Doctrine\Common\Cache\FilesystemCache;
use Thelia\Controller\Front\BaseFrontController;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\HttpFoundation\Response;
use Thelia\Log\Tlog;
use Thelia\Model\BrandQuery;
use Thelia\Model\FolderQuery;
use Thelia\Model\CategoryQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Model\Folder;
use Thelia\Model\Lang;
use Thelia\Model\LangQuery;

View File

@@ -23,26 +23,89 @@
namespace Front\Controller;
use Front\Front;
use Symfony\Component\HttpFoundation\JsonResponse;
use Thelia\Controller\Front\BaseFrontController;
use Thelia\Core\Event\Newsletter\NewsletterEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\NewsletterForm;
use Thelia\Form\Definition\FrontForm;
use Thelia\Log\Tlog;
use Thelia\Model\Customer;
use Thelia\Model\NewsletterQuery;
/**
* Class NewsletterController
* @package Thelia\Controller\Front
* @author Manuel Raynaud <mraynaud@openstudio.fr>
* @author Manuel Raynaud <manu@raynaud.io>, Franck Allimant <franck@cqfdev.fr>
*/
class NewsletterController extends BaseFrontController
{
/**
* @since 2.3.0-alpha2
*/
public function unsubscribeAction()
{
$errorMessage = false;
$newsletterForm = $this->createForm(FrontForm::NEWSLETTER_UNSUBSCRIBE);
try {
$form = $this->validateForm($newsletterForm);
$email = $form->get('email')->getData();
if (null !== $newsletter = NewsletterQuery::create()->findOneByEmail($email)) {
$event = new NewsletterEvent(
$email,
$this->getRequest()->getSession()->getLang()->getLocale()
);
$event->setId($newsletter->getId());
$this->dispatch(TheliaEvents::NEWSLETTER_UNSUBSCRIBE, $event);
// If a success URL is defined in the form, redirect to it, otherwise use the defaut view
if ($newsletterForm->hasSuccessUrl() && !$this->getRequest()->isXmlHttpRequest()) {
return $this->generateSuccessRedirect($newsletterForm);
}
}
} catch (\Exception $e) {
$errorMessage = $e->getMessage();
Tlog::getInstance()->error(sprintf('Error during newsletter unsubscription : %s', $errorMessage));
$newsletterForm->setErrorMessage($errorMessage);
}
// If Ajax Request
if ($this->getRequest()->isXmlHttpRequest()) {
return new JsonResponse([
"success" => ($errorMessage) ? false : true,
"message" => ($errorMessage) ? $errorMessage : $this->getTranslator()->trans(
"Your subscription to our newsletter has been canceled.",
[],
Front::MESSAGE_DOMAIN
)
], ($errorMessage) ? 500 : 200);
}
$this->getParserContext()
->setGeneralError($errorMessage)
->addForm($newsletterForm);
// If an error URL is defined in the form, redirect to it, otherwise use the defaut view
if ($errorMessage && $newsletterForm->hasErrorUrl()) {
return $this->generateErrorRedirect($newsletterForm);
}
}
public function subscribeAction()
{
$error_message = false;
$newsletterForm = new NewsletterForm($this->getRequest());
$errorMessage = false;
$newsletterForm = $this->createForm(FrontForm::NEWSLETTER);
try {
$form = $this->validateForm($newsletterForm);
$event = new NewsletterEvent(
@@ -50,43 +113,52 @@ class NewsletterController extends BaseFrontController
$this->getRequest()->getSession()->getLang()->getLocale()
);
/** @var Customer $customer */
if (null !== $customer = $this->getSecurityContext()->getCustomerUser()) {
$event->setFirstname($customer->getFirstname());
$event->setLastname($customer->getLastname());
$event
->setFirstname($customer->getFirstname())
->setLastname($customer->getLastname())
;
} else {
$event
->setFirstname($form->get('firstname')->getData())
->setLastname($form->get('lastname')->getData())
;
}
$this->dispatch(TheliaEvents::NEWSLETTER_SUBSCRIBE, $event);
// If a success URL is defined in the form, redirect to it, otherwise use the defaut view
if ($newsletterForm->hasSuccessUrl() && ! $this->getRequest()->isXmlHttpRequest()) {
return $this->generateSuccessRedirect($newsletterForm);
}
} catch (\Exception $e) {
$error_message = $e->getMessage();
}
$errorMessage = $e->getMessage();
\Thelia\Log\Tlog::getInstance()->error(sprintf('Error during newsletter subscription : %s', $error_message));
Tlog::getInstance()->error(sprintf('Error during newsletter subscription : %s', $errorMessage));
$newsletterForm->setErrorMessage($errorMessage);
}
// If Ajax Request
if ($this->getRequest()->isXmlHttpRequest()) {
if ($error_message) {
$response = $this->jsonResponse(json_encode(array(
"success" => false,
"message" => $error_message
)));
} else {
$response = $this->jsonResponse(json_encode(array(
"success" => true,
"message" => "Thanks for signing up! We'll keep you posted whenever we have any new updates."
)));;
}
return $response;
} else {
$newsletterForm->setErrorMessage($error_message);
$this->getParserContext()
->addForm($newsletterForm)
->setGeneralError($error_message)
;
return new JsonResponse([
"success" => ($errorMessage) ? false : true,
"message" => ($errorMessage) ? $errorMessage : $this->getTranslator()->trans(
"Thanks for signing up! We'll keep you posted whenever we have any new updates.",
[],
Front::MESSAGE_DOMAIN
)
], ($errorMessage) ? 500 : 200);
}
$this->getParserContext()
->setGeneralError($errorMessage)
->addForm($newsletterForm);
// If an error URL is defined in the form, redirect to it, otherwise use the defaut view
if ($errorMessage && $newsletterForm->hasErrorUrl()) {
return $this->generateErrorRedirect($newsletterForm);
}
}
}

View File

@@ -23,27 +23,30 @@
namespace Front\Controller;
use Front\Front;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\Exception\PropelException;
use Symfony\Component\HttpFoundation\Response as BaseResponse;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Thelia\Cart\CartTrait;
use Thelia\Controller\Front\BaseFrontController;
use Thelia\Core\Translation\Translator;
use Thelia\Exception\TheliaProcessException;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Core\Event\Delivery\DeliveryPostageEvent;
use Thelia\Core\Event\Order\OrderEvent;
use Thelia\Core\Event\Product\VirtualProductOrderDownloadResponseEvent;
use Thelia\Core\Event\TheliaEvents;
use Symfony\Component\HttpFoundation\Request;
use Thelia\Form\OrderDelivery;
use Thelia\Form\OrderPayment;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Exception\TheliaProcessException;
use Thelia\Form\Definition\FrontForm;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Log\Tlog;
use Thelia\Model\Address;
use Thelia\Model\AddressQuery;
use Thelia\Model\AreaDeliveryModuleQuery;
use Thelia\Model\OrderQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Model\ModuleQuery;
use Thelia\Model\Order;
use Thelia\TaxEngine\TaxEngine;
use Thelia\Tools\URL;
use Thelia\Model\OrderProductQuery;
use Thelia\Model\OrderQuery;
use Thelia\Module\AbstractDeliveryModule;
use Thelia\Module\Exception\DeliveryException;
/**
* Class OrderController
@@ -52,7 +55,78 @@ use Thelia\Tools\URL;
*/
class OrderController extends BaseFrontController
{
use CartTrait;
/**
* Check if the cart contains only virtual products.
*/
public function deliverView()
{
$this->checkAuth();
$this->checkCartNotEmpty();
// check if the cart contains only virtual products
$cart = $this->getSession()->getSessionCart($this->getDispatcher());
$deliveryAddress = $this->getCustomerAddress();
if ($cart->isVirtual()) {
if (null !== $deliveryAddress) {
$deliveryModule = ModuleQuery::create()->retrieveVirtualProductDelivery($this->container);
if (false === $deliveryModule) {
Tlog::getInstance()->error(
$this->getTranslator()->trans(
"To enable the virtual product feature, the VirtualProductDelivery module should be activated",
[],
Front::MESSAGE_DOMAIN
)
);
} elseif (count($deliveryModule) == 1) {
return $this->registerVirtualProductDelivery($deliveryModule[0], $deliveryAddress);
}
}
}
return $this->render(
'order-delivery',
[
'delivery_address_id' => (null !== $deliveryAddress) ? $deliveryAddress->getId() : null
]
);
}
/**
* @param AbstractDeliveryModule $moduleInstance
* @param Address $deliveryAddress
* @return \Symfony\Component\HttpFoundation\Response
*/
private function registerVirtualProductDelivery($moduleInstance, $deliveryAddress)
{
/* get postage amount */
$deliveryModule = $moduleInstance->getModuleModel();
$cart = $this->getSession()->getSessionCart($this->getDispatcher());
$deliveryPostageEvent = new DeliveryPostageEvent($moduleInstance, $cart, $deliveryAddress);
$this->getDispatcher()->dispatch(
TheliaEvents::MODULE_DELIVERY_GET_POSTAGE,
$deliveryPostageEvent
);
$postage = $deliveryPostageEvent->getPostage();
$orderEvent = $this->getOrderEvent();
$orderEvent->setDeliveryAddress($deliveryAddress->getId());
$orderEvent->setDeliveryModule($deliveryModule->getId());
$orderEvent->setPostage($postage->getAmount());
$orderEvent->setPostageTax($postage->getAmountTax());
$orderEvent->setPostageTaxRuleTitle($postage->getTaxRuleTitle());
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_ADDRESS, $orderEvent);
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_MODULE, $orderEvent);
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_POSTAGE, $orderEvent);
return $this->generateRedirectFromRoute("order.invoice");
}
/**
* set delivery address
* set delivery module
@@ -64,7 +138,7 @@ class OrderController extends BaseFrontController
$message = false;
$orderDelivery = new OrderDelivery($this->getRequest());
$orderDelivery = $this->createForm(FrontForm::ORDER_DELIVER);
try {
$form = $this->validateForm($orderDelivery, "post");
@@ -76,43 +150,81 @@ class OrderController extends BaseFrontController
/* check that the delivery address belongs to the current customer */
if ($deliveryAddress->getCustomerId() !== $this->getSecurityContext()->getCustomerUser()->getId()) {
throw new \Exception("Delivery address does not belong to the current customer");
throw new \Exception(
$this->getTranslator()->trans(
"Delivery address does not belong to the current customer",
[],
Front::MESSAGE_DOMAIN
)
);
}
/* check that the delivery module fetches the delivery address area */
if(AreaDeliveryModuleQuery::create()
->filterByAreaId($deliveryAddress->getCountry()->getAreaId())
->filterByDeliveryModuleId($deliveryModuleId)
->count() == 0) {
throw new \Exception("Delivery module cannot be use with selected delivery address");
if (null === AreaDeliveryModuleQuery::create()->findByCountryAndModule(
$deliveryAddress->getCountry(),
$deliveryModule
)) {
throw new \Exception(
$this->getTranslator()->trans(
"Delivery module cannot be use with selected delivery address",
[],
Front::MESSAGE_DOMAIN
)
);
}
/* get postage amount */
$moduleInstance = $deliveryModule->getModuleInstance($this->container);
$moduleInstance = $deliveryModule->getDeliveryModuleInstance($this->container);
$postage = $moduleInstance->getPostage($deliveryAddress->getCountry());
$cart = $this->getSession()->getSessionCart($this->getDispatcher());
$deliveryPostageEvent = new DeliveryPostageEvent($moduleInstance, $cart, $deliveryAddress);
$this->getDispatcher()->dispatch(
TheliaEvents::MODULE_DELIVERY_GET_POSTAGE,
$deliveryPostageEvent
);
if (!$deliveryPostageEvent->isValidModule() || null === $deliveryPostageEvent->getPostage()) {
throw new DeliveryException(
$this->getTranslator()->trans('The delivery module is not valid.', [], Front::MESSAGE_DOMAIN)
);
}
$postage = $deliveryPostageEvent->getPostage();
$orderEvent = $this->getOrderEvent();
$orderEvent->setDeliveryAddress($deliveryAddressId);
$orderEvent->setDeliveryModule($deliveryModuleId);
$orderEvent->setPostage($postage);
$orderEvent->setPostage($postage->getAmount());
$orderEvent->setPostageTax($postage->getAmountTax());
$orderEvent->setPostageTaxRuleTitle($postage->getTaxRuleTitle());
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_ADDRESS, $orderEvent);
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_MODULE, $orderEvent);
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_POSTAGE, $orderEvent);
$this->redirectToRoute("order.invoice");
return $this->generateRedirectFromRoute("order.invoice");
} catch (FormValidationException $e) {
$message = Translator::getInstance()->trans("Please check your input: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
$message = $this->getTranslator()->trans(
"Please check your input: %s",
['%s' => $e->getMessage()],
Front::MESSAGE_DOMAIN
);
} catch (PropelException $e) {
$this->getParserContext()->setGeneralError($e->getMessage());
} catch (\Exception $e) {
$message = Translator::getInstance()->trans("Sorry, an error occured: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
$message = $this->getTranslator()->trans(
"Sorry, an error occured: %s",
['%s' => $e->getMessage()],
Front::MESSAGE_DOMAIN
);
}
if ($message !== false) {
Tlog::getInstance()->error(sprintf("Error during order delivery process : %s. Exception was %s", $message, $e->getMessage()));
Tlog::getInstance()->error(
sprintf("Error during order delivery process : %s. Exception was %s", $message, $e->getMessage())
);
$orderDelivery->setErrorMessage($message);
@@ -121,7 +233,6 @@ class OrderController extends BaseFrontController
->setGeneralError($message)
;
}
}
/**
@@ -136,7 +247,7 @@ class OrderController extends BaseFrontController
$message = false;
$orderPayment = new OrderPayment($this->getRequest());
$orderPayment = $this->createForm(FrontForm::ORDER_PAYMENT);
try {
$form = $this->validateForm($orderPayment, "post");
@@ -147,7 +258,13 @@ class OrderController extends BaseFrontController
/* 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");
throw new \Exception(
$this->getTranslator()->trans(
"Invoice address does not belong to the current customer",
[],
Front::MESSAGE_DOMAIN
)
);
}
$orderEvent = $this->getOrderEvent();
@@ -157,18 +274,28 @@ class OrderController extends BaseFrontController
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_INVOICE_ADDRESS, $orderEvent);
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_PAYMENT_MODULE, $orderEvent);
$this->redirectToRoute("order.payment.process");
return $this->generateRedirectFromRoute("order.payment.process");
} catch (FormValidationException $e) {
$message = Translator::getInstance()->trans("Please check your input: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
$message = $this->getTranslator()->trans(
"Please check your input: %s",
['%s' => $e->getMessage()],
Front::MESSAGE_DOMAIN
);
} catch (PropelException $e) {
$this->getParserContext()->setGeneralError($e->getMessage());
} catch (\Exception $e) {
$message = Translator::getInstance()->trans("Sorry, an error occured: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
$message = $this->getTranslator()->trans(
"Sorry, an error occured: %s",
['%s' => $e->getMessage()],
Front::MESSAGE_DOMAIN
);
}
if ($message !== false) {
Tlog::getInstance()->error(sprintf("Error during order payment process : %s. Exception was %s", $message, $e->getMessage()));
Tlog::getInstance()->error(
sprintf("Error during order payment process : %s. Exception was %s", $message, $e->getMessage())
);
$orderPayment->setErrorMessage($message);
@@ -178,6 +305,7 @@ class OrderController extends BaseFrontController
;
}
return $this->generateErrorRedirect($orderPayment);
}
public function pay()
@@ -188,6 +316,13 @@ class OrderController extends BaseFrontController
/* check cart count */
$this->checkCartNotEmpty();
/* check stock not empty */
if (true === ConfigQuery::checkAvailableStock()) {
if (null !== $response = $this->checkStockNotEmpty()) {
return $response;
}
}
/* check delivery address and module */
$this->checkValidDelivery();
@@ -205,11 +340,15 @@ class OrderController extends BaseFrontController
if ($orderEvent->hasResponse()) {
return $orderEvent->getResponse();
} else {
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute('order.placed', array('order_id' => $orderEvent->getPlacedOrder()->getId()))));
return $this->generateRedirectFromRoute(
'order.placed',
[],
['order_id' => $orderEvent->getPlacedOrder()->getId()]
);
}
} else {
/* order has not been placed */
$this->redirectToRoute('cart.view');
return $this->generateRedirectFromRoute('cart.view');
}
}
@@ -221,41 +360,66 @@ class OrderController extends BaseFrontController
);
if (null === $placedOrder) {
throw new TheliaProcessException("No placed order", TheliaProcessException::NO_PLACED_ORDER, $placedOrder);
throw new TheliaProcessException(
$this->getTranslator()->trans(
"No placed order",
[],
Front::MESSAGE_DOMAIN
),
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);
throw new TheliaProcessException(
$this->getTranslator()->trans(
"Received placed order id does not belong to the current customer",
[],
Front::MESSAGE_DOMAIN
),
TheliaProcessException::PLACED_ORDER_ID_BAD_CURRENT_CUSTOMER,
$placedOrder
);
}
$session = $this->getRequest()->getSession();
$this->createCart($this->getRequest()->getSession());
$session->setOrder(new Order());
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_CART_CLEAR, $this->getOrderEvent());
$this->getParserContext()->set("placed_order_id", $placedOrder->getId());
}
public function orderFailed($order_id, $message)
{
/* check if the placed order matched the customer */
$failedOrder = OrderQuery::create()->findPk(
$this->getRequest()->attributes->get('order_id')
);
if (null === $failedOrder) {
throw new TheliaProcessException("No failed order", TheliaProcessException::NO_PLACED_ORDER, $failedOrder);
if (empty($order_id)) {
// Fallback to request parameter if the method parameter is empty.
$order_id = $this->getRequest()->get('order_id');
}
$customer = $this->getSecurityContext()->getCustomerUser();
$failedOrder = OrderQuery::create()->findPk($order_id);
if (null === $customer || $failedOrder->getCustomerId() !== $customer->getId()) {
throw new TheliaProcessException("Received failed order id does not belong to the current customer", TheliaProcessException::PLACED_ORDER_ID_BAD_CURRENT_CUSTOMER, $placedOrder);
if (null !== $failedOrder) {
$customer = $this->getSecurityContext()->getCustomerUser();
if (null === $customer || $failedOrder->getCustomerId() !== $customer->getId()) {
throw new TheliaProcessException(
$this->getTranslator()->trans(
"Received failed order id does not belong to the current customer",
[],
Front::MESSAGE_DOMAIN
),
TheliaProcessException::PLACED_ORDER_ID_BAD_CURRENT_CUSTOMER,
$failedOrder
);
}
} else {
Tlog::getInstance()->warning("Failed order ID '$order_id' not found.");
}
$this->getParserContext()
->set("failed_order_id", $failedOrder->getId())
->set("failed_order_id", $order_id)
->set("failed_order_message", $message)
;
}
@@ -282,6 +446,14 @@ class OrderController extends BaseFrontController
return $order;
}
public function viewAction($order_id)
{
$this->checkOrderCustomer($order_id);
return $this->render('account-order', ['order_id' => $order_id]);
}
public function generateInvoicePdf($order_id)
{
$this->checkOrderCustomer($order_id);
@@ -297,6 +469,35 @@ class OrderController extends BaseFrontController
return $this->generateOrderPdf($order_id, ConfigQuery::read('pdf_delivery_file', 'delivery'));
}
public function downloadVirtualProduct($order_product_id)
{
if (null !== $orderProduct = OrderProductQuery::create()->findPk($order_product_id)) {
$order = $orderProduct->getOrder();
if ($order->isPaid(false)) {
// check customer
$this->checkOrderCustomer($order->getId());
$virtualProductEvent = new VirtualProductOrderDownloadResponseEvent($orderProduct);
$this->getDispatcher()->dispatch(
TheliaEvents::VIRTUAL_PRODUCT_ORDER_DOWNLOAD_RESPONSE,
$virtualProductEvent
);
$response = $virtualProductEvent->getResponse();
if (!$response instanceof BaseResponse) {
throw new \RuntimeException('A Response must be added in the event TheliaEvents::VIRTUAL_PRODUCT_ORDER_DOWNLOAD_RESPONSE');
}
return $response;
}
}
throw new AccessDeniedHttpException();
}
private function checkOrderCustomer($order_id)
{
$this->checkAuth();
@@ -321,15 +522,83 @@ class OrderController extends BaseFrontController
public function getDeliveryModuleListAjaxAction()
{
$country = $this->getRequest()->get(
'country_id',
$this->container->get('thelia.taxEngine')->getDeliveryCountry()->getId()
);
$this->checkXmlHttpRequest();
$args = array('country' => $country);
// Change the delivery address if customer has changed it
$address = null;
$session = $this->getSession();
$addressId = $this->getRequest()->get('address_id', null);
if (null !== $addressId && $addressId !== $session->getOrder()->getChoosenDeliveryAddress()) {
$address = AddressQuery::create()->findPk($addressId);
if (null !== $address && $address->getCustomerId() === $session->getCustomerUser()->getId()) {
$session->getOrder()->setChoosenDeliveryAddress($addressId);
}
}
$address = AddressQuery::create()->findPk($session->getOrder()->getChoosenDeliveryAddress());
$countryId = $address->getCountryId();
$stateId = $address->getStateId();
$args = array(
'country' => $countryId,
'state' => $stateId,
'address' => $session->getOrder()->getChoosenDeliveryAddress()
);
return $this->render('ajax/order-delivery-module-list', $args);
}
/**
* Redirect to cart view if at least one non product is out of stock
*
* @return null|BaseResponse
*/
private function checkStockNotEmpty()
{
$cart = $this->getSession()->getSessionCart($this->getDispatcher());
$cartItems = $cart->getCartItems();
foreach ($cartItems as $cartItem) {
$pse = $cartItem->getProductSaleElements();
$product = $cartItem->getProduct();
if ($pse->getQuantity() <= 0 && $product->getVirtual() !== 1) {
return $this->generateRedirectFromRoute('cart.view');
}
}
return null;
}
/**
* Retrieve the chosen delivery address for a cart or the default customer address if not exists
*
* @return null|Address
*/
protected function getCustomerAddress()
{
$deliveryAddress = null;
$addressId = $this->getSession()->getOrder()->getChoosenDeliveryAddress();
if (null === $addressId) {
$customer = $this->getSecurityContext()->getCustomerUser();
$deliveryAddress = AddressQuery::create()
->filterByCustomerId($customer->getId())
->orderByIsDefault(Criteria::DESC)
->findOne();
if (null !== $deliveryAddress) {
$this->getSession()->getOrder()->setChoosenDeliveryAddress(
$deliveryAddress->getId()
);
}
} else {
$deliveryAddress = AddressQuery::create()->findPk($addressId);
}
return $deliveryAddress;
}
}

View File

@@ -17,7 +17,6 @@ use Doctrine\Common\Cache\FilesystemCache;
use Thelia\Controller\Front\BaseFrontController;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\HttpFoundation\Response;
use Thelia\Log\Tlog;
use Thelia\Model\ConfigQuery;
use Thelia\Model\LangQuery;
@@ -55,7 +54,6 @@ class SitemapController extends BaseFrontController {
*/
public function generateAction()
{
/** @var Request $request */
$request = $this->getRequest();