-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathAddApplePayShortcutButton.php
45 lines (38 loc) · 1.32 KB
/
AddApplePayShortcutButton.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace Mollie\Payment\Observer\ShortcutButtonsContainer;
use Magento\Catalog\Block\ShortcutButtons;
use Magento\Checkout\Block\QuoteShortcutButtons;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Mollie\Payment\Block\Applepay\Shortcut\Button;
use Mollie\Payment\Config;
class AddApplePayShortcutButton implements ObserverInterface
{
/**
* @var Config
*/
private $config;
public function __construct(
Config $config
) {
$this->config = $config;
}
public function execute(Observer $observer)
{
// We only want to show this button in the minicart
if ($observer->getData('is_catalog_product') || !$this->isEnabled()) {
return;
}
/** @var ShortcutButtons $shortcutButtons */
$shortcutButtons = $observer->getEvent()->getContainer();
$shortcut = $shortcutButtons->getLayout()->createBlock(Button::class);
$shortcut->setIsCart(get_class($shortcutButtons) === QuoteShortcutButtons::class);
$shortcutButtons->addShortcut($shortcut);
}
private function isEnabled(): bool
{
return $this->config->isProductionMode() &&
$this->config->isMethodActive('mollie_methods_applepay') &&
$this->config->applePayEnableMinicartButton();
}
}