Converting "Add to Cart" to link to an outside URL

  • Posts: 36
  • Thank you received: 0
10 years 1 month ago #196096

Waiting for your kindly answer, hopefully to finish this topic

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
10 years 1 month ago #196110

Hi,

I just tried on your website and it is working pretty fine.
On the product with the id "91" I set an "Url" in the "Url" option of the product edition page, and then on the product page the link was indeed added on the button for the redirect.

So no problem this side, but it seems that the "onclick" are replaced by "on-click", so I think it is an issue related with your text editor, please check its settings else the onclick will be replaced and will not work as expected.

Regarding the product listing, there is an override coming from your template, this override don't use our view "product / quantity" so that's why you don't have the external url on these buttons, please contact your template provider for this part.

Please Log in or Create an account to join the conversation.

  • Posts: 36
  • Thank you received: 0
10 years 1 month ago #196947

Hello Xavier and Nicolas,

When you put the url and the url field, an url appers at bootom of the page as branded URL, but nothing by clicking on the button.

What do you mean by onclick? Text editor is JCE, but it should not interfere in anything, because the url field is outside from the editor. That's right that when I try to click nothing appeans. It does not even show the url destination. How to change it?

Still same password if you want to check.

And how to include the rel=nofollow for the url field? or directly installing a plugin for all external urls to do = no follow?


Thanks

Last edit: 10 years 1 month ago by BloodyBakala.

Please Log in or Create an account to join the conversation.

  • Posts: 36
  • Thank you received: 0
10 years 1 month ago #196971

Hello back,

It seems that iframes get stripped. Maybe for RSfirewall.

I added the exceptions on rsfirewall, but I went crazy, so i directly deinstalled it.
Even global configuration editor changed to tinymce or codemirror.

Any idea about the changes for on-click instead of onclick?

the url button does not work by that.

Please Log in or Create an account to join the conversation.

  • Posts: 83766
  • Thank you received: 13555
  • MODERATOR
10 years 1 month ago #196986

Hi,

1. Add such CSS on your website and you won't get that "brand URL":
#hikashop_product_url_main{ display: none; }

2. Here is a plugin which can all you to do that:
extensions.joomla.org/profile/extension/...data/noexternallinks

Please Log in or Create an account to join the conversation.

  • Posts: 36
  • Thank you received: 0
10 years 1 month ago #197022

Yes brother, i know, but how to change the stripped iframes?

the link shows on-click instead of onclick.

went crazy and deleted rsfirewall and changed all editors in global config. any idea? with that we can finally close the topic. yeah!
I owe you both one product:)

Please Log in or Create an account to join the conversation.

  • Posts: 83766
  • Thank you received: 13555
  • MODERATOR
10 years 1 month ago #197056

The onclick is changed to on-click either by a system plugin or your Joomla template.
Try to disable them one by one until you don't have the change in the HTML and you'll find the culprit that you can either disable or fix (with the help of the developer of that extension of course).

The following user(s) said Thank You: BloodyBakala

Please Log in or Create an account to join the conversation.

  • Posts: 36
  • Thank you received: 0
10 years 1 month ago #197633

The custom php was stripped on quantity.php because of stupid rsfirewall, so i totally deinstalled that crappy component.

ID 91 is working correct now for external url amazon.com but not for urls for other items. i guess this is caused mainly by upgrading to joomla 3.4.1.

when I try to add new urls for other products, ir gives me a fattal error, because it tries to go to my url/externalurl
*****
Fatal error: Uncaught exception 'RuntimeException' with message 'Unknown column 'header' in 'field list' SQL=SELECT `new_url`,`header`,`published` FROM _redirect_links` WHERE `old_url` = '/www.amazon.com' LIMIT 0, 1' in /libraries/joomla/database/driver/mysqli.php:610 Stack trace: #0 /libraries/joomla/database/driver.php(1239): JDatabaseDriverMysqli->execute() #1 /plugins/system/redirect/redirect.php(86): JDatabaseDriver->loadObject() #2 [internal function]: PlgSystemRedirect::handleError(Object(RuntimeException)) #3 {main} thrown in libraries/joomla/database/driver/mysqli.php on line 610

*****

I am seeing a lot of websites with the same error on internet. Also check this:

issues.joomla.org/tracker/joomla-cms/6333

any solution? thanks

Last edit: 10 years 1 month ago by BloodyBakala.

Please Log in or Create an account to join the conversation.

  • Posts: 36
  • Thank you received: 0
10 years 1 month ago #197659

my error, because I did not add http:// on the url field , lol, anyways, it gives a massive crash for the new joomla 3.4.1. when adding http: for the url field, everything ok..

New little things:
1. When quantity =0 the button buy now directly disappears, but would be better to appear something like Out of Stock.
How to appear as out of stock for quantity.php when quantity= 0?

2. How to include the same code instead of for quantity.php for a module? In this case the module is SJ Listing Tabs for Hikashop. Unfortunately SmartAddons have it out of date. Although it is working with Hikashop, is literally out of date.

Would be great to insert the same code, so as it would appear on that module on index.php module, meanwhile I will find another great module like that one working for hikashop. Would you also recommend anyone?

Honored

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
10 years 1 month ago #197691

Hi,

1. By default the string "No stock" should be displayed, so I think that you have edited the view "product / quantity" or added a translation override on the key "NO_STOCK".

2. I don't know how the SJ Listing Tabs module is getting the informations from HikaShop, if it don't use our views, you have to edit it directly in the "modules" folder of your Joomla directory.

Please Log in or Create an account to join the conversation.

  • Posts: 36
  • Thank you received: 0
10 years 3 weeks ago #198656

all right.
sj HK listing tabs is the only one working for this shitty template. unfortunately gk5 is not working on my template.

There you have how sj hk listing tabs gets the code:

<div class="ltabs-item new-ltabs-item">
<div class="item-inner">
<?php
$condition = (int)$params->get('display_votes', 1) || (int)$params->get('display_add_to_cart', 1) || (int)$params->get('display_add_to_wishlist', 1);


how can I include the code you gave me there? by deleting (int)$params->get('display_add_to_cart', 1) || ?

Shall I included directly there our code?:

?>
<input type="button" onclick="window.location='<?php echo $this->row->product_url; ?>'; return false;" value="buy now"/>
<?php
//echo $this->cart->displayButton(JText::_('ADD_TO_CART'), 'add', $this->params, $url, $this->ajax, '', $max, $min);



I almost have it. at line 107:

if ((int)$params->get('display_add_to_cart', 1) || (int)$params->get('display_add_to_wishlist', 1)) {
?>
<div class="acd-btn-add">
<?php echo $btn_add; ?>
</div>
<?php

I tried to change the div class by our code, but still does not work .I have also attached full code of default_items.php of module sj hk listing, very simple it seems, but I do not know where to include our code and delete the add to cart. I am still learning php. cheers

Attachments:
Last edit: 10 years 3 weeks ago by BloodyBakala.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
10 years 3 weeks ago #198673

Hi,

$btn_add don't seems to be defined, but I think that you have to replace:

<?php echo $btn_add; ?>
By our code, but with few modification like:
<input type="button" onclick="window.location='<?php echo $item->product_url; ?>'; return false;" value="buy now"/>

We recommend to contact directly the team who create that listing :)

The following user(s) said Thank You: BloodyBakala

Please Log in or Create an account to join the conversation.

  • Posts: 36
  • Thank you received: 0
10 years 3 weeks ago #199260

Hello brother,

Of course everything is working after adding the custom input type button as here stated in quantityty.php. Everything working but just noticed that when trying to put stock 0, the button dissapears, and when trying to put stock 4 for example, again the add to cart appears.

Button only works when unlimited, which is good, but would be great when out of stock to display the noñ-stock display on quantity.php and also display stocks like 3 4 7...

here I state again the working quantity.php code:
***************

<?php
/**
* @package HikaShop for Joomla!
* @version 2.3.0
* @author hikashop.com
* @copyright (C) 2010-2014 HIKARI SOFTWARE. All rights reserved.
* @license GNU/GPLv3 www.gnu.org/licenses/gpl-3.0.html
*/
defined('_JEXEC') or die('Restricted access');
?><?php

if($this->config->get('show_quantity_field')==-2){
$this->params->set('show_quantity_field',$this->row->product_display_quantity_field);
}

$config =& hikashop_config();

$wishlistEnabled = $config->get('enable_wishlist', 1);
$hideForGuest = 1;
if(($config->get('hide_wishlist_guest', 1) && hikashop_loadUser() != null) || !$config->get('hide_wishlist_guest', 1)){
$hideForGuest = 0;
}

