Пример #1
0
 /**
  * This is a wrapper method for after an orderpayment has been received
  * that performs acts such as:
  * enabling file downloads, removing items from cart,
  * updating product quantities, etc
  *
  * @param $order_id
  * @return unknown_type
  */
 public static function setOrderPaymentReceived($order_id)
 {
     $errors = array();
     $error = false;
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables');
     $order = JTable::getInstance('Orders', 'CitruscartTable');
     $order->load($order_id);
     $lang = JFactory::getLanguage();
     $lang->load('com_citruscart', JPATH_ADMINISTRATOR);
     if (empty($order->order_id)) {
         // TODO we must make sure this class is always instantiated
         $this->setError(JText::_('COM_CITRUSCART_INVALID_ORDER_ID'));
         return false;
     }
     // optionally email the user
     $row = JTable::getInstance('OrderHistory', 'CitruscartTable');
     $row->order_id = $order_id;
     $row->order_state_id = $order->order_state_id;
     $row->notify_customer = Citruscart::getInstance()->get('autonotify_onSetOrderPaymentReceived', '0');
     $row->comments = JText::_('COM_CITRUSCART_PAYMENT_RECEIVED');
     if (!$row->save()) {
         $errors[] = $row->getError();
         $error = true;
     }
     // Fire an onAfterSetOrderPaymentReceived event
     JFactory::getApplication()->triggerEvent('onAfterSetOrderPaymentReceived', array($order_id));
     // Do orderTasks
     CitruscartHelperOrder::doCompletedOrderTasks($order_id);
     if ($error) {
         $this->setError(implode('<br/>', $errors));
         return false;
     }
     return true;
 }
Пример #2
0
 /**
  * This method is updating the all orders on the basis of the action
  * @return void
  */
 function updatebatch()
 {
     $app = JFactory::getApplication();
     $model = $this->getModel($this->get('suffix'));
     // Get the list of selected items and their selected params
     $cids = $app->input->get('cid', array(0), 'array');
     $sendMails = $app->input->get('new_orderstate_notify', array(0), 'array');
     $completeTasks = $app->input->get('completed_tasks', array(0), 'array');
     $states = $app->input->get('new_orderstate_id', array(0), 'array');
     $comments = $app->input->get('new_orderstate_comments', array(0), 'array');
     // for the updation
     $counter = 0;
     foreach ($cids as $orderId) {
         $row = $model->getTable();
         $row->load($orderId);
         $row->order_state_id = $states[$counter];
         $completed_tasks = $completeTasks[$orderId];
         $is_notify = 0;
         if ($completed_tasks == "on" && empty($row->completed_tasks)) {
             Citruscart::load('CitruscartHelperOrder', 'helpers.order');
             CitruscartHelperOrder::doCompletedOrderTasks($row->order_id);
             $row->completed_tasks = 1;
         }
         // saving the row
         if ($row->save()) {
             $model->setId($row->order_id);
             $this->messagetype = 'message';
             $this->message = JText::_('COM_CITRUSCART_ORDER_SAVED');
             $history = JTable::getInstance('OrderHistory', 'CitruscartTable');
             $history->order_id = $row->order_id;
             $history->order_state_id = $row->order_state_id;
             if ($sendMails[$orderId] == "on") {
                 $is_notify = 1;
             }
             $history->notify_customer = $is_notify;
             $history->comments = $comments[$counter];
             if (!$history->save()) {
                 $this->setError($history->getError());
                 $this->messagetype = 'notice';
                 $this->message .= " :: " . JText::_('COM_CITRUSCART_ORDERHISTORY_SAVE_FAILED');
             }
             JFactory::getApplication()->triggerEvent('onAfterUpdateStatus' . $this->get('suffix'), array($row));
         } else {
             $this->messagetype = 'notice';
             $this->message = JText::_('COM_CITRUSCART_SAVE_FAILED') . " - " . $row->getError();
         }
         $counter++;
     }
     $model->clearCache();
     $redirect = "index.php?option=com_citruscart";
     $redirect .= '&view=' . $this->get('suffix');
     $redirect = JRoute::_($redirect, false);
     $this->setRedirect($redirect, $this->message, $this->messagetype);
 }