<?php

namespace Autogedal\AtcPopup\Controller\Index;


use AllowDynamicProperties;
use Magento\Catalog\Model\CategoryFactory;
use Magento\Catalog\Model\ResourceModel\Product\Collection;
use Magento\Cron\Model\ResourceModel\Schedule\CollectionFactory;
use Magento\Framework\App\Action\Context;

#[AllowDynamicProperties] class Filters extends \Magento\Framework\App\Action\Action
{
    public Collection $productCollectionFactory;

    public function __construct(
        Context $context,
        Collection  $productCollectionFactory,
        CategoryFactory $categoryFactory
    ){
        $this->productCollectionFactory = $productCollectionFactory;
        $this->_categoryFactory = $categoryFactory;
        parent::__construct($context);

    }

    public function execute()
    {
        $categoryId = 2072;
        $category = $this->_categoryFactory->create()->load($categoryId);

        $productcollection = $this->productCollectionFactory
            ->addAttributeToSelect('*')
            ->addCategoryFilter($category);

        foreach ($productcollection as $product)
        {
            echo $product->getId() . ", ";
        }
    }
}
