Пример #1
0
 public static function retrieveOrdersForSeller($db, $user_id, $params = array())
 {
     $orderArray = array();
     $select = $db->select();
     $select->from(array('o' => 'order_profile'), 'order_unique_id')->where('uploader_id = ?', $user_id)->group('order_unique_id')->order('ts_created DESC');
     //->order(array( 'product_id DESC', 'ts_created DESC' ));
     //echo $select;
     $idArray = $db->fetchAll($select);
     foreach ($idArray as $k => $v) {
         echo 'key is: ' . $k . ' value is: ' . $v['order_unique_id'] . '<br />';
         $order = new DatabaseObject_Order($db);
         $order->loadOrderByUniqueID($v['order_unique_id']);
         echo 'here at load<br />';
         //$order->load($v['order_id']);
         $order->loadOrderProductsForSeller($user_id);
         $messageThreads = array();
         foreach ($order->products as $k => $v) {
             $MessageSelect = $db->select();
             $MessageSelect->from('sender_message', '*')->where('sender_subject = ? ', 'orderID: ' . $order->order_unique_id)->where('product_id = ?', $v['product_id'])->order('ts_created DESC');
             //echo $MessageSelect.'<br />';
             $productMessageThreads = $db->fetchAll($MessageSelect);
             if (count($productMessageThreads) > 0) {
                 $order->products[$k]['messageThreads'] = $productMessageThreads;
             }
         }
         $orderArray[] = $order;
     }
     return $orderArray;
 }