/** * Post a comment action */ public function postAction() { $challenge = $this->getRequest()->getPost('recaptcha_challenge_field'); $field = $this->getRequest()->getPost('recaptcha_response_field'); $post = $this->getPost(); $data = new Varien_Object($this->getRequest()->getPost()); try { Mage::getSingleton('wordpress/session')->setPostCommentData($post, $data->getAuthor(), $data->getEmail(), $data->getUrl(), $data->getComment()); if (Mage::helper('wordpress/recaptcha')->isEnabled()) { if (!Mage::helper('wordpress/recaptcha')->isValidValue($challenge, $field, true)) { throw new Exception($this->getCaptchaErrorMessage()); } } $comment = $post->postComment($data->getAuthor(), $data->getEmail(), $data->getUrl(), $data->getComment()); if (!$comment) { throw new Exception($this->getCommentErrorMessage()); } Mage::getSingleton('wordpress/session')->removePostCommentData($post); Mage::getSingleton('core/session')->addSuccess($this->__($this->getCommentSuccessMessage())); } catch (Exception $e) { Mage::getSingleton('core/session')->addError($this->__($e->getMessage())); } $this->_redirectUrl($post->getPermalink()); }
public function postAction() { $post = $this->getRequest()->getPost(); if ($post) { $translate = Mage::getSingleton('core/translate'); /* @var $translate Mage_Core_Model_Translate */ $translate->setTranslateInline(false); try { $postObject = new Varien_Object(); $postObject->setData($post); $error = false; if (!Zend_Validate::is(trim($post['name']), 'NotEmpty')) { $error = true; } if (!Zend_Validate::is(trim($post['comment']), 'NotEmpty')) { $error = true; } if (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) { $error = true; } if (Zend_Validate::is(trim($post['hideit']), 'NotEmpty')) { $error = true; } $akismet = Mage::getSingleton('mgt_akismet/akismet'); if ($akismet->isActive()) { $data = array('name' => $postObject->getName(), 'email' => $postObject->getEmail(), 'comment' => $postObject->getComment()); if ($akismet->isSpam($data)) { $error = true; } } if ($error) { throw new Exception(); } $mailTemplate = Mage::getModel('core/email_template'); /* @var $mailTemplate Mage_Core_Model_Email_Template */ $mailTemplate->setDesignConfig(array('area' => 'frontend'))->setReplyTo($post['email'])->sendTransactional(Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE), Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER), Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT), null, array('data' => $postObject)); if (!$mailTemplate->getSentSuccess()) { throw new Exception(); } $translate->setTranslateInline(true); Mage::getSingleton('customer/session')->addSuccess(Mage::helper('contacts')->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.')); $this->_redirect('*/*/'); return; } catch (Exception $e) { $translate->setTranslateInline(true); Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('Unable to submit your request. Please, try again later')); $this->_redirect('*/*/'); return; } } else { $this->_redirect('*/*/'); } }
/** * Creates Credit Memo * * @param mixed $returns * @return array */ public function returnPush($returns) { if (isset($returns['records'])) { $returns = $returns['records']; } $result = array(); $result['records'] = array(); foreach ($returns as $return) { $returnObj = new Varien_Object($return); Mage::dispatchEvent('retailops_return_push_record', array('record' => $returnObj)); $order = Mage::getModel('sales/order')->loadByIncrementId($returnObj->getOrderIncrementId()); $result['records'][] = $this->create($order, $returnObj->getCreditmemoData(), $returnObj->getComment(), $returnObj->getNotifyCustomer(), $returnObj->getIncludeComment(), $returnObj->getRefundToStoreCredit()); } return $result; }
/** * Run PEAR command with html output console style * * @param array|Varien_Object $runParams command, options, params, * comment, success_callback, failure_callback */ public function runHtmlConsole($runParams) { ob_implicit_flush(); $fe = $this->getFrontend(); $oldLogStream = $fe->getLogStream(); $fe->setLogStream('stdout'); if ($runParams instanceof Varien_Object) { $run = $runParams; } elseif (is_array($runParams)) { $run = new Varien_Object($runParams); } elseif (is_string($runParams)) { $run = new Varien_Object(array('title' => $runParams)); } else { throw Varien_Exception("Invalid run parameters"); } ?> <html><head><style type="text/css"> body { margin:0px; padding:3px; background:black; color:white; } pre { font:normal 11px Courier New, serif; color:#2EC029; } </style></head><body> <?php echo "<pre>" . $run->getComment(); if ($command = $run->getCommand()) { $result = $this->run($command, $run->getOptions(), $run->getParams()); if ($result instanceof PEAR_Error) { echo "\r\n\r\nPEAR ERROR: " . $result->getMessage(); } echo '</pre><script type="text/javascript">'; if ($result instanceof PEAR_Error) { if ($callback = $run->getFailureCallback()) { call_user_func_array($callback, array($result)); } } else { if ($callback = $run->getSuccessCallback()) { call_user_func_array($callback, array($result)); } } echo '</script>'; } else { $result = false; echo '</pre>'; } ?> <script type="text/javascript"> if (!auto_scroll) { var auto_scroll = window.setInterval("document.body.scrollTop+=2", 10); } </script> </body></html> <?php $fe->setLogStream($oldLogStream); return $result; }
/** * Creates shipment, adds track numbers, creates new invoices * * @param $shipments array * @return array */ public function shipmentPush($shipments) { $fullResult = array(); $fullResult['records'] = array(); if (isset($shipments['records'])) { $shipments = $shipments['records']; } foreach ($shipments as $shipmentData) { $result = array(); try { $shipment = new Varien_Object($shipmentData); Mage::dispatchEvent('retailops_shipment_process_before', array('record' => $shipment)); $result['order_increment_id'] = $shipment->getOrderIncrementId(); $orderIncrementId = $shipment->getOrderIncrementId(); $shipmentInfo = $shipment->getShipment(); $trackInfo = isset($shipmentInfo['track']) ? $shipmentInfo['track'] : array(); $invoiceInfo = isset($shipmentInfo['invoice']) ? $shipmentInfo['invoice'] : array(); $shipmentIncrementId = null; // create shipment try { $shipmentResult = array(); $shipmentIncrementId = $this->create($orderIncrementId, $shipmentInfo['qtys'], $shipmentInfo['comment'], $shipmentInfo['email'], $shipmentInfo['include_comment']); if ($shipmentIncrementId) { $shipmentResult['status'] = RetailOps_Api_Helper_Data::API_STATUS_SUCCESS; $shipmentResult['shipment_increment_id'] = $shipmentIncrementId; } else { $shipmentResult['status'] = RetailOps_Api_Helper_Data::API_STATUS_FAIL; $shipmentResult['message'] = Mage::helper('retailops_api')->__('Can not create shipment'); } } catch (Mage_Core_Exception $e) { $shipmentResult['status'] = RetailOps_Api_Helper_Data::API_STATUS_FAIL; $shipmentResult['message'] = $e->getCustomMessage() ? $e->getCustomMessage() : $e->getMessage(); } $result['shipment_result'] = $shipmentResult; if ($shipmentIncrementId) { if ($trackInfo) { $result['track_result'] = array(); foreach ($trackInfo as $track) { // add shipment track try { $trackResult = array(); $track = new Varien_Object($track); Mage::dispatchEvent('retailops_shipment_add_track_before', array('record' => $track)); $trackResult['track_number'] = $track->getData('track_number'); $trackId = $this->addTrack($shipmentIncrementId, $track->getData('carrier'), $track->getData('title'), $track->getData('track_number')); $trackResult['status'] = RetailOps_Api_Helper_Data::API_STATUS_SUCCESS; $trackResult['track_id'] = $trackId; } catch (Mage_Core_Exception $e) { $trackResult['status'] = RetailOps_Api_Helper_Data::API_STATUS_FAIL; $trackResult['message'] = $e->getMessage(); } $result['track_result'][] = $trackResult; } } // create invoice /** @var Mage_Sales_Model_Order $order */ $order = Mage::getModel('sales/order'); $order->loadByIncrementId($orderIncrementId); $isFullyShipped = $this->_checkAllItemsShipped($order); $invoices = $order->getInvoiceCollection(); $invoiceResult = array(); if ($order->canInvoice()) { $itemsToInvoice = array(); if ($order->getPayment()->canCapturePartial()) { /** * If payment allows partial capture, trying to create invoice with shipped items only and capture it */ $itemsToInvoice = $shipmentInfo['qtys']; } if (($itemsToInvoice || $isFullyShipped) && $invoiceInfo) { $invoice = new Varien_Object($invoiceInfo); $invoice->setData('items_to_invoice', $itemsToInvoice); Mage::dispatchEvent('retailops_shipment_invoice_before', array('record' => $invoice)); $invoiceResult = $this->_createInvoiceAndCapture($order, $invoice->getItemsToInvoice(), $invoice->getComment(), $invoice->getEmail(), $invoice->getIncludeComment()); $invoiceResult = array($invoiceResult); } } else { if ($isFullyShipped) { /** * Capturing all available invoices if all order items are shipped */ $invoiceResult = $this->_captureInvoices($invoices); } } $result['invoice_result'] = $invoiceResult; } } catch (Exception $e) { $result['status'] = RetailOps_Api_Helper_Data::API_STATUS_FAIL; $result['message'] = $e->getMessage(); } $fullResult['records'][] = $result; } return $fullResult; }