コード例 #1
0
 /**
  * Push `trackSiteSearch' to tracker on search result page
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return \Henhed\Piwik\Observer\SearchResultObserver
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!$this->_dataHelper->isTrackingEnabled()) {
         return $this;
     }
     $query = $this->_queryFactory->get();
     $piwikBlock = $this->_view->getLayout()->getBlock('piwik.tracker');
     /* @var $query \Magento\Search\Model\Query */
     /* @var $piwikBlock \Henhed\Piwik\Block\Piwik */
     $keyword = $query->getQueryText();
     $resultsCount = $query->getNumResults();
     if (is_null($resultsCount)) {
         // If this is a new search query the result count hasn't been saved
         // yet so we have to fetch it from the search result block instead.
         $resultBock = $this->_view->getLayout()->getBlock('search.result');
         /* @var $resultBock \Magento\CatalogSearch\Block\Result */
         if ($resultBock) {
             $resultsCount = $resultBock->getResultCount();
         }
     }
     if (is_null($resultsCount)) {
         $this->_piwikTracker->trackSiteSearch($keyword);
     } else {
         $this->_piwikTracker->trackSiteSearch($keyword, false, (int) $resultsCount);
     }
     if ($piwikBlock) {
         // Don't push `trackPageView' when `trackSiteSearch' is set
         $piwikBlock->setSkipTrackPageView(true);
     }
     return $this;
 }
コード例 #2
0
ファイル: View.php プロジェクト: aiesh/magento2
 /**
  * Prepares product view page - inits layout and all needed stuff
  *
  * $params can have all values as $params in \Magento\Catalog\Helper\Product - initProduct().
  * Plus following keys:
  *   - 'buy_request' - \Magento\Framework\Object holding buyRequest to configure product
  *   - 'specify_options' - boolean, whether to show 'Specify options' message
  *   - 'configure_mode' - boolean, whether we're in Configure-mode to edit product configuration
  *
  * @param int $productId
  * @param \Magento\Framework\App\Action\Action $controller
  * @param null|\Magento\Framework\Object $params
  *
  * @return \Magento\Catalog\Helper\Product\View
  * @throws \Magento\Framework\Model\Exception
  */
 public function prepareAndRender($productId, $controller, $params = null)
 {
     // Prepare data
     $productHelper = $this->_catalogProduct;
     if (!$params) {
         $params = new \Magento\Framework\Object();
     }
     // Standard algorithm to prepare and render product view page
     $product = $productHelper->initProduct($productId, $controller, $params);
     if (!$product) {
         throw new \Magento\Framework\Model\Exception(__('Product is not loaded'), $this->ERR_NO_PRODUCT_LOADED);
     }
     $buyRequest = $params->getBuyRequest();
     if ($buyRequest) {
         $productHelper->prepareProductOptions($product, $buyRequest);
     }
     if ($params->hasConfigureMode()) {
         $product->setConfigureMode($params->getConfigureMode());
     }
     $this->_eventManager->dispatch('catalog_controller_product_view', array('product' => $product));
     $this->_catalogSession->setLastViewedProductId($product->getId());
     $this->initProductLayout($product, $controller, $params);
     if ($controller instanceof \Magento\Catalog\Controller\Product\View\ViewInterface) {
         $this->_view->getLayout()->initMessages($this->messageGroups);
     } else {
         throw new \Magento\Framework\Model\Exception(__('Bad controller interface for showing product'), $this->ERR_BAD_CONTROLLER_INTERFACE);
     }
     $this->_view->renderLayout();
     return $this;
 }
コード例 #3
0
ファイル: Page.php プロジェクト: pavelnovitsky/magento2
 /**
  * Renders CMS page
  *
  * @param Action $action
  * @param int $pageId
  * @param bool $renderLayout
  * @return bool
  */
 protected function _renderPage(Action $action, $pageId = null, $renderLayout = true)
 {
     if (!is_null($pageId) && $pageId !== $this->_page->getId()) {
         $delimiterPosition = strrpos($pageId, '|');
         if ($delimiterPosition) {
             $pageId = substr($pageId, 0, $delimiterPosition);
         }
         $this->_page->setStoreId($this->_storeManager->getStore()->getId());
         if (!$this->_page->load($pageId)) {
             return false;
         }
     }
     if (!$this->_page->getId()) {
         return false;
     }
     $inRange = $this->_localeDate->isScopeDateInInterval(null, $this->_page->getCustomThemeFrom(), $this->_page->getCustomThemeTo());
     if ($this->_page->getCustomTheme()) {
         if ($inRange) {
             $this->_design->setDesignTheme($this->_page->getCustomTheme());
         }
     }
     if ($this->_page->getPageLayout()) {
         if ($this->_page->getCustomPageLayout() && $this->_page->getCustomPageLayout() != 'empty' && $inRange) {
             $handle = $this->_page->getCustomPageLayout();
         } else {
             $handle = $this->_page->getPageLayout();
         }
         $this->pageConfig->setPageLayout($handle);
     }
     $this->_view->getPage()->initLayout();
     $this->_view->getLayout()->getUpdate()->addHandle('cms_page_view');
     $this->_view->addPageLayoutHandles(array('id' => $this->_page->getIdentifier()));
     $this->_eventManager->dispatch('cms_page_render', array('page' => $this->_page, 'controller_action' => $action));
     $this->_view->loadLayoutUpdates();
     if ($this->_page->getCustomLayoutUpdateXml() && $inRange) {
         $layoutUpdate = $this->_page->getCustomLayoutUpdateXml();
     } else {
         $layoutUpdate = $this->_page->getLayoutUpdateXml();
     }
     if (!empty($layoutUpdate)) {
         $this->_view->getLayout()->getUpdate()->addUpdate($layoutUpdate);
     }
     $this->_view->generateLayoutXml()->generateLayoutBlocks();
     $contentHeadingBlock = $this->_view->getLayout()->getBlock('page_content_heading');
     if ($contentHeadingBlock) {
         $contentHeading = $this->_escaper->escapeHtml($this->_page->getContentHeading());
         $contentHeadingBlock->setContentHeading($contentHeading);
     }
     /* @TODO: Move catalog and checkout storage types to appropriate modules */
     $messageBlock = $this->_view->getLayout()->getMessagesBlock();
     $messageBlock->addStorageType($this->messageManager->getDefaultGroup());
     $messageBlock->addMessages($this->messageManager->getMessages(true));
     if ($renderLayout) {
         $this->_view->renderLayout();
     }
     return true;
 }
