Help

2

Direct to cart from Custom Button ,got Error , TypeError: add_to_cart() takes at least 2 arguments (1 given)

Avatar
Odoo

Hi,

This is my custom code ,version=10


@http.route('/wishlist/add-to-cart', type='http', auth="public", website=True)

    def add_to_cart(self,product_id,qty=1):

        cr, uid, context, registry = request.cr, request.uid, request.context, request.registry

    # Check user input

        try:

            product_id = int(product_id)

        except:

            product_id = None


        if product_id:

            product_id = registry["product.product"].browse(cr, uid, [product_id])


        # Is the product ok

            if product_id and product_id.sale_ok and product_id.website_published:

            # Get the cart-sale-order

                so = request.website.sale_get_order(force_create=1)

            # Update the cart

                so._cart_update(cr, uid, product_id=product_id.id, add_qty=1)


            # Redirect to cart anyway

        return request.redirect("/shop/cart")

Avatar
Discard
2 Answers
0
Avatar
Tim Lai
Best Answer

Hi

Could you please check the url generated by your custom button. It seems like the "product_id" does not pass to your add-to-cart method.

Best regards,

Tim

Avatar
Discard
0
Avatar
wizardz
Best Answer

no fix ?

Avatar
Discard