Exemplo n.º 1
0
 function voidDeal()
 {
     $db = JFactory::getDBO();
     $option = 'com_enmasse';
     $cid = JRequest::getVar('cid', array(), '', 'array');
     $appication = JFactory::getApplication();
     if ($cid == null) {
         $appication->redirect('index.php?option=' . $option . '&controller=deal', JText::_('CHOOSE_DEAL_TO_VOID'), 'error');
     }
     for ($i = 0; $i < count($cid); $i++) {
         $status = JModel::getInstance('deal', 'enmasseModel')->getStatus($cid[$i]);
         if ($status == "Voided") {
             $appication->redirect('index.php?option=' . $option . '&controller=deal', JText::_('CANNOT_VOID_VOIDED_DEAL_MSG'), 'error');
         } elseif ($status == "Confirmed") {
             $appication->redirect('index.php?option=' . $option . '&controller=deal', JText::_('CANNOT_VOID_CONFIRMED_DEAL'), 'error');
         } elseif ($status == "Pending") {
             $appication->redirect('index.php?option=' . $option . '&controller=deal', JText::_('CANNOT_VOID_PENDING_DEAL'), 'error');
         }
     }
     for ($i = 0; $i < count($cid); $i++) {
         $dealId = $cid[$i];
         $orderItemList = JModel::getInstance('orderItem', 'enmasseModel')->listByPdtIdAndStatus($dealId, "Paid");
         foreach ($orderItemList as $orderItem) {
             EnmasseHelper::orderItemWaitingForRefund($orderItem);
             sleep(1);
         }
         // update status
         JModel::getInstance('deal', 'enmasseModel')->updateStatus($dealId, 'Voided');
         //Integration with point system, refund point automatically if users paid with point
         if (EnmasseHelper::isPointSystemEnabled()) {
             //generate integration class
             $integrationClass = EnmasseHelper::getPointSystemClassFromSetting();
             $integrateFileName = $integrationClass . '.class.php';
             require_once JPATH_SITE . DS . "components" . DS . "com_enmasse" . DS . "helpers" . DS . "pointsystem" . DS . $integrationClass . DS . $integrateFileName;
             $buyerList = EnmasseHelper::getBuyerRefundVoidDeal($dealId);
             $integrationObject = new $integrationClass();
             foreach ($buyerList as $buyer) {
                 $integrationObject->integration($buyer['buyer_id'], 'refunddeal', $buyer['point_used_to_pay']);
             }
         }
     }
     $appication->redirect('index.php?option=' . $option . '&controller=deal', JText::_('VOID_DEAL_SUCCESS_MSG'));
 }