Version Notes
Fixed bug where events were triggered multiple times
Download this release
Release Info
Developer | nChannel |
Extension | nChannel_Communicator |
Version | 0.2.4 |
Comparing to | |
See all releases |
Code changes from version 0.2.3 to 0.2.4
app/code/community/Nchannel/Communicator/Model/Observer.php
CHANGED
@@ -11,6 +11,11 @@ class Nchannel_Communicator_Model_Observer
|
|
11 |
$statusConfig = Mage::getStoreConfig('Communicator/Orders/SENDONSTATUS');
|
12 |
$order = $observer->getEvent()->getOrder();
|
13 |
$origData = $order->getOrigData();
|
|
|
|
|
|
|
|
|
|
|
14 |
Mage::log("Status Configuration: " . $statusConfig,null,'nChannel_Communicator.log');
|
15 |
|
16 |
// Check the configuration options for the status to send orders down. "All" sends every order regardless.
|
@@ -54,13 +59,17 @@ class Nchannel_Communicator_Model_Observer
|
|
54 |
{
|
55 |
// Retrieve the product being updated from the event observer
|
56 |
//$info = phpinfo();
|
57 |
-
Mage::log("sendToAPI",null,'nChannel_Communicator.log');
|
58 |
$enabled = Mage::getStoreConfig('Communicator/Credentials/ENABLED');
|
59 |
if($enabled)
|
60 |
{
|
61 |
$order = $observer->getEvent()->getOrder();
|
62 |
$origData = $order->getOrigData();
|
63 |
$statusConfig = Mage::getStoreConfig('Communicator/Orders/SENDONSTATUS');
|
|
|
|
|
|
|
|
|
64 |
Mage::log("Status Configuration: " . $statusConfig,null,'nChannel_Communicator.log');
|
65 |
Mage::log("Order: " . $order->getIncrementId() . " Status: " . $order->getStatus(),null,'nChannel_Communicator.log');
|
66 |
|
11 |
$statusConfig = Mage::getStoreConfig('Communicator/Orders/SENDONSTATUS');
|
12 |
$order = $observer->getEvent()->getOrder();
|
13 |
$origData = $order->getOrigData();
|
14 |
+
Mage::log("orderSaved entered",null,'nChannel_Communicator.log');
|
15 |
+
//$giftMessage = $order->getData('gift_message');
|
16 |
+
//$giftMessageOrig = $origData->getData('gift_message');
|
17 |
+
//Mage::log("orderSaved: " . $giftMessage,null,'nChannel_Communicator.log');
|
18 |
+
//Mage::log("orderSaved: " . $giftMessageOrig,null,'nChannel_Communicator.log');
|
19 |
Mage::log("Status Configuration: " . $statusConfig,null,'nChannel_Communicator.log');
|
20 |
|
21 |
// Check the configuration options for the status to send orders down. "All" sends every order regardless.
|
59 |
{
|
60 |
// Retrieve the product being updated from the event observer
|
61 |
//$info = phpinfo();
|
62 |
+
Mage::log("sendToAPI entered",null,'nChannel_Communicator.log');
|
63 |
$enabled = Mage::getStoreConfig('Communicator/Credentials/ENABLED');
|
64 |
if($enabled)
|
65 |
{
|
66 |
$order = $observer->getEvent()->getOrder();
|
67 |
$origData = $order->getOrigData();
|
68 |
$statusConfig = Mage::getStoreConfig('Communicator/Orders/SENDONSTATUS');
|
69 |
+
//$giftMessage = $order->getData('gift_message');
|
70 |
+
//$giftMessageOrig = $origData->getData('gift_message');
|
71 |
+
//Mage::log("sendToAPI: " . $giftMessage,null,'nChannel_Communicator.log');
|
72 |
+
//Mage::log("sendToAPI: " . $giftMessageOrig,null,'nChannel_Communicator.log');
|
73 |
Mage::log("Status Configuration: " . $statusConfig,null,'nChannel_Communicator.log');
|
74 |
Mage::log("Order: " . $order->getIncrementId() . " Status: " . $order->getStatus(),null,'nChannel_Communicator.log');
|
75 |
|
app/code/community/Nchannel/Communicator/Model/Regal.Observer.php.bak
ADDED
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Nchannel_Communicator_Model_Observer
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Magento passes a Varien_Event_Observer object as
|
7 |
+
* the first parameter of dispatched events.
|
8 |
+
*/
|
9 |
+
public function orderSaved(Varien_Event_Observer $observer)
|
10 |
+
{
|
11 |
+
$statusConfig = Mage::getStoreConfig('Communicator/Orders/SENDONSTATUS');
|
12 |
+
$order = $observer->getEvent()->getOrder();
|
13 |
+
$origData = $order->getOrigData();
|
14 |
+
$giftMessage = $order->getData('gift_message');
|
15 |
+
Mage::log("Status Configuration: " . $statusConfig,null,'nChannel_Communicator.log');
|
16 |
+
|
17 |
+
if ($giftMessage !== '')
|
18 |
+
{
|
19 |
+
Mage::log("Order has gift message, will not be sent to nChannel.",null,'nChannel_Communicator.log');
|
20 |
+
}
|
21 |
+
else
|
22 |
+
{
|
23 |
+
// Check the configuration options for the status to send orders down. "All" sends every order regardless.
|
24 |
+
// "On Hold" orders are also processed based on this configuration option.
|
25 |
+
if (($order->getStatus() == $statusConfig || $statusConfig == 'all') && $origData['status'] != "holded")
|
26 |
+
{
|
27 |
+
Mage::log("Order: " . $order->getIncrementId() . " Status: " . $order->getStatus(),null,'nChannel_Communicator.log');
|
28 |
+
Mage::log("is object new" . $order->isObjectNew(),null,'nChannel_Communicator.log');
|
29 |
+
Mage::log("status: " . $order->getStatus(),null,'nChannel_Communicator.log');
|
30 |
+
Mage::log("Order will be sent to nChannel",null,'nChannel_Communicator.log');
|
31 |
+
$this->sendToAPI($observer);
|
32 |
+
}
|
33 |
+
else
|
34 |
+
{
|
35 |
+
Mage::log("orderSaved",null,'nChannel_Communicator.log');
|
36 |
+
$order = $observer->getEvent()->getOrder();
|
37 |
+
$origData = $order->getOrigData();
|
38 |
+
Mage::log("Order: " . $order->getIncrementId() . " Status: " . $order->getStatus(),null,'nChannel_Communicator.log');
|
39 |
+
Mage::log("is object new" . $order->isObjectNew(),null,'nChannel_Communicator.log');
|
40 |
+
Mage::log("status: " . $order->getStatus(),null,'nChannel_Communicator.log');
|
41 |
+
Mage::log("old status: " . $origData['status'],null,'nChannel_Communicator.log');
|
42 |
+
if((($statusConfig == "pending" || $statusConfig == "processing") && ($order->getStatus() == $statusConfig || $order->getStatus() == 'all')) && $origData)
|
43 |
+
{
|
44 |
+
if($origData['status'] == "holded")
|
45 |
+
{
|
46 |
+
Mage::log("Order will be sent to nChannel",null,'nChannel_Communicator.log');
|
47 |
+
$this->sendToAPI($observer);
|
48 |
+
}else{
|
49 |
+
Mage::log("Order will not be sent to nChannel",null,'nChannel_Communicator.log');
|
50 |
+
}
|
51 |
+
|
52 |
+
}
|
53 |
+
else
|
54 |
+
{
|
55 |
+
Mage::log("New Order will not be sent to nChannel.",null,'nChannel_Communicator.log');
|
56 |
+
}
|
57 |
+
}
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
+
public function sendToAPI(Varien_Event_Observer $observer)
|
62 |
+
{
|
63 |
+
// Retrieve the product being updated from the event observer
|
64 |
+
//$info = phpinfo();
|
65 |
+
Mage::log("sendToAPI",null,'nChannel_Communicator.log');
|
66 |
+
$enabled = Mage::getStoreConfig('Communicator/Credentials/ENABLED');
|
67 |
+
if($enabled)
|
68 |
+
{
|
69 |
+
$order = $observer->getEvent()->getOrder();
|
70 |
+
$origData = $order->getOrigData();
|
71 |
+
$statusConfig = Mage::getStoreConfig('Communicator/Orders/SENDONSTATUS');
|
72 |
+
Mage::log("Status Configuration: " . $statusConfig,null,'nChannel_Communicator.log');
|
73 |
+
Mage::log("Order: " . $order->getIncrementId() . " Status: " . $order->getStatus(),null,'nChannel_Communicator.log');
|
74 |
+
|
75 |
+
if ($order->getStatus() == $statusConfig || $statusConfig == 'all')
|
76 |
+
{
|
77 |
+
Mage::log("Processing order to send to nChannel.",null,'nChannel_Communicator.log');
|
78 |
+
$token = Mage::getStoreConfig('Communicator/Credentials/TOKEN');
|
79 |
+
$locationID = Mage::getStoreConfig('Communicator/Credentials/LOCATION');
|
80 |
+
$now = new DateTime;
|
81 |
+
$time = gettimeofday();
|
82 |
+
// Write a new line to var/log/product-updates.log
|
83 |
+
$orderID = $order->getIncrementId();
|
84 |
+
$orderXML = "<EventNotification><EventDate>{$now->format('m-d-Y')}</EventDate><EventTime>{$now->format('h:i:s A')}</EventTime><EventSite></EventSite><Event>NewOrder</Event><EventData><OrderNumber>$orderID</OrderNumber></EventData></EventNotification>";
|
85 |
+
Mage::log("Order: # {$orderID} created, enabled: {$enabled}", null, 'nChannel_Communicator.log');
|
86 |
+
Mage::log("Outbound XML = {$orderXML}", null, 'nChannel_Communicator.log');
|
87 |
+
//Create config for URL -> Production/Dev/Local
|
88 |
+
// send XML to api
|
89 |
+
$url = Mage::getStoreConfig('Communicator/Credentials/URL');
|
90 |
+
|
91 |
+
$url.= $locationID . "?token=" . $token;
|
92 |
+
Mage::log("Sending XML to nChannel API url: " . $url, null, 'nChannel_Communicator.log');
|
93 |
+
//$r = new HttpRequest($url, HttpRequest::METH_POST);
|
94 |
+
//$r->setContentType("text/xml charset=utf-8");
|
95 |
+
//$r->addRawPostData($orderXML);
|
96 |
+
Mage::log("Prepared HttpRequest",null,'nChannel_Communicator.log');
|
97 |
+
|
98 |
+
try{
|
99 |
+
Mage::log("sending",null,'nChannel_Communicator.log');
|
100 |
+
if (in_array ('curl', get_loaded_extensions())) {
|
101 |
+
Mage::log("curl loaded",null,'nChannel_Communicator.log');
|
102 |
+
}
|
103 |
+
else{
|
104 |
+
Mage::log("curl is not loaded",null,'nChannel_Communicator.log');
|
105 |
+
}
|
106 |
+
$ch = curl_init($url);
|
107 |
+
//curl_setopt($ch, CURLOPT_MUTE, 1);
|
108 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
109 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
110 |
+
curl_setopt($ch, CURLOPT_POST, 1);
|
111 |
+
//curl_setopt($ch, CURLOPT_HEADER,1);//Include Header In Output
|
112 |
+
//curl_setopt($ch, CURLOPT_NOBODY,1);//Set to HEAD & Exclude body
|
113 |
+
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
|
114 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, "$orderXML");
|
115 |
+
//curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
116 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
117 |
+
Mage::log('sending it now',null,'nChannel_Communicator.log');
|
118 |
+
$output = curl_exec($ch);
|
119 |
+
if(!curl_errno($ch))
|
120 |
+
{
|
121 |
+
//Mage::log('Error in sending Order to nChannel',null,'nChannel_Communicator.log');
|
122 |
+
$info = curl_getinfo($ch);
|
123 |
+
Mage::log('Status Code: ' . $info['http_code'],null,'nChannel_Communicator.log');
|
124 |
+
if($info['http_code'] != '200')
|
125 |
+
{
|
126 |
+
Mage::log('Sending Email to nChannel Support',null,'nChannel_Communicator.log');
|
127 |
+
$templateId = Mage::getStoreConfig('Communicator/Support/EMAILTEMPLATE');
|
128 |
+
$mailSubject = Mage::getStoreConfig('Communicator/Support/SUBJECT');
|
129 |
+
//$email = Mage::getStoreConfig('Communicator/Support/EMAILTO');
|
130 |
+
$name = Mage::getStoreConfig('Communicator/Support/EMAILTO');
|
131 |
+
$storeId = Mage::app()->getStore()->getId();
|
132 |
+
$sender = Array('name' => Mage::getStoreConfig('Communicator/Support/EMAILSENDER'),
|
133 |
+
'email' => Mage::getStoreConfig('Communicator/Support/EMAILSENDER'));
|
134 |
+
$vars = Array('order' => $order,'payment_html' => $order->getPayment()->getMethodInstance()->getTitle());
|
135 |
+
|
136 |
+
$recipients = explode(",",Mage::getStoreConfig('Communicator/Support/EMAILTO'));
|
137 |
+
foreach($recipients as $recipient){
|
138 |
+
$translate = Mage::getSingleton('core/translate');
|
139 |
+
Mage::getModel('core/email_template')
|
140 |
+
->setTemplateSubject($mailSubject)
|
141 |
+
->sendTransactional($templateId, $sender, $recipient, $name, $vars, $storeId);
|
142 |
+
$translate->setTranslateInline(true);
|
143 |
+
}
|
144 |
+
|
145 |
+
}
|
146 |
+
}else
|
147 |
+
{
|
148 |
+
|
149 |
+
Mage::log("Order sent to nChannel",null,'nChannel_Communicator.log');
|
150 |
+
}
|
151 |
+
curl_close($ch);
|
152 |
+
|
153 |
+
|
154 |
+
|
155 |
+
}catch(HttpException $ex){
|
156 |
+
Mage::log("There was an error with communicating with nChannel API. error: " . $ex,null,'nChannel_Communicator.log');
|
157 |
+
}
|
158 |
+
}else{
|
159 |
+
Mage::log("Order will not be sent to nChannel.", null, 'nChannel_Communicator.log');
|
160 |
+
}
|
161 |
+
|
162 |
+
}else{
|
163 |
+
Mage::log("nChannel Communicator is disabled: {$enabled}", null, 'nChannel_Communicator.log');
|
164 |
+
}
|
165 |
+
}
|
166 |
+
}
|
167 |
+
?>
|
app/code/community/Nchannel/Communicator/etc/config.xml
CHANGED
@@ -22,7 +22,7 @@
|
|
22 |
</Nchannel_Communicator>
|
23 |
</models>
|
24 |
<events>
|
25 |
-
|
26 |
<observers>
|
27 |
<Nchannel_Communicator>
|
28 |
<class>Nchannel_Communicator/observer</class>
|
@@ -30,8 +30,8 @@
|
|
30 |
<type>singleton</type>
|
31 |
</Nchannel_Communicator>
|
32 |
</observers>
|
33 |
-
</sales_order_place_after>
|
34 |
-
<
|
35 |
<observers>
|
36 |
<Nchannel_Communicator>
|
37 |
<class>Nchannel_Communicator/observer</class>
|
@@ -39,7 +39,7 @@
|
|
39 |
<type>singleton</type>
|
40 |
</Nchannel_Communicator>
|
41 |
</observers>
|
42 |
-
</
|
43 |
</events>
|
44 |
<helpers>
|
45 |
<Communicator>
|
22 |
</Nchannel_Communicator>
|
23 |
</models>
|
24 |
<events>
|
25 |
+
<!-- <sales_order_place_after>
|
26 |
<observers>
|
27 |
<Nchannel_Communicator>
|
28 |
<class>Nchannel_Communicator/observer</class>
|
30 |
<type>singleton</type>
|
31 |
</Nchannel_Communicator>
|
32 |
</observers>
|
33 |
+
</sales_order_place_after> -->
|
34 |
+
<sales_order_place_after>
|
35 |
<observers>
|
36 |
<Nchannel_Communicator>
|
37 |
<class>Nchannel_Communicator/observer</class>
|
39 |
<type>singleton</type>
|
40 |
</Nchannel_Communicator>
|
41 |
</observers>
|
42 |
+
</sales_order_place_after>
|
43 |
</events>
|
44 |
<helpers>
|
45 |
<Communicator>
|
package.xml
CHANGED
@@ -1,18 +1,18 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>nChannel_Communicator</name>
|
4 |
-
<version>0.2.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="https://portal.nchannel.com/Content/data/EULA_2012-04-21.pdf">nChannel EULA</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>nChannel Communicator allows for event driven communication with the nChannel API on creation of new orders.</summary>
|
10 |
<description>nChannel Communicator allows for event driven communication with the nChannel API on creation of new orders.</description>
|
11 |
-
<notes>Fixed bug
|
12 |
<authors><author><name>nChannel</name><user>jpepper</user><email>jpepper@nchannel.com</email></author></authors>
|
13 |
-
<date>2016-
|
14 |
-
<time>
|
15 |
-
<contents><target name="magecommunity"><dir name="Nchannel"><dir name="Communicator"><dir name="Block"><dir name="Adminhtml"><file name="Version.php" hash="afa8d0feea50602251007002ae1eb4b1"/></dir></dir><dir name="Helper"><file name="Data.php" hash="7d5d9a9593474991cec1d1f521f41482"/></dir><dir name="Model"><file name="Api.php" hash="9001584aa011771215b4a26d31214998"/><dir name="Api2"><dir name="Renderer"><file name="Json.php" hash="acd69b838d8787caaf570549084d2cc3"/></dir><dir name="Stock"><dir name="Item"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="6d9f6107fb7c6f582b894f36f39689a4"/></dir></dir></dir></dir></dir><file name="Observer.php" hash="
|
16 |
<compatible/>
|
17 |
<dependencies><required><php><min>5.2.0</min><max>5.5.11</max></php></required></dependencies>
|
18 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>nChannel_Communicator</name>
|
4 |
+
<version>0.2.4</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="https://portal.nchannel.com/Content/data/EULA_2012-04-21.pdf">nChannel EULA</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>nChannel Communicator allows for event driven communication with the nChannel API on creation of new orders.</summary>
|
10 |
<description>nChannel Communicator allows for event driven communication with the nChannel API on creation of new orders.</description>
|
11 |
+
<notes>Fixed bug where events were triggered multiple times</notes>
|
12 |
<authors><author><name>nChannel</name><user>jpepper</user><email>jpepper@nchannel.com</email></author></authors>
|
13 |
+
<date>2016-07-07</date>
|
14 |
+
<time>19:11:06</time>
|
15 |
+
<contents><target name="magecommunity"><dir name="Nchannel"><dir name="Communicator"><dir name="Block"><dir name="Adminhtml"><file name="Version.php" hash="afa8d0feea50602251007002ae1eb4b1"/></dir></dir><dir name="Helper"><file name="Data.php" hash="7d5d9a9593474991cec1d1f521f41482"/></dir><dir name="Model"><file name="Api.php" hash="9001584aa011771215b4a26d31214998"/><dir name="Api2"><dir name="Renderer"><file name="Json.php" hash="acd69b838d8787caaf570549084d2cc3"/></dir><dir name="Stock"><dir name="Item"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="6d9f6107fb7c6f582b894f36f39689a4"/></dir></dir></dir></dir></dir><file name="Observer.php" hash="78838590e579cdaf924c04ba467ed142"/><dir name="Productutility"><dir name="Api"><file name="V2.php" hash="06659b3dae0d7c7926a2e59bce12018c"/></dir><file name="Api.php" hash="83e30c3b4526c851d8ff31dd73957495"/></dir><file name="Regal.Observer.php.bak" hash="43e05bb68c83da6530eb494a938aeba3"/><dir name="Source"><file name="NchannelEnvironment.php" hash="7aac70643c805e246035ac240011ee0b"/><file name="NchannelOrderStatus.php" hash="c10bfe2ed4433a70a2fc5436b267a6f5"/></dir></dir><dir name="controllers"><file name="IndexController.php" hash="04f02984743361ad17d0d9c85c05afc5"/></dir><dir name="etc"><file name="adminhtml.xml" hash="1c959ca1b60ae9fc0ea61107c4bf3a8d"/><file name="api.xml" hash="9ec26efdc3de2f9ddb883000962d268c"/><file name="api2.xml" hash="d2f3d95f7c53717e5f85f953b04f33ac"/><file name="config.xml" hash="b523637684420e9c35b4c83deac0c0d9"/><file name="system.xml" hash="2fcdba2729ff1ce78c08777a38da6c0f"/><file name="wsdl.xml" hash="53112b017d3f6fc2f2ebf65bc5088c9e"/><file name="wsi.xml" hash="41f6baef07d7e977a3fbd26cb37bd5d2"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Nchannel_Communicator.xml" hash="698fe66f544b1bcf42154dcd4d621527"/></dir><dir/></target></contents>
|
16 |
<compatible/>
|
17 |
<dependencies><required><php><min>5.2.0</min><max>5.5.11</max></php></required></dependencies>
|
18 |
</package>
|