当前位置: 首页>>代码示例>>PHP>>正文


PHP Observer::getEvent方法代码示例

本文整理汇总了PHP中Magento\Framework\Event\Observer::getEvent方法的典型用法代码示例。如果您正苦于以下问题:PHP Observer::getEvent方法的具体用法?PHP Observer::getEvent怎么用?PHP Observer::getEvent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\Event\Observer的用法示例。


在下文中一共展示了Observer::getEvent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 /**
  * Process shipping method and save
  *
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     if ($this->shipperDataHelper->getConfigValue('carriers/shipper/active')) {
         $request = $observer->getEvent()->getRequest();
         $shippingMethods = $request->getPost('shipping_method', '');
         if (!is_array($shippingMethods)) {
             return;
         }
         foreach ($shippingMethods as $addressId => $shippingMethod) {
             if (empty($shippingMethod)) {
                 return;
             }
             $quote = $observer->getEvent()->getQuote();
             $addresses = $quote->getAllShippingAddresses();
             $shippingAddress = false;
             foreach ($addresses as $address) {
                 if ($address->getId() == $addressId) {
                     $shippingAddress = $address;
                     break;
                 }
             }
             $this->carrierGroupHelper->saveCarrierGroupInformation($shippingAddress, $shippingMethod);
         }
     }
 }
开发者ID:shipperhq,项目名称:module-shipper,代码行数:31,代码来源:SaveShippingMulti.php

示例2: execute

 /**
  * Check move quote item to wishlist request
  *
  * @param   Observer $observer
  * @return  $this
  */
 public function execute(Observer $observer)
 {
     $cart = $observer->getEvent()->getCart();
     $data = $observer->getEvent()->getInfo()->toArray();
     $this->_logger->log(null, $data);
     return $this;
 }
开发者ID:magento-hackathon,项目名称:Hackathon_OrderItemComments,代码行数:13,代码来源:SaveComments.php

示例3: testSetEvent

 public function testSetEvent()
 {
     $event = 'someEvent';
     $this->observer->setEvent($event);
     $result = $this->observer->getData('event');
     $this->assertEquals($result, $this->observer->getEvent($event));
 }
开发者ID:,项目名称:,代码行数:7,代码来源:

示例4: dispatch

 /**
  * Set new customer group to all his quotes
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function dispatch(\Magento\Framework\Event\Observer $observer)
 {
     /** @var CustomerData $customerDataObject */
     $customerDataObject = $observer->getEvent()->getCustomerDataObject();
     /** @var CustomerData $origCustomerDataObject */
     $origCustomerDataObject = $observer->getEvent()->getOrigCustomerDataObject();
     if ($customerDataObject->getGroupId() !== $origCustomerDataObject->getGroupId()) {
         /**
          * It is needed to process customer's quotes for all websites
          * if customer accounts are shared between all of them
          */
         /** @var $websites \Magento\Store\Model\Website[] */
         $websites = $this->_config->isWebsiteScope() ? array($this->_storeManager->getWebsite($customerDataObject->getWebsiteId())) : $this->_storeManager->getWebsites();
         foreach ($websites as $website) {
             $quote = $this->_quoteFactory->create();
             $quote->setWebsite($website);
             $quote->loadByCustomer($customerDataObject->getId());
             if ($quote->getId()) {
                 $quote->setCustomerGroupId($customerDataObject->getGroupId());
                 $quote->collectTotals();
                 $quote->save();
             }
         }
     }
 }
开发者ID:aiesh,项目名称:magento2,代码行数:31,代码来源:CustomerQuote.php

