Skip to content

Commit

Permalink
MOL-969: Store refund manager metadata in DB (#625)
Browse files Browse the repository at this point in the history
* MOL-969: Add entities

* MOL-969: store refunds in db

* MOL-969: can save refund items

* MOL-969: fix hydrator tests

* MOL-969: Fix styles

* MOL-969: fix metadata

* MOL-969: fix merge

* MOL-969: update pr

* MOL-969: create an array

---------

Co-authored-by: Vitalij Mik <[email protected]>
  • Loading branch information
BlackScorp and Vitalij Mik authored Sep 27, 2023
1 parent 486ff9a commit 4e3f5fb
Show file tree
Hide file tree
Showing 32 changed files with 1,097 additions and 468 deletions.
520 changes: 293 additions & 227 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Components/RefundManager/Builder/RefundDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function buildRefundData(OrderEntity $order, Context $context): RefundDat


try {
$refunds = $this->refundService->getRefunds($order);
$refunds = $this->refundService->getRefunds($order, $context);
} catch (PaymentNotFoundException $ex) {
# if we dont have a payment, then theres also no refunds
# we still need our data, only with an empty list of refunds
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);

namespace Kiener\MolliePayments\Components\RefundManager\DAL\OrderLineItem;

use Kiener\MolliePayments\Components\RefundManager\DAL\Refund\RefundDefinition;
use Kiener\MolliePayments\Components\RefundManager\DAL\RefundItem\RefundItemDefinition;
use Shopware\Core\Checkout\Order\Aggregate\OrderLineItem\OrderLineItemDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityExtension;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\CascadeDelete;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToOneAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToManyAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToOneAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;

class OrderLineItemExtension extends EntityExtension
{
const ORDER_LINE_ITEM_PROPERTY_NAME = 'mollieRefundLineItems';

/**
* @return string
*/
public function getDefinitionClass(): string
{
return OrderLineItemDefinition::class;
}

/**
* @param FieldCollection $collection
*/
public function extendFields(FieldCollection $collection): void
{
$collection->add(new OneToManyAssociationField(self::ORDER_LINE_ITEM_PROPERTY_NAME, RefundItemDefinition::class, 'order_line_item_id'));
}
}
3 changes: 3 additions & 0 deletions src/Components/RefundManager/DAL/Refund/RefundDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

namespace Kiener\MolliePayments\Components\RefundManager\DAL\Refund;

use Kiener\MolliePayments\Components\RefundManager\DAL\RefundItem\RefundItemDefinition;
use Shopware\Core\Checkout\Order\OrderDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\Field\FkField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\PrimaryKey;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Required;
use Shopware\Core\Framework\DataAbstractionLayer\Field\IdField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\LongTextField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToManyAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ReferenceVersionField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\StringField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
Expand Down Expand Up @@ -59,6 +61,7 @@ protected function defineFields(): FieldCollection

new LongTextField('public_description', 'publicDescription'),
new LongTextField('internal_description', 'internalDescription'),
new OneToManyAssociationField('refundItems', RefundItemDefinition::class, 'refund_id')
]);
}
}
28 changes: 28 additions & 0 deletions src/Components/RefundManager/DAL/Refund/RefundEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Kiener\MolliePayments\Components\RefundManager\DAL\Refund;

use Kiener\MolliePayments\Components\RefundManager\DAL\RefundItem\RefundItemCollection;
use Shopware\Core\Framework\DataAbstractionLayer\Entity;
use Shopware\Core\Framework\DataAbstractionLayer\EntityIdTrait;

Expand Down Expand Up @@ -36,6 +37,17 @@ class RefundEntity extends Entity
*/
protected $internalDescription;

/**
* @var RefundItemCollection
*/
protected $refundItems;

public function __construct()
{
$this->refundItems = new RefundItemCollection();
}


/**
* @return string
*/
Expand Down Expand Up @@ -120,4 +132,20 @@ public function setInternalDescription(?string $internalDescription): void
{
$this->internalDescription = $internalDescription;
}

/**
* @return RefundItemCollection
*/
public function getRefundItems(): RefundItemCollection
{
return $this->refundItems;
}

/**
* @param RefundItemCollection $refundItems
*/
public function setRefundItems(RefundItemCollection $refundItems): void
{
$this->refundItems = $refundItems;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);

namespace Kiener\MolliePayments\Components\RefundManager\DAL\RefundItem;

use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;

/**
* @extends EntityCollection<RefundItemEntity>
*/
final class RefundItemCollection extends EntityCollection
{
protected function getExpectedClass(): string
{
return RefundItemEntity::class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
declare(strict_types=1);

namespace Kiener\MolliePayments\Components\RefundManager\DAL\RefundItem;

use Google\Protobuf\Api;
use Kiener\MolliePayments\Components\RefundManager\DAL\Refund\RefundDefinition;
use Shopware\Core\Checkout\Order\Aggregate\OrderLineItem\OrderLineItemDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\Field\FkField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ApiAware;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\PrimaryKey;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Required;
use Shopware\Core\Framework\DataAbstractionLayer\Field\FloatField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\IdField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\IntField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToOneAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToOneAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ReferenceVersionField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\StringField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;

final class RefundItemDefinition extends EntityDefinition
{
public const ENTITY_NAME = 'mollie_refund_item';

public function getCollectionClass(): string
{
return RefundItemCollection::class;
}

public function getEntityClass(): string
{
return RefundItemEntity::class;
}

public function getEntityName(): string
{
return self::ENTITY_NAME;
}

protected function defineFields(): FieldCollection
{
return new FieldCollection([
(new IdField('id', 'id'))->addFlags(new Required(), new PrimaryKey(), new ApiAware()),
(new StringField('type', 'type'))->addFlags(new Required(), new ApiAware()),
(new FkField('refund_id', 'refundId', RefundDefinition::class))->addFlags(new ApiAware()),
(new ManyToOneAssociationField('refund', 'refund_id', RefundDefinition::class))->addFlags(new ApiAware()),
(new IntField('quantity', 'quantity'))->addFlags(new Required(), new ApiAware()),
(new StringField('label', 'label'))->addFlags(new ApiAware()),
(new FloatField('amount', 'amount'))->addFlags(new Required(), new ApiAware()),
(new StringField('mollie_line_id', 'mollieLineId'))->addFlags(new Required(), new ApiAware()),
(new FkField('order_line_item_id', 'orderLineItemId', OrderLineItemDefinition::class))->addFlags(new ApiAware()),
new ReferenceVersionField(OrderLineItemDefinition::class, 'order_line_item_version_id'),
(new ManyToOneAssociationField('orderLineItem', 'order_line_item_id', OrderLineItemDefinition::class))->addFlags(new ApiAware()),
]);
}
}
Loading

0 comments on commit 4e3f5fb

Please sign in to comment.