diff --git a/src/Service/VoucherService.php b/src/Service/VoucherService.php index 8820327f4..07acd6341 100644 --- a/src/Service/VoucherService.php +++ b/src/Service/VoucherService.php @@ -46,17 +46,20 @@ public function getVoucherCategory(array $cartItem, $selectedVoucherCategory) } } - public function getProductCategory(array $cartItem) + public function getProductCategory(array $cartItem): string { if (!isset($cartItem['features'])) { return ''; } + $idFeatureValue = false; + foreach ($cartItem['features'] as $feature) { - if (!$this->isVoucherFeature($feature['id_feature'])) { + if (!$this->isVoucherFeature((int) $feature['id_feature'])) { continue; } - $idFeatureValue = $feature['id_feature_value']; + + $idFeatureValue = (int) $feature['id_feature_value']; } if (!$idFeatureValue) { @@ -66,15 +69,15 @@ public function getProductCategory(array $cartItem) return $this->getVoucherCategoryByFeatureValueId($idFeatureValue); } - private function isVoucherFeature($featureId) + private function isVoucherFeature(int $featureId): bool { - return (int) $this->configuration->get(Config::MOLLIE_VOUCHER_FEATURE_ID) === (int) $featureId; + return (int) $this->configuration->get(Config::MOLLIE_VOUCHER_FEATURE_ID) === $featureId; } - private function getVoucherCategoryByFeatureValueId($idFeatureValue) + private function getVoucherCategoryByFeatureValueId(int $idFeatureValue): string { foreach (Config::MOLLIE_VOUCHER_CATEGORIES as $key => $categoryName) { - if ($this->configuration->get(Config::MOLLIE_VOUCHER_FEATURE . $key) === $idFeatureValue) { + if ((int) $this->configuration->get(Config::MOLLIE_VOUCHER_FEATURE . $key) === $idFeatureValue) { return $key; } } diff --git a/src/Validator/VoucherValidator.php b/src/Validator/VoucherValidator.php index c885a1310..36fd54715 100644 --- a/src/Validator/VoucherValidator.php +++ b/src/Validator/VoucherValidator.php @@ -34,7 +34,7 @@ public function __construct(ConfigurationAdapter $configuration, VoucherService $this->voucherService = $voucherService; } - public function validate(array $products) + public function validate(array $products): bool { if (Config::MOLLIE_VOUCHER_CATEGORY_NULL !== $this->configuration->get(Config::MOLLIE_VOUCHER_CATEGORY)) { return true; @@ -42,6 +42,7 @@ public function validate(array $products) foreach ($products as $product) { $voucherCategory = $this->voucherService->getProductCategory($product); + if ($voucherCategory) { return true; }