/** * 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())); } }
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; }
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()); }
public function confirmAction() { $updateResult = new Varien_Object(); try { $orderItemId = (int) $this->getRequest()->getParam('item_id'); $options = $this->getRequest()->getParam('options'); $orderItem = Mage::getModel('sales/order_item')->load($orderItemId); $quote = Mage::getModel('sales/quote')->load($orderItem->getOrder()->getQuoteId()); $quoteItem = Mage::getModel('sales/quote_item')->load($orderItem->getQuoteItemId())->setQuote($quote); $buyRequest = $orderItem->getBuyRequest(); $buyRequest->setOptions($options); $products = $orderItem->getProduct()->getTypeInstance(true)->prepareForCartAdvanced($buyRequest, $orderItem->getProduct(), 'lite'); $quoteItem->setOptions($products[0]->getCustomOptions()); $quoteItem->setBuyRequest($buyRequest); $productOptions = $orderItem->getProductOptions(); $productOptions['info_buyRequest'] = $buyRequest->getData(); $productOptions['options'] = Mage::helper('catalog/product_configuration')->getCustomOptions($quoteItem); $orderItem->setProductOptions($productOptions); Mage::dispatchEvent('sales_convert_quote_item_to_order_item', array('order_item' => $orderItem, 'item' => $quoteItem)); $quoteItem->save(); $orderItem->save(); $updateResult->setOk(true); } catch (Exception $e) { $updateResult->setError(true); $updateResult->setMessage($e->getMessage()); } $updateResult->setJsVarName($this->getRequest()->getParam('as_js_varname')); Mage::getSingleton('adminhtml/session')->setCompositeProductResult($updateResult); $this->_redirect('*/catalog_product/showUpdateResult'); return $this; }
/** * 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()); }
public function jsonProductInfoAction() { $response = new Varien_Object(); $id = $this->getRequest()->getParam('id'); if (intval($id) > 0) { $product = Mage::getModel('catalog/product')->load($id); $response->setId($id); $response->addData($product->getData()); $response->setError(0); } else { $response->setError(1); $response->setMessage(Mage::helper('catalog')->__('Unable to get the product ID.')); } $this->getResponse()->setBody($response->toJSON()); }
public function jsonDeleteAction() { $response = new Varien_Object(); $response->setError(0); if ($id = $this->getRequest()->getParam('id')) { try { $model = Mage::getModel('poll/poll_answer'); $model->setId(Zend_Json_Decoder::decode($id))->delete(); } catch (Exception $e) { $response->setError(1); $response->setMessage($e->getMessage()); } } else { $response->setError(1); $response->setMessage(Mage::helper('poll')->__('Unable to find answer to delete.')); } $this->getResponse()->setBody($response->toJson()); }
public function saveAction() { $this->_setTypeId(); $response = new Varien_Object(); $response->setError(0); $modelSet = Mage::getModel('eav/entity_attribute_set')->setId($this->getRequest()->getParam('id'))->setEntityTypeId(Mage::registry('entityType')); if ($this->getRequest()->getParam('gotoEdit')) { $modelSet = Mage::getModel('eav/entity_attribute_set'); $modelSet->setAttributeSetName($this->getRequest()->getParam('attribute_set_name'))->setEntityTypeId(Mage::registry('entityType')); } else { $data = Zend_Json_Decoder::decode($this->getRequest()->getPost('data')); $modelSet->organizeData($data); } try { $modelSet->validate($modelSet->getAttributeSetName()); $modelSet->save(); if ($this->getRequest()->getParam('gotoEdit') == 1) { $modelSet->initFromSkeleton($this->getRequest()->getParam('skeleton_set'))->save(); $this->_redirect('*/*/edit', array('id' => $modelSet->getId())); $this->_getSession()->addSuccess($this->__('Attribute set successfully saved.')); } else { $this->_getSession()->addSuccess($this->__('Attribute set successfully saved.')); // $this->_initLayoutMessages('adminhtml/session'); // $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml()); $response->setUrl($this->getUrl('*/*/edit', array('id' => $modelSet->getId()))); //$this->_redirect('*/*/'); Why? there is Ajax. } } catch (Exception $e) { $this->_getSession()->addError($e->getMessage()); if ($this->getRequest()->getParam('gotoEdit') == 1) { $this->_redirectReferer(); } else { $this->_initLayoutMessages('adminhtml/session'); $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml()); $response->setError(1); } } if ($this->getRequest()->getParam('gotoEdit') != 1) { $this->getResponse()->setBody($response->toJson()); } }
/** * Prepare collection of errors * * @return Enterprise_Checkout_Block_Adminhtml_Sku_Errors_Grid */ protected function _prepareCollection() { $collection = new Varien_Data_Collection(); $removeButtonHtml = $this->getLayout()->createBlock('adminhtml/widget_button', '', array('class' => 'delete', 'label' => '', 'onclick' => 'addBySku.removeFailedItem(this)', 'type' => 'button'))->toHtml(); /* @var $parentBlock Enterprise_Checkout_Block_Adminhtml_Sku_Errors_Abstract */ $parentBlock = $this->getParentBlock(); foreach ($parentBlock->getFailedItems() as $affectedItem) { // Escape user-submitted input if (isset($affectedItem['item']['qty'])) { $affectedItem['item']['qty'] = empty($affectedItem['item']['qty']) ? '' : (double) $affectedItem['item']['qty']; } $item = new Varien_Object(); $item->setCode($affectedItem['code']); if (isset($affectedItem['error'])) { $item->setError($affectedItem['error']); } $item->addData($affectedItem['item']); $item->setId($item->getSku()); /* @var $product Mage_Catalog_Model_Product */ $product = Mage::getModel('catalog/product'); if (isset($affectedItem['item']['id'])) { $productId = $affectedItem['item']['id']; $item->setProductId($productId); $product->load($productId); /* @var $stockStatus Mage_CatalogInventory_Model_Stock_Status */ $stockStatus = Mage::getModel('cataloginventory/stock_status'); $status = $stockStatus->getProductStatus($productId, $this->getWebsiteId()); if (!empty($status[$productId])) { $product->setIsSalable($status[$productId]); } $item->setPrice(Mage::helper('core')->formatPrice($product->getPrice())); } $descriptionBlock = $this->getLayout()->createBlock('enterprise_checkout/adminhtml_sku_errors_grid_description', '', array('product' => $product, 'item' => $item)); $item->setDescription($descriptionBlock->toHtml()); $item->setRemoveButton($removeButtonHtml); $collection->addItem($item); } $this->setCollection($collection); return $this; }
/** * 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()); }
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()); }
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()); }
/** * 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()); }
/** * 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()); }
/** * 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()); }
public function configureQuoteItemsAction() { // Prepare data $configureResult = new Varien_Object(); try { $quoteItemId = (int) $this->getRequest()->getParam('id'); if (!$quoteItemId) { Mage::throwException($this->__('Quote item id is not received.')); } $quoteItem = Mage::getModel('buyback/quote_item')->load($quoteItemId); if (!$quoteItem->getId()) { Mage::throwException($this->__('Quote item is not loaded.')); } $configureResult->setOk(true); $optionCollection = Mage::getModel('buyback/quote_item_option')->getCollection()->addItemFilter(array($quoteItemId)); $quoteItem->setOptions($optionCollection->getOptionsByItem($quoteItem)); $configureResult->setBuyRequest($quoteItem->getBuyRequest()); $configureResult->setCurrentStoreId($quoteItem->getStoreId()); $configureResult->setProductId($quoteItem->getProductId()); $sessionQuote = Mage::getSingleton('adminhtml/session_quote'); $configureResult->setCurrentCustomerId($sessionQuote->getCustomerId()); } catch (Exception $e) { $configureResult->setError(true); $configureResult->setMessage($e->getMessage()); } // Render page /* @var $helper Mage_Adminhtml_Helper_Catalog_Product_Composite */ $helper = Mage::helper('adminhtml/catalog_product_composite'); $helper->renderConfigureResult($this, $configureResult); return $this; }
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()); }
public function likeAction() { $response = new Varien_Object(); $response->setError(0); if (Mage::helper('fbintegrator/like')->canGetPoints()) { $customer = Mage::getSingleton('customer/session')->getCustomer(); $customerId = $customer->getId(); $url = $this->getRequest()->getParam('url'); $pointsForLike = Mage::helper('fbintegrator/like')->getPoints(); $code = $this->getRequest()->getParam('code'); if (Mage::helper('fbintegrator')->getUrlSecretCode($url) !== $code) { $response->setError(1); $this->getResponse()->setBody($response->toJson()); return; } switch ($this->getRequest()->getParam('action')) { case 'like': $validator = Mage::getModel('fbintegrator/like_validator'); /* already liked */ if ($validator->isAlreadyLiked($customerId, $url)) { $response->setError(1); $response->setMessage($this->__('Already liked')); $this->getResponse()->setBody($response->toJson()); return; } /* delay between retries */ $timeToWait = $validator->getTimeToWait($customerId); if ($timeToWait) { $response->setError(1); $response->setMessage($this->__("Please wait %s seconds", $timeToWait)); $this->getResponse()->setBody($response->toJson()); return; } /* N likes per M seconds */ if ($validator->limitLikesPerTimeReached($customerId)) { $response->setError(1); $response->setMessage($this->__("You've already reached the \"like\" limit")); $this->getResponse()->setBody($response->toJson()); return; } /* save new like */ try { $like = Mage::getModel('fbintegrator/like'); $like->setCustomerId($customerId)->setLikeTime(Mage::getModel('core/date')->gmtTimestamp())->setUrl($this->getRequest()->getParam('url'))->save(); $pointsApi = Mage::getModel('points/api'); $transaction = $pointsApi->addTransaction($pointsForLike, 'added_by_admin', $customer, null, array('comment' => $this->__("Facebook Like"))); if (!$transaction) { $response->setError(1); } else { $response->setMessage($this->__("You've just got <b>%s</b> point(s)", $pointsForLike)); } } catch (Exception $exc) { $response->setError(1); } break; case 'unlike': $like = Mage::getModel('fbintegrator/like')->getStoredLike($customerId, $url); if ($like->getId()) { try { $like->delete(); $pointsApi = Mage::getModel('points/api'); $transaction = $pointsApi->addTransaction(-$pointsForLike, 'added_by_admin', $customer, null, array('comment' => $this->__("Facebook Unlike"))); if (!$transaction) { $response->setError(1); } else { $response->setMessage($this->__("Like and get <b>%s</b> point(s)", $pointsForLike)); } } catch (Exception $exc) { $response->setError(1); } } break; default: $response->setError(1); break; } } else { $response->setError(1); } $this->getResponse()->setBody($response->toJson()); }
/** * Customer address validation. * * @param Varien_Object $response * @param Mage_Customer_Model_Customer $customer */ protected function _validateCustomerAddress($response, $customer) { $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); } } } }
public function validateAction() { $response = new Varien_Object(); $response->setError(0); if ($data = $this->getRequest()->getPost()) { $template = $this->_initTemplate('template_id'); try { if (isset($data['template'])) { $template->addData($data['template']); } $template->parse($template->getBody()); } catch (Mzax_Emarketing_Model_Template_Exception $e) { $seesion = $this->_getSession(); foreach ($e->getErrors() as $error) { switch ($error->level) { case LIBXML_ERR_WARNING: $seesion->addWarning("Line {$error->line}/{$error->column}: {$error->message} (#{$error->code})"); break; case LIBXML_ERR_ERROR: $seesion->addError("Line {$error->line}/{$error->column}: {$error->message} (#{$error->code})"); break; case LIBXML_ERR_FATAL: $seesion->addError("Line {$error->line}/{$error->column}: {$error->message} (#{$error->code})"); break; } } $this->_initLayoutMessages('adminhtml/session'); $response->setError(true); $response->setHtmlTemplateErrors($e->getErrors()); $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml()); } 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 saveAction() { // data $fields = $this->getRequest()->getPost('fields'); $useDefault = $this->getRequest()->getPost('use_default'); $data = array(); if (Mage::helper('morphes_admin')->isGlobal()) { $model = Mage::getModel('morphes_filters/filter2')->load($this->getRequest()->getParam('id')); } else { $model = Mage::getModel('morphes_filters/filter2_store')->loadByGlobalId($this->getRequest()->getParam('id'), Mage::helper('morphes_admin')->getStore()->getId()); } $response = new Varien_Object(); $update = array(); /* @var $messages Mage_Adminhtml_Block_Messages */ $messages = $this->getLayout()->createBlock('adminhtml/messages'); try { // processing $model->addEditedData($fields, $useDefault); $model->addEditedDetails($this->getRequest()); $model->validateKeys(); Mage::helper('morphes_db')->replicateObject($model, array($model->getEntityName() => array('saved' => array($model->getId())))); $model->validate(); // do save $model->save(); Mage::dispatchEvent('m_saved', array('object' => $model)); $messages->addSuccess($this->__('Your changes are successfully saved.')); } catch (Morphes_Db_Exception_Validation $e) { foreach ($e->getErrors() as $error) { $messages->addError($error); } $response->setError(true); } catch (Exception $e) { $messages->addError($e->getMessage()); $response->setError(true); } $update[] = array('selector' => '#messages', 'html' => $messages->getGroupedHtml()); $response->setUpdate($update); $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()); }
/** * IFrame handler for submitted configuration for wishlist item * * @return false */ public function updateAction() { // Update wishlist item $updateResult = new Varien_Object(); try { $this->_initData(); $buyRequest = new Varien_Object($this->getRequest()->getParams()); $this->_wishlist->updateItem($this->_wishlistItem->getId(), $buyRequest)->save(); $updateResult->setOk(true); } catch (Exception $e) { $updateResult->setError(true); $updateResult->setMessage($e->getMessage()); } $updateResult->setJsVarName($this->getRequest()->getParam('as_js_varname')); Mage::getSingleton('adminhtml/session')->setCompositeProductResult($updateResult); $this->_redirect('*/catalog_product/showUpdateResult'); return false; }
/** * 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()); }
/** * validate module before saving * @access public * @return void * @author Marius Strajeru <*****@*****.**> */ public function validateAction() { $errors = array(); $response = new Varien_Object(); $response->setError(false); $data = $this->getRequest()->getPost(); $entities = $this->getRequest()->getPost('entity'); $settings = $this->getRequest()->getPost('settings'); if (empty($settings['namespace'])) { $error = new Varien_Object(); $error->setField('settings_namespace'); $error->setMessage(Mage::helper('modulecreator')->__('Fill in the Namespace')); $errors[] = $error->toArray(); } if (empty($settings['module_name'])) { $error = new Varien_Object(); $error->setField('settings_module_name'); $error->setMessage(Mage::helper('modulecreator')->__('Fill in the Module name')); $errors[] = $error->toArray(); } else { $validModule = Mage::helper('modulecreator')->validateModuleName($settings['module_name'], $settings['current_extension']); if (is_string($validModule)) { $error = new Varien_Object(); $error->setMessage($validModule); $error->setField('settings_module_name'); $errors[] = $error->toArray(); } } $validExtension = Mage::helper('modulecreator')->validateExtensionName($settings['namespace'], $settings['module_name'], $settings['current_extension']); if (is_string($validExtension)) { $error = new Varien_Object(); $error->setMessage($validExtension); $errors[] = $error->toArray(); } if (empty($entities)) { $error = new Varien_Object(); $error->setMessage(Mage::helper('modulecreator')->__('Add at least one entity')); $errors[] = $error->toArray(); } else { //validate each entity $noAttributeEntities = false; $noNameEntities = false; foreach ($entities as $key => $entity) { if (empty($entity['name_singular'])) { $error = new Varien_Object(); $error->setMessage(Mage::helper('modulecreator')->__('This is a required field.')); $error->setField('entity_' . $key . '_name_singular'); $errors[] = $error->toArray(); } if (empty($entity['name_plural'])) { $error = new Varien_Object(); $error->setMessage(Mage::helper('modulecreator')->__('This is a required field.')); $error->setField('entity_' . $key . '_name_plural'); $errors[] = $error->toArray(); } if (!isset($entity['attributes']) && !$noAttributeEntities) { $error = new Varien_Object(); $error->setMessage(Mage::helper('modulecreator')->__('There are entities without attribtues. Add attributes or remove them before continuing.')); $errors[] = $error->toArray(); $noAttributeEntities = true; } elseif (isset($entity['attributes'])) { //validate attributes foreach ($entity['attributes'] as $attrKey => $attribute) { if (is_numeric($attrKey)) { $validAttribute = Mage::helper('modulecreator')->validateAttributeName($attribute['code']); if (is_string($validAttribute)) { $error = new Varien_Object(); $error->setMessage($validAttribute); $error->setField('attribute_' . $key . '_' . $attrKey . '_code'); $errors[] = $error->toArray(); } } } } if ((!isset($entity['attributes']) || is_null($entity['attributes']['is_name'])) && !$noNameEntities) { $error = new Varien_Object(); $error->setMessage(Mage::helper('modulecreator')->__('Each entity must have an attribute set to behave as "Name"')); $errors[] = $error->toArray(); $noNameEntities = true; } $validEntity = Mage::helper('modulecreator')->validateEntityName($settings['module_name'], @$entity['name_singular'], $settings['current_extension']); if (is_string($validEntity)) { $error = new Varien_Object(); $error->setMessage($validEntity); $error->setField('entity_' . $key . '_name_singular'); $errors[] = $error->toArray(); } } } try { $module = $this->_initModuleFromData($data); } catch (Exception $e) { $error = new Varien_Object(); $error->setMessage($e->getMessage()); $errors[] = $error->toArray(); } if (count($errors) > 0) { $response->setError(true); $response->setErrors($errors); } $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()); }
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()); }