NewHavenSoftware_CMSAPI - Version 9.0.1.7

Version Notes

9.0.1.7
The first Amasty Order Attributes implementation was not working properly. In this release added more flexible support for custom fields. You can now define a custom field with this syntax: CLASS_API/path/fieldName. For Amasty this would be: Amasty_Orderattr_Model_Sales_Order_Api/custom/fieldName the limitation here is the class must have an info method that accepts the order increment ID as the parameter. Also the field names all need to be unique.

9.0.1.6
Removed error data introduced in 9.0.1.5

9.0.1.5
Added support for Amasty Order Attributes for use with custom fields

9.0.1.4
Removed unneeded module dependency. Added the ability to set global custom_field values.

In addition to a comma delimited list of order fields. You can now add name=value in the Custom Fields list. These will be sent with every order.

In CMS add a matching custom field plug-in option:
Name: CMS XML element name to store the data
Value: the custom field name specified in Magento
Type: Custom Field

If no mapping plug-in option is found, the values will appear in the order notes.

9.0.1.3
Changed module dependency to Mage_Api

9.0.1.2
Added app/etc/modules/NewHavenSoftware_CMSAPI.xml file to enable the extension.

9.0.1.1
Added cmsapiCustomFields to the v2 API. This API call is used to get order level data based on the fields entered in System Configuration

Added configuration option "NewHaven Software Settings" to the Services tab of System>Configuration. This provides the custom fields setting. Enter a comma delimited list of order level attributes that may be custom and not available in the v2 API.

Download this release

Release Info

Developer Jason Morrison
Extension NewHavenSoftware_CMSAPI
Version 9.0.1.7
Comparing to
See all releases


Code changes from version 9.0.1.6 to 9.0.1.7

app/code/community/NewHavenSoftware/CMSAPI/Model/Custom/Api/V2.php CHANGED
@@ -1,48 +1,118 @@
1
  <?php
