0
<?php
declare(strict_types=1);

namespace custom\ScheduleContentNotifier\Plugin;

use Magento\CatalogStaging\Model\ProductApplier;
use custom\ScheduleContentNotifier\Helper\Email;
use Magento\Catalog\Model\Indexer\Product\Category;
use Magento\Catalog\Model\ResourceModel\Product;
use Magento\Catalog\Model\ResourceModel\Product\Collection;
use Magento\CatalogStaging\Helper\ReindexPool;
use Magento\Framework\Indexer\CacheContext;
use Magento\Framework\Indexer\IndexerRegistry;
use Magento\Staging\Model\StagingApplierInterface;
use Magento\Staging\Model\VersionManager;
use Magento\Staging\Api\UpdateRepositoryInterface;



class PluginProductApplier
{
    protected $emailHelper;



    /**
     * @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,
    ) {
        $this->updateRepository = $updateRepository;
        $this->productCollectionResource = $productResource;
        $this->indexerPool = $indexerPool;
        $this->indexerRegistry = $indexerRegistry;
        $this->cacheContext = $cacheContext;
        $this->emailHelper = $emailHelper;
    }

    /**
     * {@inheritdoc}
     */

    public function aroundExecute(ProductApplier $subject)
    {  
        $currentVersionId = $this->updateRepository->getVersionMaxIdByTime(strtotime('now'));

        $this->emailHelper->sendEmail();
    }
}
1
  • share the code of your di.xml file. Commented May 30, 2023 at 12:31

1 Answer 1

2

From what I understand you are building a plugin for this method Magento\CatalogStaging\Model\ProductApplier::execute.

If this is true, then your plugin aroundExecute method should looke like this

public function aroundExecute(ProductApplier $subject, callable $proceed, array $entityIds) 
{
    ....
}

To answer your question, you can get the product ids that are being process from $entityIds.
Now to explain a bit the parameters you need to add to your method.

  • ProductApplier $subject - that's the class instance you are intercepting. You already have this
  • callable $proceed - this is the original method being intercepted. you can call it anywhere inside your plugin to execute the original code like this $proceeed($entityIds). Not calling this will remove any other plugins you have on this method other than this.
  • $entityIds - this represents the parameter(s) of the original method you intercepted. So the product ids where content stating is applied

You can get more info on how around plugins work, and what parameters they accept from the official documentation: https://developer.adobe.com/commerce/php/development/components/plugins/#around-methods

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.