Example #1
0
 protected function _beforeSave()
 {
     if ($this->_mediumData) {
         $this->setData('medium_json', $this->_mediumData->toJson());
     }
     parent::_beforeSave();
 }
Example #2
0
 protected function _beforeSave()
 {
     if ($this->_mediumData) {
         $this->setData('medium_json', $this->_mediumData->toJson());
     }
     if ($this->_campaign) {
         $this->setCampaignId($this->_campaign->getId());
     }
     parent::_beforeSave();
 }
 public function popupajaxAction()
 {
     $response = new Varien_Object();
     $response->setError(0);
     try {
         $pageName = $this->getRequest()->getParam('page');
         if (!$pageName) {
             throw new Exception($this->__('PageType not found'));
         }
         $pageName = Mage::helper('core')->escapeHtml($pageName);
         $popup = Mage::helper('promotional')->getPopup($pageName);
         if (isset($popup['promotional_id'])) {
             Mage::helper('promotional')->setViewedPopup($popup['promotional_id']);
             $response->addData($popup->toArray());
             $autoHideTime = Mage::helper('promotional')->getAutoHide();
             if ($autoHideTime > 0) {
                 $response->setAutoHideTime($autoHideTime);
             }
         } else {
             throw new Exception('Promotional Popup not found');
         }
     } catch (Exception $e) {
         $response->setError(1);
         $response->setErrorMessage($e->getMessage());
     }
     $this->getResponse()->setBody($response->toJson());
     return;
 }
 /**
  * @todo Rename variables to carry more understandability
  */
 public function indexAction()
 {
     $__VH = Mage::helper('activitystream/dataValidation');
     $__activityModel = Mage::getModel('activitystream/activity');
     $__VH->mustbeavalidVarienObject($__activityModel);
     $__activityCollection = $__activityModel->getCollection();
     $__VH->mustbeavalidObject($__activityCollection);
     $__moment = $this->getRequest()->getParam('moment');
     $__storeFilter = $this->getRequest()->getParam('storefilter');
     $__items = $__activityCollection->newestFirst()->startingFrom($__moment)->joinDetails();
     switch ($__storeFilter) {
         case AW_Activitystream_Helper_Data::STREAM_STOREFILTER_STOREVIEW:
             $__activityCollection->filterByStoreView(Mage::app()->getStore()->getStoreId());
             break;
         case AW_Activitystream_Helper_Data::STREAM_STOREFILTER_STORE:
             $__activityCollection->filterByStoreGroup(Mage::app()->getStore()->getGroupId());
             break;
         case AW_Activitystream_Helper_Data::STREAM_STOREFILTER_WEBSITE:
             $__activityCollection->filterByWebsite(Mage::app()->getStore()->getWebsiteId());
             break;
     }
     $__activityCollection->filterByTypes(Mage::helper('activitystream/adminhtml')->getEnabledActivityTypes())->setPageSize(50)->setCurPage(0);
     $__activityCollection->load();
     $__items = array_reverse($__activityCollection->getItems());
     $__activities = array();
     foreach ($__items as $__item) {
         $__activity = array('DATA' => $__item->getData(), 'RECORD_HTML' => $this->__renderActivity($__item));
         array_push($__activities, $__activity);
     }
     $__responseObject = new Varien_Object();
     $__responseObject->setActivities(array_reverse($__activities));
     $this->getResponse()->setHeader('Content-Type', 'application/json')->setBody($__responseObject->toJson());
 }
 /**
  * Save shipment
  * We can save only new shipment. Existing shipments are not editable
  *
  * @return null
  */
 public function saveAction()
 {
     $data = $this->getRequest()->getPost('shipment');
     if (!empty($data['comment_text'])) {
         Mage::getSingleton('adminhtml/session')->setCommentText($data['comment_text']);
     }
     try {
         $shipment = $this->_initShipment();
         if (!$shipment) {
             $this->_forward('noRoute');
             return;
         }
         $shipment->register();
         $comment = '';
         if (!empty($data['comment_text'])) {
             $shipment->addComment($data['comment_text'], isset($data['comment_customer_notify']), isset($data['is_visible_on_front']));
             if (isset($data['comment_customer_notify'])) {
                 $comment = $data['comment_text'];
             }
         }
         if (!empty($data['send_email'])) {
             $shipment->setEmailSent(true);
         }
         $shipment->getOrder()->setCustomerNoteNotify(!empty($data['send_email']));
         $responseAjax = new Varien_Object();
         $isNeedCreateLabel = isset($data['create_shipping_label']) && $data['create_shipping_label'];
         if ($isNeedCreateLabel && $this->_createShippingLabel($shipment)) {
             $responseAjax->setOk(true);
         }
         $this->_saveShipment($shipment);
         Mage::dispatchEvent('sales_order_shipment_save_custom', array('post' => $data, 'shipment' => $shipment));
         $shipment->sendEmail(!empty($data['send_email']), $comment);
         $shipmentCreatedMessage = $this->__('The shipment has been created.');
         $labelCreatedMessage = $this->__('The shipping label has been created.');
         $this->_getSession()->addSuccess($isNeedCreateLabel ? $shipmentCreatedMessage . ' ' . $labelCreatedMessage : $shipmentCreatedMessage);
         Mage::getSingleton('adminhtml/session')->getCommentText(true);
     } catch (Mage_Core_Exception $e) {
         if ($isNeedCreateLabel) {
             $responseAjax->setError(true);
             $responseAjax->setMessage($e->getMessage());
         } else {
             $this->_getSession()->addError($e->getMessage());
             $this->_redirect('*/*/new', array('order_id' => $this->getRequest()->getParam('order_id')));
         }
     } catch (Exception $e) {
         Mage::logException($e);
         if ($isNeedCreateLabel) {
             $responseAjax->setError(true);
             $responseAjax->setMessage(Mage::helper('sales')->__('An error occurred while creating shipping label.'));
         } else {
             $this->_getSession()->addError($this->__('Cannot save shipment.'));
             $this->_redirect('*/*/new', array('order_id' => $this->getRequest()->getParam('order_id')));
         }
     }
     if ($isNeedCreateLabel) {
         $this->getResponse()->setBody($responseAjax->toJson());
     } else {
         $this->_redirect('*/sales_order/view', array('order_id' => $shipment->getOrderId()));
     }
 }
