We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12491
    • 90 Posts
    This works in 1.08 but not in 2.1.1

    Getting a Fatal error now:
    Call to a member function query() on a non-object in /var/www/clients/client3/web208/web/core/cache/includes/elements/modsnippet/81.include.cache.php on line 15

    Same server, same sources, same everything......

    
    <?php
    $total = 0;
    $hash = $_COOKIE['hash']; 
    $msg = $_GET['msg'];
    $ok = $_GET['ok'];
    $date = date("Y-m-d");
    $query = "SELECT * FROM `modx_cart` WHERE hash = '".$hash."' AND type <> 'P' ORDER BY id ASC";
    $output = '<table border="0" width="100%">
    ';
    $result = $modx->db->query( $query );
    //id, type, content_id, article_name, article_price, article_description, hash, number, date, extra
    while( $row = $modx->db->getRow( $result ) ) {
    	$output .= '<tr><td>'.$row['article_name'].'</td><td> € '.$row['article_price'].'</td><td><a href="'.$row['id'].'" class="deletefromcart" title="Delete from cart">x</a></td></tr>
    ';
    	$total = $total + $row['article_price'];
    }
    $output .= '
    <tr><td colspan="3">................................................................................</td></tr>
    <tr><td>Total:</td><td>€ '.number_format($total,2).'</td><td> </td></tr>
    </table>
    <p> </p>
    <p class="buy_now_detail_page"><a href="assets/components/msp/pay.php?price='.(100*$total).'&hash='.$hash.'" class="payment" title="MultiSafepay met iDeal" onClick="window.resizeTo(800,800);"><img src="assets/templates/Milky/[[skin]]/skin/button_buy_now_detail_page.png" alt="MultiSafepay met iDeal" /></a></p>
    ';
    if (($ok)&&($msg)){
    $output .= '<p> </p>
    <h4>'.$msg.'</h4>
    <p>We zullen uw order zo snel als mogelijk verwerken en versturen.</p>
    <script>setTimeout("window.close()",6000);</script>';
    }
    if ((!($ok))&&($msg)){
    $output .= '<p> </p>
    <h4>'.$msg.'</h4>
    ';
    }
    
    return $output;
    

      Sommige mensen hebben aan een half woord genoeg
      • 36493
      • 64 Posts
      You have some legacy code that is now removed in 2.1.1

      check this page:

      http://rtfm.modx.com/display/revolution20/Summary+of+Legacy+Code+Removed+in+2.1
        |
        • 12491
        • 90 Posts
        Does anybody have an idea how to do this now?

          Sommige mensen hebben aan een half woord genoeg
          • 26903
          • 1,336 Posts
          Try :-

          $result = $modx->query( $query );

          while($row = $result->fetch())
          ........

            Use MODx, or the cat gets it!
            • 12491
            • 90 Posts
            Thanx, no fatal errors anymore grin

            , but still not here shocked no records .... i think becouse of the hash snippets.

            Looks like there’s more to them as well,

            Any ideas on these peaces of snippit code?

            $query = "SELECT * FROM `modx_cart` WHERE hash = ’".$hash."’ AND type <> ’P’ ORDER BY id ASC";


            <?php
            $total = 0;
            $hash = $_COOKIE[’hash’];
            ...
            <?php
            $hash = $_COOKIE[’hash’];
            if ($hash=="") {$hash = md5("modx".mt_rand());}
            return $hash;
              Sommige mensen hebben aan een half woord genoeg
              • 26903
              • 1,336 Posts
              I can’t see how these are affected by MODX API changes, its just code that uses PHP’s md5. Try dumping the rows returned from your queries, what errors are you getting in your logs, if any.
                Use MODx, or the cat gets it!
                • 12491
                • 90 Posts
                Dumped the rows like you said:

                looking like this:
                368 69 product 2 99 product 2 f6253c23361ab9bc7da1162658957fe1 1 2011-06-08 0
                So you now they are there.

                These errors are in my log, but they where there before:

                (ERROR @ /index.php) `id` is not a valid integer and may not be passed to makeUrl(),
                (ERROR @ /index.php) [OnLoadWebDocument]1

                This is the new code, i just can’t see what i,m doing wrong embarrassed,
                Runs true all the code and just the html bits are showing.
                The code isn’t provoking errors anymore, but maybe my code is so offending it’s just ignored....

                [
                <?php
                $total = 0;
                $hash = $_COOKIE['hash'];
                $msg = $_GET['msg'];
                $ok = $_GET['ok'];
                $date = date("Y-m-d");
                $query = "SELECT * FROM `modx_cart` WHERE hash = '".$hash."' AND type <> 'P' ORDER BY id ASC";
                $output .= '<table border="0" width="100%">
                ';
                
                $result = $modx->query( $query );
                while ($row = $result->fetch(id, type, content_id, article_name, article_price, article_description, hash, number, date, extra)){
                $output .= '<tr><td>'.$row['article_name'].'</td><td> € '.$row['article_price'].'</td><td><a href="'.$row['id'].'" class="deletefromcart" title="Delete from cart">x</a></td></tr>
                ';
                	$total = $total + $row['article_price'];
                }
                $output .= '
                <tr><td colspan="3">................................................................................</td></tr>
                <tr><td>Total:</td><td>€ '.number_format($total,2).'</td><td> </td></tr>
                </table>
                <p> </p>
                <p class="buy_now_detail_page"><a href="assets/components/msp/pay.php?price='.(100*$total).'&hash='.$hash.'" class="payment" title="MultiSafepay met iDeal" onClick="window.resizeTo(800,800);"><img src="assets/templates/Milky/[[skin]]/skin/button_buy_now_detail_page.png" alt="MultiSafepay met iDeal" /></a></p>
                ';
                if (($ok)&&($msg)){
                $output .= '<p> </p>
                <h4>'.$msg.'</h4>
                <p>We zullen uw order zo snel als mogelijk verwerken en versturen.</p>
                <script>setTimeout("window.close()",6000);</script>';
                }
                if ((!($ok))&&($msg)){
                $output .= '<p> </p>
                <h4>'.$msg.'</h4>
                ';
                }
                
                return $output;
                  Sommige mensen hebben aan een half woord genoeg
                  • 26903
                  • 1,336 Posts
                  Change your ’$result->fetch’ line to ’$result->fetch(PDO::FETCH_ASSOC)’, get rid of the column list, your fetch is working but is set to PDO::FETCH_BOTH by default, should have mentioned this earlier.
                    Use MODx, or the cat gets it!
                    • 12491
                    • 90 Posts
                    Still no luck Shamblett,
                    the snippet code now,

                    Just don’t get it


                    <?php
                    $total = 0;
                    $hash = $_COOKIE['hash'];
                    $msg = $_GET['msg'];
                    $ok = $_GET['ok'];
                    $date = date("Y-m-d");
                    $query = "SELECT * FROM `modx_cart` WHERE hash = '".$hash."' AND type <> 'P' ORDER BY id ASC";
                    $output .= '<table border="0" width="100%">
                    ';
                    
                    $result = $modx->query( $query );
                    while ($row = $result->fetch(PDO::FETCH_ASSOC)){
                    $output .= '<tr><td>'.$row['article_name'].'</td><td> € '.$row['article_price'].'</td><td><a href="'.$row['id'].'" class="deletefromcart" title="Delete from cart">x</a></td></tr>
                    ';
                    	$total = $total + $row['article_price'];
                    }
                    $output .= '
                    <tr><td colspan="3">................................................................................</td></tr>
                    <tr><td>Total:</td><td>€ '.number_format($total,2).'</td><td> </td></tr>
                    </table>
                    <p> </p>
                    <p class="buy_now_detail_page"><a href="assets/components/msp/pay.php?price='.(100*$total).'&hash='.$hash.'" class="payment" title="MultiSafepay met iDeal" onClick="window.resizeTo(800,800);"><img src="assets/templates/Milky/[[skin]]/skin/button_buy_now_detail_page.png" alt="MultiSafepay met iDeal" /></a></p>
                    ';
                    if (($ok)&&($msg)){
                    $output .= '<p> </p>
                    <h4>'.$msg.'</h4>
                    <p>We zullen uw order zo snel als mogelijk verwerken en versturen.</p>
                    <script>setTimeout("window.close()",6000);</script>';
                    }
                    if ((!($ok))&&($msg)){
                    $output .= '<p> </p>
                    <h4>'.$msg.'</h4>
                    ';
                    }
                    
                    return $output;



                    This peace puts records in the db, maby it needs something else

                    $stmt = "INSERT INTO modx_cart VALUES( NULL, '', '".$content_id."', '".$article_name."', '".$article_price."', '".$article_description."', '".$hash."', '".$number."', '".$date."', '0')";
                    //id, type, content_id, article_name, article_price, article_description, hash, number, date, extra
                    //$result = $modx->db->query( $query );
                      Sommige mensen hebben aan een half woord genoeg
                      • 26903
                      • 1,336 Posts
                      Not sure what the second piece of cod is doing, it just sets string called $stmt, the rest is commented out.
                        Use MODx, or the cat gets it!