Post by NewB101 » Mon May 19, 2014 2:55 pm

Objective: I would like to create a link on a HTML page (e.g. online newsletter) that directly adds a specific product to OpenCart shopping cart and forwards the user to the Check Out page.

Use Case:
1. User clicks on link on HTML page
2. Product added to OpenCart shopping cart
3. User forwarded to OpenCart check-out page, to enter payment information

Question: How do I achieve above?


I have searched this forum and googled but those suggested solutions were for OpenCart versions 1.49 or earlier.

Could someone please advise urgently?



Open Cart Version: 1.5.6.4

Newbie

Posts

Joined
Mon May 19, 2014 2:45 pm

Post by NewB101 » Mon May 19, 2014 7:53 pm

@ Xyph3r - Thank you for the suggestion of paid extension.

I am hoping for a free option, that is, a code change instruction. Anyone?

Newbie

Posts

Joined
Mon May 19, 2014 2:45 pm

Post by IP_CAM » Mon May 19, 2014 9:38 pm

Reading your Post, I wanted to know if and how it works. After waisting a lot of time, looking for an easy solution to work with my famous OC v.1.5.6.1-2-3-4 based OpenShop v.1.7, I found this.It is the result of reading and using content from here:

http://forum.opencart.com/viewtopic.php?t=68007#p424320

For Newbies: It enables to use external Product-Links, i.E. hardcoded AD-Links on other Sites,
to directly lead to & order Products from Your Online - Shopping Cart as well as directing
the Customer to the Shopping-Cart/Checkout-Section.

It is supposed to be capable to handle Multi-Item/Multi Quantity - Orders in one step.
One may specify quantity[0]=x, quantity[1]=x, quantity[2]=x etc...as OPTION

ATTENTION: You need this [0], to be included in the href-line, even for single Product orders,
the (not yet tested by me) optinal >> quantity[NUMBER]='X' << X-Value would generate the Quantity.
If (the Option) Quantity Selection is used, this NUMBER MUST BE EQUAL to the NUMBER in the >product_id[NUMBER]< Line, i.E. product_id[0] ! In this case, quantity[NUMBER] would be quantity[0] as well. So, make sure, one could eventually screw up here.

Correct Sample href-link:

Code: Select all

http://www.ipc.li/shop/index.php?route=checkout/cart&product_id[0]=28
---

GOTO:

Code: Select all

 yourshop/catalog/controller/checkout/cart.php
FIND IN LINE 5 - 16 (in my File!!):

Code: Select all

public function index() {
		$this->language->load('checkout/cart');

		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);
			}
INSERT THIS PART:

Code: Select all

  
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');

                }
BETWEEN:

Code: Select all

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

-------------------- HERE -------------------------------

		// Update
TO MAKE IT LOOK LIKE:

Code: Select all


			$this->session->data['vouchers'] = array();
		}
          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');

                }

		// Update
Then call:

Code: Select all

http://www.yourshop.com/yourshopname/index.php?route=checkout/cart&product_id[0]=WHATEVER_PRODUCT_NUMBER
to add the Item to the Shopping Cart.

According to the Contributor, even multiple items could be ordered this way, but I did not test this. But it could be used to order Bundles, containing multiple Product Parts, as ONE order. not so bad, if it works...

Code: Select all

..... index.php?route=checkout/cart&product_id[0]=1102&product_id[1]=279&product_id[2]=121
My Test Site URL, sorry, I cannot place the line as links, since OC uses '[]' for other purposes...

Code: Select all

http://www.ipc.li/shop/index.php?route=checkout/cart&product_id[0]=28
http://www.ipc.li/shop/index.php?route=checkout/cart&product_id[0]=40
good luck, please ask me no questions here, I just tested it to see if it works. And, as it looks, it does.

Image

Ernie

---

PS. I did not check yet, if OC has any, exept for the register-requirement to enable order functions, (multiple, optional, built-in) BRAKES for this, I just hope so, exept for just removing this thing again ?... ::

BE AWARE OF::: the Fact, that anyone could EMPTY OUT and even KILL your Shop this way by adding all your Products to a nice little File, then get a script calling up those links until ALL your Products would be sold. Depending on the Mod's set in your Script, nobody could order anymore, because there would be no more Stock available.

As great as it seems to be an Idea, as bad can it turn out in Reality. We used to implement Code in order to avoid exactly this, namely, the DIRECT External LINKING to certain Sub-Sections by Outside Network Referrer IP's. This Option here is and does exactly the contrary. Depending on the attack-Speed set, either your store gets empty, or then, you'll have a massive problem with your Server-Hoster as well as your Site....

JUST to COMPLETE the Views..., I once 'got' a 500+Megabyte large Server-Log, 1 link only, no errors, created by a (former forum) Friend, it went on early morning for about 5 hours, he did not want to kill the server, just to practically make it unable for others to get Site Content..., as kind of Proof of his capabilities. Getting such an ORDER- Attack onto an OC Shop, the place would be gone. It's just a very small .exe-file...

I'm rarely active at the OC Forum lately. To reach me, contact: jti@jacob.ch
A Demoversion of my free OpenCart LIGHT v.1.5.6.5 Software Edition
can be seen in real Action here: http://www.jti.li/shop/
---
1'100+ FREE OC Extension-Repositories - from OC v.1.5.x up,
on the world's largest OC-related Github Site: https://github.com/IP-CAM
---
Image


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by NewB101 » Tue May 20, 2014 12:53 pm

@IP_CAM - Thank you very much for the explanation. I am trying to absorb your very informative post. :-)

Newbie

Posts

Joined
Mon May 19, 2014 2:45 pm
Who is online

Users browsing this forum: No registered users and 6 guests