Skip to content

Commit

Permalink
[TASK] "Out of stock" message improved
Browse files Browse the repository at this point in the history
* Parantheses included in translation value.
* Added parameter to ViewHelper for easy switch
  whether message shall be shown in select options
  or not.
  • Loading branch information
rintisch committed Oct 11, 2024
1 parent fb265fc commit ddf73b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions Classes/ViewHelpers/Form/VariantSelectViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class VariantSelectViewHelper extends AbstractViewHelper

public function __construct(
private readonly Context $context,
) {}
)
{
}

/**
* Initialize arguments.
Expand All @@ -53,6 +55,7 @@ public function initializeArguments(): void
$this->registerArgument('name', 'string', 'name for select');
$this->registerArgument('blank', 'string', 'blank adds blank option');
$this->registerArgument('required', 'bool', 'required adds html5 required', false, true);
$this->registerArgument('showOutOfStockMessage', 'bool', 'render "out of stock" in select field', false, true);
}

/**
Expand Down Expand Up @@ -167,11 +170,14 @@ protected function getOptions(): array
$disabled = '';
if (!$beVariant->getIsAvailable() && $beVariant->getProduct()->isHandleStockInVariants()) {
$disabled = 'disabled';
$labelOutofStock = LocalizationUtility::translate(
'tx_cartproducts.stock.out_of_stock',
'cart_products'
);
$optionLabel .= ' (' . $labelOutofStock . ')';

if ($this->arguments['showOutOfStockMessage']) {
$labelOutofStock = LocalizationUtility::translate(
'tx_cartproducts.stock.out_of_stock',
'cart_products'
);
$optionLabel .= $labelOutofStock;
}
}

if ($beVariant->getProduct()->isHandleStockInVariants()) {
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
<source>Not in stock</source>
</trans-unit>
<trans-unit id="tx_cartproducts.stock.out_of_stock">
<source>out of stock</source>
<source> (out of stock)</source>
</trans-unit>

</body>
Expand Down

0 comments on commit ddf73b5

Please sign in to comment.