Пример #1
0
 /**
  * Validate comment and call postComment function, or
  * adds errors into a customer session if some error occurs
  * @param AW_Rma_Model_Entity $request
  * @param boolean $guestMode - Is comment posted by guest
  * @return boolean
  */
 public static function saveComment($request, $guestMode = FALSE)
 {
     $_okFlag = TRUE;
     $_rmaRequest = Mage::getModel('awrma/entity');
     if ($guestMode) {
         $_rmaRequest->loadByExternalLink($request->getParam('id'));
     } else {
         $_rmaRequest->load($request->getParam('id'));
     }
     if ($_rmaRequest->getData() != array()) {
         if (!in_array($_rmaRequest->getStatus(), Mage::helper('awrma/status')->getResolvedStatuses())) {
             $_data = array();
             $_data['text'] = $request->getParam('comment');
             if ($_data['text']) {
                 if (isset($_FILES['attachedfile']['name']) && $_FILES['attachedfile']['name']) {
                     if (!in_array(Mage::helper('awrma/files')->getExtension($_FILES['attachedfile']['name']), Mage::helper('awrma/config')->getForbiddenExtensions())) {
                         if ($_FILES['attachedfile']['size'] <= Mage::helper('awrma/config')->getMaxAttachmentsSize() && $_FILES['attachedfile']['size'] > 0) {
                             if ($_FILES['attachedfile']['error'] == UPLOAD_ERR_OK) {
                                 try {
                                     $uploader = new Varien_File_Uploader('attachedfile');
                                     $uploader->setAllowedExtensions(null)->setAllowRenameFiles(TRUE)->setAllowCreateFolders(TRUE)->setFilesDispersion(FALSE);
                                     $result = $uploader->save(Mage::helper('awrma/files')->getPath(), $_FILES['attachedfile']['name']);
                                     $_data['attachments'] = $result['file'];
                                 } catch (Exception $ex) {
                                     $_okFlag = FALSE;
                                     self::_getSession()->addError($ex->getMessage());
                                 }
                             } else {
                                 $_okFlag = FALSE;
                                 self::_getSession()->addError(Mage::helper('awrma')->__('Some error occurs when uploading file'));
                             }
                         } else {
                             $_okFlag = FALSE;
                             self::_getSession()->addError(Mage::helper('awrma')->__('Maximal allowed attachment size is ' . floor(Mage::helper('awrma/config')->getMaxAttachmentsSize() / 1024) . ' kb'));
                         }
                     } else {
                         $_okFlag = FALSE;
                         self::_getSession()->addError(Mage::helper('awrma')->__('Forbidden file extension'));
                     }
                 }
                 if ($_okFlag) {
                     $_data['owner'] = AW_Rma_Model_Source_Owner::CUSTOMER;
                     self::postComment($_rmaRequest->getId(), $_data['text'], $_data);
                     //Clear form data in session
                     self::_getSession()->getAWRMACommentFormData(TRUE);
                     self::_getSession()->addSuccess(Mage::helper('awrma')->__('Comment successfully added'));
                     return $guestMode ? $_rmaRequest->getExternalLink() : $_rmaRequest->getId();
                 }
             } else {
                 $_okFlag = FALSE;
                 self::_getSession()->addError(Mage::helper('awrma')->__('Comment text can\'t be empty'));
             }
         } else {
             $_okFlag = FALSE;
             self::_getSession()->addError(Mage::helper('awrma')->__('You can\'t comment resolved Return'));
         }
     } else {
         $_okFlag = FALSE;
         self::_getSession()->addError(Mage::helper('awrma')->__('Can\'t load Return request'));
     }
     self::_getSession()->setAWRMACommentFormData($request->getParams());
     return $_okFlag;
 }
