- Posts: 1184
- Thank you received: 13
How to change product quantity logic
11 years 3 months ago #205108
by verzevoul
How to change product quantity logic was created by verzevoul
Hi!
I need your help here with a client.
We re building a shop like all others but there is a change in quantity display.
When quantity is from 1 to 5 , I need to show a color with css for example yellow
When quantity is from 5 to unlimited , I need to show a color with css for example green.
When quantity is 0 , I need to show a color with css for example red.
Is that possible without changing the core of hikashop?
Can this be done with a custom field?
Thanks!
I need your help here with a client.
We re building a shop like all others but there is a change in quantity display.
When quantity is from 1 to 5 , I need to show a color with css for example yellow
When quantity is from 5 to unlimited , I need to show a color with css for example green.
When quantity is 0 , I need to show a color with css for example red.
Is that possible without changing the core of hikashop?
Can this be done with a custom field?
Thanks!
Please Log in or Create an account to join the conversation.
11 years 3 months ago #205119
by Xavier
Replied by Xavier on topic How to change product quantity logic
Hi,
You will have to do a view override, the view in question is "product / quantity".
So in that view just add a php if/else condition on the product stock and add a div around the content with the desired class.
Then apply a css property on the created classes.
www.hikashop.com/support/support/documen...ize-the-display.html
You will have to do a view override, the view in question is "product / quantity".
So in that view just add a php if/else condition on the product stock and add a div around the content with the desired class.
Then apply a css property on the created classes.
www.hikashop.com/support/support/documen...ize-the-display.html
Please Log in or Create an account to join the conversation.
11 years 3 months ago #205243
by verzevoul
Replied by verzevoul on topic How to change product quantity logic
Thank you Xavier.
That is what I suspected I should do form the beginning. Is it possible to write in the forum the php code? An example of it?
That is what I suspected I should do form the beginning. Is it possible to write in the forum the php code? An example of it?
Please Log in or Create an account to join the conversation.
11 years 3 months ago #205258
by Xavier
Replied by Xavier on topic How to change product quantity logic
Hi,
Please replace the content of the view by:
You will have to add a translation override on the key "UNLIMITED_STOCK" something like:
The PHP if condition used to check the quantity given in the previous code is:
So you can apply your css properties on the classes "greentext" "yellowtext" and "redtext".
Please replace the content of the view by:
Code:
<?php
global $Itemid;
$url_itemid = '';
if(!empty($this->itemid))
$url_itemid = $this->itemid;
elseif(!empty($Itemid))
$url_itemid = '&Itemid='.$Itemid;
if($this->config->get('show_quantity_field') == -2)
$this->params->set('show_quantity_field', @$this->row->product_display_quantity_field);
$config =& hikashop_config();
if($this->row->product_quantity > 5 || $this->row->product_quantity == '-1'){
$customClass = 'greentext';
}elseif($this->row->product_quantity > 0){
$customClass = 'yellowtext';
}else{
$customClass = 'redtext';
}
$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');
$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;
}
}
$showFree = 0;
if($this->config->get('display_add_to_wishlist_for_free_products', 1) || (!$this->config->get('display_add_to_wishlist_for_free_products', 1) && $this->row->prices[0]->price_value != '0')){
$showFree = 1;
}
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')));
//TODO echo $this->cart->displayButton(JText::_('Pre-order and add to cart'),'add',$this->params,$url,$ajax);
?></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
$text = JText::_('UNLIMITED_STOCK').'<br/>';
echo '<span class="hikashop_product_stock_count '.$customClass.'">'.$text.'<br/></span>';
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_contentLink('product&task=show&product_id='.$this->row->product_id.'&name='.$this->row->alias.$url_itemid.$this->category_pathway,$this->row),'window.location = \''.str_replace("'","\'",hikashop_contentLink('product&task=show&product_id='.$this->row->product_id.'&name='.$this->row->alias.$url_itemid.$this->category_pathway,$this->row)).'\';return false;', '');
} else {
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 && $showFree) {
echo '<div id="hikashop_add_wishlist">' .
$this->cart->displayButton(JText::_('ADD_TO_WISHLIST'), $btnType, $this->params, $url, $wishlistAjax, '', $max, $min, '', false) .
'</div>';
}
}
} elseif($this->row->product_quantity > 0) {
?>
<div class="hikashop_product_stock">
<?php
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);
echo '<span class="hikashop_product_stock_count '.$customClass.'">'.$text.'<br/></span>';
if($config->get('button_style', 'normal') == 'css')
echo '<br />';
if($max <= 0 || $max > $this->row->product_quantity)
$max = $this->row->product_quantity;
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_contentLink('product&task=show&product_id='.$this->row->product_id.'&name='.$this->row->alias.$url_itemid.$this->category_pathway,$this->row),'window.location = \''.str_replace("'","\'",hikashop_contentLink('product&task=show&product_id='.$this->row->product_id.'&name='.$this->row->alias.$url_itemid.$this->category_pathway,$this->row)).'\';return false;','');
} else {
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 && $showFree){
echo '<div id="hikashop_add_wishlist">' .
$this->cart->displayButton(JText::_('ADD_TO_WISHLIST'), $btnType, $this->params, $url, $wishlistAjax, '', $max, $min, '', false) .
'</div>';
}
}
} else {
?>
<div class="hikashop_product_no_stock">
<?php
$text = JText::_('NO_STOCK').'<br/>';
echo '<span class="hikashop_product_stock_count '.$customClass.'">'.$text.'<br/></span>';
$waitlist = $this->config->get('product_waitlist', 0);
if(hikashop_level(1) && ($waitlist == 2 || ($waitlist == 1 && (!empty($this->row->main->product_waitlist) || !empty($this->row->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.$url_itemid), 'window.location=\''.str_replace("'","\'",hikashop_completeLink('product&task=waitlist&cid='.$this->row->product_id.$url_itemid)).'\';return false;');
}
if(hikashop_level(1) && $this->params->get('add_to_wishlist') && $wishlistEnabled && !$hideForGuest && $showFree) {
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_contentLink('product&task=show&product_id='.$this->row->product_id.'&name='.$this->row->alias.$url_itemid.$this->category_pathway,$this->row),'window.location = \''.str_replace("'","\'",hikashop_contentLink('product&task=show&product_id='.$this->row->product_id.'&name='.$this->row->alias.$url_itemid.$this->category_pathway,$this->row)).'\';return false;','');
}else{
echo '<div id="hikashop_add_wishlist">' .
$this->cart->displayButton(JText::_('ADD_TO_WISHLIST'), 'add', $this->params, $url, $wishlistAjax, '', @$this->row->product_max_per_order, 1, '', false) .
'</div>';
}
}
}
?>
</div>
<?php
} elseif(hikashop_level(1) && $wishlistEnabled && $this->params->get('add_to_wishlist', 1) && $showFree && !$hideForGuest && !$this->config->get('display_add_to_cart_for_free_products')) {
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_contentLink('product&task=show&product_id='.$this->row->product_id.'&name='.$this->row->alias.$url_itemid.$this->category_pathway,$this->row),'window.location = \''.str_replace("'","\'",hikashop_contentLink('product&task=show&product_id='.$this->row->product_id.'&name='.$this->row->alias.$url_itemid.$this->category_pathway,$this->row)).'\';return false;', '');
} else {
$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">' .
$this->cart->displayButton(JText::_('ADD_TO_WISHLIST'), 'add', $this->params, $url, $wishlistAjax, '', @$this->row->product_max_per_order, 1, '', false) .
'</div>';
}
}
?>
UNLIMITED_STOCK="Unlimited quantity"
The PHP if condition used to check the quantity given in the previous code is:
Code:
if($this->row->product_quantity > 5 || $this->row->product_quantity == '-1'){
$customClass = 'greentext';
}elseif($this->row->product_quantity > 0){
$customClass = 'yellowtext';
}else{
$customClass = 'redtext';
}
So you can apply your css properties on the classes "greentext" "yellowtext" and "redtext".
The following user(s) said Thank You: verzevoul
Please Log in or Create an account to join the conversation.
11 years 3 months ago #205854
by verzevoul
Replied by verzevoul on topic How to change product quantity logic
Thank you very much Xavier!
Can you please tell me how to NOT display the quantity now. Because I want the color to replace the logic of the real stock.
Thanks!
Can you please tell me how to NOT display the quantity now. Because I want the color to replace the logic of the real stock.
Thanks!
Please Log in or Create an account to join the conversation.
Less
More
- Posts: 12953
- Thank you received: 1778
11 years 3 months ago #205874
by Mohamed Thelji
Replied by Mohamed Thelji on topic How to change product quantity logic
Hello,
You'll just have to use a custom CSS class regarding the case, and use the "display: none;" CSS property to hide it.
You'll just have to use a custom CSS class regarding the case, and use the "display: none;" CSS property to hide it.
Please Log in or Create an account to join the conversation.
11 years 3 months ago #206057
by verzevoul
Replied by verzevoul on topic How to change product quantity logic
Mohamed I believe I can t use the display:none, because I use the $customClass = 'yellowtext'; which comes to my css like
<span class="hikashop_product_stock_count yellowtext">3 κομμάτια στο απόθεμα<br></span>
I user in my css file
span.hikashop_product_stock_count.yellowtext {
display: block;
color: yellow;
padding: 2px;
background-color: black;
So if i use
display:none,
the whole class will be vanished
There is no seperated class for the quantity text
<span class="hikashop_product_stock_count yellowtext">3 κομμάτια στο απόθεμα<br></span>
I user in my css file
span.hikashop_product_stock_count.yellowtext {
display: block;
color: yellow;
padding: 2px;
background-color: black;
So if i use
display:none,
the whole class will be vanished
There is no seperated class for the quantity text
Please Log in or Create an account to join the conversation.
11 years 3 months ago #206209
by Xavier
Replied by Xavier on topic How to change product quantity logic
Hi,
To not display the quantity you can edit the code and remove the $text between the html "span" tags.
To not display the quantity you can edit the code and remove the $text between the html "span" tags.
Please Log in or Create an account to join the conversation.
11 years 3 months ago #206243
by verzevoul
Replied by verzevoul on topic How to change product quantity logic
Please Xavier can you tell me the file I have to edit ? is it the quantity page again?
Please Log in or Create an account to join the conversation.
11 years 3 months ago #206244
by nicolas
Replied by nicolas on topic How to change product quantity logic
He was talking about this line in the same file:
echo '<span class="hikashop_product_stock_count '.$customClass.'">'.$text.'<br/></span>';
You can remove it to remove the quantity display.
echo '<span class="hikashop_product_stock_count '.$customClass.'">'.$text.'<br/></span>';
You can remove it to remove the quantity display.
Please Log in or Create an account to join the conversation.
Time to create page: 0.249 seconds