how to implement sylius cart v0.17 in symfony 2.8.3

63 views
Skip to first unread message

Akoh ojochuma victor

unread,
Apr 20, 2016, 9:01:37 PM4/20/16
to Sylius

Hello all,

Am trying to implement sylius order and cartBundle in my symfony app, for some reasons its not been smooth for me, my questions appears to be very simple i feel am missing the obvious. please i really need help. am kind off stock at this point.


1 how can i display the form below?

 from the documentation am asked use  this (
{% 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>
)
if i do this i get this error
 (An exception has been thrown during the rendering of a template ("The option "product" does not exist. Defined options are: "action", "allow_extra_fields", "attr", "auto_initialize", "block_name", "by_reference", "cascade_validation", "compound", "constraints", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_provider", "csrf_token_id", "csrf_token_manager", "data", "data_class", "disabled", "empty_data", "error_bubbling", "error_mapping", "extra_fields_message", "inherit_data", "intention", "invalid_message", "invalid_message_parameters", "label", "label_attr", "label_format", "mapped", "max_length", "method", "pattern", "post_max_size_message", "property_path", "read_only", "required", "translation_domain", "trim", "validation_groups", "virtual"."))

if I replace the
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😔
Reply all
Reply to author
Forward
0 new messages