zencart订单总体结构分析

2012-05-24 11:50 来源:www.chinab4c.com 作者:zencart专家

    zencart的订单结构,非常清晰。zen cart订单系统,他总共分成了订单总的基本信息表zen_orders,订单商品表zen_orders_products,订单商品表的一些属性规格zen_orders_products_attributes,订单状态表zen_orders_status,以及订单状态的操作历史记录zen_orders_status_history,订单的统计金额信息表zen_orders_total.我们来分析下order.php,这里就是处理订单系统的代码。

   $this->info = array();
    $this->totals = array();
    $this->products = array();
    $this->customer = array();
    $this->delivery = array();

    从这里可以看出来,info数组表示了订单中基本信息.total表示是zen cart订单信息的金额,products是该订单的商品信息,,customer为该zen cart订单的订购人基本信息。delivery为该订单中的配送信息。

   zen cart取得订单的信息都是通过order类里的function query($order_id)方法来实现的。他的大部分基本信息都是在这个SQL查询里面完成的。

   $order_query = "select customers_id, customers_name, customers_company,
                         customers_street_address, customers_suburb, customers_city,
                         customers_postcode, customers_state, customers_country,
                         customers_telephone, customers_email_address, customers_address_format_id,
                         delivery_name, delivery_company, delivery_street_address, delivery_suburb,
                         delivery_city, delivery_postcode, delivery_state, delivery_country,
                         delivery_address_format_id, billing_name, billing_company,
                         billing_street_address, billing_suburb, billing_city, billing_postcode,
                         billing_state, billing_country, billing_address_format_id,
                         payment_method, payment_module_code, shipping_method, shipping_module_code,
                         coupon_code, cc_type, cc_owner, cc_number, cc_expires, currency, currency_value,
                         date_purchased, orders_status, last_modified, order_total, order_tax, ip_address
                        from " . TABLE_ORDERS . "
                        where orders_id = '" . (int)$order_id . "'";

    $order = $db->Execute($order_query);

   以下代码是取得zen cart订单的商品总金额信息。

$totals_query = "select title, text, class
                         from " . TABLE_ORDERS_TOTAL . "
                         where orders_id = '" . (int)$order_id . "'
                         order by sort_order";

    $totals = $db->Execute($totals_query);

    while (!$totals->EOF) {


      if ($totals->fields['class'] == 'ot_coupon') {
        $coupon_link_query = "SELECT coupon_id
                from " . TABLE_COUPONS . "
                where coupon_code ='" . $order->fields['coupon_code'] . "'";
        $coupon_link = $db->Execute($coupon_link_query);
        $zc_coupon_link = '<a href="javascript:couponpopupWindow(\'' . zen_href_link(FILENAME_POPUP_COUPON_HELP, 'cID=' . $coupon_link->fields['coupon_id']) . '\')">';
      }
      $this->totals[] = array('title' => ($totals->fields['class'] == 'ot_coupon' ? $zc_coupon_link . $totals->fields['title'] . '</a>' : $totals->fields['title']),
                              'text' => $totals->fields['text'],
                              'class' => $totals->fields['class']);
      $totals->MoveNext();
    }

     来源:http://www.chinab4c.com