Platform
Joomla Version - 3.4.8
Virtuemart - 3.0.12
PHP - 5.6
As the title suggests I want to make the 'Add to cart' button redirect to an external link on certain products. In other words, when a shopper clicks on the 'Add to cart' button he gets redirected to the external url. I am new to Virtuemart, can someone please help me achieve this?
Quote from: dspblack on November 19, 2016, 14:14:41 PM
Platform
Joomla Version - 3.4.8
Virtuemart - 3.0.12
PHP - 5.6
First see
http://www.theregister.co.uk/2016/11/02/hurried_crims_target_30000_sites_to_pop_unpatched_joomla/
https://developer.joomla.org/security-centre/661-20161003-core-account-modifications.html
http://thehackernews.com/2016/10/joomla-security-update.html
Check if you have new Joomla users with administrator permissions - if so hackers have paid you a visit!
And current VirtueMart release is VM3.0.18.4 - http://dev.virtuemart.net/projects/virtuemart/files - but check update on a backup copy of your site if you are using template overrides, as some updates may be required to those.
To make add-to-cart link to an external site you can simply use overrides to remove the normal add to cart form for those products, and instead include the cart link in the product description - although there are other more complicated ways to do it.
Thanks jenkinhill for the forwarning regarding the updates. I shall update the same asap.
As for overrides, I see a 'No override' option in the Products detail page field under the Product Information tab. Does it have anything to do with what you just mentioned? I'd really appreciate it if you could provide me a step by step instruction on how to do it.
https://docs.virtuemart.net/tutorials/templating-layouts/78-introduction-template-system.html
https://docs.virtuemart.net/tutorials/templating-layouts/199-sublayouts.html
Thanks for the replies. I am just a beginner and which is why I am on a CMS. Besides some knowledge about html and css, I have no clues on php. From what I understand, PHP relies heavily on variables and I've seen a couple of similar posts from 2010-12 in the forum regarding my question but the variables seem to differ with the latest version. So far I've checked the sublayouts folder and I am guessing that I need to alter or insert some codes either in addtocart.php or addtocartbar.php. Do the following lines have anything to do with what I wanted to achieve?
$addtoCartButton = '';
if(!VmConfig::get('use_as_catalog', 0)){
if($product->addToCartButton){
$addtoCartButton = $product->addToCartButton;
} else {
$addtoCartButton = shopFunctionsF::getAddToCartButton ($product->orderable);
}
}
Any help will be much appreciated.
QuoteI am just a beginner and which is why I am on a CMS
Professionals use CMS as well.. why spend hours and hours reinventing a code framework for every site?
the code snippet below is certainly not current VM code
is this from your template ( category view) ?
If so the template isn't using VM3 standards.. VM3 usings sublayouts for things like this
e.g. in cat view each product is displayed with the sublayout products.php
in that file the add to cart is shown with the sublayout
echo shopFunctionsF::renderVmSubLayout('addtocart',array('product'=>$product,'rowHeights'=>$rowsHeight[$row], 'position' => array('ontop', 'addtocart'))); ?>
it shows the -> addtocartbar.php
which shows the -> addtocartbtn.php
basically you need to clone the addtocart.php -- rename it e.g. addtocartlink.php
then do the same for the bar and link it calls and change the button to link to wherever u are storing the link to the external product (short desc?)
call your new addtocart
echo shopFunctionsF::renderVmSubLayout('addtocartlink',array('product'=>$product,'rowHeights'=>$rowsHeight[$row], 'position' => array('ontop', 'addtocart'))); ?>
Thanks GJC Web Design, your help is much appreciated.
The snippet which I provided was from a quickstart VM template, however it was taken from /components/com_virtuemart/sublayouts/addtocart.php and not from the template html. I also found the your snippet from products.php exactly the way it is.
Well I thought I understood the call functions you've just mentioned. What I do not understand is which codes to alter in the cloned files.
Here's exactly what I wanted to do, there is a URL field in the Product Information tab. If it is populated with a link, the 'Add to cart' button should redirect to that link instead of adding the product to cart. Using Firebug, I've noticed that the URL field has the variable/name 'product_url' but I couldn't find it in the corresponding files. I didn't want to bother the folks out here but I just wanted to take my chance and learn a thing or two in the process.
you can also use the product_url field
afaik it doesn't do anything at the moment.. it needs to be coded in as suggested above