Skip to content

Commit 3d819ad

Browse files
committed
Merge pull request #5 from erfanimani/improvements
Added pause sync feature in case third-party API isn't available, cleaned up code, incremented version to 0.1.0
2 parents 26388cd + 7a0e2a1 commit 3d819ad

9 files changed

Lines changed: 86 additions & 26 deletions

File tree

app/code/community/ProxiBlue/OrderSyncQueRunner/Helper/Data.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
<?php
22

3-
class ProxiBlue_OrderSyncQueRunner_Helper_Data extends Mage_Core_Helper_Abstract
3+
class ProxiBlue_OrderSyncQueRunner_Helper_Data
4+
extends Mage_Core_Helper_Abstract
45
{
6+
7+
public function isSyncPaused()
8+
{
9+
$path = 'ordersyncquerunner/general/pause_order_sync';
10+
return (bool)Mage::getStoreConfig($path);
11+
}
12+
513
}
6-

app/code/community/ProxiBlue/OrderSyncQueRunner/Model/Cron.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ class ProxiBlue_OrderSyncQueRunner_Model_Cron
1919
public static function sync($schedule)
2020
{
2121
try {
22-
$syncModel = Mage::getModel('ordersyncquerunner/que')
22+
$queueCollection = Mage::getModel('ordersyncquerunner/que')
2323
->getCollection()
2424
->addFieldToFilter('synced_at', array('null' => true));
25-
ProxiBlue_OrderSyncQueRunner_Model_Que::doSync($syncModel);
25+
ProxiBlue_OrderSyncQueRunner_Model_Que::doSync($queueCollection);
2626
} catch (Exception $e) {
2727
// save any errors.
2828
Mage::logException($e);
@@ -55,6 +55,4 @@ public static function clean($schedule)
5555
}
5656
}
5757

58-
59-
6058
}

app/code/community/ProxiBlue/OrderSyncQueRunner/Model/Observer.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class ProxiBlue_OrderSyncQueRunner_Model_Observer
1919
*/
2020
public function sales_order_place_after(Varien_Event_Observer $observer)
2121
{
22-
2322
$order = $observer->getEvent()->getOrder();
2423
try {
2524
$syncModel = Mage::getModel('ordersyncquerunner/que');
@@ -31,14 +30,18 @@ public function sales_order_place_after(Varien_Event_Observer $observer)
3130
$syncModel->setData($data);
3231
$syncModel->save();
3332
} catch (Exception $e) {
34-
Mage::log('could not place order into sync que !' . $e->getMessage());
35-
// attempt to sync right now.
36-
Mage::dispatchEvent(
37-
'sales_order_place_after_que',
38-
array('order'=>$order)
39-
);
33+
Mage::log("Couldn't place order into sync queue! " . $e->getMessage());
34+
35+
// Attempt to sync right now if sync isn't paused
36+
if (!Mage::helper('ordersyncquerunner')->isSyncPaused()) {
37+
Mage::dispatchEvent(
38+
'sales_order_place_after_que',
39+
array('order' => $order)
40+
);
41+
}
42+
4043
}
4144
return $this;
4245
}
4346

44-
}
47+
}

app/code/community/ProxiBlue/OrderSyncQueRunner/Model/Que.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
11
<?php
22

