I have added a scheduled update for a product as shown below
Now I want to delete this schedule programatically. How to achieve that?
I see the product staging class Magento\CatalogStaging\Api\ProductStagingInterface
which has a function unschedule($product, $version)
Where I can get the information about the version of a specific product which needs to be passed to this function?
I have used below code as an example to unscedule.
<?php
namespace Vendor\CustomImport\Model;
class Test
{
protected $productStaging;
protected $productRepository;
public function __construct(
\Magento\CatalogStaging\Model\ProductStaging $productStaging,
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository
) {
$this->productStaging = $productStaging;
$this->productRepository = $productRepository;
}
public function deleteSchedule()
{
try {
$product = $this->productRepository->get('24-WG089', true);
$version = 1628165040;
$this->productStaging->unschedule($product, $version);
} catch (\Exception $e){
echo $e->getMessage();
}
}
}
I have taken $version
from catalog_product_entity table created_in
field. After executing above code, product itself gets removed from catalog and cannot be found in admin. Though I can see records for that product in catalog_product_entity table.