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

  • Posts: 1
  • Thank you received: 0
10 years 2 months ago #191459

-- HikaShop version -- : Latest Version

Hi

I am looking to add showcasing of affiliate marketing products to a site and considering Hikashop.
Similar to drop shipping, we list items from varies vendors BUT we only list items and send the visitor to the original vendor using the affiliate link (ie amazon).

Therefore, we need to
1) Replace "Add to Cart" to "Buy it Now" (ok this is just change of language and easy).
2) This button should use the url (brand url!?) link to open a new window.

Is this possible? For both, category and product listings?


Perhaps, it would be easier using a CCK! but I want full power of a shopping cart (specialty import/export to use the vendors data feed)
Thank you :)

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

  • Posts: 13201
  • Thank you received: 2322
10 years 2 months ago #191461

Hi,

Yes it is indeed possible, it will just require the edition of the view "product / quantity" and "product / add_to_cart_listing".
In these views, replace the button, by a custom one getting the link from the value $this->row->product_url; (or $this->element->product_url) and fill the Url field in the product edition page.

To rename it, as you said it is juste a translation override.

The following user(s) said Thank You: seahika

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

  • Posts: 36
  • Thank you received: 0
10 years 2 months ago #193689

hello Xavier.

I am also looking for the same thing. Use hikashop for affiliates.

So as I would also like to change the add to cart by buy it now for each item id go to each different url affiliates.

Would you mind to give me the entire little piece of php code in order to implement it?

I would need exact code for:

product / quantity" and "product / add_to_cart_listing I guess, as far as you said.

and also the exact code for:

replace the button, by a custom one getting the link from the value $this->row->product_url; (or $this->element->product_url) and fill the Url field in the product edition page

Honored Xavier

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

  • Posts: 83766
  • Thank you received: 13555
  • MODERATOR
10 years 2 months ago #193720

Hi,

It's basic HTML, javascript and PHP, like that:

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

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

  • Posts: 36
  • Thank you received: 0
10 years 2 months ago #193983

Hello dear,

Shall I change any piece of code inside
product / quantity" and "product / add_to_cart_listing ?

May you kindly give me an example code for demo affiliates?

So by the way, what happens if I have 100 products ids and I want each different product to go a one different affiliates url?

I guess that I shall implement 100 different codes, one by one, depending on the product ID. Is that right?

Can you kindly provide me a demo url to go? This code is not complete for that my dear.
<input type="button" onclick="window.location='<?php echo $this->row->product_url; ?>'; return false;" value="buy now"/>


Honored

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

  • Posts: 36
  • Thank you received: 0
10 years 2 months ago #193992

