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

BP-3894-Fix-An-error-has-happened-during-application-run-Apple-Pay #1112

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
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
Loading