CheckoutProcessor.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License").
  6. * You may not use this file except in compliance with the License.
  7. * A copy of the License is located at
  8. *
  9. * http://aws.amazon.com/apache2.0
  10. *
  11. * or in the "license" file accompanying this file. This file is distributed
  12. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  13. * express or implied. See the License for the specific language governing
  14. * permissions and limitations under the License.
  15. */
  16. namespace Amazon\Payment\Plugin;
  17. use Amazon\Core\Helper\Data;
  18. use Magento\Checkout\Model\Session;
  19. class CheckoutProcessor
  20. {
  21. /**
  22. * @var Data
  23. */
  24. private $amazonHelper;
  25. /**
  26. * @var Session
  27. */
  28. private $checkoutSession;
  29. /**
  30. * CheckoutProcessor constructor.
  31. *
  32. * @param Data $amazonHelper
  33. * @param Session $checkoutSession
  34. */
  35. public function __construct(
  36. Data $amazonHelper,
  37. Session $checkoutSession
  38. ) {
  39. $this->amazonHelper = $amazonHelper;
  40. $this->checkoutSession = $checkoutSession;
  41. }
  42. /**
  43. * Checkout LayoutProcessor after process plugin.
  44. *
  45. * @param \Magento\Checkout\Block\Checkout\LayoutProcessor $processor
  46. * @param array $jsLayout
  47. * @return array
  48. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  49. */
  50. public function afterProcess(\Magento\Checkout\Block\Checkout\LayoutProcessor $processor, $jsLayout)
  51. {
  52. $quote = $this->checkoutSession->getQuote();
  53. $shippingConfig = &$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
  54. ['children']['shippingAddress'];
  55. $paymentConfig = &$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']
  56. ['children']['payment'];
  57. if (!$quote->isVirtual() && $this->amazonHelper->isPwaEnabled()) {
  58. $shippingConfig['component'] = 'Amazon_Payment/js/view/shipping';
  59. $shippingConfig['children']['customer-email']['component'] = 'Amazon_Payment/js/view/form/element/email';
  60. $shippingConfig['children']['address-list']['component'] = 'Amazon_Payment/js/view/shipping-address/list';
  61. $shippingConfig['children']['shipping-address-fieldset']['children']
  62. ['inline-form-manipulator']['component'] = 'Amazon_Payment/js/view/shipping-address/inline-form';
  63. $paymentConfig['children']['payments-list']['component'] = 'Amazon_Payment/js/view/payment/list';
  64. } else {
  65. unset($shippingConfig['children']['customer-email']['children']['amazon-button-region']);
  66. unset($shippingConfig['children']['before-form']['children']['amazon-widget-address']);
  67. unset($paymentConfig['children']['renders']['children']['amazon_payment']);
  68. unset($paymentConfig['children']['beforeMethods']['children']['amazon-sandbox-simulator']);
  69. unset($paymentConfig['children']['payments-list']['children']['amazon_payment-form']);
  70. }
  71. return $jsLayout;
  72. }
  73. }