Skip to content

Commit

Permalink
Added fields: di_shipping_costs, di_shipping_costs_vat. Added validat…
Browse files Browse the repository at this point in the history
…ing Invoices, Items. Implemented: shipping_amount, adjustment_positive, adjustment_negative.
  • Loading branch information
Returnless committed Jun 21, 2022
1 parent 8672c38 commit 3384bcb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
34 changes: 33 additions & 1 deletion Model/Api/OrderCreditMemo.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ public function createCreditMemo($requestParams)

$order = $this->retHelper->searchOrder($requestParams['order_id']);

if (!$order->hasInvoices()) {
$response['code'] = 404;
$response['return_message'] = __("Order is not invoiced.");

return $response;
}

$orderId = $order->getId();
if (!$orderId) {
$response['code'] = 404;
Expand All @@ -125,8 +132,25 @@ public function createCreditMemo($requestParams)
$itemToCredit = [];

$creditMemoData['shipping_amount'] = 0;
if (isset($requestParams['shipping_amount'])
&& !empty($requestParams['shipping_amount'])
) {
$creditMemoData['shipping_amount'] = (float) $requestParams['shipping_amount'];
}

$creditMemoData['adjustment_positive'] = 0;
if (isset($requestParams['adjustment_positive'])
&& !empty($requestParams['adjustment_positive'])
) {
$creditMemoData['adjustment_positive'] = (float) $requestParams['adjustment_positive'];
}

$creditMemoData['adjustment_negative'] = 0;
if (isset($requestParams['adjustment_negative'])
&& !empty($requestParams['adjustment_negative'])
) {
$creditMemoData['adjustment_negative'] = (float) $requestParams['adjustment_negative'];
}

$creditMemoData['do_offline'] = 0;
if (isset($requestParams['payment_refund'])
Expand All @@ -152,10 +176,18 @@ public function createCreditMemo($requestParams)

foreach ($requestParams['items'] as $requestItem) {
$item = $this->retHelper->getItemBySku($order, $requestItem['sku']);

if (!$item) {
$response['code'] = 404;
$response['return_message'] = __("Sku is not associated to Order.");

return $response;
}

$orderItemId = $item->getId();

$itemToCredit[$orderItemId] = [
'qty' => $requestItem['qty']
'qty' => (float) $requestItem['qty']
];
}
$creditMemoData['items'] = $itemToCredit;
Expand Down
3 changes: 3 additions & 0 deletions Model/Api/OrderInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ public function getOrderInfoReturnless($incrementId)
$orderInfo['customer']['phone'] = $shippingAddress->getTelephone();
}

$orderInfo['di_shipping_costs'] = $order->getShippingAmount();
$orderInfo['di_shipping_costs_vat'] = $order->getShippingTaxAmount();

$separateBundle = $this->config->getSeparateBundle();
$orderItems = $separateBundle ? $order->getAllItems() : $order->getAllVisibleItems();

Expand Down

0 comments on commit 3384bcb

Please sign in to comment.