/**
  * Perform action and generate response
  *
  * @param RequestInterface $request
  * @return ResponseInterface|\Magento\Framework\Controller\ResultInterface
  * @throws \LogicException
  */
 public function dispatch(RequestInterface $request)
 {
     \Magento\Framework\Profiler::start('routers_match');
     $routingCycleCounter = 0;
     $result = null;
     while (!$request->isDispatched() && $routingCycleCounter++ < 100) {
         /** @var \Magento\Framework\App\RouterInterface $router */
         foreach ($this->_routerList as $router) {
             try {
                 $actionInstance = $router->match($request);
                 if ($actionInstance) {
                     $request->setDispatched(true);
                     $this->response->setNoCacheHeaders();
                     if ($actionInstance instanceof \Magento\Framework\App\Action\AbstractAction) {
                         $result = $actionInstance->dispatch($request);
                     } else {
                         $result = $actionInstance->execute();
                     }
                     break;
                 }
             } catch (\Magento\Framework\Exception\NotFoundException $e) {
                 $request->initForward();
                 $request->setActionName('noroute');
                 $request->setDispatched(false);
                 break;
             }
         }
     }
     \Magento\Framework\Profiler::stop('routers_match');
     if ($routingCycleCounter > 100) {
         throw new \LogicException('Front controller reached 100 router match iterations');
     }
     return $result;
 }
示例#2
0
 public function execute()
 {
     $resultPage = $this->resultPageFactory->create();
     \Magento\Framework\Profiler::start('foggyline:office');
     $this->logger->log(\Monolog\Logger::DEBUG, 'debug msg');
     $this->logger->log(\Monolog\Logger::INFO, 'info msg');
     $this->logger->log(\Monolog\Logger::NOTICE, 'notice msg');
     $this->logger->log(\Monolog\Logger::WARNING, 'warning msg');
     $this->logger->log(\Monolog\Logger::ERROR, 'error msg');
     $this->logger->log(\Monolog\Logger::CRITICAL, 'critical msg');
     $this->logger->log(\Monolog\Logger::ALERT, 'alert msg');
     $this->logger->log(\Monolog\Logger::EMERGENCY, 'emergency msg');
     $this->logger->debug('debug msg');
     $this->logger->info('info msg');
     $this->logger->notice('notice msg');
     $this->logger->warning('warning msg');
     $this->logger->error('error msg');
     $this->logger->critical('critical msg');
     $this->logger->alert('alert msg');
     $this->logger->emergency('emergency msg');
     sleep(2);
     /* code block or single expression here */
     \Magento\Framework\Profiler::stop('foggyline:office');
     return $resultPage;
 }
示例#3
0
 /**
  * Get html code
  *
  * @return string
  */
 protected function _toHtml()
 {
     /* @var $template \Magento\Newsletter\Model\Template */
     $template = $this->_templateFactory->create();
     if ($id = (int) $this->getRequest()->getParam('id')) {
         $this->loadTemplate($template, $id);
     } else {
         $previewData = $this->getPreviewData();
         $template->setTemplateType($previewData['type']);
         $template->setTemplateText($previewData['text']);
         $template->setTemplateStyles($previewData['styles']);
     }
     \Magento\Framework\Profiler::start($this->profilerName);
     $vars = [];
     $vars['subscriber'] = $this->_subscriberFactory->create();
     if ($this->getRequest()->getParam('subscriber')) {
         $vars['subscriber']->load($this->getRequest()->getParam('subscriber'));
     }
     $template->emulateDesign($this->getStoreId());
     $templateProcessed = $this->_appState->emulateAreaCode(\Magento\Newsletter\Model\Template::DEFAULT_DESIGN_AREA, [$template, 'getProcessedTemplate'], [$vars]);
     $template->revertDesign();
     if ($template->isPlain()) {
         $templateProcessed = "<pre>" . htmlspecialchars($templateProcessed) . "</pre>";
     }
     \Magento\Framework\Profiler::stop($this->profilerName);
     return $templateProcessed;
 }