33
/**
4-
*
4+
* Queue model
55
*
66
* @category ProxiBlue
77
* @package ProxiBlue_OrderSyncQueRunner
88
* @author Lucas van Staden (support@proxiblue.com.au)
99
*/
1010
class ProxiBlue_OrderSyncQueRunner_Model_Que extends Mage_Core_Model_Abstract
1111
{
12-
protected function _construct(){
12+
13+
protected function _construct()
14+
{
1315
$this->_init("ordersyncquerunner/que");
1416
}
1517

1618
/**
1719
* Handle sync of data
18-
* Dispatches new event to efect sync
20+
* Dispatches new event to effect sync
1921
*
20-
* @param type $syncModel
22+
* @param ProxiBlue_OrderSyncQueRunner_Model_Resource_Que_Collection $syncModel
2123
*/
22-
static public function doSync($syncModel) {
24+
static public function doSync(
25+
ProxiBlue_OrderSyncQueRunner_Model_Resource_Que_Collection $syncModel
26+
) {
2327
$helper = Mage::helper('ordersyncquerunner');
28+
29+
if ($helper->isSyncPaused()) {
30+
return;
31+
}
32+
2433
foreach ($syncModel as $sync) {
2534
$order = Mage::getModel('sales/order')->load($sync->getEntityId());
2635
try {

app/code/community/ProxiBlue/OrderSyncQueRunner/Model/Resource/Que/Collection.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
*
4+
* Queue collection
55
*
66
* @category ProxiBlue
77
* @package ProxiBlue_OrderSyncQueRunner
@@ -12,7 +12,8 @@ class ProxiBlue_OrderSyncQueRunner_Model_Resource_Que_Collection
1212
extends Mage_Core_Model_Mysql4_Collection_Abstract
1313
{
1414

15-
public function _construct() {
15+
public function _construct()
16+
{
1617
$this->_init("ordersyncquerunner/que");
1718
}
1819

app/code/community/ProxiBlue/OrderSyncQueRunner/etc/adminhtml.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
<children>
1919
<config>
2020
<children>
21-
<ordersyncquemanager>
22-
<title>Sync Queue Manager</title>
23-
</ordersyncquemanager>
21+
<ordersyncquerunner>
22+
<title>Order Sync Queue Manager</title>
23+
</ordersyncquerunner>
2424
</children>
2525
</config>
2626
</children>

app/code/community/ProxiBlue/OrderSyncQueRunner/etc/config.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<config>
33
<modules>
44
<ProxiBlue_OrderSyncQueRunner>
5-
<version>0.0.2</version>
5+
<version>0.1.0</version>
66
</ProxiBlue_OrderSyncQueRunner>
77
</modules>
88
<global>
@@ -83,4 +83,11 @@
8383
</adminhtml>
8484
</routers>
8585
</admin>
86+
<default>
87+
<ordersyncquerunner>
88+
<general>
89+
<pause_order_sync>0</pause_order_sync>
90+
</general>
91+
</ordersyncquerunner>
92+
</default>
8693
</config>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0"?>
2+
<config>
3+
<sections>
4+
<ordersyncquerunner translate="label" module="ordersyncquerunner">
5+
<label>Order Sync Queue Manager</label>
6+
<tab>sales</tab>
7+
<frontend_type>text</frontend_type>
8+
<sort_order>1100</sort_order>
9+
<show_in_default>1</show_in_default>
10+
<!-- Don't show in other scopes because it's run only on admin anyway -->
11+
<show_in_website>0</show_in_website>
12+
<show_in_store>0</show_in_store>
13+
<groups>
14+
<general translate="label">
15+
<label>General</label>
16+
<frontend_type>text</frontend_type>
17+
<sort_order>10</sort_order>
18+
<show_in_default>1</show_in_default>
19+
<expanded>1</expanded>
20+
<fields>
21+
<pause_order_sync translate="label">
22+
<label>Pause queue sync</label>
23+
<frontend_type>select</frontend_type>
24+
<source_model>adminhtml/system_config_source_yesno</source_model>
25+
<sort_order>10</sort_order>
26+
<show_in_default>1</show_in_default>
27+
<comment>Orders will still be saved to the queue, but won't be synced until unpaused. This could cause a lot of processing if you unpause it after a long time period.</comment>
28+
</pause_order_sync>
29+
</fields>
30+
</general>
31+
</groups>
32+
</ordersyncquerunner>
33+
</sections>
34+
</config>

app/code/community/ProxiBlue/OrderSyncQueRunner/sql/ordersyncquerunner_setup/install-0.0.1.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
->addColumn('synced_at', Varien_Db_Ddl_Table::TYPE_DATETIME, null, array(
2727
'unsigned' => true,
2828
'nullable' => true,
29-
), 'Synced') ;
29+
), 'Synced');
30+
3031
$installer->getConnection()->createTable($table);
3132
$installer->endSetup();

0 commit comments

Comments
 (0)