本文整理汇总了PHP中Mage::throwException方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage::throwException方法的具体用法?PHP Mage::throwException怎么用?PHP Mage::throwException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage
的用法示例。
在下文中一共展示了Mage::throwException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: changeColumnPosition
/**
* Change columns position
*
* @param string $table
* @param string $column
* @param boolean $after
* @param boolean $first
* @return Enterprise_SalesArchive_Model_Resource_Helper_Mysql4
*/
public function changeColumnPosition($table, $column, $after = false, $first = false)
{
if ($after && $first) {
if (is_string($after)) {
$first = false;
} else {
$after = false;
}
} elseif (!$after && !$first) {
// If no new position specified
return $this;
}
if (!$this->_getWriteAdapter()->isTableExists($table)) {
Mage::throwException(Mage::helper('enterprise_salesarchive')->__('Table not found'));
}
$columns = array();
$adapter = $this->_getWriteAdapter();
$description = $adapter->describeTable($table);
foreach ($description as $columnDescription) {
$columns[$columnDescription['COLUMN_NAME']] = $adapter->getColumnDefinitionFromDescribe($columnDescription);
}
if (!isset($columns[$column])) {
Mage::throwException(Mage::helper('enterprise_salesarchive')->__('Column not found'));
} elseif ($after && !isset($columns[$after])) {
Mage::throwException(Mage::helper('enterprise_salesarchive')->__('Positioning column not found'));
}
if ($after) {
$sql = sprintf('ALTER TABLE %s MODIFY COLUMN %s %s AFTER %s', $adapter->quoteIdentifier($table), $adapter->quoteIdentifier($column), $columns[$column], $adapter->quoteIdentifier($after));
} else {
$sql = sprintf('ALTER TABLE %s MODIFY COLUMN %s %s FIRST', $adapter->quoteIdentifier($table), $adapter->quoteIdentifier($column), $columns[$column]);
}
$adapter->query($sql);
return $this;
}
示例2: renderConfigureResult
/**
* Prepares and render result of composite product configuration request
*
* $configureResult holds either:
* - 'ok' = true, and 'product_id', 'buy_request', 'current_store_id', 'current_customer' or 'current_customer_id'
* - 'error' = true, and 'message' to show
*
* @param Mage_Adminhtml_Controller_Action $controller
* @param Varien_Object $configureResult
* @return Mage_Adminhtml_Helper_Catalog_Product_Composite
*/
public function renderConfigureResult($controller, Varien_Object $configureResult)
{
try {
if (!$configureResult->getOk()) {
Mage::throwException($configureResult->getMessage());
}
$currentStoreId = (int) $configureResult->getCurrentStoreId();
if (!$currentStoreId) {
$currentStoreId = Mage::app()->getStore()->getId();
}
$product = Mage::getModel('catalog/product')->setStoreId($currentStoreId)->load($configureResult->getProductId());
if (!$product->getId()) {
Mage::throwException($this->__('Product is not loaded.'));
}
Mage::register('current_product', $product);
Mage::register('product', $product);
// Prepare buy request values
$buyRequest = $configureResult->getBuyRequest();
if ($buyRequest) {
Mage::helper('catalog/product')->prepareProductOptions($product, $buyRequest);
}
$isOk = true;
$productType = $product->getTypeId();
} catch (Exception $e) {
$isOk = false;
$productType = null;
Mage::register('composite_configure_result_error_message', $e->getMessage());
}
$this->_initConfigureResultLayout($controller, $isOk, $productType);
$controller->renderLayout();
}
示例3: _beforeToHtml
/**
* Retrieve required options from parent
*/
protected function _beforeToHtml()
{
if (!$this->getParentBlock()) {
Mage::throwException(Mage::helper('adminhtml')->__('Invalid parent block for this block'));
}
parent::_beforeToHtml();
}
示例4: createIndexSitemapFile
/**
* Create additional xml index file with links to other xml files (if number of them more than 1)
*/
public function createIndexSitemapFile()
{
if (sizeof($this->filenamesForIndexSitemap) > 1) {
$io = new Varien_Io_File();
$io->setAllowCreateFolders(true);
$io->open(array('path' => $this->getPath()));
$fileToCreate = Mage::helper('ascurl')->insertStringToFilename($this->getSitemapFilename(), '_index');
if ($io->fileExists($fileToCreate) && !$io->isWriteable($fileToCreate)) {
Mage::throwException(Mage::helper('sitemap')->__('File "%s" cannot be saved. Please, make sure the directory "%s" is writeable by web server.', $fileToCreate, $this->getPath()));
}
$io->streamOpen($fileToCreate);
$io->streamWrite('<?xml version="1.0" encoding="UTF-8"?>' . "\n");
$io->streamWrite('<sitemapindex ' . self::URLSET . '>');
$storeId = $this->getStoreId();
$baseUrl = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
$date = Mage::getSingleton('core/date')->gmtDate('Y-m-d');
$path = $this->getSitemapPath();
$fullPath = preg_replace('/(?<=[^:])\\/{2,}/', '/', $baseUrl . $path);
foreach ($this->filenamesForIndexSitemap as $item) {
$xml = sprintf('<sitemap><loc>%s</loc><lastmod>%s</lastmod></sitemap>', htmlspecialchars($fullPath . $item), $date);
$io->streamWrite($xml);
}
$io->streamWrite('</sitemapindex>');
$io->streamClose();
}
}
示例5: _toHtml
/**
* Render shipping methods xml
*
* @return string
*/
protected function _toHtml()
{
/** @var $methodsXmlObj Mage_XmlConnect_Model_Simplexml_Element */
$methodsXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<shipping_methods></shipping_methods>');
$_shippingRateGroups = $this->getShippingRates();
if ($_shippingRateGroups) {
$store = $this->getQuote()->getStore();
$_sole = count($_shippingRateGroups) == 1;
foreach ($_shippingRateGroups as $code => $_rates) {
$methodXmlObj = $methodsXmlObj->addChild('method');
$methodXmlObj->addAttribute('label', $methodsXmlObj->escapeXml($this->getCarrierName($code)));
$ratesXmlObj = $methodXmlObj->addChild('rates');
$_sole = $_sole && count($_rates) == 1;
foreach ($_rates as $_rate) {
$rateXmlObj = $ratesXmlObj->addChild('rate');
$rateXmlObj->addAttribute('label', $methodsXmlObj->escapeXml($_rate->getMethodTitle()));
$rateXmlObj->addAttribute('code', $_rate->getCode());
if ($_rate->getErrorMessage()) {
$rateXmlObj->addChild('error_message', $methodsXmlObj->escapeXml($_rate->getErrorMessage()));
} else {
$price = Mage::helper('tax')->getShippingPrice($_rate->getPrice(), Mage::helper('tax')->displayShippingPriceIncludingTax(), $this->getAddress());
$formattedPrice = $store->convertPrice($price, true, false);
$rateXmlObj->addAttribute('price', Mage::helper('xmlconnect')->formatPriceForXml($store->convertPrice($price, false, false)));
$rateXmlObj->addAttribute('formated_price', $formattedPrice);
}
}
}
} else {
Mage::throwException($this->__('Shipping to this address is not possible.'));
}
return $methodsXmlObj->asNiceXml();
}
示例6: _beforeDelete
/**
* Check if group uses as default
*
* @param Mage_Core_Model_Abstract $group
* @throws Mage_Core_Exception
* @return Mage_Core_Model_Resource_Db_Abstract
*/
protected function _beforeDelete(Mage_Core_Model_Abstract $group)
{
if ($group->usesAsDefault()) {
Mage::throwException(Mage::helper('Mage_Customer_Helper_Data')->__('The group "%s" cannot be deleted', $group->getCode()));
}
return parent::_beforeDelete($group);
}
示例7: _beforeSave
/**
* Perform actions before object save
*
* @param Mage_Core_Model_Abstract $object
* @return Mage_Core_Model_Resource_Db_Abstract
* @throws Mage_Core_Exception
*/
public function _beforeSave(Mage_Core_Model_Abstract $object)
{
if ($date = $object->getDateFrom()) {
$object->setDateFrom($this->formatDate($date));
} else {
$object->setDateFrom(null);
}
if ($date = $object->getDateTo()) {
$object->setDateTo($this->formatDate($date));
} else {
$object->setDateTo(null);
}
if (!is_null($object->getDateFrom()) && !is_null($object->getDateTo()) && Varien_Date::toTimestamp($object->getDateFrom()) > Varien_Date::toTimestamp($object->getDateTo())) {
Mage::throwException(Mage::helper('core')->__('Start date cannot be greater than end date.'));
}
$check = $this->_checkIntersection($object->getStoreId(), $object->getDateFrom(), $object->getDateTo(), $object->getId());
if ($check) {
Mage::throwException(Mage::helper('core')->__('Your design change for the specified store intersects with another one, please specify another date range.'));
}
if ($object->getDateFrom() === null) {
$object->setDateFrom(new Zend_Db_Expr('null'));
}
if ($object->getDateTo() === null) {
$object->setDateTo(new Zend_Db_Expr('null'));
}
parent::_beforeSave($object);
}
示例8: _afterSave
/**
* REWRITE to properly trigger afterSave event
*
* Check base currency is available in installed currencies
*
* @return Mage_Adminhtml_Model_System_Config_Backend_Currency_Base
*/
protected function _afterSave()
{
if (!in_array($this->getValue(), $this->_getInstalledCurrencies())) {
Mage::throwException(Mage::helper('adminhtml')->__('Selected base currency is not available in installed currencies.'));
}
return parent::_afterSave();
}
示例9: getListType
/**
* Retrieve Product List Type identifier
*
* @throws Mage_Core_Exception
*
* @return int
*/
public function getListType()
{
if (is_null($this->_listType)) {
Mage::throwException(Mage::helper('enterprise_targetrule')->__('Product list type identifier does not defined'));
}
return $this->_listType;
}
示例10: fetchAction
/**
* Forced fetch reports action
*/
public function fetchAction()
{
try {
$reports = Mage::getModel('paypal/report_settlement');
/* @var $reports Mage_Paypal_Model_Report_Settlement */
$credentials = $reports->getSftpCredentials();
if (empty($credentials)) {
Mage::throwException(Mage::helper('paypal')->__('Nothing to fetch because of an empty configuration.'));
}
foreach ($credentials as $config) {
try {
$fetched = $reports->fetchAndSave($config);
$this->_getSession()->addSuccess(Mage::helper('paypal')->__("Fetched %s report rows from '%s@%s'.", $fetched, $config['username'], $config['hostname']));
} catch (Exception $e) {
$this->_getSession()->addError(Mage::helper('paypal')->__("Failed to fetch reports from '%s@%s'.", $config['username'], $config['hostname']));
Mage::logException($e);
}
}
} catch (Mage_Core_Exception $e) {
$this->_getSession()->addError($e->getMessage());
} catch (Exception $e) {
Mage::logException($e);
}
$this->_redirect('*/*/index');
}
示例11: getApiToken
/**
* Get API Token
*
* @return string
*/
public function getApiToken()
{
if (!$this->_apiToken) {
Mage::throwException(Mage::helper('iugu')->__('You need to configure API Token before performing requests.'));
}
return $this->_apiToken;
}
示例12: AutoSubmit
protected function AutoSubmit()
{
$oOrder = $this->_getOrder();
$oBilling = $oOrder->getBillingAddress();
$szHtml = '';
if ($oOrder) {
try {
$oPayment = new AllInOne();
$oPayment->ServiceURL = $this->_getConfigData('test_mode') ? 'http://payment-stage.allpay.com.tw/Cashier/AioCheckOut' : 'https://payment.allpay.com.tw/Cashier/AioCheckOut';
$oPayment->HashKey = $this->_getConfigData('hash_key');
$oPayment->HashIV = $this->_getConfigData('hash_iv');
$oPayment->MerchantID = $this->_getConfigData('merchant_id');
$oPayment->Send['ReturnURL'] = Mage::getUrl('alipay/processing/response');
$oPayment->Send['ClientBackURL'] = Mage::getUrl('');
$oPayment->Send['OrderResultURL'] = Mage::getUrl('alipay/processing/result');
$oPayment->Send['MerchantTradeNo'] = ($this->_getConfigData('test_mode') ? $this->_getConfigData('test_order_prefix') : '') . $oOrder->getIncrementId();
$oPayment->Send['MerchantTradeDate'] = date('Y/m/d H:i:s');
$oPayment->Send['TotalAmount'] = (int) $oOrder->getGrandTotal();
$oPayment->Send['TradeDesc'] = "AllPay_Magento_Module";
$oPayment->Send['ChoosePayment'] = PaymentMethod::Alipay;
$oPayment->Send['Remark'] = '';
$oPayment->Send['ChooseSubPayment'] = PaymentMethodItem::None;
$oPayment->Send['NeedExtraPaidInfo'] = ExtraPaymentInfo::No;
$oPayment->Send['DeviceSource'] = DeviceType::PC;
array_push($oPayment->Send['Items'], array('Name' => Mage::helper('alipay')->__('Commodity Group'), 'Price' => (int) $oOrder->getGrandTotal(), 'Currency' => Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol(), 'Quantity' => 1, 'URL' => ''));
$oPayment->SendExtend['Email'] = $oBilling->getEmail();
$oPayment->SendExtend['PhoneNo'] = $oBilling->getTelephone();
$oPayment->SendExtend['UserName'] = $oBilling->getName();
$szHtml = $oPayment->CheckOutString();
} catch (Exception $e) {
Mage::throwException($e->getMessage());
}
}
return $szHtml;
}
示例13: _beforeSave
/**
* @return Bronto_Common_Model_System_Config_Backend_Token
*/
protected function _beforeSave()
{
$commonHelper = Mage::helper('bronto_common');
$value = $this->getValue();
if (!empty($value)) {
if ($commonHelper->validApiToken($value) === false) {
// reset the verified status
Mage::helper('bronto_verify/apitoken')->setStatus(Mage::helper('bronto_verify/apitoken')->getPath('token_status'), '2', $this->getScope(), $this->getScopeId());
Mage::throwException($commonHelper->__('The Bronto API Token you have entered appears to be invalid.'));
}
// reset the verified status
Mage::helper('bronto_verify/apitoken')->setStatus(Mage::helper('bronto_verify/apitoken')->getPath('token_status'), '1', $this->getScope(), $this->getScopeId());
// Enable Common Module
Mage::getModel('core/config_data')->load(Bronto_Common_Helper_Data::XML_PATH_ENABLED, 'path')->setValue(1)->setPath(Bronto_Common_Helper_Data::XML_PATH_ENABLED)->setScope($this->getScope())->setScopeId($this->getScopeId())->save();
// API key is new and doesn't match existing API key
$currentApiKey = $commonHelper->getApiToken();
if (!empty($currentApiKey) && $currentApiKey !== $value) {
Mage::getSingleton('adminhtml/session')->addNotice($commonHelper->__('You have changed your Bronto API Token so all Bronto modules have been disabled for this configuration scope.' . '<br />Please proceed to each module and reconfigure all available options to avoid undesired behavior.'));
$this->_disableAndUnlink();
}
} else {
Mage::getSingleton('adminhtml/session')->addNotice($commonHelper->__('You have removed your Bronto API Token so all Bronto modules have been disabled for this configuration scope.'));
// reset the verified status
Mage::helper('bronto_verify/apitoken')->setStatus(Mage::helper('bronto_verify/apitoken')->getPath('token_status'), '0', $this->getScope(), $this->getScopeId());
$this->_disableAndUnlink(true);
}
return parent::_beforeSave();
}
示例14: saveAction
public function saveAction()
{
$session = $this->_getSession();
if ($data = $this->getRequest()->getPost()) {
try {
$data['is_shorten'] = empty($data['is_shorten']) ? 0 : $data['is_shorten'];
$data['is_published'] = empty($data['is_published']) ? 1 : $data['is_published'];
if ($data['is_shorten'] == 1 && empty($data['shorten_article'])) {
Mage::throwException('Please write a shorten article or disable it');
}
$model = Mage::getModel('yanws/news');
$model->setData($data)->setId($this->getRequest()->getParam('id'));
$model->save();
$session->addSuccess($this->__('News was saved successfully'));
$session->setFormData(false);
$this->_redirect('*/*/');
} catch (Exception $e) {
$session->addError($e->getMessage());
$session->setFormData($data);
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
}
return;
}
$session->addError($this->__('Unable to find item to save'));
$this->_redirect('*/*/');
}
示例15: _afterSave
/**
* Cron settings after save
*
* @return Mage_Adminhtml_Model_System_Config_Backend_Log_Cron
*/
protected function _afterSave()
{
$enabled = $this->getData('groups/cron/fields/enabled/value');
$time = $this->getData('groups/cron/fields/time/value');
$frequncy = $this->getData('groups/cron/fields/frequency/value');
$frequencyDaily = Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency::CRON_DAILY;
$frequencyWeekly = Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency::CRON_WEEKLY;
$frequencyMonthly = Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency::CRON_MONTHLY;
if ($enabled) {
$cronDayOfWeek = date('N');
$cronExprArray = array(intval($time[1]), intval($time[0]), $frequncy == $frequencyMonthly ? '1' : '*', '*', $frequncy == $frequencyWeekly ? '1' : '*');
$cronExprString = join(' ', $cronExprArray);
} else {
$cronExprString = '';
}
try {
Mage::getModel('core/config_data')->load(self::CRON_STRING_PATH, 'path')->setValue($cronExprString)->setPath(self::CRON_STRING_PATH)->save();
Mage::getModel('core/config_data')->load(self::CRON_MODEL_PATH, 'path')->setValue((string) Mage::getConfig()->getNode(self::CRON_MODEL_PATH))->setPath(self::CRON_MODEL_PATH)->save();
if (!empty($cronExprString)) {
Mage::getSingleton('adminhtml/session')->addNotice(Mage::helper('maverick_crawler')->__('Cron Expression Set To [%s]', $cronExprString));
}
} catch (Exception $e) {
Mage::throwException(Mage::helper('maverick_crawler')->__('Unable to save the cron expression.'));
}
}