Skip to content

Commit

Permalink
Merge pull request #18 from plentymarkets/fix/respecting_all_limitations
Browse files Browse the repository at this point in the history
FIX all settings / restrictions are now queried correctly
  • Loading branch information
estafilarakis authored Feb 25, 2020
2 parents 92797d6 + a1c567b commit 1134f6f
Show file tree
Hide file tree
Showing 7 changed files with 353 additions and 115 deletions.
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-25)
### Gefixt
- 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-25)
### Fixed
- 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 $this->getSettingFloatValue('minimumAmount');
}

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

/**
* Get the minimum order count for using the payment method.
*
* @return int
*/
public function minimumOrderCount(): int
{
return $this->getSettingIntValue('quorumOrders');
}

/**
* 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

0 comments on commit 1134f6f

Please sign in to comment.