Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2005
    Posts
    246
    Plugin Contributions
    0

    Default Has the customer purchased a certain item?

    I will be using php in ezpages to write some custom pages and I want to know if the signed in customer (if they are signed in) has purchase a particular item.

    What is the best way to get that information from the database.

    I figure it's like this, but I don't actually know the table and field names and my mySQL skills are not as strong as I'd like.

    select ORDER NUMBER and ORDER STATUS from ORDERS where CUSTOMERID is CURRENTCUSTOMER and ITEMID is MY_SPECIFIED_ID

    and I need a little help using zen's db class to make it work.

  2. #2
    Join Date
    Aug 2005
    Location
    Arizona
    Posts
    27,761
    Plugin Contributions
    9

    Default Re: Has the customer purchased a certain item?

    Should already be done...
    Sign in as a customer with a purchase history and select "my account"
    Pick from that code for your page
    Zen-Venom Get Bitten

  3. #3
    Join Date
    Feb 2005
    Posts
    246
    Plugin Contributions
    0

    Default Re: Has the customer purchased a certain item?

    Here's what worked for me, Not fully tested, but quickly tested and seemed to be okay.

    PHP Code:
    <?php
    //referenced these files to get the right code bits.
    //includes/templates/template_default/templates/tpl_account_default.php -> 
    //includes/modules/pages/account/header_php.php -> 

    $orders_query "SELECT o.orders_id, o.date_purchased, o.delivery_name,
                            o.delivery_country, o.billing_name, o.billing_country,
                            ot.text as order_total, s.orders_status_name
                     FROM   " 
    TABLE_ORDERS " o, " TABLE_ORDERS_TOTAL "  ot, " TABLE_ORDERS_STATUS " s
                     WHERE  o.customers_id = :customersID
                     AND    o.orders_id = ot.orders_id
                     AND    ot.class = 'ot_total'
                     AND    o.orders_status = s.orders_status_id
                     AND   s.language_id = :languagesID
                     ORDER BY orders_id DESC LIMIT 3"
    ;

    $orders_query $db->bindVars($orders_query':customersID'$_SESSION['customer_id'], 'integer');
    $orders_query $db->bindVars($orders_query':languagesID'$_SESSION['languages_id'], 'integer');
    $orders $db->Execute($orders_query);

    $ordersArray = array();
    while (!
    $orders->EOF) {
      if (
    zen_not_null($orders->fields['delivery_name'])) {
        
    $order_name $orders->fields['delivery_name'];
        
    $order_country $orders->fields['delivery_country'];
      } else {
        
    $order_name $orders->fields['billing_name'];
        
    $order_country $orders->fields['billing_country'];
      }

      
    $ordersArray[] = array('orders_id'=>$orders->fields['orders_id'],
      
    'date_purchased'=>$orders->fields['date_purchased'],
      
    'order_name'=>$order_name,
      
    'order_country'=>$order_country,
      
    'orders_status_name'=>$orders->fields['orders_status_name'],
      
    'order_total'=>$orders->fields['order_total']
      );

      
    $orders->MoveNext();
    }
    ?>
    <?php
      $special_item_id
    =1;
      
    $special_ordered=FALSE;
      foreach(
    $ordersArray as $orders) {
       
    $current_order_id=$orders['orders_id'];
       
    //$order_item_query="SELECT product_id from zen_orders_products WHERE order_id = $current_order_id";
       
    $current_product_id=$db->Execute($orders_query);
       if (
    $current_product_id==$special_item_id){$special_ordered=TRUE;}   
      }
    if(
    $special_ordered){echo('Welcome to our Special Page.');}else{echo('Please order our Special Item.');}
    ?>
    Last edited by TecBrat; 23 Feb 2010 at 09:49 PM. Reason: Fix php Error

  4. #4
    Join Date
    Feb 2005
    Posts
    246
    Plugin Contributions
    0

    Default Re: Has the customer purchased a certain item?

    I know I could have cleaned that up a bit, but I just copied and pasted the first part right out of header_php.php

  5. #5
    Join Date
    Jan 2004
    Posts
    482
    Plugin Contributions
    0

    Default Re: Has the customer purchased a certain item?

    Quote Originally Posted by TecBrat View Post
    I know I could have cleaned that up a bit, but I just copied and pasted the first part right out of header_php.php
    Would we be able to use this code right on a product page to show the customer if they have already purchased the item they are currently looking at??? If so ... that would rock!!

  6. #6
    Join Date
    Feb 2005
    Posts
    246
    Plugin Contributions
    0

    Default Re: Has the customer purchased a certain item?

    ksoup,

    This might not be the answer you hoped for, but all I can say is "Give it a try". That's how I learn.

 

 

Similar Threads

  1. Replies: 1
    Last Post: 1 Jun 2011, 07:58 PM
  2. Settting the price of 12+ items cheaper than buying a single item on a certain item
    By casperaustin in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 17 Sep 2010, 01:07 AM
  3. Checking that a necessary item has been purchased
    By deviouscow in forum Setting Up Categories, Products, Attributes
    Replies: 2
    Last Post: 20 May 2010, 01:19 AM
  4. Is there a mod out that has like an also purchased or recommened item
    By rickiesdiscount in forum General Questions
    Replies: 2
    Last Post: 3 Aug 2008, 02:42 PM
  5. Coupon for Free Item if certain amount purchased
    By brimsjewelry in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 5
    Last Post: 11 Dec 2006, 10:47 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