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

PIPRES-346: Voucher visibility fix #829

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading