Post by sukhdeepsinghkohli » Fri May 21, 2010 8:25 pm

Hi

I am trying to Integrate the Cart into a Website. However, the Website already has a front end.

I need a way to add product with(if possible) configurable options into cart using a query string.

Example

1. From the Front End, i will send link like

http://www.example.com/opencart/index.p ... duct_id=49


Posts

Joined
Fri May 21, 2010 7:39 pm

Post by itw_davies » Mon May 24, 2010 10:36 pm

Hi sukhdeepsinghkohli

This is an interesting idea. I think we could develop this commercially for you, if you would be happy to pay for our time.

If you'd like to talk it through some more please email me at matt.davies@itwiz.co.uk.

Regards

Matt

Matt Davies

www.itwiz.co.uk | matt.davies@itwiz.co.uk


User avatar
New member

Posts

Joined
Sun Feb 07, 2010 10:14 am
Location - Surrey and Hampshire, United Kingdom

Post by Qphoria » Mon May 24, 2010 11:56 pm

Sorry to step on the toes, but this has been added to 1.4.8 already to make it easier to have add to cart buttons from all locations (homepage, category page, sideboxes, etc)

Now it will be just like that:

Code: Select all

http://www.site.com/index.php?route=checkout/cart&product_id=40&quantity=1

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by itw_davies » Tue May 25, 2010 12:10 am

Hi Q

No toes stepped on, thats great news. Is 1.4.8 out already? I'm really looking forward to using it!

Regards

Matt

Matt Davies

www.itwiz.co.uk | matt.davies@itwiz.co.uk


User avatar
New member

Posts

Joined
Sun Feb 07, 2010 10:14 am
Location - Surrey and Hampshire, United Kingdom

Post by NoExtraTime » Thu May 27, 2010 2:57 pm

Subscribing to this topic as this is great news indeed, this will come in handy for my ebay mod im working on.

Not that what you have described already Q isn't already awesome, will that query string accept multiple adds in one swoop?

Code: Select all

http://www.site.com/index.php?route=checkout/cart&product_id1=40&qty1=1&product_id2=42&qty2=2....
Also, ETA for 1.4.8? ???

Currently developing an awesome eBay integration extension for Open Cart
Demo is Live!
You can checkout screenshots and other development status on my website


New member

Posts

Joined
Wed Mar 03, 2010 5:17 pm

Post by i2Paq » Thu May 27, 2010 4:26 pm

Keep an eye on the blog.

Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________

Our FREE search: Find your answer FAST!.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by Qphoria » Thu May 27, 2010 9:50 pm

Adding multiple products at once can be done at the controller level by looping through each product and using the $this->cart->add() function

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by jfeher » Fri Sep 10, 2010 3:28 am

Just started using OpenCart and very impressed with the results.

I'm been looking for info on adding to the Cart using a Query String.

The sample posted works, http://www.site.com/index.php?route=che ... d=40&qty=1

but only adds one item to the cart.

I've tried:

http://www.site.com/index.php?route=che ... =48&qty2=1

http://www.site.com/index.php?route=che ... 48&qty_2=1

for multiple products with no success.
I'm guessing that the variables are incorrect for multiple product/qty.

I'm assuming the controller level in the previous post means modifying the code in the php script?

Any help or relevant links would be appreciated.

Newbie

Posts

Joined
Fri Sep 10, 2010 3:10 am

Post by Qphoria » Fri Sep 10, 2010 4:54 am

eh?
variables are name=value

so qty=1, qty=2, qty=100

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by jfeher » Fri Sep 10, 2010 2:11 pm

Sorry I wasn't clear enough.

I'm working with a photobook program that opens a URL with a product id and page count.

I have a script that will calculate the number of pages and pass that value to the cart.

I can create the URL with the first product_id and quantity based on the example above.

The sample URL is http://www.mysite.com/checkout/index.ph ... quantity=1

I can't seem to figure out how to add the second product_id and quantity to cart via the URL.

Thanks.

Newbie

Posts

Joined
Fri Sep 10, 2010 3:10 am

Post by Qphoria » Fri Sep 10, 2010 9:57 pm

Ohh i see what you are saying. No it doesn't support multiple products within the url. only single
product_id and quantity

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by jfeher » Fri Sep 10, 2010 11:58 pm

I'm making some progress. I can submit a form via GET as an array.
My next step is to look at the cart.php and see if I can step through the array.

Code: Select all

<HTML>
<HEAD>
<TITLE>OpenCart Test</TITLE>
</HEAD>
<BODY>
<H1>OpenCart Test</H1>
<form action="http://www.yoursite.com/checkout/index.php" method="get" enctype="multipart/form-data">
<INPUT TYPE="Hidden" NAME="route" VALUE="checkout/cart"/>
<INPUT TYPE="Hidden" NAME="product_id[]" VALUE="40"/>
<INPUT TYPE="Hidden" NAME="quantity[]" VALUE="2"/>
<INPUT TYPE="Hidden" NAME="product_id[]" VALUE="48"/>
<INPUT TYPE="Hidden" NAME="quantity[]" VALUE="5"/>
<INPUT TYPE="SUBMIT" NAME="button" VALUE="Get">
</FORM>
</BODY>
</HTML>

Newbie

Posts

Joined
Fri Sep 10, 2010 3:10 am

Post by jfeher » Mon Sep 13, 2010 9:44 pm

Success! I was able to modify /catalog/controller/checkout/cart.php to process the multiple items and quantities in the querystring. Any changes or improvements are welcome.

