Пример #1
0
 public function generatePackageXml()
 {
     Mage::getSingleton('adminhtml/session')->setLocalExtensionPackageFormData($this->getData());
     Varien_Pear::$reloadOnRegistryUpdate = false;
     $pkg = new Varien_Pear_Package();
     #$pkg->getPear()->runHtmlConsole(array('command'=>'list-channels'));
     $pfm = $pkg->getPfm();
     $pfm->setOptions(array('packagedirectory' => '.', 'baseinstalldir' => '.', 'simpleoutput' => true));
     $this->_setPackage($pfm);
     $this->_setRelease($pfm);
     $this->_setMaintainers($pfm);
     $this->_setDependencies($pfm);
     $this->_setContents($pfm);
     #echo "<pre>".print_r($pfm,1)."</pre>";
     if (!$pfm->validate(PEAR_VALIDATE_NORMAL)) {
         //echo "<pre>".print_r($this->getData(),1)."</pre>";
         //echo "TEST:";
         //echo "<pre>".print_r($pfm->getValidationWarnings(), 1)."</pre>";
         $message = $pfm->getValidationWarnings();
         //$message = $message[0]['message'];
         throw Mage::exception('Mage_Adminhtml', Mage::helper('adminhtml')->__($message[0]['message']));
         return $this;
     }
     $this->setPackageXml($pfm->getDefaultGenerator()->toXml(PEAR_VALIDATE_NORMAL));
     return $this;
 }
Пример #2
0
 /**
  * @param array|string $key
  * @param null         $value
  *
  * @return $this
  * @throws Mage_Core_Exception
  */
 public function setData($key, $value = null)
 {
     if (is_string($key) && !array_key_exists($key, $this->getStaticData()) && !in_array($key, $this->getApprovedKeys())) {
         throw Mage::exception('Mageplace_Backup', Mage::helper('mpbackup')->__('Wrong object key: %s', $key));
     }
     return parent::setData($key, $value);
 }
Пример #3
0
 public function getNextId()
 {
     $lastId = $this->getLastId();
     if (strpos($lastId, $this->getPrefix()) === 0) {
         $lastId = substr($lastId, strlen($this->getPrefix()));
     }
     $lastId = str_pad((string) $lastId, $this->getPadLength(), $this->getPadChar(), STR_PAD_LEFT);
     $nextId = '';
     $bumpNextChar = true;
     $chars = $this->getAllowedChars();
     $lchars = strlen($chars);
     $lid = strlen($lastId) - 1;
     for ($i = $lid; $i >= 0; $i--) {
         $p = strpos($chars, $lastId[$i]);
         if (false === $p) {
             throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid character encountered in increment ID: %s', $lastId));
         }
         if ($bumpNextChar) {
             $p++;
             $bumpNextChar = false;
         }
         if ($p === $lchars) {
             $p = 0;
             $bumpNextChar = true;
         }
         $nextId = $chars[$p] . $nextId;
     }
     return $this->format($nextId);
 }
 /**
  * Check that the language code value is a valid language code. If it
  * is not, throw an exception.
  *
  * @param string
  * @return self
  * @throws EbayeEnterprise_Eb2cCore_Exception If value is not a valid language code.
  */
 protected function _validateLanguageCode($langCode)
 {
     if (!$this->_langHelper->validateLanguageCode($langCode)) {
         throw Mage::exception('EbayEnterprise_Eb2cCore', $this->_coreHelper->__(self::INVALID_LANGUAGE_CODE_MESSAGE));
     }
     return $this;
 }
Пример #5
0
 /**
  * Load layout updates by handles
  *
  * @param array|string $handles
  * @return Mage_Core_Model_Layout_Update
  */
 public function load($handles = array())
 {
     if (is_string($handles)) {
         $handles = array($handles);
     } elseif (!is_array($handles)) {
         throw Mage::exception('Mage_Core', Mage::helper('core')->__('Invalid layout update handle'));
     }
     foreach ($handles as $handle) {
         $this->addHandle($handle);
     }
     if ($this->loadCache()) {
         return $this;
     }
     $specificTime = null;
     $storeTimeStamp = Mage::app()->getLocale()->storeTimeStamp();
     foreach ($this->getHandles() as $handle) {
         $this->merge($handle);
         /* Set cache lifetime based on layout active to date*/
         if (Mage::app()->useCache('layout')) {
             if ($layoutActiveTo = Mage::getResourceModel('core/layout')->fetchLayoutActiveToByHandle($handle)) {
                 $endDate = Mage::app()->getLocale()->date()->setDate($layoutActiveTo, 'Y-M-d')->setTime('23:59:59')->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
                 $timeDiff = strtotime($endDate) - $storeTimeStamp;
                 if ($timeDiff > 0) {
                     $specificTime = is_null($specificTime) ? $timeDiff : ($specificTime > $timeDiff ? $timeDiff : $specificTime);
                 }
             }
         }
     }
     $this->saveCache($specificTime);
     return $this;
 }
Пример #6
0
 /**
  * Check customer scope, email and confirmation key before saving
  *
  * @param Mage_Customer_Model_Customer $customer
  * @throws Mage_Customer_Exception
  * @return Mage_Customer_Model_Resource_Customer
  */
 protected function _beforeSave(Varien_Object $customer)
 {
     parent::_beforeSave($customer);
     if (!$customer->getEmail()) {
         throw Mage::exception('Mage_Customer', Mage::helper('Mage_Customer_Helper_Data')->__('Customer email is required'));
     }
     $adapter = $this->_getWriteAdapter();
     $bind = array('email' => $customer->getEmail());
     $select = $adapter->select()->from($this->getEntityTable(), array($this->getEntityIdField()))->where('email = :email');
     if ($customer->getSharingConfig()->isWebsiteScope()) {
         $bind['website_id'] = (int) $customer->getWebsiteId();
         $select->where('website_id = :website_id');
     }
     if ($customer->getId()) {
         $bind['entity_id'] = (int) $customer->getId();
         $select->where('entity_id != :entity_id');
     }
     $result = $adapter->fetchOne($select, $bind);
     if ($result) {
         throw Mage::exception('Mage_Customer', Mage::helper('Mage_Customer_Helper_Data')->__('This customer email already exists'), Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS);
     }
     // set confirmation key logic
     if ($customer->getForceConfirmed()) {
         $customer->setConfirmation(null);
     } elseif (!$customer->getId() && $customer->isConfirmationRequired()) {
         $customer->setConfirmation($customer->getRandomConfirmationKey());
     }
     // remove customer confirmation key from database, if empty
     if (!$customer->getConfirmation()) {
         $customer->setConfirmation(null);
     }
     return $this;
 }
 /**
  * Initialize the class
  * @throws Mage_Core_Exception
  */
 public function _construct()
 {
     list($this->config) = $this->checkTypes($this->nullCoalesce($this->getArgs(), 'config', Mage::helper('membersonly/config')));
     if (!$this instanceof Mage_Core_Block_Template) {
         throw Mage::exception('Mage_Core', 'Invalid use of trait ' . get_class());
     }
 }
 protected function _validateGiftCardForStorate(EbayEnterprise_GiftCard_Model_IGiftcard $card)
 {
     if ($card->getCardNumber()) {
         return $this;
     }
     throw Mage::exception('EbayEnterprise_GiftCard', 'Invalid gift card.');
 }
Пример #9
0
 public function authenticate($login, $password)
 {
     // We need to websiteId value before load By Email
     $subAccountMode = false;
     $websiteId = $this->getWebsiteId();
     $useSubAccount = Mage::helper('cminds_multiuseraccounts')->isEnabled();
     $this->loadByEmail($login);
     $account = $this;
     if (!$account->getId() && $useSubAccount) {
         // No Main Account found try with SubAccount
         $account = Mage::getModel('cminds_multiuseraccounts/subAccount')->setWebsiteId($websiteId);
         $account->loadByEmail($login);
         $subAccountMode = true;
     }
     if ($account->getConfirmation() && $account->isConfirmationRequired()) {
         throw Mage::exception('Mage_Core', Mage::helper('customer')->__('This account is not confirmed.'), self::EXCEPTION_EMAIL_NOT_CONFIRMED);
     }
     if (!$account->validatePassword($password)) {
         throw Mage::exception('Mage_Core', Mage::helper('customer')->__('Invalid login or password.'), self::EXCEPTION_INVALID_EMAIL_OR_PASSWORD);
     }
     if ($subAccountMode) {
         $this->load($account->getParentCustomerId());
         $customerSession = Mage::getSingleton('customer/session');
         $customerSession->setSubAccount($account);
         $beforeUrl = $customerSession->getBeforeAuthUrl();
         if (strpos($beforeUrl, 'customer/account/subAccount') !== false) {
             $customerSession->setBeforeAuthUrl(Mage::helper('customer')->getAccountUrl());
         }
     }
     Mage::dispatchEvent('customer_customer_authenticated', array('model' => $this, 'password' => $password));
     return true;
 }
Пример #10
0
 /**
  * Formating date value before save
  *
  * Should set (bool, string) correct type for empty value from html form,
  * neccessary for farther proccess, else date string
  *
  * @param Varien_Object $object
  * @throws Mage_Eav_Exception
  * @return Mage_Eav_Model_Entity_Attribute_Backend_Datetime
  */
 public function beforeSave($object)
 {
     $attributeName = $this->getAttribute()->getName();
     $_formated = $object->getData($attributeName . '_is_formated');
     if (!$_formated && $object->hasData($attributeName)) {
         try {
             if (Mage::app()->getLocale()->getLocale() == 'fa_IR') {
                 require_once Mage::getBaseDir('lib') . '/pdate/pdate.php';
                 if ($object->getData($attributeName) != NULL) {
                     list($j_y, $j_m, $j_d) = explode('/', $object->getData($attributeName));
                     $gregorianlArray = jalali_to_gregorian($j_y, $j_m, $j_d);
                     $date = implode('-', $gregorianlArray);
                     $object->setData($attributeName, $date);
                 }
             }
             $value = $this->formatDate($object->getData($attributeName));
         } catch (Exception $e) {
             throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid date'));
         }
         if (is_null($value)) {
             $value = $object->getData($attributeName);
         }
         //Mage::log( "$attributeName, $value ") ;
         $object->setData($attributeName, $value);
         $object->setData($attributeName . '_is_formated', true);
     }
     return $this;
 }
Пример #11
0
 /**
  * Process single job
  *
  * @return Xcom_Initializer_Model_Job
  * @throws Mage_Core_Exception
  */
 public function process()
 {
     /** @var $message Xcom_Xfabric_Model_Message_Request */
     $message = Mage::helper('xcom_xfabric')->getMessage($this->getTopic());
     if (!$message) {
         throw Mage::exception('Xcom_Xfabric', Mage::helper('xcom_xfabric')->__("Message for topic %s should be created", $this->getTopic()));
     }
     $data = json_decode($this->getMessageParams(), true);
     $message->process(new Varien_Object($data));
     // we set the flag to make requests slower since it adds a timeout to wait for responce
     $message->setIsWaitResponse();
     // Save correlationId to get stub scenario working
     Mage::getModel('xcom_initializer/job')->load($this->getJobId())->setCorrelationId($message->getCorrelationId())->save();
     try {
         Mage::helper('xcom_xfabric')->getTransport()->setMessage($message)->send();
     } catch (Exception $ex) {
         Mage::logException($ex);
     }
     /*
     Update only jobs in pending status since we could get responses from the stub
     and some jobs are already set to saved status at the moment
     */
     Mage::getResourceModel('xcom_initializer/job')->updateStatusByCorrelationId(Xcom_Initializer_Model_Job::STATUS_SENT, $message->getCorrelationId(), array('status = ?' => Xcom_Initializer_Model_Job::STATUS_PENDING));
     return $this;
 }
Пример #12
0
 /**
  * @$forceCreation true overwrites existing entities with the new values
  */
 public function import($forceCreation = false)
 {
     if (is_null($this->_entity)) {
         throw Mage::exception('Please specify a valid entity.');
     }
     if (!file_exists($this->_importFile)) {
         throw Mage::exception('Please specify a valid csv file.');
     }
     if (is_null($this->_storeId)) {
         throw Mage::exception('Please specify a valid store.');
     }
     $io = new Varien_Io_File();
     $io->streamOpen($this->_importFile, 'r');
     $io->streamLock(true);
     $firstLine = true;
     while (false !== ($line = $io->streamReadCsv())) {
         if ($firstLine) {
             $firstLine = false;
             $this->_headerColumns = $line;
             continue;
         }
         $data = array();
         foreach ($this->_headerColumns as $key => $val) {
             $data[$val] = $line[$key];
         }
         $this->_importEntity($data, $forceCreation);
     }
 }
Пример #13
0
 /**
  * Send transactional email to recipient
  *
  * @param   int $templateId
  * @param   string|array $sender sneder informatio, can be declared as part of config path
  * @param   string $email recipient email
  * @param   string $name recipient name
  * @param   array $vars varianles which can be used in template
  * @param   int|null $storeId
  * @return  Mage_Core_Model_Email_Template
  */
 public function sendTransactional($templateId, $sender, $email, $name, $vars = array(), $storeId = null)
 {
     $this->setSentSuccess(false);
     if ($storeId === null && $this->getDesignConfig()->getStore()) {
         $storeId = $this->getDesignConfig()->getStore();
     }
     if (is_numeric($templateId)) {
         $this->load($templateId);
     } else {
         $localeCode = Mage::getStoreConfig('general/locale/code', $storeId);
         $this->loadDefault($templateId, $localeCode);
     }
     if (!$this->getId()) {
         throw Mage::exception('Mage_Core', Mage::helper('core')->__('Invalid transactional email code: ' . $templateId));
     }
     if (!is_array($sender)) {
         $this->setSenderName(Mage::getStoreConfig('trans_email/ident_' . $sender . '/name', $storeId));
         $this->setSenderEmail(Mage::getStoreConfig('trans_email/ident_' . $sender . '/email', $storeId));
     } else {
         $this->setSenderName($sender['name']);
         $this->setSenderEmail($sender['email']);
     }
     if (!isset($vars['store'])) {
         $vars['store'] = Mage::app()->getStore($storeId);
     }
     if (Mage::getStoreConfig("gemgento_email/settings/enabled")) {
         $this->setSentSuccess($this->gemgentoSend($email, $name, $vars));
     } else {
         $this->setSentSuccess($this->send($email, $name, $vars));
     }
     return $this;
 }
Пример #14
0
 public function checkOrderCreationAuth($observer)
 {
     $helper = Mage::helper('cminds_multiuseraccounts');
     if (!$helper->hasCreateOrderPermission()) {
         throw Mage::exception('Mage_Core', $helper->__('No Order creation permission for this account'));
     }
     return;
 }
 /**
  * Get the ROM Tender Type for the Magento CC Type.
  * @param  string $creditCardType
  * @return string
  */
 public function getTenderTypeForCcType($creditCardType)
 {
     $types = $this->getConfigModel()->tenderTypes;
     if (isset($types[$creditCardType])) {
         return $types[$creditCardType];
     }
     throw Mage::exception('EbayEnterprise_CreditCard', self::UNKNOWN_CARD_TYPE);
 }
Пример #16
0
 /**
  *
  * @param string $message
  * @param int $code
  * @throws Creativestyle_CheckoutByAmazon_Exception
  */
 public function throwException($message, $code = 0, $params = array())
 {
     $exception = Mage::exception('Creativestyle_CheckoutByAmazon', $message, $code);
     if (!$this->isExceptionLoggingLocked()) {
         Creativestyle_CheckoutByAmazon_Model_Logger::logException($message, $code ? $code : 0, $exception->getTraceAsString(), isset($params['area']) ? $params['area'] : 'General', isset($params['request_id']) ? $params['request_id'] : null, isset($params['orders']) ? $params['orders'] : null);
     }
     throw $exception;
 }
Пример #17
0
 /**
  * Create CSV files
  * @param  string $file the csv file to create
  * @return self
  * @throws EbayEnterprise_Display_Model_File_Exception
  */
 public function openCsvFile($file)
 {
     $this->_stream = fopen($file, 'w');
     if ($this->_stream === false) {
         throw Mage::exception('EbayEnterprise_Display_Model_File', 'Cannot open file for writing in ' . dirname($file) . '.');
     }
     return $this;
 }
Пример #18
0
 /**
  * Processing object before save data
  *
  * @return Mage_Core_Model_Abstract
  */
 protected function _beforeSave()
 {
     if ($this->_getResource()->isUsedBySuperProducts($this)) {
         throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('This attribute is used in configurable products'));
     }
     $this->setData('modulePrefix', self::MODULE_NAME);
     return parent::_beforeSave();
 }
Пример #19
0
 public function getDir($type)
 {
     $method = 'get' . ucwords($type) . 'Dir';
     $dir = $this->{$method}();
     if (!$dir) {
         throw Mage::exception('Mage_Core', 'Invalid dir type requested: ' . $type);
     }
     return $dir;
 }
Пример #20
0
 public function testAuthenticateMageWebapiException()
 {
     /** Prepare mocks for SUT constructor. */
     $this->_oauthServerMock->expects($this->once())->method('authenticateTwoLegged')->will($this->throwException(Mage::exception('Mage_Oauth', 'Exception message.', Mage_Oauth_Model_Server::HTTP_BAD_REQUEST)));
     $this->setExpectedException('Mage_Webapi_Exception', 'Exception message.', Mage_Webapi_Exception::HTTP_UNAUTHORIZED);
     $this->_oauthServerMock->expects($this->once())->method('reportProblem')->will($this->returnValue('Exception message.'));
     /** Execute SUT. */
     $this->_restAuthentication->authenticate();
 }
 /**
  * Search through registered config models for one that knows about the key
  * and get the actual config path from it for the lookup.
  *
  * @param string $configKey
  * @param null|string|bool|int|Mage_Core_Model_Store $store
  * @param bool $asFlag
  * @throws Mage_Core_Exception if the config path is not found.
  * @return string|bool
  */
 protected function _getStoreConfigValue($configKey, $store, $asFlag)
 {
     foreach ($this->_configModels as $configModel) {
         if ($configModel->hasKey($configKey)) {
             $configMethod = $asFlag ? 'getStoreConfigFlag' : 'getStoreConfig';
             return Mage::$configMethod($configModel->getPathForKey($configKey), $store);
         }
     }
     throw Mage::exception('Mage_Core', "Configuration path specified by '{$configKey}' was not found.");
 }
Пример #22
0
 /**
  * Add an object to the collection
  *
  * @param Varien_Object $object
  * @return Mage_Eav_Model_Entity_Collection_Abstract
  */
 public function addItem(Varien_Object $object)
 {
     if (get_class($object) !== $this->_itemObjectClass) {
         throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Attempt to add an invalid object'));
     }
     try {
         return parent::addItem($object);
     } catch (Exception $ex) {
     }
 }
Пример #23
0
 public function authenticate($login, $password)
 {
     if (!$this->getConfirmation() && $this->isConfirmationRequired()) {
         throw Mage::exception('Mage_Core', Mage::helper('customer')->__('This account is not confirmed.'), self::EXCEPTION_EMAIL_NOT_CONFIRMED);
     }
     if (!$this->validatePassword($password)) {
         throw Mage::exception('Mage_Core', Mage::helper('customer')->__('Invalid login or password.'), self::EXCEPTION_INVALID_EMAIL_OR_PASSWORD);
     }
     return true;
 }
 /**
  * Add a gift card to the container. Will make the gift card balance check
  * and make sure card can be applied to the order.
  * @param EbayEnterprise_GiftCard_Model_IGiftcard $card
  * @return self
  * @throws EbayEnterprise_GiftCard_Exception If gift card could not be added to the order.
  */
 public function addGiftCardToOrder(EbayEnterprise_GiftCard_Model_IGiftcard $card, EbayEnterprise_GiftCard_Model_IContainer $giftCardContainer)
 {
     $card->checkBalance();
     // Treat 0 balance gift cards as invalid.
     if ($card->getBalanceAmount() <= 0) {
         throw Mage::exception('EbayEnterprise_GiftCard', $this->__(self::ZERO_BALANCE_CARD_MESSAGE, $card->getCardNumber()));
     }
     $giftCardContainer->updateGiftCard($card);
     return $this;
 }
Пример #25
0
 protected function _beforeSave()
 {
     if (!Mage::getSingleton('adminhtml/session')->getIsForFME() || Mage::getSingleton('adminhtml/session')->getIsForFME() == false) {
         if ($this->_getResource()->isUsedBySuperProducts($this)) {
             throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('This attribute is used in configurable products'));
         }
         $this->setData('modulePrefix', self::MODULE_NAME);
         return parent::_beforeSave();
     }
 }
 protected function _beforeSave()
 {
     $data = $this->getData();
     $analyticsAccount = $data['groups']['analytics']['fields']['account']['value'];
     $analyticsPlusAccount = $data['groups']['analyticsplus_classic']['fields']['accountnumber2']['value'];
     if (!empty($analyticsPlusAccount) && !empty($analyticsAccount) && $analyticsAccount == $analyticsPlusAccount) {
         throw Mage::exception('Mage_Core', Mage::helper('adminhtml')->__('Your alternative account number needs to be different to your existing account number.'));
     }
     return true;
 }
Пример #27
0
 public function addExpressionToSelect($alias, $expression)
 {
     // validate alias
     if (isset($this->_joinFields[$alias])) {
         throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Joined field or attribute expression with this alias is already declared'));
     }
     $this->getSelect()->from(null, array($alias => $expression));
     $this->_joinFields[$alias] = array('table' => false, 'field' => $expression);
     return $this;
 }
Пример #28
0
 /**
  * Validation callback for checking is file is image
  *
  * @param  string $filePath Path to temporary uploaded file
  * @return null
  * @throws Mage_Core_Exception
  */
 public function validate($filePath)
 {
     $fileInfo = getimagesize($filePath);
     if (is_array($fileInfo) and isset($fileInfo[2])) {
         if ($this->isImageType($fileInfo[2])) {
             return null;
         }
     }
     throw Mage::exception('Mage_Core', Mage::helper('core')->__('Invalid MIME type.'));
 }
 /**
  * Lookup the tender type for given gift card.
  * @param string
  * @param string
  * @param bool
  * @return string
  * @throws EbayEnterprise_GiftCard_Exception_InvalidCardNumber_Exception If card number cannot be retrieved.
  */
 public function lookupTenderType($cardNumber, $currencyCode, $panIsToken = false)
 {
     try {
         $api = $this->getTenderTypeLookupApi();
         return $this->createTenderTypeLookup($cardNumber, $currencyCode, $api, $panIsToken)->getTenderType();
     } catch (EbayEnterprise_GiftCard_Exception_TenderTypeLookupFailed_Exception $e) {
         $this->logger->error('Unable to lookup tender type', $this->logContext->getMetaData(__CLASS__, [], $e));
         throw Mage::exception('EbayEnterprise_GiftCard_Exception_InvalidCardNumber', $this->helper->__(self::INVLIAD_CARD_NUMBER_MESSAGE, $cardNumber));
     }
 }
 /**
  * @dataProvider dataProvider
  */
 public function testEmailSuppressionOff($testModel, $testMethod)
 {
     $this->setExpectedException('Mage_Core_Exception', 'this exception is expected');
     $this->replaceCoreConfigRegistry(['transactionalEmailer' => 'mage']);
     $store = Mage::app()->getStore();
     $testModel = $this->getModelMock($testModel, ['_getEmails', 'getStore']);
     $testModel->expects($this->any())->method('getStore')->will($this->returnValue($store));
     $testModel->expects($this->once())->method('_getEmails')->will($this->throwException(Mage::exception('Mage_Core', 'this exception is expected')));
     $testModel->{$testMethod}();
 }