Example #6
0
 /**
  * Tests Varien_Object->toJson()
  */
 public function testToJson()
 {
     $this->_object->setData(array('key1' => 'value1', 'key2' => 'value2'));
     $this->assertEquals('{"key1":"value1","key2":"value2"}', $this->_object->toJson());
     $this->assertEquals('{"key1":"value1"}', $this->_object->toJson(array('key1')));
     $this->assertEquals('{"key1":"value1","key":null}', $this->_object->__toJson(array('key1', 'key')));
 }
Example #7
0
 public function getJson()
 {
     $response = new Varien_Object();
     $helper = Mage::helper('yanws/articleUtils');
     $response->setUrl(Mage::getBaseUrl());
     $response->setConvertTable(Mage::helper('yanws')->_getTransliterator()->getConvertTable());
     $response->setBaseRoute($helper::BASE_ROUTE);
     return $response->toJson();
 }
Example #8
0
 public function getJsonConversionPagesUrl()
 {
     $storeViewsUrls = array();
     foreach ($this->getStoreViews() as $_store) {
         Mage::helper('googleoptimizer')->setStoreId($_store->getId());
         $storeViewsUrls[$_store->getCode()] = Mage::helper('googleoptimizer')->getConversionPagesUrl()->getData();
     }
     $storeViewsUrls = new Varien_Object($storeViewsUrls);
     return $storeViewsUrls->toJson();
 }
 protected function _saveFile($type, $extensions = array())
 {
     global $_FILES;
     /* @var $core Morphes_Core_Helper_Data */
     $core = Mage::helper(strtolower('Morphes_Core'));
     /* @var $files Morphes_Core_Helper_Files */
     $files = Mage::helper(strtolower('Morphes_Core/Files'));
     try {
         $isXhr = $this->getRequest()->getParam('qqfile') != null;
         if (!$isXhr && !isset($_FILES['qqfile'])) {
             throw new Exception($this->__('No files were uploaded.'));
         }
         $filename = $isXhr ? $this->getRequest()->getParam('qqfile') : $_FILES['qqfile']['name'];
         $size = $isXhr ? (int) $_SERVER["CONTENT_LENGTH"] : $_FILES['qqfile']['size'];
         $fileinfo = pathinfo($filename);
         if (count($extensions) && !in_array(strtolower($fileinfo['extension']), $extensions)) {
             throw new Exception($this->__('Invalid file extension %s.', $fileinfo['extension']));
         }
         if ($size == 0) {
             throw new Exception($this->__('File is empty.'));
         }
         if ($size > min($core->getIniByteValue('post_max_size'), $core->getIniByteValue('upload_max_filesize'))) {
             throw new Exception($this->__('File is too large. Current maximum size is %d bytes.'));
         }
         $relativeUrl = $files->getNewUrl($filename, $type);
         $targetFileName = $files->getFilename($relativeUrl, $type, true);
         if ($isXhr) {
             // save upload as a temp file
             $input = fopen("php://input", "r");
             $temp = tmpfile();
             $realSize = stream_copy_to_stream($input, $temp);
             fclose($input);
             if ($realSize != $size) {
                 throw new Exception($this->__("File size %d was expected, but %d was actually sent", $size, $realSize));
             }
             // move temp file to target location
             $target = fopen($targetFileName, "w");
             fseek($temp, 0, SEEK_SET);
             stream_copy_to_stream($temp, $target);
             fclose($target);
         } else {
             if (!move_uploaded_file($_FILES['qqfile']['tmp_name'], $targetFileName)) {
                 throw new Exception("The upload was cancelled, or server error encountered.");
             }
         }
         $url = $files->getUrl($relativeUrl, $type);
         $id = $this->getRequest()->getParam('id');
         $response = new Varien_Object(compact('relativeUrl', 'url', 'id'));
         $this->getResponse()->setBody($response->toJson());
     } catch (Exception $e) {
         $response = new Varien_Object(array('error' => $e->getMessage()));
         $this->getResponse()->setBody($response->toJson());
     }
 }
