Skip to Content
Menu
This question has been flagged
1 Reply
4649 Views

Is there any way to add product directly to cart from a external link.

Example : Suppose I have my Odoo e-commerce website running on http://www.myodoo.com & I having a product which i am promoting from another website, now i want to set a link in such a way so when user click the link it will come to my Odoo e-commerce cart page with auto selection of that product and qty and other parameter, http://www.myodoo.com/shop/cart

So in this way no need to select the product and entry qty manually by end user , direct link maybe like http://www.myodoo.com/shop/cart?prouct='xyz'&qty=1.

Any help or suggestions are welcome....

Avatar
Discard

Hi, did you managed to get this working?

Thanks

Best Answer

Just write your own route.


@http.route('/shop/add-to-cart', type='http', auth="public", website=True)
def add_to_cart(self,pId,qty=1){
     cr,uid,context,registry = request.cr,request.uid,request.context,request.registry

     #Check user input
     try:
        product_id = int(pId)
    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=qty)
   
    #Redirect to cart anyway   
    return request.redirect("/shop/cart")    
}

    
I couldn't try this code, but it should work.
If you need help with writing modules. You can find useful information here

\http://www.odoo.com/documentation/8.0/howtos/website.html#urls-and-routing


Avatar
Discard

it doesn't work = this error comes : add_new_cart() takes at least 2 arguments (1 given)

Related Posts Replies Views Activity
0
Dec 16
2973
0
Nov 19
2776
0
Apr 23
821
1
Apr 23
1417
3
Mar 20
5474