[Skip to main content](#vessel-content)

#   Update order status programatically and notify customer.

##

- **[erix](/forum/user/4328-erix "View erix's Profile")**
- [![erix's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar4328.jpg)](/forum/user/4328-erix "View erix's Profile") Topic Author
- [ Offline](/forum/user/4328-erix)

Less More

- Posts: 78
- Thank you received: 5
-
-
-
- [](http://www.agerix.fr)
-

4 years 8 months ago [\#339672](#339672) by [erix](/forum/user/4328-erix "View erix's Profile")  *[Update order status programatically and notify customer.](/forum/31-development/904021-update-order-status-programatically-and-notify-customer#339672 "-- 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 &quot;Error: Failed to start application: Failed to start application&quot;  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")* was created by *[erix](/forum/user/4328-erix "View erix's Profile")*

-- 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](https://www.hikashop.com/forum/development/886597-set-statut-programmatically-notify-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-&gt;order_id = (int)$id; $order-&gt;order_status = 'shipped'; $order-&gt;history = new stdClass(); $order-&gt;history-&gt;history_notified = 1; $order-&gt;history-&gt;history_reason = 'CRON update'; $order-&gt;history-&gt;history_type = 'modification'; $orderClass-&gt;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](http://www.agerix.fr)

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50LzkwNDAyMS11cGRhdGUtb3JkZXItc3RhdHVzLXByb2dyYW1hdGljYWxseS1hbmQtbm90aWZ5LWN1c3RvbWVyP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86363
- Thank you received: 14296
-
-

4 years 8 months ago -  4 years 8 months ago [\#339677](#339677) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Update order status programatically and notify customer.](/forum/31-development/904021-update-order-status-programatically-and-notify-customer#339677 "-- 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 &quot;Error: Failed to start application: Failed to start application&quot;  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")*

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](https://forum.joomla.org/viewtopic.php?t=981661) they recommend you have Code:

JFactory::$application = $this;

in your code to initialize JApplication so that the code can then use JFactory::getApplication()

Last edit: 4 years 8 months ago by [nicolas](/forum/user/63-nicolas "View nicolas's Profile").

The following user(s) said Thank You: [erix](/forum/user/4328-erix "View erix's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50LzkwNDAyMS11cGRhdGUtb3JkZXItc3RhdHVzLXByb2dyYW1hdGljYWxseS1hbmQtbm90aWZ5LWN1c3RvbWVyP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[erix](/forum/user/4328-erix "View erix's Profile")**
- [![erix's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar4328.jpg)](/forum/user/4328-erix "View erix's Profile") Topic Author
- [ Offline](/forum/user/4328-erix)

Less More

- Posts: 78
- Thank you received: 5
-
-
-
- [](http://www.agerix.fr)
-

4 years 8 months ago [\#339695](#339695) by [erix](/forum/user/4328-erix "View erix's Profile")  Replied by *[erix](/forum/user/4328-erix "View erix's Profile")* on topic *[Update order status programatically and notify customer.](/forum/31-development/904021-update-order-status-programatically-and-notify-customer#339695 "-- 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 &quot;Error: Failed to start application: Failed to start application&quot;  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")*

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 ![;-)](/media/kunena/emoticons/24.png ";-)")
Code:

&lt;?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-&gt;order_id = 4219; $order-&gt;order_status = 'shipped'; $order-&gt;history = new stdClass(); $order-&gt;history-&gt;history_reason = 'CRON update'; $order-&gt;history-&gt;history_notified = 1; $order-&gt;history-&gt;history_type = 'modification'; $orderClass-&gt;save($order); } } JApplicationCli::getInstance('UpdateOrdersCli')-&gt;execute();

Thanks a lot,
Manu @Agerix

---

Adishatz, erix
[ www.agerix.fr](http://www.agerix.fr)

The following user(s) said Thank You: [nicolas](/forum/user/63-nicolas "View nicolas's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50LzkwNDAyMS11cGRhdGUtb3JkZXItc3RhdHVzLXByb2dyYW1hdGljYWxseS1hbmQtbm90aWZ5LWN1c3RvbWVyP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.051 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