Example #10
0
 public function toJson(array $arrAttributes = array())
 {
     $this->setSuccess(true);
     if ($this->isError()) {
         $this->setSuccess(false);
         $this->setMsg($this->_error);
     } else {
         $this->setMsg($this->_msg);
     }
     return parent::toJson($arrAttributes);
 }
Example #11
0
 public function updateAction()
 {
     $data = $this->getRequest()->getPost();
     $response = array('action' => $data['action'], 'errorMessage' => '');
     try {
         switch ($data['action']) {
             case 'update':
                 $updateInfo = array();
                 foreach ($data['items'] as $itemId => $qty) {
                     $updateInfo[$itemId] = array('qty' => max((int) $qty, 1));
                 }
                 $this->_getCart()->updateItems($updateInfo)->save();
                 $this->_getSession()->setCartWasUpdated(true);
                 /*
                 
                 					$quoteItem = $cart->getQuote()->getItemById($id);
                 					if (!$quoteItem) {
                 						Mage::throwException($this->__('Quote item is not found.'));
                 					}
                 					if ($qty == 0) {
                 						$cart->removeItem($id);
                 					} else {
                 						$quoteItem->setQty($qty)->save();
                 					}
                 					$this->_getCart()->save();/**/
                 break;
             case 'delete':
                 $this->_getCart()->removeItem($data['itemId'])->save();
                 break;
             case 'clear':
                 $oemAttrSetId = Mage::getStoreConfig('arioem/add_to_cart/oem_product_attr_set_id');
                 $items = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();
                 foreach ($items as $item) {
                     if ($oemAttrSetId == $item->getProduct()->getAttributeSetId()) {
                         $this->_getCart()->removeItem($item->getId());
                     }
                 }
                 $this->_getCart()->save();
                 break;
             case 'refresh':
             default:
                 // do nothing here
         }
         Mage::register('isAJAX', true);
         $response['html'] = $this->getLayout()->createBlock('arioem/shoppinglist')->toHtml();
     } catch (Exception $e) {
         $response['errorMessage'] = Vikont_ARIOEM_Helper_Data::reportError($e->getMessage());
     }
     $responseAjax = new Varien_Object($response);
     $this->getResponse()->setBody($responseAjax->toJson());
 }
 public function validateAction()
 {
     $response = new Varien_Object();
     $response->setError(false);
     $attributeCode = $this->getRequest()->getParam('attribute_code');
     $attributeId = $this->getRequest()->getParam('attribute_id');
     $attribute = Mage::getModel('catalog/entity_attribute')->loadByCode($this->_entityTypeId, $attributeCode);
     if ($attribute->getId() && !$attributeId) {
         Mage::getSingleton('adminhtml/session')->addError(Mage::helper('catalog')->__('Attribute with the same code already exists'));
         $this->_initLayoutMessages('adminhtml/session');
         $response->setError(true);
         $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml());
     }
     $this->getResponse()->setBody($response->toJson());
 }
 /**
  * Save grid edit form action
  *
  */
 public function saveFormAction()
 {
     $codeId = $this->getRequest()->getParam('code_id');
     $response = new Varien_Object();
     try {
         $model = Mage::getModel('find_feed/codes');
         if ($codeId) {
             $model->load($codeId);
         }
         $model->setImportCode($this->getRequest()->getParam('import_code'));
         $model->setEavCode($this->getRequest()->getParam('eav_code'));
         $model->setIsImported(intval($this->getRequest()->getParam('is_imported')));
         $model->save();
         $response->setError(0);
     } catch (Exception $e) {
         $response->setError(1);
         $response->setMessage('Save error');
     }
     $this->getResponse()->setBody($response->toJson());
 }
Example #14
0
 /**
  * Attributes validation action
  *
  */
 public function validateAction()
 {
     $response = new Varien_Object();
     $response->setError(false);
     $attributesData = $this->getRequest()->getParam('attributes', array());
     $data = new Varien_Object();
     try {
         if ($attributesData) {
             $dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
             $storeId = $this->_getHelper()->getSelectedStoreId();
             foreach ($attributesData as $attributeCode => $value) {
                 $attribute = Mage::getSingleton('Mage_Eav_Model_Config')->getAttribute('catalog_product', $attributeCode);
                 if (!$attribute->getAttributeId()) {
                     unset($attributesData[$attributeCode]);
                     continue;
                 }
                 $data->setData($attributeCode, $value);
                 $attribute->getBackend()->validate($data);
             }
         }
     } catch (Mage_Eav_Model_Entity_Attribute_Exception $e) {
         $response->setError(true);
         $response->setAttribute($e->getAttributeCode());
         $response->setMessage($e->getMessage());
     } catch (Mage_Core_Exception $e) {
         $response->setError(true);
         $response->setMessage($e->getMessage());
     } catch (Exception $e) {
         $this->_getSession()->addException($e, $this->__('An error occurred while updating the product(s) attributes.'));
         $this->_initLayoutMessages('Mage_Adminhtml_Model_Session');
         $response->setError(true);
         $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml());
     }
     $this->getResponse()->setBody($response->toJson());
 }
 /**
  * Validate Staging before it save
  *
  */
 public function validateAction()
 {
     $response = new Varien_Object();
     $response->setError(false);
     try {
         $stagingData = $this->getRequest()->getPost('staging');
         Mage::getModel('enterprise_staging/staging')->setStagingId($this->getRequest()->getParam('id'))->addData($stagingData)->validate();
     } catch (Enterprise_Staging_Exception $e) {
         $response->setError(true);
         $response->setMessage($e->getMessage());
     } catch (Exception $e) {
         $this->_getSession()->addError(Mage::helper('enterprise_staging')->__('An error occurred while validating data. Please review the log and try again.'));
         $this->_initLayoutMessages('adminhtml/session');
         $response->setError(true);
         $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml());
     }
     $this->getResponse()->setBody($response->toJson());
 }
 /**
  * Validate attribute action
  *
  */
 public function validateAction()
 {
     $response = new Varien_Object();
     $response->setError(false);
     $attributeId = $this->getRequest()->getParam('attribute_id');
     if (!$attributeId) {
         $attributeCode = $this->getRequest()->getParam('attribute_code');
         $attributeObject = $this->_initAttribute()->loadByCode($this->_getEntityType()->getId(), $attributeCode);
         if ($attributeObject->getId()) {
             $this->_getSession()->addError(Mage::helper('enterprise_customer')->__('Attribute with the same code already exists'));
             $this->_initLayoutMessages('adminhtml/session');
             $response->setError(true);
             $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml());
         }
     }
     $this->getResponse()->setBody($response->toJson());
 }
 public function validateAction()
 {
     $url = $this->getRequest()->getPost('tag_identifier');
     if (!$url) {
         $url = Mage::helper('blog/post')->friendlyURL($this->getRequest()->getPost('name'));
     } else {
         $url = Mage::helper('blog/post')->friendlyURL($url);
     }
     $response = new Varien_Object();
     $response->setError(false);
     $urlInstance = Mage::getModel('blog/url');
     if ($urlInstance->validate('tag/' . $url . '.html', 'tag_id', $this->getRequest()->getParam('id'))) {
         $response->setError(true);
         $response->setAttribute("Tag Identifier");
         $response->setMessage("Tag identifier is unique");
         $response->setData('identifier', $url);
     }
     $this->getResponse()->setBody($response->toJson());
 }
