/** * Converts a specified rate model to a shipping method data object. * * @param \Magento\Quote\Model\Quote\Item $item * @return array * @throws \Exception */ public function modelToDataObject($item) { $this->eventManager->dispatch('items_additional_data', ['item' => $item]); $items = $item->toArray(); $items['options'] = $this->getFormattedOptionValue($item); $itemsData = $this->totalsItemFactory->create(); $this->dataObjectHelper->populateWithArray($itemsData, $items, '\\Magento\\Quote\\Api\\Data\\TotalsItemInterface'); return $itemsData; }
/** * @param Action $subject * @param \Closure $proceed * @param array $productIds * @param array $attrData * @param int $storeId * @return Action * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundUpdateAttributes(Action $subject, \Closure $proceed, $productIds, $attrData, $storeId) { $returnValue = $proceed($productIds, $attrData, $storeId); $this->cacheContext->registerEntities(Product::CACHE_TAG, $productIds); $this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this->cacheContext]); return $returnValue; }
/** * 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; }
public function testProcessRelations() { $this->relationProcessorMock->expects($this->once())->method('processRelation')->with($this->salesModelMock); $this->salesModelMock->expects($this->once())->method('getEventPrefix')->willReturn('sales_event_prefix'); $this->eventManagerMock->expects($this->once())->method('dispatch')->with('sales_event_prefix_process_relation', ['object' => $this->salesModelMock]); $this->entityRelationComposite->processRelations($this->salesModelMock); }
/** * Send email to customer * * @param Order $order * @param bool $notify * @param string $comment * @return bool */ public function send(Order $order, $notify = true, $comment = '') { $transport = ['order' => $order, 'comment' => $comment, 'billing' => $order->getBillingAddress(), 'store' => $order->getStore(), 'formattedShippingAddress' => $this->getFormattedShippingAddress($order), 'formattedBillingAddress' => $this->getFormattedBillingAddress($order)]; $this->eventManager->dispatch('email_order_comment_set_template_vars_before', ['sender' => $this, 'transport' => $transport]); $this->templateContainer->setTemplateVars($transport); return $this->checkAndSend($order, $notify); }
/** * Clears cache and updates translations file * * @return array */ public function updateAndGetTranslations() { $this->eventManager->dispatch('adminhtml_cache_flush_system'); $translations = $this->translateResource->getTranslationArray(null, $this->localeResolver->getLocale()); $this->fileManager->updateTranslationFileContent(json_encode($translations)); return $translations; }
/** * Reset search results * * @return $this */ public function resetSearchResults() { $connection = $this->getConnection(); $connection->update($this->getTable('search_query'), ['is_processed' => 0], ['is_processed != 0']); $this->_eventManager->dispatch('catalogsearch_reset_search_result'); return $this; }
public function testDispatchPostDispatch() { $this->_requestMock->expects($this->exactly(3))->method('getFullActionName')->will($this->returnValue(self::FULL_ACTION_NAME)); $this->_requestMock->expects($this->exactly(2))->method('getRouteName')->will($this->returnValue(self::ROUTE_NAME)); $expectedEventParameters = ['controller_action' => $this->action, 'request' => $this->_requestMock]; $this->_eventManagerMock->expects($this->at(0))->method('dispatch')->with('controller_action_predispatch', $expectedEventParameters); $this->_eventManagerMock->expects($this->at(1))->method('dispatch')->with('controller_action_predispatch_' . self::ROUTE_NAME, $expectedEventParameters); $this->_eventManagerMock->expects($this->at(2))->method('dispatch')->with('controller_action_predispatch_' . self::FULL_ACTION_NAME, $expectedEventParameters); $this->_requestMock->expects($this->once())->method('isDispatched')->will($this->returnValue(true)); $this->_actionFlagMock->expects($this->at(0))->method('get')->with('', Action::FLAG_NO_DISPATCH)->will($this->returnValue(false)); // _forward expectations $this->_requestMock->expects($this->once())->method('initForward'); $this->_requestMock->expects($this->once())->method('setParams')->with(self::$actionParams); $this->_requestMock->expects($this->once())->method('setControllerName')->with(self::CONTROLLER_NAME); $this->_requestMock->expects($this->once())->method('setModuleName')->with(self::MODULE_NAME); $this->_requestMock->expects($this->once())->method('setActionName')->with(self::ACTION_NAME); $this->_requestMock->expects($this->once())->method('setDispatched')->with(false); // _redirect expectations $this->_redirectMock->expects($this->once())->method('redirect')->with($this->_responseMock, self::FULL_ACTION_NAME, self::$actionParams); $this->_actionFlagMock->expects($this->at(1))->method('get')->with('', Action::FLAG_NO_POST_DISPATCH)->will($this->returnValue(false)); $this->_eventManagerMock->expects($this->at(3))->method('dispatch')->with('controller_action_postdispatch_' . self::FULL_ACTION_NAME, $expectedEventParameters); $this->_eventManagerMock->expects($this->at(4))->method('dispatch')->with('controller_action_postdispatch_' . self::ROUTE_NAME, $expectedEventParameters); $this->_eventManagerMock->expects($this->at(5))->method('dispatch')->with('controller_action_postdispatch', $expectedEventParameters); $this->assertEquals($this->_responseMock, $this->action->dispatch($this->_requestMock)); }
/** * Copy data from object|array to object|array containing fields from fieldset matching an aspect. * * Contents of $aspect are a field name in target object or array. * If targetField attribute is not provided - will be used the same name as in the source object or array. * * @param string $fieldset * @param string $aspect * @param array|\Magento\Framework\Object $source * @param array|\Magento\Framework\Object $target * @param string $root * @return array|\Magento\Framework\Object|null the value of $target * * @api */ public function copyFieldsetToTarget($fieldset, $aspect, $source, $target, $root = 'global') { if (!$this->_isFieldsetInputValid($source, $target)) { return null; } $fields = $this->_fieldsetConfig->getFieldset($fieldset, $root); if ($fields === null) { return $target; } $targetIsArray = is_array($target); foreach ($fields as $code => $node) { if (empty($node[$aspect])) { continue; } $value = $this->_getFieldsetFieldValue($source, $code); $targetCode = (string) $node[$aspect]; $targetCode = $targetCode == '*' ? $code : $targetCode; if ($targetIsArray) { $target[$targetCode] = $value; } else { $target->setDataUsingMethod($targetCode, $value); } } $eventName = sprintf('core_copy_fieldset_%s_%s', $fieldset, $aspect); $this->_eventManager->dispatch($eventName, ['target' => $target, 'source' => $source, 'root' => $root]); return $target; }
public function testGetHtmlTxnIdIsNull() { $this->eventManagerMock->expects($this->once())->method('dispatch'); $this->transaction->setData('txn_id', 'test'); $this->assertEquals('test', $this->transaction->getHtmlTxnId()); $this->assertEquals(null, $this->transaction->getData('html_txn_id')); }
/** * Execute full indexation * * @return void */ public function executeFull() { $this->indexBuilder->reindexFull(); $this->_eventManager->dispatch('clean_cache_by_tags', ['object' => $this]); //TODO: remove after fix fpc. MAGETWO-50668 $this->getCacheManager()->clean($this->getIdentities()); }
/** * Run application * * @return ResponseInterface */ public function launch() { $this->_state->setAreaCode('crontab'); $this->_eventManager->dispatch('default'); $this->_response->setCode(0); return $this->_response; }
/** * @param Address $object * @param array $data * @return OrderInterface */ public function convert(Address $object, $data = []) { $orderData = $this->objectCopyService->getDataFromFieldset( 'quote_convert_address', 'to_order', $object ); /** * @var $order \Magento\Sales\Model\Order */ $order = $this->orderFactory->create(); $this->dataObjectHelper->populateWithArray( $order, array_merge($orderData, $data), '\Magento\Sales\Api\Data\OrderInterface' ); $order->setStoreId($object->getQuote()->getStoreId()) ->setQuoteId($object->getQuote()->getId()) ->setIncrementId($object->getQuote()->getReservedOrderId()); $this->objectCopyService->copyFieldsetToTarget('sales_convert_quote', 'to_order', $object->getQuote(), $order); $this->eventManager->dispatch( 'sales_convert_quote_to_order', ['order' => $order, 'quote' => $object->getQuote()] ); return $order; }
/** * @return \Magento\Framework\Object */ private function getAvailableFrontendTypes() { $availableFrontendTypes = $this->objectFactory->create(); $availableFrontendTypes->setData(['values' => ['select']]); $this->eventManager->dispatch('product_suggested_attribute_frontend_type_init_after', ['types_dto' => $availableFrontendTypes]); return $availableFrontendTypes; }
/** * Reset search results * * @return $this */ public function resetSearchResults() { $adapter = $this->_getWriteAdapter(); $adapter->update($this->getTable('search_query'), ['is_processed' => 0]); $this->_eventManager->dispatch('catalogsearch_reset_search_result'); return $this; }
/** * @param DesignConfigRepository $subject * @param DesignConfigInterface $designConfig * @return DesignConfigInterface * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterDelete(DesignConfigRepository $subject, DesignConfigInterface $designConfig) { $website = in_array($designConfig->getScope(), [ScopeInterface::SCOPE_WEBSITE, ScopeInterface::SCOPE_WEBSITES]) ? $this->storeManager->getWebsite($designConfig->getScopeId()) : ''; $store = in_array($designConfig->getScope(), [ScopeInterface::SCOPE_STORE, ScopeInterface::SCOPE_STORES]) ? $this->storeManager->getStore($designConfig->getScopeId()) : ''; $this->eventManager->dispatch('admin_system_config_changed_section_design', ['website' => $website, 'store' => $store]); return $designConfig; }
/** * Process model's relations saves * * @param AbstractModel $object * @return void */ public function processRelations(AbstractModel $object) { foreach ($this->relationProcessors as $processor) { /**@var $processor RelationInterface*/ $processor->processRelation($object); } $this->eventManager->dispatch($object->getEventPrefix() . '_process_relation', ['object' => $object]); }
/** * @return $this|\Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection */ public function getProductCollection() { /** @var $reviewModel \Magento\Review\Model\Review */ $reviewModel = $this->reviewFactory->create(); $collection = $reviewModel->getProductCollection()->addStatusFilter($reviewModel->getPendingStatus())->addAttributeToSelect('name', 'inner')->setDateOrder(); $this->eventManager->dispatch('rss_catalog_review_collection_select', ['collection' => $collection]); return $collection; }
public function testAfterSaveDispatchWithStore() { $this->designConfig->expects($this->exactly(2))->method('getScope')->willReturn('store'); $this->designConfig->expects($this->once())->method('getScopeId')->willReturn(1); $this->storeManager->expects($this->once())->method('getStore')->with(1)->willReturn($this->store); $this->eventManager->expects($this->once())->method('dispatch')->with('admin_system_config_changed_section_design', ['website' => '', 'store' => $this->store]); $this->plugin->afterSave($this->repository, $this->designConfig); }
/** * @param bool $result * * @dataProvider dataProviderForTestIsAvailable */ public function testIsAvailable($result) { $storeId = 15; $this->quoteMock->expects($this->once())->method('getStoreId')->willReturn($storeId); $this->scopeConfigMock->expects($this->once())->method('getValue')->with('payment/' . Stub::STUB_CODE . '/active', ScopeInterface::SCOPE_STORE, $storeId)->willReturn($result); $this->eventManagerMock->expects($this->once())->method('dispatch')->with($this->equalTo('payment_method_is_active'), $this->countOf(3)); $this->assertEquals($result, $this->payment->isAvailable($this->quoteMock)); }
/** * Format address in a specific way * * @param DataObject $storeInfo * @param string $type * @return string */ public function format(DataObject $storeInfo, $type = 'html') { $this->eventManager->dispatch('store_address_format', ['type' => $type, 'store_info' => $storeInfo]); $address = $this->filterManager->template("{{var name}}\n{{var street_line1}}\n{{depend street_line2}}{{var street_line2}}\n{{/depend}}" . "{{var city}}, {{var region}} {{var postcode}},\n{{var country}}", ['variables' => $storeInfo->getData()]); if ($type == 'html') { $address = nl2br($address); } return $address; }
public function testUpdateAndGetTranslations() { $translations = ['phrase1' => 'translated1', 'phrase2' => 'translated2']; $this->eventManagerMock->expects($this->once())->method('dispatch'); $this->translateResourceMock->expects($this->once())->method('getTranslationArray')->willReturn($translations); $this->localeResolverMock->expects($this->once())->method('getLocale')->willReturn('en_US'); $this->fileManagerMock->expects($this->once())->method('updateTranslationFileContent'); $this->assertEquals($translations, $this->model->updateAndGetTranslations()); }
public function testAssignData() { $data = new DataObject(); $paymentInfo = $this->getMock(InfoInterface::class); $this->payment->setInfoInstance($paymentInfo); $eventData = [AbstractDataAssignObserver::METHOD_CODE => $this, AbstractDataAssignObserver::MODEL_CODE => $paymentInfo, AbstractDataAssignObserver::DATA_CODE => $data]; $this->eventManagerMock->expects(static::exactly(2))->method('dispatch')->willReturnMap([['payment_method_assign_data_' . Stub::STUB_CODE, $eventData], ['payment_method_assign_data', $eventData]]); $this->payment->assignData($data); }
/** * Format address in a specific way * * @param Address $address * @param string $type * @return string|null */ public function format(Address $address, $type) { $formatType = $this->addressConfig->getFormatByCode($type); if (!$formatType || !$formatType->getRenderer()) { return null; } $this->eventManager->dispatch('customer_address_format', ['type' => $formatType, 'address' => $address]); return $formatType->getRenderer()->renderArray($address->getData()); }
/** * Check a theme, it's assigned to any of store * * @param EventObserver $observer * @return void */ public function execute(EventObserver $observer) { $theme = $observer->getEvent()->getData('theme'); if ($theme instanceof \Magento\Framework\View\Design\ThemeInterface) { /** @var $theme \Magento\Framework\View\Design\ThemeInterface */ if ($this->themeConfig->isThemeAssignedToStore($theme)) { $this->eventDispatcher->dispatch('assigned_theme_changed', ['theme' => $theme]); } } }
/** * Prepare response object and dispatch prepare price event * Return response object * * @param \Magento\Framework\DB\Select $select * @return \Magento\Framework\Object */ protected function _dispatchPreparePriceEvent($select) { // prepare response object for event $response = new \Magento\Framework\Object(); $response->setAdditionalCalculations(array()); // prepare event arguments $eventArgs = array('select' => $select, 'table' => 'price_index', 'store_id' => $this->_storeManager->getStore()->getId(), 'response_object' => $response); $this->_eventManager->dispatch('catalog_prepare_price_select', $eventArgs); return $response; }
/** * Dispatch event "catalogrule_apply_all" and set success or error message depends on result * * @return \Magento\CatalogRule\Model\Rule\Job */ public function applyAll() { try { $this->_eventManager->dispatch('catalogrule_apply_all'); $this->setSuccess(__('The rules have been applied.')); } catch (\Magento\Framework\Model\Exception $e) { $this->setError($e->getMessage()); } return $this; }
public function testCheckThemeIsAssigned() { $themeMock = $this->getMockBuilder('Magento\\Framework\\View\\Design\\ThemeInterface')->getMockForAbstractClass(); $eventMock = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->getMock(); $eventMock->expects($this->any())->method('getData')->with('theme')->willReturn($themeMock); $observerMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock(); $observerMock->expects($this->any())->method('getEvent')->willReturn($eventMock); $this->themeConfig->expects($this->any())->method('isThemeAssignedToStore')->with($themeMock)->willReturn(true); $this->eventDispatcher->expects($this->any())->method('dispatch')->with('assigned_theme_changed', ['theme' => $themeMock]); $this->themeObserver->checkThemeIsAssigned($observerMock); }
/** * Check and clear session data if persistent session expired * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute(\Magento\Framework\Event\Observer $observer) { if (!$this->_persistentData->canProcess($observer)) { return; } if ($this->_persistentData->isEnabled() && !$this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn() && $this->_checkoutSession->getQuoteId() && !$observer->getControllerAction() instanceof \Magento\Checkout\Controller\Onepage) { $this->_eventManager->dispatch('persistent_session_expired'); $this->quoteManager->expire(); $this->_customerSession->setCustomerId(null)->setCustomerGroupId(null); } }
/** * @expectedException \Exception * @expectedExceptionMessage Expected Exception * @throws \Exception */ public function testSaveFailed() { $this->modelMock->expects($this->any())->method('getEventPrefix')->will($this->returnValue('event_prefix')); $this->modelMock->expects($this->any())->method('getEventObject')->will($this->returnValue('event_object')); $this->appResourceMock->expects($this->once())->method('getConnection')->will($this->returnValue($this->connectionMock)); $exception = new \Exception('Expected Exception'); $this->modelMock->expects($this->any())->method('getId')->will($this->throwException($exception)); $this->connectionMock->expects($this->once())->method('beginTransaction'); $this->connectionMock->expects($this->once())->method('rollback'); $this->eventManagerMock->expects($this->once())->method('dispatch')->with('event_prefix_save_attribute_before', ['event_object' => $this->attribute, 'object' => $this->modelMock, 'attribute' => ['attribute']]); $this->attribute->saveAttribute($this->modelMock, 'attribute'); }