Page 1 of 1
Add to cart button redirect to external link
Posted: Thu Jan 26, 2017 8:48 pm
by Steyn
Does anybody know of a free add to cart button redirect module to external link? If not, does anybody know how to manually change the link of the add to cart button on the product page? Ver 2.3.0.2
Re: Add to cart button redirect to external link
Posted: Thu Jan 26, 2017 9:25 pm
by thekrotek
What exactly are you trying to achieve? Why do you want external link?
Re: Add to cart button redirect to external link
Posted: Thu Jan 26, 2017 9:45 pm
by Steyn
as in an Affiliate link
Re: Add to cart button redirect to external link
Posted: Thu Jan 26, 2017 9:47 pm
by thekrotek
So basically you want to display products from YOUR database, but Add to Cart button should redirect customer to 3rd party site?
Re: Add to cart button redirect to external link
Posted: Thu Jan 26, 2017 9:50 pm
by Steyn
That is correct. I know there is a few good modules one can buy, but with our weak currency, that will be very expensive for me.
Re: Add to cart button redirect to external link
Posted: Thu Jan 26, 2017 9:56 pm
by thekrotek
Guess, in this case you need to have an extra field on product editing page, something like Redirect Link. You need to query this field on front-end and replace all occurrences of cart.add() functions in your template with this redirect link. It's not hard to do, but not something you can achieve without some knowledge in coding.
Re: Add to cart button redirect to external link
Posted: Thu Jan 26, 2017 9:58 pm
by Steyn
OK thank you for your reply
Re: Add to cart button redirect to external link
Posted: Fri Jan 27, 2017 2:35 am
by angela
Did this on one of the sites I'm working on:
Steyn wrote:Does anybody know of a free add to cart button redirect module to external link? If not, does anybody know how to manually change the link of the add to cart button on the product page? Ver 2.3.0.2
In line with thekrotek's suggestion (adding the field to the db, calling that field in the query returns from catalog/model/catalog/product.php & catalog/controller/product/product.php)
You can do something as easy as this in catalog/view/theme/mytheme/template/product/category.php & product.php (basically, anywhere that add to cart button shows - there's quite a few places; search engine, manufacturer pages, etc.):
Find:
Code: Select all
<button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>', '<?php echo $product['minimum']; ?>');"><span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span> <i class="fa fa-shopping-cart"></i></button>
Replace with:
Code: Select all
<?php
if ($affiliate_link) {
?>
<button type="button" onclick="location.href=('<?php echo $affiliate_link;?>');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart;?></span></button>
<?php } ?>
That way, you can have both an affiliate field and your own products loading. If $affiliate_link returns blank, it defaults to the native add to cart button.
Re: Add to cart button redirect to external link
Posted: Fri Jan 27, 2017 3:12 am
by thekrotek
angela wrote:You can do something as easy as this in catalog/view/theme/mytheme/template/product/category.php & product.php (basically, anywhere that add to cart button shows - there's quite a few places; search engine, manufacturer pages, etc.)
Files' extension is .tpl and there're also modules, don't forget them. Every module also have cart.add() function.
Re: Add to cart button redirect to external link
Posted: Fri Jan 27, 2017 4:26 am
by Steyn
Thank you Angela