Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
5611 Tampilan

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
Buang

Hi, did you managed to get this working?

Thanks

Jawaban Terbai

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
Buang

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

Post Terkait Replies Tampilan Aktivitas
0
Des 16
3932
0
Nov 19
3713
0
Apr 23
1562
1
Apr 23
2373
3
Mar 20
6378