Skip to content

Commit

Permalink
PIPRES-346: Voucher visibility fix (#829)
Browse files Browse the repository at this point in the history
* PIPRES-346: Voucher visibility fix

* reverted back logic
  • Loading branch information
mandan2 authored Oct 16, 2023
1 parent e672e61 commit 3fa88fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/Service/VoucherService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Validator/VoucherValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ 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;
}

foreach ($products as $product) {
$voucherCategory = $this->voucherService->getProductCategory($product);

if ($voucherCategory) {
return true;
}
Expand Down

0 comments on commit 3fa88fd

Please sign in to comment.