Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-kl1 committed Jan 4, 2022
1 parent 5899d3a commit 9463c72
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
15 changes: 7 additions & 8 deletions Model/CanShowPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,19 @@ public function canShowPrice(int $customerGroupId): bool

private function isEnabled(): bool
{
return $this->isEnabled ?? $this->isEnabled = $this->scopeConfig->isSetFlag(
return $this->isEnabled ??= $this->scopeConfig->isSetFlag(
self::CONFIG_PATH_RESTRICT_SHOW_PRICE,
ScopeInterface::SCOPE_WEBSITE
);
}

private function resolveAllowedGroups(): array
{
return $this->allowedGroups
?? $this->allowedGroups = array_map('\intval', array_filter(
explode(',', (string) $this->scopeConfig->getValue(
self::CONFIG_PATH_CAN_SHOW_PRICE_GROUPS,
ScopeInterface::SCOPE_WEBSITE
))
));
return $this->allowedGroups ??= array_map('\intval', array_filter(
explode(',', (string) $this->scopeConfig->getValue(
self::CONFIG_PATH_CAN_SHOW_PRICE_GROUPS,
ScopeInterface::SCOPE_WEBSITE
))
));
}
}
15 changes: 7 additions & 8 deletions Model/IsSaleable.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,19 @@ public function isSaleable(int $customerGroupId): bool

private function isEnabled(): bool
{
return $this->isEnabled ?? $this->isEnabled = $this->scopeConfig->isSetFlag(
return $this->isEnabled ??= $this->scopeConfig->isSetFlag(
self::CONFIG_PATH_RESTRICT_SALEABLE,
ScopeInterface::SCOPE_WEBSITE
);
}

private function resolveAllowedGroups(): array
{
return $this->allowedGroups
?? $this->allowedGroups = array_map('\intval', array_filter(
explode(',', (string) $this->scopeConfig->getValue(
self::CONFIG_PATH_IS_SALEABLE_GROUPS,
ScopeInterface::SCOPE_WEBSITE
))
));
return $this->allowedGroups ??= array_map('\intval', array_filter(
explode(',', (string) $this->scopeConfig->getValue(
self::CONFIG_PATH_IS_SALEABLE_GROUPS,
ScopeInterface::SCOPE_WEBSITE
))
));
}
}
2 changes: 1 addition & 1 deletion Plugin/Saleable/CanShowPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(
$this->canShowPrice = $canShowPrice;
}

public function afterGetData(Product $product, $result, $key = '')
public function afterGetData(Product $product, $result, $key = null)
{
if ($key === 'can_show_price') {
$groupId = $this->httpContext->getValue(CustomerContext::CONTEXT_GROUP);
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ The configuration for this module is available in 'Stores > Configuration > Sale
If you need to determine the rules by products, create new product attributes:

- can_show_price (yes/no) The module has a plugin to enforce the type result to be a boolean.
- salable (yes/no) The module has a plugin to enforce the type result to be a boolean.
- is_purchasable (yes/no)

Do not create the following attributes as they are already in use internally by field alias and internal flag:

- is_salable
- salable

Magento will automatically handle these attributes to check if a product is saleable or its price can be displayed.

Expand Down

0 comments on commit 9463c72

Please sign in to comment.