Example #18
0
 public function validateAction()
 {
     $response = new Varien_Object();
     $response->setError(0);
     $websiteId = Mage::app()->getStore()->getWebsiteId();
     $accountData = $this->getRequest()->getPost('account');
     $customer = Mage::getModel('Mage_Customer_Model_Customer');
     $customerId = $this->getRequest()->getParam('id');
     if ($customerId) {
         $customer->load($customerId);
         $websiteId = $customer->getWebsiteId();
     } else {
         if (isset($accountData['website_id'])) {
             $websiteId = $accountData['website_id'];
         }
     }
     /* @var $customerForm Mage_Customer_Model_Form */
     $customerForm = Mage::getModel('Mage_Customer_Model_Form');
     $customerForm->setEntity($customer)->setFormCode('adminhtml_customer')->setIsAjaxRequest(true)->ignoreInvisible(false);
     $data = $customerForm->extractData($this->getRequest(), 'account');
     $errors = $customerForm->validateData($data);
     if ($errors !== true) {
         foreach ($errors as $error) {
             $this->_getSession()->addError($error);
         }
         $response->setError(1);
     }
     # additional validate email
     if (!$response->getError()) {
         # Trying to load customer with the same email and return error message
         # if customer with the same email address exisits
         $checkCustomer = Mage::getModel('Mage_Customer_Model_Customer')->setWebsiteId($websiteId);
         $checkCustomer->loadByEmail($accountData['email']);
         if ($checkCustomer->getId() && $checkCustomer->getId() != $customer->getId()) {
             $response->setError(1);
             $this->_getSession()->addError(Mage::helper('Mage_Adminhtml_Helper_Data')->__('Customer with the same email already exists.'));
         }
     }
     $addressesData = $this->getRequest()->getParam('address');
     if (is_array($addressesData)) {
         /* @var $addressForm Mage_Customer_Model_Form */
         $addressForm = Mage::getModel('Mage_Customer_Model_Form');
         $addressForm->setFormCode('adminhtml_customer_address')->ignoreInvisible(false);
         foreach (array_keys($addressesData) as $index) {
             if ($index == '_template_') {
                 continue;
             }
             $address = $customer->getAddressItemById($index);
             if (!$address) {
                 $address = Mage::getModel('Mage_Customer_Model_Address');
             }
             $requestScope = sprintf('address/%s', $index);
             $formData = $addressForm->setEntity($address)->extractData($this->getRequest(), $requestScope);
             $errors = $addressForm->validateData($formData);
             if ($errors !== true) {
                 foreach ($errors as $error) {
                     $this->_getSession()->addError($error);
                 }
                 $response->setError(1);
             }
         }
     }
     if ($response->getError()) {
         $this->_initLayoutMessages('Mage_Adminhtml_Model_Session');
         $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml());
     }
     $this->getResponse()->setBody($response->toJson());
 }
 /**
  * Rollback Action
  *
  * @return Mage_Adminhtml_Controller_Action
  */
 public function rollbackAction()
 {
     if (!Mage::helper('datareset')->isRollbackAllowed()) {
         return $this->_forward('denied');
     }
     if (!$this->getRequest()->isAjax()) {
         return $this->getUrl('*/*/index');
     }
     $helper = Mage::helper('backup');
     $response = new Varien_Object();
     try {
         /* @var $backup Mage_Backup_Model_Backup */
         $backup = Mage::getModel('backup/backup')->loadByTimeAndType($this->getRequest()->getParam('time'), $this->getRequest()->getParam('type'));
         if (!$backup->getTime() || !$backup->exists()) {
             return $this->_redirect('*/*');
         }
         if (!$backup->getTime()) {
             throw new Mage_Backup_Exception_CantLoadSnapshot();
         }
         $type = $backup->getType();
         $backupManager = Mage::getModel('datareset/rollback')->setBackupExtension($helper->getExtensionByType($type))->setTime($backup->getTime())->setBackupsDir($helper->getBackupsDir())->setName($backup->getName(), false)->setResourceModel(Mage::getResourceModel('backup/db'));
         Mage::register('backup_manager', $backupManager);
         $passwordValid = Mage::getModel('backup/backup')->validateUserPassword($this->getRequest()->getParam('password'));
         if (!$passwordValid) {
             $response->setError(Mage::helper('backup')->__('Invalid Password.'));
             $backupManager->setErrorMessage(Mage::helper('backup')->__('Invalid Password.'));
             return $this->getResponse()->setBody($response->toJson());
         }
         if ($this->getRequest()->getParam('maintenance_mode')) {
             $turnedOn = $helper->turnOnMaintenanceMode();
             if (!$turnedOn) {
                 $response->setError(Mage::helper('backup')->__('You do not have sufficient permissions to enable Maintenance Mode during this operation.') . ' ' . Mage::helper('backup')->__('Please either unselect the "Put store on the maintenance mode" checkbox or update your permissions to proceed with the rollback."'));
                 $backupManager->setErrorMessage(Mage::helper('backup')->__("System couldn't put store on the maintenance mode"));
                 return $this->getResponse()->setBody($response->toJson());
             }
         }
         if ($type != Mage_Backup_Helper_Data::TYPE_DB) {
             $backupManager->setRootDir(Mage::getBaseDir())->addIgnorePaths($helper->getRollbackIgnorePaths());
             if ($this->getRequest()->getParam('use_ftp', false)) {
                 $backupManager->setUseFtp($this->getRequest()->getParam('ftp_host', ''), $this->getRequest()->getParam('ftp_user', ''), $this->getRequest()->getParam('ftp_pass', ''), $this->getRequest()->getParam('ftp_path', ''));
             }
         }
         $backupManager->rollback();
         $helper->invalidateCache()->invalidateIndexer();
         $adminSession = $this->_getSession();
         $adminSession->unsetAll();
         $adminSession->getCookie()->delete($adminSession->getSessionName());
         $response->setRedirectUrl($this->getUrl('*'));
     } catch (Mage_Backup_Exception_CantLoadSnapshot $e) {
         $errorMsg = Mage::helper('backup')->__('Backup file not found');
     } catch (Mage_Backup_Exception_FtpConnectionFailed $e) {
         $errorMsg = Mage::helper('backup')->__('Failed to connect to FTP');
     } catch (Mage_Backup_Exception_FtpValidationFailed $e) {
         $errorMsg = Mage::helper('backup')->__('Failed to validate FTP');
     } catch (Mage_Backup_Exception_NotEnoughPermissions $e) {
         Mage::log($e->getMessage());
         $errorMsg = Mage::helper('backup')->__('Not enough permissions to perform rollback');
     } catch (Exception $e) {
         Mage::log($e->getMessage());
         $errorMsg = Mage::helper('backup')->__('Failed to rollback');
     }
     if (!empty($errorMsg)) {
         $response->setError($errorMsg);
         $backupManager->setErrorMessage($errorMsg);
     }
     if ($this->getRequest()->getParam('maintenance_mode')) {
         $helper->turnOffMaintenanceMode();
     }
     $this->getResponse()->setBody($response->toJson());
 }