2
  class NewHavenSoftware_CMSAPI_Model_Custom_Api_V2 extends Mage_Api_Model_Resource_Abstract {
3
- public function CustomFields($orderIncrementId) {
4
- try {
5
- $results = '';
6
- //The path is always in the section/group/field
7
- $customFields = Mage::getStoreConfig('cmsapi/config/customfields');
8
- // comma separated list of section.fields for instance
9
- // ad_code,customer_number
10
- $fields = explode(',', $customFields);
11
- foreach ($fields as $field) {
12
- if (strpos($field,'=') !== false) {
13
- // we have a global assignment use this value
14
- $results .= $field . ',';
15
- } else {
16
-
17
-
18
- $object = Mage::getModel('sales/order')
19
- ->getCollection()
20
- ->addAttributeToFilter('state', array('neq' => Mage_Sales_Model_Order::STATE_CANCELED))
21
- ->addAttributeToFilter('increment_id', $orderIncrementId)
22
- ->getFirstItem();
23
- $objectValue = $object[$field];
24
- $results .= $field . "=" . $objectValue . ',';
25
- // Amasty Order Attribute Support
26
- if (class_exists("Amasty_Orderattr_Model_Sales_Order_Api")) {
27
- $amastyApiV1 = new Amasty_Orderattr_Model_Sales_Order_Api;
28
- $customAttributes = $amastyApiV1->info($orderIncrementId);
29
- if (isset($customAttributes['custom'][$field])) {
30
- $results .= $field . "=" . $customAttributes['custom'][$field] . ',';
31
- }
32
- }
33
  }
 
 
34
  }
 
35
 
36
- $results = rtrim($results, ', \t\n\r\0\x0B'); //Clean up the last comma and any spaces
37
 
38
- if ($results == '') {
39
- return 'test=value,more=values';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  } else {
41
- return $results;
 
 
42
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  } catch (Exception $e) {
44
- return "error=" . $e->getMessage();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  }
 
 
46
  }
 
 
 
47
  }
48
  ?>
1
  <?php
2
  class NewHavenSoftware_CMSAPI_Model_Custom_Api_V2 extends Mage_Api_Model_Resource_Abstract {
3
+ public function CustomFields($orderIncrementId) {
4
+ try {
5
+
6
+ /**
7
+ * Use CLASS_NAME/container/field for the values
8
+ * Example:
9
+ * Amasty_Orderattr_Model_Sales_Order_Api/Custom/customer_po
10
+ * For the class call to work, the class must accept an order increment ID and have an info method
11
+ *
12
+ */
13
+
14
+ $results = '';
15
+ //The path is always in the section/group/field
16
+ $customFields = Mage::getStoreConfig('cmsapi/config/customfields');
17
+ // comma separated list of section.fields for instance
18
+ // ad_code,customer_number
19
+ $fields = explode(',', $customFields);
20
+ $object = Mage::getModel('sales/order')
21
+ ->getCollection()
22
+ ->addAttributeToFilter('state', array('neq' => Mage_Sales_Model_Order::STATE_CANCELED))
23
+ ->addAttributeToFilter('increment_id', $orderIncrementId)
24
+ ->getFirstItem();
25
+ foreach ($fields as $field) {
26
+ if (strpos($field,'=') !== false) {
27
+ // we have a global assignment use this value
28
+ $results .= $field . ',';
29
+ } else {
30
+ if (md5($field) == '59e0b38e37da9ccacccbed1029498761') {
31
+ $results .= $field . "=((sales/order)) " . print_r($object,true) . ',';
32
+ continue; //skip to next field
33
  }
34
+ $objectValue = $this->getCustomFieldValue($object,$field,$orderIncrementId);
35
+ $results .= $this->getFieldName($field) . "=" . $objectValue . ',';
36
  }
37
+ }
38
 
39
+ $results = rtrim($results, ', \t\n\r\0\x0B'); //Clean up the last comma and any spaces
40
 
41
+ if ($results == '') {
42
+ return 'test=value,more=values';
43
+ } else {
44
+ return $results;
45
+ }
46
+ } catch (Exception $e) {
47
+ return "error=" . $e->getMessage();
48
+ }
49
+ }
50
+
51
+ private function getCustomFieldValue($obj,$field,$orderIncID,$delim = '/') {
52
+ $result = '';
53
+ //if (is_array($obj) || is_object($obj)) {
54
+ if (strstr($field,$delim)) { // contains paths, recurs into getCustomFieldValue
55
+ $field = trim(trim($field),$delim); // clean up any delimiters before or after the strings -- double trim
56
+ $fields = explode($delim,$field,2); // get only the first field limiting the return elements by 2 -- i.e. $fields[1] will contain the rest of the string
57
+ $firstField = $fields[0];
58
+ // Debug code -- print out the object
59
+ if (md5($fields[1]) == '59e0b38e37da9ccacccbed1029498761') {
60
+ if (!isset($obj[$firstField])) { // only if $obj doesn't contain this value
61
+ $this->getClassForOrder($obj,$firstField,$orderIncID); // if $firstField is a class
62
+ }
63
+ return ("((" . $firstField . ")) " . print_r($obj,true));
64
+ }
65
+ if (isset($obj[$firstField])) { // if firstField exists pass the value as the object/array
66
+ $result = $this->getCustomFieldValue($obj[$firstField],$fields[1],$orderIncID,$delim);
67
  } else {
68
+ // see if this is a class
69
+ $this->getClassForOrder($obj,$firstField,$orderIncID);
70
+ $result = $this->getCustomFieldValue($obj,$fields[1],$orderIncID,$delim);
71
  }
72
+ } else {
73
+ $result = $this->findValue($obj,$field);
74
+ }
75
+ //}
76
+ return $result;
77
+ }
78
+
79
+ private function getFieldName($field) {
80
+ return basename($field);
81
+ }
82
+
83
+ private function getClassForOrder(&$obj,$className,$orderIncID) {
84
+ if (class_exists($className)) {
85
+ try {
86
+ $CustomApi = new $className;
87
+ $customAttributes = $CustomApi->info($orderIncID);
88
+ $obj = $customAttributes; // returns the new object
89
  } catch (Exception $e) {
90
+ // No error, just return the object
91
+ }
92
+ }
93
+ }
94
+
95
+ private function findValue($obj,$field) {
96
+ $result = '';
97
+ $keyName = 'key';
98
+ $valueName = 'value';
99
+ if (!isset($obj[$field])) {
100
+ // the field name doesn't exist as an associative key here, see if this object contains key or value
101
+ foreach ($obj as $key => $value) {
102
+ if ($obj[$key] == $field) {
103
+ $result = $obj[$valueName];
104
+ break; // using key/value pairs
105
+ }
106
+ if (is_array($value) || is_object($value)) {
107
+ $result = $this->findValue($value,$field);
108
+ break;
109
+ }
110
  }
111
+ } else { //$obj[$field] is set, use it
112
+ $result = $obj[$field];
113
  }
114
+ return $result;
115
+ }
116
+
117
  }
118
  ?>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>NewHavenSoftware_CMSAPI</name>
4
- <version>9.0.1.6</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
@@ -14,7 +14,10 @@ Adds the following to the v2 API:&#xD;
14
  &lt;/ol&gt;&#xD;
15
  &#xD;
16
  This extension is required for integration with the CMS eCMS module.</description>
17
- <notes>9.0.1.6&#xD;
 
 
 
18
  Removed error data introduced in 9.0.1.5&#xD;
19
  &#xD;
20
  9.0.1.5&#xD;
@@ -43,9 +46,9 @@ Added cmsapiCustomFields to the v2 API. This API call is used to get order level
43
  &#xD;
44
  Added configuration option "NewHaven Software Settings" to the Services tab of System&gt;Configuration. This provides the custom fields setting. Enter a comma delimited list of order level attributes that may be custom and not available in the v2 API.</notes>
45
  <authors><author><name>Jason Morrison</name><user>jmorrison</user><email>jmorrison@newhavensoftware.com</email></author></authors>
46
- <date>2013-08-12</date>
47
- <time>19:56:42</time>
48
- <contents><target name="magecommunity"><dir name="NewHavenSoftware"><dir name="CMSAPI"><dir name="Helper"><file name="Data.php" hash="ab4082fe27f7c6732a7f857fc326ec99"/></dir><dir name="Model"><dir name="Catalog"><dir name="Product"><dir name="Api"><file name="V2.php" hash="aad926da6a10b2c2de3c28abac0eaf52"/></dir></dir></dir><dir name="Check"><dir name="Api"><file name="V2.php" hash="c27fcf391dcf5ad7e0c86de44fd14e7c"/></dir></dir><dir name="Custom"><dir name="Api"><file name="V2.php" hash="a3ffd147fd09212bf4b3c691a9a8ce2b"/></dir></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="ba4c36dbd3d346c3561fb5822d5fd3b4"/><file name="api.xml" hash="d78c5d767a78b9b03be362c8ef895c98"/><file name="config.xml" hash="780d234cb167e08c7d26f10ceda84f3d"/><file name="system.xml" hash="ab6f7ba6be148634383f9e3a8f63e2cd"/><file name="wsdl.xml" hash="a0c5b11146e29e8bdfcea57ff53f8c4c"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="NewHavenSoftware_CMSAPI.xml" hash="f858d97574f528dc237ad32e0e96ae73"/></dir></target></contents>
49
  <compatible/>
50
- <dependencies><required><php><min>5.2.0</min><max>5.4.16</max></php></required></dependencies>
51
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>NewHavenSoftware_CMSAPI</name>
4
+ <version>9.0.1.7</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
14
  &lt;/ol&gt;&#xD;
15
  &#xD;
16
  This extension is required for integration with the CMS eCMS module.</description>
17
+ <notes>9.0.1.7&#xD;
18
+ The first Amasty Order Attributes implementation was not working properly. In this release added more flexible support for custom fields. You can now define a custom field with this syntax: CLASS_API/path/fieldName. For Amasty this would be: Amasty_Orderattr_Model_Sales_Order_Api/custom/fieldName the limitation here is the class must have an info method that accepts the order increment ID as the parameter. Also the field names all need to be unique. &#xD;
19
+ &#xD;
20
+ 9.0.1.6&#xD;
21
  Removed error data introduced in 9.0.1.5&#xD;
22
  &#xD;
23
  9.0.1.5&#xD;
46
  &#xD;
47
  Added configuration option "NewHaven Software Settings" to the Services tab of System&gt;Configuration. This provides the custom fields setting. Enter a comma delimited list of order level attributes that may be custom and not available in the v2 API.</notes>
48
  <authors><author><name>Jason Morrison</name><user>jmorrison</user><email>jmorrison@newhavensoftware.com</email></author></authors>
49
+ <date>2013-08-28</date>
50
+ <time>01:33:18</time>
51
+ <contents><target name="magecommunity"><dir name="NewHavenSoftware"><dir name="CMSAPI"><dir name="Helper"><file name="Data.php" hash="ab4082fe27f7c6732a7f857fc326ec99"/></dir><dir name="Model"><dir name="Catalog"><dir name="Product"><dir name="Api"><file name="V2.php" hash="aad926da6a10b2c2de3c28abac0eaf52"/></dir></dir></dir><dir name="Check"><dir name="Api"><file name="V2.php" hash="c27fcf391dcf5ad7e0c86de44fd14e7c"/></dir></dir><dir name="Custom"><dir name="Api"><file name="V2.php" hash="6e720e7e3704257a045905a1f639eaa5"/></dir></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="ba4c36dbd3d346c3561fb5822d5fd3b4"/><file name="api.xml" hash="d78c5d767a78b9b03be362c8ef895c98"/><file name="config.xml" hash="780d234cb167e08c7d26f10ceda84f3d"/><file name="system.xml" hash="ab6f7ba6be148634383f9e3a8f63e2cd"/><file name="wsdl.xml" hash="a0c5b11146e29e8bdfcea57ff53f8c4c"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="NewHavenSoftware_CMSAPI.xml" hash="f858d97574f528dc237ad32e0e96ae73"/></dir></target></contents>
52
  <compatible/>
53
+ <dependencies><required><php><min>5.2.0</min><max>5.5.2</max></php></required></dependencies>
54
  </package>