diff --git a/core/lib/Thelia/Cart/CartTrait.php b/core/lib/Thelia/Cart/CartTrait.php index dce726552..f100d6ddc 100644 --- a/core/lib/Thelia/Cart/CartTrait.php +++ b/core/lib/Thelia/Cart/CartTrait.php @@ -120,7 +120,7 @@ trait CartTrait */ protected function duplicateCart(EventDispatcherInterface $dispatcher, CartModel $cart, Session $session, Customer $customer = null) { - $newCart = $cart->duplicate($this->generateCookie(), $customer); + $newCart = $cart->duplicate($this->generateCookie(), $customer, $dispatcher); $session->setCart($newCart->getId()); $cartEvent = new CartEvent($newCart); diff --git a/core/lib/Thelia/Core/Event/Cart/CartItemDuplicationItem.php b/core/lib/Thelia/Core/Event/Cart/CartItemDuplicationItem.php new file mode 100644 index 000000000..2ea8b04e6 --- /dev/null +++ b/core/lib/Thelia/Core/Event/Cart/CartItemDuplicationItem.php @@ -0,0 +1,70 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Cart; + +use Thelia\Core\Event\ActionEvent; +use Thelia\Model\CartItem; + + +/** + * Class CartItemDuplicationItem + * @package Thelia\Core\Event\Cart + * @author Manuel Raynaud + */ +class CartItemDuplicationItem extends ActionEvent +{ + /** + * @var \Thelia\Model\CartItem + */ + protected $oldItem; + + /** + * @var \Thelia\Model\CartItem + */ + protected $newItem; + + function __construct(CartItem $newItem, CartItem $oldItem) + { + $this->newItem = $newItem; + $this->oldItem = $oldItem; + } + + /** + * @return \Thelia\Model\CartItem + */ + public function getNewItem() + { + return $this->newItem; + } + + /** + * @return \Thelia\Model\CartItem + */ + public function getOldItem() + { + return $this->oldItem; + } + + +} \ 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 580fac029..d4d4945bc 100644 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -342,6 +342,8 @@ final class TheliaEvents */ const CART_DUPLICATE = "cart.duplicate"; + const CART_ITEM_DUPLICATE = "cart.item.duplicate"; + /** * sent when a new item is added to current cart */ diff --git a/core/lib/Thelia/Model/Cart.php b/core/lib/Thelia/Model/Cart.php index c2cb6486a..eac891986 100644 --- a/core/lib/Thelia/Model/Cart.php +++ b/core/lib/Thelia/Model/Cart.php @@ -4,6 +4,9 @@ namespace Thelia\Model; use Propel\Runtime\ActiveQuery\Criteria; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Thelia\Core\Event\Cart\CartItemDuplicationItem; +use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Base\Cart as BaseCart; class Cart extends BaseCart @@ -15,7 +18,7 @@ class Cart extends BaseCart * @param Customer $customer * @return Cart */ - public function duplicate($token, Customer $customer = null) + public function duplicate($token, Customer $customer = null, EventDispatcherInterface $dispatcher) { $cartItems = $this->getCartItems(); @@ -62,6 +65,7 @@ class Cart extends BaseCart ->setPriceEndOfLife(time() + ConfigQuery::read("cart.priceEOF", 60*60*24*30)); } $item->save(); + $dispatcher->dispatch(TheliaEvents::CART_ITEM_DUPLICATE, new CartItemDuplicationItem($item, $cartItem)); } }