Example #1
0
 protected function _beforeToHtml()
 {
     Magento_Profiler::start('customer/tabs');
     /*
             if (Mage::registry('current_customer')->getId()) {
                 $this->addTab('view', array(
                     'label'     => Mage::helper('Mage_Customer_Helper_Data')->__('Customer View'),
                     'content'   => $this->getLayout()->createBlock('Mage_Adminhtml_Block_Customer_Edit_Tab_View')->toHtml(),
                     'active'    => true
                 ));
             }
     */
     $this->addTab('account', array('label' => Mage::helper('Mage_Customer_Helper_Data')->__('Account Information'), 'content' => $this->getLayout()->createBlock('Mage_Adminhtml_Block_Customer_Edit_Tab_Account')->initForm()->toHtml(), 'active' => Mage::registry('current_customer')->getId() ? false : true));
     $this->addTab('addresses', array('label' => Mage::helper('Mage_Customer_Helper_Data')->__('Addresses'), 'content' => $this->getLayout()->createBlock('Mage_Adminhtml_Block_Customer_Edit_Tab_Addresses')->initForm()->toHtml()));
     // load: Orders, Shopping Cart, Wishlist, Product Reviews, Product Tags - with ajax
     if (Mage::registry('current_customer')->getId()) {
         if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::actions_view')) {
             $this->addTab('orders', array('label' => Mage::helper('Mage_Customer_Helper_Data')->__('Orders'), 'class' => 'ajax', 'url' => $this->getUrl('*/*/orders', array('_current' => true))));
         }
         $this->addTab('cart', array('label' => Mage::helper('Mage_Customer_Helper_Data')->__('Shopping Cart'), 'class' => 'ajax', 'url' => $this->getUrl('*/*/carts', array('_current' => true))));
         $this->addTab('wishlist', array('label' => Mage::helper('Mage_Customer_Helper_Data')->__('Wishlist'), 'class' => 'ajax', 'url' => $this->getUrl('*/*/wishlist', array('_current' => true))));
         if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Newsletter::subscriber')) {
             $this->addTab('newsletter', array('label' => Mage::helper('Mage_Customer_Helper_Data')->__('Newsletter'), 'content' => $this->getLayout()->createBlock('Mage_Adminhtml_Block_Customer_Edit_Tab_Newsletter')->initForm()->toHtml()));
         }
         if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Review::reviews_ratings')) {
             $this->addTab('reviews', array('label' => Mage::helper('Mage_Customer_Helper_Data')->__('Product Reviews'), 'class' => 'ajax', 'url' => $this->getUrl('*/*/productReviews', array('_current' => true))));
         }
     }
     $this->_updateActiveTab();
     Magento_Profiler::stop('customer/tabs');
     return parent::_beforeToHtml();
 }
Example #2
0
 protected function _toHtml()
 {
     /* @var $template Mage_Newsletter_Model_Template */
     $template = Mage::getModel('Mage_Newsletter_Model_Template');
     if ($id = (int) $this->getRequest()->getParam('id')) {
         $queue = Mage::getModel('Mage_Newsletter_Model_Queue');
         $queue->load($id);
         $template->setTemplateType($queue->getNewsletterType());
         $template->setTemplateText($queue->getNewsletterText());
         $template->setTemplateStyles($queue->getNewsletterStyles());
     } else {
         $template->setTemplateType($this->getRequest()->getParam('type'));
         $template->setTemplateText($this->getRequest()->getParam('text'));
         $template->setTemplateStyles($this->getRequest()->getParam('styles'));
     }
     $storeId = (int) $this->getRequest()->getParam('store_id');
     if (!$storeId) {
         $storeId = Mage::app()->getDefaultStoreView()->getId();
     }
     Magento_Profiler::start("newsletter_queue_proccessing");
     $vars = array();
     $vars['subscriber'] = Mage::getModel('Mage_Newsletter_Model_Subscriber');
     $template->emulateDesign($storeId);
     $templateProcessed = $template->getProcessedTemplate($vars, true);
     $template->revertDesign();
     if ($template->isPlain()) {
         $templateProcessed = "<pre>" . htmlspecialchars($templateProcessed) . "</pre>";
     }
     Magento_Profiler::stop("newsletter_queue_proccessing");
     return $templateProcessed;
 }
Example #3
0
 /**
  * @param string $definitionsFile
  * @param Magento_Di $diInstance
  * @param Magento_Di_InstanceManager $instanceManager
  */
 public function __construct($definitionsFile = null, Magento_Di $diInstance = null, Magento_Di_InstanceManager $instanceManager = null)
 {
     Magento_Profiler::start('di');
     $this->_di = $diInstance ?: new Magento_Di_Zend(null, $instanceManager, null, $definitionsFile);
     $this->_di->instanceManager()->addSharedInstance($this, 'Magento_ObjectManager');
     Magento_Profiler::stop('di');
 }
