1

I'm trying to build an affiliate shop using OpenCart. It is possible to add affiliate products on opencart and the user clicks the products add to cart button it'll goes to a external link in a new tab? I realy don't need a add to cart option for my entire website. I only use affiliate products.

I already change the name of the add to cart button to buy now. but just a name. Still the button function is add to cart.

How can i redirect the customers to an external link in a new tab when a user clicks buy now button.?

HDP
  • 4,005
  • 2
  • 36
  • 58
fb pass
  • 11
  • 3

2 Answers2

1

There is an option in the admin panel for affiliation, you can do this form there.

Tanmoy
  • 1,035
  • 6
  • 19
1

I found a way to add affiliate products to opencart. It may be too late for the OP, but people coming from Google may need this small tutorial. Note that the method I'm about to explain still has some flaws I couldn't get around and you should try to fix yourself. It gets the job done for me, so I might as well share it with you:

Let's start with the preparation:

  1. Make a Attributes Group called Affiliate Products(or something of your liking).
  2. Make an Attribute called Affiliate Link

Ok, now you just make a regular product with some information about it. The most important information you provide are the product title and image, because you won't ever see the description. Make sure to disable the possibility to order the product by either setting the stock to 0 or your preffered method. This part is important:

  1. Get your affliate link
  2. Add a new attribute for your product and add the Affiliate Link attribute.
  3. Paste your affiliate link in the Affiliate Link attribute
  4. Add a random option to your product (like the size or colour) This is to make the add to cart button redirect to the product page

The final part is to edit the core files of Opencart, so you may want to backup the file you're about to edit: Open the file at:/your_website_root/catalog/controller/product/product.php

At the beginning of the page, paste this code just behind index(){:

$this->load->model('catalog/product');
$attributes = $this->model_catalog_product->getProductAttributes($this->request->get['product_id']); 
if($attributes[0]['attribute'][0]['name'] = "Affiliate Link" && !empty($attributes[0]['attribute'][0]['text'])){
$affiliate =$attributes[0]['attribute'][0]['text'];
header("Location: $affiliate");
die();
}

Basically, the code looks for the attributes of the requested product. If the attribute Affiliate Link is available and not empty, the webpage will be redirected to the affiliate link in the Affiliate Link attribute. If not, the product page will be shown normally.

Your Affiliate Link attribute must always be the first attribute in the list, otherwise the code won't work!

I hope this helps you. I would like to here someone improve the code if they can!

Flaws:

  • The Redirect is not SEO friendly
  • The Affiliate Link will be shown in the comparison table
  • It does not open in a new window