From 46542ad66fa29ce4cc792fb3d309003e27b0ac2e Mon Sep 17 00:00:00 2001 From: "nicole.norman" Date: Mon, 16 Dec 2024 09:55:51 -0600 Subject: [PATCH] Add PageSource to sdk payment options --- .../AddExpressPayButtonsObserver.php | 19 ++++++++++-- UI/PaymentBoosterConfigProvider.php | 5 +-- view/frontend/layout/catalog_product_view.xml | 22 ------------- view/frontend/layout/checkout_cart_index.xml | 14 --------- view/frontend/layout/checkout_index_index.xml | 3 ++ view/frontend/templates/express-pay.phtml | 6 ++-- .../frontend/web/js/express-pay-storefront.js | 31 +++---------------- view/frontend/web/js/view/bold-express-pay.js | 3 +- 8 files changed, 34 insertions(+), 69 deletions(-) delete mode 100644 view/frontend/layout/catalog_product_view.xml delete mode 100644 view/frontend/layout/checkout_cart_index.xml diff --git a/Observer/ShortcutButtons/AddExpressPayButtonsObserver.php b/Observer/ShortcutButtons/AddExpressPayButtonsObserver.php index 4d920787..8d1a8c5c 100644 --- a/Observer/ShortcutButtons/AddExpressPayButtonsObserver.php +++ b/Observer/ShortcutButtons/AddExpressPayButtonsObserver.php @@ -43,15 +43,30 @@ public function execute(Observer $observer): void /** @var ExpressPayShortcutButtons $expressPayShortcutButtons */ $expressPayShortcutButtons = $layout->createBlock( ExpressPayShortcutButtons::class, - ExpressPayShortcutButtons::BLOCK_ALIAS, + '', [ 'data' => [ 'express_pay_view_model' => $this->expressPayFactory->create(), - 'render_page_source' => PaymentBoosterConfigProvider::PAGE_SOURCE_MINICART + 'render_page_source' => $this->getPageType($observer->getEvent()) ] ] ); $container->addShortcut($expressPayShortcutButtons); } + + /** + * @param $event + * @return string + */ + private function getPageType($event) : string + { + if ($event->getIsCatalogProduct()) { + return PaymentBoosterConfigProvider::PAGE_SOURCE_PRODUCT; + } + if ($event->getIsShoppingCart()) { + return PaymentBoosterConfigProvider::PAGE_SOURCE_CART; + } + return PaymentBoosterConfigProvider::PAGE_SOURCE_MINICART; + } } diff --git a/UI/PaymentBoosterConfigProvider.php b/UI/PaymentBoosterConfigProvider.php index 498aa4b7..3086b20e 100644 --- a/UI/PaymentBoosterConfigProvider.php +++ b/UI/PaymentBoosterConfigProvider.php @@ -20,9 +20,10 @@ class PaymentBoosterConfigProvider implements ConfigProviderInterface { - public const PAGE_SOURCE_PRODUCT = 'product'; + public const PAGE_SOURCE_PRODUCT = 'product-details'; public const PAGE_SOURCE_CART = 'cart'; public const PAGE_SOURCE_MINICART = 'mini-cart'; + public const PAGE_SOURCE_CHECKOUT = 'checkout'; /** * @var CheckoutData @@ -113,7 +114,7 @@ public function getConfig(): array if ($epsGatewayId === null) { $errorMsgs[] = '$epsGatewayId is null.'; } - + $this->logger->critical('Error in PaymentBoosterConfigProvider->getConfig(): '.implode(', ', $errorMsgs)); return []; } diff --git a/view/frontend/layout/catalog_product_view.xml b/view/frontend/layout/catalog_product_view.xml deleted file mode 100644 index 9182e18f..00000000 --- a/view/frontend/layout/catalog_product_view.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - Bold\CheckoutPaymentBooster\ViewModel\ExpressPay - Bold\CheckoutPaymentBooster\UI\PaymentBoosterConfigProvider::PAGE_SOURCE_PRODUCT - - - - - - - Bold\CheckoutPaymentBooster\ViewModel\ExpressPay - Bold\CheckoutPaymentBooster\UI\PaymentBoosterConfigProvider::PAGE_SOURCE_PRODUCT - - - - - diff --git a/view/frontend/layout/checkout_cart_index.xml b/view/frontend/layout/checkout_cart_index.xml deleted file mode 100644 index 1095aa4a..00000000 --- a/view/frontend/layout/checkout_cart_index.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - Bold\CheckoutPaymentBooster\ViewModel\ExpressPay - Bold\CheckoutPaymentBooster\UI\PaymentBoosterConfigProvider::PAGE_SOURCE_CART - - - - - diff --git a/view/frontend/layout/checkout_index_index.xml b/view/frontend/layout/checkout_index_index.xml index 57890d61..b04ee1cb 100644 --- a/view/frontend/layout/checkout_index_index.xml +++ b/view/frontend/layout/checkout_index_index.xml @@ -13,6 +13,9 @@ Bold_CheckoutPaymentBooster/js/view/bold-express-pay 0 + + Bold\CheckoutPaymentBooster\UI\PaymentBoosterConfigProvider::PAGE_SOURCE_CHECKOUT + diff --git a/view/frontend/templates/express-pay.phtml b/view/frontend/templates/express-pay.phtml index e0cbefb6..f9716484 100644 --- a/view/frontend/templates/express-pay.phtml +++ b/view/frontend/templates/express-pay.phtml @@ -11,6 +11,7 @@ use Bold\CheckoutPaymentBooster\ViewModel\ExpressPay; $expressPayViewModel = $block->getData('express_pay_view_model'); $pageSource = $block->getData('render_page_source'); $isEnabled = $expressPayViewModel->isEnabled($pageSource); +$containerId = 'express-pay-buttons-' . $pageSource; if (!$isEnabled): return; @@ -18,7 +19,7 @@ endif; ?>
-
+