本文整理汇总了PHP中Varien_Object::setError方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Object::setError方法的具体用法?PHP Varien_Object::setError怎么用?PHP Varien_Object::setError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Object
的用法示例。
在下文中一共展示了Varien_Object::setError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveAction
/**
* 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()));
}
}
示例2: popupajaxAction
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;
}
示例3: validateAction
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());
}
示例4: confirmAction
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;
}
示例5: saveFormAction
/**
* 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());
}
示例6: jsonProductInfoAction
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());
}
示例7: jsonDeleteAction
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());
}
示例8: saveAction
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());
}
}
示例9: _prepareCollection
/**
* 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;
}
示例10: validateAction
/**
* 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());
}
示例11: validateAction
/**
* 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());
}
示例12: validateAction
/**
* 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());
}
示例13: validateAction
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());
}
示例14: validateAction
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());
}
示例15: validateAction
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());
}