From 42c5335f2770b9008cccd4ef41f0ce4af0fedbb3 Mon Sep 17 00:00:00 2001 From: gRoussac Date: Fri, 26 Jul 2013 17:55:53 +0200 Subject: [PATCH] [*] WS : order history add(POST) send customer email if sendemail=1 url parameter, thanks @gerdus --- classes/order/OrderHistory.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/classes/order/OrderHistory.php b/classes/order/OrderHistory.php index 232dab50b..55f0795f7 100644 --- a/classes/order/OrderHistory.php +++ b/classes/order/OrderHistory.php @@ -64,6 +64,9 @@ class OrderHistoryCore extends ObjectModel 'id_order_state' => array('required' => true, 'xlink_resource'=> 'order_states'), 'id_order' => array('xlink_resource' => 'orders'), ), + 'objectMethods' => array( + 'add' => 'addWs', + ), ); /** @@ -445,4 +448,27 @@ class OrderHistoryCore extends ObjectModel AND os.`logable` = 1'); } -} + /** + * Add method for webservice create resource Order History + * If sendemail=1 GET parameter is present sends email to customer otherwise does not + * @return bool + */ + public function addWs() + { + $sendemail = (bool)Tools::getValue('sendemail', false); + if ($sendemail) + { + //Mail::Send requires link object on context and is not set when getting here + $context = Context::getContext(); + if ($context->link == null) + { + $protocol_link = (Tools::usingSecureMode() && Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://'; + $protocol_content = (Tools::usingSecureMode() && Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://'; + $context->link = new Link($protocol_link, $protocol_content); + } + return $this->addWithemail(); + } + else + return $this->add(); + } +} \ No newline at end of file