Answers.Body: <p>I haven't used foxycart plugin, but looking at the '<a href="https://github.com/FoxyCart/foxycart-craft/blob/master/foxycart/templates/_settings.html" rel="nofollow">_settings.html</a>' file, it looks like it stores both the 'storedomain' and 'apikey' as part of the plugin settings. I would suspect that you would need to fork the plugin and modify it. </p>
  
  <p>You could possibly add additional settings to the plugin for the different domains (i.e. storedomain-en, storedomain-es, apikey-en, apikey-es), and then add some logic in the plugins main 'init' method to pick up the different settings based on the current locale.</p>
  
  <pre><code>$settings = craft()-&gt;plugins-&gt;getPlugin('foxycart')-&gt;getSettings();
  \FoxyCart_Helper::setSecret($settings['apikey-'.craft()-&gt;language]);
  \FoxyCart_Helper::setCartUrl("https://" . $settings['storedomain-'.craft()-&gt;language] . "/cart");
  </code></pre>
  
  <p>Or, you could set the 'storedomain' and 'apikey' in your multi-environment config array:</p>
  
  <pre><code>return array( 
      '*' =&gt; array(
          'storedomain' =&gt; array(
              'en' =&gt; cart.en.domain.com,
              'es' =&gt; cart.es.domain.com',
          ),
          'apikey' =&gt; array(
              'en' =&gt; 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
              'es' =&gt; 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYY',
          ),
      ),
      ...
  );
  </code></pre>
  
  <p>and then retrieve them using something like:</p>
  
  <pre><code>$settings = craft()-&gt;plugins-&gt;getPlugin('foxycart')-&gt;getSettings();
  $storedomain = craft()-&gt;config-&gt;get('storedomain');
  $apikey = craft()-&gt;config-&gt;get('apikey');
  \FoxyCart_Helper::setSecret($apikey[craft()-&gt;language]);
  \FoxyCart_Helper::setCartUrl("https://" . $storedomain[craft()-&gt;language] . "/cart");
  </code></pre>
  
  <p>You would probably also need to go and modify some the variable methods to return the localized versions, so that when you asked for 'storedomain', it returned the correct value. I.e. :</p>
  
  <pre><code>&lt;form action="https://{{ craft.foxyCart.storedomain }}/cart" method="post" accept-charset="utf-8"&gt;
  </code></pre>
  
  <p>I have no idea what other integration points the foxycart plugin has with craft however. If it attempts to sync data in any way with foxycart, it might not like switching accounts like that.</p>
  
  <p>Overall this sounds pretty messy. I would proceed with caution.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-11T16:57:00.170Z
Answers.LastActivityDate: 2015-02-11T19:08:43.080Z
Answers.LastEditDate: 2015-02-11T19:08:43.080Z
Answers.UserDisplayName: Douglas McDonald
Body: <p>I'm looking into the possibility of using Foxycart for a multilingual, multi currency site. Currently it is not possible to have multiple currencies in Foxycart so it would require having separate Foxycart accounts for each currency. I would therefore need to store the cart url and api keys for each Foxycart account within the foxycart plugin.</p>
  
  <p>What would be the best way of going about this? Is it possible to store different plugin setting based on locale?</p>
  
  <p>The other idea I had was to store the api key etc in the config file but not sure if that is best practice or not.</p>
  
Tags: <plugins>
Title: Is it possible to have different plugin settings per locale?
ThreadText: # Is it possible to have different plugin settings per locale?
  
  (Asked by: username_0 on 2015-02-11)
  
  I'm looking into the possibility of using Foxycart for a multilingual, multi currency site. Currently it is not possible to have multiple currencies in Foxycart so it would require having separate Foxycart accounts for each currency. I would therefore need to store the cart url and api keys for each Foxycart account within the foxycart plugin.
  
  What would be the best way of going about this? Is it possible to store different plugin setting based on locale?
  
  The other idea I had was to store the api key etc in the config file but not sure if that is best practice or not.
  
  **Tags:** plugins
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-02-11. Score: 2
  
  I haven't used foxycart plugin, but looking at the '[\_settings.html](https://github.com/FoxyCart/foxycart-craft/blob/master/foxycart/templates/_settings.html)' file, it looks like it stores both the 'storedomain' and 'apikey' as part of the plugin settings. I would suspect that you would need to fork the plugin and modify it.
  
  You could possibly add additional settings to the plugin for the different domains (i.e. storedomain-en, storedomain-es, apikey-en, apikey-es), and then add some logic in the plugins main 'init' method to pick up the different settings based on the current locale.
  
  ```
  $settings = craft()->plugins->getPlugin('foxycart')->getSettings();
  \FoxyCart_Helper::setSecret($settings['apikey-'.craft()->language]);
  \FoxyCart_Helper::setCartUrl("https://" . $settings['storedomain-'.craft()->language] . "/cart");
  
  ```
  
  Or, you could set the 'storedomain' and 'apikey' in your multi-environment config array:
  
  ```
  return array( 
      '*' => array(
          'storedomain' => array(
              'en' => cart.en.domain.com,
              'es' => cart.es.domain.com',
          ),
          'apikey' => array(
              'en' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
              'es' => 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYY',
          ),
      ),
      ...
  );
  
  ```
  
  and then retrieve them using something like:
  
  ```
  $settings = craft()->plugins->getPlugin('foxycart')->getSettings();
  $storedomain = craft()->config->get('storedomain');
  $apikey = craft()->config->get('apikey');
  \FoxyCart_Helper::setSecret($apikey[craft()->language]);
  \FoxyCart_Helper::setCartUrl("https://" . $storedomain[craft()->language] . "/cart");
  
  ```
  
  You would probably also need to go and modify some the variable methods to return the localized versions, so that when you asked for 'storedomain', it returned the correct value. I.e. :
  
  ```
  <form action="https://{{ craft.foxyCart.storedomain }}/cart" method="post" accept-charset="utf-8">
  
  ```
  
  I have no idea what other integration points the foxycart plugin has with craft however. If it attempts to sync data in any way with foxycart, it might not like switching accounts like that.
  
  Overall this sounds pretty messy. I would proceed with caution.
  
  
  ---
  
  