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


PHP Observer::getOrder方法代码示例

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


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

示例1: getRegName

 protected function getRegName(\Magento\Framework\Event\Observer $observer)
 {
     $id = $observer->getOrder()->getIncrementId();
     if ($id) {
         $regName = 'komfortkasse_order_status_' . $id;
         return $regName;
     }
 }
开发者ID:ltckomfortkasse,项目名称:komfortkasse-magento2,代码行数:8,代码来源:AbstractRegObserver.php

示例2: execute

 /**
  * If AvaTax GetTaxRequest failed and if configuration is set to prevent checkout, throw exception
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  * @throws LocalizedException
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     /** @var \Magento\Sales\Api\Data\OrderInterface $order */
     $order = $observer->getOrder();
     if ($this->coreRegistry->registry(Tax::AVATAX_GET_TAX_REQUEST_ERROR)) {
         $errorMessage = $this->config->getErrorActionDisableCheckoutMessage($order->getStoreId());
         throw new LocalizedException($errorMessage);
     }
     return $this;
 }
开发者ID:classyllama,项目名称:ClassyLlama_AvaTax,代码行数:17,代码来源:PreventOrderPlaceObserver.php

示例3: execute

 /**
  * Set payment fee to order
  *
  * @param EventObserver $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $quote = $observer->getQuote();
     $CustomFeeFee = $quote->getFee();
     $CustomFeeBaseFee = $quote->getBaseFee();
     if (!$CustomFeeFee || !$CustomFeeBaseFee) {
         return $this;
     }
     //Set fee data to order
     $order = $observer->getOrder();
     $order->setData('fee', $CustomFeeFee);
     $order->setData('base_fee', $CustomFeeBaseFee);
     return $this;
 }
开发者ID:sivajik34,项目名称:Custom-Fee-Magento2,代码行数:20,代码来源:AddFeeToOrderObserver.php

示例4: execute

 /**
  * Add VAT validation request date and identifier to order comments
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     /** @var $orderInstance \Magento\Sales\Model\Order */
     $orderInstance = $observer->getOrder();
     /** @var $orderAddress \Magento\Sales\Model\Order\Address */
     $orderAddress = $this->_getVatRequiredSalesAddress($orderInstance);
     if (!$orderAddress instanceof \Magento\Sales\Model\Order\Address) {
         return;
     }
     $vatRequestId = $orderAddress->getVatRequestId();
     $vatRequestDate = $orderAddress->getVatRequestDate();
     if (is_string($vatRequestId) && !empty($vatRequestId) && is_string($vatRequestDate) && !empty($vatRequestDate)) {
         $orderHistoryComment = __('VAT Request Identifier') . ': ' . $vatRequestId . '<br />' . __('VAT Request Date') . ': ' . $vatRequestDate;
         $orderInstance->addStatusHistoryComment($orderHistoryComment, false);
     }
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:22,代码来源:AddVatRequestParamsOrderComment.php

示例5: execute

 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $order = $observer->getOrder();
     if (!$order) {
         return;
     }
     if ($order->dataHasChangedFor('state')) {
         try {
             $this->_orderApi->post($order, Api::ACTION_UPDATE);
         } catch (\Exception $e) {
             $this->_logger->critical($e);
         }
     } else {
         $this->_logger->debug(__("No data found"));
     }
 }
开发者ID:Riskified,项目名称:magento2,代码行数:16,代码来源:OrderPlacedAfter.php

