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


PHP Event\Observer类代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: execute

 /**
  * Refresh stock index for specific stock items after successful order placement
  *
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     // Reindex quote ids
     $quote = $observer->getEvent()->getQuote();
     $productIds = [];
     foreach ($quote->getAllItems() as $item) {
         $productIds[$item->getProductId()] = $item->getProductId();
         $children = $item->getChildrenItems();
         if ($children) {
             foreach ($children as $childItem) {
                 $productIds[$childItem->getProductId()] = $childItem->getProductId();
             }
         }
     }
     if ($productIds) {
         $this->stockIndexerProcessor->reindexList($productIds);
     }
     // Reindex previously remembered items
     $productIds = [];
     foreach ($this->itemsForReindex->getItems() as $item) {
         $item->save();
         $productIds[] = $item->getProductId();
     }
     if (!empty($productIds)) {
         $this->priceIndexer->reindexList($productIds);
     }
     $this->itemsForReindex->clear();
     // Clear list of remembered items - we don't need it anymore
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:35,代码来源:ReindexQuoteInventoryObserver.php

示例5: 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

示例6: execute

 /**
  * If it's configured to capture on shipment - do this.
  *
  * @param \Magento\Framework\Event\Observer $observer
  *
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $customer = $observer->getEvent()->getCustomer();
     $email = $customer->getEmail();
     $websiteId = $customer->getWebsiteId();
     $apiEnabled = $this->helper->isEnabled($websiteId);
     $customerSync = $this->helper->isCustomerSyncEnabled($websiteId);
     /*
      * Remove contact.
      */
     if ($apiEnabled && $customerSync) {
         try {
             //register in queue with importer
             $this->importerFactory->create()->registerQueue(\Dotdigitalgroup\Email\Model\Importer::IMPORT_TYPE_CONTACT, $email, \Dotdigitalgroup\Email\Model\Importer::MODE_CONTACT_DELETE, $websiteId);
             $contactModel = $this->contactFactory->create()->loadByCustomerEmail($email, $websiteId);
             if ($contactModel->getId()) {
                 //remove contact
                 $contactModel->delete();
             }
         } catch (\Exception $e) {
             $this->helper->debug((string) $e, []);
         }
     }
     return $this;
 }
开发者ID:dotmailer,项目名称:dotmailer-magento2-extension,代码行数:32,代码来源:RemoveContact.php

示例7: execute

 public function execute(Observer $observer)
 {
     if (!$this->_api->enabled()) {
         return;
     }
     try {
         /** @var $order Order */
         $order = $observer->getEvent()->getOrder();
         // Check if a payment is available for this order yet
         if ($order->getState() == \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT) {
             return;
         }
         // Check if case already exists for this order
         if ($this->_helper->doesCaseExist($order)) {
             return;
         }
         $orderData = $this->_helper->processOrderData($order);
         // Add order to database
         $case = $this->_helper->createNewCase($order);
         // Post case to signifyd service
         $result = $this->_helper->postCaseToSignifyd($orderData, $order);
         if ($order->canHold()) {
             $order->hold()->getResource()->save($order);
         }
         if ($result) {
             $case->setCode($result);
             $case->setMagentoStatus(CaseRetry::IN_REVIEW_STATUS)->setUpdated(strftime('%Y-%m-%d %H:%M:%S', time()));
             $case->getResource()->save($case);
         }
     } catch (\Exception $ex) {
         $this->_logger->error($ex->getMessage());
     }
 }
开发者ID:signifyd,项目名称:magento2,代码行数:33,代码来源:Purchase.php

示例8: execute

 /**
  * @param \Magento\Framework\Event\Observer $observer
  * @return \Magento\Quote\Model\Quote\Item
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     /** @var  \Magento\Quote\Model\Quote\Item $item */
     $item = $observer->getEvent()->getItem();
     $item->setRowTotal($this->getRowTotal($item))->setRowTotalInclTax($this->getRowTotalInclTax($item))->setPrice($this->getUnitDisplayPriceExclTax($item))->setPriceInclTax($this->getUnitDisplayPriceInclTax($item));
     return $item;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:11,代码来源:ItemObserver.php

