We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50653
    • 2 Posts
    Hi

    I got little problem with snippet, Im preety new to snippets and making things in ModX, can someone point me what im doing wrong. As I wanted to make things as simple as possible made snipped called:

    [[generate_control_data]]

    <?php
    function calculateControlData($pos_id, $order_id, $session_id, $amount, $currency, $test, $language, $client_ip, $country, $email, $sharedkey){
    
    	return hash("sha256", $pos_id.$order_id.$session_id.$amount.$currency.$test.$language.$client_ip.$country.$email.$sharedkey);
    
    
    }
    ?>


    All varibles are passed from other chunks or snippets, all separate calls works fine.

    [[generate_control_data &pos_id=`{{pos_id}}` &order_id=`[!generate_order_id!]` &session_id=`[!generate_session_id!]` &amount=`{{amount5}}` ¤cy=`{{pln}}` &test=`{{test}}` &language=`{{lang}}` &client_ip=`[!get_client_ip!]` &country=`{{country}}` &email=`{{email}}` &sharedkey=`[!generate_shared_key32!]`]]

    It seems like no varibles are passed to snippet, can someone point me what is wrong.
    Thanks

    This question has been answered by krizzgru. See the first response.

    [ed. note: krizzgru last edited this post 11 years, 3 months ago.]
      • 17403 ☆ A M B ☆
      • 183 Posts
      Quote from: krizzgru at Jun 23, 2015, 11:10 AM
      Hi

      [[generate_control_data]]

      <!--?php
      function calculateControlData($pos_id, $order_id, $session_id, $amount, $currency, $test, $language, $client_ip, $country, $email, $sharedkey){
      
      	return hash("sha256", $pos_id.$order_id.$session_id.$amount.$currency.$test.$language.$client_ip.$country.$email.$sharedkey);
      
      
      }
      ?-->


      Remove the "function" bracket...

      <?
      return hash("sha256", $pos_id.$order_id.$session_id.$amount.$currency.$test.$language.$client_ip.$country.$email.$sharedkey);
      
        zaenal.lokamaya
        • 3749
        • 24,544 Posts
        If you need to keep it as a function and you're already calling your function, the issue is that those variables are not available inside the function. The best solution would be to send them as arguments to the function.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
        • discuss.answer
          • 50653
          • 2 Posts
          Thank you guys for reply, now I get it.