My cron file code as follows.crontab.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd">
<group id="default">
<job instance="My\Catalog\Cron\CheckCatalogMrp" method="execute" name="My_catalog_cron">
<schedule>* * * * *</schedule>
</job>
</group>
</config>
Cron is not running and when i run the command php bin/magento cron:run
It is giving output as "Ran Jobs by Schedule"
But my magento.cron.log file have this error. How can i resolve this error?
sh: 1: Syntax error: "(" unexpected
sh: 1: Syntax error: "(" unexpected
sh: 1: Syntax error: "(" unexpected
sh: 1: Syntax error: "(" unexpected
sh: 1: Syntax error: "(" unexpected
sh: 1: Syntax error: "(" unexpected
My execute method as follows.
public function execute()
{
/* $state = $this->_objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('adminhtml');*/
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
/* $directory = 'PosMrp';
if(!is_dir(BP.'var/log/'.$directory)) {
mkdir(BP.'var/log/'.$directory,0777,true);
} */
$log_file = 'return_'.date('Y-m-d').'.log';
$writer = new \Zend\Log\Writer\Stream(BP.'/var/log/'.$log_file);
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$today1 = date("m/d/Y H:i:s");
$logger->info($today1.' - today');
//$cenvertedTime = date('Y-m-d H:i:s',strtotime('+5 hour +30 minutes',strtotime($today1)));
$barcodes = array();
$collection = $this->_productCollectionFactory->create();
$collection->addAttributeToFilter('sku',array('neq' => 'wallet_product'));
$collection->setPageSize(10);
foreach ($collection as $product) {
$barcodes[] = "".$product->getSku()."";
}
$store_id = 14567;
$call_url = 'http://myesydata.com';
$request_url = $call_url.'/online/getMrp';
$data = array(
'store_id' => $store_id,
'barcodes' => $barcodes
);
$post = curl_init();
curl_setopt($post, CURLOPT_URL, $request_url);
curl_setopt($post, CURLOPT_POST,TRUE);
curl_setopt($post, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($post, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($post);
curl_close($post);
$result = json_decode($response, true);
if($result['success'] == 1){
if($result['data']){
foreach ($result['data'] as $key => $value) {
$product_rep = $objectManager->get('\Magento\Catalog\Model\ProductRepository')->get($key);
if($product_rep){
if($product_rep->getPrice() != $value && $value != 0){
$product_rep->setPrice($value);
if($product_rep->save()){
$logger->info($key.' - Price Updated');
}else{
$logger->info($key.' - Price Update Failed');
}
}else{
$logger->info($key.' - Product Not Found');
}
}else{
$logger->info($key.' - Product Price Same as Previous----ECOM PRICE----'.$product_rep->getPrice().'POS PRICE---'.$value);
}
}
}
}
$logger->info('Status'.json_encode($result));
return $this;
}