示例#4
0
 /**
  * Get html code
  *
  * @return string
  */
 protected function _toHtml()
 {
     /* @var $template \Magento\Newsletter\Model\Template */
     $template = $this->_templateFactory->create();
     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'));
     }
     $storeId = (int) $this->getRequest()->getParam('store_id');
     if (!$storeId) {
         $storeId = $this->_storeManager->getDefaultStoreView()->getId();
     }
     \Magento\Framework\Profiler::start("newsletter_template_proccessing");
     $vars = array();
     $vars['subscriber'] = $this->_subscriberFactory->create();
     if ($this->getRequest()->getParam('subscriber')) {
         $vars['subscriber']->load($this->getRequest()->getParam('subscriber'));
     }
     $template->emulateDesign($storeId);
     $templateProcessed = $this->_appState->emulateAreaCode(\Magento\Newsletter\Model\Template::DEFAULT_DESIGN_AREA, array($template, 'getProcessedTemplate'), array($vars, true));
     $template->revertDesign();
     if ($template->isPlain()) {
         $templateProcessed = "<pre>" . htmlspecialchars($templateProcessed) . "</pre>";
     }
     \Magento\Framework\Profiler::stop("newsletter_template_proccessing");
     return $templateProcessed;
 }
示例#5
0
 /**
  * Prepare html output
  *
  * @return string
  */
 protected function _toHtml()
 {
     /** @var $template \Magento\Email\Model\Template */
     $template = $this->_emailFactory->create(['data' => ['area' => \Magento\Framework\App\Area::AREA_FRONTEND]]);
     $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'));
     }
     $template->setTemplateText($this->_maliciousCode->filter($template->getTemplateText()));
     \Magento\Framework\Profiler::start("email_template_proccessing");
     $vars = [];
     $store = $this->getAnyStoreView();
     $storeId = $store ? $store->getId() : null;
     $template->setDesignConfig(['area' => $this->_design->getArea(), 'store' => $storeId]);
     $templateProcessed = $template->getProcessedTemplate($vars, true);
     if ($template->isPlain()) {
         $templateProcessed = "<pre>" . htmlspecialchars($templateProcessed) . "</pre>";
     }
     \Magento\Framework\Profiler::stop("email_template_proccessing");
     return $templateProcessed;
 }
示例#6
0
 /**
  * Run application
  *
  * @param string $applicationName
  * @param array $arguments
  * @return void
  */
 public function run($applicationName, array $arguments = array())
 {
     try {
         \Magento\Framework\Profiler::start('magento');
         if (!$this->_locator) {
             $locatorFactory = new \Magento\Framework\App\ObjectManagerFactory();
             $this->_locator = $locatorFactory->create($this->_rootDir, $this->_parameters);
         }
         $application = $this->_locator->create($applicationName, $arguments);
         $response = $application->launch();
         \Magento\Framework\Profiler::stop('magento');
         $response->sendResponse();
     } catch (\Exception $exception) {
         if (isset($this->_parameters[State::PARAM_MODE]) && $this->_parameters[State::PARAM_MODE] == State::MODE_DEVELOPER) {
             echo $exception->getMessage() . "\n\n";
             echo $exception->getTraceAsString();
         } else {
             $message = "Error happened during application run.\n";
             try {
                 if (!$this->_locator) {
                     throw new \DomainException();
                 }
                 $this->_locator->get('Magento\\Framework\\Logger')->logException($exception);
             } catch (\Exception $e) {
                 $message .= "Could not write error message to log. Please use developer mode to see the message.\n";
             }
             echo $message;
         }
     }
 }
