Put this code in your cron file
/**
* @var \Magento\Framework\Serialize\SerializerInterface
*/
private $serializer;
/**
* @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
*/
private $productCollectionFactory;
public function __construct(
\Magento\Framework\Serialize\SerializerInterface $serializer,
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
) {
$this->serializer = $serializer;
$this->productCollectionFactory = $productCollectionFactory;
}
public function execute()
{
$collection = $this->productCollectionFactory->create();
$collection->addAttributeToSelect('*');
$collection = $this->serializer->serialize($collection);
//Set you CLI command here and pass product collection array in the --collection argument
system('php bin/magento customer:product:update --collection='.escapeshellarg($collection));
}
How to get --collection data in CLI file
$collection = $input->getOption(self::COLLECTION_OBJECT);
$collection = $this->serializer->unserialize($collection);
Informative blog. Thank you for sharing.
ReplyDeleteMagento 2 Development Service
Magento Support Service