Beispiel #1
0
 /**
  * Product variations attributes validation
  *
  * @param Product $parentProduct
  * @param array $products
  * @param RequestInterface $request
  * @return array
  */
 protected function _validateProductVariations(Product $parentProduct, array $products, RequestInterface $request)
 {
     $this->eventManager->dispatch('catalog_product_validate_variations_before', ['product' => $parentProduct, 'variations' => $products]);
     $validationResult = [];
     foreach ($products as $productData) {
         $product = $this->productFactory->create();
         $product->setData('_edit_mode', true);
         $storeId = $request->getParam('store');
         if ($storeId) {
             $product->setStoreId($storeId);
         }
         $product->setAttributeSetId($parentProduct->getAttributeSetId());
         $product->addData($this->getRequiredDataFromProduct($parentProduct));
         $product->addData($productData);
         $product->setCollectExceptionMessages(true);
         $configurableAttribute = [];
         $encodedData = $productData['configurable_attribute'];
         if ($encodedData) {
             $configurableAttribute = $this->jsonHelper->jsonDecode($encodedData);
         }
         $configurableAttribute = implode('-', $configurableAttribute);
         $errorAttributes = $product->validate();
         if (is_array($errorAttributes)) {
             foreach ($errorAttributes as $attributeCode => $result) {
                 if (is_string($result)) {
                     $key = 'variations-matrix-' . $configurableAttribute . '-' . $attributeCode;
                     $validationResult[$key] = $result;
                 }
             }
         }
     }
     return $validationResult;
 }
Beispiel #2
0
 /**
  * Clear cache after reindex all
  *
  * @param \Magento\Indexer\Model\Processor $subject
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterReindexAllInvalid(\Magento\Indexer\Model\Processor $subject)
 {
     $this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this->context]);
     if (!empty($this->context->getIdentities())) {
         $this->getCache()->clean($this->context->getIdentities());
     }
 }
Beispiel #3
0
 /**
  * After generate Xml
  *
  * @param \Magento\Framework\View\LayoutInterface $subject
  * @param \Magento\Framework\View\LayoutInterface $result
  * @return \Magento\Framework\View\LayoutInterface
  */
 public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
 {
     if ($this->moduleManager->isEnabled('Magento_PageCache') && $this->cacheConfig->isEnabled() && !$this->request->isAjax() && $subject->isCacheable()) {
         $this->eventManager->dispatch('depersonalize_clear_session');
         session_write_close();
         $this->messageSession->clearStorage();
     }
     return $result;
 }
 /**
  * After generate Xml
  *
  * @param \Magento\Framework\View\LayoutInterface $subject
  * @param \Magento\Framework\View\LayoutInterface $result
  * @return \Magento\Framework\View\LayoutInterface
  */
 public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
 {
     if ($this->depersonalizeChecker->checkIfDepersonalize($subject)) {
         $this->eventManager->dispatch('depersonalize_clear_session');
         session_write_close();
         $this->messageSession->clearStorage();
     }
     return $result;
 }
Beispiel #5
0
 /**
  * Run application
  *
  * @return ResponseInterface
  */
 public function launch()
 {
     $areaCode = $this->_areaList->getCodeByFrontName($this->_request->getFrontName());
     $this->_state->setAreaCode($areaCode);
     $this->_objectManager->configure($this->_configLoader->load($areaCode));
     $this->_response = $this->_objectManager->get('Magento\\Framework\\App\\FrontControllerInterface')->dispatch($this->_request);
     // This event gives possibility to launch something before sending output (allow cookie setting)
     $eventParams = array('request' => $this->_request, 'response' => $this->_response);
     $this->_eventManager->dispatch('controller_front_send_response_before', $eventParams);
     return $this->_response;
 }
