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

NTR: refactor repositories #920

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .php_cs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

$finder = \PhpCsFixer\Finder::create()->in([
__DIR__ . '/src',
__DIR__.'/tests/PHPUnit',
]);

$finder->exclude(
Expand Down
8 changes: 4 additions & 4 deletions src/Command/DAL/DALCleanupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace Kiener\MolliePayments\Command\DAL;

use Doctrine\DBAL\Connection;
use Kiener\MolliePayments\Repository\Product\ProductRepositoryInterface;
use Kiener\MolliePayments\Struct\Product\ProductAttributes;
use Psr\Log\LoggerInterface;
use Shopware\Core\Content\Product\ProductEntity;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -20,7 +20,7 @@ class DALCleanupCommand extends Command


/**
* @var ProductRepositoryInterface
* @var EntityRepository
*/
private $repoProducts;

Expand All @@ -36,11 +36,11 @@ class DALCleanupCommand extends Command


/**
* @param ProductRepositoryInterface $repoProducts
* @param EntityRepository $repoProducts
* @param Connection $connection
* @param LoggerInterface $logger
*/
public function __construct(ProductRepositoryInterface $repoProducts, Connection $connection, LoggerInterface $logger)
public function __construct(EntityRepository $repoProducts, Connection $connection, LoggerInterface $logger)
{
$this->repoProducts = $repoProducts;
$this->connection = $connection;
Expand Down
54 changes: 34 additions & 20 deletions src/Components/ApplePayDirect/ApplePayDirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
use Kiener\MolliePayments\Facade\MolliePaymentDoPay;
use Kiener\MolliePayments\Factory\MollieApiFactory;
use Kiener\MolliePayments\Handler\Method\ApplePayPayment;
use Kiener\MolliePayments\Repository\Order\OrderAddressRepositoryInterface;
use Kiener\MolliePayments\Repository\PaymentMethod\PaymentMethodRepository;
use Kiener\MolliePayments\Repository\PaymentMethodRepository;
use Kiener\MolliePayments\Service\Cart\CartBackupService;
use Kiener\MolliePayments\Service\CartServiceInterface;
use Kiener\MolliePayments\Service\CustomerService;
Expand All @@ -33,6 +32,9 @@
use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionEntity;
use Shopware\Core\Checkout\Order\OrderEntity;
use Shopware\Core\Checkout\Payment\Cart\AsyncPaymentTransactionStruct;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\Validation\DataBag\DataBag;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
Expand Down Expand Up @@ -106,7 +108,7 @@ class ApplePayDirect
private $orderService;

/**
* @var OrderAddressRepositoryInterface
* @var EntityRepository
*/
private $repoOrderAdresses;

Expand Down Expand Up @@ -135,11 +137,11 @@ class ApplePayDirect
* @param MollieApiFactory $mollieApiFactory
* @param ShopService $shopService
* @param OrderService $orderService
* @param OrderAddressRepositoryInterface $repoOrderAdresses
* @param EntityRepository $repoOrderAdresses
* @param ApplePayDirectDomainAllowListGateway $domainAllowListGateway
* @param ApplePayDirectDomainSanitizer $domainSanitizer
*/
public function __construct(ApplePayDomainVerificationService $domainFileDownloader, ApplePayPayment $paymentHandler, MolliePaymentDoPay $molliePayments, CartServiceInterface $cartService, ApplePayFormatter $formatter, ApplePayShippingBuilder $shippingBuilder, SettingsService $pluginSettings, CustomerService $customerService, PaymentMethodRepository $repoPaymentMethods, CartBackupService $cartBackupService, MollieApiFactory $mollieApiFactory, ShopService $shopService, OrderService $orderService, OrderAddressRepositoryInterface $repoOrderAdresses, ApplePayDirectDomainAllowListGateway $domainAllowListGateway, ApplePayDirectDomainSanitizer $domainSanitizer)
public function __construct(ApplePayDomainVerificationService $domainFileDownloader, ApplePayPayment $paymentHandler, MolliePaymentDoPay $molliePayments, CartServiceInterface $cartService, ApplePayFormatter $formatter, ApplePayShippingBuilder $shippingBuilder, SettingsService $pluginSettings, CustomerService $customerService, PaymentMethodRepository $repoPaymentMethods, CartBackupService $cartBackupService, MollieApiFactory $mollieApiFactory, ShopService $shopService, OrderService $orderService, EntityRepository $repoOrderAdresses, ApplePayDirectDomainAllowListGateway $domainAllowListGateway, ApplePayDirectDomainSanitizer $domainSanitizer)
{
$this->domainFileDownloader = $domainFileDownloader;
$this->paymentHandler = $paymentHandler;
Expand Down Expand Up @@ -175,7 +177,18 @@ public function downloadDomainAssociationFile(): void
*/
public function getActiveApplePayID(SalesChannelContext $context): string
{
return $this->repoPaymentMethods->getActiveApplePayID($context->getContext());
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('handlerIdentifier', ApplePayPayment::class));
$criteria->addFilter(new EqualsFilter('active', true));

/** @var array<string> $paymentMethods */
$paymentMethods = $this->repoPaymentMethods->getRepository()->searchIds($criteria, $context->getContext())->getIds();

if (count($paymentMethods) <= 0) {
throw new \Exception('Payment Method Apple Pay Direct not found in system');
}

return (string)$paymentMethods[0];
}

/**
Expand All @@ -194,7 +207,7 @@ public function isApplePayDirectEnabled(SalesChannelContext $context): bool

if (is_array($salesChannelPaymentIDs) && $settings->isEnableApplePayDirect()) {
try {
$applePayMethodID = $this->repoPaymentMethods->getActiveApplePayID($context->getContext());
$applePayMethodID = $this->getActiveApplePayID($context);

foreach ($salesChannelPaymentIDs as $tempID) {
# verify if our Apple Pay payment method is indeed in use
Expand Down Expand Up @@ -444,19 +457,20 @@ public function createPayment(OrderEntity $order, string $shopwareReturnUrl, str
foreach ($order->getAddresses() as $address) {
# attention, Apple Pay does not have a company name
# therefore we always need to make sure to remove the company field in our order
$this->repoOrderAdresses->updateAddress(
$address->getId(),
$firstname,
$lastname,
'',
'',
'',
$street,
$zipcode,
$city,
$countryID,
$context->getContext()
);
$this->repoOrderAdresses->update([
[
'id' => $address->getId(),
'firstName' => $firstname,
'lastName' => $lastname,
'company' => '',
'department' => '',
'vatId' => '',
'street' => $street,
'zipcode' => $zipcode,
'city' => $city,
'countryId' => $countryID,
]
], $context->getContext());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

namespace Kiener\MolliePayments\Components\ApplePayDirect\Services;

use Kiener\MolliePayments\Repository\Customer\CustomerRepositoryInterface;
use Kiener\MolliePayments\Repository\CustomerAddress\CustomerAddressRepositoryInterface;
use Shopware\Core\Checkout\Customer\CustomerEntity;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\Uuid\Uuid;

/**
Expand All @@ -17,12 +16,12 @@
class ApplePayShippingAddressFaker
{
private const ID_SUFFIX = 'applePayAddressId';
private CustomerRepositoryInterface $customerRepository;
private CustomerAddressRepositoryInterface $customerAddressRepository;
private EntityRepository $customerRepository;
private EntityRepository $customerAddressRepository;

public function __construct(
CustomerRepositoryInterface $customerRepository,
CustomerAddressRepositoryInterface $customerAddressRepository
EntityRepository $customerRepository,
EntityRepository $customerAddressRepository
) {
$this->customerRepository = $customerRepository;
$this->customerAddressRepository = $customerAddressRepository;
Expand Down
6 changes: 3 additions & 3 deletions src/Components/CancelManager/CancelItemFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
use Kiener\MolliePayments\Components\RefundManager\Integrators\StockManagerInterface;
use Kiener\MolliePayments\Event\OrderLinesUpdatedEvent;
use Kiener\MolliePayments\Factory\MollieApiFactory;
use Kiener\MolliePayments\Repository\OrderLineItem\OrderLineItemRepositoryInterface;
use Mollie\Api\MollieApiClient;
use Psr\Log\LoggerInterface;
use Shopware\Core\Checkout\Order\Aggregate\OrderLineItem\OrderLineItemEntity;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

Expand All @@ -23,11 +23,11 @@ class CancelItemFacade


private LoggerInterface $logger;
private OrderLineItemRepositoryInterface $orderLineItemRepository;
private EntityRepository $orderLineItemRepository;
private StockManagerInterface $stockManager;
private EventDispatcherInterface $eventDispatcher;

public function __construct(MollieApiFactory $clientFactory, OrderLineItemRepositoryInterface $orderLineItemRepository, StockManagerInterface $stockManager, EventDispatcherInterface $eventDispatcher, LoggerInterface $logger)
public function __construct(MollieApiFactory $clientFactory, EntityRepository $orderLineItemRepository, StockManagerInterface $stockManager, EventDispatcherInterface $eventDispatcher, LoggerInterface $logger)
{
$this->client = $clientFactory->getClient();
$this->logger = $logger;
Expand Down
11 changes: 5 additions & 6 deletions src/Components/OrderExpiration/ExpireAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
namespace Kiener\MolliePayments\Components\OrderExpiration;

use Kiener\MolliePayments\Handler\Method\BankTransferPayment;
use Kiener\MolliePayments\Repository\Order\OrderRepositoryInterface;
use Kiener\MolliePayments\Repository\SalesChannel\SalesChannelRepositoryInterface;
use Kiener\MolliePayments\Service\Order\OrderExpireService;
use Kiener\MolliePayments\Service\SettingsService;
use Psr\Log\LoggerInterface;
use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionStates;
use Shopware\Core\Checkout\Order\OrderCollection;
use Shopware\Core\Defaults;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\OrFilter;
Expand All @@ -22,15 +21,15 @@

class ExpireAction
{
private OrderRepositoryInterface $orderRepository;
private SalesChannelRepositoryInterface $salesChannelRepository;
private EntityRepository $orderRepository;
private EntityRepository $salesChannelRepository;
private OrderExpireService $orderExpireService;
private SettingsService $settingsService;
private LoggerInterface $logger;

public function __construct(
OrderRepositoryInterface $orderRepository,
SalesChannelRepositoryInterface $salesChannelRepository,
EntityRepository $orderRepository,
EntityRepository $salesChannelRepository,
OrderExpireService $orderExpireService,
SettingsService $settingsService,
LoggerInterface $logger
Expand Down
20 changes: 18 additions & 2 deletions src/Components/PaypalExpress/PayPalExpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace Kiener\MolliePayments\Components\PaypalExpress;

use Kiener\MolliePayments\Factory\MollieApiFactory;
use Kiener\MolliePayments\Repository\PaymentMethod\PaymentMethodRepository;
use Kiener\MolliePayments\Handler\Method\PayPalExpressPayment;
use Kiener\MolliePayments\Repository\PaymentMethodRepository;
use Kiener\MolliePayments\Service\CartServiceInterface;
use Kiener\MolliePayments\Service\CustomerService;
use Kiener\MolliePayments\Service\MollieApi\Builder\MollieOrderPriceBuilder;
Expand All @@ -12,6 +13,8 @@
use Mollie\Api\Resources\Session;
use Shopware\Core\Checkout\Cart\Cart;
use Shopware\Core\Checkout\Customer\CustomerEntity;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\System\SalesChannel\SalesChannelContext;

class PayPalExpress
Expand Down Expand Up @@ -97,7 +100,20 @@ public function isPaypalExpressEnabled(SalesChannelContext $context): bool
*/
public function getActivePaypalExpressID(SalesChannelContext $context): string
{
return $this->repoPaymentMethods->getActivePaypalExpressID($context);
$criteria = new Criteria();
$criteria->addAssociation('salesChannels');
$criteria->addFilter(new EqualsFilter('handlerIdentifier', PayPalExpressPayment::class));
$criteria->addFilter(new EqualsFilter('active', true));
$criteria->addFilter(new EqualsFilter('salesChannels.id', $context->getSalesChannelId()));

/** @var array<string> $paymentMethods */
$paymentMethods = $this->repoPaymentMethods->getRepository()->searchIds($criteria, $context->getContext())->getIds();

if (count($paymentMethods) <= 0) {
throw new \Exception('Payment Method PayPal Express not found in system');
}

return (string)$paymentMethods[0];
}


Expand Down
8 changes: 4 additions & 4 deletions src/Components/RefundManager/RefundManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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;
use Kiener\MolliePayments\Components\RefundManager\Request\RefundRequest;
Expand All @@ -33,6 +32,7 @@
use Shopware\Core\Checkout\Order\Aggregate\OrderLineItem\OrderLineItemEntity;
use Shopware\Core\Checkout\Order\OrderEntity;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;

Expand Down Expand Up @@ -74,7 +74,7 @@ class RefundManager implements RefundManagerInterface
private $flowBuilderEventFactory;

/**
* @var RefundRepositoryInterface
* @var EntityRepository
*/
protected $refundRepository;

Expand All @@ -93,7 +93,7 @@ class RefundManager implements RefundManagerInterface
* @param FlowBuilderFactoryInterface $flowBuilderFactory
* @param FlowBuilderEventFactory $flowBuilderEventFactory
* @param StockManagerInterface $stockUpdater
* @param RefundRepositoryInterface $refundRepository
* @param EntityRepository $refundRepository
* @param LoggerInterface $logger
*/
public function __construct(
Expand All @@ -104,7 +104,7 @@ public function __construct(
FlowBuilderFactoryInterface $flowBuilderFactory,
FlowBuilderEventFactory $flowBuilderEventFactory,
StockManagerInterface $stockUpdater,
RefundRepositoryInterface $refundRepository,
EntityRepository $refundRepository,
RefundCreditNoteService $creditNoteService,
LoggerInterface $logger
) {
Expand Down
8 changes: 4 additions & 4 deletions src/Components/Subscription/Actions/RemindAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
use Kiener\MolliePayments\Components\Subscription\Services\SubscriptionHistory\SubscriptionHistoryHandler;
use Kiener\MolliePayments\Components\Subscription\Services\SubscriptionReminder\ReminderValidator;
use Kiener\MolliePayments\Gateway\MollieGatewayInterface;
use Kiener\MolliePayments\Repository\SalesChannel\SalesChannelRepositoryInterface;
use Kiener\MolliePayments\Service\CustomerService;
use Kiener\MolliePayments\Service\SettingsService;
use Psr\Log\LoggerInterface;
use Shopware\Core\Checkout\Customer\CustomerEntity;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\System\SalesChannel\SalesChannelEntity;

class RemindAction extends BaseAction
{
/**
* @var SalesChannelRepositoryInterface
* @var EntityRepository
*/
private $repoSalesChannel;

Expand All @@ -55,11 +55,11 @@ class RemindAction extends BaseAction
* @param FlowBuilderEventFactory $flowBuilderEventFactory
* @param SubscriptionHistoryHandler $subscriptionHistory
* @param LoggerInterface $logger
* @param SalesChannelRepositoryInterface $repoSalesChannel
* @param EntityRepository $repoSalesChannel
* @param ReminderValidator $reminderValidator
* @throws Exception
*/
public function __construct(SettingsService $pluginSettings, SubscriptionRepository $repoSubscriptions, SubscriptionBuilder $subscriptionBuilder, MollieDataBuilder $mollieRequestBuilder, CustomerService $customers, MollieGatewayInterface $gwMollie, CancellationValidator $cancellationValidator, FlowBuilderFactory $flowBuilderFactory, FlowBuilderEventFactory $flowBuilderEventFactory, SubscriptionHistoryHandler $subscriptionHistory, LoggerInterface $logger, SalesChannelRepositoryInterface $repoSalesChannel, ReminderValidator $reminderValidator)
public function __construct(SettingsService $pluginSettings, SubscriptionRepository $repoSubscriptions, SubscriptionBuilder $subscriptionBuilder, MollieDataBuilder $mollieRequestBuilder, CustomerService $customers, MollieGatewayInterface $gwMollie, CancellationValidator $cancellationValidator, FlowBuilderFactory $flowBuilderFactory, FlowBuilderEventFactory $flowBuilderEventFactory, SubscriptionHistoryHandler $subscriptionHistory, LoggerInterface $logger, EntityRepository $repoSalesChannel, ReminderValidator $reminderValidator)
{
parent::__construct(
$pluginSettings,
Expand Down
Loading
Loading