/** * 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())); } }
/** * Tries to ping AvaTax service with provided credentials * * @param int $storeId * @return bool|array */ public function ping($storeId = null) { /** @var OnePica_AvaTax_Model_Service_Avatax16_Config $config */ $config = $this->getServiceConfig(); $connection = $config->getTaxConnection(); $result = null; $message = ''; try { /** @var OnePica\AvaTax16\AddressResolution\PingResponse $result */ $result = $connection->ping(); } catch (Exception $exception) { $message = $exception->getMessage(); } if (!isset($result) || !is_object($result) || !$result->getHasError()) { $actualResult = $result; $result = new Varien_Object(); $result->setHasError($result->getHasError()); $result->setActualResult($actualResult); $result->setMessage($message); } $this->_log(OnePica_AvaTax_Model_Source_Avatax_Logtype::PING, new stdClass(), $result, $storeId, $config->getParams()); if ($result->getHasError()) { if (is_array($result->getErrors())) { $messages = array(); foreach ($result->getErrors() as $messageItem) { $messages[] = $this->__($messageItem); } $message .= implode(' ', $messages); } } if (!$message) { $message = $this->__('The user or account could not be authenticated.'); } return !$result->getHasError() ? true : $message; }
public function getLineCollection() { $maxCollectionSize = max(1, $this->mHelper('config')->getLogViewerMaxCollectionSize()); $regExp = '/(\\d+-\\d+-\\d+T\\d+[0-9\\-+T:]+?)\\s+?([A-Z]+?)\\s+?\\((\\d+)\\)\\:\\s+?(.+?)(?:(?=(?:\\d+-\\d+-\\d+T\\d+[0-9\\-+T:]+?))|$)/si'; $contents = file_get_contents($this->getPath()); $lines = array(); if (preg_match_all($regExp, $contents, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { $lines[] = $match[0]; } } $lines = array_reverse($lines); $collection = Mage::getModel('ewcore/system_log_file_line_collection'); foreach ($lines as $line) { if ($collection->count() >= $maxCollectionSize) { break; } $line = trim($line); if (preg_match($regExp, $line, $match)) { list($date, $priorityName, $priority, $message) = array_slice($match, 1); $message = trim($message); if ($date and $priorityName and $priority and $message) { $item = new Varien_Object(); $item->setDate($date); $item->setPriorityName($priorityName); $item->setPriority($priority); $item->setMessage($message); $collection->addItem($item); } } } return $collection; }
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; }
/** * Return response object * * @return Varien_Object */ protected function _prepareResponseObject() { $responseObject = new Varien_Object(); $responseObject->setStatus(false); $responseObject->setResponse(null); $responseObject->setMessage(null); return $responseObject; }
public function testPaymentCapturedLifecyceEvent() { $expectedValue = new Varien_Object(); $expectedValue->setMessage('Captured Payment'); $observer = $this->mockModel('deg_orderlifecycle/hooks', array('_dispatchEvent')); $observer->expects($this->any())->method('_dispatchEvent')->with('lifecycle_event', $expectedValue); $observerObject = new Varien_Event_Observer(); $observer->paymentCaptureLifecyceEvent($observerObject); }
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()); }
protected function _prepareCollection() { $collection = new Varien_Data_Collection(); $logs = explode("\n\n", $this->getJob()->getLog()); foreach ($logs as $log) { @(list($date, $message) = explode("\t", $log, 2)); if ($date and $message) { $object = new Varien_Object(); $object->setCreatedAt($date); $object->setMessage($message); $collection->addItem($object); } } $this->setCollection($collection); return parent::_prepareCollection(); }
/** * 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 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->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.')); $response->setMessage(Mage::helper('catalog')->__('Attribute set successfully saved.')); $this->_redirect('*/*/'); } } catch (Exception $e) { if ($this->getRequest()->getParam('gotoEdit') == 1) { $this->_getSession()->addError($this->__('Attribute set with the same name already exists.')); $this->_redirectReferer(); } else { $this->_getSession()->addError($this->__('Attribute set with the same name already exists.')); $this->_initLayoutMessages('adminhtml/session'); $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml()); $response->setError(1); } } if ($this->getRequest()->getParam('gotoEdit') != 1) { $this->getResponse()->setBody($response->toJson()); } }
/** * Tries to ping AvaTax service with provided credentials * * @param int $storeId * @return bool|array */ public function ping($storeId = null) { /** @var OnePica_AvaTax_Model_Config $config */ $config = $this->getServiceConfig(); $connection = $config->getTaxConnection(); $result = null; $message = null; try { $result = $connection->ping(); } catch (Exception $exception) { $message = $exception->getMessage(); } if (!isset($result) || !is_object($result) || !$result->getResultCode()) { $actualResult = $result; $result = new Varien_Object(); $result->setResultCode(SeverityLevel::$Exception); $result->setActualResult($actualResult); $result->setMessage($message); } $this->_log(OnePica_AvaTax_Model_Source_Avatax_Logtype::PING, new stdClass(), $result, $storeId, $config->getParams()); return $result->getResultCode() == SeverityLevel::$Success ? true : $result->getMessage(); }
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()); }
/** * Checking quote item quantity * * @param mixed $qty quantity of this item (item qty x parent item qty) * @param mixed $summaryQty quantity of this product in whole shopping cart which should be checked for stock availability * @param mixed $origQty original qty of item (not multiplied on parent item qty) * @return Varien_Object */ public function checkQuoteItemQty($qty, $summaryQty, $origQty = 0) { $result = new Varien_Object(); $result->setHasError(false); if (!is_numeric($qty)) { $qty = Mage::app()->getLocale()->getNumber($qty); } /** * Check quantity type */ $result->setItemIsQtyDecimal($this->getIsQtyDecimal()); if (!$this->getIsQtyDecimal()) { $result->setHasQtyOptionUpdate(true); $qty = intval($qty); /** * Adding stock data to quote item */ $result->setItemQty($qty); if (!is_numeric($qty)) { $qty = Mage::app()->getLocale()->getNumber($qty); } $origQty = intval($origQty); $result->setOrigQty($origQty); } if ($this->getMinSaleQty() && $qty < $this->getMinSaleQty()) { $result->setHasError(true)->setMessage(Mage::helper('cataloginventory')->__('The minimum quantity allowed for purchase is %s.', $this->getMinSaleQty() * 1))->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in the requested quantity'))->setQuoteMessageIndex('qty'); return $result; } if ($this->getMaxSaleQty() && $qty > $this->getMaxSaleQty()) { $result->setHasError(true)->setMessage(Mage::helper('cataloginventory')->__('The maximum quantity allowed for purchase is %s.', $this->getMaxSaleQty() * 1))->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products can not be ordered in requested quantity'))->setQuoteMessageIndex('qty'); return $result; } if (!$this->getManageStock()) { return $result; } if (!$this->getIsInStock()) { $result->setHasError(true)->setMessage(Mage::helper('cataloginventory')->__('This product is currently out of stock.'))->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products are currently out of stock'))->setQuoteMessageIndex('stock'); $result->setItemUseOldQty(true); return $result; } if (!$this->checkQty($summaryQty)) { $message = Mage::helper('cataloginventory')->__('The requested quantity for "%s" is not available.', $this->getProduct()->getName()); $result->setHasError(true)->setMessage($message)->setQuoteMessage($message)->setQuoteMessageIndex('qty'); return $result; } else { if ($this->getQty() - $summaryQty < 0) { if ($this->getProduct()) { $backorderQty = $this->getQty() > 0 ? ($summaryQty - $this->getQty()) * 1 : $qty * 1; if ($backorderQty > $qty) { $backorderQty = $qty; } $result->setItemBackorders($backorderQty); if ($this->getBackorders() == Mage_CatalogInventory_Model_Stock::BACKORDERS_YES_NOTIFY) { $result->setMessage(Mage::helper('cataloginventory')->__('This product is not available in the requested quantity. %d of the items will be backordered.', $backorderQty, $this->getProduct()->getName())); } } } // no return intentionally } return $result; }
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()); }
/** * 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 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 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()); }
/** * 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()); }
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 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)); $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()); }
/** * Check qty increments * * @param int|float $qty * @return Varien_Object */ public function checkQtyIncrements($qty) { $result = new Varien_Object(); if ($this->getSuppressCheckQtyIncrements()) { return $result; } $qtyIncrements = $this->getQtyIncrements(); if ($qtyIncrements && Mage::helper('core')->getExactDivision($qty, $qtyIncrements) != 0) { $result->setHasError(true)->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in the requested quantity.'))->setErrorCode('qty_increments')->setQuoteMessageIndex('qty'); if ($this->getIsChildItem()) { $result->setMessage(Mage::helper('cataloginventory')->__('%s is available for purchase in increments of %s only.', $this->getProductName(), $qtyIncrements * 1)); } else { $result->setMessage(Mage::helper('cataloginventory')->__('This product is available for purchase in increments of %s only.', $qtyIncrements * 1)); } } return $result; }
/** * 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 checkQtyIncrements($item, $qty) { // $product = $item->getData('product'); if (is_numeric($item)) { $_product = Mage::getModel('catalog/product')->load($item); } elseif ($item instanceof Mage_Catalog_Model_Product) { $_product = $item; } elseif ($item->getData('product') instanceof Mage_Catalog_Model_Product) { $_product = $item->getData('product'); } else { throw new Exception(Mage::helper('qquoteadv')->__("incorrect first parameter for checkQtyIncrements should be product or product_id")); } $stockItem = $_product->getStockItem(); $qtyIncrements = $stockItem->getQtyIncrements(); $result = new Varien_Object(); if ($qtyIncrements && $qty % $qtyIncrements != 0) { $result->setHasError(true)->setProductUrl($_product->getProductUrl())->setQuoteMessage(Mage::helper('qquoteadv')->__('%s cannot be added to the quotation in the requested quantity.', $_product->getName()))->setErrorCode('qty_increments')->setQuoteMessageIndex('qty'); $result->setMessage(Mage::helper('qquoteadv')->__('%s is available for quotation in increments of %s only.', $_product->getName(), $qtyIncrements * 1)); } return $result; }
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 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() { $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()); }
/** * Get validation message that will be displayed to user by VAT validation result object * * @param Mage_Customer_Model_Address $customerAddress * @param bool $customerGroupAutoAssignDisabled * @param Varien_Object $validationResult * @return Varien_Object */ public function getVatValidationUserMessage($customerAddress, $customerGroupAutoAssignDisabled, $validationResult) { $message = ''; $isError = true; $customerVatClass = $this->getCustomerVatClass($customerAddress->getCountryId(), $validationResult); $groupAutoAssignDisabled = Mage::getStoreConfigFlag(self::XML_PATH_CUSTOMER_VIV_GROUP_AUTO_ASSIGN); $willChargeTaxMessage = $this->__('You will be charged tax.'); $willNotChargeTaxMessage = $this->__('You will not be charged tax.'); if ($validationResult->getIsValid()) { $message = $this->__('Your VAT ID was successfully validated.'); $isError = false; if (!$groupAutoAssignDisabled && !$customerGroupAutoAssignDisabled) { $message .= ' ' . ($customerVatClass == self::VAT_CLASS_DOMESTIC ? $willChargeTaxMessage : $willNotChargeTaxMessage); } } else { if ($validationResult->getRequestSuccess()) { $message = sprintf($this->__('The VAT ID entered (%s) is not a valid VAT ID.') . ' ', $this->escapeHtml($customerAddress->getVatId())); if (!$groupAutoAssignDisabled && !$customerGroupAutoAssignDisabled) { $message .= $willChargeTaxMessage; } } else { $contactUsMessage = sprintf($this->__('If you believe this is an error, please contact us at %s'), Mage::getStoreConfig(self::XML_PATH_SUPPORT_EMAIL)); $message = $this->__('Your Tax ID cannot be validated.') . ' ' . (!$groupAutoAssignDisabled && !$customerGroupAutoAssignDisabled ? $willChargeTaxMessage . ' ' : '') . $contactUsMessage; } } $validationMessageEnvelope = new Varien_Object(); $validationMessageEnvelope->setMessage($message); $validationMessageEnvelope->setIsError($isError); return $validationMessageEnvelope; }
/** * 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()); }