protected function getRegName(\Magento\Framework\Event\Observer $observer)
 {
     $id = $observer->getOrder()->getIncrementId();
     if ($id) {
         $regName = 'komfortkasse_order_status_' . $id;
         return $regName;
     }
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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);
     }
 }
예제 #5
0
 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"));
     }
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
예제 #10
0
 /**
  * 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()));
             }
         }
     }
 }
예제 #11
0
 /**
  * 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;
         }
     }
 }
예제 #12
0
 /**
  * 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");
 }