示例#7
0
 /**
  *
  * {@inheritdoc}
  */
 public function logStats($type, $sql, $bind = [], $result = null)
 {
     $log = [];
     //Change approach to "around" and then break return string into MySQL columns
     //  as right now we cannot get time of query execution
     //Problem remains how to pass the YES/NO on time and full backtrace
     // maybe its best to simply record all and then remove it from __destruct
     // as in __destruct we have access to helper
     // trace log and all log simply kill the database size, thus we need them as config
     self::$counter++;
     \Magento\Framework\Profiler::start('foggyline_sentinel_logStats_' . self::$counter);
     $log['type'] = $type;
     $log['time'] = sprintf('%.4f', microtime(true) - $this->timer);
     $log['sql'] = $sql;
     $log['bind'] = var_export($bind, true);
     if ($result instanceof \Zend_Db_Statement_Pdo) {
         $log['row_count'] = $result->rowCount();
     }
     /**
      * When backtrace is assigned, it consumes roughly:
      *  - 0.3 seconds on homepage,
      *  - 0.5 seconds on admin product page
      *
      * Problem here is that we cannot control Debug::backtrace via Magento admin config, so we have to leave it
      * either running or comment it out. If we leave it running, we can add some minor tome to overhead but we
      * can then use $this->helper->getQueryLogCallStack(); to either save it in database or not.
      *
      * Backtrace adds enormous amount of data to database. We are talking MB of data just in 3-4 page requests.
      * Thus it is highly important be very careful with full log stack (backtrace) loging to dataabse.
      */
     $log['backtrace'] = \Magento\Framework\Debug::backtrace(true, false);
     $this->queryLogs[] = $log;
     \Magento\Framework\Profiler::stop('foggyline_sentinel_logStats_' . self::$counter);
 }
示例#8
0
 /**
  * Apply rewrites to current request
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @return void
  */
 public function applyRewrites(\Magento\Framework\App\RequestInterface $request)
 {
     // URL rewrite
     if (!$request->isStraight()) {
         \Magento\Framework\Profiler::start('db_url_rewrite');
         /** @var $urlRewrite \Magento\UrlRewrite\Model\UrlRewrite */
         $urlRewrite = $this->_rewriteFactory->create();
         $urlRewrite->rewrite($request);
         \Magento\Framework\Profiler::stop('db_url_rewrite');
     }
 }
示例#9
0
 /**
  * @SuppressWarnings(PHPMD.StaticAccess)
  *
  * {@inheritdoc}
  */
 public function query(RequestInterface $request)
 {
     \Magento\Framework\Profiler::start('ES:Execute Search Query');
     try {
         $searchResponse = $this->doSearch($request);
     } catch (\Exception $e) {
         $searchResponse = [];
         $this->logger->error($e->getMessage());
     }
     \Magento\Framework\Profiler::stop('ES:Execute Search Query');
     return $this->responseFactory->create(['searchResponse' => $searchResponse]);
 }
示例#10
0
 /**
  * Dispatch event
  *
  * Calls all observer callbacks registered for this event
  * and multiple observers matching event name pattern
  *
  * @param string $eventName
  * @param array $data
  * @return void
  */
 public function dispatch($eventName, array $data = array())
 {
     \Magento\Framework\Profiler::start('EVENT:' . $eventName, array('group' => 'EVENT', 'name' => $eventName));
     foreach ($this->_eventConfig->getObservers($eventName) as $observerConfig) {
         $event = new \Magento\Framework\Event($data);
         $event->setName($eventName);
         $wrapper = new Observer();
         $wrapper->setData(array_merge(array('event' => $event), $data));
         \Magento\Framework\Profiler::start('OBSERVER:' . $observerConfig['name']);
         $this->_invoker->dispatch($observerConfig, $wrapper);
         \Magento\Framework\Profiler::stop('OBSERVER:' . $observerConfig['name']);
     }
     \Magento\Framework\Profiler::stop('EVENT:' . $eventName);
 }
示例#11
0
 /**
  * Perform action and generate response
  *
  * @param RequestInterface $request
  * @return ResponseInterface|\Magento\Framework\Controller\ResultInterface
  * @throws \LogicException
  */
 public function dispatch(RequestInterface $request)
 {
     \Magento\Framework\Profiler::start('routers_match');
     $routingCycleCounter = 0;
     $result = null;
     while (!$request->isDispatched() && $routingCycleCounter++ < 100) {
         $result = $this->processRequest($request);
     }
     \Magento\Framework\Profiler::stop('routers_match');
     if ($routingCycleCounter > 100) {
         throw new \LogicException('Front controller reached 100 router match iterations');
     }
     return $result;
 }
 public function dispatch($eventName, array $data = [])
 {
     \Magento\Framework\Profiler::start('EVENT:' . $eventName, ['group' => 'EVENT', 'name' => $eventName]);
     foreach ($this->_eventConfig->getObservers($eventName) as $observerConfig) {
         $event = new \Magento\Framework\Event($data);
         $event->setName($eventName);
         $wrapper = new \Magento\Framework\Event\Observer();
         $wrapper->setData(array_merge(['event' => $event], $data));
         \Magento\Framework\Profiler::start('OBSERVER:' . $observerConfig['name']);
         $this->_invoker->dispatch($observerConfig, $wrapper);
         $observerConfig['method'] = 'execute';
         $this->_devHelper->setObserverDetails($observerConfig, $eventName);
         \Magento\Framework\Profiler::stop('OBSERVER:' . $observerConfig['name']);
     }
     \Magento\Framework\Profiler::stop('EVENT:' . $eventName);
 }