示例6: execute

 /**
  * Add coupon's rule name to order data
  *
  * @param EventObserver $observer
  * @return $this
  */
 public function execute(EventObserver $observer)
 {
     $order = $observer->getOrder();
     $couponCode = $order->getCouponCode();
     if (empty($couponCode)) {
         return $this;
     }
     $this->_coupon->loadByCode($couponCode);
     $ruleId = $this->_coupon->getRuleId();
     if (empty($ruleId)) {
         return $this;
     }
     /** @var \Magento\SalesRule\Model\Rule $rule */
     $rule = $this->_ruleFactory->create()->load($ruleId);
     $order->setCouponRuleName($rule->getName());
     return $this;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:23,代码来源:AddSalesRuleNameToOrderObserver.php

示例7: execute

 /**
  * Add subtotals to order data
  *
  * @param EventObserver $observer
  * @return $this
  */
 public function execute(EventObserver $observer)
 {
     $order = $observer->getOrder();
     $quote = $observer->getQuote();
     $discountCoupon = $quote->getShippingAddress()->getDiscountCouponAmount();
     $baseDiscountCoupon = $quote->getShippingAddress()->getBaseDiscountCouponAmount();
     $financeCost = $quote->getShippingAddress()->getFinanceCostAmount();
     $baseFinanceCost = $quote->getShippingAddress()->getBaseFinanceCostAmount();
     if (!empty($discountCoupon)) {
         $order->setDiscountCouponAmount($discountCoupon);
         $order->setBaseDiscountCouponAmount($baseDiscountCoupon);
     }
     if (!empty($financeCost)) {
         $order->setFinanceCostAmount($financeCost);
         $order->setBaseFinanceCostAmount($baseFinanceCost);
     }
     return $this;
 }
开发者ID:SummaSolutions,项目名称:cart-magento2,代码行数:24,代码来源:AddMpSubtotalsToOrderObserver.php

示例8: execute

 /**
  * Converting order will remove the email quote.
  *
  * @param \Magento\Framework\Event\Observer $observer
  *
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     try {
         $order = $observer->getOrder();
         $websiteId = $order->getStore()->getWebsiteId();
         $apiEnabled = $this->_helper->isEnabled($websiteId);
         $syncEnabled = $this->_helper->getWebsiteConfig(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_SYNC_QUOTE_ENABLED, $websiteId);
         if ($apiEnabled && $syncEnabled) {
             $quoteId = $order->getQuoteId();
             $connectorQuote = $this->_quoteFactory->create()->loadQuote($quoteId);
             if ($connectorQuote) {
                 //register in queue with importer for single delete
                 $this->_proccessorFactory->create()->registerQueue(\Dotdigitalgroup\Email\Model\Proccessor::IMPORT_TYPE_QUOTE, array($connectorQuote->getQuoteId()), \Dotdigitalgroup\Email\Model\Proccessor::MODE_SINGLE_DELETE, $order->getStore()->getWebsiteId());
                 //delete from table
                 $connectorQuote->delete();
             }
         }
     } catch (\Exception $e) {
         $this->_helper->debug((string) $e, array());
     }
     return $this;
 }
开发者ID:ThomasNegeli,项目名称:dotmailer-magento2-extension,代码行数:29,代码来源:ConvertOrderRemoveQuote.php

示例9: execute

 /**
  * Updates configuration values based every time MercadoPago configuration section is saved
  * @param \Magento\Framework\Event\Observer $observer
  *
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $order = $observer->getOrder();
     $method = $order->getShippingMethod();
     $shippingCost = $order->getBaseShippingAmount();
     $paramsME = [];
     if ($this->shipmentCarrierHelper->isMercadoEnviosMethod($method)) {
         $shippingAddress = $order->getShippingAddress();
         $zipCode = $shippingAddress->getPostcode();
         $defaultShippingId = substr($method, strpos($method, '_') + 1);
         $paramsME = ['mode' => 'me2', 'zip_code' => $zipCode, 'default_shipping_method' => intval($defaultShippingId), 'dimensions' => $this->shipmentCarrierHelper->getDimensions($this->shipmentCarrierHelper->getAllItems($order->getAllItems()))];
         if ($shippingCost == 0) {
             $paramsME['free_methods'] = [['id' => intval($defaultShippingId)]];
         }
     }
     if (!empty($shippingCost)) {
         $paramsME['cost'] = (double) $order->getBaseShippingAmount();
     }
     $observer->getParams()->setParams($paramsME);
     $this->shipmentCarrierHelper->log('REQUEST SHIPMENT ME: ', $paramsME);
     return $observer;
 }
开发者ID:SummaSolutions,项目名称:cart-magento2,代码行数:28,代码来源:ShipmentParams.php

示例10: execute

 /**
  * Event handler for the "catalog_product_save_after" and  event.
  * Sends a product update API call to Nosto.
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if ($this->_moduleManager->isEnabled('Nosto_Tagging')) {
         /* @var Order $order */
         $order = $observer->getOrder();
         $nostoOrder = $this->_orderBuilder->build($order);
         $nostoAccount = $this->_accountHelper->findAccount($this->_storeManager->getStore());
         if ($nostoAccount !== null) {
             $quoteId = $order->getQuoteId();
             $nostoCustomer = $this->_customerFactory->create()->load($quoteId, NostoCustomer::QUOTE_ID);
             $orderService = new \NostoServiceOrder($nostoAccount);
             try {
                 $orderService->confirm($nostoOrder, $nostoCustomer->getNostoId());
             } catch (\Exception $e) {
                 $this->_logger->error(sprintf("Failed to save order with qoute #%s for customer #%s.\n                        Message was: %s", $quoteId, $nostoCustomer->getNostoId(), $e->getMessage()));
             }
         }
     }
 }
开发者ID:Nosto,项目名称:nosto-magento2,代码行数:26,代码来源:Save.php

示例11: execute

 /**
  * Observer handler
  * @param \Magento\Framework\Event\Observer $observer
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $order = $observer->getOrder();
     $riskifiedStatus = (string) $observer->getStatus();
     $riskifiedOldStatus = (string) $observer->getOldStatus();
     $description = (string) $observer->getDescription();
     $newState = $newStatus = null;
     $currentState = $order->getState();
     $currentStatus = $order->getStatus();
     $this->logger->log("Checking if should update order '" . $order->getId() . "' from state: '{$currentState}' and status: '{$currentStatus}'");
     $this->logger->log("Data received from riskified: status: " . $riskifiedStatus . ", old_status: " . $riskifiedOldStatus . ", description: " . $description);
     $this->logger->log("On Hold Status Code : " . $this->apiOrderConfig->getOnHoldStatusCode() . " and Transport Error Status Code : " . $this->apiOrderConfig->getTransportErrorStatusCode());
     switch ($riskifiedStatus) {
         case 'approved':
             if ($currentState == Order::STATE_HOLDED && ($currentStatus == $this->apiOrderConfig->getOnHoldStatusCode() || $currentStatus == $this->apiOrderConfig->getTransportErrorStatusCode())) {
                 $newState = $this->apiOrderConfig->getSelectedApprovedState();
                 $newStatus = $this->apiOrderConfig->getSelectedApprovedStatus();
             }
             break;
         case 'declined':
             if ($currentState == Order::STATE_HOLDED && ($currentStatus == $this->apiOrderConfig->getOnHoldStatusCode() || $currentStatus == $this->apiOrderConfig->getTransportErrorStatusCode())) {
                 $newState = $this->apiOrderConfig->getSelectedDeclinedState();
                 $newStatus = $this->apiOrderConfig->getSelectedDeclinedStatus();
             }
             break;
         case 'submitted':
             if ($currentState == Order::STATE_PROCESSING || $currentState == Order::STATE_HOLDED && $currentStatus == $this->apiOrderConfig->getTransportErrorStatusCode()) {
                 $newState = Order::STATE_HOLDED;
                 $newStatus = $this->apiOrderConfig->getOnHoldStatusCode();
             }
             break;
         case 'error':
             if ($currentState == Order::STATE_PROCESSING && $this->apiConfig->isAutoInvoiceEnabled()) {
                 $newState = Order::STATE_HOLDED;
                 $newStatus = $this->apiOrderConfig->getTransportErrorStatusCode();
             }
     }
     $changed = false;
     if ($newState && ($newState != $currentState || $newStatus != $currentStatus) && $this->apiConfig->getConfigStatusControlActive()) {
         if ($newState == Order::STATE_CANCELED) {
             $this->logger->log("Order '" . $order->getId() . "' should be canceled - calling cancel method");
             $order->cancel();
             $order->addStatusHistoryComment($description, $newStatus);
         } else {
             $order->setState($newState, $newStatus, $description);
             $order->setStatus($newStatus);
             $order->addStatusHistoryComment($description, $newStatus);
             $this->logger->log("Updated order '" . $order->getId() . "' to: state:  '{$newState}', status: '{$newStatus}', description: '{$description}'");
         }
         $changed = true;
     } elseif ($description && $riskifiedStatus != $riskifiedOldStatus) {
         if ($riskifiedStatus != 'approved' || !$this->apiConfig->isAutoInvoiceEnabled()) {
             $this->logger->log("Updated order " . $order->getId() . " history comment to: " . $description);
             $order->addStatusHistoryComment($description);
             $changed = true;
         }
     } else {
         $this->logger->log("No update to state, status, comments is required for " . $order->getId());
     }
     if ($changed) {
         try {
             $order->save();
         } catch (\Exception $e) {
             $this->logger->log("Error saving order: " . $e->getMessage());
             return;
         }
     }
 }
开发者ID:Riskified,项目名称:magento2,代码行数:72,代码来源:UpdateOrderState.php

示例12: execute

 /**
  * Main method ran during event raise
  *
  * @param \Magento\Framework\Event\Observer $observer
  */
 public function execute(Observer $observer)
 {
     if (!$this->canRun()) {
         return false;
     }
     $order = $observer->getOrder();
     if (!$order || !$order->getId()) {
         return false;
     }
     $this->logger->addInfo("Auto-invoicing  order " . $order->getId());
     if (!$order->canInvoice() || $order->getState() != \Magento\Sales\Model\Order::STATE_PROCESSING) {
         $this->logger->addInfo("Order cannot be invoiced");
         if ($this->apiConfig->isLoggingEnabled()) {
             $this->apiOrderLogger->logInvoice($order);
         }
         return false;
     }
     $invoice = $this->state->emulateAreaCode('adminhtml', array($this->invoiceService, 'prepareInvoice'), array($order));
     if (!$invoice->getTotalQty()) {
         $this->logger->addInfo("Cannot create an invoice without products");
         return;
     }
     try {
         $invoice->setRequestedCaptureCase($this->apiConfig->getCaptureCase())->addComment(__('Invoice automatically created by Riskified when order was approved'), false, false)->register();
         $order->setStatus('riskified_approved');
         $order->addStatusHistoryComment(__("Reviewed and approved by Riskified"), 'riskified_approved');
         $order->save();
     } catch (\Exception $e) {
         $this->logger->addInfo("Error creating invoice: " . $e->getMessage());
         return false;
     }
     try {
         $invoice->save();
         $invoice->getOrder()->save();
     } catch (\Exception $e) {
         $this->logger->addCritical("Error creating transaction: " . $e->getMessage());
         return false;
     }
     $this->logger->addInfo("Transaction saved");
 }
开发者ID:Riskified,项目名称:magento2,代码行数:45,代码来源:AutoInvoice.php


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