Page 1 of 2

[1.5.x] external website 'add to cart' href

Posted: Wed Jun 22, 2011 12:31 am
by elastic
Hello

In previous versions (1.4.9.x), if you had a link on an external website with the href set to this;

<a href="http://yourwebsite/index.php?route=chec ... quantity=1"> link! </a>

...it added a product to the cart. That doesn't work any more (I'm guessing because of the new Ajax cart, could be wrong).

Is there an updated URL/href to add products I could use?

many thanks
Matt

Re: [1.5.x] external website 'add to cart' href

Posted: Wed Jun 22, 2011 6:14 pm
by elastic
Found it.

If anyone is interested, you can add a product to the (1.5.x) cart from an external website using this form structure;

<form action="http://yoursite/index.php?route=checkout/cart" method="post">
<input type="hidden" name="product_id" value="XX">
<input type="hidden" name="quantity" value="1">
<input type="submit" name="submit" value="submit">
</form>

where XX is the product ID number and 'yoursite' is obviously the domain of your shop.

Cheers
Matt

Re: [1.5.x] external website 'add to cart' href

Posted: Tue Sep 13, 2011 10:04 am
by st3vieb
This is very useful.

What if I want to add another variable (a small additional piece of information) to be sent? How do I configure opencart 1.5x to do that?

Basically I want to send something similar to:

<form action="http://st3vieb.com/store/index.php?route=checkout/cart" id="personalVirtualPrivateServerForm" method="post">
<input type="hidden" name="product_id" value="80">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="info" value="whatever">
<a href="#" class="link" onClick="document.getElementById('personalVirtualPrivateServerForm').submit()">Purchase</a>
</form>

and have open cart receive product_id, quantity and info variables.

Is there a simple module that I could use that allows me to pass product_id, quantity and another variable (info) straight to the cart from a form/external link?

Steve

Re: [1.5.x] external website 'add to cart' href

Posted: Tue Sep 13, 2011 11:29 am
by Xsecrets
st3vieb wrote:This is very useful.

What if I want to add another variable (a small additional piece of information) to be sent? How do I configure opencart 1.5x to do that?

Basically I want to send something similar to:

<form action="http://st3vieb.com/store/index.php?route=checkout/cart" id="personalVirtualPrivateServerForm" method="post">
<input type="hidden" name="product_id" value="80">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="info" value="whatever">
<a href="#" class="link" onClick="document.getElementById('personalVirtualPrivateServerForm').submit()">Purchase</a>
</form>

and have open cart receive product_id, quantity and info variables.

Is there a simple module that I could use that allows me to pass product_id, quantity and another variable (info) straight to the cart from a form/external link?

Steve
no

Re: [1.5.x] external website 'add to cart' href

Posted: Tue Sep 13, 2011 2:37 pm
by st3vieb
Is anyone aware of any way to send dynamic variables other than "product_id" and "quantity" to the cart from an external form?

I need to get this done.

Re: [1.5.x] external website 'add to cart' href

Posted: Tue Sep 13, 2011 6:05 pm
by uksitebuilder
It depends on what it is you want to send.

The only way I can see this working is if you have an option on the product set-up as a text input.

You should then be able to figure out what variable to send over

Re: [1.5.x] external website 'add to cart' href

Posted: Tue Sep 13, 2011 9:44 pm
by Xsecrets
yes you can send over text options, but it would have to already be setup on that product and can't be dynamic.

Re: [1.5.x] external website 'add to cart' href

Posted: Wed Sep 14, 2011 11:58 am
by st3vieb
I'm looking to send an alpha numeric string (its actually a domain name eg the string would be "whatever123.com") which would vary depending upon the domain that the user wishes to purchase. Thus the input text needs to be dynamic.

I've attempted using the "available options" (called options in opencart 1.5 admin area), but when viewing the source code for the product the code is an "option" and not "input type" and thus I couldn't send a dynamic variable - it had to be from a predifined option value as setup in the admin area. Same goes for using "attributes" in the admin section.

Code from product page (couldn't send dynamic variable due to not being an input type):

<div id="option-226" class="option">
<span class="required">*</span>
<b>Domain:</b><br />
<select name="option[226]">
<option value=""> --- Please Select --- </option>
</select>
</div>


Any thoughts on how to go about implementing a dynamic text-input? Or altering some opencart code so that "available options" can be sent values dynamically? It only needs to apply to one particular product if that helps.

BTW thankyou to all for help to date.

Re: [1.5.x] external website 'add to cart' href

Posted: Wed Sep 14, 2011 12:24 pm
by st3vieb
uksitebuilder wrote:It depends on what it is you want to send.

The only way I can see this working is if you have an option on the product set-up as a text input.

You should then be able to figure out what variable to send over
I totally agree.

How do I go about implementing your suggestion?

Re: [1.5.x] external website 'add to cart' href

Posted: Sat Apr 07, 2012 4:13 am
by scd1982
elastic wrote: If anyone is interested, you can add a product to the (1.5.x) cart from an external website using this form structure;

<form action="http://yoursite/index.php?route=checkout/cart" method="post">
<input type="hidden" name="product_id" value="XX">
<input type="hidden" name="quantity" value="1">
<input type="submit" name="submit" value="submit">
</form>

where XX is the product ID number and 'yoursite' is obviously the domain of your shop.
When I do this in 1.5.2.1, I get the following error:

Code: Select all

Warning: Invalid argument supplied for foreach() in /home/public_html/vqmod/vqcache/vq2-catalog_controller_checkout_cart.php on line 14Warning: Cannot modify header information - headers already sent by (output started at /home/public_html/index.php:104) in /home/public_html/vqmod/vqcache/vq2-system_engine_controller.php on line 28Warning: Cannot modify header information - headers already sent by (output started at /home/public_html/index.php:104) in /home/public_html/vqmod/vqcache/vq2-system_engine_controller.php on line 29
Lines 13, 14, 15 and 16 of /home/public_html/vqmod/vqcache/vq2-catalog_controller_checkout_cart.php:

Code: Select all

13 if (!empty($this->request->post['quantity'])) {
14	foreach ($this->request->post['quantity'] as $key => $value) {
15		$this->cart->update($key, $value);
16		}
Line 27, 28, 29, 30 and 31 of /home/public_html/vqmod/vqcache/vq2-system_engine_controller.php:

Code: Select all

27	protected function redirect($url, $status = 302) {
28		header('Status: ' . $status);
29		header('Location: ' . str_replace('&', '&', $url));
30		exit();
31	}
I'm not sure why this is happening. Any thoughts?

Re: [1.5.x] external website 'add to cart' href

Posted: Mon Apr 09, 2012 1:56 am
by alber99
anyone know how to apply "add to cart" functionality to a banner - so that customer can click header banner image on product page to add to cart ? The banner manager in admin only has an entry field for "link".

Re: [1.5.x] external website 'add to cart' href

Posted: Tue Apr 10, 2012 1:57 am
by scd1982
alber99 wrote:anyone know how to apply "add to cart" functionality to a banner - so that customer can click header banner image on product page to add to cart ? The banner manager in admin only has an entry field for "link".
Check out this post http://forum.opencart.com/viewtopic.php?t=14960 Depending on what version of OC you are running, there's a way to set a URL to add a product to the cart.

Re: [1.5.x] external website 'add to cart' href

Posted: Wed Apr 11, 2012 6:57 am
by naturesfootprint
scd1982 wrote:
elastic wrote: If anyone is interested, you can add a product to the (1.5.x) cart from an external website using this form structure;

<form action="http://yoursite/index.php?route=checkout/cart" method="post">
<input type="hidden" name="product_id" value="XX">
<input type="hidden" name="quantity" value="1">
<input type="submit" name="submit" value="submit">
</form>

where XX is the product ID number and 'yoursite' is obviously the domain of your shop.
When I do this in 1.5.2.1, I get the following error:

Code: Select all

Warning: Invalid argument supplied for foreach() in /home/public_html/vqmod/vqcache/vq2-catalog_controller_checkout_cart.php on line 14Warning: Cannot modify header information - headers already sent by (output started at /home/public_html/index.php:104) in /home/public_html/vqmod/vqcache/vq2-system_engine_controller.php on line 28Warning: Cannot modify header information - headers already sent by (output started at /home/public_html/index.php:104) in /home/public_html/vqmod/vqcache/vq2-system_engine_controller.php on line 29
Lines 13, 14, 15 and 16 of /home/public_html/vqmod/vqcache/vq2-catalog_controller_checkout_cart.php:

Code: Select all

13 if (!empty($this->request->post['quantity'])) {
14	foreach ($this->request->post['quantity'] as $key => $value) {
15		$this->cart->update($key, $value);
16		}
Line 27, 28, 29, 30 and 31 of /home/public_html/vqmod/vqcache/vq2-system_engine_controller.php:

Code: Select all

27	protected function redirect($url, $status = 302) {
28		header('Status: ' . $status);
29		header('Location: ' . str_replace('&', '&', $url));
30		exit();
31	}
I'm not sure why this is happening. Any thoughts?
I'm having the same issue, find any solutions yet?

Re: [1.5.x] external website 'add to cart' href

Posted: Thu Apr 12, 2012 1:56 am
by scd1982
naturesfootprint wrote:I'm having the same issue, find any solutions yet?
Check this post out, and see if it helps: http://forum.opencart.com/viewtopic.php?f=20&t=55340
It isn't exactly the same thing, but it gets the same result.

Re: [1.5.x] external website 'add to cart' href

Posted: Fri Apr 13, 2012 1:35 am
by naturesfootprint
scd1982 wrote:
naturesfootprint wrote:I'm having the same issue, find any solutions yet?
Check this post out, and see if it helps: http://forum.opencart.com/viewtopic.php?f=20&t=55340
It isn't exactly the same thing, but it gets the same result.
Excellent! that works for getting the item into the cart and defining a quantity, but I can't figure out how to set up the variable option. I've got a product with three color options and somewhere the customer needs to select that color.

Re: [1.5.x] external website 'add to cart' href

Posted: Fri Apr 13, 2012 2:10 am
by scd1982
naturesfootprint wrote:Excellent! that works for getting the item into the cart and defining a quantity, but I can't figure out how to set up the variable option. I've got a product with three color options and somewhere the customer needs to select that color.
I haven't figured out the options yet either. A quick fix might be to setup 3 identical products, one for each color. Then set your form/link to point to the correct product (color) as necessary.

Re: [1.5.x] external website 'add to cart' href

Posted: Fri Aug 03, 2012 11:49 pm
by pooks
Umm do you mean that there is no way to send product options from external site? Like color or size?

Re: [1.5.x] external website 'add to cart' href

Posted: Sat Aug 04, 2012 3:08 am
by scd1982
pooks wrote:Umm do you mean that there is no way to send product options from external site? Like color or size?
No, not as far as I can tell. Unless something has been developed to do this in the meantime??

Re: [1.5.x] external website 'add to cart' href

Posted: Tue Dec 04, 2012 9:19 pm
by DefconRhall
None of these solutions seem to work for 1.5.4
This really should be a feature put into the base system

Re: [1.5.x] external website 'add to cart' href

Posted: Wed Mar 06, 2013 1:46 am
by Dcru
Has there been any progress made getting this working for 1.5.4?