Code: Select all

    public function index() {
        $this->language->load('checkout/cart');
        
        if ($this->request->server['REQUEST_METHOD'] == 'GET' && isset($this->request->get['product_id'][0])) {
                $myresult=count($_GET["product_id"]);
                
                FOR ($i="0";$i<$myresult;$i++)
                {
        
            if (isset($this->request->get['option'][$i])) {
                $option = $this->request->get['option'][$i];
            } else {
                $option = array();    
            }
                
            if (isset($this->request->get['quantity'][$i])) {
                $quantity = $this->request->get['quantity'][$i];
            } else {
                $quantity = 1;
            }
        
            
            unset($this->session->data['shipping_methods']);
            unset($this->session->data['shipping_method']);
            unset($this->session->data['payment_methods']);
            unset($this->session->data['payment_method']);
            
            
            $this->cart->add($this->request->get['product_id'][$i], $quantity, $option);
            }
            $this->redirect(HTTPS_SERVER . 'index.php?route=checkout/cart');
            
        } elseif ($this->request->server['REQUEST_METHOD'] == 'POST') {

Newbie

Posts

Joined
Fri Sep 10, 2010 3:10 am

Post by Qphoria » Mon Sep 13, 2010 11:48 pm

Good to hear!

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by marc_cole » Mon Jan 03, 2011 11:28 am

jfeher wrote:I was able to modify /catalog/controller/checkout/cart.php to process the multiple items and quantities in the querystring.
I ran across your code and gave it a try, but it's not working for me. If I use this URL:

Code: Select all

http://localhost:8888/opencart/index.php?route=checkout/cart&product_id=5887&quantity=2&product_id=6447&quantity=2&product_id=6454&quantity=4
only the last item and qty get entered in the cart.

Is my URL formatted incorrectly?

Thanks,
Marc

OpenCart v1.4.9.4
VQMod | Categories Home | Cleaner By Default - 2 Column | Speak Good English


Active Member

Posts

Joined
Tue Dec 14, 2010 11:26 am
Location - Seattle, WA

Post by marc_cole » Wed Jan 05, 2011 8:59 am

I didn't realize this was an older thread when I posted. Is there updated code to get this to work with 1.4.9.3?

Thanks,
Marc

OpenCart v1.4.9.4
VQMod | Categories Home | Cleaner By Default - 2 Column | Speak Good English


Active Member

Posts

Joined
Tue Dec 14, 2010 11:26 am
Location - Seattle, WA

Post by marc_cole » Thu Jan 06, 2011 12:37 am

I'm getting closer.

Code: Select all

http://localhost:8888/opencart/index.php?route=checkout/cart&product_id[]=5887&quantity=2&product_id[]=6447&quantity=2&product_id[]=6454&quantity=4
This code now adds all three products to the cart, but the quantities are wrong.

Any ideas?

OpenCart v1.4.9.4
VQMod | Categories Home | Cleaner By Default - 2 Column | Speak Good English


Active Member

Posts

Joined
Tue Dec 14, 2010 11:26 am
Location - Seattle, WA

Post by marc_cole » Thu Jan 06, 2011 6:44 am

I finally figured this out. jfeher's code above produces an array of product_id and quantity, so the URL has to reflect that. (I'm sure that's worded incorrectly.) :-\

Code: Select all

 http://localhost:8888/opencart/index.php?route=checkout/cart&product_id[0]=5887&quantity[0]=2&product_id[1]=6447&quantity[1]=3&product_id[2]=6454&quantity[2]=4
The numbers in the brackets refer to the array elements. PHP numbering starts at zero, so [0] is the first element. Numbering all the pairs of the elements with the proper sequence results in the items being added to the cart properly.

BTW, a good PHP book is worth it's weight in gold. I'm reading "Beginning PHP 5.3" by Matt Doyle and just got to the section on arrays and that's what helped me figure this out.

Marc

Edit: I've added a vqmod with jfeher's code, in case anyone else wants to do this.

Attachments

Last edited by marc_cole on Sat Jan 08, 2011 2:22 am, edited 1 time in total.

OpenCart v1.4.9.4
VQMod | Categories Home | Cleaner By Default - 2 Column | Speak Good English


Active Member

Posts

Joined
Tue Dec 14, 2010 11:26 am
Location - Seattle, WA

Post by marc_cole » Fri Jan 07, 2011 6:54 am

I've been trying to modify this to work with the model # instead of product_id, but I'm not having any luck. Does anyone else know how to make this work?

Code: Select all

http://localhost:8888/opencart/index.php?route=checkout/cart&model[0]=4D-2448-7P&quantity[0]=2&model[1]=1D-2448-P&quantity[1]=3&model[2]=S2448P&quantity[2]=4
Thanks,
Marc

OpenCart v1.4.9.4
VQMod | Categories Home | Cleaner By Default - 2 Column | Speak Good English


Active Member

Posts

Joined
Tue Dec 14, 2010 11:26 am
Location - Seattle, WA

Post by jonle28 » Fri Apr 08, 2011 3:31 am

marc_cole wrote:I've been trying to modify this to work with the model # instead of product_id, but I'm not having any luck. Does anyone else know how to make this work?

Code: Select all

http://localhost:8888/opencart/index.php?route=checkout/cart&model[0]=4D-2448-7P&quantity[0]=2&model[1]=1D-2448-P&quantity[1]=3&model[2]=S2448P&quantity[2]=4
Thanks,
Marc

Just to let you know, http://localhost:8888/ means only people on your computer/server can see it. Screen shots or a live test server would help the sharing.

Newbie

Posts

Joined
Sat Mar 26, 2011 12:07 pm
Who is online

Users browsing this forum: No registered users and 5 guests