示例#13
0
 /**
  * Dispatches an event to observer's callback
  *
  * @param Event $event
  * @return $this
  */
 public function dispatch(Event $event)
 {
     if (!$this->isValidFor($event)) {
         return $this;
     }
     $callback = $this->getCallback();
     $this->setEvent($event);
     $_profilerKey = 'OBSERVER: ';
     if (is_object($callback[0])) {
         $_profilerKey .= get_class($callback[0]);
     } else {
         $_profilerKey .= (string) $callback[0];
     }
     $_profilerKey .= ' -> ' . $callback[1];
     \Magento\Framework\Profiler::start($_profilerKey);
     call_user_func($callback, $this);
     \Magento\Framework\Profiler::stop($_profilerKey);
     return $this;
 }
示例#14
0
 /**
  * Reindex all data what process is responsible
  *
  * @return void
  */
 public function execute()
 {
     /** @var $process \Magento\Index\Model\Process */
     $process = $this->_initProcess();
     if ($process) {
         try {
             \Magento\Framework\Profiler::start('__INDEX_PROCESS_REINDEX_ALL__');
             $process->reindexEverything();
             \Magento\Framework\Profiler::stop('__INDEX_PROCESS_REINDEX_ALL__');
             $this->messageManager->addSuccess(__('%1 index was rebuilt.', $process->getIndexer()->getName()));
         } catch (\Magento\Framework\Model\Exception $e) {
             $this->messageManager->addError($e->getMessage());
         } catch (\Exception $e) {
             $this->messageManager->addException($e, __('There was a problem with reindexing process.'));
         }
     } else {
         $this->messageManager->addError(__('Cannot initialize the indexer process.'));
     }
     $this->_redirect('adminhtml/*/list');
 }
示例#15
0
 /**
  * @inheritdoc
  */
 public function getCurrency($currency)
 {
     \Magento\Framework\Profiler::start('locale/currency');
     if (!isset(self::$_currencyCache[$this->_localeResolver->getLocale()][$currency])) {
         $options = [];
         try {
             $currencyObject = $this->_currencyFactory->create(['options' => $currency, 'locale' => $this->_localeResolver->getLocale()]);
         } catch (\Exception $e) {
             $currencyObject = $this->_currencyFactory->create(['options' => $this->getDefaultCurrency(), 'locale' => $this->_localeResolver->getLocale()]);
             $options[self::CURRENCY_OPTION_NAME] = $currency;
             $options[self::CURRENCY_OPTION_CURRENCY] = $currency;
             $options[self::CURRENCY_OPTION_SYMBOL] = $currency;
         }
         $options = new \Magento\Framework\Object($options);
         $this->_eventManager->dispatch('currency_display_options_forming', ['currency_options' => $options, 'base_code' => $currency]);
         $currencyObject->setFormat($options->toArray());
         self::$_currencyCache[$this->_localeResolver->getLocale()][$currency] = $currencyObject;
     }
     \Magento\Framework\Profiler::stop('locale/currency');
     return self::$_currencyCache[$this->_localeResolver->getLocale()][$currency];
 }