if(!isset($this->cart)) $this->cart = hikashop_get('helper.cart');
if(!empty($this->row->has_options)){
if($this->params->get('add_to_cart',1)) echo $this->cart->displayButton(JText::_('CHOOSE_OPTIONS'),'choose_options',$this->params,hikashop_completeLink('product&task=show&product_id='.$this->row->product_id.'&name='.$this->row->alias.$this->itemid.$this->category_pathway),'window.location = \''.str_replace("'","\'",hikashop_completeLink('product&task=show&product_id='.$this->row->product_id.'&name='.$this->row->alias.$this->itemid.$this->category_pathway)).'\';return false;','');
}else{
$this->cart = hikashop_get('helper.cart');
$url = '';
$module_id = $this->params->get('from_module',0);
if(empty($this->ajax)){
$this->ajax = 'return hikashopModifyQuantity(\''.$this->row->product_id.'\',field,1,0,\'cart\','.$module_id.')';
}
if(@$this->row->product_sale_start || empty($this->element->main)){
$start_date = @$this->row->product_sale_start;
}else{
$start_date = $this->element->main->product_sale_start;
}
if(@$this->row->product_sale_end || empty($this->element->main)){
$end_date = @$this->row->product_sale_end;
}else{
$end_date = $this->element->main->product_sale_end;
}
$formName = ',0';
if (!$this->config->get('ajax_add_to_cart', 0) || ($this->config->get('show_quantity_field')>=2 && !@$this->element->product_id)) {
if(empty($this->formName)) {
if(@$this->row->product_id)
$formName = ',\'hikashop_product_form_'.$this->row->product_id.'_'.$this->params->get('main_div_name').'\'';
else
$formName = ',\'hikashop_product_form_'.$this->params->get('main_div_name').'\'';
} else {
$formName = $this->formName;
}
}
if($end_date && $end_date<time()){
?>
<span class="hikashop_product_sale_end">
<?php echo JText::_('ITEM_NOT_SOLD_ANYMORE'); ?>
</span>
<?php
}elseif($start_date && $start_date>time()){
?>
<span class="hikashop_product_sale_start">
<?php
echo JText::sprintf('ITEM_SOLD_ON_DATE',hikashop_getDate($start_date,$this->params->get('date_format','%d %B %Y')));
?>
</span>
<?php
}elseif(!$this->params->get('catalogue') && ($this->config->get('display_add_to_cart_for_free_products') || !empty($this->row->prices))){
if(@$this->row->product_min_per_order || empty($this->element->main)){
$min = @$this->row->product_min_per_order;
}else{
$min = @$this->element->main->product_min_per_order;
}
if(@$this->row->product_max_per_order || empty($this->element->main)){
$max = @$this->row->product_max_per_order;
}else{
$max = @$this->element->main->product_max_per_order;
}
if($min<=0){
$min=1;
}
$wishlistAjax = 'if(hikashopCheckChangeForm(\'item\''.$formName.')){ return hikashopModifyQuantity(\'' . (int)@$this->row->product_id . '\',field,1' . $formName . ',\'wishlist\','.$module_id.'); } else { return false; }';

if($this->row->product_quantity == -1 && !empty($this->element->main) && $this->element->main->product_quantity != -1){
$this->row->product_quantity = $this->element->main->product_quantity;
}
$btnType = 'add';
if($this->row->product_quantity==-1){
?>
<div class="hikashop_product_stock">
<?php
if($this->params->get('add_to_cart',1)){
?>
<input type="button" class="button btn" onClick="window.location='<?php echo $this->row->product_url; ?>'; return false;" value="comprar"/>
<?php
//echo $this->cart->displayButton(JText::_('ADD_TO_CART'), 'add', $this->params, $url, $this->ajax, '', $max, $min);
$btnType = 'wish';
}
if(hikashop_level(1) && $this->params->get('add_to_wishlist') && $wishlistEnabled && !$hideForGuest && $this->config->get('display_add_to_wishlist_for_free_products','1')){
echo '<div id="hikashop_add_wishlist">';
echo $this->cart->displayButton(JText::_('ADD_TO_WISHLIST'),$btnType,$this->params,$url,$wishlistAjax,'',$max,$min,'',false);
echo '</div>';
}
}elseif($this->row->product_quantity>0){
?>
<div class="hikashop_product_stock">
<?php
if($config->get('button_style','normal')=='css'){
echo '<br />';
}
if($max<=0 || $max>$this->row->product_quantity) $max = $this->row->product_quantity;
if($this->params->get('add_to_cart',1)){
echo $this->cart->displayButton(JText::_('ADD_TO_CART'),'add',$this->params,$url,$this->ajax,'',$max,$min);
$btnType = 'wish';
}
if(hikashop_level(1) && $this->params->get('add_to_wishlist') && $wishlistEnabled && !$hideForGuest && $this->config->get('display_add_to_wishlist_for_free_products','1')){
echo '<div id="hikashop_add_wishlist">';
echo $this->cart->displayButton(JText::_('ADD_TO_WISHLIST'),$btnType,$this->params,$url,$wishlistAjax,'',$max,$min,'',false);
echo '</div>';
}
}else{
?>
<div class="hikashop_product_no_stock">
<?php
$waitlist = $this->config->get('product_waitlist',0);
if(hikashop_level(1) && ($waitlist==2 || ($waitlist==1 && (!empty($this->element->main->product_waitlist) || !empty($this->element->product_waitlist))))){ ?>
</div><div id="hikashop_product_waitlist_main" class="hikashop_product_waitlist_main">
<?php
$empty='';
jimport('joomla.html.parameter');
$params = new HikaParameter($empty);
echo $this->cart->displayButton(JText::_('ADD_ME_WAITLIST'),'add_waitlist',$params,hikashop_completeLink('product&task=waitlist&cid='.$this->row->product_id),'window.location=\''.str_replace("'","\'",hikashop_completeLink('product&task=waitlist&cid='.$this->row->product_id)).'\';return false;');
}
if(hikashop_level(1) && $this->params->get('add_to_wishlist') && $wishlistEnabled && !$hideForGuest && $this->config->get('display_add_to_wishlist_for_free_products','1')){
echo '<div id="hikashop_add_wishlist">';
echo $this->cart->displayButton(JText::_('ADD_TO_WISHLIST'),'add',$this->params,$url,$wishlistAjax,'',@$this->row->product_max_per_order,1,'',false);
echo '</div>';
}
}?>
</div>
<?php
}elseif(hikashop_level(1) && $wishlistEnabled && $this->params->get('add_to_wishlist','1') && $this->config->get('display_add_to_wishlist_for_free_products','1') && !$hideForGuest && !$this->config->get('display_add_to_cart_for_free_products')){
$wishlistAjax = 'if(hikashopCheckChangeForm(\'item\''.$formName.')){ return hikashopModifyQuantity(\'' . (int)@$this->row->product_id . '\',field,1' . $formName . ',\'wishlist\','.$module_id.'); } else { return false; }';
echo '<div id="hikashop_add_wishlist">';
echo $this->cart->displayButton(JText::_('ADD_TO_WISHLIST'),'add',$this->params,$url,$wishlistAjax,'',@$this->row->product_max_per_order,1,'',false);
echo '</div>';
}
}

