Revert "Revert "Merge branch 'cleanmaster' into modules""

This reverts commit b3ac365b45.

Conflicts:
	Readme.md
	core/lib/Thelia/Controller/Admin/AbstractCrudController.php
	core/lib/Thelia/Core/Template/Assets/AssetManagerInterface.php
	core/lib/Thelia/Core/Template/Assets/AsseticAssetManager.php
	core/lib/Thelia/Core/Template/Smarty/SmartyParser.php
	core/lib/Thelia/Core/Template/TemplateDefinition.php
	core/lib/Thelia/Model/Base/Coupon.php
	core/lib/Thelia/Model/Base/CouponQuery.php
	core/lib/Thelia/Model/Base/CouponVersion.php
	core/lib/Thelia/Model/Base/CouponVersionQuery.php
	core/lib/Thelia/Model/Base/OrderCouponQuery.php
This commit is contained in:
Etienne Roudeix
2014-01-06 11:25:25 +01:00
parent d4582f467f
commit 99038e688a
327 changed files with 3728 additions and 3732 deletions

View File

@@ -30,7 +30,6 @@ use Thelia\Core\Event\UpdateSeoEvent;
use Thelia\Exception\UrlRewritingException;
use Thelia\Form\Exception\FormValidationException;
use \Thelia\Model\Tools\UrlRewritingTrait;
class BaseAction
{
@@ -82,8 +81,8 @@ class BaseAction
/**
* Changes SEO Fields for an object.
*
* @param ModelCriteria $query
* @param UpdateSeoEvent $event
* @param ModelCriteria $query
* @param UpdateSeoEvent $event
*
* @return mixed
*/
@@ -105,7 +104,7 @@ class BaseAction
// Update the rewritten URL, if required
try {
$object->setRewrittenUrl($event->getLocale(), $event->getUrl());
} catch(UrlRewritingException $e) {
} catch (UrlRewritingException $e) {
throw new FormValidationException($e->getMessage(), $e->getCode());
}

View File

@@ -28,6 +28,7 @@ use Thelia\Condition\ConditionFactory;
use Thelia\Condition\Implementation\ConditionInterface;
use Thelia\Core\Event\Coupon\CouponConsumeEvent;
use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent;
use Thelia\Core\Event\Order\OrderEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Coupon\CouponFactory;
@@ -36,6 +37,7 @@ use Thelia\Condition\ConditionCollection;
use Thelia\Coupon\Type\CouponInterface;
use Thelia\Model\Coupon as CouponModel;
use Thelia\Model\CouponQuery;
use Thelia\Model\OrderCoupon;
/**
* Process Coupon Events
@@ -118,23 +120,20 @@ class Coupon extends BaseAction implements EventSubscriberInterface
$request->getSession()->setConsumedCoupons($consumedCoupons);
$totalDiscount = $couponManager->getDiscount();
// @todo insert false product in cart with the name of the coupon and the discount as negative price
// Decrement coupon quantity
// @todo move this part in after order event
$couponQuery = CouponQuery::create();
$couponModel = $couponQuery->findOneByCode($coupon->getCode());
$couponManager->decrementQuantity($couponModel);
$request
->getSession()
->getCart()
->setDiscount($totalDiscount)
->save();
$request
->getSession()
->getOrder()
->setDiscount($totalDiscount)
->save();
}
}
$event->setIsValid($isValid);
$event->setDiscount($totalDiscount);
}
@@ -203,6 +202,68 @@ class Coupon extends BaseAction implements EventSubscriberInterface
$event->setCouponModel($coupon);
}
/**
* @param \Thelia\Core\Event\Order\OrderEvent $event
*/
public function testFreePostage(OrderEvent $event)
{
/** @var CouponManager $couponManager */
$couponManager = $this->container->get('thelia.coupon.manager');
if($couponManager->isCouponRemovingPostage()) {
$order = $event->getOrder();
$order->setPostage(0);
$event->setOrder($order);
$event->stopPropagation();
}
}
/**
* @param \Thelia\Core\Event\Order\OrderEvent $event
*/
public function afterOrder(OrderEvent $event)
{
$request = $this->container->get('request');
/** @var CouponManager $couponManager */
$couponManager = $this->container->get('thelia.coupon.manager');
$consumedCoupons = $request->getSession()->getConsumedCoupons();
if (is_array($consumedCoupons)) {
foreach($consumedCoupons as $couponCode) {
$couponQuery = CouponQuery::create();
$couponModel = $couponQuery->findOneByCode($couponCode);
$couponModel->setLocale($request->getSession()->getLang()->getLocale());
/* decrease coupon quantity */
$couponManager->decrementQuantity($couponModel);
/* memorize coupon */
$orderCoupon = new OrderCoupon();
$orderCoupon->setOrder($event->getOrder())
->setCode($couponModel->getCode())
->setType($couponModel->getType())
->setAmount($couponModel->getAmount())
->setTitle($couponModel->getTitle())
->setShortDescription($couponModel->getShortDescription())
->setDescription($couponModel->getDescription())
->setExpirationDate($couponModel->getExpirationDate())
->setIsCumulative($couponModel->getIsCumulative())
->setIsRemovingPostage($couponModel->getIsRemovingPostage())
->setIsAvailableOnSpecialOffers($couponModel->getIsAvailableOnSpecialOffers())
->setSerializedConditions($couponModel->getSerializedConditions())
;
$orderCoupon->save();
}
}
}
/**
* Returns an array of event names this subscriber listens to.
*
@@ -229,7 +290,9 @@ class Coupon extends BaseAction implements EventSubscriberInterface
TheliaEvents::COUPON_CREATE => array("create", 128),
TheliaEvents::COUPON_UPDATE => array("update", 128),
TheliaEvents::COUPON_CONSUME => array("consume", 128),
TheliaEvents::COUPON_CONDITION_UPDATE => array("updateCondition", 128)
TheliaEvents::COUPON_CONDITION_UPDATE => array("updateCondition", 128),
TheliaEvents::ORDER_SET_POSTAGE => array("testFreePostage", 256),
TheliaEvents::ORDER_BEFORE_PAYMENT => array("afterOrder", 128),
);
}
}

View File

@@ -35,7 +35,7 @@ class MailingSystem extends BaseAction implements EventSubscriberInterface
*/
public function update(MailingSystemEvent $event)
{
if($event->getEnabled()) {
if ($event->getEnabled()) {
ConfigQuery::enableSmtp();
} else {
ConfigQuery::disableSmtp();

View File

@@ -30,6 +30,7 @@ use Thelia\Core\Event\Cart\CartEvent;
use Thelia\Core\Event\Order\OrderAddressEvent;
use Thelia\Core\Event\Order\OrderEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Coupon\CouponManager;
use Thelia\Exception\TheliaProcessException;
use Thelia\Model\AddressQuery;
use Thelia\Model\ConfigQuery;
@@ -73,6 +74,17 @@ class Order extends BaseAction implements EventSubscriberInterface
$order = $event->getOrder();
$order->setDeliveryModuleId($event->getDeliveryModule());
$event->setOrder($order);
}
/**
* @param \Thelia\Core\Event\Order\OrderEvent $event
*/
public function setPostage(OrderEvent $event)
{
$order = $event->getOrder();
$order->setPostage($event->getPostage());
$event->setOrder($order);
@@ -178,6 +190,11 @@ class Order extends BaseAction implements EventSubscriberInterface
OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_NOT_PAID)->getId()
);
/* memorize discount */
$placedOrder->setDiscount(
$cart->getDiscount()
);
$placedOrder->save($con);
/* fulfill order_products and decrease stock */
@@ -262,8 +279,6 @@ class Order extends BaseAction implements EventSubscriberInterface
}
}
/* discount @todo */
$con->commit();
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_BEFORE_PAYMENT, new OrderEvent($placedOrder));
@@ -273,7 +288,7 @@ class Order extends BaseAction implements EventSubscriberInterface
$sessionOrder = new \Thelia\Model\Order();
$event->setOrder($sessionOrder);
$event->setPlacedOrder($placedOrder);
$this->getSession()->setOrder($sessionOrder);
$this->getSession()->setOrder($placedOrder);
/* empty cart */
$this->getDispatcher()->dispatch(TheliaEvents::CART_CLEAR, new CartEvent($this->getCart($this->getRequest())));
@@ -290,7 +305,7 @@ class Order extends BaseAction implements EventSubscriberInterface
{
$contact_email = ConfigQuery::read('contact_email');
if($contact_email) {
if ($contact_email) {
$message = MessageQuery::create()
->filterByName('order_confirmation')
@@ -412,6 +427,7 @@ class Order extends BaseAction implements EventSubscriberInterface
return array(
TheliaEvents::ORDER_SET_DELIVERY_ADDRESS => array("setDeliveryAddress", 128),
TheliaEvents::ORDER_SET_DELIVERY_MODULE => array("setDeliveryModule", 128),
TheliaEvents::ORDER_SET_POSTAGE => array("setPostage", 128),
TheliaEvents::ORDER_SET_INVOICE_ADDRESS => array("setInvoiceAddress", 128),
TheliaEvents::ORDER_SET_PAYMENT_MODULE => array("setPaymentModule", 128),
TheliaEvents::ORDER_PAY => array("create", 128),

View File

@@ -131,7 +131,6 @@ class Product extends BaseAction implements EventSubscriberInterface
return $this->genericUpdateSeo(ProductQuery::create(), $event);
}
/**
* Delete a product entry
*

View File

@@ -209,8 +209,7 @@ class ProductSaleElement extends BaseAction implements EventSubscriberInterface
if ($product->countSaleElements() <= 0) {
// If we just deleted the last PSE, create a default one
$product->createProductSaleElement($con, 0, 0, 0, $event->getCurrencyId(), true);
}
elseif ($pse->getIsDefault()) {
} elseif ($pse->getIsDefault()) {
// If we deleted the default PSE, make the last created one the default
$pse = ProductSaleElementsQuery::create()
@@ -238,8 +237,8 @@ class ProductSaleElement extends BaseAction implements EventSubscriberInterface
*
* @param ProductCombinationGenerationEvent $event
*/
public function generateCombinations(ProductCombinationGenerationEvent $event) {
public function generateCombinations(ProductCombinationGenerationEvent $event)
{
$con = Propel::getWriteConnection(ProductSaleElementsTableMap::DATABASE_NAME);
$con->beginTransaction();
@@ -252,7 +251,7 @@ class ProductSaleElement extends BaseAction implements EventSubscriberInterface
$isDefault = true;
// Create all combinations
foreach($event->getCombinations() as $combinationAttributesAvIds) {
foreach ($event->getCombinations() as $combinationAttributesAvIds) {
// Create the PSE
$saleElement = $event->getProduct()->createProductSaleElement(
@@ -276,8 +275,7 @@ class ProductSaleElement extends BaseAction implements EventSubscriberInterface
// Store all the stuff !
$con->commit();
}
catch (\Exception $ex) {
} catch (\Exception $ex) {
$con->rollback();
@@ -288,9 +286,9 @@ class ProductSaleElement extends BaseAction implements EventSubscriberInterface
/**
* Create a combination for a given product sale element
*
* @param ConnectionInterface $con the Propel connection
* @param ProductSaleElement $salesElement the product sale element
* @param unknown $combinationAttributes an array oif attributes av IDs
* @param ConnectionInterface $con the Propel connection
* @param ProductSaleElement $salesElement the product sale element
* @param unknown $combinationAttributes an array oif attributes av IDs
*/
protected function createCombination(ConnectionInterface $con, ProductSaleElements $salesElement, $combinationAttributes)
{