ProductFrontendActionSection.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Catalog\CustomerData;
  7. use Magento\Catalog\Model\Product\ProductFrontendAction\Synchronizer;
  8. use Magento\Catalog\Model\ProductFrontendAction;
  9. use Magento\Customer\CustomerData\SectionSourceInterface;
  10. use Magento\Framework\App\Config;
  11. use Psr\Log\LoggerInterface;
  12. /**
  13. * Generates Product Frontend Action Section in Customer Data
  14. */
  15. class ProductFrontendActionSection implements SectionSourceInterface
  16. {
  17. /**
  18. * Identification of Type of a Product Frontend Action
  19. *
  20. * @var string
  21. */
  22. private $typeId;
  23. /**
  24. * @var Synchronizer
  25. */
  26. private $synchronizer;
  27. /**
  28. * @var LoggerInterface
  29. */
  30. private $logger;
  31. /**
  32. * @var Config
  33. */
  34. private $appConfig;
  35. /**
  36. * @param Synchronizer $synchronizer
  37. * @param string $typeId Identification of Type of a Product Frontend Action
  38. * @param LoggerInterface $logger
  39. * @param Config $appConfig
  40. */
  41. public function __construct(
  42. Synchronizer $synchronizer,
  43. $typeId,
  44. LoggerInterface $logger,
  45. Config $appConfig
  46. ) {
  47. $this->typeId = $typeId;
  48. $this->synchronizer = $synchronizer;
  49. $this->logger = $logger;
  50. $this->appConfig = $appConfig;
  51. }
  52. /**
  53. * Post Process collection data in order to eject all customer sensitive information
  54. *
  55. * {@inheritdoc}
  56. */
  57. public function getSectionData()
  58. {
  59. if (!(bool) $this->appConfig->getValue(Synchronizer::ALLOW_SYNC_WITH_BACKEND_PATH)) {
  60. return [
  61. 'count' => 0,
  62. 'items' => [],
  63. ];
  64. }
  65. $actions = $this->synchronizer->getActionsByType($this->typeId);
  66. $items = [];
  67. /** @var ProductFrontendAction $action */
  68. foreach ($actions as $action) {
  69. $items[$action->getProductId()] = [
  70. 'added_at' => $action->getAddedAt(),
  71. 'product_id' => $action->getProductId(),
  72. ];
  73. }
  74. return [
  75. 'count' => count($items),
  76. 'items' => $items,
  77. ];
  78. }
  79. }