Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2006
    Posts
    308
    Plugin Contributions
    0

    Default getting list of products from last order

    I'm trying to get a list of products ordered on the checkout_success page so I can add some Facebook share buttons for each one. I can do the rest if I can manage to get a list of the products into an array.

    I have this in includes/languages/english/html_includes/mytemplate/define_checkout_success.php


    PHP Code:
    $orders_query "SELECT * FROM " TABLE_ORDERS "
                     WHERE customers_id = :customersID
                     ORDER BY date_purchased DESC LIMIT 1"
    ;
    $orders_query $db->bindVars($orders_query':customersID'$_SESSION['customer_id'], 'integer');
    $orders $db->Execute($orders_query);                 

    $orders_id $orders->fields['orders_id'];
    $products_query "SELECT products_id, products_name
                         FROM " 
    TABLE_ORDERS_PRODUCTS "
                         WHERE orders_id = '
    $orders_id'
                         ORDER BY products_name"
    ;     

    $products $db->Execute($products_query);

    echo 
    '<pre>';
    var_dump($products);
    echo 
    '</pre>'
    I'm getting the below output. It's only returning one product, when the order has two products. Is this the way the db->Execute function works, limiting the results to 1? Is there another way I can get all results?


    object(queryFactoryResult)#23 (5) { ["is_cached"]=> bool(false) ["resource"]=> resource(530) of type (mysql result) ["cursor"]=> int(0) ["EOF"]=> bool(false) ["fields"]=> array(2) { ["products_id"]=> string(4) "1994" ["products_name"]=> string(61) "Widget Product Name" } }

  2. #2
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: getting list of products from last order

    Yes basically. The normal process from that point is to iterate until $products->EOF is true. I have also seen somewhere that it may be possible (future?) To foreach on $products so that do not have to test for the EOF and do not have to remember to MoveNext() on $products.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #3
    Join Date
    Jul 2006
    Posts
    308
    Plugin Contributions
    0

    Default Re: getting list of products from last order

    Thanks, I used Movenext and that's the trick.

  4. #4
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: getting list of products from last order

    Quote Originally Posted by fakeDecoy View Post
    Thanks, I used Movenext and that's the trick.
    $products->MoveNext() will give your second product, but hopefully you employed something like:
    Code:
    while(!$products->EOF) {
    $products_array[] = $products->fields;
    $products->MoveNext();
    }
    Where $products_array is previously declared as an array.

    Then to tell if there are any values stored in the array can simply check the sizeof($products_array) to see if it is >0 which would mean that a value was assigned.

    The important thing to note is that in the OP it was indicated that the test was going to only involve two products in the list. Then without further clarification of what was being done/used, someone not too familiar with the code methodology might think that using MoveNext() one time would be sufficient for all cases and that it wouldn't be a problem if only one item was in the order.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 

Similar Threads

  1. v151 list of products order by id?
    By evilsorcerer1 in forum General Questions
    Replies: 2
    Last Post: 11 Jun 2013, 05:31 AM
  2. Getting products from a different database
    By JohnGullman in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 10 Jan 2010, 03:12 PM
  3. Replies: 1
    Last Post: 23 Jun 2009, 05:00 AM
  4. Getting $ from a CC Order?
    By Skeeball in forum Managing Customers and Orders
    Replies: 2
    Last Post: 1 Jul 2007, 05:53 AM
  5. Credit card number from last order reused
    By DataDeskGuy in forum Managing Customers and Orders
    Replies: 1
    Last Post: 18 Oct 2006, 07:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg