From 3fa88fd5c5efd6108c4756e7dcc20396d09632f4 Mon Sep 17 00:00:00 2001 From: mandan2 <61560082+mandan2@users.noreply.github.com> Date: Mon, 16 Oct 2023 17:09:27 +0300 Subject: [PATCH] PIPRES-346: Voucher visibility fix (#829) * PIPRES-346: Voucher visibility fix * reverted back logic --- src/Service/VoucherService.php | 17 ++++++++++------- src/Validator/VoucherValidator.php | 3 ++- 2 files changed, 12 insertions(+), 8 deletions(-) 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; }