示例9: execute

 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $activationHelper = $this->_objectManager->get('LoginRadius\\Activation\\Model\\Helper\\Data');
     $customerRegistrationHelper = $this->_objectManager->get("LoginRadius" . "\\" . $activationHelper->getAuthDirectory() . "\\Model\\Helper\\Data");
     if ($customerRegistrationHelper->enableRaas() != '1') {
         return;
     }
     $events = $observer->getEvent();
     $customer = $events->getCustomerDataObject();
     $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#\$%^&*()_-=?";
     $birthDate = date("m-d-Y", strtotime($customer->getDob()));
     $newUserData = array('emailid' => $customer->getEmail(), 'firstname' => $customer->getFirstname(), 'lastname' => $customer->getLastname(), 'password' => substr(str_shuffle($chars), 0, 8), 'gender' => $this->getGenderValue($customer->getGender()), 'birthdate' => $birthDate);
     $userAPI = new \LoginRadiusSDK\CustomerRegistration\UserAPI($activationHelper->siteApiKey(), $activationHelper->siteApiSecret(), array('authentication' => true, 'output_format' => 'json'));
     $homeDomain = $this->_objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->getStore()->getBaseUrl();
     if (!isset($_POST['customer']['entity_id'])) {
         try {
             $userCreatedata = $userAPI->create($newUserData);
             try {
                 $rsetPasswordUrl = 'https://api.loginradius.com/raas/client/password/forgot?apikey=' . $activationHelper->siteApiKey() . '&emailid=' . $customer->getEmail() . '&resetpasswordurl=' . $homeDomain . 'customer/account/login/';
                 $result = \LoginRadiusSDK\LoginRadius::apiClient($rsetPasswordUrl, FALSE, array('output_format' => 'json'));
             } catch (\LoginRadiusSDK\LoginRadiusException $e) {
                 $errorDescription = isset($e->getErrorResponse()->description) ? $e->getErrorResponse()->description : '';
                 $this->_messageManager->addError($errorDescription);
             }
             try {
                 $this->socialLinkingData($customer->getId(), $userCreatedata);
             } catch (\Exception $e) {
             }
         } catch (\LoginRadiusSDK\LoginRadiusException $e) {
         }
         return;
     }
 }
开发者ID:LoginRadius,项目名称:magento-identity-extension,代码行数:33,代码来源:CreateUser.php

示例10: execute

 /**
  * If it's configured to capture on shipment - do this
  *
  * @param \Magento\Framework\Event\Observer $observer
  *
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $customer = $observer->getEvent()->getCustomer();
     $email = $customer->getEmail();
     $websiteId = $customer->getWebsiteId();
     $customerId = $customer->getEntityId();
     $isSubscribed = $customer->getIsSubscribed();
     try {
         // fix for a multiple hit of the observer
         $emailReg = $this->_registry->registry($email . '_customer_save');
         if ($emailReg) {
             return $this;
         }
         $this->_registry->register($email . '_customer_save', $email);
         $emailBefore = $this->_customerFactory->create()->load($customer->getId())->getEmail();
         $contactModel = $this->_contactFactory->create()->loadByCustomerEmail($emailBefore, $websiteId);
         //email change detection
         if ($email != $emailBefore) {
             $this->_helper->log('email change detected : ' . $email . ', after : ' . $emailBefore . ', website id : ' . $websiteId);
             $data = array('emailBefore' => $emailBefore, 'email' => $email, 'isSubscribed' => $isSubscribed);
             $this->_proccessor->registerQueue(\Dotdigitalgroup\Email\Model\Proccessor::IMPORT_TYPE_CONTACT_UPDATE, $data, \Dotdigitalgroup\Email\Model\Proccessor::MODE_CONTACT_EMAIL_UPDATE, $websiteId);
         } elseif (!$emailBefore) {
             //for new contacts update email
             $contactModel->setEmail($email);
         }
         $contactModel->setEmailImported(\Dotdigitalgroup\Email\Model\Contact::EMAIL_CONTACT_NOT_IMPORTED)->setCustomerId($customerId)->save();
     } catch (\Exception $e) {
         $this->_helper->debug((string) $e, array());
     }
     return $this;
 }
开发者ID:dragonsword007008,项目名称:magento2,代码行数:38,代码来源:CreateUpdateContact.php

示例11: execute

 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     // get the product object
     $_product = $observer->getProduct();
     // pass the SKU to Processwire
     $this->updateWireProduct($_product, 'On Save');
 }
开发者ID:the-big-surf,项目名称:wire-products-hook,代码行数:7,代码来源:WireProductsSaveAfter.php

示例12: execute

 /**
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute(Observer $observer)
 {
     /** @var $customer \Magento\Customer\Api\Data\CustomerInterface */
     $customer = $observer->getEvent()->getCustomer();
     // Check if customer is valid (remove persistent cookie for invalid customer)
     if (!$customer || !$customer->getId() || !$this->_persistentSession->isRememberMeChecked()) {
         $this->_sessionFactory->create()->removePersistentCookie();
         return;
     }
     $persistentLifeTime = $this->_persistentData->getLifeTime();
     // Delete persistent session, if persistent could not be applied
     if ($this->_persistentData->isEnabled() && $persistentLifeTime <= 0) {
         // Remove current customer persistent session
         $this->_sessionFactory->create()->deleteByCustomerId($customer->getId());
         return;
     }
     /** @var $sessionModel \Magento\Persistent\Model\Session */
     $sessionModel = $this->_persistentSession->getSession();
     // Check if session is wrong or not exists, so create new session
     if (!$sessionModel->getId() || $sessionModel->getCustomerId() != $customer->getId()) {
         /** @var \Magento\Persistent\Model\Session $sessionModel */
         $sessionModel = $this->_sessionFactory->create();
         $sessionModel->setLoadExpired()->loadByCustomerId($customer->getId());
         if (!$sessionModel->getId()) {
             /** @var \Magento\Persistent\Model\Session $sessionModel */
             $sessionModel = $this->_sessionFactory->create();
             $sessionModel->setCustomerId($customer->getId())->save();
         }
         $this->_persistentSession->setSession($sessionModel);
     }
     // Set new cookie
     if ($sessionModel->getId()) {
         $sessionModel->setPersistentCookie($persistentLifeTime, $this->_customerSession->getCookiePath());
     }
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:40,代码来源:SynchronizePersistentOnLoginObserver.php

