Update order status programatically and notify customer.
4 years 7 months ago #339672
by erix
Adishatz, erix
www.agerix.fr
Update order status programatically and notify customer. was created by erix
-- HikaShop version -- : 4.4.5
-- Joomla version -- : 3.10.5
-- PHP version -- : 7.4.25
-- Browser(s) name and version -- : Firefox Developer 98.0b4
Hi,
I created a CLI CRON script to send orders to the client ERP that is working fine for now.
My client wants now to mark all exported orders as shipped and notify customers.
I followed the solution on this thread : www.hikashop.com/forum/development/88659...fy-the-customer.html
It works fine in the web application but doesn't in a CLI script because the order class requires JApplication to trigger plugin events.
My terminal send me back this error message "Error: Failed to start application: Failed to start application"
Here is my code :
Is there another way to do that so that I can use it in a CLI script ?
Thanks in forward for your help,
Manu @Agerix
-- Joomla version -- : 3.10.5
-- PHP version -- : 7.4.25
-- Browser(s) name and version -- : Firefox Developer 98.0b4
Hi,
I created a CLI CRON script to send orders to the client ERP that is working fine for now.
My client wants now to mark all exported orders as shipped and notify customers.
I followed the solution on this thread : www.hikashop.com/forum/development/88659...fy-the-customer.html
It works fine in the web application but doesn't in a CLI script because the order class requires JApplication to trigger plugin events.
My terminal send me back this error message "Error: Failed to start application: Failed to start application"
Here is my code :
Code:
if(!defined('DS')) define('DS', DIRECTORY_SEPARATOR);
if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return true;
foreach ($ids as $id) // Order IDs
{
$orderClass = hikashop_get('class.order');
$order = new stdClass();
$order->order_id = (int)$id;
$order->order_status = 'shipped';
$order->history = new stdClass();
$order->history->history_notified = 1;
$order->history->history_reason = 'CRON update';
$order->history->history_type = 'modification';
$orderClass->save($order);
}
Is there another way to do that so that I can use it in a CLI script ?
Thanks in forward for your help,
Manu @Agerix
Adishatz, erix
www.agerix.fr
Please Log in or Create an account to join the conversation.
4 years 7 months ago - 4 years 7 months ago #339677
by nicolas
Replied by nicolas on topic Update order status programatically and notify customer.
Hi,
I think the issue is that you need to define JApplication yourself in the factory and you didn't because Joomla doesn't do it for you in cli mode.
As per forum.joomla.org/viewtopic.php?t=981661 they recommend you have
in your code to initialize JApplication so that the code can then use JFactory::getApplication()
I think the issue is that you need to define JApplication yourself in the factory and you didn't because Joomla doesn't do it for you in cli mode.
As per forum.joomla.org/viewtopic.php?t=981661 they recommend you have
Code:
JFactory::$application = $this;
Last edit: 4 years 7 months ago by nicolas.
The following user(s) said Thank You: erix
Please Log in or Create an account to join the conversation.
4 years 7 months ago #339695
by erix
Adishatz, erix
www.agerix.fr
Replied by erix on topic Update order status programatically and notify customer.
Hi Nicolas,
First of all thanks for your quick answer.
Unfortunately the code provided by mbaker doesn't work but it pointed me to the right direction.
Here is a minimalistic example that WORK.
Hope it may help other users
Thanks a lot,
Manu @Agerix
First of all thanks for your quick answer.
Unfortunately the code provided by mbaker doesn't work but it pointed me to the right direction.
Here is a minimalistic example that WORK.
Hope it may help other users
Code:
<?php
const _JEXEC = 1;
if (file_exists(dirname(__DIR__) . '/defines.php')) {
require_once dirname(__DIR__) . '/defines.php';
}
if (!defined('_JDEFINES')) {
define('JPATH_BASE', dirname(__DIR__));
require_once JPATH_BASE . '/includes/defines.php';
}
require_once JPATH_LIBRARIES . '/import.legacy.php';
require_once JPATH_LIBRARIES . '/cms.php';
$app = JFactory::getApplication('site');
class UpdateOrdersCli extends JApplicationCli
{
public function doExecute()
{
if (!defined('DS')) define('DS', DIRECTORY_SEPARATOR);
if (!include_once(rtrim(JPATH_ADMINISTRATOR, DS) . DS . 'components' . DS . 'com_hikashop' . DS . 'helpers' . DS . 'helper.php')) return true;
// See : https://www.hikashop.com/forum/development/886597-set-statut-programmatically-notify-the-customer.html
$orderClass = hikashop_get('class.order');
$order = new stdClass();
$order->order_id = 4219;
$order->order_status = 'shipped';
$order->history = new stdClass();
$order->history->history_reason = 'CRON update';
$order->history->history_notified = 1;
$order->history->history_type = 'modification';
$orderClass->save($order);
}
}
JApplicationCli::getInstance('UpdateOrdersCli')->execute();
Thanks a lot,
Manu @Agerix
Adishatz, erix
www.agerix.fr
The following user(s) said Thank You: nicolas
Please Log in or Create an account to join the conversation.
Time to create page: 0.235 seconds