We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21884
    • 57 Posts
    i haven’t been able to find anything like this here, perhaps i didn’t search correctly, but i have gone through a fair amount of the posts before asking this

    i have some prices on a few pages in my site, that are in a single currency right now as they are just static bits of text in various pages

    is it possible, that if a user clicks on one of a number of "currency choice" links, i can have those bits of text switch to showing the value in the selected currency?

    my initial thinking is to have a TV for each price listed on the page, in each currency, then if the user clicks on the link, the document loads using the tv(s) for that currency, (not sure if this is the right way to go about it)

    i’m also not sure how to make that choice persist for the user’s entire session?
      • 4172
      • 5,888 Posts
      let’s say you have a price-TV for each product in your default-currency and you would list them with ditto.
      One of 100 ways could be to create a phx-modifier ’conv_cur’ to convert from default-currency to custom-currency by actual values.
      then you can convert your price in your ditto-chunk with [+price:conv_cur+]
      you can of course store the customer-choice in a $_SESSION-var.

      if you have fixed prices for different currencies you can store them in different price-tvs and let a new snippet ’myprice’ choose the right TV.
      then you call your snippet with [[myprice? &id=`[+id+]`]]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 21884
        • 57 Posts
        what an amazing community, thanks for the fast response!

        i like the 2nd option you presented, as my prices aren’t necessarily actual "conversions"

        i’m a bit new to the whole create snippet thing, you wouldn’t happen to know of any that use sessions that i could base my snippet off of?
          • 4172
          • 5,888 Posts
          this is not tested, but its the idea:

          <?php
          //USD,EUR,CNY ISO 4217 Currency Code List see http://www.xe.com/iso4217.php
          //price-tvs: priceEUR, priceUSD, priceCNY
          //link-examples:<ul><li><a href="[~[*id*]~]&currency=EUR">Euro</a></li><li><a href="[~[*id*]~]&currency=USD">US-Dollar</a></li></ul>
          //[!myprice? &id=`[+id+]`!]
          //[!myprice? &id=`[+id+]`&defaultCur=`USD`!]
          
          if ( isset ($_GET['currency']))
          {
              $_SESSION['currency'] = $_GET['currency'];
          }
          $defaultCur = isset ($defaultCur)?$defaultCur:'EUR';
          $currency = isset ($_SESSION['currency'])?$_SESSION['currency']:$defaultCur;
          $priceTv = 'price'.$currency;
          $tvs = $modx->getTemplateVarOutput($priceTv, $id);
          return $tvs[$priceTv].' '.$currency;
          
          ?>
          
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 21884
            • 57 Posts
            wow,

            i’ll give that a whirl, cheers mate!
              • 21884
              • 57 Posts
              works wonderfully!

              now to figure out how to call it multiple times on a page for different price values... maybe i need to re-think how i’m going about this...

              ok so i changed it to this:

              <?php
              //USD,EUR,CNY ISO 4217 Currency Code List see http://www.xe.com/iso4217.php
              //price-tvs: priceEUR, priceUSD, priceCNY
              //link-examples:<ul><li><a href="[~[*id*]~]&currency=EUR">Euro</a></li><li><a href="[~[*id*]~]&currency=USD">US-Dollar</a></li></ul>
              //[!myprice? &id=`[+id+]`&tv=`priceTV`!]
              //[!myprice? &id=`[+id+]`&tv=`priceTV`&defaultCur=`USD`!]
              
              if ( isset ($_GET['currency']))
              {
                  $_SESSION['currency'] = $_GET['currency'];
              }
              $defaultCur = isset ($defaultCur)?$defaultCur:'EUR';
              $currency = isset ($_SESSION['currency'])?$_SESSION['currency']:$defaultCur;
              $priceTv = $tv;
              $tvs = $modx->getTemplateVarOutput($priceTv, $id);
              return $tvs[$priceTv].' '.$currency;
              
              ?>


              but i’m fairly sure that’s not the most "efficient" way to do it, or is it?
                • 21884
                • 57 Posts
                gosh i’m sleepy...

                ok just realized that doing that change screws up my currency selection...

                <?php
                //USD,EUR,CNY ISO 4217 Currency Code List see http://www.xe.com/iso4217.php
                //price-tvs: priceEUR, priceUSD, priceCNY
                //link-examples:<ul><li><a href="[~[*id*]~]&currency=EUR">Euro</a></li><li><a href="[~[*id*]~]&currency=USD">US-Dollar</a></li></ul>
                //[!myprice? &id=`[+id+]`&tv=`priceTV`!]
                //[!myprice? &id=`[+id+]`&tv=`priceTV`&defaultCur=`USD`!]
                
                if ( isset ($_GET['currency']))
                {
                    $_SESSION['currency'] = $_GET['currency'];
                }
                $defaultCur = isset ($defaultCur)?$defaultCur:'EUR';
                $currency = isset ($_SESSION['currency'])?$_SESSION['currency']:$defaultCur;
                $priceTv = $tv.$currency;
                $tvs = $modx->getTemplateVarOutput($priceTv, $id);
                return $tvs[$priceTv].' '.$currency;
                
                ?>


                so i changed it to that...
                  • 21884
                  • 57 Posts
                  ok well that’s working...

                  i have a bunch of tvs like this:

                  value1EUR value1USD, value2EUR, value2USD etc...

                  and then call them with &tv=`value1` etc...

                  thanks again for the help...