We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    As far as repeating an order, I was referring to one method in the articles mentioned of checking for the existance of the item in the data store already. I seriously doubt anyone is going to use the "back" button to repeat an order, and it won’t work if they do.

    I’ll be using a timestamp in a hidden field (which will be generated by a snippet in a user-defined cart form template) on page creation, storing that timestamp in an array in the SESSION when processing an order, then checking any subsequent orders. Since the page is refreshed after each order, the timestamp will be different after every order. If the timestamp of the new incoming order matches any of the timestamps in the array, this means it’s not a new order but a repeat of a previous one and will be discarded.

    Of course, once I add on Ajax features to the fully-functional cart, I’ll have to return a new timestamp and have the javascript replace the existing one as part of the Ajax request.

      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 32241
      • 1,495 Posts
      Quote from: sottwell at Apr 06, 2006, 11:34 AM

      As far as repeating an order, I was referring to one method in the articles mentioned of checking for the existance of the item in the data store already. I seriously doubt anyone is going to use the "back" button to repeat an order, and it won’t work if they do.

      I’ll be using a timestamp in a hidden field (which will be generated by a snippet in a user-defined cart form template) on page creation, storing that timestamp in an array in the SESSION when processing an order, then checking any subsequent orders. Since the page is refreshed after each order, the timestamp will be different after every order. If the timestamp of the new incoming order matches any of the timestamps in the array, this means it’s not a new order but a repeat of a previous one and will be discarded.

      Of course, once I add on Ajax features to the fully-functional cart, I’ll have to return a new timestamp and have the javascript replace the existing one as part of the Ajax request.

      I think that will be the best way to go. Go for it Susan wink
        Wendy Novianto
        [font=Verdana]PT DJAMOER Technology Media
        [font=Verdana]Xituz Media
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Yes! Yes! Yes! We are so good!!! grin

        Now the shopping cart system won’t repeat orders or order updates if the user clicks refresh or the back button! Aside from the usual getting parameters backwards in the in_array() function and forgetting a closing parentheses or two, it worked the first try! Thanks go to the comments in the PHP documentation on how to deal with a non-existant array, since until an order has been added to the cart the "tokens" array won’t exist.

        And I fixed up the demo a bit.

        Next up, the checkout snippet.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 4266
          • 70 Posts
          Happy with the progress laugh laugh laugh
            • 32241
            • 1,495 Posts
            Keep it up Susan.

            Thanks
              Wendy Novianto
              [font=Verdana]PT DJAMOER Technology Media
              [font=Verdana]Xituz Media
              • 37272
              • 216 Posts
              Good to hear it’s going well, Susan! smiley
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                One step at at time...baby steps grin
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 37272
                  • 216 Posts
                  Hey Susan,

                  No biggie, just a heads up: the "Your Cart" div displays incorrectly in IE6.
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    I’m not at all surprised. Maybe tomorrow I’ll fire up the Windows machine and look into it. It’s just a matter of CSS, which would be up to the developer using this system anyway, and would depend on where the cart is placed. Putting it up in the heading block was just a bit of whimsy on my part, like the rss feed from the forums. "Because I can" cool
                      Studying MODX in the desert - http://sottwell.com
                      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                      Join the Slack Community - http://modx.org
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      Ok, the checkout framework has been completed. It is based on one snippet, very similar to the mini-cart snippet, except it allows for editing of the quanitities of items.

                      Then it uses two main TVs, one for selecting shipping options and the other for selecting payment options.

                      Both of these TVs in turn call on individual TVs for each option. This way all you need to do is edit the two Options TVS to indicate what options you are making available.
                      @EVAL
                      if(isset($_SESSION['orders'])) {
                      return '
                      <form action="[~[*id*]~]" method="post">
                      <fieldset id="scShipmethods">
                      [*ShipDHL*][*ShipCourier*][*ShipAirmail*]<br />
                      <input type="submit" class="button" name="shipping" value="Select Shipping Method" />
                      </fieldset>
                      </form>
                      ';
                      }

                      Then comes the hard part... write the code for each option’s functionality. The shipping TVs are entirely done in the one TV for each option; the TV creates the button and does all the processing. The payment options TVs will generate the option button, but will then pass off the processing to other TVs or included files. This is because they are generally much more complex than the shipping option units. You could pack the whole payment option into the same TV, but I think you’d regret it before long.
                        Studying MODX in the desert - http://sottwell.com
                        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                        Join the Slack Community - http://modx.org