Example #20
0
 /**
  * Validate Action
  *
  */
 public function validateAction()
 {
     $response = new Varien_Object(array('error' => false));
     $variable = $this->_initVariable();
     $variable->addData($this->getRequest()->getPost('variable'));
     $result = $variable->validate();
     if ($result !== true && is_string($result)) {
         $this->_getSession()->addError($result);
         $this->_initLayoutMessages('Mage_Adminhtml_Model_Session');
         $response->setError(true);
         $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml());
     }
     $this->getResponse()->setBody($response->toJson());
 }
 /**
  * Submit prompt action
  *
  * @return  string
  */
 public function promptAction()
 {
     $params = $this->getRequest()->getParams();
     $response = new Varien_Object();
     try {
         $key = $params['id'];
         $data = $params['data'];
         if (empty($key) || empty($data)) {
             Mage::throwException('Parameters key and data are required');
         }
         if (!($prompt = $this->_loadPrompt($key))) {
             Mage::throwException('Session time out, try again');
         }
         $request = $this->_getRequestModel()->setRequest($prompt)->dispatch($data);
         $response->setStatus('OK');
         $response->setMessage($request->getMessage());
         $response->setType(MageHack_MageConsole_Model_Abstract::RESPONSE_TYPE_MESSAGE);
     } catch (Exception $e) {
         $response->setStatus('ERROR');
         $response->setType(MageHack_MageConsole_Model_Abstract::RESPONSE_TYPE_ERROR);
         $response->setMessage($e->getMessage());
     }
     $this->getResponse()->setHeader('Content-Type', 'application/json', true)->setBody($response->toJson());
 }
 public function validateAction()
 {
     $postData = $this->getRequest()->getPost('post');
     $response = new Varien_Object();
     if (!$postData['post_identifier']) {
         $url = Mage::helper('blog/post')->friendlyURL($postData['title']);
     } else {
         $url = Mage::helper('blog/post')->friendlyURL($postData['post_identifier']);
     }
     $urlInstance = Mage::getModel('blog/url');
     if ($urlInstance->validate($url . '.html', 'post_id', $postData['entity_id'])) {
         $response->setError(true);
         $response->setAttribute("post_identifier");
         $response->setMessage(Mage::helper('blog')->__("The value of post identifier is unique"));
         $response->setData('post_identifier', $url);
     } else {
         $response->setError(false);
     }
     $this->getResponse()->setBody($response->toJson());
 }
