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

FIX all settings / restrictions are now queried correctly #18

Merged
merged 7 commits into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 5 additions & 1 deletion meta/documents/changelog_de.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Release Notes für Kauf auf Rechnung

## 2.0.3 (2019-12-17)
## 2.0.4 (2020-02-17)
### Gefixt
j-konopka marked this conversation as resolved.
Show resolved Hide resolved
- Alle Einstellungen / Beschränkungen werden nun korrekt abgefragt.

## 2.0.3 (2020-02-10)
### Gefixt
- Der Mindest- und Maximalbetrag wird nun korrekt geprüft, wenn der Kunde die Zahlungsart in Mein Konto ändern will.

Expand Down
6 changes: 5 additions & 1 deletion meta/documents/changelog_en.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Release Notes for Invoice

## 2.0.3 (2019-12-17)
## 2.0.4 (2020-02-17)
### Gefixt
- All settings / restrictions are now queried correctly.

## 2.0.3 (20120-02-10)
### Fixed
- The minimum and maximum limit is now checked properly, when a customer wants to change the payment method in an order under My Account.

Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version" : "2.0.3",
"version" : "2.0.4",
"name" : "Invoice",
"marketplaceName" : {"de":"Kauf auf Rechnung","en":"Invoice"},
"license" : "AGPL-3.0",
Expand Down
145 changes: 145 additions & 0 deletions src/Helper/SettingsHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?php

namespace Invoice\Helper;

use Invoice\Services\SettingsService;

/**
* Class SettingsHelper
*
* @author emmanouil.stafilarakis <[email protected]>
*
* @package Invoice\Helper
*/
class SettingsHelper
{
/**
* The current settings
*
* @var SettingsService
*/
private $settings;

/**
* The current plenty id.
*
* @var int
*/
private $plentyId;

/**
* SettingsHelper constructor.
*
* @param SettingsService $settings The settings service
* @param int $plentyId The plenty ID
*/
public function __construct(SettingsService $settings, int $plentyId)
{
$this->settings = $settings;
$this->plentyId = $plentyId;
}

/**
* Get whether the country is active or not
*
* @param int $countryId The country ID to be checked.
*
* @return bool
*/
public function isCountryActive(int $countryId): bool
{
$countries = $this->settings->getShippingCountriesByPlentyId($this->plentyId);
return in_array($countryId, $countries);
}

/**
* Get whether or not the payment method has active countries.
*
* @return bool
*/
public function hasActiveCountries(): bool
{
$countries = $this->settings->getShippingCountriesByPlentyId($this->plentyId);
return count($countries) > 0;
}

/**
* Get the minimum amount for using the payment method.
*
* @return float
*/
public function minimumAmount(): float
{
return (float)$this->getSettingFloatValue('minimumAmount');
}

/**
* Get the maximum amount for using the payment method.
*
* @return float
*/
public function maximumAmount(): float
{
return (float)$this->getSettingFloatValue('maximumAmount');
}

/**
* Get the minimum amount for using the payment method.
*
* @return float
*/
public function minimumOrderCount(): int
{
return (int)$this->getSettingIntValue('quorumOrders');
}
estafilarakis marked this conversation as resolved.
Show resolved Hide resolved

/**
* Get whether the invoice payment is allowed for guests or not.
*
* @return bool
*/
public function guestsAllowed():bool
{
return $this->getSettingIntValue('disallowInvoiceForGuest', 1) != 1;

}

/**
* Get whether the delivery address should equals the billing address or not.
*
* @return bool
*/
public function shouldHaveIdenticalAddresses(): bool
{
return $this->getSettingIntValue('invoiceEqualsShippingAddress', 0) != 0;
}

/**
* Get an integer setting.
*
* @param string $setting The setting key
* @param int $default The default value, if setting key is not set
*
* @return int
*/
private function getSettingIntValue(string $setting, int $default = 0): int
{
$settings = $this->settings->getSettingsForPlentyId($this->plentyId, 'de');
return isset($settings[$setting]) ? (int)$settings[$setting] : $default;
}

/**
* Get a float setting.
*
* @param string $setting The setting key
* @param float $default The default value, if setting key is not set
*
* @return float
*/
private function getSettingFloatValue(string $setting, float $default = 0.0): float
{
$settings = $this->settings->getSettingsForPlentyId($this->plentyId, 'de');
return isset($settings[$setting]) ? (float)$settings[$setting] : $default;
}
}

Loading