/**
  * 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;
 }
Example #2
0
 /**
  * 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;
 }
Example #3
0
    /**
     * @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;

    }
 /**
  * @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;
 }
Example #5
0
 /**
  * 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;
 }
Example #6
0
 /**
  * @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;
 }
Example #7
0
 /**
  * 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;
 }
 /**
  * @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;
 }
Example #9
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;
 }
 /**
  * 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);
 }
Example #11
0
 /**
  * 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;
 }
Example #12
0
 /**
  * Run application
  *
  * @return ResponseInterface
  */
 public function launch()
 {
     $this->_state->setAreaCode('crontab');
     $this->_eventManager->dispatch('default');
     $this->_response->setCode(0);
     return $this->_response;
 }
Example #13
0
 /**
  * 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());
 }
 /**
  * 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]);
 }
Example #15
0
 /**
  * @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;
 }
Example #16
0
 /**
  * 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;
 }
Example #17
0
 /**
  * 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());
 }
Example #18
0
 /**
  * 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;
 }
 /**
  * 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]);
         }
     }
 }
Example #20
0
 /**
  * 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;
 }
 /**
  * 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);
     }
 }
 /**
  * @return \Magento\Catalog\Model\ResourceModel\Product\Collection
  */
 public function getProductsCollection()
 {
     /* @var $product \Magento\Catalog\Model\Product */
     $product = $this->productFactory->create();
     /* @var $collection \Magento\Catalog\Model\ResourceModel\Product\Collection */
     $collection = $product->getCollection();
     /** @var $resourceStock \Magento\CatalogInventory\Model\ResourceModel\Stock */
     $resourceStock = $this->stockFactory->create();
     $resourceStock->addLowStockFilter($collection, ['qty', 'notify_stock_qty', 'low_stock_date', 'use_config' => 'use_config_notify_stock_qty']);
     $collection->addAttributeToSelect('name', true)->addAttributeToFilter('status', ['in' => $this->productStatus->getVisibleStatusIds()])->setOrder('low_stock_date');
     $this->eventManager->dispatch('rss_catalog_notify_stock_collection_select', ['collection' => $collection]);
     return $collection;
 }
Example #23
0
 /**
  * Send email to customer
  *
  * @param Order $order
  * @param bool $notify
  * @param string $comment
  * @return bool
  */
 public function send(Order $order, $notify = true, $comment = '')
 {
     if ($order->getShippingAddress()) {
         $formattedShippingAddress = $this->addressRenderer->format($order->getShippingAddress(), 'html');
     } else {
         $formattedShippingAddress = '';
     }
     $formattedBillingAddress = $this->addressRenderer->format($order->getBillingAddress(), 'html');
     $transport = new \Magento\Framework\Object(['template_vars' => ['order' => $order, 'comment' => $comment, 'billing' => $order->getBillingAddress(), 'store' => $order->getStore(), 'formattedShippingAddress' => $formattedShippingAddress, 'formattedBillingAddress' => $formattedBillingAddress]]);
     $this->eventManager->dispatch('email_order_comment_set_template_vars_before', ['sender' => $this, 'transport' => $transport]);
     $this->templateContainer->setTemplateVars($transport->getTemplateVars());
     return $this->checkAndSend($order, $notify);
 }
Example #24
0
 /**
  * {@inheritdoc}
  */
 public function match(RequestInterface $request)
 {
     /** @var \Magento\Framework\App\Request\Http $request */
     $identifier = trim($request->getPathInfo(), '/');
     $this->eventManager->dispatch('core_controller_router_match_before', ['router' => $this, 'condition' => new DataObject(['identifier' => $identifier, 'continue' => true])]);
     $pathInfo = $request->getPathInfo();
     $result = $this->url->match($pathInfo);
     if ($result) {
         $params = $result->getParams();
         $request->setModuleName($result->getModuleName())->setControllerName($result->getControllerName())->setActionName($result->getActionName())->setParams($params);
         return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]);
     }
     return false;
 }
