diff --git a/core/lib/Thelia/Action/Cart.php b/core/lib/Thelia/Action/Cart.php
index 8634feabb..e4255aa30 100755
--- a/core/lib/Thelia/Action/Cart.php
+++ b/core/lib/Thelia/Action/Cart.php
@@ -24,9 +24,12 @@
namespace Thelia\Action;
use Symfony\Component\Config\Definition\Exception\Exception;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\ActionEvent;
+use Thelia\Core\Event\CartEvent;
+use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\HttpFoundation\Session\Session;
use Thelia\Form\CartAdd;
use Thelia\Model\CartQuery;
@@ -36,6 +39,13 @@ use Thelia\Model\Customer;
class Cart implements EventSubscriberInterface
{
+ protected $dispatcher;
+
+ public function __construct(EventDispatcherInterface $dispatcher)
+ {
+ $this->dispatcher = $dispatcher;
+ }
+
/**
*
* add an article to cart
@@ -44,6 +54,7 @@ class Cart implements EventSubscriberInterface
*/
public function addArticle(ActionEvent $event)
{
+ var_dump($this);
$request = $event->getRequest();
if ($request->isMethod("post")) {
@@ -66,7 +77,6 @@ class Cart implements EventSubscriberInterface
if($form->isValid()) {
} else {
- var_dump($form->createView());
}
}
@@ -194,7 +204,10 @@ class Cart implements EventSubscriberInterface
$newCart = $cart->duplicate($this->generateCookie(), $customer);
$session->setCart($newCart->getId());
- return $newCart;
+ $cartEvent = new CartEvent($newCart);
+ $this->dispatcher->dispatch(TheliaEvents::CART_DUPLICATE, $newCart);
+
+ return $cartEvent->cart;
}
protected function generateCookie()
diff --git a/core/lib/Thelia/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml
index 0816f9958..aa79127a1 100755
--- a/core/lib/Thelia/Config/Resources/action.xml
+++ b/core/lib/Thelia/Config/Resources/action.xml
@@ -14,6 +14,8 @@
+
+
diff --git a/core/lib/Thelia/Core/Event/CartEvent.php b/core/lib/Thelia/Core/Event/CartEvent.php
index 92092f154..f4d79c78c 100644
--- a/core/lib/Thelia/Core/Event/CartEvent.php
+++ b/core/lib/Thelia/Core/Event/CartEvent.php
@@ -29,30 +29,13 @@ use Thelia\Model\Cart;
class CartEvent extends InternalEvent {
- protected $cart;
- protected $modified;
+ public $cart;
public function __construct(Cart $cart)
{
$this->cart = $cart;
- $this->modified = false;
}
- public function setCart(Cart $cart)
- {
- $this->cart = $cart;
- $this->modified = true;
- }
-
- public function getCart()
- {
- return $this->cart;
- }
-
- public function isModified()
- {
- return $this->modified;
- }
}
\ No newline at end of file
diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php
index c086f4fa9..883ea5aff 100755
--- a/core/lib/Thelia/Core/Event/TheliaEvents.php
+++ b/core/lib/Thelia/Core/Event/TheliaEvents.php
@@ -88,4 +88,9 @@ final class TheliaEvents
* Sent before customer insertion, to allow modules to create a custom customer reference.
*/
const CREATECUSTOMER_CUSTOMREF = "customer.creation.customref";
+
+ /**
+ * sent when a new existing cat id duplicated. This append when current customer is different from current cart
+ */
+ const CART_DUPLICATE = "cart.duplicate";
}
\ No newline at end of file
diff --git a/core/lib/Thelia/Model/Cart.php b/core/lib/Thelia/Model/Cart.php
index 8d74c6f20..2e2a1206c 100644
--- a/core/lib/Thelia/Model/Cart.php
+++ b/core/lib/Thelia/Model/Cart.php
@@ -8,14 +8,6 @@ use Thelia\Model\Base\ProductSaleElementsQuery;
class Cart extends BaseCart
{
-
- protected $dispatcher;
-
- public function setDispatcher(EventDispatcherInterface $dispatcher)
- {
- $this->dispatcher = $dispatcher;
- }
-
public function duplicate($token, Customer $customer = null)
{
$cartItems = $this->getCartItems();
@@ -50,9 +42,4 @@ class Cart extends BaseCart
return $cart;
}
-
- protected function dispatchEvent($name)
- {
-
- }
}