示例#16
0
 /**
  * Prepare html output
  *
  * @return string
  */
 protected function _toHtml()
 {
     $storeId = $this->getAnyStoreView()->getId();
     /** @var $template \Magento\Email\Model\Template */
     $template = $this->_emailFactory->create();
     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->_maliciousCode->filter($template->getTemplateText()));
     \Magento\Framework\Profiler::start($this->profilerName);
     $template->emulateDesign($storeId);
     $templateProcessed = $this->_appState->emulateAreaCode(\Magento\Email\Model\AbstractTemplate::DEFAULT_DESIGN_AREA, [$template, 'getProcessedTemplate']);
     $template->revertDesign();
     if ($template->isPlain()) {
         $templateProcessed = "<pre>" . htmlspecialchars($templateProcessed) . "</pre>";
     }
     \Magento\Framework\Profiler::stop($this->profilerName);
     return $templateProcessed;
 }
示例#17
0
 /**
  * Shopping cart display action
  *
  * @return void
  */
 public function execute()
 {
     if ($this->cart->getQuote()->getItemsCount()) {
         $this->cart->init();
         $this->cart->save();
         if (!$this->cart->getQuote()->validateMinimumAmount()) {
             $currencyCode = $this->_objectManager->get('Magento\\Framework\\StoreManagerInterface')->getStore()->getCurrentCurrencyCode();
             $minimumAmount = $this->_objectManager->get('Magento\\Framework\\Locale\\CurrencyInterface')->getCurrency($currencyCode)->toCurrency($this->_scopeConfig->getValue('sales/minimum_order/amount', \Magento\Store\Model\ScopeInterface::SCOPE_STORE));
             $warning = $this->_scopeConfig->getValue('sales/minimum_order/description', \Magento\Store\Model\ScopeInterface::SCOPE_STORE) ? $this->_scopeConfig->getValue('sales/minimum_order/description', \Magento\Store\Model\ScopeInterface::SCOPE_STORE) : __('Minimum order amount is %1', $minimumAmount);
             $this->messageManager->addNotice($warning);
         }
     }
     // Compose array of messages to add
     $messages = array();
     /** @var \Magento\Framework\Message\MessageInterface $message  */
     foreach ($this->cart->getQuote()->getMessages() as $message) {
         if ($message) {
             // Escape HTML entities in quote message to prevent XSS
             $message->setText($this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($message->getText()));
             $messages[] = $message;
         }
     }
     $this->messageManager->addUniqueMessages($messages);
     /**
      * if customer enteres shopping cart we should mark quote
      * as modified bc he can has checkout page in another window.
      */
     $this->_checkoutSession->setCartWasUpdated(true);
     \Magento\Framework\Profiler::start(__METHOD__ . 'cart_display');
     $this->_view->loadLayout();
     $layout = $this->_view->getLayout();
     $layout->initMessages();
     $layout->getBlock('head')->setTitle(__('Shopping Cart'));
     $this->_view->renderLayout();
     \Magento\Framework\Profiler::stop(__METHOD__ . 'cart_display');
 }
示例#18
0
 /**
  * Retrieve layer state object
  *
  * @return \Magento\Catalog\Model\Layer\State
  */
 public function getState()
 {
     $state = $this->getData('state');
     if (is_null($state)) {
         \Magento\Framework\Profiler::start(__METHOD__);
         $state = $this->_layerStateFactory->create();
         $this->setData('state', $state);
         \Magento\Framework\Profiler::stop(__METHOD__);
     }
     return $state;
 }
示例#19
0
文件: Config.php 项目: aiesh/magento2
 /**
  * Preload entity type attributes for performance optimization
  *
  * @param   mixed $entityType
  * @param   mixed $attributes
  * @return $this
  */
 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\Framework\Profiler::start('EAV: ' . __METHOD__ . ':' . $entityTypeCode, array('group' => 'EAV', 'method' => __METHOD__, 'entity_type_code' => $entityTypeCode));
     $attributesInfo = $this->_universalFactory->create($entityType->getEntityAttributeCollection())->setEntityTypeFilter($entityType)->setCodeFilter($attributes)->getData();
     if (!$attributesInfo) {
         \Magento\Framework\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\Framework\Profiler::stop('EAV: ' . __METHOD__ . ':' . $entityTypeCode);
     return $this;
 }
