Post by ultraspoon » Thu Mar 08, 2012 1:45 am

If found an older thread which told me how to do what im looking for, but it did not work for me.

I am using 1.495 and I want to add to cart from an external page,

http://www.teststore/index.php?route=ch ... quantity=1

I tried that above but it just took me the shopping cart which was empty.

Any Ideas?

Thanks

Active Member

Posts

Joined
Mon Oct 18, 2010 5:56 pm

Post by ultraspoon » Fri Mar 09, 2012 10:41 pm

Does nobody know how to do this?

Active Member

Posts

Joined
Mon Oct 18, 2010 5:56 pm

Post by scd1982 » Sat Apr 07, 2012 3:35 am

Is this what you're looking for?
http://forum.opencart.com/viewtopic.php?t=14960
I think this has been disabled for 1.5x, but I've used it on 1.4.9.2.

Code: Select all

http://www.site.com/index.php?route=checkout/cart&product_id=40&quantity=1
Just need to change "www.site.com" to your site, and the product id (40) to your product's id number.

I usually forget to mention I'm using OC v1.4.9.4


New member

Posts

Joined
Tue Mar 27, 2012 3:57 am

Post by Avvici » Sat Apr 07, 2012 3:12 pm

You are going to want to go into your cart.php file within the checkout folder. Once in there you want to set up a check for certain GET variables set in your URL. This would be done inside the public function index() { Now, you have power to do really anything you want. You can call any function you wish inside that file to add, delete, update items to your cart. Or you can add something to your cart on the spot inside the if statement.
AMENDED CODE UPDATE

Code: Select all

http://www.yoursite.com/index.php?route=checkout/cart&productid=40&quantity=1
Just run a check and execute the code in the index function at the top somewhere like this:

Code: Select all

if(isset($this->request->get['productid']) && isset($this->request->get['quantity'])){
      //add to the cart
$this->cart->add($this->request->get['productid'], $this->request->get['quantity'], $option = array());
 //you can leave the 3rd $option argument alone..
}

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by admintech » Sat Jun 02, 2012 2:51 pm

Hi Avvici

I have followed your post and changed cart.php found under catalog/controller/checkout with your code in the top.

However, I get following errors:

Code: Select all

Warning: Invalid argument supplied for foreach() in /home/exlors/public_html/intelliproducts.co.uk/tempcart/catalog/controller/checkout/cart.php on line 19Warning: Cannot modify header information - headers already sent by (output started at /home/exlors/public_html/intelliproducts.co.uk/tempcart/index.php:104) in /home/exlors/public_html/intelliproducts.co.uk/tempcart/vqmod/vqcache/vq2-system_engine_controller.php on line 28Warning: Cannot modify header information - headers already sent by (output started at /home/exlors/public_html/intelliproducts.co.uk/tempcart/index.php:104) in /home/exlors/public_html/intelliproducts.co.uk/tempcart/vqmod/vqcache/vq2-system_engine_controller.php on line 29
Thanks in anticipation.

Newbie

Posts

Joined
Sat Jun 02, 2012 2:46 pm

Post by Avvici » Sat Jun 02, 2012 8:22 pm

Tested and works great. Did you place it BELOW public function index()? Are you supplying the actual add to cart function with the get URL?

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by admintech » Mon Jun 04, 2012 3:56 pm

Hi Avvici

I have changed cart.php under catalog/controller/checkout folder.. below is the part of code; I have added the code to top of public function index() as below:

Code: Select all

public function index() {
		$this->language->load('checkout/cart');
if(isset($this->request->get['productid']) && isset($this->request->get['quantity'])){
      //add to the cart
$this->cart->add($this->request->get['productid'], $this->request->get['quantity'], $option);
//you can leave the 3rd $option argument alone..
}

		if (!isset($this->session->data['vouchers'])) {
			$this->session->data['vouchers'] = array();
		}
		
		// Update
		if (!empty($this->request->post['quantity'])) {
			foreach ($this->request->post['quantity'] as $key => $value) {
				$this->cart->update($key, $value);
			}
			
			unset($this->session->data['shipping_method']);
			unset($this->session->data['shipping_methods']);
			unset($this->session->data['payment_method']);
			unset($this->session->data['payment_methods']); 
			unset($this->session->data['reward']);
			
			$this->redirect($this->url->link('checkout/cart'));  			
		}
       	
		// Remove.....

Newbie

Posts

Joined
Sat Jun 02, 2012 2:46 pm

Post by Avvici » Mon Jun 04, 2012 6:37 pm

No, it's because your URL is not passing the info like I suggested. Your url:

Code: Select all

http://www.intelliproducts.co.uk/tempcart/index.php?route=checkout/cart
Correct url:

Code: Select all

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

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by admintech » Mon Jun 04, 2012 8:12 pm

Hi Avvici

I updated the said code and now it takes me to the page but does not add anything and says shopping cart empty.

I have put:

Code: Select all

   <form action="http://www.intelliproducts.co.uk/tempcart/index.php?route=checkout/cart&product_id=50&quantity=1 method="post">
<input type="submit" name="submit" class="submit" />
</form>

Newbie

Posts

Joined
Sat Jun 02, 2012 2:46 pm

Post by rob55 » Wed Jul 04, 2012 6:56 am

I'm having the same issues. It appears to work in IE9, but no go in IE8 or FF

Newbie

Posts

Joined
Wed Jul 04, 2012 1:51 am

Post by Avvici » Wed Jul 04, 2012 8:56 am

Guys, everyone, you are directing towards a URL not a FORM URL.

http://www.yoursite.com/index.php?route ... quantity=1

Don't stick that url in a form lol. Make it a basic <a href


WRONG: <form action="http://www.intelliproducts.co.uk/tempca ... quantity=1 method="post">
<input type="submit" name="submit" class="submit" />
</form>

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by irbe » Sun Jul 08, 2012 9:33 pm

Yes, this works using a url-link (get).
However I experience strange things with quantity, adding quantity 1 (one) of the article with this link:

Code: Select all

http://www.mydomain.eu/webshop/index.php?route=checkout/cart&productid=52&quantity=1
I end up with one in cart. Now I delete the one in the cart and try again.
Now I have quantity 2 (two) of the article. Delete and try again.
Quantity 3 (three).
etc, etc.

irbe

Newbie

Posts

Joined
Fri Jul 06, 2012 3:50 am

Post by Avvici » Sun Jul 08, 2012 11:12 pm

I made an error in the code that will in fact throw an error so here it the corrected code:

Code: Select all

if(isset($this->request->get['productid']) && isset($this->request->get['quantity'])){
      //add to the cart
$this->cart->add($this->request->get['productid'], $this->request->get['quantity'], $option = array());
 //you can leave the 3rd $option argument alone..
}
As far as your particular problem what version of Open Cart are you using? What you are describing is impossible. The only way that you are aggregating a quantity in the cart like that is if the URL in your browser is not changing after you delete. You are in fact using a GET so the quantity=1 is going to be there and take affect.

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by irbe » Sun Jul 08, 2012 11:44 pm

It did. However after changing $option = "" to $option = array() it started to work.

Thanks!

irbe

Newbie

Posts

Joined
Fri Jul 06, 2012 3:50 am

Post by Avvici » Sun Jul 08, 2012 11:52 pm

cheers

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by Eugen77777 » Tue Sep 04, 2012 9:45 pm

Pleas let me up this topic.

Avvici, I have done all those thing.
I add code to cart.php

Code: Select all

	public function index() {

		$this->language->load('checkout/cart');

if(isset($this->request->get['productid']) && isset($this->request->get['quantity'])){
      //add to the cart
$this->cart->add($this->request->get['productid'], $this->request->get['quantity'], $option = array());
 //you can leave the 3rd $option argument alone..
}

		if (!isset($this->session->data['vouchers'])) {

			$this->session->data['vouchers'] = array();

		}

		
After I try to use link

http://www.novyjrazum.ru/store/index.ph ... quantity=1

but in IE I have an error: Access is denied.


Help me fix this problem pleas.



Version 1.5.3.1 of OpenCart

Newbie

Posts

Joined
Tue Sep 04, 2012 1:45 am
Who is online

Users browsing this forum: No registered users and 182 guests