Skip to content

Commit

Permalink
Merge pull request #1112 from buckaroo-it/BP-3894-Fix-An-error-has-ha…
Browse files Browse the repository at this point in the history
…ppened-during-application-run-Apple-Pay

BP-3894-Fix-An-error-has-happened-during-application-run-Apple-Pay
  • Loading branch information
vegimcarkaxhija authored Dec 2, 2024
2 parents 5b0c123 + 5406f3e commit f33b491
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
18 changes: 14 additions & 4 deletions Block/Catalog/Product/View/Applepay.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

use Magento\Checkout\Model\Cart;
use Magento\Checkout\Model\CompositeConfigProvider;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Buckaroo\Magento2\Model\ConfigProvider\Method\Applepay as ApplepayConfig;
Expand Down Expand Up @@ -58,13 +59,22 @@ public function __construct(
}

/**
* @param $page
* @return bool
* @throws NoSuchEntityException
*/
public function canShowButton($page)
public function canShowButton($page): bool
{
return $this->isModuleActive() &&
in_array($page, $this->applepayConfigProvider->getAvailableButtons()) &&
$this->applepayConfigProvider->isApplePayEnabled($this->_storeManager->getStore());
if (!$this->isModuleActive()) {
return false;
}

$availableButtons = $this->applepayConfigProvider->getAvailableButtons();
if (!in_array($page, $availableButtons, true)) {
return false;
}

return $this->applepayConfigProvider->isApplePayEnabled($this->_storeManager->getStore());
}

/**
Expand Down
18 changes: 10 additions & 8 deletions Model/ConfigProvider/Method/Applepay.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,21 @@ public function getConfig()
];
}

public function getAvailableButtons()

/**
* @return array
*/
public function getAvailableButtons(): array
{
$availableButtons = $this->scopeConfig->getValue(
$availableButtonsConfig = $this->scopeConfig->getValue(
static::XPATH_APPLEPAY_AVAILABLE_BUTTONS,
ScopeInterface::SCOPE_STORE
);
if ($availableButtons) {
$availableButtons = explode(',', (string)$availableButtons);
} else {
$availableButtons = [];
}

return $availableButtons;
if (!$availableButtonsConfig) {
return [];
}
return array_map('trim', explode(',', (string)$availableButtonsConfig));
}

/**
Expand Down

0 comments on commit f33b491

Please sign in to comment.