Example #1
0
 /**
  * {@inheritdoc}
  */
 public function getAllItems()
 {
     $resultItems = [];
     foreach ($this->_salesModel->getAllItems() as $item) {
         $resultItems[] = new \Magento\Framework\DataObject(['parent_item' => $item->getParentItem(), 'name' => $item->getName(), 'qty' => (int) $item->getQtyOrdered(), 'price' => (double) $item->getBasePrice(), 'original_item' => $item]);
     }
     return $resultItems;
 }
Example #2
0
 /**
  * Prepare order creditmemo based on order items and requested params
  *
  * @param array $data
  * @return \Magento\Sales\Model\Order\Creditmemo
  */
 public function prepareCreditmemo($data = [])
 {
     $totalQty = 0;
     $creditmemo = $this->_convertor->toCreditmemo($this->_order);
     $qtys = isset($data['qtys']) ? $data['qtys'] : [];
     foreach ($this->_order->getAllItems() as $orderItem) {
         if (!$this->_canRefundItem($orderItem, $qtys)) {
             continue;
         }
         $item = $this->_convertor->itemToCreditmemoItem($orderItem);
         if ($orderItem->isDummy()) {
             $qty = 1;
             $orderItem->setLockedDoShip(true);
         } else {
             if (isset($qtys[$orderItem->getId()])) {
                 $qty = (double) $qtys[$orderItem->getId()];
             } elseif (!count($qtys)) {
                 $qty = $orderItem->getQtyToRefund();
             } else {
                 continue;
             }
         }
         $totalQty += $qty;
         $item->setQty($qty);
         $creditmemo->addItem($item);
     }
     $creditmemo->setTotalQty($totalQty);
     $this->_initCreditmemoData($creditmemo, $data);
     $creditmemo->collectTotals();
     return $creditmemo;
 }
Example #3
0
 /**
  * @param Order $order
  * @return array
  */
 public function getKhipuRequest(Order $order)
 {
     $token = substr(md5(rand()), 0, 32);
     $payment = $order->getPayment();
     $payment->setAdditionalInformation('khipu_order_token', $token);
     $payment->save();
     $description = array();
     foreach ($order->getAllItems() as $item) {
         $description[] = number_format($item->getQtyOrdered(), 0) . ' × ' . $item->getName();
     }
     $configuration = new \Khipu\Configuration();
     $configuration->setSecret($this->getConfigData('merchant_secret'));
     $configuration->setReceiverId($this->getConfigData('merchant_id'));
     $configuration->setPlatform('magento2-khipu', Payment::KHIPU_MAGENTO_VERSION);
     $client = new \Khipu\ApiClient($configuration);
     $payments = new \Khipu\Client\PaymentsApi($client);
     try {
         $createPaymentResponse = $payments->paymentsPost($this->storeManager->getWebsite()->getName() . ' Carro #' . $order->getIncrementId(), $order->getOrderCurrencyCode(), number_format($order->getGrandTotal(), $this->getDecimalPlaces($order->getOrderCurrencyCode()), '.', ''), $payment->getAdditionalInformation('khipu_order_token'), null, join($description, ', '), null, $this->urlBuilder->getUrl('checkout/onepage/success'), $this->urlBuilder->getUrl('checkout/onepage/failure'), null, $this->urlBuilder->getUrl('khipu/payment/callback') . '?order_id=' . $order->getIncrementId(), '1.3', null, null, null, null, null, null, null, null);
     } catch (\Khipu\ApiException $exception) {
         $error = $exception->getResponseObject();
         $msg = "Error de comunicación con khipu.\n";
         $msg .= "Código: " . $error->getStatus() . "\n";
         $msg .= "Mensaje: " . $error->getMessage() . "\n";
         if (method_exists($error, 'getErrors')) {
             $msg .= "Errores:";
             foreach ($error->getErrors() as $errorItem) {
                 $msg .= "\n" . $errorItem->getField() . ": " . $errorItem->getMessage();
             }
         }
         return array('reason' => $msg, 'status' => false);
     }
     return array('status' => true, 'payment_url' => $createPaymentResponse->getPaymentUrl());
 }