示例13: execute

 /**
  * Apply catalog price rules to product in admin
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $product = $observer->getEvent()->getProduct();
     $storeId = $product->getStoreId();
     $date = $this->localeDate->scopeDate($storeId);
     $key = false;
     $ruleData = $this->coreRegistry->registry('rule_data');
     if ($ruleData) {
         $wId = $ruleData->getWebsiteId();
         $gId = $ruleData->getCustomerGroupId();
         $pId = $product->getId();
         $key = "{$date->format('Y-m-d H:i:s')}|{$wId}|{$gId}|{$pId}";
     } elseif ($product->getWebsiteId() !== null && $product->getCustomerGroupId() !== null) {
         $wId = $product->getWebsiteId();
         $gId = $product->getCustomerGroupId();
         $pId = $product->getId();
         $key = "{$date->format('Y-m-d H:i:s')}|{$wId}|{$gId}|{$pId}";
     }
     if ($key) {
         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,代码行数:36,代码来源:ProcessAdminFinalPriceObserver.php

示例14: execute

 /**
  * Unlock customer on success login attempt.
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     /** @var \Magento\Customer\Model\Customer $customer */
     $customer = $observer->getEvent()->getData('model');
     $this->authentication->unlock($customer->getId());
     return $this;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:12,代码来源:CustomerLoginSuccessObserver.php

示例15: execute

 /**
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     /** @var \Magento\Sales\Model\Order\Payment $orderPayment */
     $orderPayment = $observer->getEvent()->getPayment();
     $agreementCreated = false;
     if ($orderPayment->getBillingAgreementData()) {
         $order = $orderPayment->getOrder();
         /** @var \Magento\Paypal\Model\Billing\Agreement $agreement */
         $agreement = $this->agreementFactory->create()->importOrderPayment($orderPayment);
         if ($agreement->isValid()) {
             $message = __('Created billing agreement #%1.', $agreement->getReferenceId());
             $order->addRelatedObject($agreement);
             $agreement->addOrderRelation($order);
             $this->checkoutSession->setLastBillingAgreementReferenceId($agreement->getReferenceId());
             $agreementCreated = true;
         } else {
             $message = __('We can\'t create a billing agreement for this order.');
         }
         $comment = $order->addStatusHistoryComment($message);
         $order->addRelatedObject($comment);
     }
     if (!$agreementCreated) {
         $this->checkoutSession->unsLastBillingAgreementReferenceId();
     }
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:29,代码来源:AddBillingAgreementToSessionObserver.php


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