Override cart.php at the admin level

  • Posts: 57
  • Thank you received: 5
10 years 10 months ago #138000

Hi Hika team,

I am working on the product views of hikashop and I would like to remove the table layout that is used for the quantity field, + and - buttons and the add to cart button.

The file that I need to edit is located at administrator/com_hikashop/helpers/cart.php. I want to modify this bit

<table>
<tr>
<td rowspan="2">
<input id="hikashop_product_quantity_field_'.$i.'" type="text" value="'.JRequest::getInt('quantity',$min_quantity).'" class="hikashop_product_quantity_field" name="quantity" onchange="hikashopCheckQuantityChange(\'hikashop_product_quantity_field_'.$i.'\','.$max_quantity.','.$min_quantity.');" />
</td>

<td>
<a id="hikashop_product_quantity_field_change_plus_'.$i.'" class="hikashop_product_quantity_field_change_plus hikashop_product_quantity_field_change" href="#" onclick="return hikashopQuantityChange(\'hikashop_product_quantity_field_'.$i.'\',1,'.$max_quantity.','.$min_quantity.');">+</a>

</td>
<td rowspan="2">
'.$html.'
</td>
</tr>

<tr>
<td>
<a id="hikashop_product_quantity_field_change_minus_'.$i.'" class="hikashop_product_quantity_field_change_minus hikashop_product_quantity_field_change" href="#" onclick="return hikashopQuantityChange(\'hikashop_product_quantity_field_'.$i.'\',0,'.$max_quantity.','.$min_quantity.');">&ndash;</a>
</td>
</tr>
</table>

I have not found a way on how to override this file.

Is it possible to override it at all?

Kind regards,

Drago.

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

  • Posts: 82906
  • Thank you received: 13378
  • MODERATOR
10 years 10 months ago #138004

Hi,

Yes it's possible with a template override as explained in our developer documentation:
www.hikashop.com/support/documentation/6...tation.html#override

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

  • Posts: 57
  • Thank you received: 5
10 years 9 months ago #144173

Hi Nicolas,

Is it possible to guide by the hand a bit, since my php knowledge = 0?

I read through every line of the cart.php and although I have no php knowledge, it somehow makes sense. I can see where the conditions for the overrides are and with some trial and error I managed to achieve my desired layout override (no tables). However the add to cart button is missing. I see quantity field, plus sign, minus sign, no add to cart.

The $html variable will contain the HTML of the "add to cart" button


I know I have to do something with this.

My head scratch moment is that I actually don't want to do anything with the add to cart button, It is fine as it is in its original state.

Here is how my hikashop_button.php looks like at the moment. How do I add my "add to cart" button in all of this?
<?php
/**
 * @package	HikaShop for Joomla!
 * @version	2.2.2
 * @author	hikashop.com
 * @copyright	(C) 2010-2013 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?>

<?php
function hikashop_quantity_render($html,$i,$max_quantity,$min_quantity){
	$override ='
	<div>
		<div>
			<div>
				<input id="hikashop_product_quantity_field_'.$i.'" type="text" value="'.JRequest::getInt('quantity',$min_quantity).'" class="hikashop_product_quantity_field" name="quantity" onchange="hikashopCheckQuantityChange(\'hikashop_product_quantity_field_'.$i.'\','.$max_quantity.','.$min_quantity.');" />
			</div>	
			
			<div class="hika_incr_decr">
				<a id="hikashop_product_quantity_field_change_plus_'.$i.'" class="hikashop_product_quantity_field_change_plus hikashop_product_quantity_field_change" href="#" onclick="return hikashopQuantityChange(\'hikashop_product_quantity_field_'.$i.'\',1,'.$max_quantity.','.$min_quantity.');">+</a>
			</div>

			<div class="hika_incr_decr">
				<a id="hikashop_product_quantity_field_change_minus_'.$i.'" class="hikashop_product_quantity_field_change_minus hikashop_product_quantity_field_change" href="#" onclick="return hikashopQuantityChange(\'hikashop_product_quantity_field_'.$i.'\',0,'.$max_quantity.','.$min_quantity.');">&ndash;</a>
			</div>
			
		</div>
	</div>
			'
	;
	return $override;
	}
	
	
?>

Kind regards,

Drago.

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

  • Posts: 82906
  • Thank you received: 13378
  • MODERATOR
10 years 9 months ago #144215

The add to cart button is in the $html variable. You need to insert it where you want it in your $override variable and you'll see it.

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

  • Posts: 57
  • Thank you received: 5
10 years 9 months ago #144256

Thanks, I have it the way I want it now.

Just to reiterate for anybody else:

$html = add to cart button.

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

  • Posts: 57
  • Thank you received: 4
9 years 8 months ago #194320

Hi, I'm sorry but i don't understood.

For example, in my case I wan't to Increment and decrement not 1 by 1 but the value of the minimum_value_per_order.

I know that I what I want I can find in:
./administrator/components/com_hikashop/helpers/cart.php in to different lines (94 and 154).
There I have this:

function hikashopQuantityChange(field,plus,max,min){
    var fieldEl=document.getElementById(field);
    var current = fieldEl.value;
    current = parseInt(current);
    if(plus){
        if(max==0 || current<max){
            fieldEl.value=parseInt(fieldEl.value)+1;
        }else if(max && current==max){
            alert(\''.JText::_('NOT_ENOUGH_STOCK',true).'\n'.JText::_('NOT_ENOUGH_STOCK_AUTO_UPDATE',true).'\'+max);
        }
    }else{
        if(current>1 && current>min){
            fieldEl.value=current-1;
        }
    }
    return false;
}

function hikashopCheckQuantityChange(field,max,min){
    var fieldEl=document.getElementById(field);
    var current = fieldEl.value;
    current = parseInt(current);
    if(max && current>max){
        fieldEl.value=max;
	alert(\''.JText::_('NOT_ENOUGH_STOCK',true).'\n'.JText::_('NOT_ENOUGH_STOCK_AUTO_UPDATE',true).'\'+max);
    }else if(current<min){
        fieldEl.value=min;
    }
    return false;					}

There if I change on the line 100 the value from 1 to 50 for example, this increase this 50 to the input value.

But I don't understood very well what i can do to solve that.
I understood that I can override this using the file ./YOUR_TEMPLATE/html/hikashop_button.php but I don't understood how and what I need to put and change for this works.

Can you show me a demo please?
For example, increase and decrease using the minimum_value_per_order variable?

Thanks.

Last edit: 9 years 8 months ago by rfernandes.

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

  • Posts: 82906
  • Thank you received: 13378
  • MODERATOR
9 years 8 months ago #194362

Hi,

You don't need to create such override anymore with recent versions of HikaShop. Now you can just edit the file "show_quantity" via the menu Display>Views and directly change the code there.

So in your case, you can either:
- change the code calling hikashopQuantityChange there to directly add the increment you want in $min_quantity
- actually don't change any code and just change the option "Quantity layout on product page" of the HikaShop configuration to not have an input anymore but a dropdown with fixed values that the customer can choose and which correspond to the minimum quantity per order

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

  • Posts: 57
  • Thank you received: 4
9 years 8 months ago #194468

Hi, thanks for your answer, but yesterday I have found one solution.

I have copied this javascript functions and paste in ./template/html/com_hikashop/product/show_quantity.php and works.

But thanks again for your help.

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

Time to create page: 0.086 seconds
Powered by Kunena Forum