Example #4
0
 /**
  * @param Order $order
  * @return array
  */
 public function getCoinGateRequest(Order $order)
 {
     $token = substr(md5(rand()), 0, 32);
     $payment = $order->getPayment();
     $payment->setAdditionalInformation('coingate_order_token', $token);
     $payment->save();
     $description = array();
     foreach ($order->getAllItems() as $item) {
         $description[] = number_format($item->getQtyOrdered(), 0) . ' × ' . $item->getName();
     }
     $params = array('order_id' => $order->getIncrementId(), 'price' => number_format($order->getGrandTotal(), 2, '.', ''), 'currency' => $order->getOrderCurrencyCode(), 'receive_currency' => $this->getConfigData('receive_currency'), 'callback_url' => $this->urlBuilder->getUrl('coingate/payment/callback') . '?token=' . $payment->getAdditionalInformation('coingate_order_token'), 'cancel_url' => $this->urlBuilder->getUrl('checkout/onepage/failure'), 'success_url' => $this->urlBuilder->getUrl('checkout/onepage/success'), 'title' => $this->storeManager->getWebsite()->getName(), 'description' => join($description, ', '));
     $this->coingate->createOrder($params);
     if ($this->coingate->success) {
         return array('status' => true, 'payment_url' => $this->coingate->response['payment_url']);
     } else {
         return array('status' => false);
     }
 }
 /**
  * Adds items to the shipment.
  *
  * @param \Magento\Sales\Api\Data\ShipmentInterface $shipment
  * @param \Magento\Sales\Model\Order $order
  * @param array $items
  * @return \Magento\Sales\Api\Data\ShipmentInterface
  */
 protected function prepareItems(\Magento\Sales\Api\Data\ShipmentInterface $shipment, \Magento\Sales\Model\Order $order, array $items = [])
 {
     $totalQty = 0;
     foreach ($order->getAllItems() as $orderItem) {
         if (!$this->canShipItem($orderItem, $items)) {
             continue;
         }
         /** @var \Magento\Sales\Model\Order\Shipment\Item $item */
         $item = $this->converter->itemToShipmentItem($orderItem);
         if ($orderItem->isDummy(true)) {
             $qty = 0;
             if (isset($items[$orderItem->getParentItemId()])) {
                 $productOptions = $orderItem->getProductOptions();
                 if (isset($productOptions['bundle_selection_attributes'])) {
                     $bundleSelectionAttributes = unserialize($productOptions['bundle_selection_attributes']);
                     if ($bundleSelectionAttributes) {
                         $qty = $bundleSelectionAttributes['qty'] * $items[$orderItem->getParentItemId()];
                         $qty = min($qty, $orderItem->getSimpleQtyToShip());
                         $item->setQty($qty);
                         $shipment->addItem($item);
                         continue;
                     } else {
                         $qty = 1;
                     }
                 }
             } else {
                 $qty = 1;
             }
         } else {
             if (isset($items[$orderItem->getId()])) {
                 $qty = min($items[$orderItem->getId()], $orderItem->getQtyToShip());
             } elseif (!count($items)) {
                 $qty = $orderItem->getQtyToShip();
             } else {
                 continue;
             }
         }
         $totalQty += $qty;
         $item->setQty($qty);
         $shipment->addItem($item);
     }
     return $shipment->setTotalQty($totalQty);
 }
Example #6
0
 /**
  * Process items dependency for new order, returns qty of affected items;
  *
  * @param \Magento\Sales\Model\Order $object
  * @return int
  */
 protected function calculateItems(\Magento\Sales\Model\Order $object)
 {
     $itemsCount = 0;
     if (!$object->getId()) {
         foreach ($object->getAllItems() as $item) {
             /** @var  \Magento\Sales\Model\Order\Item $item */
             $parent = $item->getQuoteParentItemId();
             if ($parent && !$item->getParentItem()) {
                 $item->setParentItem($object->getItemByQuoteItemId($parent));
             }
             $childItems = $item->getChildrenItems();
             if (empty($childItems)) {
                 $itemsCount++;
             }
         }
     }
     return $itemsCount;
 }
Example #7
0
 /**
  * @param $order Order
  * @return Purchase
  */
 protected function makePurchase(Order $order)
 {
     // Get all of the purchased products
     $items = $order->getAllItems();
     $purchase = SignifydModel::Make("\\Signifyd\\Models\\Purchase");
     $purchase->orderChannel = "WEB";
     $purchase->products = array();
     foreach ($items as $item) {
         $purchase->products[] = $this->makeProduct($item);
     }
     $purchase->totalPrice = $order->getGrandTotal();
     $purchase->currency = $order->getOrderCurrencyCode();
     $purchase->orderId = $order->getIncrementId();
     $purchase->paymentGateway = $order->getPayment()->getMethod();
     $purchase->shippingPrice = floatval($order->getShippingAmount());
     $purchase->avsResponseCode = $order->getPayment()->getCcAvsStatus();
     $purchase->cvvResponseCode = $order->getPayment()->getCcSecureVerify();
     $purchase->createdAt = date('c', strtotime($order->getCreatedAt()));
     $purchase->browserIpAddress = $this->getIPAddress($order);
     return $purchase;
 }
Example #8
0
 /**
  * Get formatted order description
  *
  * @param \Magento\Sales\Model\Order $order
  * @return string
  */
 protected function _getOrderDescription($order)
 {
     $invoiceDesc = '';
     foreach ($order->getAllItems() as $item) {
         if ($item->getParentItem()) {
             continue;
         }
         //COM filed can only handle max 100
         if ($this->string->strlen($invoiceDesc . $item->getName()) > 100) {
             break;
         }
         $invoiceDesc .= $item->getName() . ', ';
     }
     return $this->string->substr($invoiceDesc, 0, -2);
 }