diff --git a/Block/Catalog/Product/View/Applepay.php b/Block/Catalog/Product/View/Applepay.php index 5c7bbae2c..450a70ab0 100644 --- a/Block/Catalog/Product/View/Applepay.php +++ b/Block/Catalog/Product/View/Applepay.php @@ -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; @@ -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()); } /** diff --git a/Model/ConfigProvider/Method/Applepay.php b/Model/ConfigProvider/Method/Applepay.php index 25742fa96..c9a69ce88 100644 --- a/Model/ConfigProvider/Method/Applepay.php +++ b/Model/ConfigProvider/Method/Applepay.php @@ -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)); } /**