Jump to content

Default produt order by diferent languages


saphire

Recommended Posts

Hello, does anyone know how to set a default order of products depending on the language?
Example:
EN language default view of products sort by price ASC
FR language default view of products sort by price DESC

 

Thank you very much

Link to comment
Share on other sites

Ok I am not sure

 

when and where do you want do these

 

 

but for example  

 

Category::getProducts have $order_by $order_way options

 

you can do or override these function to do waht you want by default or your needs change all the calls with the correct params 

Link to comment
Share on other sites

I experienced change in product-sort.tpl

 

Adding by language for each block

 

{if $lang_iso == en}  

 

<option value="{$orderbydefault|escape:'html':'UTF-8'}:{$orderwaydefault|escape:'html':'UTF-8'}" {if $orderby eq $orderbydefault}selected="selected"{/if}>{l s='Sort by'}</option>  

...

{/if}  

{if $lang_iso == fr}  

<option value="{$orderbydefault|escape:'html':'UTF-8'}:{$orderwaydefaultb|escape:'html':'UTF-8'}" {if $orderby eq $orderbydefaultb}selected="selected"{/if}>{l s='Sort by'}</option>  

{/if}  

 

and edited Frontcontroller.php

 

 

$stock_management = Configuration::get('PS_STOCK_MANAGEMENT') ? true : false; // no display quantity order if stock management disabled
$order_by_values = array(0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity', 7 => 'reference');
$order_way_values = array(0 => 'asc', 1 => 'desc');
 
 
 
$this->orderBy = Tools::strtolower(Tools::getValue('orderby', $order_by_values[(int)Configuration::get('PS_PRODUCTS_ORDER_BY')]));
$this->orderWay = Tools::strtolower(Tools::getValue('orderway', $order_way_values[(int)Configuration::get('PS_PRODUCTS_ORDER_WAY')]));
$this->orderWay = Tools::strtolower(Tools::getValue('orderway', $order_way_valuesb[(int)Configuration::get('PS_PRODUCTS_ORDER_WAYB')]));
 
 
 
if (!in_array($this->orderBy, $order_by_values))
$this->orderBy = $order_by_values[0];
if (!in_array($this->orderWay, $order_way_values))
$this->orderWay = $order_way_values[0];
if (!in_array($this->orderWay, $order_way_valuesb))
$this->orderWay = $order_way_valuesb[0];
 
 
 
$this->context->smarty->assign(array(
'orderby' => $this->orderBy,
'orderway' => $this->orderWay,
'orderbydefault' => $order_by_values[(int)Configuration::get('PS_PRODUCTS_ORDER_BY')],
'orderwayposition' => $order_way_values[(int)Configuration::get('PS_PRODUCTS_ORDER_WAY')], // Deprecated: orderwayposition
'orderwaydefault' => $order_way_values[(int)Configuration::get('PS_PRODUCTS_ORDER_WAY')],
 'orderwaydefaultb' => $order_way_valuesb[(int)Configuration::get('PS_PRODUCTS_ORDER_WAYB')],
'stock_management' => (int)$stock_management));
 
}
 
In db duplicate the PS_PRODUCTS_ORDER_WAY to PS_PRODUCTS_ORDER_WAYB 
 
One with value 0 = ASC other Value 1= DESC
 
But not happens. The default order configured on BO remain. 
 
Sorry but I'm not a programmer . I try to find out
Link to comment
Share on other sites

On BO exist the option to define the default order of products on all store

Preferences > Products

 

What I need is have a order (ASC or DESC) on products on one especific language

Geral example english is ok whith the order defined on BO (PRICE = ASC)  but I need that products in French have the order (PRICE = DESC).

Link to comment
Share on other sites

Ok

 

I didnt try but but the list of products on a category come from Category Class from getProducts

		if ($random === true)
			$sql .= ' ORDER BY RAND() LIMIT '.(int)$random_number_products;
		else
			$sql .= ' ORDER BY '.(!empty($order_by_prefix) ? $order_by_prefix.'.' : '').'`'.bqSQL($order_by).'` '.pSQL($order_way).'
			LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n;

you can override the class check the language - change the $order_way

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...