fix issue on adding item action

This commit is contained in:
Manuel Raynaud
2013-08-13 09:53:49 +02:00
parent 7f83225645
commit 541fe7f75d
4 changed files with 61 additions and 11 deletions

View File

@@ -22,23 +22,27 @@
/*************************************************************************************/
namespace Thelia\Action;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Thelia\Form\CategoryDeletionForm;
use Thelia\Form\BaseForm;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Action\Exception\FormValidationException;
use Thelia\Core\Event\ActionEvent;
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 Thelia\Core\Security\SecurityContext;
use Thelia\Core\Security\Exception\AuthorizationException;
class BaseAction
{
/**
* @var The container
*/
protected $container;
public function __construct(ContainerInterface $container) {
$this->container = $container;
}
/**
* Validate a BaseForm
*
@@ -88,4 +92,14 @@ class BaseAction
$event->stopPropagation();
}
/**
* Return the event dispatcher,
*
* @return \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
public function getDispatcher()
{
return $this->container->get('event_dispatcher');
}
}

View File

@@ -55,6 +55,7 @@ class Cart extends BaseAction implements EventSubscriberInterface
public function addArticle(CartEvent $event)
{
$request = $event->getRequest();
$message = null;
try {
$cartAdd = $this->getAddCartForm($request);
@@ -91,11 +92,19 @@ class Cart extends BaseAction implements EventSubscriberInterface
$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)
{
$cartItem->setDisptacher($this->getDispatcher());
@@ -103,6 +112,15 @@ class Cart extends BaseAction implements EventSubscriberInterface
->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)
{
$cartItem = new CartItem();
@@ -118,6 +136,15 @@ class Cart extends BaseAction implements EventSubscriberInterface
->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)
{
return CartItemQuery::create()
@@ -127,6 +154,12 @@ class Cart extends BaseAction implements EventSubscriberInterface
->findOne();
}
/**
* Find the good way to construct the cart form
*
* @param Request $request
* @return CartAdd
*/
private function getAddCartForm(Request $request)
{
if ($request->isMethod("post")) {

View File

@@ -13,14 +13,17 @@
<services>
<service id="thelia.action.cart" class="Thelia\Action\Cart">
<argument type="service" id="service_container"/>
<tag name="kernel.event_subscriber"/>
</service>
<service id="thelia.action.customer" class="Thelia\Action\Customer">
<argument type="service" id="service_container"/>
<tag name="kernel.event_subscriber"/>
</service>
<service id="thelia.action.category" class="Thelia\Action\Category">
<argument type="service" id="service_container"/>
<tag name="kernel.event_subscriber"/>
</service>

View File

@@ -199,7 +199,7 @@ class BaseController extends ContainerAware
*
* @return EventDispatcherInterface
*/
protected function getDispatcher()
public function getDispatcher()
{
return $this->container->get('event_dispatcher');
}