Beispiel #6
0
 /**
  * Run application
  *
  * @return ResponseInterface
  */
 public function launch()
 {
     try {
         $areaCode = $this->_areaList->getCodeByFrontName($this->_request->getFrontName());
         $this->_state->setAreaCode($areaCode);
         $this->_objectManager->configure($this->_configLoader->load($areaCode));
         $this->_response = $this->_objectManager->get('Magento\\Framework\\App\\FrontControllerInterface')->dispatch($this->_request);
         // This event gives possibility to launch something before sending output (allow cookie setting)
         $eventParams = array('request' => $this->_request, 'response' => $this->_response);
         $this->_eventManager->dispatch('controller_front_send_response_before', $eventParams);
     } catch (\Exception $exception) {
         $message = $exception->getMessage() . "\n";
         try {
             if ($this->_state->getMode() == State::MODE_DEVELOPER) {
                 $message .= '<pre>';
                 $message .= $exception->getMessage() . "\n\n";
                 $message .= $exception->getTraceAsString();
                 $message .= '</pre>';
             } else {
                 $reportData = array($exception->getMessage(), $exception->getTraceAsString());
                 // retrieve server data
                 if (isset($_SERVER)) {
                     if (isset($_SERVER['REQUEST_URI'])) {
                         $reportData['url'] = $_SERVER['REQUEST_URI'];
                     }
                     if (isset($_SERVER['SCRIPT_NAME'])) {
                         $reportData['script_name'] = $_SERVER['SCRIPT_NAME'];
                     }
                 }
                 require_once $this->_filesystem->getPath(Filesystem::PUB_DIR) . '/errors/report.php';
                 $processor = new \Magento\Framework\Error\Processor($this->_response);
                 $processor->saveReport($reportData);
                 $this->_response = $processor->processReport();
             }
         } catch (\Exception $exception) {
             $message .= "Unknown error happened.";
         }
         $this->_response->setHttpResponseCode(500);
         $this->_response->setBody($message);
     }
     return $this->_response;
 }
Beispiel #7
0
 /**
  * Run application
  *
  * @throws \InvalidArgumentException
  * @return ResponseInterface
  */
 public function launch()
 {
     $areaCode = $this->_areaList->getCodeByFrontName($this->_request->getFrontName());
     $this->_state->setAreaCode($areaCode);
     $this->_objectManager->configure($this->_configLoader->load($areaCode));
     /** @var \Magento\Framework\App\FrontControllerInterface $frontController */
     $frontController = $this->_objectManager->get('Magento\\Framework\\App\\FrontControllerInterface');
     $result = $frontController->dispatch($this->_request);
     // TODO: Temporary solution until all controllers return ResultInterface (MAGETWO-28359)
     if ($result instanceof ResultInterface) {
         $this->registry->register('use_page_cache_plugin', true, true);
         $result->renderResult($this->_response);
     } elseif ($result instanceof HttpInterface) {
         $this->_response = $result;
     } else {
         throw new \InvalidArgumentException('Invalid return type');
     }
     // This event gives possibility to launch something before sending output (allow cookie setting)
     $eventParams = ['request' => $this->_request, 'response' => $this->_response];
     $this->_eventManager->dispatch('controller_front_send_response_before', $eventParams);
     return $this->_response;
 }
 public function testDispatchWithEmptyEventObservers()
 {
     $this->_eventConfigMock->expects($this->once())->method('getObservers')->with('some_event')->will($this->returnValue([]));
     $this->_invoker->expects($this->never())->method('dispatch');
     $this->_eventManager->dispatch('some_event');
 }
Beispiel #9
0
 /**
  * Clear cache after reindex all
  *
  * @param \Magento\Indexer\Model\Processor $subject
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterReindexAllInvalid(\Magento\Indexer\Model\Processor $subject)
 {
     $this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this->context]);
 }
 /**
  * Update indexer views
  *
  * @param \Magento\Indexer\Model\Processor $subject
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterUpdateMview(\Magento\Indexer\Model\Processor $subject)
 {
     if ($this->moduleManager->isEnabled('Magento_PageCache')) {
         $this->eventManager->dispatch('clean_cache_after_reindex', ['object' => $this->context]);
     }
 }