Skip to content

Commit

Permalink
MDEE-624: Fix credit memo comments are not being extracted (#358)
Browse files Browse the repository at this point in the history
* MDEE-624: change creditmemo adjustment to use base currency
  • Loading branch information
kuflower authored Nov 29, 2023
1 parent 9603bc3 commit 6a254ba
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 8 deletions.
32 changes: 32 additions & 0 deletions SalesOrdersDataExporter/Model/Provider/CreditMemoComment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\SalesOrdersDataExporter\Model\Provider;

class CreditMemoComment
{
/**
* Getting credit memo comments.
*
* @param array $values
* @return array
*/
public function get(array $values): array
{
$output = [];
foreach ($values as $group) {
foreach ($group as $creditMemo) {
$output[] = [
'entityId' => $creditMemo['entityId'],
'creditMemoComments' => $creditMemo['comment'],
];
}
}
return $output;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected function runIndexer(array $ids) : void
$this->indexer->load(self::ORDER_FEED_INDEXER);
$this->indexer->reindexList($ids);
} catch (Throwable $e) {
throw new RuntimeException('Could not reindex orders data');
throw new RuntimeException('Could not reindex orders data', $e);
}
}
}
20 changes: 16 additions & 4 deletions SalesOrdersDataExporter/Test/Integration/CreateOrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,8 @@ private function getExpectedCreditMemosData(OrderInterface $order): ?array
'orderItemId' => ['id' => $itemUuid],
'qtyRefunded' => $creditmemoItem->getQty(),
'basePrice' => $creditmemoItem->getBasePrice(),
//TODO: Need to be implement
//'baseRowTotal' => $creditmemoItem->getBaseRowTotal(),
'baseRowTotal' => $creditmemoItem->getQty() * $creditmemoItem->getBasePrice()
- $creditmemoItem->getBaseDiscountAmount(),
//TODO: Need to be implemented
//'productTaxes' => ''
];
Expand All @@ -539,21 +539,33 @@ private function getExpectedCreditMemosData(OrderInterface $order): ?array
'createdAt' => $this->convertDate($creditMemo->getCreatedAt()),
'shippingAmount' => $creditMemo->getBaseShippingAmount(),
'shippingTaxAmount' => $creditMemo->getBaseShippingTaxAmount(),
'adjustment' => $creditMemo->getAdjustment(),
'adjustment' => $creditMemo->getBaseAdjustment(),
'currency' => $creditMemo->getOrderCurrencyCode(),
//TODO: Need to be implemented
//'refundTaxes' => $creditMemo->getTaxAmount()
'subtotal' => $creditMemo->getBaseSubtotal(),
'productsTaxAmount' => $creditMemo->getBaseTaxAmount(),
'commerceCreditMemoNumber' => $creditMemo->getIncrementId(),
'grandTotal' => $creditMemo->getBaseGrandTotal(),
'refundItems' => $creditMemoItems
'refundItems' => $creditMemoItems,
'creditMemoComments' => $this->extractComments($creditMemo->getComments())
];
}

return empty($creditMemos) ? null : $creditMemos;
}

private function extractComments(array $comments): ?array
{
$commentValues = array_map(
function ($comment) {
return $comment->getComment();
},
$comments
);
return $commentValues ? array_values($commentValues) : null;
}

/**
* @param OrderInterface $order
* @return array|null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,15 @@
$orderData['items'][$item->getId()] = $item;
}
$order->setItems($orderData['items']);

$creditmemo = $creditmemoFactory->createByOrder($order, $orderData);
$creditmemo->setBaseShippingAmount(3.14);
$creditmemo->setBaseShippingTaxAmount(1.14);
$creditmemo->setAdjustment(2.77);
$creditmemo->setBaseTaxAmount(1.5);
$creditmemo->setIncrementId($order->getIncrementId());
$creditmemo->addComment("note");
$creditmemo->addComment("note2");

$creditItem = $creditmemoItemFactory->create();
$creditItem->setCreditmemo($creditmemo)
Expand Down
5 changes: 4 additions & 1 deletion SalesOrdersDataExporter/etc/et_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@
provider="Magento\DataExporter\Model\Provider\DateConverter">
<using field="entityId" />
</field>
<field name="creditMemoComments" type="String" repeated="true" />
<field name="creditMemoComments" type="String" repeated="true"
provider="Magento\SalesOrdersDataExporter\Model\Provider\CreditMemoComment">
<using field="entityId" />
</field>
<field name="shippingAmount" type="Float" />
<field name="shippingTaxAmount" type="Float" />

Expand Down
4 changes: 2 additions & 2 deletions SalesOrdersDataExporter/etc/query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,14 @@
<attribute name="base_currency_code" alias="currency" />
<attribute name="base_subtotal" alias="subtotal" />
<attribute name="base_tax_amount" alias="productsTaxAmount" />
<attribute name="adjustment" />
<attribute name="base_adjustment" alias="adjustment" />
<attribute name="increment_id" alias="commerceCreditMemoNumber" />
<attribute name="base_grand_total" alias="grandTotal" />
<filter glue="and">
<condition attribute="order_id" operator="in" type="placeholder">commerceOrderId</condition>
</filter>
<link-source name="sales_creditmemo_comment" link-type="left">
<attribute name="comment" alias="credit_memo_comments" />
<attribute name="comment" />
<using glue="and">
<condition attribute="parent_id" operator="eq" type="identifier">entity_id</condition>
</using>
Expand Down

0 comments on commit 6a254ba

Please sign in to comment.