Exemple #1
0
 /**
  * Returns history of client orders. Orders are sorted most recent first.
  *
  * @param string $ps_order_type Type of order to return history for. L=loans, O=sales orders. If set to any other value all types of orders will be returned.
  * @return array List of orders
  */
 public function getClientHistory($ps_order_type)
 {
     if (!$this->getPrimaryKey()) {
         return null;
     }
     $vn_object_id = $this->getPrimaryKey();
     $ps_order_type = strtoupper($ps_order_type);
     $va_options = array();
     if (!in_array($ps_order_type, array('O', 'L'))) {
         $ps_order_type = null;
     } else {
         $va_options['type'] = $ps_order_type;
     }
     $va_orders = ca_commerce_orders::getUsageOfItemInOrders($vn_object_id, $va_options);
     $va_history = array();
     foreach ($va_orders as $vn_id => $va_order) {
         $va_order['loan_checkout_date_raw'] = $va_order['loan_checkout_date'];
         $va_order['loan_checkout_date'] = caGetLocalizedDate($va_order['loan_checkout_date'], array('timeOmit' => true, 'dateFormat' => 'delimited'));
         $va_order['loan_due_date_raw'] = $va_order['loan_due_date'];
         $va_order['loan_due_date'] = $va_order['loan_due_date'] ? caGetLocalizedDate($va_order['loan_due_date'], array('timeOmit' => true, 'dateFormat' => 'delimited')) : '';
         $va_order['loan_return_date_raw'] = $va_order['loan_return_date'];
         $va_order['loan_return_date'] = $va_order['loan_return_date'] ? caGetLocalizedDate($va_order['loan_return_date'], array('timeOmit' => true, 'dateFormat' => 'delimited')) : '';
         $va_order['order_number'] = ca_commerce_orders::generateOrderNumber($va_order['order_id'], $va_order['created_on']);
         $va_history[$va_order['loan_checkout_date']] = $va_order;
     }
     ksort($va_history);
     return array_reverse($va_history);
 }
 public function update($pa_options = null)
 {
     if (!$this->_preSaveActions()) {
         return false;
     }
     $vn_old_status = $this->getOriginalValue('order_status');
     $vn_old_ship_date = $this->getOriginalValue('shipping_date');
     $vn_old_shipped_on_date = $this->getOriginalValue('shipped_on_date');
     // Move order status automatically to reflect business logic
     switch ($this->get('order_status')) {
         case 'PROCESSED':
             if ($this->get('shipped_on_date') && $this->changed('shipped_on_date') && !$this->requiresDownload()) {
                 // If it shipped and there's nothing left to fulfill by download then ship status to "complete"
                 $this->set('order_status', 'COMPLETED');
             }
             break;
         case 'AWAITING_PAYMENT':
             if ($this->get('payment_received_on') && $this->changed('payment_received_on') || $this->getTotal() == 0) {
                 if ($this->get('order_type') == 'L') {
                     // LOANS
                     $this->set('order_status', 'PROCESSED');
                 } else {
                     // SALES ORDERS
                     // If it paid for then flip status to "PROCESSED" (if it's all ready to go) or "PROCESSED_AWAITING_DIGITIZATION" if stuff needs to be digitized
                     if (sizeof($va_items_with_no_media = $this->itemsWithNoDownloadableMedia()) > 0) {
                         $this->set('order_status', 'PROCESSED_AWAITING_DIGITIZATION');
                     } else {
                         // If "original" files are missing then mark as PROCESSED_AWAITING_MEDIA_ACCESS
                         if (sizeof($va_items_missing_media = $this->itemsMissingDownloadableMedia('original'))) {
                             $this->set('order_status', 'PROCESSED_AWAITING_MEDIA_ACCESS');
                         } else {
                             $this->set('order_status', 'PROCESSED');
                         }
                     }
                 }
             }
             break;
     }
     $vb_status_changed = $this->changed('order_status');
     $this->set('order_number', ca_commerce_orders::generateOrderNumber($this->getPrimaryKey(), $this->get('created_on', array('GET_DIRECT_DATE' => true))));
     if ($vn_rc = parent::update($pa_options)) {
         if ($vb_status_changed) {
             $this->sendStatusChangeEmailNotification($vn_old_status, $vn_old_ship_date, $vn_old_shipped_on_date);
         }
         if (in_array($this->get('order_status'), array('PROCESSED', 'PROCESSED_AWAITING_DIGITIZATION', 'PROCESSED_AWAITING_MEDIA_ACCESS', 'COMPLETED'))) {
             // Delete originating set if configured to do so
             if ($this->opo_client_services_config->get('set_disposal_policy') == 'DELETE_WHEN_ORDER_PROCESSED') {
                 $t_trans = new ca_commerce_transactions($this->get('transaction_id'));
                 if ($t_trans->getPrimaryKey()) {
                     $t_set = new ca_sets($t_trans->get('set_id'));
                     if ($t_set->getPrimaryKey()) {
                         $t_set->setMode(ACCESS_WRITE);
                         $t_set->delete(true);
                     }
                 }
             }
         }
     }
     return $vn_rc;
 }