ProductPagePaymentLink.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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\Block;
  17. use Amazon\Core\Helper\CategoryExclusion;
  18. use Amazon\Core\Helper\Data;
  19. use Magento\Catalog\Model\Product;
  20. use Magento\Framework\Registry;
  21. use Magento\Framework\View\Element\Template;
  22. use Magento\Framework\View\Element\Template\Context;
  23. /**
  24. * @api
  25. */
  26. class ProductPagePaymentLink extends PaymentLink
  27. {
  28. /**
  29. * @var CategoryExclusion
  30. */
  31. protected $categoryExclusionHelper;
  32. /**
  33. * @var Registry
  34. */
  35. private $registry;
  36. /**
  37. * @param Context $context
  38. * @param Data $coreHelper
  39. * @param CategoryExclusion $categoryExclusionHelper
  40. * @param Registry $registry
  41. * @param array $data
  42. */
  43. public function __construct(
  44. Context $context,
  45. Data $coreHelper,
  46. CategoryExclusion $categoryExclusionHelper,
  47. Registry $registry,
  48. array $data = []
  49. ) {
  50. parent::__construct($context, $coreHelper, $categoryExclusionHelper, $data);
  51. $this->registry = $registry;
  52. }
  53. /**
  54. * {@inheritdoc}
  55. */
  56. protected function _toHtml()
  57. {
  58. if (! $this->coreHelper->isPwaButtonVisibleOnProductPage()) {
  59. return '';
  60. }
  61. /** @var \Magento\Catalog\Model\Product $product */
  62. $product = $this->registry->registry('product');
  63. if ($product instanceof Product &&
  64. $this->categoryExclusionHelper->productHasExcludedCategory($product)
  65. ) {
  66. return '';
  67. }
  68. return parent::_toHtml();
  69. }
  70. }