:(

Last edit: 10 years 1 month ago by BloodyBakala.

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

  • Posts: 83766
  • Thank you received: 13555
  • MODERATOR
10 years 2 months ago #194028

Hi,

The code is complete.
Just add it to the view and you should see a new button appear that you can click on and which will redirect you to the URL that your entered in the "URL" field of each product.
So there is no need for a different code for each product. You however need to configure the redirection URL in each product.

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

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

1. Appologies but I am totally null in php and just learning it so I do now know how to do it.

I am attaching you the complete piece of code for add_to_cart_listing.php
I guess that is the same accesible from www\your_site\components\com_hikashop\views\product\tmpl

And also i do not know what do you stand for :
You however need to configure the redirection URL in each product.

2.you can check your piece of code at the end, where the input buttons are. Shall I also include it on product / quantity.php?

so somewhere should I include the affiliates urls, deppending on different product IDS.

Sorry for my ignorance. please check code inside add_to_cart_listing.php

*****

<?php
/**
 * @package	HikaShop for Joomla!
 * @version	2.3.5
 * @author	hikashop.com
 * @copyright	(C) 2010-2015 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php if ($this->config->get('show_quantity_field')<2) { ?>
	<form action="<?php echo hikashop_completeLink('product&task=updatecart'); ?>" method="post" name="hikashop_product_form_<?php echo $this->row->product_id.'_'.$this->params->get('main_div_name'); ?>" enctype="multipart/form-data">
<?php }

if(empty($this->row->has_options) && ($this->row->product_quantity==-1 || $this->row->product_quantity>0)&& !$this->config->get('catalogue') && ($this->config->get('display_add_to_cart_for_free_products') || !empty($this->row->prices))){
	$itemFields = $this->fieldsClass->getFields('frontcomp',$this->row,'item','checkout&task=state');
	if(!empty($itemFields) && !$this->params->get('display_custom_item_fields',0)){
		$this->row->has_options = true;
		$itemFields = array();
	}
	$null=array();
	$this->fieldsClass->addJS($null,$null,$null);
	$this->fieldsClass->jsToggle($itemFields,$this->row,0);
	$extraFields = array('item'=>&$itemFields);
	$requiredFields = array();
	$validMessages = array();
	$values = array('item'=>$this->row);
	$this->fieldsClass->checkFieldsForJS($extraFields,$requiredFields,$validMessages,$values);
	$this->fieldsClass->addJS($requiredFields,$validMessages,array('item'));

	if($this->params->get('display_custom_item_fields',0) && !empty($itemFields)){
	 ?>
	<!-- CUSTOM ITEM FIELDS -->
	<div id="hikashop_product_custom_item_info_for_product_<?php echo $this->row->product_id; ?>" class="hikashop_product_custom_item_info hikashop_product_listing_custom_item">
		<table class="hikashop_product_custom_item_info_table hikashop_product_listing_custom_item_table" width="100%">
		<?php
		foreach($itemFields as $fieldName => $oneExtraField) {
			$itemData = JRequest::getString('item_data_'.$fieldName,$this->row->$fieldName);  ?>
			<tr id="hikashop_item_<?php echo $oneExtraField->field_namekey; ?>" class="hikashop_item_<?php echo $oneExtraField->field_namekey;?>_line">
				<td class="key">
					<span id="hikashop_product_custom_item_name_<?php echo $oneExtraField->field_id;?>_for_product_<?php echo $this->row->product_id; ?>" class="hikashop_product_custom_item_name">
						<?php echo $this->fieldsClass->getFieldName($oneExtraField);?>
					</span>
				</td>
				<td>
					<span id="hikashop_product_custom_item_value_<?php echo $oneExtraField->field_id;?>_for_product_<?php echo $this->row->product_id; ?>" class="hikashop_product_custom_item_value"><?php
						$onWhat='onchange';
						if($oneExtraField->field_type=='radio')
							$onWhat = 'onclick';
						$oneExtraField->product_id = $this->row->product_id;
						$this->fieldsClass->prefix = 'product_'.$this->row->product_id.'_';
						echo $this->fieldsClass->display(
							$oneExtraField,
							$itemData,
							'data[item]['.$oneExtraField->field_namekey.']',
							false,
							' '.$onWhat.'="if (\'function\' == typeof window.hikashopToggleFields) { hikashopToggleFields(this.value,\''.$fieldName.'\',\'item\',0); }"'
						);
					?></span>
				</td>
			</tr>
		<?php }
		$this->fieldsClass->prefix=''; ?>
		</table>
	</div>
	<!-- EO CUSTOM ITEM FIELDS -->
<?php }
}

if ($this->config->get('show_quantity_field')<2) {
		$module_id = $this->params->get('from_module',0);

		$this->formName = ',\'hikashop_product_form_'.$this->row->product_id.'_'.$this->params->get('main_div_name').'\'';
		$this->ajax='';
		if(!$this->config->get('ajax_add_to_cart',0)||!empty($itemFields)){
			$this->ajax = 'if(hikashopCheckChangeForm(\'item\',\'hikashop_product_form_'.$this->row->product_id.'_'.$this->params->get('main_div_name').'\')){ return hikashopModifyQuantity(\''.$this->row->product_id.'\',field,1,\'hikashop_product_form_'.$this->row->product_id.'_'.$this->params->get('main_div_name').'\',\'cart\','.$module_id.'); } return false;';
		}
		$this->setLayout('quantity');
		echo $this->loadTemplate();
		if(!empty($this->ajax) && $this->config->get('redirect_url_after_add_cart','stay_if_cart')=='ask_user'){ ?>
			<input type="hidden" name="popup" value="1"/>
		<?php } ?>
		<input type="button" onclick="window.location='<?php echo $this->row->product_url; ?>'; return false;" value="buy now"/>
		<input type="hidden" name="hikashop_cart_type_<?php echo $this->row->product_id.'_'.$module_id; ?>" id="hikashop_cart_type_<?php echo $this->row->product_id.'_'.$module_id; ?>" value="cart"/>
		<input type="hidden" name="product_id" value="<?php echo $this->row->product_id; ?>" />
		<input type="hidden" name="module_id" value="<?php echo $module_id; ?>" />
		<input type="hidden" name="add" value="1"/>
		<input type="hidden" name="ctrl" value="product"/>
		<input type="hidden" name="task" value="updatecart"/>
		<input type="hidden" name="return_url" value="<?php echo urlencode(base64_encode(urldecode($this->redirect_url)));?>"/>
	</form>
<?php }elseif(empty($this->row->has_options)&& !$this->config->get('catalogue') && ($this->config->get('display_add_to_cart_for_free_products') || !empty($this->row->prices))){
	if($this->row->product_quantity==-1 || $this->row->product_quantity>0){ ?>
		<input id="hikashop_listing_quantity_<?php echo $this->row->product_id;?>" type="text" style="width:40px;" name="data[<?php echo $this->row->product_id;?>]" class="hikashop_listing_quantity_field" value="0" />
	<?php }else{
		echo JText::_('NO_STOCK');
	}
} ?>

Last edit: 10 years 1 month ago by Xavier. Reason: Use of [code]...[/code] tags

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

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

Hi,

There is no need to know PHP or HTML. Copy/paste the code I gave you at the top or at the end of the view files and you'll see the button where the view is used.
The only thing left to do then is to enter the URL where you want the customer to go in the "URL" field of the product edition page.

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

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

Hello back my dear,

I am still trying this piece of code but nothing happens.

By the way, when adding this piece of code you sent me here, only appears the button buy now, when on clicking nothing happens, because you did ot sent me the example piece of code for outside urls deppending on different products.

For example for product1 I want to go to www.amazon/1
product2 go to www.ebay.com/2

Shall I create a table or something inside sql? Do I need to add any other .php somewhere?

And last question, how to delete the add to cart and start using the new button? What about using the same add to cart button? would be even better, and when clicking on it, deppending on the product, it shall go to a different external url, instead to:
<form action="<?php echo hikashop_completeLink('product&task=updatecart'); ?>

I have attached a picture and sent you the url by private.


Thanks

Attachments:
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 #195306

Honored for your answer. i am waiting for your answer dear team. nicolas, Xavier and Jerome.

Last edit: 10 years 1 month ago by BloodyBakala.

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

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

Hi,

I already sent you the example piece of code for outside URLs depending on different products !
As I already said, use that code:
<input type="button" onclick="window.location='<?php echo $this->row->product_url; ?>'; return false;" value="buy now"/>
and in each product edition page, enter the URL that you want for the buy now button in the "URL" field.

I'm sorry but it's already three times I told you what to do... I can't tell you more than what I already told you since that's the solution. There is no need to create a table, or do something in SQL, or add any other php. Just follow what I say and that's it.

If you want to have a specific styling on the button, that's possible. Just add custom CSS code for that.
www.hikashop.com/support/support/documen...ize-the-display.html
And if you don't want the add to cart buttons, just turn off the "Display add to cart buttons" option of your menu via the menu Display>Content menus.

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

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

Hello,

Apologies for my previous answers, but I am not familiar with advanced php for objects.

Regarding your answer, when including www.amazon.com for example inside the URL field , the URLS now displayes at the end of the page product as Brand URL, but the bottom is not created inside the product page, at the same position where add to cart was.

The buttom was created for categories, but from there when clicking on it, nothing happens.

I am sending you the website with your administrator URL and password, so as you can freely check.
I am also including a screenshot.

Honored dear

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

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

Hi,

That's totally normal. Your questions didn't mention the product page, only the listings.
If you want that button for both the product page and the listings, then instead of adding the custom code in the add_to_cart_listing view file, you should add it in the quantity view file and remove the line below which displays the normal add to cart:
echo $this->cart->displayButton(JText::_('ADD_TO_CART'), 'add', $this->params, $url, $this->ajax, '', $max, $min);

And to remove the "brand url" link from the product page, you can add such CSS on your frontend CSS file:
#hikashop_product_url_main{ display: none; }

www.hikashop.com/support/support/documen...ize-the-display.html

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 #195501

I think I will love you.

I will try later and I will inform you. You rock

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

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

Dear brother,

I have followed your steps, and it gives me a big Parse error: syntax error, unexpected '<' in /html/com_hikashop/product/quantity.php on line 94

exactly that line, where I included the
<input type="button" onclick="window.location='<?php echo $this->row->product_url; ?>'; return false;" value="buy now"/>

in quantity.php

after deleting on that line 94:

echo $this->cart->displayButton(JText::_('ADD_TO_CART'), 'add', $this->params, $url, $this->ajax, '', $max, $min);


also deleted

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

on add_to_cart_listing.php

I am sending you the private credentials to access. you can freely touch everything because is offline. I created a supper user for you.

Just inform me here after changes. Maybe also other people would be interested on the answer.

Check the private message I have sent you here. Thank you

P.S.

Would be easier if someone might directly change, edit and save changes o add to cart HTML link, on each product, but there is no option to save.

Attachments:

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

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

Did you receive my private message with details¿?

Cheers

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

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

Hi,

There was an error because the code used is HTML code and not PHP, so you have to close the php tag before and re-open it after, like that:

				?>
				<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);

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

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

Dear brother,

FInally after 2 weeks, we almost ended up with the solution.

i have seen that you actually included the code above to quantity.phpwith the credentials I sent you by private, ok great, now the button appears on all articles (not in categories), but.. when editing one product article and including the URL on the URL field, the url only appears below, by brand URL and not by clicking that buttons.

May you kindly check it? you have full access by the private credentials to the microniche.

2. And also... how might we include the rel = no follow on that php urls?

Honored, and luckily finishing today with this topic :)

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

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

Any final answer? Thanks

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

Time to create page: 0.108 seconds
Powered by Kunena Forum