Last edit: 10 years 2 weeks ago by Xavier.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
10 years 2 weeks ago #199266

Hi,

To add the "No stock" text you have to add the code:

echo JText::_('NO_STOCK').'<br/>';
After:
	<div class="hikashop_product_no_stock">
<?php

To display the stock, you have yo add:
		if($this->row->product_quantity == 1 && JText::_('X_ITEM_IN_STOCK') != 'X_ITEM_IN_STOCK')
			$text = JText::sprintf('X_ITEM_IN_STOCK', $this->row->product_quantity);
		else
			$text = JText::sprintf('X_ITEMS_IN_STOCK', $this->row->product_quantity);
after:
	<div class="hikashop_product_stock">
<?php

As in the original quantity file ;)

The following user(s) said Thank You: BloodyBakala

Please Log in or Create an account to join the conversation.

  • Posts: 344
  • Thank you received: 3
8 years 3 months ago #260976

Hikashop 3
Joomla 3.6.5

So iv'e used your code (below) and created a "buy now" button that links to external products (when I fill out brand url)

<input type="button" onclick="window.location='<?php echo $this->row->product_url; ?>'; return false;" value="buy now"/>

I placed it in the file product | quantity and it works perfect.

Anyway I have a question:

Is it possible to use php code to create a function that hide's the native "add to cart" button on the product page when the "brand URL" of the product is filled out ?

Would it be something like this
if($this->row->hikashop_product_url_main == 1)
{
$this->row->addtocartoption = 0;
}

?

Last edit: 8 years 3 months ago by river.

Please Log in or Create an account to join the conversation.

  • Posts: 26232
  • Thank you received: 4035
  • MODERATOR
8 years 3 months ago #260978

Hi,

That thread is almost two years old...
Thanks to HikaShop 3 ; there is a new way to add products in the cart. I think it will be better to open a new thread if you have question about it.
www.hikashop.com/blog/367-hikashop-3-0-out.html#cart

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

Time to create page: 0.105 seconds
Powered by Kunena Forum