示例#20
0
 /**
  * Create structure of elements from the loaded XML configuration
  *
  * @return void
  */
 public function generateElements()
 {
     \Magento\Framework\Profiler::start(__CLASS__ . '::' . __METHOD__);
     $cacheId = 'structure_' . $this->getUpdate()->getCacheId();
     $result = $this->cache->load($cacheId);
     if ($result) {
         $this->readerContext = unserialize($result);
     } else {
         \Magento\Framework\Profiler::start('build_structure');
         $this->readerPool->interpret($this->getReaderContext(), $this->getNode());
         \Magento\Framework\Profiler::stop('build_structure');
         $this->cache->save(serialize($this->getReaderContext()), $cacheId, $this->getUpdate()->getHandles());
     }
     $generatorContext = $this->generatorContextFactory->create(['structure' => $this->structure, 'layout' => $this]);
     \Magento\Framework\Profiler::start('generate_elements');
     $this->generatorPool->process($this->getReaderContext(), $generatorContext);
     \Magento\Framework\Profiler::stop('generate_elements');
     $this->addToOutputRootContainers();
     \Magento\Framework\Profiler::stop(__CLASS__ . '::' . __METHOD__);
 }
示例#21
0
 /**
  * Retrieve Selected Attributes info
  *
  * @param  \Magento\Catalog\Model\Product $product
  * @return array
  */
 public function getSelectedAttributesInfo($product)
 {
     $attributes = [];
     \Magento\Framework\Profiler::start('CONFIGURABLE:' . __METHOD__, ['group' => 'CONFIGURABLE', 'method' => __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])) {
                 /** @var \Magento\Catalog\Model\Resource\Eav\Attribute $attribute */
                 $attribute = $usedAttributes[$attributeId]->getProductAttribute();
                 $label = $attribute->getStoreLabel();
                 $value = $attribute;
                 if ($value->getSourceModel()) {
                     $value = $value->getSource()->getOptionText($attributeValue);
                 } else {
                     $value = '';
                 }
                 $attributes[] = ['label' => $label, 'value' => $value];
             }
         }
     }
     \Magento\Framework\Profiler::stop('CONFIGURABLE:' . __METHOD__);
     return $attributes;
 }
示例#22
0
 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function getItems()
 {
     Profiler::start(__METHOD__);
     $items = [];
     /** @var \Magento\Catalog\Model\Product $product */
     foreach ($this->collection as $product) {
         $item = ['sku' => $product->getSku(), 'name' => $product->getName(), 'url' => $product->getProductUrl(), 'description' => null, 'image' => null, 'price' => null, 'rating' => null];
         if ($this->config->isShowShortDescription()) {
             $item['description'] = html_entity_decode(strip_tags($product->getDataUsingMethod('description')));
         }
         $image = false;
         if ($product->getImage() && $product->getImage() != 'no_selection') {
             $image = $product->getImage();
         } elseif ($product->getSmallImage() && $product->getSmallImage() != 'no_selection') {
             $image = $product->getSmallImage();
         }
         if ($this->config->isShowImage() && $image) {
             $item['image'] = $this->imageHelper->init($product, false)->setImageFile($image)->resize(65 * 2, 80 * 2)->getUrl();
         }
         if ($this->config->isShowPrice()) {
             $item['price'] = $this->catalogHelper->getTaxPrice($product, $product->getFinalPrice());
             $item['price'] = $this->pricingHelper->currency($item['price'], false, false);
         }
         if ($this->config->isShowRating()) {
             $item['rating'] = $this->reviewRenderer->getReviewsSummaryHtml($product, ReviewRendererInterface::SHORT_VIEW);
         }
         $items[] = $item;
     }
     Profiler::stop(__METHOD__);
     return $items;
 }