Example #4
0
 /**
  * Initialization session namespace
  *
  * @param string $namespace
  */
 public function init($namespace)
 {
     if (!Zend_Session::sessionExists()) {
         $this->start();
     }
     Magento_Profiler::start(__METHOD__ . '/init');
     $this->_namespace = new Zend_Session_Namespace($namespace, Zend_Session_Namespace::SINGLE_INSTANCE);
     Magento_Profiler::stop(__METHOD__ . '/init');
     return $this;
 }
Example #5
0
 /**
  * @param string $definitionsFile
  * @param Zend\Di\Di $diInstance
  */
 public function __construct($definitionsFile = null, Zend\Di\Di $diInstance = null)
 {
     Magento_Profiler::start('di');
     if (is_file($definitionsFile) && is_readable($definitionsFile)) {
         $definition = new Magento_Di_Definition_ArrayDefinition_Zend(unserialize(file_get_contents($definitionsFile)));
     } else {
         $definition = new Magento_Di_Definition_RuntimeDefinition_Zend();
     }
     $this->_di = $diInstance ? $diInstance : new Magento_Di();
     $this->_di->setDefinitionList(new Magento_Di_DefinitionList_Zend($definition));
     $this->_di->instanceManager()->addSharedInstance($this, 'Magento_ObjectManager');
     Magento_Profiler::stop('di');
 }
Example #6
0
 /**
  * Dispatches an event to observer's callback
  *
  * @param Varien_Event $event
  * @return Varien_Event_Observer
  */
 public function dispatch(Varien_Event $event)
 {
     if (!$this->isValidFor($event)) {
         return $this;
     }
     $callback = $this->getCallback();
     $this->setEvent($event);
     $_profilerKey = 'OBSERVER: ' . (is_object($callback[0]) ? get_class($callback[0]) : (string) $callback[0]) . ' -> ' . $callback[1];
     Magento_Profiler::start($_profilerKey);
     call_user_func($callback, $this);
     Magento_Profiler::stop($_profilerKey);
     return $this;
 }
Example #7
0
 /**
  * Calculate metric value from set of timer names
  *
  * @param array $timerNames
  * @param string $fetchKey
  * @return int
  */
 protected function _aggregateTimerValues(array $timerNames, $fetchKey = Magento_Profiler::FETCH_AVG)
 {
     /* Prepare pattern that matches timers with deepest nesting level only */
     $nestingSep = preg_quote(Magento_Profiler::NESTING_SEPARATOR, '/');
     array_map('preg_quote', $timerNames, array('/'));
     $pattern = '/(?<=' . $nestingSep . '|^)(?:' . implode('|', $timerNames) . ')$/';
     /* Sum profiler values for matched timers */
     $result = 0;
     foreach ($this->_getTimers() as $timerId) {
         if (preg_match($pattern, $timerId)) {
             $result += Magento_Profiler::fetch($timerId, $fetchKey);
         }
     }
     /* Convert seconds -> milliseconds */
     $result = round($result * 1000);
     return $result;
 }
Example #8
0
 protected function _toHtml()
 {
     $template = Mage::getModel('Mage_Core_Model_Email_Template');
     if ($id = (int) $this->getRequest()->getParam('id')) {
         $template->load($id);
     } else {
         $template->setTemplateType($this->getRequest()->getParam('type'));
         $template->setTemplateText($this->getRequest()->getParam('text'));
         $template->setTemplateStyles($this->getRequest()->getParam('styles'));
     }
     $template->setTemplateText($this->escapeHtml($template->getTemplateText()));
     Magento_Profiler::start("email_template_proccessing");
     $vars = array();
     $templateProcessed = $template->getProcessedTemplate($vars, true);
     if ($template->isPlain()) {
         $templateProcessed = "<pre>" . htmlspecialchars($templateProcessed) . "</pre>";
     }
     Magento_Profiler::stop("email_template_proccessing");
     return $templateProcessed;
 }
