Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble with How to change a redirect after the add to cart action? #7877

Closed
ascameron1 opened this issue Apr 2, 2017 · 1 comment
Closed

Comments

@ascameron1
Copy link

Hi,

I am new to sylius and php in generally and I'm having trouble with the redirect after adding to the car. I have followed the cookbook tutorial but not sure what is meant at the end by handling this on the front end?

What I've tried:

I've tried to implement what is set out in the tutorial and set the redirect link to:

$newUrl = $this->router->generate('sylius_shop_product_index', ['slug' => 'product']);
$event->setResponse(new RedirectResponse($newUrl));

However this causes an error in the Javascript:

sylius-add-to-cart.js
$.each(response.errors.errors, function (key, message) {
        validationMessage += message;
});

Uncaught TypeError: Cannot read property 'errors' of undefined
    at HTMLFormElement.onFailure (app.js:1363)
    at Object.fail (app.js:23)
    at i (app.js:2)
    at Object.fireWith [as rejectWith] (app.js:2)
    at app.js:23

Ideally, i wanted this to happen with no redirect at all and for the cart total to update automatically. However i have tried unsuccessfully to override the sylius-add-to-cart.js file. I have tried to disable the redirect path in both cart.yml and _addToCart.html.twig:

sylius_shop_ajax_cart_add_item:
    path: /add
    methods: [POST]
    defaults:
        _controller: sylius.controller.order_item:addAction
        _format: json
        _sylius:
            factory:
                method: createForProduct
                arguments:    [expr:notFoundOnNull(service('sylius.repository.product').find($productId))]
            form:
                type: Sylius\Bundle\CoreBundle\Form\Type\Order\AddToCartType
                options:
                    product: expr:notFoundOnNull(service('sylius.repository.product').find($productId))
#            redirect:
#                route: sylius_shop_cart_summary
#                parameters: {}
            flash: sylius.cart.add_item  

Im at a loss with this now and im considering just doing my own ajax call etc to add to cart but i thought there was a more sylius/symfony way to do this?

Any help will be greatly appreciated.

p.s. i have tried Stack overflow as well.

@cchapleau
Copy link

I have the same problem.
Doesn't anyone know how to fix this problem?
Any help would be appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants