Esempio n. 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_tienda/tables');
     $order = JTable::getInstance('Orders', 'TiendaTable');
     $order->load($order_id);
     $lang = JFactory::getLanguage();
     $lang->load('com_tienda', JPATH_ADMINISTRATOR);
     if (empty($order->order_id)) {
         // TODO we must make sure this class is always instantiated
         $this->setError(JText::_('COM_TIENDA_INVALID_ORDER_ID'));
         return false;
     }
     // optionally email the user
     $row = JTable::getInstance('OrderHistory', 'TiendaTable');
     $row->order_id = $order_id;
     $row->order_state_id = $order->order_state_id;
     $row->notify_customer = Tienda::getInstance()->get('autonotify_onSetOrderPaymentReceived', '0');
     $row->comments = JText::_('COM_TIENDA_PAYMENT_RECEIVED');
     if (!$row->save()) {
         $errors[] = $row->getError();
         $error = true;
     }
     // Fire an onAfterSetOrderPaymentReceived event
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onAfterSetOrderPaymentReceived', array($order_id));
     // Do orderTasks
     TiendaHelperOrder::doCompletedOrderTasks($order_id);
     if ($error) {
         $this->setError(implode('<br/>', $errors));
         return false;
     }
     return true;
 }
Esempio n. 2
0
 /**
  * This method is updating the all orders on the basis of the action
  * @return void
  */
 function updatebatch()
 {
     $model = $this->getModel($this->get('suffix'));
     // Get the list of selected items and their selected params
     $cids = JRequest::getVar('cid', array(0), 'post', 'array');
     $sendMails = JRequest::getVar('new_orderstate_notify', array(0), 'post', 'array');
     $completeTasks = JRequest::getVar('completed_tasks', array(0), 'post', 'array');
     $states = JRequest::getVar('new_orderstate_id', array(0), 'post', 'array');
     $comments = JRequest::getVar('new_orderstate_comments', array(0), 'post', '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)) {
             Tienda::load('TiendaHelperOrder', 'helpers.order');
             TiendaHelperOrder::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_TIENDA_ORDER_SAVED');
             $history = JTable::getInstance('OrderHistory', 'TiendaTable');
             $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_TIENDA_ORDERHISTORY_SAVE_FAILED');
             }
             $dispatcher = JDispatcher::getInstance();
             $dispatcher->trigger('onAfterUpdateStatus' . $this->get('suffix'), array($row));
         } else {
             $this->messagetype = 'notice';
             $this->message = JText::_('COM_TIENDA_SAVE_FAILED') . " - " . $row->getError();
         }
         $counter++;
     }
     $model->clearCache();
     $redirect = "index.php?option=com_tienda";
     $redirect .= '&view=' . $this->get('suffix');
     $redirect = JRoute::_($redirect, false);
     $this->setRedirect($redirect, $this->message, $this->messagetype);
 }