for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types = 1);
namespace SyliusCart\Domain\CommandHandler;
use Broadway\CommandHandling\CommandHandler;
use Broadway\Repository\RepositoryInterface;
use SyliusCart\Domain\Command\AddProductToCart;
use SyliusCart\Domain\Model\CartContract;
/**
* @author Arkadiusz Krakowiak <[email protected]>
*/
final class AddProductToCartCommandHandler extends CommandHandler
{
* @var RepositoryInterface
private $cartRepository;
* @param RepositoryInterface $cartRepository
public function __construct(RepositoryInterface $cartRepository)
$this->cartRepository = $cartRepository;
}
* @param AddProductToCart $command
public function handleAddProductToCart(AddProductToCart $command): void
/** @var CartContract $cart */
$cart = $this->cartRepository->load($command->getCartId());
$cart->addProductToCart($command->getProductCode(), $command->getQuantity(), $command->getPrice(), $command->getProductCurrencyCode());
$this->cartRepository->save($cart);