/** * Prepares and render result of composite product configuration request * * $configureResult holds either: * - 'ok' = true, and 'product_id', 'buy_request', 'current_store_id', 'current_customer' or 'current_customer_id' * - 'error' = true, and 'message' to show * * @param Mage_Adminhtml_Controller_Action $controller * @param Varien_Object $configureResult * @return Mage_Adminhtml_Helper_Catalog_Product_Composite */ public function renderConfigureResult($controller, Varien_Object $configureResult) { try { if (!$configureResult->getOk()) { Mage::throwException($configureResult->getMessage()); } $currentStoreId = (int) $configureResult->getCurrentStoreId(); if (!$currentStoreId) { $currentStoreId = Mage::app()->getStore()->getId(); } $product = Mage::getModel('catalog/product')->setStoreId($currentStoreId)->load($configureResult->getProductId()); if (!$product->getId()) { Mage::throwException($this->__('Product is not loaded.')); } Mage::register('current_product', $product); Mage::register('product', $product); // Prepare buy request values $buyRequest = $configureResult->getBuyRequest(); if ($buyRequest) { Mage::helper('catalog/product')->prepareProductOptions($product, $buyRequest); } $isOk = true; $productType = $product->getTypeId(); } catch (Exception $e) { $isOk = false; $productType = null; Mage::register('composite_configure_result_error_message', $e->getMessage()); } $this->_initConfigureResultLayout($controller, $isOk, $productType); $controller->renderLayout(); }
public function testConnection() { $exportDirectory = $this->_fixBasePath($this->getDestination()->getPath()); $testResult = new Varien_Object(); // Check for forbidden folders $forbiddenFolders = array(Mage::getBaseDir('base'), Mage::getBaseDir('base') . DS . 'downloader'); foreach ($forbiddenFolders as $forbiddenFolder) { if (@realpath($exportDirectory) == $forbiddenFolder) { return $testResult->setSuccess(false)->setMessage(Mage::helper('xtento_orderexport')->__('It is not allowed to save export files in the directory you have specified. Please change the local export directory to be located in the ./var/ folder for example. Do not use the Magento root directory for example.')); } } if (!is_dir($exportDirectory) && !preg_match('/%exportid%/', $exportDirectory)) { // Try to create the directory. if (!@mkdir($exportDirectory)) { return $testResult->setSuccess(false)->setMessage(Mage::helper('xtento_orderexport')->__('The specified local directory does not exist. We could not create it either. Please make sure the parent directory is writable or create the directory manually: %s', $exportDirectory)); } else { $testResult->setDirectoryCreated(true); } } $this->_connection = @opendir($exportDirectory); if (!$this->_connection || @(!is_writable($exportDirectory))) { return $testResult->setSuccess(false)->setMessage(Mage::helper('xtento_orderexport')->__('Could not open local export directory for writing. Please make sure that we have rights to read and write in the directory: %s', $exportDirectory)); } if ($testResult->getDirectoryCreated()) { $testResult->setSuccess(true)->setMessage(Mage::helper('xtento_orderexport')->__('Local directory didn\'t exist and was created successfully. Connection tested successfully.')); if (!$this->getDestination()->getBackupDestination()) { $this->getDestination()->setLastResult($testResult->getSuccess())->setLastResultMessage($testResult->getMessage())->save(); } return $testResult; } else { $testResult->setSuccess(true)->setMessage(Mage::helper('xtento_orderexport')->__('Local directory exists and is writable. Connection tested successfully.')); if (!$this->getDestination()->getBackupDestination()) { $this->getDestination()->setLastResult($testResult->getSuccess())->setLastResultMessage($testResult->getMessage())->save(); } return $testResult; } }
public function updateData($data) { $is_updated = false; $dataObject = new Varien_Object($data); $feedbackDataObject = new Varien_Object($dataObject->getFeedback()); $messages = $dataObject->getMessage(); $helper = Mage::helper('magenotification'); // update feedback if ($feedbackDataObject->getStatus() != $this->getStatus()) { $this->setStatus($feedbackDataObject->getStatus()); $is_updated = true; } if ($feedbackDataObject->getCouponCode() != $this->getCouponCode()) { $this->setCouponCode($feedbackDataObject->getCouponCode()); $is_updated = true; } if ($feedbackDataObject->getCouponValue() != $this->getCouponValue()) { $this->setCouponValue($feedbackDataObject->getCouponValue()); $is_updated = true; } if ($feedbackDataObject->getExpiredCoupon() != $this->getExpiredCoupon()) { $this->setExpiredCoupon($feedbackDataObject->getExpiredCoupon()); $is_updated = true; } $this->setUpdated(time()); $this->save(); //update message if (count($messages)) { $messageModel = Mage::getModel('magenotification/feedbackmessage'); foreach ($messages as $message) { $messageDataObject = new Varien_Object($message); $messageModel->import($messageDataObject); } } return $this; }
/** * Submit action * * @return string */ public function submitAction() { $params = $this->getRequest()->getParams(); $response = new Varien_Object(); try { $request = $this->_getRequestModel()->setRequest($params['request'])->dispatch(); $response->setStatus('OK'); $response->setRequest($params['request']); $response->setMessage($request->getMessage()); $response->setType($request->getType()); if ($request->getType() == MageHack_MageConsole_Model_Abstract::RESPONSE_TYPE_PROMPT) { $key = $this->_savePrompt($params['request']); $response->setId($key); } } catch (Exception $e) { $response->setStatus('ERROR'); $response->setType(MageHack_MageConsole_Model_Abstract::RESPONSE_TYPE_ERROR); $response->setMessage($e->getMessage()); } if ($response->getType() == 'FILE') { $requestDetails = preg_split('/\\s+/', $params['request']); $this->_prepareDownloadResponse($requestDetails[1] . '_export.csv', $response->getMessage()); } else { $this->getResponse()->setBody($response->toJson()); } }
/** * Format messages output * * @param Varien_Object $command * @return string Message */ protected function formatMessages(Varien_Object $command, $payload = null) { $messages = ''; $messages .= PHP_EOL . ' - ' . $command->getMessage() . PHP_EOL; $messages .= 'INPUT: ' . $command->getCommand() . PHP_EOL; $messages .= 'OUTPUT: ' . print_r($command->getOutput()) . PHP_EOL . PHP_EOL; return $messages; }
public function render(Varien_Object $row) { return nl2br(htmlentities($row->getMessage())); }
function add_products_to_quote($params) { $errors = array(); if (!isset($params['quote_id'])) { $this->_fault('data_invalid', 'Quotation ID missing'); } else { $quoteId = $params['quote_id']; $_qquoteadv = Mage::getModel('qquoteadv/qqadvcustomer')->load($quoteId); if (!count($_qquoteadv->getData())) { $this->_fault('not_exists', 'Quotation ID (' . $quoteId . ') does not exist'); } } if (!isset($params['products']) || !is_array($params['products']) || !count($params['products'])) { $this->_fault('data_invalid', 'Products missing'); } else { //check that the proucts exist $productIds = $params['products']; foreach ($productIds as $productId) { $product = Mage::getModel('catalog/product')->load($productId); if (!$product->getData('entity_id')) { $this->_fault('not_exists', 'Product ID (' . $productId . ') does not exist'); } } } if (!count($errors)) { $hasOptions = FALSE; $options = FALSE; $storeId = $_qquoteadv->getStoreId(); $modelProduct = Mage::getModel('qquoteadv/qqadvproduct'); $qty = 1; foreach ($productIds as $productId) { $productsCollection = $modelProduct->getCollection()->addFieldToFilter('quote_id', $quoteId)->addFieldToFilter('product_id', $productId); $attribute = serialize(array('product' => $productId, 'qty' => $qty)); // don't add if it has already been added if (!count($productsCollection)) { $qproduct = array('quote_id' => $quoteId, 'product_id' => $productId, 'qty' => $qty, 'attribute' => $attribute, 'has_options' => $hasOptions, 'options' => $options, 'store_id' => $storeId); $checkQty = $modelProduct->addProduct($qproduct); if (is_null($checkQty)) { // product has not been added redirect with error $checkQty = new Varien_Object(); $checkQty->setHasError(true); $checkQty->setMessage(Mage::helper('qquoteadv')->__('product can not be added to quote list')); } if ($checkQty->getHasError()) { $this->_fault('save_error', $checkQty->getMessage()); } else { $quoteadvProductId = $checkQty->getData('id'); $ownerPrice = Mage::helper('qquoteadv')->_applyPrice($quoteadvProductId, $qty); $originalPrice = Mage::helper('qquoteadv')->_applyPrice($quoteadvProductId, $qty); //#current currency price $currencyCode = $_qquoteadv->getCurrency(); $ownerCurPrice = Mage::helper('qquoteadv')->_applyPrice($quoteadvProductId, $qty, $currencyCode); $originalCurPrice = Mage::helper('qquoteadv')->_applyPrice($quoteadvProductId, $qty, $currencyCode); $item = array('quote_id' => $quoteId, 'product_id' => $productId, 'request_qty' => $qty, 'owner_base_price' => $ownerPrice, 'original_price' => $originalPrice, 'owner_cur_price' => $ownerCurPrice, 'original_cur_price' => $originalCurPrice, 'quoteadv_product_id' => $quoteadvProductId); $requestitem = Mage::getModel('qquoteadv/requestitem')->setData($item); $requestitem->save(); } } } } return array('success' => true); }