Page 1 of 1

plural singular product-products depend on quanity

Posted: Wed Sep 18, 2013 4:49 pm
by jerdna
Simple question.....is ist possible to call different words to the cart text based on quantity.
I our cuntry we also have special word for 2 products.

1 product...product
2 products.... in SLOVENIA diferent word
3 and more products...products

Is there a simple code that would pull the corect word based on quantity that is in cart from language file.

Thanx in advance Andrej

Re: plural singular product-products depend on quanity

Posted: Mon May 20, 2019 3:32 am
by Lucmac
För that u would have to edit the common cart files, if you're still interested I can help

Re: plural singular product-products depend on quanity

Posted: Tue May 21, 2019 2:00 pm
by cedcommerceteam
Hello Jerdna,

You need to add custom JS through which you can add different text in cart according to quantity, as this is a modification in core file so you need to use vQmod or Ocmod file (according to your OC Version) to add a JS into core file.

Thanks.

Re: plural singular product-products depend on quanity

Posted: Sat Feb 01, 2020 10:37 am
by rndmizer
For those who need a custom solution (no perfect but works for me)

//in language files define plural like below

Code: Select all

$_['text_reviews']  = '%s reviews|%s review';
//in system/general.php add

Code: Select all

if(!function_exists('returnPlural')){
    function returnPlural($message, $count, $delimiter="|"){
        return strpos($message, $delimiter) !== false ?
            str_replace($delimiter, '', substr(stristr(sprintf($message, $count, $count), $delimiter, ($count <= 1 ? 0 : 1)), 0)) :
            sprintf($message, $count);
    }
}
//usage

Code: Select all

$reviews = returnPlural($this->language->get('text_reviews'), (int)$result['reviews']);