Example #9
0
 /**
  * Prepare html output
  *
  * @return string
  */
 protected function _toHtml()
 {
     /** @var $template Mage_Core_Model_Email_Template */
     $template = Mage::getModel('Mage_Core_Model_Email_Template');
     $id = (int) $this->getRequest()->getParam('id');
     if ($id) {
         $template->load($id);
     } else {
         $template->setTemplateType($this->getRequest()->getParam('type'));
         $template->setTemplateText($this->getRequest()->getParam('text'));
         $template->setTemplateStyles($this->getRequest()->getParam('styles'));
     }
     /* @var $filter Mage_Core_Model_Input_Filter_MaliciousCode */
     $filter = Mage::getSingleton('Mage_Core_Model_Input_Filter_MaliciousCode');
     $template->setTemplateText($filter->filter($template->getTemplateText()));
     Magento_Profiler::start("email_template_proccessing");
     $vars = array();
     $templateProcessed = $template->getProcessedTemplate($vars, true);
     if ($template->isPlain()) {
         $templateProcessed = "<pre>" . htmlspecialchars($templateProcessed) . "</pre>";
     }
     Magento_Profiler::stop("email_template_proccessing");
     return $templateProcessed;
 }
Example #10
0
 /**
  * Retrieve category id URL
  *
  * @return string
  */
 public function getCategoryIdUrl()
 {
     Magento_Profiler::start('REGULAR: ' . __METHOD__, array('group' => 'REGULAR', 'method' => __METHOD__));
     $urlKey = $this->getUrlKey() ? $this->getUrlKey() : $this->formatUrlKey($this->getName());
     $url = $this->getUrlInstance()->getUrl('catalog/category/view', array('s' => $urlKey, 'id' => $this->getId()));
     Magento_Profiler::stop('REGULAR: ' . __METHOD__);
     return $url;
 }
Example #11
0
 /**
  * Front end main entry point
  *
  * @param string $code
  * @param string $type
  * @param string|array $options
  */
 public static function run($code = '', $type = 'store', $options = array())
 {
     try {
         Magento_Profiler::start('mage');
         self::setRoot();
         if (isset($options['edition'])) {
             self::$_currentEdition = $options['edition'];
         }
         self::$_app = new Mage_Core_Model_App();
         if (isset($options['request'])) {
             self::$_app->setRequest($options['request']);
         }
         if (isset($options['response'])) {
             self::$_app->setResponse($options['response']);
         }
         self::$_events = new Varien_Event_Collection();
         self::_setIsInstalled($options);
         self::_setConfigModel($options);
         self::$_app->run(array('scope_code' => $code, 'scope_type' => $type, 'options' => $options));
         Magento_Profiler::stop('mage');
     } catch (Mage_Core_Model_Session_Exception $e) {
         header('Location: ' . self::getBaseUrl());
     } catch (Mage_Core_Model_Store_Exception $e) {
         require_once self::getBaseDir() . '/pub/errors/404.php';
     } catch (Exception $e) {
         self::printException($e);
     }
 }
Example #12
0
 /**
  * Configure session handler and start session
  *
  * @param string $sessionName
  * @return Mage_Core_Model_Session_Abstract
  */
 public function start($sessionName = null)
 {
     if (isset($_SESSION) && !$this->getSkipEmptySessionCheck()) {
         return $this;
     }
     switch ($this->getSessionSaveMethod()) {
         case 'db':
             ini_set('session.save_handler', 'user');
             $sessionResource = Mage::getResourceSingleton('Mage_Core_Model_Resource_Session');
             /* @var $sessionResource Mage_Core_Model_Resource_Session */
             $sessionResource->setSaveHandler();
             break;
         case 'memcache':
             ini_set('session.save_handler', 'memcache');
             session_save_path($this->getSessionSavePath());
             break;
         case 'memcached':
             ini_set('session.save_handler', 'memcached');
             session_save_path($this->getSessionSavePath());
             break;
         case 'eaccelerator':
             ini_set('session.save_handler', 'eaccelerator');
             break;
         default:
             session_module_name($this->getSessionSaveMethod());
             if (is_writable($this->getSessionSavePath())) {
                 session_save_path($this->getSessionSavePath());
             }
             break;
     }
     $cookie = $this->getCookie();
     // session cookie params
     $cookieParams = array('lifetime' => 0, 'path' => $cookie->getPath(), 'domain' => $cookie->getConfigDomain(), 'secure' => $cookie->isSecure(), 'httponly' => $cookie->getHttponly());
     if (!$cookieParams['httponly']) {
         unset($cookieParams['httponly']);
         if (!$cookieParams['secure']) {
             unset($cookieParams['secure']);
             if (!$cookieParams['domain']) {
                 unset($cookieParams['domain']);
             }
         }
     }
     if (isset($cookieParams['domain'])) {
         $cookieParams['domain'] = $cookie->getDomain();
     }
     call_user_func_array('session_set_cookie_params', $cookieParams);
     if (!empty($sessionName)) {
         $this->setSessionName($sessionName);
     }
     // potential custom logic for session id (ex. switching between hosts)
     $this->setSessionId();
     Magento_Profiler::start('session_start');
     $sessionCacheLimiter = Mage::getConfig()->getNode('global/session_cache_limiter');
     if ($sessionCacheLimiter) {
         session_cache_limiter((string) $sessionCacheLimiter);
     }
     session_start();
     Magento_Profiler::stop('session_start');
     return $this;
 }
