2
votes

After much fruitless research am still stranded trying to use sylius cart. I found out that one way to add item to cart from the twig template is

<form action="{{ path('sylius_cart_item_add', {'id': product.id}) }}" method="post" class="clearfix">
            {% set form = sylius_cart_form({'product': product}) %}
            {{ form_widget(form.quantity, {'attr': {'class': 'center-text'}, 'empty_value': '1'}) }}
            {{ form_widget(form._token) }}
            <button type="submit" class="btn btn-success"><i class="icon-shopping-cart icon-white"></i> {{ 'sylius.add_to_cart'|trans }}</button>
        </form>

when I try to use this I get 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.

1
Are you using Sylius Resource bundle too? Or is it a custom controller?gvf
@gvf Its a custom controllerAkoh Victor Gutz

1 Answers

1
votes

Twig:

 <form action="{{ path('sylius_cart_item_add', {'id': product.id}) }}" method="post">
    {{ form(form) }}
    <input type="submit" value="Submit">
 </form>

The form should be sent by the controller.