Example #25
0
 /**
  * Retrieve searchable attributes
  *
  * @param string $backendType
  * @return \Magento\Eav\Model\Entity\Attribute[]
  */
 protected function getSearchableAttributes($backendType = null)
 {
     if (null === $this->searchableAttributes) {
         $this->searchableAttributes = [];
         $productAttributes = $this->productAttributeCollectionFactory->create();
         $productAttributes->addToIndexFilter(true);
         /** @var \Magento\Eav\Model\Entity\Attribute[] $attributes */
         $attributes = $productAttributes->getItems();
         $this->eventManager->dispatch('catelogsearch_searchable_attributes_load_after', ['engine' => $this->engineProvider->get(), 'attributes' => $attributes]);
         $entity = $this->getEavConfig()->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getEntity();
         foreach ($attributes as $attribute) {
             $attribute->setEntity($entity);
         }
         $this->searchableAttributes = $attributes;
     }
     if ($backendType !== null) {
         $attributes = [];
         foreach ($this->searchableAttributes as $attributeId => $attribute) {
             if ($attribute->getBackendType() == $backendType) {
                 $attributes[$attributeId] = $attribute;
             }
         }
         return $attributes;
     }
     return $this->searchableAttributes;
 }
Example #26
0
 /**
  * Validate and Match Cms Page and modify request
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @return bool
  *
  * @SuppressWarnings(PHPMD.ExitExpression)
  */
 public function match(\Magento\Framework\App\RequestInterface $request)
 {
     if (!$this->_appState->isInstalled()) {
         $this->_response->setRedirect($this->_url->getUrl('install'))->sendResponse();
         exit;
     }
     $identifier = trim($request->getPathInfo(), '/');
     $condition = new \Magento\Framework\Object(array('identifier' => $identifier, 'continue' => true));
     $this->_eventManager->dispatch('cms_controller_router_match_before', array('router' => $this, 'condition' => $condition));
     $identifier = $condition->getIdentifier();
     if ($condition->getRedirectUrl()) {
         $this->_response->setRedirect($condition->getRedirectUrl());
         $request->setDispatched(true);
         return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Redirect', array('request' => $request));
     }
     if (!$condition->getContinue()) {
         return null;
     }
     /** @var \Magento\Cms\Model\Page $page */
     $page = $this->_pageFactory->create();
     $pageId = $page->checkIdentifier($identifier, $this->_storeManager->getStore()->getId());
     if (!$pageId) {
         return null;
     }
     $request->setModuleName('cms')->setControllerName('page')->setActionName('view')->setParam('page_id', $pageId);
     $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $identifier);
     return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', array('request' => $request));
 }
 /**
  * Dispatch "after" load method events
  *
  * @return void
  */
 protected function afterLoad()
 {
     $this->eventManager->dispatch('abstract_search_result_load_after', ['collection' => $this]);
     if ($this->eventPrefix && $this->eventObject) {
         $this->eventManager->dispatch($this->eventPrefix . '_load_after', [$this->eventObject => $this]);
     }
 }
Example #28
0
 /**
  * Prepare email template with variables
  *
  * @param Order $order
  * @return void
  */
 protected function prepareTemplate(Order $order)
 {
     $transport = new \Magento\Framework\Object(['template_vars' => ['order' => $order, 'billing' => $order->getBillingAddress(), 'payment_html' => $this->getPaymentHtml($order), 'store' => $order->getStore(), 'formattedShippingAddress' => $this->addressRenderer->format($order->getShippingAddress(), 'html'), 'formattedBillingAddress' => $this->addressRenderer->format($order->getBillingAddress(), 'html')]]);
     $this->eventManager->dispatch('email_order_set_template_vars_before', ['sender' => $this, 'transport' => $transport]);
     $this->templateContainer->setTemplateVars($transport->getTemplateVars());
     parent::prepareTemplate($order);
 }
Example #29
0
 /**
  * Fire event to allow overwriting of discount amounts
  *
  * @param \Magento\SalesRule\Model\Rule\Action\Discount\Data $discountData
  * @param \Magento\Quote\Model\Quote\Item\AbstractItem $item
  * @param \Magento\SalesRule\Model\Rule $rule
  * @param float $qty
  * @return $this
  */
 protected function eventFix(\Magento\SalesRule\Model\Rule\Action\Discount\Data $discountData, \Magento\Quote\Model\Quote\Item\AbstractItem $item, \Magento\SalesRule\Model\Rule $rule, $qty)
 {
     $quote = $item->getQuote();
     $address = $item->getAddress();
     $this->_eventManager->dispatch('salesrule_validator_process', ['rule' => $rule, 'item' => $item, 'address' => $address, 'quote' => $quote, 'qty' => $qty, 'result' => $discountData]);
     return $this;
 }
Example #30
0
 /**
  * Adding new message to message collection
  *
  * @param MessageInterface $message
  * @param string|null $group
  * @return $this
  */
 public function addMessage(MessageInterface $message, $group = null)
 {
     $this->hasMessages = true;
     $this->getMessages(false, $group)->addMessage($message);
     $this->eventManager->dispatch('session_abstract_add_message');
     return $this;
 }