Example #23
0
 public function assemblyAction()
 {
     $responseAjax = new Varien_Object(Mage::helper('arioem')->getAssemblyData());
     $this->getResponse()->setBody($responseAjax->toJson());
 }
 public function validateAction()
 {
     $response = new Varien_Object();
     $response->setError(false);
     try {
         $productData = $this->getRequest()->getPost('product');
         if ($productData && !isset($productData['stock_data']['use_config_manage_stock'])) {
             $productData['stock_data']['use_config_manage_stock'] = 0;
         }
         $product = Mage::getModel('catalog/product')->setId($this->getRequest()->getParam('id'))->addData($productData)->validate();
     } catch (Mage_Eav_Model_Entity_Attribute_Exception $e) {
         $response->setError(true);
         $response->setAttribute($e->getAttributeCode());
         $response->setMessage($e->getMessage());
     } catch (Exception $e) {
         $this->_getSession()->addError($e->getMessage());
         $this->_initLayoutMessages('adminhtml/session');
         $response->setError(true);
         $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml());
     }
     $this->getResponse()->setBody($response->toJson());
 }
 public function validateAction()
 {
     $response = new Varien_Object();
     $response->setError(false);
     try {
         /**
          * @todo implement full validation process with errors returning which are ignoring now
          */
     } catch (Mage_Eav_Model_Entity_Attribute_Exception $e) {
         $response->setError(true);
         $response->setAttribute($e->getAttributeCode());
         $response->setMessage($e->getMessage());
     } catch (Mage_Core_Exception $e) {
         $response->setError(true);
         $response->setMessage($e->getMessage());
     } catch (Exception $e) {
         $this->_getSession()->addError($e->getMessage());
         $this->_initLayoutMessages('adminhtml/session');
         $response->setError(true);
         $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml());
     }
     $this->getResponse()->setBody($response->toJson());
 }
Example #26
0
 /**
  * Validate action
  *
  */
 public function validateAction()
 {
     $response = new Varien_Object();
     $response->setError(false);
     $widgetInstance = $this->_initWidgetInstance();
     $result = $widgetInstance->validate();
     if ($result !== true && is_string($result)) {
         $this->_getSession()->addError($result);
         $this->_initLayoutMessages('adminhtml/session');
         $response->setError(true);
         $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml());
     }
     $this->setBody($response->toJson());
 }
Example #27
0
 public function jsonDeleteAction()
 {
     $response = new Varien_Object();
     $response->setError(0);
     if ($id = $this->getRequest()->getParam('id')) {
         try {
             $model = Mage::getModel('Mage_Poll_Model_Poll_Answer');
             $model->setId(Zend_Json::decode($id))->delete();
         } catch (Exception $e) {
             $response->setError(1);
             $response->setMessage($e->getMessage());
         }
     } else {
         $response->setError(1);
         $response->setMessage(Mage::helper('Mage_Poll_Helper_Data')->__('Unable to find an answer to delete.'));
     }
     $this->getResponse()->setBody($response->toJson());
 }
 /**
  * Validate Action
  *
  */
 public function validateAction()
 {
     $response = new Varien_Object(array('error' => false));
     $post = $this->getRequest()->getParam('rate');
     $message = null;
     if (!isset($post['customer_group_id']) || !isset($post['website_id']) || !isset($post['direction']) || !isset($post['value']) || !isset($post['equal_value'])) {
         $message = $this->__('Please enter all Rate information.');
     } elseif ($post['direction'] == Enterprise_Reward_Model_Reward_Rate::RATE_EXCHANGE_DIRECTION_TO_CURRENCY && ((int) $post['value'] <= 0 || (double) $post['equal_value'] <= 0)) {
         if ((int) $post['value'] <= 0) {
             $message = $this->__('Please enter a positive integer number in the left rate field.');
         } else {
             $message = $this->__('Please enter a positive number in the right rate field.');
         }
     } elseif ($post['direction'] == Enterprise_Reward_Model_Reward_Rate::RATE_EXCHANGE_DIRECTION_TO_POINTS && ((double) $post['value'] <= 0 || (int) $post['equal_value'] <= 0)) {
         if ((int) $post['equal_value'] <= 0) {
             $message = $this->__('Please enter a positive integer number in the right rate field.');
         } else {
             $message = $this->__('Please enter a positive number in the left rate field.');
         }
     } else {
         $rate = $this->_initRate();
         $isRateUnique = $rate->getIsRateUniqueToCurrent($post['website_id'], $post['customer_group_id'], $post['direction']);
         if (!$isRateUnique) {
             $message = $this->__('Rate with the same website, customer group and direction or covering rate already exists.');
         }
     }
     if ($message) {
         $this->_getSession()->addError($message);
         $this->_initLayoutMessages('adminhtml/session');
         $response->setError(true);
         $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml());
     }
     $this->getResponse()->setBody($response->toJson());
 }
 public function validateAction()
 {
     $response = new Varien_Object();
     $response->setError(0);
     $websiteId = AO::app()->getStore()->getWebsiteId();
     $accountData = $this->getRequest()->getPost('account');
     $customer = AO::getModel('customer/customer');
     if ($id = $this->getRequest()->getParam('id')) {
         $customer->load($id);
         $websiteId = $customer->getWebsiteId();
     }
     if (isset($accountData['website_id'])) {
         $websiteId = $accountData['website_id'];
     }
     # Checking if we received email. If not - ERROR
     if (!$accountData['email']) {
         $response->setError(1);
         AO::getSingleton('adminhtml/session')->addError(AO::helper('adminhtml')->__("Please fill in 'email' field."));
         $this->_initLayoutMessages('adminhtml/session');
         $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml());
     } else {
         # Trying to load customer with the same email and return error message
         # if customer with the same email address exisits
         $checkCustomer = AO::getModel('customer/customer')->setWebsiteId($websiteId);
         $checkCustomer->loadByEmail($accountData['email']);
         if ($checkCustomer->getId() && $checkCustomer->getId() != $customer->getId()) {
             $response->setError(1);
             AO::getSingleton('adminhtml/session')->addError(AO::helper('adminhtml')->__('Customer with the same email already exists.'));
             $this->_initLayoutMessages('adminhtml/session');
             $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml());
         }
     }
     $this->getResponse()->setBody($response->toJson());
 }
