From e777d68393e53f24034e0f4a96e82bbfcd9adaa1 Mon Sep 17 00:00:00 2001 From: Emmanouil Stafilarakis Date: Fri, 21 Feb 2020 10:35:53 +0100 Subject: [PATCH] REWORK review annotations --- src/Helper/SettingsHelper.php | 10 ++++---- src/Methods/InvoicePaymentMethod.php | 27 +++++++++------------- src/Services/InvoiceLimitationsService.php | 23 +++++++++--------- 3 files changed, 28 insertions(+), 32 deletions(-) diff --git a/src/Helper/SettingsHelper.php b/src/Helper/SettingsHelper.php index 916c6bc..3df1836 100644 --- a/src/Helper/SettingsHelper.php +++ b/src/Helper/SettingsHelper.php @@ -70,7 +70,7 @@ public function hasActiveCountries(): bool */ public function minimumAmount(): float { - return (float)$this->getSettingFloatValue('minimumAmount'); + return $this->getSettingFloatValue('minimumAmount'); } /** @@ -80,17 +80,17 @@ public function minimumAmount(): float */ public function maximumAmount(): float { - return (float)$this->getSettingFloatValue('maximumAmount'); + return $this->getSettingFloatValue('maximumAmount'); } /** - * Get the minimum amount for using the payment method. + * Get the minimum order count for using the payment method. * - * @return float + * @return int */ public function minimumOrderCount(): int { - return (int)$this->getSettingIntValue('quorumOrders'); + return $this->getSettingIntValue('quorumOrders'); } /** diff --git a/src/Methods/InvoicePaymentMethod.php b/src/Methods/InvoicePaymentMethod.php index b442123..1a9259c 100755 --- a/src/Methods/InvoicePaymentMethod.php +++ b/src/Methods/InvoicePaymentMethod.php @@ -12,7 +12,6 @@ use Plenty\Modules\Frontend\Services\AccountService; use Plenty\Modules\Frontend\Services\SystemService; use Plenty\Modules\Order\Contracts\OrderRepositoryContract; -use Plenty\Modules\Order\Models\OrderAmount; use Plenty\Plugin\Application; use Plenty\Modules\Frontend\Contracts\Checkout; use Plenty\Modules\Payment\Method\Contracts\PaymentMethodService; @@ -82,21 +81,18 @@ public function isActive( BasketRepositoryContract $basketRepositoryContract):bo $isGuest = !($this->accountService->getIsAccountLoggedIn() && $basket->customerId > 0); $contact = null; - if(!$isGuest && $basket->customerId > 0) { + if(!$isGuest) { try { $contact = $contactRepo->findContactById($basket->customerId, ['orderSummary']); } catch(\Exception $ex) {} } - $amount = $amount = pluginApp(OrderAmount::class); - $amount->currency = $basket->currency; - $amount->invoiceTotal = $basket->basketAmount; - return $helper->respectsAllLimitations( pluginApp(SettingsHelper::class, [$this->settings, $this->systemService->getPlentyId()]), - $isGuest, - $amount, $this->checkout->getShippingCountryId(), + $isGuest, + $basket->basketAmount, + $basket->currency, $this->checkout->getCustomerInvoiceAddressId(), $this->checkout->getCustomerShippingAddressId(), $contact @@ -224,9 +220,10 @@ public function isSwitchableTo(int $orderId = null):bool return $helper->respectsAllLimitations( pluginApp(SettingsHelper::class, [$this->settings, $order->plentyId]), - $contact === null, - $order->amount, $order->deliveryAddress->countryId, + $contact === null || $contact->singleAccess === "1", + $order->amount->invoiceTotal, + $order->amount->currency, $order->billingAddress->id, $order->deliveryAddress->id, $contact @@ -245,20 +242,18 @@ public function isSwitchableTo(int $orderId = null):bool $basket = $basketRepo->load(); $isGuest = !($this->accountService->getIsAccountLoggedIn() && $basket->customerId > 0); $contact = null; - if(!$isGuest && $basket->customerId > 0) { + if(!$isGuest) { try { $contact = $contactRepo->findContactById($basket->customerId, ['orderSummary']); } catch(\Exception $ex) {} } - $amount = pluginApp(OrderAmount::class); - $amount->currency = $basket->currency; - $amount->invoiceTotal = $basket->basketAmount; return $helper->respectsAllLimitations( pluginApp(SettingsHelper::class, [$this->settings, $this->systemService->getPlentyId()]), - $isGuest, - $amount, $this->checkout->getShippingCountryId(), + $isGuest, + $basket->basketAmount, + $basket->currency, $this->checkout->getCustomerInvoiceAddressId(), $this->checkout->getCustomerShippingAddressId(), $contact diff --git a/src/Services/InvoiceLimitationsService.php b/src/Services/InvoiceLimitationsService.php index 9930957..8dbaf07 100644 --- a/src/Services/InvoiceLimitationsService.php +++ b/src/Services/InvoiceLimitationsService.php @@ -6,7 +6,6 @@ use Plenty\Modules\Account\Contact\Models\Contact; use Plenty\Modules\Account\Contact\Models\ContactAllowedMethodOfPayment; use Plenty\Modules\Frontend\Contracts\CurrencyExchangeRepositoryContract; -use Plenty\Modules\Order\Models\OrderAmount; /** * Class InvoiceLimitationsService @@ -21,9 +20,10 @@ class InvoiceLimitationsService * Get whether all payment method limitations are respected or not. * * @param SettingsHelper $settingsHelper The setting helper - * @param bool $isGuest Whether or not the current customer is a guest or not - * @param OrderAmount $amount The total amount * @param int $shippingCountryId The ID of the shipping country + * @param bool $isGuest Whether or not the current customer is a guest or not + * @param float $amount The total amount + * @param string $currency The current currency * @param int $billingAddressId The ID of the billing address * @param int $deliveryAddressId The ID of the delivery address * @param Contact|null $contact The contact instance, if customer is not a quest @@ -32,9 +32,10 @@ class InvoiceLimitationsService */ public function respectsAllLimitations( SettingsHelper $settingsHelper, - bool $isGuest, - OrderAmount $amount, int $shippingCountryId, + bool $isGuest, + float $amount, + string $currency = 'EUR', int $billingAddressId = null, int $deliveryAddressId = null, Contact $contact = null @@ -58,7 +59,7 @@ public function respectsAllLimitations( } // Third: Check the addresses - // Addresses are equal when: $deliveryAddressId === null || $billingAddressId === $deliveryAddressId + // Addresses are equal when: $deliveryAddressId === null || $billingAddressId === $deliveryAddressId if($settingsHelper->shouldHaveIdenticalAddresses() && $deliveryAddressId !== null && $billingAddressId !== $deliveryAddressId) { return false; } @@ -76,19 +77,19 @@ public function respectsAllLimitations( } } - if($amount->invoiceTotal > 0.0) { + if($amount > 0.0) { /** @var CurrencyExchangeRepositoryContract $currencyService */ $currencyService = pluginApp(CurrencyExchangeRepositoryContract::class); // Fifth: Check minimum amount - $minAmount = (float)$currencyService->convertFromDefaultCurrency($amount->currency, $settingsHelper->minimumAmount()); - if($minAmount > 0.0 && $minAmount > $amount->invoiceTotal) { + $minAmount = (float)$currencyService->convertFromDefaultCurrency($currency, $settingsHelper->minimumAmount()); + if($minAmount > 0.0 && $minAmount > $amount) { return false; } // Sixth: Check maximum amount - $maxAmount = (float)$currencyService->convertFromDefaultCurrency($amount->currency, $settingsHelper->maximumAmount()); - if($maxAmount > 0.0 && $maxAmount < $amount->invoiceTotal) { + $maxAmount = (float)$currencyService->convertFromDefaultCurrency($currency, $settingsHelper->maximumAmount()); + if($maxAmount > 0.0 && $maxAmount < $amount) { return false; } }