{% set form = sylius_cart_form({'product': product}) %} {# You can pass options as an argument. #} <form action="{{ path('sylius_cart_item_add', {'productId': product.id}) }}" method="post"> {{ form_row(form.quantity)}} {{ form_widget(form._token) }} <input type="submit" value="Add to cart"> </form>)
sylius_cart_form({'product': product})
with
sylius_cart_form({'data_class': sylius_cart_item})
the error goes out when I submit the quantity does not persist.
Also i notice that i was asked to process this form in my resolver
"The sylius_cart_form
returns the form view for the CartItem form. It allows you to easily
build more complex actions for
adding items to cart. In this simple example we allow to provide the
quantity of item. You’ll need to process this form in your resolver."
if the replacing of
sylius_cart_form({'product': product})
with
sylius_cart_form({'data_class': sylius_cart_item})
is correct then the next question is how do i
process this form in my resolver ?
this is my resolver
<?php
namespace AppBundle\Service\Cart;
use AppBundle\Entity\OrderItem;
use Sylius\Component\Cart\Model\CartItemInterface;
use Sylius\Component\Cart\Resolver\ItemResolverInterface;
use Sylius\Component\Cart\Resolver\ItemResolvingException;
use Doctrine\ORM\EntityManager;
class ItemResolver implements ItemResolverInterface
{
private $entityManager;
public function __construct(EntityManager $entityManager,)
{
$this->entityManager = $entityManager;
}
public function resolve(CartItemInterface $item, $request)
{
$productId = $request->query->get('productId');
item = new OrderItem();
// If no product id given, or product not found, we throw exception with nice message.
if (!$productId || !$product = $this->getProductRepository()->find($productId)) {
throw new ItemResolvingException('Requested product was not found. Report this to ch...@nimikiddies.com');
}
if (!$request->isMethod('POST')) {
throw new ItemResolvingException('Wrong request method');
}
$this->isStockAvailable($product);
// Assign the product to the item and define the unit price.
$item->setProduct($product);
$item->setUnitPrice($product->getPrice());
return $item;
}
private function isStockAvailable($product)
{
//check the if the selected product is available
}
private function getProductRepository()
{
return $this->entityManager->getRepository('AppBundle:Product');
}
///
x

the end result for the cart is for me to able to get the cart summary as shown in the
image above
Thank you for your time