示例5: execute

 /**
  * Apply catalog price rules to product on frontend
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $product = $observer->getEvent()->getProduct();
     $pId = $product->getId();
     $storeId = $product->getStoreId();
     if ($observer->hasDate()) {
         $date = new \DateTime($observer->getEvent()->getDate());
     } else {
         $date = $this->localeDate->scopeDate($storeId);
     }
     if ($observer->hasWebsiteId()) {
         $wId = $observer->getEvent()->getWebsiteId();
     } else {
         $wId = $this->storeManager->getStore($storeId)->getWebsiteId();
     }
     if ($observer->hasCustomerGroupId()) {
         $gId = $observer->getEvent()->getCustomerGroupId();
     } elseif ($product->hasCustomerGroupId()) {
         $gId = $product->getCustomerGroupId();
     } else {
         $gId = $this->customerSession->getCustomerGroupId();
     }
     $key = "{$date->format('Y-m-d H:i:s')}|{$wId}|{$gId}|{$pId}";
     if (!$this->rulePricesStorage->hasRulePrice($key)) {
         $rulePrice = $this->resourceRuleFactory->create()->getRulePrice($date, $wId, $gId, $pId);
         $this->rulePricesStorage->setRulePrice($key, $rulePrice);
     }
     if ($this->rulePricesStorage->getRulePrice($key) !== false) {
         $finalPrice = min($product->getData('final_price'), $this->rulePricesStorage->getRulePrice($key));
         $product->setFinalPrice($finalPrice);
     }
     return $this;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:39,代码来源:ProcessFrontFinalPriceObserver.php

示例6: execute

 /**
  * Checking whether the using static urls in WYSIWYG allowed event
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $block = $observer->getEvent()->getBlock();
     $menuRootNode = $observer->getEvent()->getMenu();
     $block->addIdentity(Category::CACHE_TAG);
     $rootId = $this->storeManager->getStore()->getRootCategoryId();
     $storeId = $this->storeManager->getStore()->getId();
     /** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $collection */
     $collection = $this->getCategoryTree($storeId, $rootId);
     $currentCategory = $this->getCurrentCategory();
     $mapping = [$rootId => $menuRootNode];
     // use nodes stack to avoid recursion
     foreach ($collection as $category) {
         if (!isset($mapping[$category->getParentId()])) {
             continue;
         }
         /** @var Node $parentCategoryNode */
         $parentCategoryNode = $mapping[$category->getParentId()];
         $categoryNode = new Node($this->getCategoryAsArray($category, $currentCategory), 'id', $parentCategoryNode->getTree(), $parentCategoryNode);
         $parentCategoryNode->addChild($categoryNode);
         $mapping[$category->getId()] = $categoryNode;
         //add node in stack
         $block->addIdentity(Category::CACHE_TAG . '_' . $category->getId());
     }
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:31,代码来源:AddCatalogToTopmenuItemsObserver.php

示例7: execute

 /**
  * Just some test code to log customer email on login
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return self
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $password = $observer->getEvent()->getPassword();
     $customer = $observer->getEvent()->getModel();
     $this->logger->debug('Foggyline\\Office: ' . $customer->getEmail() . ' Password: ' . $password);
     return $this;
 }
开发者ID:ksz2013,项目名称:m2-foggyline-office,代码行数:13,代码来源:LogCustomerEmail.php

示例8: execute

 /**
  * Generate options for currency displaying with custom currency symbol
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $baseCode = $observer->getEvent()->getBaseCode();
     $currencyOptions = $observer->getEvent()->getCurrencyOptions();
     $currencyOptions->setData($this->getCurrencyOptions($baseCode));
     return $this;
 }
开发者ID:IlyaGluschenko,项目名称:test001,代码行数:13,代码来源:CurrencyDisplayOptions.php

示例9: dispatch

 /**
  * Set new customer group to all his quotes
  *
  * @param Observer $observer
  * @return void
  */
 public function dispatch(Observer $observer)
 {
     /** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
     $customer = $observer->getEvent()->getCustomerDataObject();
     /** @var \Magento\Customer\Api\Data\CustomerInterface $origCustomer */
     $origCustomer = $observer->getEvent()->getOrigCustomerDataObject();
     if ($customer->getGroupId() !== $origCustomer->getGroupId()) {
         /**
          * It is needed to process customer's quotes for all websites
          * if customer accounts are shared between all of them
          */
         /** @var $websites \Magento\Store\Model\Website[] */
         $websites = $this->config->isWebsiteScope() ? [$this->storeManager->getWebsite($customer->getWebsiteId())] : $this->storeManager->getWebsites();
         foreach ($websites as $website) {
             try {
                 $quote = $this->quoteRepository->getForCustomer($customer->getId());
                 $quote->setWebsite($website);
                 $quote->setCustomerGroupId($customer->getGroupId());
                 $quote->collectTotals();
                 $this->quoteRepository->save($quote);
             } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
             }
         }
     }
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:31,代码来源:CustomerQuote.php

示例10: execute

 /**
  * Check move quote item to wishlist request
  *
  * @param   Observer $observer
  * @return  $this
  */
 public function execute(Observer $observer)
 {
     $cart = $observer->getEvent()->getCart();
     $data = $observer->getEvent()->getInfo()->toArray();
     $productIds = [];
     $wishlist = $this->getWishlist($cart->getQuote()->getCustomerId());
     if (!$wishlist) {
         return $this;
     }
     /**
      * Collect product ids marked for move to wishlist
      */
     foreach ($data as $itemId => $itemInfo) {
         if (!empty($itemInfo['wishlist']) && ($item = $cart->getQuote()->getItemById($itemId))) {
             $productId = $item->getProductId();
             $buyRequest = $item->getBuyRequest();
             if (array_key_exists('qty', $itemInfo) && is_numeric($itemInfo['qty'])) {
                 $buyRequest->setQty($itemInfo['qty']);
             }
             $wishlist->addNewItem($productId, $buyRequest);
             $productIds[] = $productId;
             $cart->getQuote()->removeItem($itemId);
         }
     }
     if (count($productIds)) {
         $wishlist->save();
         $this->wishlistData->calculate();
     }
     return $this;
 }
开发者ID:IlyaGluschenko,项目名称:protection,代码行数:36,代码来源:CartUpdateBefore.php

示例11: execute

 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     try {
         if (!$this->_registry->registry('core_config_data_save_after_done')) {
             if ($groups = $observer->getEvent()->getConfigData()->getGroups()) {
                 if (isset($groups['catalog_sync']['fields']['catalog_values']['value'])) {
                     $configAfter = $groups['catalog_sync']['fields']['catalog_values']['value'];
                     $configBefore = $this->_registry->registry('core_config_data_save_before');
                     if ($configAfter != $configBefore) {
                         //reset catalog to re-import
                         $this->_connectorCatalogFactory->create()->reset();
                     }
                     $this->_registry->register('core_config_data_save_after_done', true);
                 }
             }
         }
         if (!$this->_registry->registry('core_config_data_save_after_done_status')) {
             if ($groups = $observer->getEvent()->getConfigData()->getGroups()) {
                 if (isset($groups['data_fields']['fields']['order_statuses']['value'])) {
                     $configAfter = $groups['data_fields']['fields']['order_statuses']['value'];
                     $configBefore = $this->_registry->registry('core_config_data_save_before_status');
                     if ($configAfter != $configBefore) {
                         //reset all contacts
                         $this->_connectorContactFactory->create()->resetAllContacts();
                     }
                     $this->_registry->register('core_config_data_save_after_done_status', true);
                 }
             }
         }
     } catch (\Exception $e) {
         $this->_helper->debug((string) $e, array());
     }
     return $this;
 }
开发者ID:dragonsword007008,项目名称:magento2,代码行数:34,代码来源:ResetCatalogContactImport.php

示例12: currencyDisplayOptions

 /**
  * Generate options for currency displaying with custom currency symbol
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function currencyDisplayOptions(\Magento\Framework\Event\Observer $observer)
 {
     $baseCode = $observer->getEvent()->getBaseCode();
     $currencyOptions = $observer->getEvent()->getCurrencyOptions();
     $currencyOptions->setData($this->_currencySymbolData->getCurrencyOptions($baseCode));
     return $this;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:13,代码来源:Observer.php

示例13: execute

 public function execute(\Magento\Framework\Event\Observer $eventObserver)
 {
     // event dispatched for ALL rendered magento blocks, so we need to skip unnecessary blocks ASAP
     if (!$eventObserver->getEvent()->getBlock() instanceof \Magento\Shipping\Block\Adminhtml\Create && !$eventObserver->getEvent()->getBlock() instanceof \Magento\Shipping\Block\Adminhtml\View) {
         return;
     }
     parent::execute($eventObserver);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:8,代码来源:Before.php

示例14: execute

 /**
  * Set recurring payment renderer
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute($observer)
 {
     $form = $observer->getEvent()->getForm();
     $recurringPaymentElement = $form->getElement('recurring_payment');
     $recurringPaymentBlock = $observer->getEvent()->getLayout()->createBlock('Magento\\RecurringPayment\\Block\\Adminhtml\\Product\\Edit\\Tab\\Price\\Recurring');
     if ($recurringPaymentElement) {
         $recurringPaymentElement->setRenderer($recurringPaymentBlock);
     }
 }
开发者ID:zhangjiachao,项目名称:magento2,代码行数:15,代码来源:SetFormRecurringElementRenderer.php

示例15: execute

 /**
  * Block admin ability to use customer billing agreements
  *
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     $event = $observer->getEvent();
     $methodInstance = $event->getMethodInstance();
     if ($methodInstance instanceof \Magento\Paypal\Model\Payment\Method\Billing\AbstractAgreement && false == $this->_authorization->isAllowed('Magento_Paypal::use')) {
         /** @var \Magento\Framework\DataObject $result */
         $result = $observer->getEvent()->getResult();
         $result->setData('is_available', false);
     }
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:16,代码来源:RestrictAdminBillingAgreementUsageObserver.php


注:本文中的Magento\Framework\Event\Observer::getEvent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。