Version Notes
* Performance improvements for different catalog settings
Download this release
Release Info
Developer | Christiaan de Ridder |
Extension | Tritac_ChannelEngine |
Version | 4.3.0 |
Comparing to | |
See all releases |
Code changes from version 3.5.0 to 4.3.0
- app/code/community/Tritac/ChannelEngine/Helper/Data.php +49 -18
- app/code/community/Tritac/ChannelEngine/Model/Loader.php +24 -0
- app/code/community/Tritac/ChannelEngine/Model/Observer.php +299 -248
- app/code/community/Tritac/ChannelEngine/controllers/Adminhtml/GenerateController.php +19 -4
- app/code/community/Tritac/ChannelEngine/etc/config.xml +29 -9
- app/code/community/Tritac/ChannelEngine/etc/system.xml +0 -8
- lib/ChannelEngine/.gitignore +2 -0
- lib/Tritac/ChannelEngineApiClient/AddTrustExternalCARoot.crt +0 -25
- lib/Tritac/ChannelEngineApiClient/Client.php +0 -282
- lib/Tritac/ChannelEngineApiClient/Enums/CancellationLineStatus.php +0 -8
- lib/Tritac/ChannelEngineApiClient/Enums/CancellationStatus.php +0 -9
- lib/Tritac/ChannelEngineApiClient/Enums/Gender.php +0 -8
- lib/Tritac/ChannelEngineApiClient/Enums/MancoReason.php +0 -8
- lib/Tritac/ChannelEngineApiClient/Enums/OrderStatus.php +0 -13
- lib/Tritac/ChannelEngineApiClient/Enums/ReturnAcceptStatus.php +0 -6
- lib/Tritac/ChannelEngineApiClient/Enums/ReturnReason.php +0 -10
- lib/Tritac/ChannelEngineApiClient/Enums/ReturnStatus.php +0 -6
- lib/Tritac/ChannelEngineApiClient/Enums/ShipmentLineStatus.php +0 -8
- lib/Tritac/ChannelEngineApiClient/Enums/ShipmentStatus.php +0 -5
- lib/Tritac/ChannelEngineApiClient/Helpers/Collection.php +0 -49
- lib/Tritac/ChannelEngineApiClient/Helpers/HttpMethod.php +0 -9
- lib/Tritac/ChannelEngineApiClient/Helpers/JsonMapper.php +0 -91
- lib/Tritac/ChannelEngineApiClient/Models/Address.php +0 -97
- lib/Tritac/ChannelEngineApiClient/Models/BaseModel.php +0 -23
- lib/Tritac/ChannelEngineApiClient/Models/Cancellation.php +0 -39
- lib/Tritac/ChannelEngineApiClient/Models/CancellationLine.php +0 -33
- lib/Tritac/ChannelEngineApiClient/Models/Message.php +0 -12
- lib/Tritac/ChannelEngineApiClient/Models/Order.php +0 -154
- lib/Tritac/ChannelEngineApiClient/Models/OrderExtraDataItem.php +0 -19
- lib/Tritac/ChannelEngineApiClient/Models/OrderLine.php +0 -146
- lib/Tritac/ChannelEngineApiClient/Models/ReturnLine.php +0 -46
- lib/Tritac/ChannelEngineApiClient/Models/ReturnObject.php +0 -64
- lib/Tritac/ChannelEngineApiClient/Models/Shipment.php +0 -73
- lib/Tritac/ChannelEngineApiClient/Models/ShipmentLine.php +0 -48
- lib/Tritac/ChannelEngineApiClient/loader.php +0 -14
- package.xml +6 -7
app/code/community/Tritac/ChannelEngine/Helper/Data.php
CHANGED
@@ -1,6 +1,9 @@
|
|
1 |
<?php
|
2 |
class Tritac_ChannelEngine_Helper_Data extends Mage_Core_Helper_Abstract {
|
3 |
|
|
|
|
|
|
|
4 |
protected $_config = null;
|
5 |
|
6 |
/**
|
@@ -10,6 +13,42 @@ class Tritac_ChannelEngine_Helper_Data extends Mage_Core_Helper_Abstract {
|
|
10 |
*/
|
11 |
protected $_defaultTimeToShip = 5;
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
/**
|
14 |
* Get extension general config
|
15 |
*
|
@@ -44,10 +83,13 @@ class Tritac_ChannelEngine_Helper_Data extends Mage_Core_Helper_Abstract {
|
|
44 |
{
|
45 |
$result = array();
|
46 |
|
47 |
-
foreach($this->getConfig() as $storeId => $storeConfig)
|
48 |
-
|
|
|
|
|
|
|
|
|
49 |
}
|
50 |
-
|
51 |
return $result;
|
52 |
}
|
53 |
|
@@ -60,29 +102,18 @@ class Tritac_ChannelEngine_Helper_Data extends Mage_Core_Helper_Abstract {
|
|
60 |
public function checkGeneralConfig($storeId = null)
|
61 |
{
|
62 |
$config = Mage::getStoreConfig('channelengine/general', $storeId);
|
63 |
-
|
64 |
-
if(empty($config['api_key']) || empty($config['api_secret']) || empty($config['tenant'])) {
|
65 |
-
$storeMsg = ($storeId) ? 'for store '.$storeId : '';
|
66 |
-
Mage::log(
|
67 |
-
"Couldn't connect to ChannelEngine.
|
68 |
-
Please specify account keys {$storeMsg}
|
69 |
-
(System/Configuration/Tritac ChannelEngine/Settings/General)"
|
70 |
-
);
|
71 |
-
return false;
|
72 |
-
}
|
73 |
-
|
74 |
-
return true;
|
75 |
}
|
76 |
|
77 |
/**
|
78 |
* Get store expected shipment text
|
79 |
*
|
80 |
-
* @param $
|
81 |
* @return DateTime
|
82 |
*/
|
83 |
-
public function getExpectedShipmentDate($
|
84 |
{
|
85 |
-
$config = $this->getConfig($
|
86 |
|
87 |
$weekdays = (int) $config['shipping']['expected_date'];
|
88 |
if($weekdays <= 0)
|
1 |
<?php
|
2 |
class Tritac_ChannelEngine_Helper_Data extends Mage_Core_Helper_Abstract {
|
3 |
|
4 |
+
const AUTOLOAD_FILENAME = 'autoload.php';
|
5 |
+
const DEFAULT_PATH = '{{libdir}}/ChannelEngine/vendor';
|
6 |
+
|
7 |
protected $_config = null;
|
8 |
|
9 |
/**
|
13 |
*/
|
14 |
protected $_defaultTimeToShip = 5;
|
15 |
|
16 |
+
/**
|
17 |
+
* The location of the vendor directory on the machine the site is running on.
|
18 |
+
* It always comes without a trailing slash.
|
19 |
+
*
|
20 |
+
* @return string
|
21 |
+
*/
|
22 |
+
public function getVendorDirectoryPath()
|
23 |
+
{
|
24 |
+
$path = (string) Mage::getConfig()->getNode('global/composer_autoloader/path');
|
25 |
+
if (!$path) {
|
26 |
+
$path = self::DEFAULT_PATH;
|
27 |
+
}
|
28 |
+
$path = str_replace('/', DS, $path);
|
29 |
+
$path = str_replace('{{basedir}}', Mage::getBaseDir(), $path);
|
30 |
+
$path = str_replace('{{libdir}}', Mage::getBaseDir('lib'), $path);
|
31 |
+
$path = rtrim($path, DS);
|
32 |
+
return realpath($path);
|
33 |
+
}
|
34 |
+
|
35 |
+
/**
|
36 |
+
* @param string|null $path Path to vendor directory. Pass null to use the configured value.
|
37 |
+
* @param string|null $filename Filename of autoload file. Pass null to use the default (autoload.php).
|
38 |
+
*/
|
39 |
+
public function registerAutoloader($path = null, $filename = null)
|
40 |
+
{
|
41 |
+
if ($path === null) {
|
42 |
+
$path = $this->getVendorDirectoryPath();
|
43 |
+
}
|
44 |
+
if ($filename === null) {
|
45 |
+
$filename = self::AUTOLOAD_FILENAME;
|
46 |
+
}
|
47 |
+
if (file_exists($path . DS . $filename)) {
|
48 |
+
require_once($path . DS . $filename);
|
49 |
+
}
|
50 |
+
}
|
51 |
+
|
52 |
/**
|
53 |
* Get extension general config
|
54 |
*
|
83 |
{
|
84 |
$result = array();
|
85 |
|
86 |
+
foreach($this->getConfig() as $storeId => $storeConfig)
|
87 |
+
{
|
88 |
+
if(isset($storeConfig['general']))
|
89 |
+
{
|
90 |
+
$result[$storeId] = $storeConfig['general'];
|
91 |
+
}
|
92 |
}
|
|
|
93 |
return $result;
|
94 |
}
|
95 |
|
102 |
public function checkGeneralConfig($storeId = null)
|
103 |
{
|
104 |
$config = Mage::getStoreConfig('channelengine/general', $storeId);
|
105 |
+
return (empty($config['api_key']) || empty($config['api_secret']) || empty($config['tenant'])) ? false : true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
}
|
107 |
|
108 |
/**
|
109 |
* Get store expected shipment text
|
110 |
*
|
111 |
+
* @param $storeId
|
112 |
* @return DateTime
|
113 |
*/
|
114 |
+
public function getExpectedShipmentDate($storeId)
|
115 |
{
|
116 |
+
$config = $this->getConfig($storeId);
|
117 |
|
118 |
$weekdays = (int) $config['shipping']['expected_date'];
|
119 |
if($weekdays <= 0)
|
app/code/community/Tritac/ChannelEngine/Model/Loader.php
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Observer model
|
4 |
+
*/
|
5 |
+
class Tritac_ChannelEngine_Model_Loader
|
6 |
+
{
|
7 |
+
/**
|
8 |
+
* @var bool
|
9 |
+
*/
|
10 |
+
protected static $added = false;
|
11 |
+
/**
|
12 |
+
* Register the Composer autoloader
|
13 |
+
* @param Varien_Event_Observer $observer
|
14 |
+
*/
|
15 |
+
public function addComposerAutoloader(Varien_Event_Observer $observer)
|
16 |
+
{
|
17 |
+
if (self::$added === false) {
|
18 |
+
/** @var $helper Tritac_ChannelEngine_Helper_Data */
|
19 |
+
$helper = Mage::helper('channelengine');
|
20 |
+
$helper->registerAutoloader();
|
21 |
+
self::$added = true;
|
22 |
+
}
|
23 |
+
}
|
24 |
+
}
|
app/code/community/Tritac/ChannelEngine/Model/Observer.php
CHANGED
@@ -2,12 +2,27 @@
|
|
2 |
/**
|
3 |
* Observer model
|
4 |
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
class Tritac_ChannelEngine_Model_Observer
|
6 |
{
|
7 |
/**
|
8 |
* API client
|
9 |
*
|
10 |
-
* @var
|
11 |
*/
|
12 |
protected $_client = null;
|
13 |
|
@@ -27,6 +42,8 @@ class Tritac_ChannelEngine_Model_Observer
|
|
27 |
|
28 |
const ATTRIBUTES_LIMIT = 30;
|
29 |
|
|
|
|
|
30 |
/**
|
31 |
* Retrieve and validate API config
|
32 |
* Initialize API client
|
@@ -34,21 +51,33 @@ class Tritac_ChannelEngine_Model_Observer
|
|
34 |
public function __construct()
|
35 |
{
|
36 |
$this->_helper = Mage::helper('channelengine');
|
|
|
|
|
37 |
$this->_config = $this->_helper->getConfig();
|
38 |
/**
|
39 |
* Check required config parameters. Initialize API client.
|
40 |
*/
|
41 |
foreach($this->_config as $storeId => $storeConfig) {
|
42 |
if($this->_helper->checkGeneralConfig($storeId)) {
|
43 |
-
$
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
48 |
}
|
49 |
}
|
50 |
}
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
/**
|
53 |
* Fetch new orders from ChannelEngine.
|
54 |
* Ran by cron. The cronjob is set in extension config file.
|
@@ -60,88 +89,87 @@ class Tritac_ChannelEngine_Model_Observer
|
|
60 |
/**
|
61 |
* Check if client is initialized
|
62 |
*/
|
63 |
-
if(is_null($this->_client))
|
64 |
-
return false;
|
65 |
|
66 |
-
foreach($this->_client as $storeId => $
|
67 |
-
|
68 |
-
|
69 |
-
*/
|
70 |
-
$orders = $_client->getOrders(array(
|
71 |
-
Tritac_ChannelEngineApiClient_Enums_OrderStatus::NEW_ORDER
|
72 |
-
));
|
73 |
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
continue;
|
|
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
foreach($orders as $order) {
|
83 |
|
|
|
|
|
84 |
$billingAddress = $order->getBillingAddress();
|
85 |
$shippingAddress = $order->getShippingAddress();
|
86 |
-
if(empty($billingAddress)) continue;
|
87 |
|
88 |
$lines = $order->getLines();
|
89 |
|
90 |
-
if(
|
91 |
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
$ids = explode('_', $productNo);
|
99 |
-
$productId = $ids[0];
|
100 |
-
$productOptions = array();
|
101 |
-
if(count($ids) == 3) {
|
102 |
-
$productOptions = array($ids[1] => intval($ids[2]));
|
103 |
-
}
|
104 |
|
105 |
-
|
106 |
-
|
|
|
|
|
107 |
$_product->load($productId);
|
|
|
108 |
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
}
|
114 |
-
|
115 |
-
// Prepare product parameters for quote
|
116 |
-
$params = new Varien_Object();
|
117 |
-
$params->setQty($item->getQuantity());
|
118 |
-
$params->setOptions($productOptions);
|
119 |
-
|
120 |
-
// Add product to quote
|
121 |
-
try {
|
122 |
-
$_quoteItem = $quote->addProduct($_product, $params);
|
123 |
-
|
124 |
-
if(is_string($_quoteItem)) {
|
125 |
-
// Magento sometimes returns a string when the method fails. -_-"
|
126 |
-
Mage::throwException('Failed to create quote item: ' . $_quoteItem);
|
127 |
-
}
|
128 |
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
|
|
|
|
|
|
|
|
|
|
134 |
|
|
|
|
|
|
|
|
|
|
|
135 |
|
136 |
-
} catch (Exception $e) {
|
137 |
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
|
|
|
|
145 |
}
|
146 |
}
|
147 |
|
@@ -159,7 +187,7 @@ class Tritac_ChannelEngine_Model_Observer
|
|
159 |
'postcode' => $billingAddress->getZipCode(),
|
160 |
'city' => $billingAddress->getCity(),
|
161 |
'street' =>
|
162 |
-
$billingAddress->getStreetName().
|
163 |
$billingAddress->getHouseNr().
|
164 |
$billingAddress->getHouseNrAddition()
|
165 |
);
|
@@ -174,7 +202,7 @@ class Tritac_ChannelEngine_Model_Observer
|
|
174 |
'postcode' => $shippingAddress->getZipCode(),
|
175 |
'city' => $shippingAddress->getCity(),
|
176 |
'street' =>
|
177 |
-
$shippingAddress->getStreetName().
|
178 |
$shippingAddress->getHouseNr().
|
179 |
$shippingAddress->getHouseNrAddition()
|
180 |
);
|
@@ -207,76 +235,87 @@ class Tritac_ChannelEngine_Model_Observer
|
|
207 |
$quote->getPayment()->importData(array('method' => 'channelengine'));
|
208 |
|
209 |
// Save quote and convert it to new order
|
210 |
-
try
|
211 |
-
|
212 |
$quote->save();
|
213 |
-
|
214 |
$service = Mage::getModel('sales/service_quote', $quote);
|
215 |
-
|
216 |
$service->submitAll();
|
217 |
-
|
218 |
-
|
|
|
219 |
Mage::getModel('adminnotification/inbox')->addCritical(
|
220 |
-
"An order (#{$order->
|
221 |
"Reason: {$e->getMessage()} Please contact ChannelEngine support at <a href='mailto:support@channelengine.com'>support@channelengine.com</a> or +31(0)71-5288792"
|
222 |
);
|
223 |
Mage::logException($e);
|
224 |
continue;
|
225 |
}
|
226 |
|
227 |
-
$
|
228 |
|
|
|
|
|
|
|
|
|
|
|
229 |
|
230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
try {
|
236 |
-
// Initialize new invoice model
|
237 |
-
$invoice = Mage::getModel('sales/service_order', $_order)->prepareInvoice();
|
238 |
-
// Add comment to invoice
|
239 |
-
$invoice->addComment(
|
240 |
-
"Order paid on the marketplace.",
|
241 |
-
false,
|
242 |
-
true
|
243 |
-
);
|
244 |
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
Mage::
|
|
|
|
|
|
|
|
|
|
|
279 |
}
|
|
|
|
|
280 |
}
|
281 |
}
|
282 |
|
@@ -295,55 +334,80 @@ class Tritac_ChannelEngine_Model_Observer
|
|
295 |
$event = $observer->getEvent();
|
296 |
/** @var $_shipment Mage_Sales_Model_Order_Shipment */
|
297 |
$_shipment = $event->getShipment();
|
298 |
-
|
299 |
/** @var $_order Mage_Sales_Model_Order */
|
300 |
$_order = $_shipment->getOrder();
|
301 |
-
|
302 |
$storeId = $_order->getStoreId();
|
303 |
-
|
304 |
$ceOrder = Mage::getModel('channelengine/order')->loadByOrderId($_order->getId());
|
305 |
-
$
|
|
|
|
|
|
|
306 |
|
307 |
-
if(!$ceOrderId) return false;
|
308 |
-
|
309 |
// Check if the API client was initialized for this order
|
310 |
if(!isset($this->_client[$storeId])) return false;
|
311 |
|
|
|
|
|
312 |
// Initialize new ChannelEngine shipment object
|
313 |
-
$ceShipment = new
|
314 |
-
$ceShipment->
|
315 |
$ceShipment->setMerchantShipmentNo($_shipment->getId());
|
316 |
|
317 |
// Set tracking info if available
|
318 |
-
$trackingCode = null;
|
319 |
$trackingCodes = $_shipment->getAllTracks();
|
320 |
-
|
|
|
|
|
321 |
$trackingCode = $trackingCodes[0];
|
322 |
$ceShipment->setTrackTraceNo($trackingCode->getNumber());
|
323 |
-
$ceShipment->setMethod($trackingCode->getTitle());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
324 |
}
|
325 |
|
326 |
// If the shipment is already known to ChannelEngine we will just update it
|
327 |
$_channelShipment = Mage::getModel('channelengine/shipment')->loadByShipmentId($_shipment->getId());
|
328 |
|
329 |
-
if($_channelShipment->getId() != null)
|
|
|
|
|
|
|
|
|
330 |
|
331 |
-
|
332 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
333 |
}
|
334 |
|
335 |
-
Mage::log("CE Shipment Id: #{$_channelShipment->getChannelengineShipmentId()}");
|
336 |
-
$ceShipment->setId($_channelShipment->getChannelengineShipmentId());
|
337 |
-
$this->_client[$storeId]->putShipment($ceShipment);
|
338 |
return true;
|
339 |
}
|
340 |
|
341 |
-
Mage::log('New shipment, continue');
|
342 |
-
|
343 |
// Add the shipment lines
|
344 |
-
$ceShipmentLines =
|
345 |
-
foreach($_shipment->getAllItems() as $_shipmentItem)
|
346 |
-
|
347 |
// Get the quantity for this shipment
|
348 |
$shippedQty = (int)$_shipmentItem->getQty();
|
349 |
if($shippedQty == 0) continue;
|
@@ -352,12 +416,10 @@ class Tritac_ChannelEngine_Model_Observer
|
|
352 |
$_orderItem = Mage::getModel('sales/order_item')->load($_shipmentItem->getOrderItemId());
|
353 |
if($_orderItem == null) continue;
|
354 |
|
355 |
-
$ceShipmentLine = new
|
356 |
-
$ceShipmentLine->
|
357 |
$ceShipmentLine->setQuantity($shippedQty);
|
358 |
-
$ceShipmentLine
|
359 |
-
|
360 |
-
$ceShipmentLines->append($ceShipmentLine);
|
361 |
}
|
362 |
|
363 |
// Check if there are any shipment lines
|
@@ -366,31 +428,29 @@ class Tritac_ChannelEngine_Model_Observer
|
|
366 |
$ceShipment->setLines($ceShipmentLines);
|
367 |
|
368 |
// Post shipment to ChannelEngine
|
369 |
-
try
|
370 |
-
|
371 |
-
$
|
372 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
373 |
|
374 |
$_channelShipment = Mage::getModel('channelengine/shipment')
|
375 |
-
->setShipmentId($_shipment->getId())
|
376 |
-
->setChannelengineShipmentId($result->getId());
|
377 |
$_channelShipment->save();
|
378 |
|
379 |
-
Mage::log("Shipment #{$_shipment->getId()}
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
Mage::getModel('adminnotification/inbox')->addCritical(
|
386 |
-
"A shipment (#{$_shipment->getId()}) could not be exported",
|
387 |
-
"Please contact ChannelEngine support at <a href='mailto:support@channelengine.com'>support@channelengine.com</a> or +31(0)71-5288792"
|
388 |
-
);
|
389 |
-
|
390 |
Mage::logException($e);
|
391 |
-
|
392 |
}
|
393 |
-
|
394 |
|
395 |
return true;
|
396 |
}
|
@@ -402,46 +462,38 @@ class Tritac_ChannelEngine_Model_Observer
|
|
402 |
*/
|
403 |
public function fetchReturns()
|
404 |
{
|
405 |
-
|
406 |
-
* Check if client is initialized
|
407 |
-
*/
|
408 |
-
if(is_null($this->_client))
|
409 |
-
return false;
|
410 |
|
411 |
-
foreach($this->_client as $storeId => $
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
$
|
416 |
-
Tritac_ChannelEngineApiClient_Enums_ReturnStatus::DECLARED
|
417 |
-
));
|
418 |
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
|
425 |
-
|
426 |
-
$_channelOrder = Mage::getModel('channelengine/order')->loadByChannelOrderId($return->getOrderId());
|
427 |
-
$_order = Mage::getModel('sales/order')->load($_channelOrder->getOrderId());
|
428 |
|
429 |
-
|
430 |
-
|
431 |
-
|
|
|
432 |
|
|
|
433 |
|
434 |
-
$link = "https://". $this->_config[$storeId]['general']['tenant'] .".channelengine.net/
|
435 |
-
$
|
436 |
-
$
|
437 |
-
|
438 |
-
$message = "Magento Order #: <a href='".
|
439 |
-
Mage::helper('adminhtml')->getUrl('adminhtml/sales_order/view', array('order_id'=>$_order->getOrderId())).
|
440 |
"'>".
|
441 |
$_order->getIncrementId().
|
442 |
"</a><br />";
|
443 |
-
$message .= "
|
444 |
-
$message .= "Reason: {$
|
445 |
$message .= "For more details visit ChannelEngine your <a href='".$link."' target='_blank'>account</a>";
|
446 |
|
447 |
// Check if notification is already exist
|
@@ -454,16 +506,10 @@ class Tritac_ChannelEngine_Model_Observer
|
|
454 |
->limit(1);
|
455 |
$data = $_connectionRead->fetchRow($select);
|
456 |
|
457 |
-
if ($data)
|
458 |
-
continue;
|
459 |
-
}
|
460 |
|
461 |
// Add new notification
|
462 |
-
Mage::getModel('adminnotification/inbox')->addCritical(
|
463 |
-
$title,
|
464 |
-
$message,
|
465 |
-
$link
|
466 |
-
);
|
467 |
}
|
468 |
}
|
469 |
}
|
@@ -504,12 +550,15 @@ class Tritac_ChannelEngine_Model_Observer
|
|
504 |
* Export products from each store.
|
505 |
* Note: products with undefined website id will not be export.
|
506 |
*/
|
507 |
-
foreach(Mage::app()->getStores() as $_store)
|
508 |
-
|
|
|
|
|
509 |
$path = Mage::getBaseDir('media') . DS . 'channelengine' . DS;
|
510 |
$storeConfig = $this->_helper->getConfig($_store->getId());
|
511 |
$name = $storeConfig['general']['tenant'].'_products.xml';
|
512 |
$file = $path . DS . $name;
|
|
|
513 |
|
514 |
$io = new Varien_Io_File();
|
515 |
$io->setAllowCreateFolders(true);
|
@@ -517,7 +566,8 @@ class Tritac_ChannelEngine_Model_Observer
|
|
517 |
$io->streamOpen($file, 'w+');
|
518 |
$io->streamLock(true);
|
519 |
$io->streamWrite('<?xml version="1.0" encoding="UTF-8"?>' . "\n");
|
520 |
-
$io->streamWrite('<Products xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
|
|
521 |
|
522 |
/**
|
523 |
* Prepare custom options array
|
@@ -542,16 +592,19 @@ class Tritac_ChannelEngine_Model_Observer
|
|
542 |
/**
|
543 |
* Retrieve product collection with all visible attributes
|
544 |
*/
|
545 |
-
|
546 |
-
|
547 |
-
}
|
548 |
-
$collection = Mage::getModel('catalog/product')->getCollection();
|
549 |
|
550 |
-
|
551 |
-
|
552 |
-
|
|
|
|
|
|
|
553 |
|
554 |
-
$
|
|
|
|
|
555 |
'name',
|
556 |
'description',
|
557 |
'image',
|
@@ -565,35 +618,33 @@ class Tritac_ChannelEngine_Model_Observer
|
|
565 |
'msrp'
|
566 |
);
|
567 |
|
568 |
-
$
|
569 |
-
$attributes = Mage::
|
570 |
-
->getEntityType(Mage_Catalog_Model_Product::ENTITY)->getAttributeCollection();
|
571 |
|
572 |
-
foreach($attributes as $attribute)
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
$visibleAttributes[$code]['label'] = $attribute->getFrontendLabel();
|
578 |
|
579 |
-
|
580 |
-
|
581 |
-
}
|
582 |
-
if(!in_array($code, $attributesToSelect)) {
|
583 |
-
$attributesToSelect[] = $code;
|
584 |
-
}
|
585 |
-
}
|
586 |
-
}
|
587 |
|
588 |
-
|
589 |
-
$attributesToSelect[] = $this->_config[$storeId]['feed']['gtin'];
|
590 |
-
}
|
591 |
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
597 |
}
|
598 |
|
599 |
$collection->addAttributeToSelect($attributesToSelect, 'left')
|
@@ -620,7 +671,6 @@ class Tritac_ChannelEngine_Model_Observer
|
|
620 |
)
|
621 |
->group('e.entity_id');
|
622 |
|
623 |
-
|
624 |
Mage::getSingleton('core/resource_iterator')->walk(
|
625 |
$collection->getSelect(),
|
626 |
array(array($this, 'callbackGenerateFeed')),
|
@@ -859,6 +909,7 @@ class Tritac_ChannelEngine_Model_Observer
|
|
859 |
if(isset($additional['attributes'])) {
|
860 |
$xml .= '<Attributes>';
|
861 |
foreach($additional['attributes'] as $code => $attribute) {
|
|
|
862 |
if(isset($product[$code]) && !in_array($code, $additional['systemAttributes'])) {
|
863 |
$xml .= "<".$code.">";
|
864 |
/*$xml .= "<label><![CDATA[".$attribute['label']."]]></label>";
|
2 |
/**
|
3 |
* Observer model
|
4 |
*/
|
5 |
+
|
6 |
+
use ChannelEngine\ApiClient\ApiClient;
|
7 |
+
use ChannelEngine\ApiClient\Configuration;
|
8 |
+
|
9 |
+
use ChannelEngine\ApiClient\Api\OrderApi;
|
10 |
+
use ChannelEngine\ApiClient\Api\ShipmentApi;
|
11 |
+
use ChannelEngine\ApiClient\Api\CancellationApi;
|
12 |
+
use ChannelEngine\ApiClient\Api\ReturnApi;
|
13 |
+
|
14 |
+
use ChannelEngine\ApiClient\Model\MerchantOrderResponse;
|
15 |
+
use ChannelEngine\ApiClient\Model\OrderAcknowledgement;
|
16 |
+
use ChannelEngine\ApiClient\Model\MerchantShipmentRequest;
|
17 |
+
use ChannelEngine\ApiClient\Model\MerchantShipmentTrackingRequest;
|
18 |
+
use ChannelEngine\ApiClient\Model\MerchantShipmentLineRequest;
|
19 |
+
|
20 |
class Tritac_ChannelEngine_Model_Observer
|
21 |
{
|
22 |
/**
|
23 |
* API client
|
24 |
*
|
25 |
+
* @var ChannelEngine\ApiClient\ApiClient
|
26 |
*/
|
27 |
protected $_client = null;
|
28 |
|
42 |
|
43 |
const ATTRIBUTES_LIMIT = 30;
|
44 |
|
45 |
+
private $_hasPostNL = false;
|
46 |
+
|
47 |
/**
|
48 |
* Retrieve and validate API config
|
49 |
* Initialize API client
|
51 |
public function __construct()
|
52 |
{
|
53 |
$this->_helper = Mage::helper('channelengine');
|
54 |
+
$this->_hasPostNL = Mage::helper('core')->isModuleEnabled('TIG_PostNL');
|
55 |
+
|
56 |
$this->_config = $this->_helper->getConfig();
|
57 |
/**
|
58 |
* Check required config parameters. Initialize API client.
|
59 |
*/
|
60 |
foreach($this->_config as $storeId => $storeConfig) {
|
61 |
if($this->_helper->checkGeneralConfig($storeId)) {
|
62 |
+
$apiConfig = new Configuration();
|
63 |
+
|
64 |
+
$apiConfig->setApiKey('apikey', $storeConfig['general']['api_key']);
|
65 |
+
$apiConfig->setHost('https://'.$storeConfig['general']['tenant'].'.channelengine.net/api');
|
66 |
+
|
67 |
+
$client = new ApiClient($apiConfig);
|
68 |
+
$this->_client[$storeId] = $client;
|
69 |
}
|
70 |
}
|
71 |
}
|
72 |
|
73 |
+
private function logApiError($storeId, $apiResponse)
|
74 |
+
{
|
75 |
+
Mage::log(
|
76 |
+
'Failed to make ChannelEngine API call '. $storeId . "\r\n" .
|
77 |
+
'['.$response->getStatusCode().'] ' . $response->getMessage()
|
78 |
+
);
|
79 |
+
}
|
80 |
+
|
81 |
/**
|
82 |
* Fetch new orders from ChannelEngine.
|
83 |
* Ran by cron. The cronjob is set in extension config file.
|
89 |
/**
|
90 |
* Check if client is initialized
|
91 |
*/
|
92 |
+
if(is_null($this->_client)) return false;
|
|
|
93 |
|
94 |
+
foreach($this->_client as $storeId => $client)
|
95 |
+
{
|
96 |
+
$orderApi = new OrderApi($client);
|
|
|
|
|
|
|
|
|
97 |
|
98 |
+
$response = $orderApi->orderGetNew();
|
99 |
+
if(!$response->getSuccess())
|
100 |
+
{
|
101 |
+
$this->logApiError($storeId, $response);
|
102 |
continue;
|
103 |
+
}
|
104 |
|
105 |
+
if($response->getCount() == 0) continue;
|
|
|
|
|
106 |
|
107 |
+
foreach($response->getContent() as $order)
|
108 |
+
{
|
109 |
$billingAddress = $order->getBillingAddress();
|
110 |
$shippingAddress = $order->getShippingAddress();
|
|
|
111 |
|
112 |
$lines = $order->getLines();
|
113 |
|
114 |
+
if(count($lines) == 0 || empty($billingAddress)) continue;
|
115 |
|
116 |
+
// Initialize new quote
|
117 |
+
$quote = Mage::getModel('sales/quote')->setStoreId($storeId);
|
118 |
+
|
119 |
+
foreach($lines as $item)
|
120 |
+
{
|
121 |
+
$productNo = $item->getMerchantProductNo();
|
122 |
+
|
123 |
+
$ids = explode('_', $productNo);
|
124 |
+
$productId = $ids[0];
|
125 |
+
$productOptions = array();
|
126 |
+
if(count($ids) == 3) {
|
127 |
+
$productOptions = array($ids[1] => intval($ids[2]));
|
128 |
+
}
|
129 |
|
130 |
+
// Load magento product
|
131 |
+
$_product = Mage::getModel('catalog/product')->setStoreId($storeId);
|
132 |
+
$_product->load($productId);
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
+
if(!$_product->getId())
|
135 |
+
{
|
136 |
+
// If the product can't be found by ID, fall back on the SKU.
|
137 |
+
$productId = $_product->getIdBySku($productNo);
|
138 |
$_product->load($productId);
|
139 |
+
}
|
140 |
|
141 |
+
// Prepare product parameters for quote
|
142 |
+
$params = new Varien_Object();
|
143 |
+
$params->setQty($item->getQuantity());
|
144 |
+
$params->setOptions($productOptions);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
|
146 |
+
// Add product to quote
|
147 |
+
try
|
148 |
+
{
|
149 |
+
$_quoteItem = $quote->addProduct($_product, $params);
|
150 |
+
|
151 |
+
if(is_string($_quoteItem))
|
152 |
+
{
|
153 |
+
// Magento sometimes returns a string when the method fails. -_-"
|
154 |
+
Mage::throwException('Failed to create quote item: ' . $_quoteItem);
|
155 |
+
}
|
156 |
|
157 |
+
$price = $item->getUnitPriceInclVat();
|
158 |
+
$_quoteItem->setOriginalCustomPrice($price);
|
159 |
+
$_quoteItem->setCustomPrice($price);
|
160 |
+
$_quoteItem->getProduct()->setIsSuperMode(true);
|
161 |
+
$_quoteItem->setChannelengineOrderLineId($item->getChannelProductNo());
|
162 |
|
|
|
163 |
|
164 |
+
}
|
165 |
+
catch (Exception $e)
|
166 |
+
{
|
167 |
+
Mage::getModel('adminnotification/inbox')->addCritical(
|
168 |
+
"An order ({$order->getChannelName()} #{$order->getChannelOrderNo()}) could not be imported",
|
169 |
+
"Failed add product to order: #{$productNo}. Reason: {$e->getMessage()} Please contact ChannelEngine support at <a href='mailto:support@channelengine.com'>support@channelengine.com</a> or +31(0)71-5288792"
|
170 |
+
);
|
171 |
+
Mage::logException($e);
|
172 |
+
break;
|
173 |
}
|
174 |
}
|
175 |
|
187 |
'postcode' => $billingAddress->getZipCode(),
|
188 |
'city' => $billingAddress->getCity(),
|
189 |
'street' =>
|
190 |
+
$billingAddress->getStreetName()."\n".
|
191 |
$billingAddress->getHouseNr().
|
192 |
$billingAddress->getHouseNrAddition()
|
193 |
);
|
202 |
'postcode' => $shippingAddress->getZipCode(),
|
203 |
'city' => $shippingAddress->getCity(),
|
204 |
'street' =>
|
205 |
+
$shippingAddress->getStreetName()."\n".
|
206 |
$shippingAddress->getHouseNr().
|
207 |
$shippingAddress->getHouseNrAddition()
|
208 |
);
|
235 |
$quote->getPayment()->importData(array('method' => 'channelengine'));
|
236 |
|
237 |
// Save quote and convert it to new order
|
238 |
+
try
|
239 |
+
{
|
240 |
$quote->save();
|
|
|
241 |
$service = Mage::getModel('sales/service_quote', $quote);
|
|
|
242 |
$service->submitAll();
|
243 |
+
}
|
244 |
+
catch (Exception $e)
|
245 |
+
{
|
246 |
Mage::getModel('adminnotification/inbox')->addCritical(
|
247 |
+
"An order ({$order->getChannelName()} #{$order->getChannelOrderNo()}) could not be imported",
|
248 |
"Reason: {$e->getMessage()} Please contact ChannelEngine support at <a href='mailto:support@channelengine.com'>support@channelengine.com</a> or +31(0)71-5288792"
|
249 |
);
|
250 |
Mage::logException($e);
|
251 |
continue;
|
252 |
}
|
253 |
|
254 |
+
$magentoOrder = $service->getOrder();
|
255 |
|
256 |
+
if(!$magentoOrder->getIncrementId())
|
257 |
+
{
|
258 |
+
Mage::log("An order (#{$order->getId()}) could not be imported");
|
259 |
+
continue;
|
260 |
+
}
|
261 |
|
262 |
+
try
|
263 |
+
{
|
264 |
+
// Initialize new invoice model
|
265 |
+
$invoice = Mage::getModel('sales/service_order', $magentoOrder)->prepareInvoice();
|
266 |
+
// Add comment to invoice
|
267 |
+
$invoice->addComment(
|
268 |
+
"Order paid on the marketplace.",
|
269 |
+
false,
|
270 |
+
true
|
271 |
+
);
|
272 |
|
273 |
+
// Register invoice. Register invoice items. Collect invoice totals.
|
274 |
+
$invoice->register();
|
275 |
+
$invoice->getOrder()->setIsInProcess(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
276 |
|
277 |
+
$os = $order->getChannelOrderSupport();
|
278 |
+
$canShipPartiallyItem = ($os == MerchantOrderResponse::CHANNEL_ORDER_SUPPORT_SPLIT_ORDER_LINES);
|
279 |
+
$canShipPartially = ($canShipPartiallyItem || $os == MerchantOrderResponse::CHANNEL_ORDER_SUPPORT_SPLIT_ORDERS);
|
280 |
+
|
281 |
+
|
282 |
+
// Initialize new channel order
|
283 |
+
$_channelOrder = Mage::getModel('channelengine/order');
|
284 |
+
$_channelOrder->setOrderId($magentoOrder->getId())
|
285 |
+
->setChannelOrderId($order->getChannelOrderNo())
|
286 |
+
->setChannelName($order->getChannelName())
|
287 |
+
->setCanShipPartial($canShipPartially);
|
288 |
+
|
289 |
+
$invoice->getOrder()
|
290 |
+
->setCanShipPartiallyItem($canShipPartiallyItem)
|
291 |
+
->setCanShipPartially($canShipPartially);
|
292 |
+
|
293 |
+
// Start new transaction
|
294 |
+
$transactionSave = Mage::getModel('core/resource_transaction')
|
295 |
+
->addObject($invoice)
|
296 |
+
->addObject($invoice->getOrder())
|
297 |
+
->addObject($_channelOrder);
|
298 |
+
$transactionSave->save();
|
299 |
+
|
300 |
+
|
301 |
+
// Send order acknowledgement to CE.
|
302 |
+
$ack = new OrderAcknowledgement();
|
303 |
+
$ack->setMerchantOrderNo($magentoOrder->getId());
|
304 |
+
$ack->setOrderId($order->getId());
|
305 |
+
$orderApi->orderAcknowledge($ack);
|
306 |
+
|
307 |
+
}
|
308 |
+
catch (Exception $e)
|
309 |
+
{
|
310 |
+
Mage::getModel('adminnotification/inbox')->addCritical(
|
311 |
+
"An invoice could not be created (order #{$magentoOrder->getIncrementId()}, {$order->getChannelName()} #{$order->getChannelOrderNo()})",
|
312 |
+
"Reason: {$e->getMessage()} Please contact ChannelEngine support at <a href='mailto:support@channelengine.com'>support@channelengine.com</a> or +31(0)71-5288792"
|
313 |
+
);
|
314 |
+
Mage::logException($e);
|
315 |
+
continue;
|
316 |
}
|
317 |
+
|
318 |
+
Mage::log("Order #{$magentoOrder->getIncrementId()} was imported successfully.");
|
319 |
}
|
320 |
}
|
321 |
|
334 |
$event = $observer->getEvent();
|
335 |
/** @var $_shipment Mage_Sales_Model_Order_Shipment */
|
336 |
$_shipment = $event->getShipment();
|
|
|
337 |
/** @var $_order Mage_Sales_Model_Order */
|
338 |
$_order = $_shipment->getOrder();
|
339 |
+
|
340 |
$storeId = $_order->getStoreId();
|
341 |
+
|
342 |
$ceOrder = Mage::getModel('channelengine/order')->loadByOrderId($_order->getId());
|
343 |
+
if($ceOrder->getId() == null) return true;
|
344 |
+
|
345 |
+
$errorTitle = "A shipment (#{$_shipment->getId()}) could not be updated";
|
346 |
+
$errorMessage = "Please contact ChannelEngine support at <a href='mailto:support@channelengine.com'>support@channelengine.com</a> or +31(0)71-5288792";
|
347 |
|
|
|
|
|
348 |
// Check if the API client was initialized for this order
|
349 |
if(!isset($this->_client[$storeId])) return false;
|
350 |
|
351 |
+
$shipmentApi = new ShipmentApi($this->_client[$storeId]);
|
352 |
+
|
353 |
// Initialize new ChannelEngine shipment object
|
354 |
+
$ceShipment = new MerchantShipmentRequest();
|
355 |
+
$ceShipment->setMerchantOrderNo($_order->getId());
|
356 |
$ceShipment->setMerchantShipmentNo($_shipment->getId());
|
357 |
|
358 |
// Set tracking info if available
|
|
|
359 |
$trackingCodes = $_shipment->getAllTracks();
|
360 |
+
|
361 |
+
if(count($trackingCodes) > 0)
|
362 |
+
{
|
363 |
$trackingCode = $trackingCodes[0];
|
364 |
$ceShipment->setTrackTraceNo($trackingCode->getNumber());
|
365 |
+
$ceShipment->setMethod(($trackingCode->getCarrierCode() == 'custom') ? $trackingCode->getTitle() : $trackingCode->getCarrierCode());
|
366 |
+
}
|
367 |
+
|
368 |
+
// Post NL support, in case of a leter box parcel, we can safely omit the tracking code.
|
369 |
+
if($this->_hasPostNL)
|
370 |
+
{
|
371 |
+
$postnlShipment = Mage::getModel('postnl_core/shipment')->load($_shipment->getId(), 'shipment_id');
|
372 |
+
if($postnlShipment->getId() != null && $postnlShipment->getIsBuspakje())
|
373 |
+
{
|
374 |
+
$ceShipment->setMethod('Briefpost');
|
375 |
+
}
|
376 |
}
|
377 |
|
378 |
// If the shipment is already known to ChannelEngine we will just update it
|
379 |
$_channelShipment = Mage::getModel('channelengine/shipment')->loadByShipmentId($_shipment->getId());
|
380 |
|
381 |
+
if($_channelShipment->getId() != null)
|
382 |
+
{
|
383 |
+
$ceShipmentUpdate = new MerchantShipmentTrackingRequest();
|
384 |
+
$ceShipmentUpdate->setTrackTraceNo($ceShipment->getTrackTraceNo());
|
385 |
+
$ceShipmentUpdate->setTrackTraceNo($ceShipment->getMethod());
|
386 |
|
387 |
+
try
|
388 |
+
{
|
389 |
+
$response = $shipmentApi->shipmentUpdate($_shipment->getId(), $ceShipmentUpdate);
|
390 |
+
if(!$response->getSuccess())
|
391 |
+
{
|
392 |
+
$this->logApiError($storeId, $response);
|
393 |
+
Mage::getModel('adminnotification/inbox')->addCritical($errorTitle, $errorMessage);
|
394 |
+
return false;
|
395 |
+
}
|
396 |
+
}
|
397 |
+
catch(Exception $e)
|
398 |
+
{
|
399 |
+
//Mage::getModel('adminnotification/inbox')->addCritical($errorTitle, $errorMessage);
|
400 |
+
Mage::logException($e);
|
401 |
+
return false;
|
402 |
}
|
403 |
|
|
|
|
|
|
|
404 |
return true;
|
405 |
}
|
406 |
|
|
|
|
|
407 |
// Add the shipment lines
|
408 |
+
$ceShipmentLines = [];
|
409 |
+
foreach($_shipment->getAllItems() as $_shipmentItem)
|
410 |
+
{
|
411 |
// Get the quantity for this shipment
|
412 |
$shippedQty = (int)$_shipmentItem->getQty();
|
413 |
if($shippedQty == 0) continue;
|
416 |
$_orderItem = Mage::getModel('sales/order_item')->load($_shipmentItem->getOrderItemId());
|
417 |
if($_orderItem == null) continue;
|
418 |
|
419 |
+
$ceShipmentLine = new MerchantShipmentLineRequest();
|
420 |
+
$ceShipmentLine->setMerchantProductNo($_shipmentItem->getProductId());
|
421 |
$ceShipmentLine->setQuantity($shippedQty);
|
422 |
+
$ceShipmentLines[] = $ceShipmentLine;
|
|
|
|
|
423 |
}
|
424 |
|
425 |
// Check if there are any shipment lines
|
428 |
$ceShipment->setLines($ceShipmentLines);
|
429 |
|
430 |
// Post shipment to ChannelEngine
|
431 |
+
try
|
432 |
+
{
|
433 |
+
$response = $shipmentApi->shipmentCreate($ceShipment);
|
434 |
+
|
435 |
+
if(!$response->getSuccess())
|
436 |
+
{
|
437 |
+
$this->logApiError($storeId, $response);
|
438 |
+
Mage::getModel('adminnotification/inbox')->addCritical($errorTitle, $errorMessage);
|
439 |
+
return false;
|
440 |
+
}
|
441 |
|
442 |
$_channelShipment = Mage::getModel('channelengine/shipment')
|
443 |
+
->setShipmentId($_shipment->getId());
|
|
|
444 |
$_channelShipment->save();
|
445 |
|
446 |
+
Mage::log("Shipment #{$_shipment->getId()} was placed successfully.");
|
447 |
+
}
|
448 |
+
catch(Exception $e)
|
449 |
+
{
|
450 |
+
Mage::getModel('adminnotification/inbox')->addCritical($errorTitle, $errorMessage);
|
|
|
|
|
|
|
|
|
|
|
|
|
451 |
Mage::logException($e);
|
452 |
+
return false;
|
453 |
}
|
|
|
454 |
|
455 |
return true;
|
456 |
}
|
462 |
*/
|
463 |
public function fetchReturns()
|
464 |
{
|
465 |
+
if(is_null($this->_client)) return false;
|
|
|
|
|
|
|
|
|
466 |
|
467 |
+
foreach($this->_client as $storeId => $client)
|
468 |
+
{
|
469 |
+
$returnApi = new ReturnApi($client);
|
470 |
+
$lastUpdatedAt = new DateTime('-1 day');
|
471 |
+
$response = $returnApi->returnGetDeclaredByChannel($lastUpdatedAt);
|
|
|
|
|
472 |
|
473 |
+
if(!$response->getSuccess())
|
474 |
+
{
|
475 |
+
$this->logApiError($storeId, $response);
|
476 |
+
continue;
|
477 |
+
}
|
478 |
|
479 |
+
if($response->getCount() == 0) continue;
|
|
|
|
|
480 |
|
481 |
+
foreach($response->getContent() as $return)
|
482 |
+
{
|
483 |
+
//$_channelOrder = Mage::getModel('channelengine/order')->loadByChannelOrderId($return->getOrderId());
|
484 |
+
$_order = Mage::getModel('sales/order')->load($return->getMerchantOrderNo());
|
485 |
|
486 |
+
if(!$_order->getIncrementId()) continue;
|
487 |
|
488 |
+
$link = "https://". $this->_config[$storeId]['general']['tenant'] .".channelengine.net/returns";
|
489 |
+
$title = "A new return was declared in ChannelEngine for order #" . $_order->getIncrementId();
|
490 |
+
$message = "Magento Order #<a href='".
|
491 |
+
Mage::helper('adminhtml')->getUrl('adminhtml/sales_order/view', array('order_id' => $_order->getId())).
|
|
|
|
|
492 |
"'>".
|
493 |
$_order->getIncrementId().
|
494 |
"</a><br />";
|
495 |
+
$message .= "Comment: {$return->getCustomerComment()}<br />";
|
496 |
+
$message .= "Reason: {$return->getReason()}<br />";
|
497 |
$message .= "For more details visit ChannelEngine your <a href='".$link."' target='_blank'>account</a>";
|
498 |
|
499 |
// Check if notification is already exist
|
506 |
->limit(1);
|
507 |
$data = $_connectionRead->fetchRow($select);
|
508 |
|
509 |
+
if ($data) continue;
|
|
|
|
|
510 |
|
511 |
// Add new notification
|
512 |
+
Mage::getModel('adminnotification/inbox')->addCritical($title, $message);
|
|
|
|
|
|
|
|
|
513 |
}
|
514 |
}
|
515 |
}
|
550 |
* Export products from each store.
|
551 |
* Note: products with undefined website id will not be export.
|
552 |
*/
|
553 |
+
foreach(Mage::app()->getStores() as $_store)
|
554 |
+
{
|
555 |
+
Mage::app()->setCurrentStore($_store);
|
556 |
+
|
557 |
$path = Mage::getBaseDir('media') . DS . 'channelengine' . DS;
|
558 |
$storeConfig = $this->_helper->getConfig($_store->getId());
|
559 |
$name = $storeConfig['general']['tenant'].'_products.xml';
|
560 |
$file = $path . DS . $name;
|
561 |
+
$date = date('c');
|
562 |
|
563 |
$io = new Varien_Io_File();
|
564 |
$io->setAllowCreateFolders(true);
|
566 |
$io->streamOpen($file, 'w+');
|
567 |
$io->streamLock(true);
|
568 |
$io->streamWrite('<?xml version="1.0" encoding="UTF-8"?>' . "\n");
|
569 |
+
$io->streamWrite('<Products xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
570 |
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" GeneratedAt="'.$date.'">' . "\n");
|
571 |
|
572 |
/**
|
573 |
* Prepare custom options array
|
592 |
/**
|
593 |
* Retrieve product collection with all visible attributes
|
594 |
*/
|
595 |
+
$collection = Mage::getResourceModel('catalog/product_collection');
|
596 |
+
$collection->getEntity()->setStoreId($storeId);
|
|
|
|
|
597 |
|
598 |
+
$flatCatalogEnabled = $collection->isEnabledFlat();
|
599 |
+
|
600 |
+
// Make sure to create a new instance of our collection after setting the store ID
|
601 |
+
// when using the flat catalog. Otherwise store ID will be ignored. This is a bug in magento.
|
602 |
+
// https://magento.stackexchange.com/a/25908
|
603 |
+
if($flatCatalogEnabled) $collection = Mage::getResourceModel('catalog/product_collection');
|
604 |
|
605 |
+
$visibleAttributes = array();
|
606 |
+
$systemAttributes = array();
|
607 |
+
$attributesToSelect = array(
|
608 |
'name',
|
609 |
'description',
|
610 |
'image',
|
618 |
'msrp'
|
619 |
);
|
620 |
|
621 |
+
if(!empty($this->_config[$storeId]['feed']['gtin'])) $attributesToSelect[] = $this->_config[$storeId]['feed']['gtin'];
|
622 |
+
$attributes = Mage::getResourceModel('catalog/product_attribute_collection');
|
|
|
623 |
|
624 |
+
foreach($attributes as $attribute)
|
625 |
+
{
|
626 |
+
$code = $attribute->getAttributeCode();
|
627 |
+
$isFlat = $flatCatalogEnabled && $attribute->getUsedInProductListing();
|
628 |
+
$isRegular = !$flatCatalogEnabled && $attribute->getIsVisible() && $attribute->getIsVisibleOnFront();
|
|
|
629 |
|
630 |
+
// Only allow a subset of system attributes
|
631 |
+
$isSystem = !$attribute->getIsUserDefined();
|
|
|
|
|
|
|
|
|
|
|
|
|
632 |
|
633 |
+
if(!$isFlat && !$isRegular || in_array($code, $attributesToSelect)) continue;
|
|
|
|
|
634 |
|
635 |
+
if($isSystem)
|
636 |
+
{
|
637 |
+
$systemAttributes[] = $code;
|
638 |
+
continue;
|
639 |
+
}
|
640 |
+
|
641 |
+
$attributesToSelect[] = $code;
|
642 |
+
|
643 |
+
$visibleAttributes[$code]['label'] = $attribute->getFrontendLabel();
|
644 |
+
foreach($attribute->getSource()->getAllOptions(false) as $option)
|
645 |
+
{
|
646 |
+
$visibleAttributes[$code]['values'][$option['value']] = $option['label'];
|
647 |
+
}
|
648 |
}
|
649 |
|
650 |
$collection->addAttributeToSelect($attributesToSelect, 'left')
|
671 |
)
|
672 |
->group('e.entity_id');
|
673 |
|
|
|
674 |
Mage::getSingleton('core/resource_iterator')->walk(
|
675 |
$collection->getSelect(),
|
676 |
array(array($this, 'callbackGenerateFeed')),
|
909 |
if(isset($additional['attributes'])) {
|
910 |
$xml .= '<Attributes>';
|
911 |
foreach($additional['attributes'] as $code => $attribute) {
|
912 |
+
|
913 |
if(isset($product[$code]) && !in_array($code, $additional['systemAttributes'])) {
|
914 |
$xml .= "<".$code.">";
|
915 |
/*$xml .= "<label><![CDATA[".$attribute['label']."]]></label>";
|
app/code/community/Tritac/ChannelEngine/controllers/Adminhtml/GenerateController.php
CHANGED
@@ -1,12 +1,27 @@
|
|
1 |
<?php
|
2 |
class Tritac_ChannelEngine_Adminhtml_GenerateController extends Mage_Adminhtml_Controller_Action
|
3 |
{
|
4 |
-
public function ajaxAction()
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
|
|
|
|
6 |
$observer = Mage::getModel('channelengine/observer');
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
11 |
}
|
12 |
}
|
1 |
<?php
|
2 |
class Tritac_ChannelEngine_Adminhtml_GenerateController extends Mage_Adminhtml_Controller_Action
|
3 |
{
|
4 |
+
public function ajaxAction()
|
5 |
+
{
|
6 |
+
$observer = Mage::getModel('channelengine/observer');
|
7 |
+
$res = $this->getResponse();
|
8 |
+
$res->setHeader('Content-type', 'application/json');
|
9 |
+
if($observer->generateFeed()) $res->setBody(1);
|
10 |
+
}
|
11 |
|
12 |
+
public function importOrdersAction()
|
13 |
+
{
|
14 |
$observer = Mage::getModel('channelengine/observer');
|
15 |
+
$res = $this->getResponse();
|
16 |
+
$res->setHeader('Content-type', 'application/json');
|
17 |
+
if($observer->fetchNewOrders()) $res->setBody(1);
|
18 |
+
}
|
19 |
|
20 |
+
public function importReturnsAction()
|
21 |
+
{
|
22 |
+
$observer = Mage::getModel('channelengine/observer');
|
23 |
+
$res = $this->getResponse();
|
24 |
+
$res->setHeader('Content-type', 'application/json');
|
25 |
+
if($observer->fetchReturns()) $res->setBody(1);
|
26 |
}
|
27 |
}
|
app/code/community/Tritac/ChannelEngine/etc/config.xml
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Tritac_ChannelEngine>
|
5 |
-
<version>3.
|
6 |
</Tritac_ChannelEngine>
|
7 |
</modules>
|
8 |
|
@@ -130,6 +130,15 @@
|
|
130 |
</shipmentsave>
|
131 |
</observers>
|
132 |
</sales_order_shipment_save_after>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
<!--<core_block_abstract_prepare_layout_before>
|
134 |
<observers>
|
135 |
<ordergrid_column_append>
|
@@ -165,30 +174,41 @@
|
|
165 |
|
166 |
<crontab>
|
167 |
<jobs>
|
168 |
-
<
|
169 |
<schedule>
|
170 |
-
<cron_expr>*/
|
171 |
</schedule>
|
172 |
<run>
|
173 |
<model>channelengine/observer::fetchNewOrders</model>
|
174 |
</run>
|
175 |
-
</
|
176 |
-
<
|
177 |
<schedule>
|
178 |
-
<cron_expr>*/
|
179 |
</schedule>
|
180 |
<run>
|
181 |
<model>channelengine/observer::fetchReturns</model>
|
182 |
</run>
|
183 |
-
</
|
184 |
-
<
|
185 |
<schedule>
|
186 |
<cron_expr>30 * * * *</cron_expr>
|
187 |
</schedule>
|
188 |
<run>
|
189 |
<model>channelengine/observer::generateFeed</model>
|
190 |
</run>
|
191 |
-
</
|
192 |
</jobs>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
</crontab>
|
194 |
</config>
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Tritac_ChannelEngine>
|
5 |
+
<version>4.3.0</version>
|
6 |
</Tritac_ChannelEngine>
|
7 |
</modules>
|
8 |
|
130 |
</shipmentsave>
|
131 |
</observers>
|
132 |
</sales_order_shipment_save_after>
|
133 |
+
<resource_get_tablename>
|
134 |
+
<observers>
|
135 |
+
<channelengine_composer_autoloader>
|
136 |
+
<type>singleton</type>
|
137 |
+
<class>channelengine/loader</class>
|
138 |
+
<method>addComposerAutoloader</method>
|
139 |
+
</channelengine_composer_autoloader>
|
140 |
+
</observers>
|
141 |
+
</resource_get_tablename>
|
142 |
<!--<core_block_abstract_prepare_layout_before>
|
143 |
<observers>
|
144 |
<ordergrid_column_append>
|
174 |
|
175 |
<crontab>
|
176 |
<jobs>
|
177 |
+
<channelengine_import_orders>
|
178 |
<schedule>
|
179 |
+
<cron_expr>*/5 * * * *</cron_expr>
|
180 |
</schedule>
|
181 |
<run>
|
182 |
<model>channelengine/observer::fetchNewOrders</model>
|
183 |
</run>
|
184 |
+
</channelengine_import_orders>
|
185 |
+
<channelengine_import_returns>
|
186 |
<schedule>
|
187 |
+
<cron_expr>*/5 * * * *</cron_expr>
|
188 |
</schedule>
|
189 |
<run>
|
190 |
<model>channelengine/observer::fetchReturns</model>
|
191 |
</run>
|
192 |
+
</channelengine_import_returns>
|
193 |
+
<channelengine_generate_feed>
|
194 |
<schedule>
|
195 |
<cron_expr>30 * * * *</cron_expr>
|
196 |
</schedule>
|
197 |
<run>
|
198 |
<model>channelengine/observer::generateFeed</model>
|
199 |
</run>
|
200 |
+
</channelengine_generate_feed>
|
201 |
</jobs>
|
202 |
+
<events>
|
203 |
+
<resource_get_tablename>
|
204 |
+
<observers>
|
205 |
+
<channelengine_composer_autoloader>
|
206 |
+
<type>singleton</type>
|
207 |
+
<class>channelengine/loader</class>
|
208 |
+
<method>addComposerAutoloader</method>
|
209 |
+
</channelengine_composer_autoloader>
|
210 |
+
</observers>
|
211 |
+
</resource_get_tablename>
|
212 |
+
</events>
|
213 |
</crontab>
|
214 |
</config>
|
app/code/community/Tritac/ChannelEngine/etc/system.xml
CHANGED
@@ -33,14 +33,6 @@
|
|
33 |
<show_in_website>0</show_in_website>
|
34 |
<show_in_store>1</show_in_store>
|
35 |
</api_key>
|
36 |
-
<api_secret translate="label">
|
37 |
-
<label>Api Secret</label>
|
38 |
-
<frontend_type>text</frontend_type>
|
39 |
-
<sort_order>2</sort_order>
|
40 |
-
<show_in_default>0</show_in_default>
|
41 |
-
<show_in_website>0</show_in_website>
|
42 |
-
<show_in_store>1</show_in_store>
|
43 |
-
</api_secret>
|
44 |
<tenant translate="label">
|
45 |
<label>Account Name</label>
|
46 |
<frontend_type>text</frontend_type>
|
33 |
<show_in_website>0</show_in_website>
|
34 |
<show_in_store>1</show_in_store>
|
35 |
</api_key>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
<tenant translate="label">
|
37 |
<label>Account Name</label>
|
38 |
<frontend_type>text</frontend_type>
|
lib/ChannelEngine/.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
*
|
2 |
+
!.gitignore
|
lib/Tritac/ChannelEngineApiClient/AddTrustExternalCARoot.crt
DELETED
@@ -1,25 +0,0 @@
|
|
1 |
-
-----BEGIN CERTIFICATE-----
|
2 |
-
MIIENjCCAx6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBvMQswCQYDVQQGEwJTRTEU
|
3 |
-
MBIGA1UEChMLQWRkVHJ1c3QgQUIxJjAkBgNVBAsTHUFkZFRydXN0IEV4dGVybmFs
|
4 |
-
IFRUUCBOZXR3b3JrMSIwIAYDVQQDExlBZGRUcnVzdCBFeHRlcm5hbCBDQSBSb290
|
5 |
-
MB4XDTAwMDUzMDEwNDgzOFoXDTIwMDUzMDEwNDgzOFowbzELMAkGA1UEBhMCU0Ux
|
6 |
-
FDASBgNVBAoTC0FkZFRydXN0IEFCMSYwJAYDVQQLEx1BZGRUcnVzdCBFeHRlcm5h
|
7 |
-
bCBUVFAgTmV0d29yazEiMCAGA1UEAxMZQWRkVHJ1c3QgRXh0ZXJuYWwgQ0EgUm9v
|
8 |
-
dDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALf3GjPm8gAELTngTlvt
|
9 |
-
H7xsD821+iO2zt6bETOXpClMfZOfvUq8k+0DGuOPz+VtUFrWlymUWoCwSXrbLpX9
|
10 |
-
uMq/NzgtHj6RQa1wVsfwTz/oMp50ysiQVOnGXw94nZpAPA6sYapeFI+eh6FqUNzX
|
11 |
-
mk6vBbOmcZSccbNQYArHE504B4YCqOmoaSYYkKtMsE8jqzpPhNjfzp/haW+710LX
|
12 |
-
a0Tkx63ubUFfclpxCDezeWWkWaCUN/cALw3CknLa0Dhy2xSoRcRdKn23tNbE7qzN
|
13 |
-
E0S3ySvdQwAl+mG5aWpYIxG3pzOPVnVZ9c0p10a3CitlttNCbxWyuHv77+ldU9U0
|
14 |
-
WicCAwEAAaOB3DCB2TAdBgNVHQ4EFgQUrb2YejS0Jvf6xCZU7wO94CTLVBowCwYD
|
15 |
-
VR0PBAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wgZkGA1UdIwSBkTCBjoAUrb2YejS0
|
16 |
-
Jvf6xCZU7wO94CTLVBqhc6RxMG8xCzAJBgNVBAYTAlNFMRQwEgYDVQQKEwtBZGRU
|
17 |
-
cnVzdCBBQjEmMCQGA1UECxMdQWRkVHJ1c3QgRXh0ZXJuYWwgVFRQIE5ldHdvcmsx
|
18 |
-
IjAgBgNVBAMTGUFkZFRydXN0IEV4dGVybmFsIENBIFJvb3SCAQEwDQYJKoZIhvcN
|
19 |
-
AQEFBQADggEBALCb4IUlwtYj4g+WBpKdQZic2YR5gdkeWxQHIzZlj7DYd7usQWxH
|
20 |
-
YINRsPkyPef89iYTx4AWpb9a/IfPeHmJIZriTAcKhjW88t5RxNKWt9x+Tu5w/Rw5
|
21 |
-
6wwCURQtjr0W4MHfRnXnJK3s9EK0hZNwEGe6nQY1ShjTK3rMUUKhemPR5ruhxSvC
|
22 |
-
Nr4TDea9Y355e6cJDUCrat2PisP29owaQgVR1EX1n6diIWgVIEM8med8vSTYqZEX
|
23 |
-
c4g/VhsxOBi0cQ+azcgOno4uG+GMmIPLHzHxREzGBHNJdmAPx/i9F4BrLunMTA5a
|
24 |
-
mnkPIAou1Z5jJh5VkpTYghdae9C8x49OhgQ=
|
25 |
-
-----END CERTIFICATE-----
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/Tritac/ChannelEngineApiClient/Client.php
DELETED
@@ -1,282 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Tritac_ChannelEngineApiClient_Client {
|
4 |
-
|
5 |
-
private $environment;
|
6 |
-
private $tenant;
|
7 |
-
private $certificate;
|
8 |
-
|
9 |
-
private $apiUrl;
|
10 |
-
private $apiKey;
|
11 |
-
private $apiSecret;
|
12 |
-
|
13 |
-
private $lastRepresentation;
|
14 |
-
|
15 |
-
const FIDDLER_PROXY = '127.0.0.1:8888';
|
16 |
-
const USE_FIDDLER = false;
|
17 |
-
const FIDDLER_CERTIFICATE_PATH = 'fiddler.crt';
|
18 |
-
|
19 |
-
const ENV_DEVELOPMENT = 'dev';
|
20 |
-
const ENV_ACCEPTATION = 'acc';
|
21 |
-
const ENV_PRODUCTION = 'prod';
|
22 |
-
|
23 |
-
const DEV_URL = 'http://%s.channelengine.local';
|
24 |
-
const ACC_URL = 'http://%s.channelengine-acc.nl';
|
25 |
-
const PROD_URL = 'https://%s.channelengine.net';
|
26 |
-
|
27 |
-
const BASE_PATH = '/api/v1/';
|
28 |
-
const CERTIFICATE_PATH = 'AddTrustExternalCARoot.crt';
|
29 |
-
|
30 |
-
const ORDERS_PATH = 'orders/';
|
31 |
-
const SHIPMENTS_PATH = 'shipments/';
|
32 |
-
const RETURNS_PATH = 'returns/';
|
33 |
-
|
34 |
-
/**
|
35 |
-
* Create a new instance of the Kieskeurig Api client.
|
36 |
-
* @param string $apiKey Your personal Api key
|
37 |
-
* @param string $apiSecret Your personal Api secret
|
38 |
-
* @param string $tenant Your personal ChannelEngine name. If your ChannelEngine Url is https://yourshop.channelengine.net your personal name is "yourshop"
|
39 |
-
*/
|
40 |
-
public function __construct($apiKey, $apiSecret, $tenant, $environment = null)
|
41 |
-
{
|
42 |
-
if($environment == null || $environment == self::ENV_PRODUCTION){
|
43 |
-
$this->apiUrl = sprintf(self::PROD_URL, $tenant);
|
44 |
-
}elseif($environment == self::ENV_ACCEPTATION){
|
45 |
-
$this->apiUrl = sprintf(self::ACC_URL, $tenant);
|
46 |
-
}elseif($environment == self::ENV_DEVELOPMENT){
|
47 |
-
$this->apiUrl = sprintf(self::DEV_URL, $tenant);
|
48 |
-
}
|
49 |
-
|
50 |
-
$this->environment = $environment;
|
51 |
-
$this->tenant = $tenant;
|
52 |
-
$this->apiKey = $apiKey;
|
53 |
-
$this->apiSecret = $apiSecret;
|
54 |
-
$this->certificate = __DIR__ . DIRECTORY_SEPARATOR . (self::USE_FIDDLER ? self::FIDDLER_CERTIFICATE_PATH : self::CERTIFICATE_PATH);
|
55 |
-
|
56 |
-
$this->lastRepresentation = '';
|
57 |
-
}
|
58 |
-
|
59 |
-
/* Public API methods */
|
60 |
-
|
61 |
-
/* ORDERS */
|
62 |
-
|
63 |
-
/**
|
64 |
-
* Gets all orders with selected parameters
|
65 |
-
* @param array $statuses An array of ChannelEngineApiClient\Enums\OrderStatus or NULL for all new orders.
|
66 |
-
* @param DateTime $dateFrom Filter orders from the given date
|
67 |
-
* @param DateTime $dateTo Filter orders until the given date
|
68 |
-
* @return ChannelEngineApiClient\Helpers\MerchantOrderCollection The retrieved orders
|
69 |
-
*/
|
70 |
-
public function getOrders(array $statuses = array(Tritac_ChannelEngineApiClient_Enums_OrderStatus::NEW_ORDER), DateTime $dateFrom = null, DateTime $dateTo = null)
|
71 |
-
{
|
72 |
-
$args = array();
|
73 |
-
$args['OrderStatus'] = $statuses;
|
74 |
-
$args = $this->addDateArgs($dateFrom, $dateTo, $args);
|
75 |
-
|
76 |
-
$url = self::BASE_PATH . self::ORDERS_PATH;
|
77 |
-
$result = $this->makeRequest(Tritac_ChannelEngineApiClient_Helpers_HttpMethod::GET, $url, $this->createQueryString($args));
|
78 |
-
return Tritac_ChannelEngineApiClient_Helpers_JsonMapper::fromJson($result, 'Tritac_ChannelEngineApiClient_Helpers_Collection(Tritac_ChannelEngineApiClient_Models_Order)');
|
79 |
-
}
|
80 |
-
|
81 |
-
/* SHIPMENTS */
|
82 |
-
|
83 |
-
/**
|
84 |
-
* Create a new shipment for the given order with the given lines
|
85 |
-
* @param ChannelEngineApiClient\Models\Shipment $shipment The shipment to send
|
86 |
-
*/
|
87 |
-
public function postShipment(Tritac_ChannelEngineApiClient_Models_Shipment $shipment)
|
88 |
-
{
|
89 |
-
$url = self::BASE_PATH . self::SHIPMENTS_PATH;
|
90 |
-
$result = $this->makeRequest(Tritac_ChannelEngineApiClient_Helpers_HttpMethod::POST, $url, '', Tritac_ChannelEngineApiClient_Helpers_JsonMapper::toJson($shipment));
|
91 |
-
return Tritac_ChannelEngineApiClient_Helpers_JsonMapper::fromJson($result, 'Tritac_ChannelEngineApiClient_Models_Shipment');
|
92 |
-
}
|
93 |
-
|
94 |
-
/**
|
95 |
-
* Update an existing Shipment
|
96 |
-
* @param ChannelEngineApiClient\Models\Shipment $shipment The shipment to send
|
97 |
-
*/
|
98 |
-
public function putShipment(Tritac_ChannelEngineApiClient_Models_Shipment $shipment)
|
99 |
-
{
|
100 |
-
$url = self::BASE_PATH . self::SHIPMENTS_PATH;
|
101 |
-
$result = $this->makeRequest(Tritac_ChannelEngineApiClient_Helpers_HttpMethod::PUT, $url, '', Tritac_ChannelEngineApiClient_Helpers_JsonMapper::toJson($shipment));
|
102 |
-
return Tritac_ChannelEngineApiClient_Helpers_JsonMapper::fromJson($result, 'Tritac_ChannelEngineApiClient_Models_Shipment');
|
103 |
-
}
|
104 |
-
|
105 |
-
/* RETURNS */
|
106 |
-
|
107 |
-
/**
|
108 |
-
* Gets all orders with selected parameters
|
109 |
-
* @param array $statuses An array of ChannelEngineApiClient\Enums\ReturnStatus or NULL for all declared returns
|
110 |
-
* @param DateTime $dateFrom Filter returns from the given date
|
111 |
-
* @param DateTime $dateTo Filter returns until the given date
|
112 |
-
* @return ChannelEngineApiClient\Helpers\ReturnCollection The retrieved returns
|
113 |
-
*/
|
114 |
-
public function getReturns(array $statuses = array(Tritac_ChannelEngineApiClient_Enums_ReturnStatus::DECLARED), DateTime $dateFrom = null, DateTime $dateTo = null)
|
115 |
-
{
|
116 |
-
$args = array();
|
117 |
-
$args['Status'] = $statuses;
|
118 |
-
$args = $this->addDateArgs($dateFrom, $dateTo, $args);
|
119 |
-
|
120 |
-
$url = self::BASE_PATH . self::RETURNS_PATH;
|
121 |
-
$result = $this->makeRequest(Tritac_ChannelEngineApiClient_Helpers_HttpMethod::GET, $url, $this->createQueryString($args));
|
122 |
-
return Tritac_ChannelEngineApiClient_Helpers_JsonMapper::fromJson($result, 'Tritac_ChannelEngineApiClient_Helpers_Collection(Tritac_ChannelEngineApiClient_Models_ReturnObject)');
|
123 |
-
}
|
124 |
-
|
125 |
-
/**
|
126 |
-
* Create a new return for the given shipment with the given lines
|
127 |
-
* @param ChannelEngineApiClient\Models\ReturnObject $return The shipment to send
|
128 |
-
*/
|
129 |
-
public function postReturn(Tritac_ChannelEngineApiClient_Models_ReturnObject $return)
|
130 |
-
{
|
131 |
-
$url = self::BASE_PATH . self::RETURNS_PATH;
|
132 |
-
$result = $this->makeRequest(Tritac_ChannelEngineApiClient_Helpers_HttpMethod::POST, $url, '', Tritac_ChannelEngineApiClient_Helpers_JsonMapper::toJson($return));
|
133 |
-
return Tritac_ChannelEngineApiClient_Helpers_JsonMapper::fromJson($result, 'Tritac_ChannelEngineApiClient_Models_ReturnObject');
|
134 |
-
}
|
135 |
-
|
136 |
-
/**
|
137 |
-
* Updates the status of the given return
|
138 |
-
* @param ChannelEngineApiClient\Models\ReturnObject $return The return to update
|
139 |
-
*/
|
140 |
-
public function putReturn(Tritac_ChannelEngineApiClient_Models_ReturnObject $return)
|
141 |
-
{
|
142 |
-
$url = self::BASE_PATH . self::RETURNS_PATH;
|
143 |
-
$result = $this->makeRequest(Tritac_ChannelEngineApiClient_Helpers_HttpMethod::PUT, $url, '', Tritac_ChannelEngineApiClient_Helpers_JsonMapper::toJson($return));
|
144 |
-
return Tritac_ChannelEngineApiClient_Helpers_JsonMapper::fromJson($result, 'Tritac_ChannelEngineApiClient_Models_ReturnObject');
|
145 |
-
}
|
146 |
-
|
147 |
-
/* Private methods */
|
148 |
-
|
149 |
-
private function makeRequest($method, $url, $queryString = '', $content = null)
|
150 |
-
{
|
151 |
-
$request = curl_init();
|
152 |
-
|
153 |
-
// Create the required Http headers and Hmac signature
|
154 |
-
$headers = $this->buildHeaders($method, $url, $content);
|
155 |
-
|
156 |
-
if($this->environment == self::ENV_DEVELOPMENT && self::USE_FIDDLER)
|
157 |
-
{
|
158 |
-
// We use this to redirect the request through a local proxy and trace it with fiddler
|
159 |
-
curl_setopt($request, CURLOPT_PROXY, self::FIDDLER_PROXY);
|
160 |
-
}
|
161 |
-
|
162 |
-
// Set the Url
|
163 |
-
curl_setopt($request, CURLOPT_URL, $this->apiUrl . $url . $queryString);
|
164 |
-
|
165 |
-
// Add the headers and hmac auth.
|
166 |
-
curl_setopt($request, CURLOPT_HTTPHEADER, $headers);
|
167 |
-
|
168 |
-
// Return the response as a string
|
169 |
-
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
|
170 |
-
|
171 |
-
// Set custom request method because curl has no setting for PUT and DELETE
|
172 |
-
curl_setopt($request, CURLOPT_CUSTOMREQUEST, $method);
|
173 |
-
|
174 |
-
// Make the headers accessible for debugging purposes
|
175 |
-
curl_setopt($request, CURLINFO_HEADER_OUT, true);
|
176 |
-
|
177 |
-
// Point curl to the correct certificate.
|
178 |
-
// See: http://stackoverflow.com/questions/6400300/php-curl-https-causing-exception-ssl-certificate-problem-verify-that-the-ca-cer
|
179 |
-
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, true);
|
180 |
-
curl_setopt($request, CURLOPT_CAINFO, $this->certificate);
|
181 |
-
|
182 |
-
// If we have a request body send it too
|
183 |
-
if(strlen($content) > 0)
|
184 |
-
curl_setopt($request, CURLOPT_POSTFIELDS, $content);
|
185 |
-
|
186 |
-
// Make the request
|
187 |
-
$response = curl_exec($request);
|
188 |
-
|
189 |
-
// Get the status code
|
190 |
-
$status = curl_getinfo($request, CURLINFO_HTTP_CODE);
|
191 |
-
|
192 |
-
// Check for errors
|
193 |
-
// First we check if the response is missing which will probably be caused by a cURL error
|
194 |
-
// After this the check if there are not HTTP errors (status codes other than 200-206)
|
195 |
-
if ($response === false)
|
196 |
-
{
|
197 |
-
$error = curl_error($request);
|
198 |
-
curl_close($request);
|
199 |
-
throw new Exception('cURL error: ' . $error);
|
200 |
-
}
|
201 |
-
else if($status < 200 || $status > 206)
|
202 |
-
{
|
203 |
-
$headers = curl_getinfo($request, CURLINFO_HEADER_OUT);
|
204 |
-
$message = Tritac_ChannelEngineApiClient_Helpers_JsonMapper::fromJson($response, 'Tritac_ChannelEngineApiClient_Models_Message');
|
205 |
-
curl_close($request);
|
206 |
-
|
207 |
-
throw new Exception("\r\n".
|
208 |
-
'------Sent Headers-------------' . "\r\n" . $headers . "\r\n" .
|
209 |
-
'------Sent Content-------------' . "\r\n" . $content . "\r\n" .
|
210 |
-
'------Used Representation------' . "\r\n" . $this->lastRepresentation . "\r\n" .
|
211 |
-
'------Response Status----------' . "\r\n" . $status . "\r\n" .
|
212 |
-
'------Response Content---------' . "\r\n" . $message->getMessage() . "\r\n"
|
213 |
-
);
|
214 |
-
}
|
215 |
-
else
|
216 |
-
{
|
217 |
-
curl_close($request);
|
218 |
-
|
219 |
-
return $response;
|
220 |
-
}
|
221 |
-
}
|
222 |
-
|
223 |
-
private function buildHeaders($method, $url, $content = null)
|
224 |
-
{
|
225 |
-
$date = time();
|
226 |
-
$headers = array(
|
227 |
-
'Accept: application/json',
|
228 |
-
'Authorization: HMAC ' . $this->apiKey . ':' . $this->calculateHmac($method, $url, $date, $content),
|
229 |
-
'Content-Type: application/json; charset=utf-8',
|
230 |
-
'Content-Length: ' . strlen($content),
|
231 |
-
'Content-MD5: ' . ((strlen($content) > 0) ? base64_encode(md5($content, true)) : ''),
|
232 |
-
'Date: ' . gmdate('D, d M Y H:i:s', $date) . ' GMT',
|
233 |
-
);
|
234 |
-
|
235 |
-
return $headers;
|
236 |
-
}
|
237 |
-
|
238 |
-
/*
|
239 |
-
Builds message representation as follows:
|
240 |
-
|
241 |
-
Timestamp\n +
|
242 |
-
HTTP METHOD\n +
|
243 |
-
Request URI
|
244 |
-
Content-MD5 (base64)\n +
|
245 |
-
apikey\n +
|
246 |
-
|
247 |
-
*/
|
248 |
-
private function calculateHmac($method, $url, $date, $content = null)
|
249 |
-
{
|
250 |
-
$representation = array(
|
251 |
-
gmdate('m/d/Y H:i:s', $date),
|
252 |
-
$method,
|
253 |
-
$url,
|
254 |
-
(strlen($content) > 0) ? base64_encode(md5($content, true)) : '',
|
255 |
-
$this->apiKey
|
256 |
-
);
|
257 |
-
$representationString = implode("\n", $representation);
|
258 |
-
|
259 |
-
$this->lastRepresentation = $representationString;
|
260 |
-
|
261 |
-
$hash = hash_hmac('sha256', utf8_encode($representationString), utf8_encode($this->apiSecret), true);
|
262 |
-
$signature = base64_encode($hash);
|
263 |
-
|
264 |
-
return $signature;
|
265 |
-
}
|
266 |
-
|
267 |
-
private function createQueryString(array $args)
|
268 |
-
{
|
269 |
-
$queryString = (count($args) > 0) ? '?' . http_build_query($args) : '';
|
270 |
-
|
271 |
-
// .Net does not seem to like the /?foo[0]=bar&foo[1]=baz notation so we
|
272 |
-
// convert it to /?foo=bar&foo=baz
|
273 |
-
return preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $queryString);
|
274 |
-
}
|
275 |
-
|
276 |
-
private function addDateArgs(DateTime $dateFrom = null, DateTime $dateTo = null, array $args)
|
277 |
-
{
|
278 |
-
if(!is_null($dateFrom)) $args['FromDate'] = $dateFrom->format('Y-m-d H:i:s');
|
279 |
-
if(!is_null($dateTo)) $args['ToDate'] = $dateTo->format('Y-m-d H:i:s');
|
280 |
-
return $args;
|
281 |
-
}
|
282 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/Tritac/ChannelEngineApiClient/Enums/CancellationLineStatus.php
DELETED
@@ -1,8 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
class Tritac_ChannelEngineApiClient_Enums_CancellationLineStatus {
|
3 |
-
|
4 |
-
const PENDING = 0;
|
5 |
-
const ACCEPTED = 1;
|
6 |
-
const REJECTED = 2;
|
7 |
-
|
8 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/Tritac/ChannelEngineApiClient/Enums/CancellationStatus.php
DELETED
@@ -1,9 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
class Tritac_ChannelEngineApiClient_Enums_CancellationStatus {
|
3 |
-
|
4 |
-
const PENDING = 0;
|
5 |
-
const CLOSED = 2; // refunded or maybe not
|
6 |
-
const REFUND_STARTED = 3;
|
7 |
-
const REFUND_FAILED = 4;
|
8 |
-
|
9 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/Tritac/ChannelEngineApiClient/Enums/Gender.php
DELETED
@@ -1,8 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
class Tritac_ChannelEngineApiClient_Enums_Gender {
|
3 |
-
|
4 |
-
const MALE = 1;
|
5 |
-
const FEMALE = 2;
|
6 |
-
const NOT_APPLICABLE = 3;
|
7 |
-
|
8 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/Tritac/ChannelEngineApiClient/Enums/MancoReason.php
DELETED
@@ -1,8 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
class Tritac_ChannelEngineApiClient_Enums_MancoReason {
|
3 |
-
const NOT_IN_STOCK = 0;
|
4 |
-
const DAMAGED = 1;
|
5 |
-
const INCOMPLETE = 2;
|
6 |
-
const CLIENT_CANCELLED = 3;
|
7 |
-
const OTHER = 99;
|
8 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/Tritac/ChannelEngineApiClient/Enums/OrderStatus.php
DELETED
@@ -1,13 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
class Tritac_ChannelEngineApiClient_Enums_OrderStatus {
|
3 |
-
|
4 |
-
const IN_PROGRESS = 0;
|
5 |
-
const SHIPPED = 1;
|
6 |
-
const IN_BACKORDER = 2;
|
7 |
-
const CANCELED = 3;
|
8 |
-
const MANCO = 4;
|
9 |
-
const IN_COMBI = 5; // combi: one or more not closed
|
10 |
-
const CLOSED = 6; // combi:closed
|
11 |
-
const NEW_ORDER = 7; // renamed NEW to NEW_ORDER because new is a protected keyword in php
|
12 |
-
|
13 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/Tritac/ChannelEngineApiClient/Enums/ReturnAcceptStatus.php
DELETED
@@ -1,6 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
class Tritac_ChannelEngineApiClient_Enums_ReturnAcceptStatus {
|
3 |
-
const PENDING = 0;
|
4 |
-
const ACCEPTED = 1;
|
5 |
-
const REJECTED = 2; // refunded
|
6 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
lib/Tritac/ChannelEngineApiClient/Enums/ReturnReason.php
DELETED
@@ -1,10 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
class Tritac_ChannelEngineApiClient_Enums_ReturnReason {
|
3 |
-
const PRODUCT_DEFECT = 0;
|
4 |
-
const PRODUCT_UNSATISFACTORY = 1;
|
5 |
-
const REFUSED = 4;
|
6 |
-
const REFUSED_DAMAGED = 5;
|
7 |
-
const WRONG_ADDRESS = 6;
|
8 |
-
const NOT_COLLECTED = 7;
|
9 |
-
const OTHER = 99;
|
10 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/Tritac/ChannelEngineApiClient/Enums/ReturnStatus.php
DELETED
@@ -1,6 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
class Tritac_ChannelEngineApiClient_Enums_ReturnStatus {
|
3 |
-
const DECLARED = 0;
|
4 |
-
const RECEIVED = 1;
|
5 |
-
const CLOSED = 2;
|
6 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
lib/Tritac/ChannelEngineApiClient/Enums/ShipmentLineStatus.php
DELETED
@@ -1,8 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
class Tritac_ChannelEngineApiClient_Enums_ShipmentLineStatus {
|
3 |
-
|
4 |
-
const SHIPPED = 1;
|
5 |
-
const IN_BACKORDER = 2;
|
6 |
-
const MANCO = 4;
|
7 |
-
|
8 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/Tritac/ChannelEngineApiClient/Enums/ShipmentStatus.php
DELETED
@@ -1,5 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
class Tritac_ChannelEngineApiClient_Enums_ShipmentStatus {
|
3 |
-
const PENDING = 0;
|
4 |
-
const CLOSED = 2;
|
5 |
-
}
|
|
|
|
|
|
|
|
|
|
lib/Tritac/ChannelEngineApiClient/Helpers/Collection.php
DELETED
@@ -1,49 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
class Tritac_ChannelEngineApiClient_Helpers_Collection extends ArrayObject{
|
3 |
-
|
4 |
-
private $type;
|
5 |
-
private $test;
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
public function __construct($type = 'stdObject')
|
10 |
-
{
|
11 |
-
$matches = array();
|
12 |
-
if(preg_match('/Collection\(([\\\\\w]+)\)$/', $type, $matches))
|
13 |
-
{
|
14 |
-
$this->type = $matches[1];
|
15 |
-
}
|
16 |
-
else
|
17 |
-
{
|
18 |
-
$this->type = $type;
|
19 |
-
}
|
20 |
-
|
21 |
-
$this->test = new $this->type();
|
22 |
-
}
|
23 |
-
|
24 |
-
public function append($item)
|
25 |
-
{
|
26 |
-
$this->checkType($item);
|
27 |
-
parent::append($item);
|
28 |
-
}
|
29 |
-
|
30 |
-
public function offsetSet($idx, $item)
|
31 |
-
{
|
32 |
-
$this->checkType($item);
|
33 |
-
parent::offsetSet($idx, $item);
|
34 |
-
}
|
35 |
-
|
36 |
-
private function checkType($item)
|
37 |
-
{
|
38 |
-
if(!($item instanceof $this->test))
|
39 |
-
{
|
40 |
-
throw new Exception('Invalid type inserted in list with type ' . $this->type);
|
41 |
-
}
|
42 |
-
}
|
43 |
-
|
44 |
-
public function getTypeName()
|
45 |
-
{
|
46 |
-
return $this->type;
|
47 |
-
}
|
48 |
-
|
49 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/Tritac/ChannelEngineApiClient/Helpers/HttpMethod.php
DELETED
@@ -1,9 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
class Tritac_ChannelEngineApiClient_Helpers_HttpMethod {
|
3 |
-
|
4 |
-
const GET = 'GET';
|
5 |
-
const POST = 'POST';
|
6 |
-
const PUT = 'PUT';
|
7 |
-
const DELETE = 'DELETE';
|
8 |
-
|
9 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/Tritac/ChannelEngineApiClient/Helpers/JsonMapper.php
DELETED
@@ -1,91 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
class Tritac_ChannelEngineApiClient_Helpers_JsonMapper {
|
3 |
-
|
4 |
-
public static function fromJson($jsonString, $rootType)
|
5 |
-
{
|
6 |
-
$jsonRoot = json_decode($jsonString);
|
7 |
-
return self::convertToObject($jsonRoot, $rootType);
|
8 |
-
}
|
9 |
-
|
10 |
-
private static function convertToObject($jsonObject, $jsonType)
|
11 |
-
{
|
12 |
-
$rootObject = null;
|
13 |
-
if(preg_match('/Collection\(([\\\\\w]+)\)$/', $jsonType))
|
14 |
-
{
|
15 |
-
$rootObject = new Tritac_ChannelEngineApiClient_Helpers_Collection($jsonType);
|
16 |
-
if(is_array($jsonObject))
|
17 |
-
{
|
18 |
-
foreach ($jsonObject as $jsonChildObject)
|
19 |
-
{
|
20 |
-
$rootObject[] = self::convertToObject($jsonChildObject, $rootObject->getTypeName());
|
21 |
-
}
|
22 |
-
}
|
23 |
-
}
|
24 |
-
else
|
25 |
-
{
|
26 |
-
$rootObject = new $jsonType();
|
27 |
-
if($jsonObject != null){
|
28 |
-
foreach (get_object_vars($jsonObject) as $key => $value)
|
29 |
-
{
|
30 |
-
if(array_key_exists(lcfirst($key), $rootObject::$typeMap))
|
31 |
-
{
|
32 |
-
$value = self::convertToObject($value, $rootObject::$typeMap[lcfirst($key)]);
|
33 |
-
}
|
34 |
-
$action = 'set' . $key;
|
35 |
-
if(method_exists($rootObject, $action))
|
36 |
-
{
|
37 |
-
$rootObject->{$action}($value);
|
38 |
-
}
|
39 |
-
}
|
40 |
-
}
|
41 |
-
}
|
42 |
-
return $rootObject;
|
43 |
-
}
|
44 |
-
|
45 |
-
private static function isIterable($var)
|
46 |
-
{
|
47 |
-
return ($var !== null && (is_array($var) || $var instanceof Iterator || $var instanceof IteratorAggregate));
|
48 |
-
}
|
49 |
-
|
50 |
-
public static function toJson($object)
|
51 |
-
{
|
52 |
-
return json_encode(self::convertFromObject($object));
|
53 |
-
}
|
54 |
-
|
55 |
-
public static function convertFromObject($root, $d = 0, $mustexist = false)
|
56 |
-
{
|
57 |
-
if($root instanceof Tritac_ChannelEngineApiClient_Helpers_Collection)
|
58 |
-
{
|
59 |
-
$root = $root->getArrayCopy();
|
60 |
-
foreach($root as $key => $value)
|
61 |
-
{
|
62 |
-
if($value instanceof Tritac_ChannelEngineApiClient_Models_BaseModel || $value instanceof Tritac_ChannelEngineApiClient_Helpers_Collection)
|
63 |
-
$root[ucfirst($key)] = self::convertFromObject($value, $d+1, true);
|
64 |
-
}
|
65 |
-
return $root;
|
66 |
-
}
|
67 |
-
elseif($root instanceof Tritac_ChannelEngineApiClient_Models_BaseModel)
|
68 |
-
{
|
69 |
-
$newRoot = new stdClass();
|
70 |
-
foreach($root->getProperties() as $key => $value)
|
71 |
-
{
|
72 |
-
if($value instanceof Tritac_ChannelEngineApiClient_Models_BaseModel || $value instanceof Tritac_ChannelEngineApiClient_Helpers_Collection)
|
73 |
-
{
|
74 |
-
$newRoot->{ucfirst($key)} = self::convertFromObject($value, $d+1, true);
|
75 |
-
}
|
76 |
-
else
|
77 |
-
{
|
78 |
-
$newRoot->{ucfirst($key)} = $value;
|
79 |
-
}
|
80 |
-
|
81 |
-
}
|
82 |
-
return $newRoot;
|
83 |
-
}
|
84 |
-
elseif($mustexist)
|
85 |
-
{
|
86 |
-
throw new Exception('No or invalid object given to the function.');
|
87 |
-
}
|
88 |
-
|
89 |
-
return new stdClass();
|
90 |
-
}
|
91 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/Tritac/ChannelEngineApiClient/Models/Address.php
DELETED