當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。