Jump to content

How can ı access the selected currency from Override Hook


SametALMDR

Recommended Posts

Hello everyone ,

I've got a question about a hook.I am trying to access the active currency (selected currency by the user) on the OrderProductPricingOverride hook. But ı could not access that variable in any way. 

How can access the currency which is selected by the user on the OrderProductPricingOverride hook ?

Can anybody help me ? @brian! 🙂

Link to comment
Share on other sites

  • 1 month later...

Did you try choosing the hook point you want and type in it 

var_dump($vars);

This will print all the variables available for use, then when you open that page. Use the find option of your browser and search for currency to see what you are getting.

You can then use this variable in your hook.

Link to comment
Share on other sites

On 25/06/2020 at 20:33, SametALMDR said:

I've got a question about a hook.I am trying to access the active currency (selected currency by the user) on the OrderProductPricingOverride hook. But ı could not access that variable in any way. 

I thought that I had answered this thread - the backlog is far worse than I thought! 😲

On 25/06/2020 at 20:33, SametALMDR said:

How can access the currency which is selected by the user on the OrderProductPricingOverride hook ?

I think you would need to make upto three checks to get the users currency...

  1. if they're logged in as a client, then you can get it via $client context (remembering that clients cannot change currency).
  2. if they're not logged in and they have chosen a currency, then you can pull the value from the session array.
  3. if they're not logged in and they haven't changes currencies, then the currency value won't be set in the session and you'll have to assume they're using your default currency.

untested, but it would be along the lines of..

$client = Menu::context('client');
if ($client) {
	$currency = $client->currency;
}
elseif (!empty($_SESSION['currency'])) {
	currency = $_SESSION['currency'];
}
else {
	$currency = 1;
}

i'm cheating on the third step and assuming that you will know what your default currency is and can just hardcode its id value in the hook - but you could easily use capsule (declare its use first) to pull the id from the tblcurrencies database table for the default currency.

currency = Capsule::table('tblcurrencies')->where('default','1')->value('id');

then once you have your currency value, you can use it in your override hook if statements to determine what to charge per product, per currency.

15 hours ago, weelow said:

This will print all the variables available for use, then when you open that page.

I doubt it would print the session array.

Edited by brian!
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated