for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Eccube\Service\PurchaseFlow\Processor;
use Eccube\Entity\ItemInterface;
use Eccube\Service\PurchaseFlow\ItemValidateException;
use Eccube\Service\PurchaseFlow\PurchaseContext;
use Eccube\Service\PurchaseFlow\ValidatableItemProcessor;
/**
* 在庫制限チェック.
*/
class StockValidator extends ValidatableItemProcessor
{
protected function validate(ItemInterface $item, PurchaseContext $context)
if (!$item->isProduct()) {
return;
}
if ($item->getProductClass()->getStockUnlimited()) {
$stock = $item->getProductClass()->getStock();
$quantity = $item->getQuantity();
if ($stock == 0) {
throw ItemValidateException::fromProductClass('cart.zero.stock', $item->getProductClass());
if ($stock < $quantity) {
throw ItemValidateException::fromProductClass('cart.over.stock', $item->getProductClass());
protected function handle(ItemInterface $item, PurchaseContext $context)
$item->setQuantity($stock);