Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Product.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Sitemap\Model\ResourceModel\Catalog\ProductFactory;
10 use Magento\Sitemap\Model\SitemapItemInterfaceFactory;
11 
13 {
19  private $productFactory;
20 
26  private $itemFactory;
27 
33  private $configReader;
34 
42  public function __construct(
43  ConfigReaderInterface $configReader,
44  ProductFactory $productFactory,
45  SitemapItemInterfaceFactory $itemFactory
46  ) {
47  $this->productFactory = $productFactory;
48  $this->itemFactory = $itemFactory;
49  $this->configReader = $configReader;
50  }
51 
55  public function getItems($storeId)
56  {
57  $collection = $this->productFactory->create()
58  ->getCollection($storeId);
59 
60  $items = array_map(function ($item) use ($storeId) {
61  return $this->itemFactory->create([
62  'url' => $item->getUrl(),
63  'updatedAt' => $item->getUpdatedAt(),
64  'images' => $item->getImages(),
65  'priority' => $this->configReader->getPriority($storeId),
66  'changeFrequency' => $this->configReader->getChangeFrequency($storeId),
67  ]);
68  }, $collection);
69 
70  return $items;
71  }
72 }
__construct(ConfigReaderInterface $configReader, ProductFactory $productFactory, SitemapItemInterfaceFactory $itemFactory)
Definition: Product.php:42
$items