Example #13
0
 /**
  * Loading part of area
  *
  * @param   string $part
  * @return  Mage_Core_Model_App_Area
  */
 protected function _loadPart($part)
 {
     if (isset($this->_loadedParts[$part])) {
         return $this;
     }
     Magento_Profiler::start('load_area:' . $this->_code . '.' . $part);
     switch ($part) {
         case self::PART_CONFIG:
             $this->_initConfig();
             break;
         case self::PART_EVENTS:
             $this->_initEvents();
             break;
         case self::PART_TRANSLATE:
             $this->_initTranslate();
             break;
         case self::PART_DESIGN:
             $this->_initDesign();
             break;
     }
     $this->_loadedParts[$part] = true;
     Magento_Profiler::stop('load_area:' . $this->_code . '.' . $part);
     return $this;
 }
Example #14
0
 /**
  * Retrieve the list of timer Ids
  *
  * @return array
  */
 protected function _getTimers()
 {
     $pattern = $this->_filter;
     $timerIds = $this->_getSortedTimers();
     $result = array();
     foreach ($timerIds as $timerId) {
         /* Filter by timer id pattern */
         if ($pattern && !preg_match($pattern, $timerId)) {
             continue;
         }
         /* Filter by column value thresholds */
         $skip = false;
         foreach ($this->_thresholds as $fetchKey => $minAllowedValue) {
             $skip = Magento_Profiler::fetch($timerId, $fetchKey) < $minAllowedValue;
             /* First value not less than the allowed one forces to include timer to the result */
             if (!$skip) {
                 break;
             }
         }
         if (!$skip) {
             $result[] = $timerId;
         }
     }
     return $result;
 }
Example #15
0
 /**
  * Add products to items and item options
  *
  * @return Mage_Sales_Model_Resource_Quote_Item_Collection
  */
 protected function _assignProducts()
 {
     Magento_Profiler::start('QUOTE:' . __METHOD__);
     $productIds = array();
     foreach ($this as $item) {
         $productIds[] = (int) $item->getProductId();
     }
     $this->_productIds = array_merge($this->_productIds, $productIds);
     $productCollection = Mage::getModel('Mage_Catalog_Model_Product')->getCollection()->setStoreId($this->getStoreId())->addIdFilter($this->_productIds)->addAttributeToSelect(Mage::getSingleton('Mage_Sales_Model_Quote_Config')->getProductAttributes())->addOptionsToResult()->addStoreFilter()->addUrlRewrite()->addTierPriceData();
     Mage::dispatchEvent('prepare_catalog_product_collection_prices', array('collection' => $productCollection, 'store_id' => $this->getStoreId()));
     Mage::dispatchEvent('sales_quote_item_collection_products_after_load', array('product_collection' => $productCollection));
     $recollectQuote = false;
     foreach ($this as $item) {
         $product = $productCollection->getItemById($item->getProductId());
         if ($product) {
             $product->setCustomOptions(array());
             $qtyOptions = array();
             $optionProductIds = array();
             foreach ($item->getOptions() as $option) {
                 /**
                  * Call type-specific logic for product associated with quote item
                  */
                 $product->getTypeInstance()->assignProductToOption($productCollection->getItemById($option->getProductId()), $option, $product);
                 if (is_object($option->getProduct()) && $option->getProduct()->getId() != $product->getId()) {
                     $optionProductIds[$option->getProduct()->getId()] = $option->getProduct()->getId();
                 }
             }
             if ($optionProductIds) {
                 foreach ($optionProductIds as $optionProductId) {
                     $qtyOption = $item->getOptionByCode('product_qty_' . $optionProductId);
                     if ($qtyOption) {
                         $qtyOptions[$optionProductId] = $qtyOption;
                     }
                 }
             }
             $item->setQtyOptions($qtyOptions)->setProduct($product);
         } else {
             $item->isDeleted(true);
             $recollectQuote = true;
         }
         $item->checkData();
     }
     if ($recollectQuote && $this->_quote) {
         $this->_quote->collectTotals();
     }
     Magento_Profiler::stop('QUOTE:' . __METHOD__);
     return $this;
 }
