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:
- Make a Attributes Group called Affiliate Products(or something of
your liking).
- 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:
- Get your affliate link
- Add a new attribute for your product and add the Affiliate Link attribute.
- Paste your affiliate link in the Affiliate Link attribute
- 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