Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

How To Change Store Currency From Addon Rate Topic   - - - - -

 
  • Elsherif
  • Member
  • Trial users
  • Join Date: 10-Jul 15
  • 36 posts

Posted 04 August 2015 - 06:10 AM #1

How can I change the current currency of the site from addon code?
Default currency changer uses GET request variable 'currency' to change the currency.
But I need to change it from the code according to some condition.

 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19797 posts

Posted 04 August 2015 - 11:56 AM #2

You can find how the currency is defined in the fn_init_currency function (app/functions/fn.init.php). Check for $secondary_currency.

We suggest you to use the
fn_set_session_data('secondary_currencyC', 'USD');
code

Note that it should be executed before the fn_init_currency function is called

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • Elsherif
  • Member
  • Trial users
  • Join Date: 10-Jul 15
  • 36 posts

Posted 04 August 2015 - 12:55 PM #3

You can find how the currency is defined in the fn_init_currency function (app/functions/fn.init.php). Check for $secondary_currency.

We suggest you to use the

fn_set_session_data('secondary_currencyC', 'USD');
code

Note that it should be executed before the fn_init_currency function is called


Yes, I've already seen that but didn't know how to perform it before init.
Right know I got it to work by adding a new hook to 'fn_init_currency'.

But, I really don't like this ... I don't want to touch anything in the original cs-cart code. So, if anyone has a better solution please share it.
Thanks

 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19797 posts

Posted 04 August 2015 - 07:23 PM #4

I have made quick overview and have not found any hooks. As a workaround you can set up currency in the nearest hook and redirect page to itself

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • Elsherif
  • Member
  • Trial users
  • Join Date: 10-Jul 15
  • 36 posts

Posted 05 August 2015 - 05:25 AM #5

I have made quick overview and have not found any hooks. As a workaround you can set up currency in the nearest hook and redirect page to itself

The problem with this is that the 'fn_init_currency' function defines a constant for the currency.
So using any hook after it will give an error "constant already defined".

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 11406 posts

Posted 05 August 2015 - 11:59 PM #6

You will have to modify the init_currency function to check for your condition and do the appropriate setup.

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • Elsherif
  • Member
  • Trial users
  • Join Date: 10-Jul 15
  • 36 posts

Posted 06 August 2015 - 01:17 PM #7

You will have to modify the init_currency function to check for your condition and do the appropriate setup.

Basically I've done the same by adding a new hook to the function. But, doing what you are suggesting will force the new functionality even after deactivating or uninstalling the plugin.

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 11406 posts

Posted 06 August 2015 - 06:52 PM #8

Don't think a hook will work here. The addon has not yet been initialized.

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • Elsherif
  • Member
  • Trial users
  • Join Date: 10-Jul 15
  • 36 posts

Posted 07 August 2015 - 05:33 AM #9

Don't think a hook will work here. The addon has not yet been initialized.

I don't understand what you mean by "The addon has not yet been initialized" but it is already working fine.
I'm just not liking that I had to modify cs-cart core file for this so I'm looking for another way.

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 11406 posts

Posted 07 August 2015 - 08:15 PM #10

My mistake. Addons are initialized further up the init.php process so the hook would be registered.
You can request a hook be added here: http://forum.cs-cart...__fromsearch__1

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • Elsherif
  • Member
  • Trial users
  • Join Date: 10-Jul 15
  • 36 posts

Posted 11 August 2015 - 05:57 AM #11

My mistake. Addons are initialized further up the init.php process so the hook would be registered.
You can request a hook be added here: http://forum.cs-cart...__fromsearch__1


I've just requested the new hook.
Thanks :)

 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19797 posts

Posted 11 August 2015 - 08:39 AM #12

The problem with this is that the 'fn_init_currency' function defines a constant for the currency.
So using any hook after it will give an error "constant already defined".


My solutions allows to exclude any changes in the core files. But in this case additional redirect is required. Usually such redirects are not visible for the customers

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • Elsherif
  • Member
  • Trial users
  • Join Date: 10-Jul 15
  • 36 posts

Posted 12 August 2015 - 05:41 AM #13

My solutions allows to exclude any changes in the core files. But in this case additional redirect is required. Usually such redirects are not visible for the customers


Although I don't like the redirection idea (because I see it as a workaround more than a solution), I realize it is possibly the only way to achieve this (without the hook of course).
I will also check this. Thank you :)

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 11406 posts

Posted 12 August 2015 - 07:10 PM #14

You can always request that they leave the define and use a registry (runtime.cart_currency) instead. The define would remain in place for compatibility, but all internal uses would use the runtime registry value allowing addon developers to migrate over time.

But if they remove the define, all the addon developers are going to be mad at you for making a change that probably impacts most of them but with very little (if any) value returned to them.

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • Elsherif
  • Member
  • Trial users
  • Join Date: 10-Jul 15
  • 36 posts

Posted 13 August 2015 - 05:30 AM #15

You can always request that they leave the define and use a registry (runtime.cart_currency) instead. The define would remain in place for compatibility, but all internal uses would use the runtime registry value allowing addon developers to migrate over time.

But if they remove the define, all the addon developers are going to be mad at you for making a change that probably impacts most of them but with very little (if any) value returned to them.


Wow ... I most certainly don't want that :D
I think the hook is just enough.