Files
sterivein/documentation/api/files/Model/CartItem.php.txt
Etienne Roudeix 86b11096ba Merge branch 'master' into loops
Conflicts:
	core/lib/Thelia/Core/Template/Loop/Category.php
	core/lib/Thelia/Core/Template/Loop/FeatureValue.php
	core/lib/Thelia/Core/Template/Loop/Folder.php
	core/lib/Thelia/Core/Template/Loop/Product.php
	core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php
	install/faker.php
2013-08-21 09:19:56 +02:00

69 lines
1.6 KiB
Plaintext
Executable File

<?php
namespace Thelia\Model;
use Propel\Runtime\Connection\ConnectionInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Thelia\Core\Event\Internal\CartEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\Base\CartItem as BaseCartItem;
use Thelia\Model\ConfigQuery;
class CartItem extends BaseCartItem
{
protected $dispatcher;
public function setDisptacher(EventDispatcherInterface $dispatcher)
{
$this->dispatcher = $dispatcher;
}
public function postInsert(ConnectionInterface $con = null)
{
if ($this->dispatcher) {
$cartEvent = new CartEvent($this->getCart());
$this->dispatcher->dispatch(TheliaEvents::AFTER_CARTADDITEM, $cartEvent);
}
}
public function postUpdate(ConnectionInterface $con = null)
{
if ($this->dispatcher) {
$cartEvent = new CartEvent($this->getCart());
$this->dispatcher->dispatch(TheliaEvents::AFTER_CARTCHANGEITEM, $cartEvent);
}
}
/**
* @param $value
* @return $this
*/
public function updateQuantity($value)
{
$currentQuantity = $this->getQuantity();
if($value <= 0)
{
$value = $currentQuantity;
}
if(ConfigQuery::read("verifyStock", 1) == 1)
{
$productSaleElements = $this->getProductSaleElements();
if($productSaleElements->getQuantity() < $value) {
$value = $currentQuantity;
}
}
$this->setQuantity($value);
return $this;
}
}