Esempio n. 1
0
 public function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     $format = AO::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
     if ($date = $object->getDateFrom()) {
         $date = AO::app()->getLocale()->date($date, $format, null, false);
         $object->setDateFrom($date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT));
     } else {
         $object->setDateFrom(null);
     }
     if ($date = $object->getDateTo()) {
         $date = AO::app()->getLocale()->date($date, $format, null, false);
         $object->setDateTo($date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT));
     } else {
         $object->setDateTo(null);
     }
     if (!is_null($object->getDateFrom()) && !is_null($object->getDateTo()) && strtotime($object->getDateFrom()) > strtotime($object->getDateTo())) {
         AO::throwException(AO::helper('core')->__('Start date can\'t be greater than end date'));
     }
     $check = $this->_checkIntersection($object->getStoreId(), $object->getDateFrom(), $object->getDateTo(), $object->getId());
     if ($check) {
         AO::throwException(AO::helper('core')->__('Your design change for the specified store intersects with another one, please specify another date range'));
     }
     if (is_null($object->getDateFrom())) {
         $object->setDateFrom(new Zend_Db_Expr('null'));
     }
     if (is_null($object->getDateTo())) {
         $object->setDateTo(new Zend_Db_Expr('null'));
     }
     parent::_beforeSave($object);
 }
Esempio n. 2
0
 protected function _beforeDelete(Mage_Core_Model_Abstract $group)
 {
     if ($group->usesAsDefault()) {
         AO::throwException(AO::helper('customer')->__('Group "%s" can not be deleted', $group->getCode()));
     }
     return parent::_beforeDelete($group);
 }
 /**
  * Prepare option value for cart
  *
  * @throws Mage_Core_Exception
  * @return mixed Prepared option value
  */
 public function prepareForCart()
 {
     if ($this->getIsValid()) {
         return is_array($this->getUserValue()) ? implode(',', $this->getUserValue()) : $this->getUserValue();
     }
     AO::throwException(AO::helper('catalog')->__('Option validation failed to add product to cart'));
 }
Esempio n. 4
0
 /**
  * Try to login user in admin
  *
  * @param  string $username
  * @param  string $password
  * @param  Mage_Core_Controller_Request_Http $request
  * @return Mage_Admin_Model_User|null
  */
 public function login($username, $password, $request = null)
 {
     if (empty($username) || empty($password)) {
         return;
     }
     try {
         /* @var $user Mage_Admin_Model_User */
         $user = AO::getModel('admin/user');
         $user->login($username, $password);
         if ($user->getId()) {
             if (AO::getSingleton('adminhtml/url')->useSecretKey()) {
                 AO::getSingleton('adminhtml/url')->renewSecretUrls();
             }
             $session = AO::getSingleton('admin/session');
             $session->setIsFirstVisit(true);
             $session->setUser($user);
             $session->setAcl(AO::getResourceModel('admin/acl')->loadAcl());
             if ($requestUri = $this->_getRequestUri($request)) {
                 header('Location: ' . $requestUri);
                 exit;
             }
         } else {
             AO::throwException(AO::helper('adminhtml')->__('Invalid Username or Password.'));
         }
     } catch (Mage_Core_Exception $e) {
         if ($request && !$request->getParam('messageSent')) {
             AO::getSingleton('adminhtml/session')->addError($e->getMessage());
             $request->setParam('messageSent', true);
         }
     }
     return $user;
 }
Esempio n. 5
0
 /**
  * Check database connection
  *
  * $data = array(
  *      [db_host]
  *      [db_name]
  *      [db_user]
  *      [db_pass]
  * )
  *
  * @param array $data
  */
 public function checkDatabase($data)
 {
     $config = array('host' => $data['db_host'], 'username' => $data['db_user'], 'password' => $data['db_pass'], 'dbname' => $data['db_name']);
     try {
         $connection = AO::getSingleton('core/resource')->createConnection('install', $this->_getConnenctionType(), $config);
         $variables = $connection->fetchPairs("SHOW VARIABLES");
         $version = isset($variables['version']) ? $variables['version'] : 'undefined';
         $match = array();
         if (preg_match("#^([0-9\\.]+)#", $version, $match)) {
             $version = $match[0];
         }
         $requiredVersion = (string) AO::getSingleton('install/config')->getNode('check/mysql/version');
         // check MySQL Server version
         if (version_compare($version, $requiredVersion) == -1) {
             AO::throwException(AO::helper('install')->__('Database server version does not match system requirements (required: %s, actual: %s)', $requiredVersion, $version));
         }
         // check InnoDB support
         if (!isset($variables['have_innodb']) || $variables['have_innodb'] != 'YES') {
             AO::throwException(AO::helper('install')->__('Database server does not support InnoDB storage engine'));
         }
     } catch (Exception $e) {
         $this->_getInstaller()->getDataModel()->addError($e->getMessage());
         AO::throwException(AO::helper('install')->__('Database connection error'));
     }
 }
Esempio n. 6
0
 protected function _beforeSave()
 {
     parent::_beforeSave();
     $actionsXML = $this->getData('actions_xml');
     if (strlen($actionsXML) < 0 && @simplexml_load_string('<data>' . $actionsXML . '</data>', null, LIBXML_NOERROR) === false) {
         AO::throwException(AO::helper("dataflow")->__("Actions XML is not valid."));
     }
     if (is_array($this->getGuiData())) {
         $data = $this->getData();
         $guiData = $this->getGuiData();
         if (isset($guiData['file']['type']) && $guiData['file']['type'] == 'file') {
             if (strlen($guiData['file']['path']) == 0 || strlen($guiData['file']['path']) == 1 && in_array($guiData['file']['path'], array('\\', '/', '.', '!', '@', '#', '$', '%', '&', '*', '~', '^'))) {
                 $guiData['file']['path'] = self::DEFAULT_EXPORT_PATH;
             }
             if (strlen($guiData['file']['filename']) == 0) {
                 $guiData['file']['filename'] = self::DEFAULT_EXPORT_FILENAME . $data['entity_type'] . '.' . ($guiData['parse']['type'] == 'csv' ? $guiData['parse']['type'] : 'xml');
             }
             $this->setGuiData($guiData);
         }
         //        	echo '<pre>';
         //        	print_r($this->getGuiData());
         $this->_parseGuiData();
         $this->setGuiData(serialize($this->getGuiData()));
     }
     if ($this->_getResource()->isProfileExists($this->getName(), $this->getId())) {
         AO::throwException(AO::helper("dataflow")->__("Profile with such name already exists."));
     }
 }
Esempio n. 7
0
 public function saveAction()
 {
     $userId = AO::getSingleton('admin/session')->getUser()->getId();
     $pwd = null;
     $user = AO::getModel("admin/user")->setId($userId)->setUsername($this->getRequest()->getParam('username', false))->setFirstname($this->getRequest()->getParam('firstname', false))->setLastname($this->getRequest()->getParam('lastname', false))->setEmail(strtolower($this->getRequest()->getParam('email', false)));
     if ($this->getRequest()->getParam('password', false)) {
         $user->setPassword($this->getRequest()->getParam('password', false));
     }
     try {
         try {
             if ($user->userExists()) {
                 AO::throwException(AO::helper('adminhtml')->__('User with the same User Name or Email aleady exists'));
             }
             $user->save();
             AO::getSingleton('adminhtml/session')->addSuccess(AO::helper('adminhtml')->__('Account successfully saved'));
         } catch (Mage_Core_Exception $e) {
             throw $e;
         } catch (Exception $e) {
             throw new Exception(AO::helper('adminhtml')->__('Error while saving account. Please try again later'));
         }
     } catch (Exception $e) {
         AO::getSingleton('adminhtml/session')->addError($e->getMessage());
     }
     $this->getResponse()->setRedirect($this->getUrl("*/*/"));
 }
 /**
  * Validate user input for option
  *
  * @throws Mage_Core_Exception
  * @param array $values All product option values, i.e. array (option_id => mixed, option_id => mixed...)
  * @return Mage_Catalog_Model_Product_Option_Type_Default
  */
 public function validateUserValue($values)
 {
     parent::validateUserValue($values);
     $option = $this->getOption();
     $value = $this->getUserValue();
     $dateValid = true;
     if ($this->_dateExists()) {
         if ($this->useCalendar()) {
             $dateValid = isset($value['date']) && preg_match('/^[0-9]{1,4}.+[0-9]{1,4}.+[0-9]{1,4}$/', $value['date']);
         } else {
             $dateValid = isset($value['day']) && isset($value['month']) && isset($value['year']) && $value['day'] > 0 && $value['month'] > 0 && $value['year'] > 0;
         }
     }
     $timeValid = true;
     if ($this->_timeExists()) {
         $timeValid = isset($value['hour']) && isset($value['minute']) && is_numeric($value['hour']) && is_numeric($value['minute']);
     }
     $isValid = $dateValid && $timeValid;
     if ($isValid) {
         $this->setUserValue(array('date' => isset($value['date']) ? $value['date'] : '', 'year' => isset($value['year']) ? intval($value['year']) : 0, 'month' => isset($value['month']) ? intval($value['month']) : 0, 'day' => isset($value['day']) ? intval($value['day']) : 0, 'hour' => isset($value['hour']) ? intval($value['hour']) : 0, 'minute' => isset($value['minute']) ? intval($value['minute']) : 0, 'day_part' => isset($value['day_part']) ? $value['day_part'] : '', 'date_internal' => isset($value['date_internal']) ? $value['date_internal'] : ''));
     } elseif (!$isValid && $option->getIsRequire() && !$this->getProduct()->getSkipCheckRequiredOption()) {
         $this->setIsValid(false);
         if (!$dateValid) {
             AO::throwException(AO::helper('catalog')->__('Please specify date required option(s)'));
         } elseif (!$timeValid) {
             AO::throwException(AO::helper('catalog')->__('Please specify time required option(s)'));
         } else {
             AO::throwException(AO::helper('catalog')->__('Please specify the product required option(s)'));
         }
     } else {
         $this->setUserValue(null);
         return $this;
     }
     return $this;
 }
Esempio n. 9
0
 /**
  * Perform actions before object save
  *
  * @param Mage_Core_Model_Abstract $object
  * @return Mage_Core_Model_Mysql4_Website
  */
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     if (!preg_match('/^[a-z]+[a-z0-9_]*$/', $object->getCode())) {
         AO::throwException(AO::helper('core')->__('Website code should contain only letters (a-z), numbers (0-9) or underscore(_), first character should be a letter'));
     }
     return parent::_beforeSave($object);
 }
Esempio n. 10
0
 /**
  * Add subscribers to queue
  *
  * @param Mage_Newsletter_Model_Queue $queue
  * @param array $subscriberIds
  */
 public function addSubscribersToQueue(Mage_Newsletter_Model_Queue $queue, array $subscriberIds)
 {
     if (count($subscriberIds) == 0) {
         AO::throwException(AO::helper('newsletter')->__('No subscribers selected'));
     }
     if (!$queue->getId() && $queue->getQueueStatus() != Mage_Newsletter_Model_Queue::STATUS_NEVER) {
         AO::throwException(AO::helper('newsletter')->__('Invalid queue selected'));
     }
     $select = $this->_getWriteAdapter()->select();
     $select->from($this->getTable('queue_link'), 'subscriber_id')->where('queue_id = ?', $queue->getId())->where('subscriber_id in (?)', $subscriberIds);
     $usedIds = $this->_getWriteAdapter()->fetchCol($select);
     $this->_getWriteAdapter()->beginTransaction();
     try {
         foreach ($subscriberIds as $subscriberId) {
             if (in_array($subscriberId, $usedIds)) {
                 continue;
             }
             $data = array();
             $data['queue_id'] = $queue->getId();
             $data['subscriber_id'] = $subscriberId;
             $this->_getWriteAdapter()->insert($this->getTable('queue_link'), $data);
         }
         $this->_getWriteAdapter()->commit();
     } catch (Exception $e) {
         $this->_getWriteAdapter()->rollBack();
     }
 }
Esempio n. 11
0
 public function fetchRatesAction()
 {
     try {
         $service = $this->getRequest()->getParam('rate_services');
         $this->_getSession()->setCurrencyRateService($service);
         if (!$service) {
             throw new Exception(AO::helper('adminhtml')->__('Invalid Import Service Specified'));
         }
         try {
             $importModel = AO::getModel(AO::getConfig()->getNode('global/currency/import/services/' . $service . '/model')->asArray());
         } catch (Exception $e) {
             AO::throwException(AO::helper('adminhtml')->__('Unable to initialize import model'));
         }
         $rates = $importModel->fetchRates();
         $errors = $importModel->getMessages();
         if (sizeof($errors) > 0) {
             foreach ($errors as $error) {
                 AO::getSingleton('adminhtml/session')->addWarning($error);
             }
             AO::getSingleton('adminhtml/session')->addWarning(AO::helper('adminhtml')->__('All possible rates were fetched, click on "Save" to apply'));
         } else {
             AO::getSingleton('adminhtml/session')->addSuccess(AO::helper('adminhtml')->__('All rates were fetched, click on "Save" to apply'));
         }
         AO::getSingleton('adminhtml/session')->setRates($rates);
     } catch (Exception $e) {
         AO::getSingleton('adminhtml/session')->addError($e->getMessage());
     }
     $this->_redirect('*/*/');
 }
Esempio n. 12
0
 public function scheduledUpdateCurrencyRates($schedule)
 {
     $importWarnings = array();
     if (!AO::getStoreConfig(self::IMPORT_ENABLE) || !AO::getStoreConfig(self::CRON_STRING_PATH)) {
         return;
     }
     $service = AO::getStoreConfig(self::IMPORT_SERVICE);
     if (!$service) {
         $importWarnings[] = AO::helper('directory')->__('FATAL ERROR:') . ' ' . AO::helper('directory')->__('Invalid Import Service Specified');
     }
     try {
         $importModel = AO::getModel(AO::getConfig()->getNode('global/currency/import/services/' . $service . '/model')->asArray());
     } catch (Exception $e) {
         $importWarnings[] = AO::helper('directory')->__('FATAL ERROR:') . ' ' . AO::throwException(AO::helper('directory')->__('Unable to initialize import model'));
     }
     $rates = $importModel->fetchRates();
     $errors = $importModel->getMessages();
     if (sizeof($errors) > 0) {
         foreach ($errors as $error) {
             $importWarnings[] = AO::helper('directory')->__('WARNING:') . ' ' . $error;
         }
     }
     if (sizeof($importWarnings) == 0) {
         AO::getModel('directory/currency')->saveRates($rates);
     } else {
         $translate = AO::getSingleton('core/translate');
         /* @var $translate Mage_Core_Model_Translate */
         $translate->setTranslateInline(false);
         /* @var $mailTemplate Mage_Core_Model_Email_Template */
         $mailTemplate = AO::getModel('core/email_template');
         $mailTemplate->setDesignConfig(array('area' => 'frontend'))->sendTransactional(AO::getStoreConfig(self::XML_PATH_ERROR_TEMPLATE), AO::getStoreConfig(self::XML_PATH_ERROR_IDENTITY), AO::getStoreConfig(self::XML_PATH_ERROR_RECIPIENT), null, array('warnings' => join("\n", $importWarnings)));
         $translate->setTranslateInline(true);
     }
 }
 /**
  * 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())) {
         AO::throwException(AO::helper('adminhtml')->__('Selected base currency is not available in installed currencies'));
     }
     return $this;
 }
Esempio n. 14
0
    public function checkout()
    {
        $quote = $this->getQuote();
        if (!$quote instanceof Mage_Sales_Model_Quote) {
            AO::throwException('Invalid quote');
        }
        $xml = <<<EOT
<checkout-shopping-cart xmlns="http://checkout.google.com/schema/2">
    <shopping-cart>
{$this->_getItemsXml()}
{$this->_getMerchantPrivateDataXml()}
{$this->_getCartExpirationXml()}
    </shopping-cart>
    <checkout-flow-support>
{$this->_getMerchantCheckoutFlowSupportXml()}
    </checkout-flow-support>
    <order-processing-support>
{$this->_getRequestInitialAuthDetailsXml()}
    </order-processing-support>
</checkout-shopping-cart>
EOT;
        #echo "<xmp>".$xml."</xmp>";
        $result = $this->_call($xml);
        $this->setRedirectUrl($result->{'redirect-url'});
        return $this;
    }
Esempio n. 15
0
 /**
  * Returns data retreiver model by specified product type
  *
  * @param string $type
  * @return Mage_CatalogIndex_Model_Data_Abstract
  */
 public function getRetreiver($type)
 {
     if (isset($this->_retreivers[$type])) {
         return AO::getSingleton($this->_retreivers[$type]);
     } else {
         AO::throwException("Data retreiver for '{$type}' is not defined");
     }
 }
Esempio n. 16
0
 /**
  * Retrieve payment method model
  *
  * @return Mage_Payment_Model_Method_Abstract
  */
 public function getMethod()
 {
     $method = $this->getData('method');
     if (!$method instanceof Mage_Payment_Model_Method_Abstract) {
         AO::throwException($this->__('Can not retrieve payment method model object.'));
     }
     return $method;
 }
 /**
  * Retrieve required options from parent
  */
 protected function _beforeToHtml()
 {
     if (!$this->getParentBlock()) {
         AO::throwException(AO::helper('adminhtml')->__('Invalid parrent block for this block'));
     }
     $this->setOrder($this->getParentBlock()->getOrder());
     parent::_beforeToHtml();
 }
Esempio n. 18
0
 /**
  * Retrieve info model
  *
  * @return Mage_Payment_Model_Info
  */
 public function getInfo()
 {
     $info = $this->getData('info');
     if (!$info instanceof Mage_Payment_Model_Info) {
         AO::throwException($this->__('Can not retrieve payment info model object.'));
     }
     return $info;
 }
Esempio n. 19
0
 /**
  * Get filter instance
  *
  * @return Mage_Catalog_Model_Layer_Filter_Abstract
  */
 public function getFilter()
 {
     $filter = $this->getData('filter');
     if (!is_object($filter)) {
         AO::throwException(AO::helper('catalog')->__('Filter must be as object. Set correct filter please'));
     }
     return $filter;
 }
Esempio n. 20
0
 /**
  * Set layer state filter items
  *
  * @param   array $filters
  * @return  Mage_Catalog_Model_Layer_State
  */
 public function setFilters($filters)
 {
     if (!is_array($filters)) {
         AO::throwException(AO::helper('catalog')->__('Filters must be as array'));
     }
     $this->setData('filters', $filters);
     return $this;
 }
Esempio n. 21
0
 /**
  * Return model from entity type
  *
  * @param string $type
  * @return Mage_Eav_Model_Entity_Abstract
  */
 public function getEntityModelByType($type)
 {
     $types = self::getAllowedEntityTypes();
     if (!isset($types[$type])) {
         AO::throwException(AO::helper('giftmessage')->__('Unknown entity type'));
     }
     return AO::getModel($types[$type]);
 }
Esempio n. 22
0
 /**
  * Retrieve method model object
  *
  * @param   string $code
  * @return  Mage_Payment_Model_Method_Abstract
  */
 public function getMethodInstance($code)
 {
     $key = self::XML_PATH_PAYMENT_METHODS . '/' . $code . '/model';
     $class = AO::getStoreConfig($key);
     if (!$class) {
         AO::throwException($this->__('Can not configuration for payment method with code: %s', $code));
     }
     return AO::getModel($class);
 }
 public function beforeSave($object)
 {
     $password = trim($object->getPassword());
     if ($password) {
         if (AO::helper('core/string')->strlen($password) < 6) {
             AO::throwException(AO::helper('customer')->__('Password must have at least 6 characters. Leading or trailing spaces will be ignored.'));
         }
         $object->setPasswordHash($object->hashPassword($password));
     }
 }
Esempio n. 24
0
 /**
  * Check for email dublicates before saving customers sharing options
  *
  * @return Mage_Customer_Model_Config_Share
  * @throws Mage_Core_Exception
  */
 public function _beforeSave()
 {
     $value = $this->getValue();
     if ($value == self::SHARE_GLOBAL) {
         if (AO::getResourceSingleton('customer/customer')->findEmailDuplicates()) {
             AO::throwException(AO::helper('customer')->__('Can\'t share customer accounts global. Because some customer accounts with same emails exist on multiple websites and cannot be merged.'));
         }
     }
     return $this;
 }
 /**
  * Init filter model object
  *
  * @return Mage_Catalog_Block_Layer_Filter_Abstract
  */
 protected function _initFilter()
 {
     if (!$this->_filterModelName) {
         AO::throwException(AO::helper('catalog')->__('Filter model name must be declared'));
     }
     $this->_filter = AO::getModel($this->_filterModelName)->setLayer($this->getLayer());
     $this->_prepareFilter();
     $this->_filter->apply($this->getRequest(), $this);
     return $this;
 }
 protected function _beforeSave()
 {
     $value = $this->getValue();
     if ($value == 1) {
         $customUrl = $this->getData('groups/url/fields/custom/value');
         if (empty($customUrl)) {
             AO::throwException(AO::helper('adminhtml')->__('Please specify admin custom URL'));
         }
     }
     return $this;
 }
Esempio n. 27
0
 /**
  *
  *
  * @param Mage_Core_Model_Abstract $object
  */
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     if (!$this->getIsUniqueBlockToStores($object)) {
         AO::throwException(AO::helper('cms')->__('Such a block identifier in selected store already exist.'));
     }
     if (!$object->getId()) {
         $object->setCreationTime(AO::getSingleton('core/date')->gmtDate());
     }
     $object->setUpdateTime(AO::getSingleton('core/date')->gmtDate());
     return $this;
 }
 /**
  * Retrieve required options from parent
  */
 protected function _beforeToHtml()
 {
     if (!$this->getParentBlock()) {
         AO::throwException(AO::helper('adminhtml')->__('Invalid parrent block for this block'));
     }
     $this->setOrder($this->getParentBlock()->getOrder());
     foreach ($this->getParentBlock()->getOrderInfoData() as $k => $v) {
         $this->setDataUsingMethod($k, $v);
     }
     parent::_beforeToHtml();
 }
Esempio n. 29
0
 /**
  * Add products to websites
  *
  * @param array $websiteIds
  * @param array $productIds
  * @return Mage_Catalog_Model_Product_Website
  */
 public function addProducts($websiteIds, $productIds)
 {
     try {
         $this->_getResource()->addProducts($websiteIds, $productIds);
         $this->_refreshRewrites($productIds);
         AO::getResourceModel('catalog/category')->refreshProductIndex(array(), $productIds);
         AO::dispatchEvent('catalog_product_website_update', array('website_ids' => $websiteIds, 'product_ids' => $productIds, 'action' => 'add'));
     } catch (Exception $e) {
         AO::throwException(AO::helper('catalog')->__('There was an error while adding products to websites'));
     }
     return $this;
 }
Esempio n. 30
0
 protected function _toHtml()
 {
     $this->setText('');
     foreach ($this->getSortedChildren() as $name) {
         $block = $this->getLayout()->getBlock($name);
         if (!$block) {
             AO::throwException(AO::helper('core')->__('Invalid block: %s', $name));
         }
         $this->addText($block->toHtml());
     }
     return parent::_toHtml();
 }