Jump to content

How "read" the nationality of customer in a TPL file


l.zuccarini

Recommended Posts

Hi all, 

I would like change the result of a TPL file be based from nationality of customer.

EXAMPLE

			<!-- quantity pallet -->

//For Italian customer
			<div align="center"; style="font-size:10px">
            	{if $product->id|intval == 3}
					{l s='56 bales = 1 Pallet'}
                {else if $product->id|intval == 8}
                	{l s='1 Pallet = 60 bags'}                      
                {/if}
			</div>

// For Danmark customer
	<div align="center"; style="font-size:10px">
            	{if $product->id|intval == 3}
					{l s='50 bales = 1 Pallet'}
                {else if $product->id|intval == 8}
                	{l s='1 Pallet = 40 bags'}                      
                {/if}
			</div>

How can "read the nationality of customer?

Thank you in advance.

 

 

 

Prestashop 1.5.3.1

Link to comment
Share on other sites

A "Nationality" is not given/stored for the customer, but you could either decide where the customer currently is (geo-location) OR use the address where the customer is registered as an indication where he/she comes from:

 

 

if you want to use the geo-location way, there's an geoloc_id_country that holds the current country

in classes/Customer:

/** @var int customer id_country as determined by geolocation */
public $geoloc_id_country;
 

(You have to turn on geo location to make this work: Preferences->Geo-location   )

 

 

if you want to use the address way, there's a function that gets the current country of the customer:

in classes/Customer.php:
public static function getCurrentCountry($id_customer, Cart $cart = null)
 
 
So, then in your php function that initializes or calls the tpl file, add a smarty variable that holds this country ID and check in the tpl to take further action.
 
So either something like:
$this->context->smarty->assign(array(
    'customer_country' => (int)$this->context->customer->geoloc_id_country),
    ....
));
 
or something like:
 
$this->context->smarty->assign(array(
    'customer_country' => (int)Customer::getCurrentCountry($this->context->customer->id),
    ....
));
 
 
(Haven't tested it, but expect it to be something like this)
 
Then in the tpl file, check the {$customer_country} variable to be some number you need
 
Hope this helps,
pascal.
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...