示例#23
0
 /**
  * Calculate product price based on special price data and price rules
  *
  * @param   float $basePrice
  * @param   float $specialPrice
  * @param   string $specialPriceFrom
  * @param   string $specialPriceTo
  * @param   bool|float|null $rulePrice
  * @param   mixed|null $wId
  * @param   integer|null $gId
  * @param   int|null $productId
  * @return  float
  */
 public function calculatePrice($basePrice, $specialPrice, $specialPriceFrom, $specialPriceTo, $rulePrice = false, $wId = null, $gId = null, $productId = null)
 {
     \Magento\Framework\Profiler::start('__PRODUCT_CALCULATE_PRICE__');
     if ($wId instanceof Store) {
         $sId = $wId->getId();
         $wId = $wId->getWebsiteId();
     } else {
         $sId = $this->_storeManager->getWebsite($wId)->getDefaultGroup()->getDefaultStoreId();
     }
     $finalPrice = $basePrice;
     $finalPrice = $this->calculateSpecialPrice($finalPrice, $specialPrice, $specialPriceFrom, $specialPriceTo, $sId);
     if ($rulePrice === false) {
         $date = $this->_localeDate->scopeDate($sId);
         $rulePrice = $this->_ruleFactory->create()->getRulePrice($date, $wId, $gId, $productId);
     }
     if ($rulePrice !== null && $rulePrice !== false) {
         $finalPrice = min($finalPrice, $rulePrice);
     }
     $finalPrice = max($finalPrice, 0);
     \Magento\Framework\Profiler::stop('__PRODUCT_CALCULATE_PRICE__');
     return $finalPrice;
 }
示例#24
0
 /**
  * After Load Entity process
  *
  * @param \Magento\Framework\Object $object
  * @return $this
  */
 protected function _afterLoad(\Magento\Framework\Object $object)
 {
     \Magento\Framework\Profiler::start('after_load');
     $this->walkAttributes('backend/afterLoad', array($object));
     \Magento\Framework\Profiler::stop('after_load');
     return $this;
 }
示例#25
0
 /**
  * Fetch & add layout updates for the specified handle from the database
  *
  * @param string $handle
  * @return bool
  */
 protected function _fetchDbLayoutUpdates($handle)
 {
     $_profilerKey = 'layout_db_update: ' . $handle;
     \Magento\Framework\Profiler::start($_profilerKey);
     $updateStr = $this->getDbUpdateString($handle);
     if (!$updateStr) {
         \Magento\Framework\Profiler::stop($_profilerKey);
         return false;
     }
     $updateStr = '<update_xml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' . $updateStr . '</update_xml>';
     $updateStr = $this->_substitutePlaceholders($updateStr);
     $updateXml = $this->_loadXmlString($updateStr);
     $this->_fetchRecursiveUpdates($updateXml);
     $this->addUpdate($updateXml->innerXml());
     \Magento\Framework\Profiler::stop($_profilerKey);
     return (bool) $updateStr;
 }
示例#26
0
 /**
  * Retrieve category id URL
  *
  * @return string
  */
 public function getCategoryIdUrl()
 {
     Profiler::start('REGULAR: ' . __METHOD__, ['group' => 'REGULAR', 'method' => __METHOD__]);
     $urlKey = $this->getUrlKey() ? $this->getUrlKey() : $this->formatUrlKey($this->getName());
     $url = $this->getUrlInstance()->getUrl('catalog/category/view', ['s' => $urlKey, 'id' => $this->getId()]);
     Profiler::stop('REGULAR: ' . __METHOD__);
     return $url;
 }
示例#27
0
 /**
  * Runs an application
  *
  * @param \Magento\Framework\AppInterface $application
  * @return void
  */
 public function run(AppInterface $application)
 {
     try {
         try {
             \Magento\Framework\Profiler::start('magento');
             $this->initErrorHandler();
             $this->initObjectManager();
             $this->assertMaintenance();
             $this->assertInstalled();
             $response = $application->launch();
             $response->sendResponse();
             \Magento\Framework\Profiler::stop('magento');
         } catch (\Exception $e) {
             \Magento\Framework\Profiler::stop('magento');
             if (!$application->catchException($this, $e)) {
                 throw $e;
             }
         }
     } catch (\Exception $e) {
         $this->terminate($e);
     }
 }