Пример #2
0
 /**
  * Validate RMA request and adds it to database when all is good
  * @param AW_Rma_Model_Entity $request
  * @param boolean $guestMode
  * @return boolean
  */
 public static function save($request, $guestMode = FALSE)
 {
     $_data = array();
     $_addNewEntityFlag = TRUE;
     $_data['order_id'] = $request->getParam('order');
     //Checking OrderID
     if ($_data['order_id']) {
         //Trying to load order
         $_order = Mage::getModel('sales/order')->loadByIncrementId($_data['order_id']);
         if (!($_order->getData() == array())) {
             //Getting order items
             $_orderItems = $request->getParam('orderitems');
             if (Mage::helper('awrma/config')->getAllowPerOrderRMA() && count($_orderItems) || !Mage::helper('awrma/config')->getAllowPerOrderRMA()) {
                 //Gets order items from post if per-order item RMA is allowed
                 //and gets it directly from order otherwise
                 if (!Mage::helper('awrma/config')->getAllowPerOrderRMA()) {
                     $_orderItems = array();
                     foreach ($_order->getItemsCollection() as $_item) {
                         $_orderItems[$_item->getId()] = $_item->getQtyOrdered() * 1;
                     }
                 } else {
                     //Checking items count
                     foreach ($_order->getItemsCollection() as $_item) {
                         if (isset($_orderItems[$_item->getId()]) && ($_orderItems[$_item->getId()] < 1 || $_orderItems[$_item->getId()] > $_item->getQtyOrdered() * 1)) {
                             $_addNewEntityFlag = FALSE;
                             self::_getSession()->addError(Mage::helper('awrma')->__('Wrong quantity for ' . $_item->getName()));
                         }
                     }
                 }
                 if ($_addNewEntityFlag) {
                     $_data['order_items'] = $_orderItems;
                     //Checking package opened and request type values
                     if (!(Mage::getModel('awrma/source_packageopened')->getOption($request->getParam('packageopened')) === FALSE)) {
                         $_data['package_opened'] = $request->getParam('packageopened');
                         $_data['request_type'] = $request->getParam('requesttype') ? $request->getParam('requesttype') : null;
                         $_data['created_at'] = date(AW_Rma_Model_Mysql4_Entity::DATETIMEFORMAT, time());
                         $_data['status'] = Mage::helper('awrma/status')->getPendingApprovalStatusId();
                         $_data['external_link'] = Mage::helper('awrma')->getExtLink();
                         if ($guestMode) {
                             $_data['customer_email'] = $_order->getCustomerEmail();
                             $_data['customer_name'] = $_order->getShippingAddress()->getFirstname() . ' ' . $_order->getShippingAddress()->getLastname();
                         } else {
                             $_data['customer_name'] = self::_getSession()->getCustomer()->getFirstname() . ' ' . self::_getSession()->getCustomer()->getLastname();
                             $_data['customer_email'] = self::_getSession()->getCustomer()->getEmail();
                             $_data['customer_id'] = self::_getSession()->getCustomer()->getId();
                         }
                         $rmaEntity = Mage::getModel('awrma/entity');
                         $rmaEntity->setData($_data);
                         $rmaEntity->save();
                         if ($request->getParam('additionalinfo')) {
                             //save comment
                             $_data['owner'] = AW_Rma_Model_Source_Owner::CUSTOMER;
                             Mage::helper('awrma/comments')->postComment($rmaEntity->getId(), $request->getParam('additionalinfo'), $_data, FALSE);
                         }
                         Mage::getModel('awrma/notify')->notifyNew($rmaEntity, $request->getParam('additionalinfo'));
                         //Clear form data stored in session
                         self::_getSession()->getAWRMAFormData(TRUE);
                         self::_getSession()->addSuccess(Mage::helper('awrma')->__('New Return request has been successfully added'));
                         self::_getSession()->addNotice(Mage::helper('awrma')->__('Your Return is currently waiting for approval'));
                         return $guestMode ? $rmaEntity->getExternalLink() : $rmaEntity->getId();
                     } else {
                         $_addNewEntityFlag = FALSE;
                         self::_getSession()->addError(Mage::helper('awrma')->__('Wrong form data'));
                     }
                 }
             } else {
                 $_addNewEntityFlag = FALSE;
                 self::_getSession()->addError(Mage::helper('awrma')->__('No items for request specified'));
             }
         } else {
             $_addNewEntityFlag = FALSE;
             self::_getSession()->addError(Mage::helper('awrma')->__('Wrong order ID'));
         }
     } else {
         $_addNewEntityFlag = FALSE;
         self::_getSession()->addError(Mage::helper('awrma')->__('Wrong form data'));
     }
     self::_getSession()->setAWRMAFormData($request->getParams());
     return $_addNewEntityFlag;
 }
Пример #3
0
 /**
  * Check changes in request and call some functions on it
  * @param AW_Rma_Model_Entity $rmaRequest
  * @param string $commentText
  * @param boolean $isFrontend
  * @return AW_Rma_Model_Notify
  */
 public function checkChanges($rmaRequest, $commentText = null, $isFrontend = FALSE)
 {
     if ($this->_isGenerallyEnabled()) {
         if ($rmaRequest->getData('status') != $rmaRequest->getOrigData('status')) {
             # Status changes
             $this->setFlagStatusChanged(true);
             $this->_notifyByStatus($rmaRequest, $commentText, $isFrontend);
         } elseif ($commentText) {
             # Comment added without status change
             $this->notifyAboutComment($rmaRequest, $commentText, $isFrontend);
         }
     }
     return $this;
 }