Example #30
0
 public function validateAction()
 {
     $response = new Varien_Object();
     $response->setError(false);
     if ($this->getRequest()->getPost()) {
         try {
             $pollModel = Mage::getModel('poll/poll');
             if (!$this->getRequest()->getParam('id')) {
                 $pollModel->setDatePosted(now());
             }
             if ($this->getRequest()->getParam('closed') && !$this->getRequest()->getParam('was_closed')) {
                 $pollModel->setDateClosed(now());
             }
             if (!$this->getRequest()->getParam('closed')) {
                 $pollModel->setDateClosed(new Zend_Db_Expr('null'));
             }
             $pollModel->setPollTitle($this->getRequest()->getParam('poll_title'))->setClosed($this->getRequest()->getParam('closed'));
             if ($this->getRequest()->getParam('id') > 0) {
                 $pollModel->setId($this->getRequest()->getParam('id'));
             }
             $stores = $this->getRequest()->getParam('store_ids');
             if (!is_array($stores) || count($stores) == 0) {
                 Mage::throwException(Mage::helper('adminhtml')->__('Please, select "Visible in Stores" for this poll first.'));
             }
             if (is_array($stores)) {
                 $storeIds = array();
                 foreach ($stores as $storeIdList) {
                     $storeIdList = explode(',', $storeIdList);
                     if (!$storeIdList) {
                         continue;
                     }
                     foreach ($storeIdList as $storeId) {
                         if ($storeId > 0) {
                             $storeIds[] = $storeId;
                         }
                     }
                 }
                 if (count($storeIds) === 0) {
                     Mage::throwException(Mage::helper('adminhtml')->__('Please, select "Visible in Stores" for this poll first.'));
                 }
                 $pollModel->setStoreIds($storeIds);
             }
             $answers = $this->getRequest()->getParam('answer');
             if (!is_array($answers) || sizeof($answers) == 0) {
                 Mage::throwException(Mage::helper('adminhtml')->__('Please, add some answers to this poll first.'));
             }
             if (is_array($answers)) {
                 $_titles = array();
                 foreach ($answers as $key => $answer) {
                     if (in_array($answer['title'], $_titles)) {
                         Mage::throwException(Mage::helper('adminhtml')->__('Your answers contain duplicates.'));
                     }
                     $_titles[] = $answer['title'];
                     $answerModel = Mage::getModel('poll/poll_answer');
                     if (intval($key) > 0) {
                         $answerModel->setId($key);
                     }
                     $answerModel->setAnswerTitle($answer['title'])->setVotesCount($answer['votes']);
                     $pollModel->addAnswer($answerModel);
                 }
             }
             $pollModel->save();
             Mage::register('current_poll_model', $pollModel);
             $answersDelete = $this->getRequest()->getParam('deleteAnswer');
             if (is_array($answersDelete)) {
                 foreach ($answersDelete as $answer) {
                     $answerModel = Mage::getModel('poll/poll_answer');
                     $answerModel->setId($answer)->delete();
                 }
             }
         } catch (Exception $e) {
             Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
             $this->_initLayoutMessages('adminhtml/session');
             $response->setError(true);
             $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml());
         }
     }
     $this->getResponse()->setBody($response->toJson());
 }