/**
  * Collect orders data and call service method to register order PV.
  *
  * @param \Magento\Sales\Api\Data\OrderInterface $order
  */
 public function savePv(\Magento\Sales\Api\Data\OrderInterface $order)
 {
     $orderId = $order->getId();
     $state = $order->getState();
     $dateCreated = $order->getCreatedAt();
     $itemsData = $this->_subCollector->getServiceItemsForMageSaleOrder($order);
     /* compose request data and request itself */
     /** @var \Praxigento\Pv\Service\Sale\Request\Save $req */
     $req = $this->_manObj->create(\Praxigento\Pv\Service\Sale\Request\Save::class);
     $req->setSaleOrderId($orderId);
     $req->setOrderItems($itemsData);
     if ($state == \Magento\Sales\Model\Order::STATE_PROCESSING) {
         $req->setSaleOrderDatePaid($dateCreated);
     }
     $this->_callSale->save($req);
 }
Exemple #2
0
 /**
  * Links transaction with parent transaction
  *
  * @param TransactionInterface $transaction
  * @return TransactionInterface
  */
 protected function linkWithParentTransaction(TransactionInterface $transaction)
 {
     $parentTransactionId = $this->payment->getParentTransactionId();
     if ($parentTransactionId) {
         $transaction->setParentTxnId($parentTransactionId);
         if ($this->payment->getShouldCloseParentTransaction()) {
             $parentTransaction = $this->transactionRepository->getByTransactionId($parentTransactionId, $this->payment->getid(), $this->order->getId());
             if ($parentTransaction) {
                 if (!$parentTransaction->getIsClosed()) {
                     $parentTransaction->isFailsafe($this->failSafe)->close(false);
                 }
                 $this->order->addRelatedObject($parentTransaction);
             }
         }
     }
     return $transaction;
 }
 /**
  * @param \Magento\Sales\Api\Data\OrderInterface $mageOrder
  * @return \Praxigento\Odoo\Data\Odoo\SaleOrder\Line[]
  */
 public function getSaleOrderLines(\Magento\Sales\Api\Data\OrderInterface $mageOrder)
 {
     $lines = [];
     /* collect data */
     $orderId = $mageOrder->getId();
     $storeId = $mageOrder->getStoreId();
     $stockId = $this->_manStock->getStockIdByStoreId($storeId);
     $aggSaleOrderItems = $this->_repoAggSaleOrderItem->getByOrderAndStock($orderId, $stockId);
     foreach ($aggSaleOrderItems as $item) {
         $productIdOdoo = $item->getOdooIdProduct();
         /* process order line */
         if (isset($lines[$productIdOdoo])) {
             $line = $lines[$productIdOdoo];
         } else {
             $line = $this->_extractLine($item);
         }
         /* process lot for order line ($item is a flat structure - if one sale item consists of 2 lots then
            two entries will be in aggregated results) */
         $lots = $line->getLots();
         $lot = $this->_extractLineLot($item);
         /* save Odoo data object into Odoo line */
         $lots[] = $lot;
         $line->setLots($lots);
         $lines[$productIdOdoo] = $line;
     }
     /* remove keys from array */
     $result = array_values($lines);
     return $result;
 }
 /**
  * Return customer code according to the admin configured format
  *
  * @param \Magento\Quote\Api\Data\CartInterface|\Magento\Sales\Api\Data\OrderInterface $data
  * @return string
  */
 protected function getCustomerCode($data)
 {
     switch ($this->config->getCustomerCodeFormat($data->getStoreId())) {
         case Config::CUSTOMER_FORMAT_OPTION_EMAIL:
             $email = $data->getCustomerEmail();
             return $email ?: Config::CUSTOMER_MISSING_EMAIL;
             break;
         case Config::CUSTOMER_FORMAT_OPTION_NAME_ID:
             $customer = $this->getCustomerById($data->getCustomerId());
             if ($customer && $customer->getId()) {
                 $name = $customer->getFirstname() . ' ' . $customer->getLastname();
                 $id = $customer->getId();
             } else {
                 if (!$data->getIsVirtual()) {
                     $address = $data->getShippingAddress();
                 } else {
                     $address = $data->getBillingAddress();
                 }
                 $name = $address->getFirstname() . ' ' . $address->getLastname();
                 if (!trim($name)) {
                     $name = Config::CUSTOMER_MISSING_NAME;
                 }
                 $id = Config::CUSTOMER_GUEST_ID;
             }
             return sprintf(Config::CUSTOMER_FORMAT_NAME_ID, $name, $id);
             break;
         case Config::CUSTOMER_FORMAT_OPTION_ID:
         default:
             return $data->getCustomerId() ?: strtolower(Config::CUSTOMER_GUEST_ID) . '-' . $data->getId();
             break;
     }
 }