コード例 #4
0
ファイル: Data.php プロジェクト: steegi/paystand-magento2
 /**
  * Get payment method step html
  *
  * @param \Magento\Framework\App\ViewInterface $view
  * @return string
  */
 public function getPaymentMethodsHtml(\Magento\Framework\App\ViewInterface $view)
 {
     $layout = $view->getLayout();
     $update = $layout->getUpdate();
     $update->load('checkout_onepage_paymentmethod');
     $layout->generateXml();
     $layout->generateElements();
     $output = $layout->getOutput();
     return $output;
 }
コード例 #5
0
 /**
  * Set data for response of frontend saveOrder action
  *
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     /* @var $order \Magento\Sales\Model\Order */
     $order = $this->_coreRegistry->registry('hss_order');
     if ($order && $order->getId()) {
         $payment = $order->getPayment();
         if ($payment && in_array($payment->getMethod(), $this->_paypalHss->getHssMethods())) {
             $result = $observer->getData('result')->getData();
             if (empty($result['error'])) {
                 $this->_view->loadLayout('checkout_onepage_review', true, true, false);
                 $html = $this->_view->getLayout()->getBlock('paypal.iframe')->toHtml();
                 $result['update_section'] = ['name' => 'paypaliframe', 'html' => $html];
                 $result['redirect'] = false;
                 $result['success'] = false;
                 $observer->getData('result')->setData($result);
             }
         }
     }
 }
コード例 #6
0
ファイル: Composite.php プロジェクト: pavelnovitsky/magento2
 /**
  * Init composite product configuration layout
  *
  * $isOk - true or false, whether action was completed nicely or with some error
  * If $isOk is FALSE (some error during configuration), so $productType must be null
  *
  * @param bool $isOk
  * @param string $productType
  * @return $this
  */
 protected function _initConfigureResultLayout($isOk, $productType)
 {
     $update = $this->_view->getLayout()->getUpdate();
     if ($isOk) {
         $update->addHandle('CATALOG_PRODUCT_COMPOSITE_CONFIGURE')->addHandle('catalog_product_view_type_' . $productType);
     } else {
         $update->addHandle('CATALOG_PRODUCT_COMPOSITE_CONFIGURE_ERROR');
     }
     $this->_view->loadLayoutUpdates();
     $this->_view->generateLayoutXml();
     $this->_view->generateLayoutBlocks();
     return $this;
 }
コード例 #7
0
ファイル: Observer.php プロジェクト: zhangjiachao/magento2
 /**
  * Set data for response of frontend saveOrder action
  *
  * @param EventObserver $observer
  * @return $this
  */
 public function setResponseAfterSaveOrder(EventObserver $observer)
 {
     /* @var $order \Magento\Sales\Model\Order */
     $order = $this->_coreRegistry->registry('hss_order');
     if ($order && $order->getId()) {
         $payment = $order->getPayment();
         if ($payment && in_array($payment->getMethod(), $this->_paypalHss->getHssMethods())) {
             /* @var $controller \Magento\Framework\App\Action\Action */
             $controller = $observer->getEvent()->getData('controller_action');
             $result = $this->_coreData->jsonDecode($controller->getResponse()->getBody('default'));
             if (empty($result['error'])) {
                 $this->_view->loadLayout('checkout_onepage_review', true, true, false);
                 $html = $this->_view->getLayout()->getBlock('paypal.iframe')->toHtml();
                 $result['update_section'] = array('name' => 'paypaliframe', 'html' => $html);
                 $result['redirect'] = false;
                 $result['success'] = false;
                 $controller->getResponse()->clearHeader('Location');
                 $controller->getResponse()->representJson($this->_coreData->jsonEncode($result));
             }
         }
     }
     return $this;
 }