Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOL-969: Store refund manager metadata in DB #625

Merged
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,33 @@
<?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\OneToOneAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;

final class OrderLineItemExtension extends EntityExtension
{
const ORDER_LINE_ITEM_PROPERTY_NAME = 'refundLineItem';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mollieRefundItem wäre evtl sicherer?


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

/**
* @param FieldCollection $collection
*/
public function extendFields(FieldCollection $collection): void
{
$collection->add(new OneToOneAssociationField(self::ORDER_LINE_ITEM_PROPERTY_NAME, 'id', 'order_line_item_id', RefundItemDefinition::class));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attention partial refunds
1 line item can be in multiple mollie line items

}
}
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('reference', 'reference'))->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 OneToOneAssociationField('orderLineItem', 'order_line_item_id', 'id', OrderLineItemDefinition::class, false))->addFlags(new ApiAware()),
]);
}
}
Loading
Loading