<?php
declare(strict_types=1);
namespace customScheduleContentNotifierPlugin;
use MagentoCatalogStagingModelProductApplier;
use customScheduleContentNotifierHelperEmail;
use MagentoCatalogModelIndexerProductCategory;
use MagentoCatalogModelResourceModelProduct;
use MagentoCatalogModelResourceModelProductCollection;
use MagentoCatalogStagingHelperReindexPool;
use MagentoFrameworkIndexerCacheContext;
use MagentoFrameworkIndexerIndexerRegistry;
use MagentoStagingModelStagingApplierInterface;
use MagentoStagingModelVersionManager;
use MagentoStagingApiUpdateRepositoryInterface;
use MagentoCatalogModelResourceModelProductCollectionFactory;
class PluginProductApplier
{
protected $emailHelper;
protected $_productCollectionFactory;
/**
* @var UpdateRepositoryInterface
*/
protected $updateRepository;
/**
* @var Collection
*/
protected $productCollectionResource;
/**
* @var ReindexPool
*/
protected $indexerPool;
/**
* @var IndexerRegistry
*/
protected $indexerRegistry;
/**
* @var CacheContext
*/
protected $cacheContext;
/**
* @param UpdateRepositoryInterface $updateRepository
* @param Collection $productResource
* @param ReindexPool $indexerPool
* @param IndexerRegistry $indexerRegistry
* @param CacheContext $cacheContext
*/
public function __construct(
Collection $productResource,
ReindexPool $indexerPool,
IndexerRegistry $indexerRegistry,
CacheContext $cacheContext,
UpdateRepositoryInterface $updateRepository,
Email $emailHelper,
CollectionFactory $productCollectionFactory,
array $data = []
) {
$this->updateRepository = $updateRepository;
$this->productCollectionResource = $productResource;
$this->indexerPool = $indexerPool;
$this->indexerRegistry = $indexerRegistry;
$this->cacheContext = $cacheContext;
$this->emailHelper = $emailHelper;
$this->_productCollectionFactory = $productCollectionFactory;
}
/**
* {@inheritdoc}
*/
public function aroundExecute(ProductApplier $subject, callable $proceed, array $entityIds)
{
if($entityIds) {
$currentVersionId = $this->updateRepository->getVersionMaxIdByTime(strtotime('now'));
$productcollection = $this->_productCollectionFactory->create();
$productcollection->addAttributeToFilter('entity_id', ['in' => $entityIds]);
$productcollection->addAttributeToFilter('created_in', $currentVersionId);
echo $productcollection->getSelect();
die();
if ($currentVersionId === $createdAt) {
$this->emailHelper->sendEmail();
}
}
}
}