示例#28
0
 /**
  * Dispatch request
  *
  * @param RequestInterface $request
  * @return ResponseInterface
  * @throws NotFoundException
  */
 public function dispatch(RequestInterface $request)
 {
     $this->_request = $request;
     $profilerKey = 'CONTROLLER_ACTION:' . $request->getFullActionName();
     $eventParameters = ['controller_action' => $this, 'request' => $request];
     $this->_eventManager->dispatch('controller_action_predispatch', $eventParameters);
     $this->_eventManager->dispatch('controller_action_predispatch_' . $request->getRouteName(), $eventParameters);
     $this->_eventManager->dispatch('controller_action_predispatch_' . $request->getFullActionName(), $eventParameters);
     \Magento\Framework\Profiler::start($profilerKey);
     $result = null;
     if ($request->isDispatched() && !$this->_actionFlag->get('', self::FLAG_NO_DISPATCH)) {
         \Magento\Framework\Profiler::start('action_body');
         $result = $this->execute();
         \Magento\Framework\Profiler::start('postdispatch');
         if (!$this->_actionFlag->get('', self::FLAG_NO_POST_DISPATCH)) {
             $this->_eventManager->dispatch('controller_action_postdispatch_' . $request->getFullActionName(), $eventParameters);
             $this->_eventManager->dispatch('controller_action_postdispatch_' . $request->getRouteName(), $eventParameters);
             $this->_eventManager->dispatch('controller_action_postdispatch', $eventParameters);
         }
         \Magento\Framework\Profiler::stop('postdispatch');
         \Magento\Framework\Profiler::stop('action_body');
     }
     \Magento\Framework\Profiler::stop($profilerKey);
     return $result ?: $this->_response;
 }
示例#29
0
 /**
  * Add products to items and item options
  *
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function _assignProducts()
 {
     \Magento\Framework\Profiler::start('QUOTE:' . __METHOD__, ['group' => 'QUOTE', 'method' => __METHOD__]);
     $productIds = [];
     foreach ($this as $item) {
         $productIds[] = (int) $item->getProductId();
     }
     $this->_productIds = array_merge($this->_productIds, $productIds);
     $productCollection = $this->_productCollectionFactory->create()->setStoreId($this->getStoreId())->addIdFilter($this->_productIds)->addAttributeToSelect($this->_quoteConfig->getProductAttributes())->addOptionsToResult()->addStoreFilter()->addUrlRewrite()->addTierPriceData();
     $this->_eventManager->dispatch('prepare_catalog_product_collection_prices', ['collection' => $productCollection, 'store_id' => $this->getStoreId()]);
     $this->_eventManager->dispatch('sales_quote_item_collection_products_after_load', ['collection' => $productCollection]);
     $recollectQuote = false;
     foreach ($this as $item) {
         $product = $productCollection->getItemById($item->getProductId());
         if ($product) {
             $product->setCustomOptions([]);
             $qtyOptions = [];
             $optionProductIds = [];
             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\Framework\Profiler::stop('QUOTE:' . __METHOD__);
     return $this;
 }
示例#30
0
 /**
  * Initialize currently ran store
  *
  * @param \Magento\Store\Model\StoreManagerInterface $storage
  * @param array $arguments
  * @return void
  * @throws \Magento\Framework\Exception\State\InitException
  */
 protected function _reinitStores(\Magento\Store\Model\StoreManagerInterface $storage, $arguments)
 {
     Profiler::start('init_stores');
     $storage->reinitStores();
     Profiler::stop('init_stores');
     $scopeCode = $arguments['scopeCode'];
     $scopeType = $arguments['scopeType'] ?: ScopeInterface::SCOPE_STORE;
     if (empty($scopeCode) && false == ($storage->getWebsite(true) === null)) {
         $scopeCode = $storage->getWebsite(true)->getCode();
         $scopeType = ScopeInterface::SCOPE_WEBSITE;
     }
     switch ($scopeType) {
         case ScopeInterface::SCOPE_STORE:
             $storage->setCurrentStore($scopeCode);
             break;
         case ScopeInterface::SCOPE_GROUP:
             $storage->setCurrentStore($this->_getStoreByGroup($storage, $scopeCode));
             break;
         case ScopeInterface::SCOPE_WEBSITE:
             $storage->setCurrentStore($this->_getStoreByWebsite($storage, $scopeCode));
             break;
         default:
             throw new \Magento\Framework\Exception\State\InitException(__('Store Manager has not been initialized properly'));
     }
     $currentStore = $storage->getStore()->getCode();
     if (!empty($currentStore)) {
         $this->_checkCookieStore($storage, $scopeType);
         $this->_checkRequestStore($storage, $scopeType);
     }
 }