I would like run cron job every 30 minutes to check items in the warehouse. We will update stock based on that. When I check by CLI tool
sw:cron:run ExampleStockManagerCron
. This is working as expected but the interval is not working. Is there any issue with any settings I need.
A plugin Root file:
addCron();
}
/**
* Uninstall Plugin
*
* Drop a table when plugin uninstall
*/
public function uninstall(UninstallContext $context): void
{
$this->removeCron();
}
public function addCron()
{
$connection = $this->container->get('dbal_connection');
$connection->insert(
's_crontab',
[
'name' => 'ExampleStockManagerCron',
'action' => 'ExampleStockManagerCron',
'next' => new \DateTime(),
'start' => null,
'`interval`' => '100',
'active' => 1,
'end' => new \DateTime(),
'pluginID' => null
],
[
'next' => 'datetime',
'end' => 'datetime',
]
);
}
public function removeCron()
{
$this->container->get('dbal_connection')->executeQuery('DELETE FROM s_crontab WHERE `name` = ?', [
'ExampleStockManagerCron'
]);
return;
}
}
?>
An XML for Cron Register:
StockManagerCron
Shopware_CronJob_ExampleStockManagerCron
true
300
true
A Subscriber Class
'ExampleStockManagerCron'
];
}
/**
* APIStockManagerCron() this will update stock based on API
*/
public function ExampleStockManagerCron(\Shopware_Components_Cron_CronJob $job)
{
$responseMsg = 'Product id '.$value['ordernumber'].' updated with QTY '.$goodsQTY;
$sql = "INSERT INTO `s_plugin_SwagAPI_log` (`id`, `response_desc`) VALUES (NULL, '$responseMsg')";
Shopware()->Db()->query($sql);
}
}