Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default php help please - set variable based on items on order

    Hi guys, one for the php gurus, hoping someone will be able to advise a quick lightweight solution.

    I wish to set a variable to true if the following conditions on a specific order exists:

    NUMBER of Products ordered = 1 & Quantity of that product ordered = 1

    Order ID will obviously be known in this script so based on that I just want to do a quick check for the condition and if true set the variable.

    Cheers in advance.

    Phil
    Phil Rogers
    A problem shared is a problem solved.

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,502
    Plugin Contributions
    88

    Default Re: php help please - set variable based on items on order

    I've checked this out in a couple of scenarios and it seems to work!
    Code:
    $order_check = $db->Execute ("SELECT count(*) as total, products_quantity FROM" . TABLE_ORDERS_PRODUCTS . " WHERE orders_id = $orders_id");
    $one_product_ordered = (!$order_check->EOF && $order_check->fields['total'] == 1 && $order_check->fields['products_quantity'] == 1);

  3. #3
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default Re: php help please - set variable based on items on order

    I was just about to post my poor attempt at the logic, yours look much neater! thank you :)

    PHP Code:
    $restult1 SELECT count(*) as count FROM `orders_productsWHERE `orders_id` = 14532;

    if 
    $result1 {  

    $result2 SELECT `products_quantityFROM `orders_productsWHERE `orders_id` = 14532;

    if 
    $result2 

    $oneItemOrder true;

    }


    Phil Rogers
    A problem shared is a problem solved.

  4. #4
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default Re: php help please - set variable based on items on order

    Quote Originally Posted by lat9 View Post
    I've checked this out in a couple of scenarios and it seems to work!
    Code:
    $order_check = $db->Execute ("SELECT count(*) as total, products_quantity FROM" . TABLE_ORDERS_PRODUCTS . " WHERE orders_id = $orders_id");
    $one_product_ordered = (!$order_check->EOF && $order_check->fields['total'] == 1 && $order_check->fields['products_quantity'] == 1);
    thanks again for this, apologies as its been way to long since I've played with php. am I right in assuming that if I want to do something based on this I can simply use:

    PHP Code:
    if ($one_product_ordered) {
    do 
    something

    or does it need to be

    PHP Code:
    if ($one_product_ordered true) {
    do 
    something

    ?
    Phil Rogers
    A problem shared is a problem solved.

  5. #5
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,502
    Plugin Contributions
    88

    Default Re: php help please - set variable based on items on order

    You're welcome!

    [edit, responding to additional question] Either of the code fragments that you posted will work, making sure to change the 2nd one to
    Code:
    if ($one_product_ordered == true) {
    do something
    }
    Last edited by lat9; 7 Aug 2014 at 04:57 PM.

  6. #6
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default Re: php help please - set variable based on items on order

    perfect thanks. Once I have worked out the rest of my code that goes in the do something bit I will report back and let you know how I got on :)
    Phil Rogers
    A problem shared is a problem solved.

  7. #7
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default Re: php help please - set variable based on items on order

    Quote Originally Posted by lat9 View Post
    I've checked this out in a couple of scenarios and it seems to work!
    Code:
    $order_check = $db->Execute ("SELECT count(*) as total, products_quantity FROM" . TABLE_ORDERS_PRODUCTS . " WHERE orders_id = $orders_id");
    $one_product_ordered = (!$order_check->EOF && $order_check->fields['total'] == 1 && $order_check->fields['products_quantity'] == 1);
    WORKS PERFECTLY! thank you so much :)
    Phil Rogers
    A problem shared is a problem solved.

  8. #8
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default Re: php help please - set variable based on items on order

    Hi lat9.

    So I have everything working perfectly on a test file. However, when I include the code to the checkout process I get the following error:

    [13-Aug-2014 16:58:02 UTC] PHP Fatal error: Call to a member function Execute() on a non-object in /home/site/public_html/includes/mycode-includes.php on line 285

    I include the code using the following:
    include('includes/mycode-includes.php');

    this file is included directly after the sending of emails in the includes/classes/order.php file

    This works for my code I already had previously but it doesn't seem to like the new code.

    Its worth noting that code I previously used never used the execute function hence why I haven't had this error before. When I look at the code in the order.php file there are many times it is using the Execute function so I am a little confused why its not liking it?

    Any ideas?

    Thanks

    Phil
    Phil Rogers
    A problem shared is a problem solved.

  9. #9
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default Re: php help please - set variable based on items on order

    I have as a test simply added this line only directly to the includes/classes/order.php file

    $order_check = $db->Execute ("SELECT count(*) as total, products_quantity FROM" . TABLE_ORDERS_PRODUCTS . " WHERE orders_id = $orders_id");

    I still get the error:
    [13-Aug-2014 17:37:17 UTC] PHP Fatal error: Call to a member function Execute() on a non-object in /home/site/public_html/includes/classes/order.php on line 1106

    I am confused
    Phil Rogers
    A problem shared is a problem solved.

  10. #10
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default Re: php help please - set variable based on items on order

    also worth noting that actually my code is included in the function send_order_email

    I notice that at the top of the function there is the following:
    global $currencies, $order_totals;

    actually when I previously said other instances of the db->Execute were being used, I've noticed this are obviously within other functions. An looking at these functions these actually have this at the top:
    global $db;

    So am I right in thinking that is I amend the function send_order_email first part to:
    global $currencies, $order_totals, $db;

    then it should resolve my problem???
    Phil Rogers
    A problem shared is a problem solved.

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 6
    Last Post: 29 Aug 2012, 12:28 PM
  2. Which php variable calls for Total Items in Cart?
    By samar777 in forum General Questions
    Replies: 8
    Last Post: 24 Sep 2010, 09:59 PM
  3. Modify items in existing order or variable pricing
    By DocRocks in forum General Questions
    Replies: 5
    Last Post: 29 Oct 2009, 11:21 PM
  4. help finding Category Variable please :)
    By ink in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 15 Aug 2009, 01:02 PM

Bookmarks

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
Zen-Cart, Internet Selling Services, Klamath Falls, OR