Example #16
0
 /**
  * A test ended.
  * Method signature is implied by implemented interface, not all parameters are needed.
  *
  * @param  PHPUnit_Framework_Test $test
  * @param  float                  $time
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function endTest(PHPUnit_Framework_Test $test, $time)
 {
     if (!$test instanceof PHPUnit_Framework_TestCase || $test instanceof PHPUnit_Framework_Warning) {
         return;
     }
     $this->_notifyObservers('endTest', true);
     $this->_currentTest = null;
     Magento_Profiler::stop('integration_test');
 }
Example #17
0
 /**
  * Preload entity type attributes for performance optimization
  *
  * @param   mixed $entityType
  * @param   mixed $attributes
  * @return  Mage_Eav_Model_Config
  */
 public function preloadAttributes($entityType, $attributes)
 {
     if (is_string($attributes)) {
         $attributes = array($attributes);
     }
     $entityType = $this->getEntityType($entityType);
     $entityTypeCode = $entityType->getEntityTypeCode();
     if (!isset($this->_preloadedAttributes[$entityTypeCode])) {
         $this->_preloadedAttributes[$entityTypeCode] = $attributes;
     } else {
         $attributes = array_diff($attributes, $this->_preloadedAttributes[$entityTypeCode]);
         $this->_preloadedAttributes[$entityTypeCode] = array_merge($this->_preloadedAttributes[$entityTypeCode], $attributes);
     }
     if (empty($attributes)) {
         return $this;
     }
     Magento_Profiler::start('EAV: ' . __METHOD__ . ':' . $entityTypeCode);
     $attributesInfo = Mage::getResourceModel($entityType->getEntityAttributeCollection())->setEntityTypeFilter($entityType)->setCodeFilter($attributes)->getData();
     if (!$attributesInfo) {
         Magento_Profiler::stop('EAV: ' . __METHOD__ . ':' . $entityTypeCode);
         return $this;
     }
     $attributesData = $codes = array();
     foreach ($attributesInfo as $attribute) {
         if (empty($attribute['attribute_model'])) {
             $attribute['attribute_model'] = $entityType->getAttributeModel();
         }
         $attributeCode = $attribute['attribute_code'];
         $attributeId = $attribute['attribute_id'];
         $this->_addAttributeReference($attributeId, $attributeCode, $entityTypeCode);
         $attributesData[$attributeCode] = $attribute;
         $codes[] = $attributeCode;
     }
     $this->_attributeData[$entityTypeCode] = $attributesData;
     Magento_Profiler::stop('EAV: ' . __METHOD__ . ':' . $entityTypeCode);
     return $this;
 }
Example #18
0
 /**
  * Update products which are matched for rule
  *
  * @param Mage_CatalogRule_Model_Rule $rule
  *
  * @return Mage_CatalogRule_Model_Resource_Rule
  */
 public function updateRuleProductData(Mage_CatalogRule_Model_Rule $rule)
 {
     $ruleId = $rule->getId();
     $write = $this->_getWriteAdapter();
     $write->beginTransaction();
     if ($rule->getProductsFilter()) {
         $write->delete($this->getTable('catalogrule_product'), array('rule_id=?' => $ruleId, 'product_id IN (?)' => $rule->getProductsFilter()));
     } else {
         $write->delete($this->getTable('catalogrule_product'), $write->quoteInto('rule_id=?', $ruleId));
     }
     if (!$rule->getIsActive()) {
         $write->commit();
         return $this;
     }
     $websiteIds = $rule->getWebsiteIds();
     if (!is_array($websiteIds)) {
         $websiteIds = explode(',', $websiteIds);
     }
     if (empty($websiteIds)) {
         return $this;
     }
     Magento_Profiler::start('__MATCH_PRODUCTS__');
     $productIds = $rule->getMatchingProductIds();
     Magento_Profiler::stop('__MATCH_PRODUCTS__');
     $customerGroupIds = $rule->getCustomerGroupIds();
     $fromTime = strtotime($rule->getFromDate());
     $toTime = strtotime($rule->getToDate());
     $toTime = $toTime ? $toTime + self::SECONDS_IN_DAY - 1 : 0;
     $sortOrder = (int) $rule->getSortOrder();
     $actionOperator = $rule->getSimpleAction();
     $actionAmount = $rule->getDiscountAmount();
     $subActionOperator = $rule->getSubIsEnable() ? $rule->getSubSimpleAction() : '';
     $subActionAmount = $rule->getSubDiscountAmount();
     $actionStop = $rule->getStopRulesProcessing();
     $rows = array();
     try {
         foreach ($productIds as $productId) {
             foreach ($websiteIds as $websiteId) {
                 foreach ($customerGroupIds as $customerGroupId) {
                     $rows[] = array('rule_id' => $ruleId, 'from_time' => $fromTime, 'to_time' => $toTime, 'website_id' => $websiteId, 'customer_group_id' => $customerGroupId, 'product_id' => $productId, 'action_operator' => $actionOperator, 'action_amount' => $actionAmount, 'action_stop' => $actionStop, 'sort_order' => $sortOrder, 'sub_simple_action' => $subActionOperator, 'sub_discount_amount' => $subActionAmount);
                     if (count($rows) == 1000) {
                         $write->insertMultiple($this->getTable('catalogrule_product'), $rows);
                         $rows = array();
                     }
                 }
             }
         }
         if (!empty($rows)) {
             $write->insertMultiple($this->getTable('catalogrule_product'), $rows);
         }
         $write->commit();
     } catch (Exception $e) {
         $write->rollback();
         throw $e;
     }
     return $this;
 }
Example #19
0
 /**
  * Reset collected statistics for specified timer or for whole profiler if timer name is omitted
  *
  * @param string|null $timerName
  */
 public static function reset($timerName = null)
 {
     if ($timerName === null) {
         self::$_timers = array();
         self::$_currentPath = array();
         return;
     }
     $timerId = self::_getTimerId($timerName);
     self::$_timers[$timerId] = array('start' => false, self::FETCH_TIME => 0, self::FETCH_COUNT => 0, self::FETCH_REALMEM => 0, self::FETCH_EMALLOC => 0);
 }
Example #20
0
 /**
  * After load collection process
  *
  * @return Mage_Catalog_Model_Resource_Product_Type_Configurable_Attribute_Collection
  */
 protected function _afterLoad()
 {
     parent::_afterLoad();
     Magento_Profiler::start('TTT1:' . __METHOD__, array('group' => 'TTT1', 'method' => __METHOD__));
     $this->_addProductAttributes();
     Magento_Profiler::stop('TTT1:' . __METHOD__);
     Magento_Profiler::start('TTT2:' . __METHOD__, array('group' => 'TTT2', 'method' => __METHOD__));
     $this->_addAssociatedProductFilters();
     Magento_Profiler::stop('TTT2:' . __METHOD__);
     Magento_Profiler::start('TTT3:' . __METHOD__, array('group' => 'TTT3', 'method' => __METHOD__));
     $this->_loadLabels();
     Magento_Profiler::stop('TTT3:' . __METHOD__);
     Magento_Profiler::start('TTT4:' . __METHOD__, array('group' => 'TTT4', 'method' => __METHOD__));
     $this->_loadPrices();
     Magento_Profiler::stop('TTT4:' . __METHOD__);
     return $this;
 }
Example #21
0
 /**
  * Get model class instance.
  *
  * Example:
  * $config->getModelInstance('catalog/product')
  *
  * Will instantiate Mage_Catalog_Model_Resource_Product
  *
  * @param string $modelClass
  * @param array|object $constructArguments
  * @return Mage_Core_Model_Abstract|false
  */
 public function getModelInstance($modelClass = '', $constructArguments = array())
 {
     $className = $this->getModelClassName($modelClass);
     if (class_exists($className)) {
         Magento_Profiler::start('FACTORY:' . $className);
         $obj = new $className($constructArguments);
         Magento_Profiler::stop('FACTORY:' . $className);
         return $obj;
     } else {
         return false;
     }
 }
Example #22
0
 public function dispatch()
 {
     $request = $this->getRequest();
     // If pre-configured, check equality of base URL and requested URL
     $this->_checkBaseUrl($request);
     Magento_Profiler::start('dispatch');
     $request->setPathInfo()->setDispatched(false);
     if (!$request->isStraight()) {
         Magento_Profiler::start('db_url_rewrite');
         Mage::getModel('Mage_Core_Model_Url_Rewrite')->rewrite();
         Magento_Profiler::stop('db_url_rewrite');
     }
     Magento_Profiler::start('config_url_rewrite');
     $this->rewrite();
     Magento_Profiler::stop('config_url_rewrite');
     Magento_Profiler::stop('dispatch');
     Magento_Profiler::start('routers_match');
     $i = 0;
     while (!$request->isDispatched() && $i++ < 100) {
         foreach ($this->_routers as $router) {
             if ($router->match($this->getRequest())) {
                 break;
             }
         }
     }
     Magento_Profiler::stop('routers_match');
     if ($i > 100) {
         Mage::throwException('Front controller reached 100 router match iterations');
     }
     //This event give possibility to launch smth before sending ouptut(Allow cookie setting)
     Mage::dispatchEvent('controller_front_send_response_before', array('front' => $this));
     Magento_Profiler::start('send_response');
     $this->getResponse()->sendResponse();
     Magento_Profiler::stop('send_response');
     Mage::dispatchEvent('controller_front_send_response_after', array('front' => $this));
     return $this;
 }
Example #23
0
 /**
  * Retrieve Selected Attributes info
  *
  * @param  Mage_Catalog_Model_Product $product
  * @return array
  */
 public function getSelectedAttributesInfo($product)
 {
     $attributes = array();
     Magento_Profiler::start('CONFIGURABLE:' . __METHOD__);
     if ($attributesOption = $product->getCustomOption('attributes')) {
         $data = unserialize($attributesOption->getValue());
         $this->getUsedProductAttributeIds($product);
         $usedAttributes = $product->getData($this->_usedAttributes);
         foreach ($data as $attributeId => $attributeValue) {
             if (isset($usedAttributes[$attributeId])) {
                 $attribute = $usedAttributes[$attributeId];
                 $label = $attribute->getLabel();
                 $value = $attribute->getProductAttribute();
                 if ($value->getSourceModel()) {
                     $value = $value->getSource()->getOptionText($attributeValue);
                 } else {
                     $value = '';
                 }
                 $attributes[] = array('label' => $label, 'value' => $value);
             }
         }
     }
     Magento_Profiler::stop('CONFIGURABLE:' . __METHOD__);
     return $attributes;
 }
Example #24
0
 /**
  * Load attribute data by code
  *
  * @param  mixed $entityType
  * @param  string $code
  * @return Mage_Eav_Model_Entity_Attribute_Abstract
  * @throws Mage_Core_Exception
  */
 public function loadByCode($entityType, $code)
 {
     Magento_Profiler::start('load_by_code');
     if (is_numeric($entityType)) {
         $entityTypeId = $entityType;
     } elseif (is_string($entityType)) {
         $entityType = Mage::getModel('Mage_Eav_Model_Entity_Type')->loadByCode($entityType);
     }
     if ($entityType instanceof Mage_Eav_Model_Entity_Type) {
         $entityTypeId = $entityType->getId();
     }
     if (empty($entityTypeId)) {
         throw Mage::exception('Mage_Eav', Mage::helper('Mage_Eav_Helper_Data')->__('Invalid entity supplied.'));
     }
     $this->_getResource()->loadByCode($this, $entityTypeId, $code);
     $this->_afterLoad();
     Magento_Profiler::stop('load_by_code');
     return $this;
 }
Example #25
0
 public function getRegionsJs()
 {
     Magento_Profiler::start('TEST: ' . __METHOD__);
     $regionsJs = $this->getData('regions_js');
     if (!$regionsJs) {
         $countryIds = array();
         foreach ($this->getCountryCollection() as $country) {
             $countryIds[] = $country->getCountryId();
         }
         $collection = Mage::getModel('Mage_Directory_Model_Region')->getResourceCollection()->addCountryFilter($countryIds)->load();
         $regions = array();
         foreach ($collection as $region) {
             if (!$region->getRegionId()) {
                 continue;
             }
             $regions[$region->getCountryId()][$region->getRegionId()] = array('code' => $region->getCode(), 'name' => $region->getName());
         }
         $regionsJs = Mage::helper('Mage_Core_Helper_Data')->jsonEncode($regions);
     }
     Magento_Profiler::stop('TEST: ' . __METHOD__);
     return $regionsJs;
 }
Example #26
0
 /**
  * Reindex all data what process is responsible
  */
 public function reindexProcessAction()
 {
     $process = $this->_initProcess();
     if ($process) {
         try {
             Magento_Profiler::start('__INDEX_PROCESS_REINDEX_ALL__');
             $process->reindexEverything();
             Magento_Profiler::stop('__INDEX_PROCESS_REINDEX_ALL__');
             $this->_getSession()->addSuccess(Mage::helper('Mage_Index_Helper_Data')->__('%s index was rebuilt.', $process->getIndexer()->getName()));
         } catch (Mage_Core_Exception $e) {
             $this->_getSession()->addError($e->getMessage());
         } catch (Exception $e) {
             $this->_getSession()->addException($e, Mage::helper('Mage_Index_Helper_Data')->__('There was a problem with reindexing process.'));
         }
     } else {
         $this->_getSession()->addError(Mage::helper('Mage_Index_Helper_Data')->__('Cannot initialize the indexer process.'));
     }
     $this->_redirect('*/*/list');
 }
Example #27
0
    /**
     * Retrieve block view from file (template)
     *
     * @param   string $fileName
     * @return  string
     */
    public function fetchView($fileName)
    {
        Magento_Profiler::start('TEMPLATE:' . $fileName);
        // EXTR_SKIP protects from overriding
        // already defined variables
        extract($this->_viewVars, EXTR_SKIP);
        $do = $this->getDirectOutput();
        if (!$do) {
            ob_start();
        }
        if ($this->getShowTemplateHints()) {
            echo <<<HTML
<div style="position:relative; border:1px dotted red; margin:6px 2px; padding:18px 2px 2px 2px; zoom:1;">
<div style="position:absolute; left:0; top:0; padding:2px 5px; background:red; color:white; font:normal 11px Arial;
text-align:left !important; z-index:998;" onmouseover="this.style.zIndex='999'"
onmouseout="this.style.zIndex='998'" title="{$fileName}">{$fileName}</div>
HTML;
            if (self::$_showTemplateHintsBlocks) {
                $thisClass = get_class($this);
                echo <<<HTML
<div style="position:absolute; right:0; top:0; padding:2px 5px; background:red; color:blue; font:normal 11px Arial;
text-align:left !important; z-index:998;" onmouseover="this.style.zIndex='999'" onmouseout="this.style.zIndex='998'"
title="{$thisClass}">{$thisClass}</div>
HTML;
            }
        }
        try {
            $templateFile = realpath($fileName);
            if (strpos($templateFile, Mage::getBaseDir('app')) === 0 || strpos($templateFile, realpath($this->_viewDir)) === 0 || $this->_getAllowSymlinks()) {
                include $templateFile;
            } else {
                Mage::log("Invalid template file: '{$fileName}'", Zend_Log::CRIT, null, null, true);
            }
        } catch (Exception $e) {
            ob_get_clean();
            throw $e;
        }
        if ($this->getShowTemplateHints()) {
            echo '</div>';
        }
        if (!$do) {
            $html = ob_get_clean();
        } else {
            $html = '';
        }
        Magento_Profiler::stop('TEMPLATE:' . $fileName);
        return $html;
    }
Example #28
0
 public static function tearDownAfterClass()
 {
     Magento_Profiler::reset();
 }
Example #29
0
 /**
  * Shopping cart display action
  */
 public function indexAction()
 {
     $cart = $this->_getCart();
     if ($cart->getQuote()->getItemsCount()) {
         $cart->init();
         $cart->save();
         if (!$this->_getQuote()->validateMinimumAmount()) {
             $warning = Mage::getStoreConfig('sales/minimum_order/description');
             $cart->getCheckoutSession()->addNotice($warning);
         }
     }
     // Compose array of messages to add
     $messages = array();
     foreach ($cart->getQuote()->getMessages() as $message) {
         if ($message) {
             $messages[] = $message;
         }
     }
     $cart->getCheckoutSession()->addUniqueMessages($messages);
     /**
      * if customer enteres shopping cart we should mark quote
      * as modified bc he can has checkout page in another window.
      */
     $this->_getSession()->setCartWasUpdated(true);
     Magento_Profiler::start(__METHOD__ . 'cart_display');
     $this->loadLayout()->_initLayoutMessages('Mage_Checkout_Model_Session')->_initLayoutMessages('Mage_Catalog_Model_Session')->getLayout()->getBlock('head')->setTitle($this->__('Shopping Cart'));
     $this->renderLayout();
     Magento_Profiler::stop(__METHOD__ . 'cart_display');
 }
Example #30
0
 public function dispatchEvent($eventName, $args)
 {
     foreach ($this->_events as $area => $events) {
         if (!isset($events[$eventName])) {
             $eventConfig = $this->getConfig()->getEventConfig($area, $eventName);
             if (!$eventConfig) {
                 $this->_events[$area][$eventName] = false;
                 continue;
             }
             $observers = array();
             foreach ($eventConfig->observers->children() as $obsName => $obsConfig) {
                 $observers[$obsName] = array('type' => (string) $obsConfig->type, 'model' => $obsConfig->class ? (string) $obsConfig->class : $obsConfig->getClassName(), 'method' => (string) $obsConfig->method, 'args' => (array) $obsConfig->args);
             }
             $events[$eventName]['observers'] = $observers;
             $this->_events[$area][$eventName]['observers'] = $observers;
         }
         if (false === $events[$eventName]) {
             continue;
         } else {
             $event = new Varien_Event($args);
             $event->setName($eventName);
             $observer = new Varien_Event_Observer();
         }
         foreach ($events[$eventName]['observers'] as $obsName => $obs) {
             $observer->setData(array('event' => $event));
             Magento_Profiler::start('OBSERVER:' . $obsName);
             switch ($obs['type']) {
                 case 'disabled':
                     break;
                 case 'object':
                 case 'model':
                     $method = $obs['method'];
                     $observer->addData($args);
                     $object = Mage::getModel($obs['model']);
                     $this->_callObserverMethod($object, $method, $observer);
                     break;
                 default:
                     $method = $obs['method'];
                     $observer->addData($args);
                     $object = Mage::getSingleton($obs['model']);
                     $this->_callObserverMethod($object, $method, $observer);
                     break;
             }
             Magento_Profiler::stop('OBSERVER:' . $obsName);
         }
     }
     return $this;
 }