Skip to content

Commit

Permalink
MOL-969: create an array
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitalij Mik committed Sep 27, 2023
1 parent 3701291 commit 3c23202
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 26 deletions.
33 changes: 33 additions & 0 deletions src/Components/RefundManager/DAL/RefundItem/RefundItemEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,37 @@ public function setOrderLineItemVersionId(?string $orderLineItemVersionId): void
{
$this->orderLineItemVersionId = $orderLineItemVersionId;
}

/**
* @param string $type
* @param string $mollieLineId
* @param string $label
* @param int $quantity
* @param float $amount
* @param null|string $oderLineItemId
* @param null|string $oderLineItemVersionId
* @param null|string $refundId
* @return array<mixed>
*/
public static function createEntryArray(string $type, string $mollieLineId, string $label, int $quantity, float $amount, ?string $oderLineItemId, ?string $oderLineItemVersionId, ?string $refundId): array
{
$row = [
'type' => $type,
'mollieLineId' => $mollieLineId,
'label' => $label,
'quantity' => $quantity,
'amount' => $amount,
'oderLineItemId' => $oderLineItemId,
'oderLineItemVersionId' => $oderLineItemVersionId,
];

/**
* refundId is not given when we create a new entry because the id is created by shopware dal
*/
if ($refundId !== null) {
$row['refundId'] = $refundId;
}

return $row;
}
}
21 changes: 12 additions & 9 deletions src/Components/RefundManager/RefundManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Kiener\MolliePayments\Compatibility\Bundles\FlowBuilder\FlowBuilderEventFactory;
use Kiener\MolliePayments\Compatibility\Bundles\FlowBuilder\FlowBuilderFactoryInterface;
use Kiener\MolliePayments\Components\RefundManager\Builder\RefundDataBuilder;
use Kiener\MolliePayments\Components\RefundManager\DAL\RefundItem\RefundItemEntity;
use Kiener\MolliePayments\Components\RefundManager\DAL\Repository\RefundRepositoryInterface;
use Kiener\MolliePayments\Components\RefundManager\Integrators\StockManagerInterface;
use Kiener\MolliePayments\Components\RefundManager\RefundData\RefundData;
Expand Down Expand Up @@ -466,16 +467,18 @@ private function convertToRepositoryArray(array $serviceItems, string $type): ar
if ($item->getQuantity() <= 0) {
continue;
}
$row = RefundItemEntity::createEntryArray(
$type,
$item->getMollieLineID(),
$item->getShopwareReference(),
$item->getQuantity(),
$item->getAmount(),
$item->getShopwareLineID(),
$item->getShopwareLineVersionId(),
null
);

$data[] = [
'type' => $type,
'orderLineItemId' => $item->getShopwareLineID(),
'orderLineItemVersionId' => $item->getShopwareLineVersionId(),
'mollieLineId' => $item->getMollieLineID(),
'label' => (string)$item->getShopwareReference(),
'quantity' => $item->getQuantity(),
'amount' => $item->getAmount(),
];
$data[] = $row;
}
return $data;
}
Expand Down
34 changes: 17 additions & 17 deletions src/Service/Refund/CompositionMigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,30 +79,30 @@ public function updateRefundItems(Refund $refund, OrderEntity $order, Context $c

$dataToSave = [];
foreach ($oldCompositions as $composition) {
$reference = $composition->swReference;
if (strlen($reference) === 0) {
$reference = RoundingDifferenceFixer::DEFAULT_TITLE;
$label = $composition->swReference;
if (strlen($label) === 0) {
$label = RoundingDifferenceFixer::DEFAULT_TITLE;
}

$row = [
'type' => $oldMetadata->type,
'mollieLineId' => $composition->mollieLineId,
'label' => $reference,
'quantity' => $composition->quantity,
'amount' => $composition->amount,
'refundId' => $shopwareRefund->getId(),
'oderLineItemId' => null,
'oderLineItemVersionId' => null,
];


$orderLineItemId = null;
$orderLineItemVersionId = null;
$orderLineItem = $this->filterByMollieId($orderLineItems, $composition->mollieLineId);

if ($orderLineItem instanceof OrderLineItemEntity) {
$row['orderLineItemId'] = $orderLineItem->getId();
$row['orderLineItemVersionId'] = $orderLineItem->getVersionId();
$orderLineItemId = $orderLineItem->getId();
$orderLineItemVersionId = $orderLineItem->getVersionId();
}

$row = RefundItemEntity::createEntryArray(
$oldMetadata->type,
$composition->mollieLineId,
$label,
$composition->quantity,
$composition->amount,
$orderLineItemId,
$orderLineItemVersionId,
$shopwareRefund->getId()
);

$dataToSave[] = $row;
}
Expand Down

0 comments on commit 3c23202

Please sign in to comment.