fix issue on adding item action
This commit is contained in:
@@ -22,23 +22,27 @@
|
|||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
namespace Thelia\Action;
|
namespace Thelia\Action;
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
||||||
use Thelia\Form\CategoryDeletionForm;
|
|
||||||
use Thelia\Form\BaseForm;
|
use Thelia\Form\BaseForm;
|
||||||
use Thelia\Core\HttpFoundation\Request;
|
|
||||||
use Thelia\Action\Exception\FormValidationException;
|
use Thelia\Action\Exception\FormValidationException;
|
||||||
use Thelia\Core\Event\ActionEvent;
|
use Thelia\Core\Event\ActionEvent;
|
||||||
use Symfony\Component\Form\Form;
|
use Symfony\Component\Form\Form;
|
||||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
|
||||||
use Thelia\Core\Template\ParserContext;
|
|
||||||
use Thelia\Log\Tlog;
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Thelia\Core\Security\SecurityContext;
|
|
||||||
use Thelia\Core\Security\Exception\AuthorizationException;
|
|
||||||
|
|
||||||
class BaseAction
|
class BaseAction
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var The container
|
||||||
|
*/
|
||||||
|
protected $container;
|
||||||
|
|
||||||
|
public function __construct(ContainerInterface $container) {
|
||||||
|
$this->container = $container;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate a BaseForm
|
* Validate a BaseForm
|
||||||
*
|
*
|
||||||
@@ -88,4 +92,14 @@ class BaseAction
|
|||||||
$event->stopPropagation();
|
$event->stopPropagation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the event dispatcher,
|
||||||
|
*
|
||||||
|
* @return \Symfony\Component\EventDispatcher\EventDispatcherInterface
|
||||||
|
*/
|
||||||
|
public function getDispatcher()
|
||||||
|
{
|
||||||
|
return $this->container->get('event_dispatcher');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -55,6 +55,7 @@ class Cart extends BaseAction implements EventSubscriberInterface
|
|||||||
public function addArticle(CartEvent $event)
|
public function addArticle(CartEvent $event)
|
||||||
{
|
{
|
||||||
$request = $event->getRequest();
|
$request = $event->getRequest();
|
||||||
|
$message = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$cartAdd = $this->getAddCartForm($request);
|
$cartAdd = $this->getAddCartForm($request);
|
||||||
@@ -91,11 +92,19 @@ class Cart extends BaseAction implements EventSubscriberInterface
|
|||||||
|
|
||||||
$message = $e->getMessage();
|
$message = $e->getMessage();
|
||||||
}
|
}
|
||||||
|
if($message) {
|
||||||
|
// The form has errors, propagate it.
|
||||||
|
$this->propagateFormError($cartAdd, $message, $event);
|
||||||
|
}
|
||||||
|
|
||||||
// The form has errors, propagate it.
|
|
||||||
$this->propagateFormError($cartAdd, $message, $event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* increase the quantity for an existing cartItem
|
||||||
|
*
|
||||||
|
* @param CartItem $cartItem
|
||||||
|
* @param float $quantity
|
||||||
|
*/
|
||||||
protected function updateQuantity(CartItem $cartItem, $quantity)
|
protected function updateQuantity(CartItem $cartItem, $quantity)
|
||||||
{
|
{
|
||||||
$cartItem->setDisptacher($this->getDispatcher());
|
$cartItem->setDisptacher($this->getDispatcher());
|
||||||
@@ -103,6 +112,15 @@ class Cart extends BaseAction implements EventSubscriberInterface
|
|||||||
->save();
|
->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* try to attach a new item to an existing cart
|
||||||
|
*
|
||||||
|
* @param \Thelia\Model\Cart $cart
|
||||||
|
* @param int $productId
|
||||||
|
* @param int $productSaleElementsId
|
||||||
|
* @param float $quantity
|
||||||
|
* @param ProductPrice $productPrice
|
||||||
|
*/
|
||||||
protected function addItem(\Thelia\Model\Cart $cart, $productId, $productSaleElementsId, $quantity, ProductPrice $productPrice)
|
protected function addItem(\Thelia\Model\Cart $cart, $productId, $productSaleElementsId, $quantity, ProductPrice $productPrice)
|
||||||
{
|
{
|
||||||
$cartItem = new CartItem();
|
$cartItem = new CartItem();
|
||||||
@@ -118,6 +136,15 @@ class Cart extends BaseAction implements EventSubscriberInterface
|
|||||||
->save();
|
->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* find a specific record in CartItem table using the Cart id, the product id
|
||||||
|
* and the product_sale_elements id
|
||||||
|
*
|
||||||
|
* @param int $cartId
|
||||||
|
* @param int $productId
|
||||||
|
* @param int $productSaleElementsId
|
||||||
|
* @return ChildCartItem
|
||||||
|
*/
|
||||||
protected function findItem($cartId, $productId, $productSaleElementsId)
|
protected function findItem($cartId, $productId, $productSaleElementsId)
|
||||||
{
|
{
|
||||||
return CartItemQuery::create()
|
return CartItemQuery::create()
|
||||||
@@ -127,6 +154,12 @@ class Cart extends BaseAction implements EventSubscriberInterface
|
|||||||
->findOne();
|
->findOne();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the good way to construct the cart form
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @return CartAdd
|
||||||
|
*/
|
||||||
private function getAddCartForm(Request $request)
|
private function getAddCartForm(Request $request)
|
||||||
{
|
{
|
||||||
if ($request->isMethod("post")) {
|
if ($request->isMethod("post")) {
|
||||||
|
|||||||
@@ -13,14 +13,17 @@
|
|||||||
<services>
|
<services>
|
||||||
|
|
||||||
<service id="thelia.action.cart" class="Thelia\Action\Cart">
|
<service id="thelia.action.cart" class="Thelia\Action\Cart">
|
||||||
|
<argument type="service" id="service_container"/>
|
||||||
<tag name="kernel.event_subscriber"/>
|
<tag name="kernel.event_subscriber"/>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="thelia.action.customer" class="Thelia\Action\Customer">
|
<service id="thelia.action.customer" class="Thelia\Action\Customer">
|
||||||
|
<argument type="service" id="service_container"/>
|
||||||
<tag name="kernel.event_subscriber"/>
|
<tag name="kernel.event_subscriber"/>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="thelia.action.category" class="Thelia\Action\Category">
|
<service id="thelia.action.category" class="Thelia\Action\Category">
|
||||||
|
<argument type="service" id="service_container"/>
|
||||||
<tag name="kernel.event_subscriber"/>
|
<tag name="kernel.event_subscriber"/>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ class BaseController extends ContainerAware
|
|||||||
*
|
*
|
||||||
* @return EventDispatcherInterface
|
* @return EventDispatcherInterface
|
||||||
*/
|
*/
|
||||||
protected function getDispatcher()
|
public function getDispatcher()
|
||||||
{
|
{
|
||||||
return $this->container->get('event_dispatcher');
|
return $this->container->get('event_dispatcher');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user