Displaying available products as less or more than

  • Posts: 299
  • Thank you received: 2
10 years 3 months ago #138880

-- url of the page with the problem -- : www.gobbe.se
-- HikaShop version -- : 2.2.3 Business
-- Joomla version -- : 2.5.17
-- PHP version -- : 5.3.3
-- Browser(s) name and version -- : Chrome 31.0.1650.63 m
-- Error-message(debug-mod must be tuned on) -- : Not necessary

Hi, Short question:
How can I set up HikaShop to display every products amount like below 5 left and more than 5 left instead of exact numbers of how many is left in stock?
I have seen plenty of shops displaying amount of products like this but how do I set it up?

Thanks
Micke

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

  • Posts: 12953
  • Thank you received: 1778
10 years 3 months ago #138905

Hi,
The solution will probably be to edit the code of your "quantity" file of the "product" view of your front-end template through "Hikashop->Display->Views" , and change these lines :

 <div class="hikashop_product_stock">
    <?php
      echo '<span class="hikashop_product_stock_count">'.JText::sprintf('X_ITEMS_IN_STOCK',$this->row->product_quantity).'<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($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>';
      }
    }
Hope this will help you a little.

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

  • Posts: 299
  • Thank you received: 2
10 years 3 months ago #138988

Hi,
Ok but as I'm no programmer I have no idea what to put in in order to display what I want,, :-(
I want for example the quantity to display lie this (in english to make you understand)*:

More than 5 pcs left (if the number left of this product is 5 or more than five items)
or
Less than 5 pcs left (if the number of that product is less than 5).

Maybe you can give me a hint how to do it?

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

  • Posts: 13201
  • Thank you received: 2322
10 years 3 months ago #139180

Hi,

You have to replace:

echo '<span class="hikashop_product_stock_count">'.JText::sprintf('X_ITEMS_IN_STOCK',$this->row->product_quantity).'<br/></span>';
By:
$qtyMessSet = 5;
if($this->row->product_quantity >= $qtyMessSet || $this->row->product_quantity == '-1')
    echo ' <span class="hikashop_product_stock_count">'.JText::sprintf('MORE_THAN_X_ITEMS',$qtyMessSet).'<br/></span>';
else
    echo ' <span class="hikashop_product_stock_count">'.JText::sprintf('LESS_THAN_X_ITEMS',$qtyMessSet).'<br/></span>';

And add translations like:

MORE_THAN_X_ITEMS="More than %s pcs left"
LESS_THAN_X_ITEMS="Less than %s pcs left"

in the language file.

The following user(s) said Thank You: LAMF

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

  • Posts: 12953
  • Thank you received: 1778
10 years 3 months ago #139186

Hi,
The solution will probably be to change this line :

echo '<span class="hikashop_product_stock_count">'.JText::sprintf('X_ITEMS_IN_STOCK',$this->row->product_quantity).'<br/></span>';
By :
if($this->row->product_quantity < 5)
	echo '<span class="hikashop_product_stock_count">Less than 5 pcs left<br/></span>';
else
	echo '<span class="hikashop_product_stock_count">More than 5 pcs left<br/></span>';

Edit
Note that the solution that Xavier gave you will probably be better ;).

Last edit: 10 years 3 months ago by Mohamed Thelji.
The following user(s) said Thank You: LAMF

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

  • Posts: 299
  • Thank you received: 2
10 years 3 months ago #139252

Ok thanks a lot guys! I ued Xaviers methd as I like to add the translation in the language file. :)

I have another question.
Is it possible to add quantity to multiple products at one go?
Can a cronjob do this and if so how can you do that?

Maybe it's possible to add all products in a CSV/Excel exported from HikaShop and edit the file and the product_quantity field for each of these products and then re-import it via the product import?

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

  • Posts: 299
  • Thank you received: 2
10 years 3 months ago #139263

Just want to let you know it works and it saves a lot of work too :)
Jut export a product category with all products and edit the fields you want to change value in and save and upload and voila!

Last edit: 10 years 3 months ago by LAMF. Reason: more info added

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

  • Posts: 290
  • Thank you received: 22
8 months 3 weeks ago #354124

Hi, just wanted to ask if this solution is still OK with the new versions of HikaShop?
It's been more then 9 year :-)

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

  • Posts: 4533
  • Thank you received: 612
  • MODERATOR
8 months 3 weeks ago #354128

Bonjour,

Oui, ce code devrait marcher tel quel, le seul point potentiel à considérer serait peut être les classes qui ont potentiellement évolués.
Mais en partant de l'existant de votre HikaShop pour reprendre le principe de la modification ne devrait poser aucun souci.

Cordialement

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

Time to create page: 0.116 seconds
Powered by Kunena Forum