Version Notes
- sync orders from Magento to iConnect POS
Download this release
Release Info
Developer | InspireSmart inc. |
Extension | InspireSmart_IConnectSync |
Version | 1.2.1.0 |
Comparing to | |
See all releases |
Version 1.2.1.0
- app/code/community/InspireSmart/IConnectSync/Block/Adminhtml/System/Store/Edit/Form.php +24 -0
- app/code/community/InspireSmart/IConnectSync/Block/Button.php +22 -0
- app/code/community/InspireSmart/IConnectSync/Helper/Data.php +91 -0
- app/code/community/InspireSmart/IConnectSync/Model/Cron.php +70 -0
- app/code/community/InspireSmart/IConnectSync/Model/Observer.php +51 -0
- app/code/community/InspireSmart/IConnectSync/Model/Product.php +121 -0
- app/code/community/InspireSmart/IConnectSync/Model/Que.php +164 -0
- app/code/community/InspireSmart/IConnectSync/Model/Resource/Que.php +18 -0
- app/code/community/InspireSmart/IConnectSync/Model/Resource/Que/Collection.php +17 -0
- app/code/community/InspireSmart/IConnectSync/controllers/SynchronizeController.php +28 -0
- app/code/community/InspireSmart/IConnectSync/etc/config.xml +182 -0
- app/code/community/InspireSmart/IConnectSync/etc/system.xml +59 -0
- app/code/community/InspireSmart/IConnectSync/sql/iconnectsync_setup/install-1.0.0.php +113 -0
- app/etc/modules/InspireSmart_IConnectSync.xml +12 -0
- package.xml +18 -0
app/code/community/InspireSmart/IConnectSync/Block/Adminhtml/System/Store/Edit/Form.php
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class InspireSmart_IConnectSync_Block_Adminhtml_System_Store_Edit_Form extends Mage_Adminhtml_Block_System_Store_Edit_Form{
|
3 |
+
protected function _prepareForm(){
|
4 |
+
parent::_prepareForm();
|
5 |
+
if (Mage::registry('store_type') == 'website'){
|
6 |
+
$websiteModel = Mage::registry('store_data');
|
7 |
+
|
8 |
+
$fieldset = $this->getForm()->getElement('website_fieldset');
|
9 |
+
|
10 |
+
$fieldset->addField('iconnect_location_id', 'text', array(
|
11 |
+
'name' => 'website[iconnect_location_id]',
|
12 |
+
'label' => Mage::helper('core')->__('iConnect Location Id'),
|
13 |
+
'value' => $websiteModel->getData('iconnect_location_id'),
|
14 |
+
'required' => false
|
15 |
+
));
|
16 |
+
|
17 |
+
$fieldset->addField('synchronize_location', 'hidden', array(
|
18 |
+
'name' => 'website[synchronize_location]',
|
19 |
+
'value' => (int)$websiteModel->getData('synchronize_location'),
|
20 |
+
));
|
21 |
+
}
|
22 |
+
return $this;
|
23 |
+
}
|
24 |
+
}
|
app/code/community/InspireSmart/IConnectSync/Block/Button.php
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class InspireSmart_IConnectSync_Block_Button extends Mage_Adminhtml_Block_System_Config_Form_Field
|
4 |
+
{
|
5 |
+
|
6 |
+
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
|
7 |
+
{
|
8 |
+
$this->setElement($element);
|
9 |
+
$url = $this->getUrl('iconnect/synchronize');
|
10 |
+
|
11 |
+
$html = $this->getLayout()->createBlock('adminhtml/widget_button')
|
12 |
+
->setType('button')
|
13 |
+
->setClass('scalable')
|
14 |
+
->setLabel('Synchronize...')
|
15 |
+
->setOnClick("setLocation('$url')")
|
16 |
+
->toHtml();
|
17 |
+
|
18 |
+
return $html;
|
19 |
+
}
|
20 |
+
}
|
21 |
+
|
22 |
+
?>
|
app/code/community/InspireSmart/IConnectSync/Helper/Data.php
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Sample Widget Helper
|
4 |
+
*/
|
5 |
+
class InspireSmart_IConnectSync_Helper_Data extends Mage_Core_Helper_Abstract
|
6 |
+
{
|
7 |
+
public function isSyncPaused()
|
8 |
+
{
|
9 |
+
return (bool)Mage::getStoreConfig('iconnectsync/general/pause_sync');
|
10 |
+
}
|
11 |
+
|
12 |
+
public function orderSyncStatus()
|
13 |
+
{
|
14 |
+
return Mage::getStoreConfig('iconnectsync/general/sync_order_on_status');
|
15 |
+
}
|
16 |
+
|
17 |
+
public function getDefaultAttributeSetId()
|
18 |
+
{
|
19 |
+
$entityTypeId = Mage::getModel('eav/entity')
|
20 |
+
->setType('catalog_product')
|
21 |
+
->getTypeId();
|
22 |
+
$attributeSetName = 'Default';
|
23 |
+
$attributeSetId = Mage::getModel('eav/entity_attribute_set')
|
24 |
+
->getCollection()
|
25 |
+
->setEntityTypeFilter($entityTypeId)
|
26 |
+
->addFieldToFilter('attribute_set_name', $attributeSetName)
|
27 |
+
->getFirstItem()
|
28 |
+
->getAttributeSetId();
|
29 |
+
|
30 |
+
return $attributeSetId;
|
31 |
+
}
|
32 |
+
|
33 |
+
public function getData($api, $page=NULL, $version=NULL)
|
34 |
+
{
|
35 |
+
$token = Mage::getStoreConfig('iconnectsync/general/iconnect_api_token');
|
36 |
+
$host = Mage::getStoreConfig('iconnectsync/general/iconnect_api_url');
|
37 |
+
$args = array_slice(func_get_args(),1);
|
38 |
+
array_push($args,$token);
|
39 |
+
if( $curl = curl_init()) {
|
40 |
+
curl_setopt_array($curl, array(
|
41 |
+
CURLOPT_RETURNTRANSFER => 1,
|
42 |
+
CURLOPT_URL => vsprintf($host.$api,$args)
|
43 |
+
));
|
44 |
+
$out = curl_exec($curl);
|
45 |
+
curl_close($curl);
|
46 |
+
return $out;
|
47 |
+
}
|
48 |
+
return "";
|
49 |
+
}
|
50 |
+
|
51 |
+
public function sendData($api, $postfields)
|
52 |
+
{
|
53 |
+
$token = Mage::getStoreConfig('iconnectsync/general/iconnect_api_token');
|
54 |
+
$host = Mage::getStoreConfig('iconnectsync/general/iconnect_api_url');
|
55 |
+
|
56 |
+
if( $curl = curl_init()) {
|
57 |
+
curl_setopt_array($curl, array(
|
58 |
+
CURLOPT_HTTPHEADER => array(
|
59 |
+
'Content-Type: application/json',
|
60 |
+
'Content-Length: '.strlen($postfields)),
|
61 |
+
CURLOPT_RETURNTRANSFER => true,
|
62 |
+
CURLOPT_POST => true,
|
63 |
+
CURLOPT_POSTFIELDS => $postfields,
|
64 |
+
CURLOPT_URL => vsprintf($host.$api,$token)
|
65 |
+
));
|
66 |
+
$out = curl_exec($curl);
|
67 |
+
curl_close($curl);
|
68 |
+
return $out;
|
69 |
+
}
|
70 |
+
return "";
|
71 |
+
}
|
72 |
+
public function getFileData($productId)
|
73 |
+
{
|
74 |
+
$token = Mage::getStoreConfig('iconnect/general/iconnect_api_token');
|
75 |
+
$host = Mage::getStoreConfig('iconnect/general/iconnect_api_url');
|
76 |
+
$api = self::ICONNECT_GET_PRODUCT_FILE_IMAGE_API;
|
77 |
+
return @file_get_contents(sprintf($host.$api,$productId,$token));
|
78 |
+
}
|
79 |
+
|
80 |
+
public function NewGuid()
|
81 |
+
{
|
82 |
+
$s = strtoupper(md5(uniqid(rand(),true)));
|
83 |
+
$guidText =
|
84 |
+
substr($s,0,8) . '-' .
|
85 |
+
substr($s,8,4) . '-' .
|
86 |
+
substr($s,12,4). '-' .
|
87 |
+
substr($s,16,4). '-' .
|
88 |
+
substr($s,20);
|
89 |
+
return $guidText;
|
90 |
+
}
|
91 |
+
}
|
app/code/community/InspireSmart/IConnectSync/Model/Cron.php
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Cron functions
|
5 |
+
*
|
6 |
+
* @category InspireSmart
|
7 |
+
* @package InspireSmart_IConnectSync
|
8 |
+
* @author Viacheslav Galanov (vgalanov@inspiresmart.com)
|
9 |
+
*/
|
10 |
+
class InspireSmart_IConnectSync_Model_Cron
|
11 |
+
{
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Sync via cron schedule
|
15 |
+
*
|
16 |
+
* @param object $schedule
|
17 |
+
* @return void
|
18 |
+
*/
|
19 |
+
public static function syncOrders($schedule)
|
20 |
+
{
|
21 |
+
$helper = Mage::helper('iconnectsync');
|
22 |
+
|
23 |
+
if ($helper->isSyncPaused()) {
|
24 |
+
return;
|
25 |
+
}
|
26 |
+
|
27 |
+
$status = $helper->orderSyncStatus();
|
28 |
+
try {
|
29 |
+
|
30 |
+
$queueCollection = Mage::getModel('iconnectsync/que')
|
31 |
+
->getCollection()
|
32 |
+
->join(array('order' => 'sales/order'), 'main_table.entity_id=order.entity_id')
|
33 |
+
//->addFieldToFilter('synced_at', array('null' => true))
|
34 |
+
->addFieldToFilter('order.status', array('eq' => $status));
|
35 |
+
|
36 |
+
InspireSmart_IConnectSync_Model_Que::doSync($queueCollection);
|
37 |
+
|
38 |
+
} catch (Exception $e) {
|
39 |
+
// save any errors.
|
40 |
+
Mage::logException($e);
|
41 |
+
return $e->getMessage();
|
42 |
+
}
|
43 |
+
}
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Clean old records on schedule
|
47 |
+
*
|
48 |
+
* @param object $schedule
|
49 |
+
* @return void
|
50 |
+
*/
|
51 |
+
public static function clean($schedule)
|
52 |
+
{
|
53 |
+
try {
|
54 |
+
$syncModel = Mage::getModel('iconnectsync/que')->getCollection()
|
55 |
+
->addFieldToFilter(
|
56 |
+
'created_at',
|
57 |
+
array('lteq' => $schedule->getExecutedAt())
|
58 |
+
)
|
59 |
+
->addFieldToFilter('synced_at', array('notnull' => true));
|
60 |
+
foreach ($syncModel as $key => $sync) {
|
61 |
+
$sync->delete();
|
62 |
+
}
|
63 |
+
} catch (Exception $e) {
|
64 |
+
// save any errors.
|
65 |
+
Mage::logException($e);
|
66 |
+
return $e->getMessage();
|
67 |
+
}
|
68 |
+
}
|
69 |
+
|
70 |
+
}
|
app/code/community/InspireSmart/IConnectSync/Model/Observer.php
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*
|
4 |
+
* @category InspireSmart
|
5 |
+
* @package InspireSmart_IConnectSync
|
6 |
+
* @author Viacheslav Galanov (vgalanov@inspiresmart.com)
|
7 |
+
*/
|
8 |
+
|
9 |
+
class InspireSmart_IConnectSync_Model_Observer
|
10 |
+
{
|
11 |
+
const ICONNECT_PUT_ORDERS_API = "api/putOrder?token=%s";
|
12 |
+
/**
|
13 |
+
* Event to set temporary order id
|
14 |
+
*
|
15 |
+
* @param Varien_Event_Observer $observer
|
16 |
+
* @return InspireSmart_IConnectSync_Model_Observer
|
17 |
+
*/
|
18 |
+
public function save_temporary_order_id(Varien_Event_Observer $observer)
|
19 |
+
{
|
20 |
+
$helper = Mage::helper('iconnectsync');
|
21 |
+
$order = $observer->getEvent()->getOrder();
|
22 |
+
$order->setTemporaryOrderId($helper->NewGuid());
|
23 |
+
}
|
24 |
+
/**
|
25 |
+
* Event to save order to que
|
26 |
+
*
|
27 |
+
* @param Varien_Event_Observer $observer
|
28 |
+
* @return InspireSmart_IConnectSync_Model_Observer
|
29 |
+
*/
|
30 |
+
public function sales_order_place_after(Varien_Event_Observer $observer)
|
31 |
+
{
|
32 |
+
$order = $observer->getEvent()->getOrder();
|
33 |
+
$location_id = $order->getStore()->getWebsite()->getData('iconnect_location_id');
|
34 |
+
if(!$location_id)
|
35 |
+
return $this;
|
36 |
+
try {
|
37 |
+
$syncModel = Mage::getModel('iconnectsync/que');
|
38 |
+
$data = array(
|
39 |
+
'increment_id'=>$order->getIncrementId(),
|
40 |
+
'entity_id'=> $order->getId(),
|
41 |
+
'created_at'=> now(),
|
42 |
+
);
|
43 |
+
$syncModel->setData($data);
|
44 |
+
$syncModel->save();
|
45 |
+
} catch (Exception $e) {
|
46 |
+
Mage::log("Couldn't place order into sync queue! " . $e->getMessage());
|
47 |
+
}
|
48 |
+
return $this;
|
49 |
+
}
|
50 |
+
|
51 |
+
}
|
app/code/community/InspireSmart/IConnectSync/Model/Product.php
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Product model
|
4 |
+
*
|
5 |
+
* @category InspireSmart
|
6 |
+
* @package InspireSmart_IConnectSync
|
7 |
+
* @author Viacheslav Galanov (vgalanov@inspiresmart.com)
|
8 |
+
*/
|
9 |
+
class InspireSmart_IConnectSync_Model_Product extends Mage_Core_Model_Abstract {
|
10 |
+
|
11 |
+
const ICONNECT_GET_PRODUCTS_API = "api/getProductServicesByCompany/%d?version=%d&token=%s&type=false&sellOnline=true";
|
12 |
+
|
13 |
+
protected function _construct()
|
14 |
+
{
|
15 |
+
$this->_init("iconnectsync/product");
|
16 |
+
}
|
17 |
+
|
18 |
+
static public function runSyncing() {
|
19 |
+
|
20 |
+
$config = new Mage_Core_Model_Config();
|
21 |
+
$version = $newversion = Mage::getStoreConfig('iconnectsync/versions/products');
|
22 |
+
$page = 0;
|
23 |
+
$numberOfPages = 0;
|
24 |
+
$helper = Mage::helper('iconnectsync');
|
25 |
+
|
26 |
+
$attributeSetId = $helper->getDefaultAttributeSetId();
|
27 |
+
|
28 |
+
do
|
29 |
+
{
|
30 |
+
// Get products from iConnect. To resync all products, set product row version to 0 in cms
|
31 |
+
$result = $helper->getData(self::ICONNECT_GET_PRODUCTS_API,$page,$version);
|
32 |
+
$result = json_decode($result);
|
33 |
+
|
34 |
+
if($result)
|
35 |
+
{
|
36 |
+
// Look through the result set and create new products as needed
|
37 |
+
foreach($result->data as $entity)
|
38 |
+
{
|
39 |
+
// There is a dummy 'service' product in iConnect that we don't want with sku 002
|
40 |
+
if($entity->Sku == '000' || $entity->Sku == '001' || $entity->Sku == '002')
|
41 |
+
continue;
|
42 |
+
|
43 |
+
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
|
44 |
+
|
45 |
+
try{
|
46 |
+
self::createProduct($entity,$attributeSetId);
|
47 |
+
}
|
48 |
+
catch(Exception $e){
|
49 |
+
Mage::log($e->getMessage());
|
50 |
+
}
|
51 |
+
}
|
52 |
+
|
53 |
+
$page++;
|
54 |
+
$numberOfPages = $result->pages;
|
55 |
+
|
56 |
+
if($version == $newversion)
|
57 |
+
$newversion = $result->version;
|
58 |
+
}
|
59 |
+
else{
|
60 |
+
// Nebo edit: We've had an issue where no data gets collected from iConnect in the product api call
|
61 |
+
die('No result');
|
62 |
+
}
|
63 |
+
}
|
64 |
+
while($page < $numberOfPages);
|
65 |
+
|
66 |
+
// Saves the 'row version' in Magento to prevent resync.
|
67 |
+
$config->saveConfig('iconnectsync/versions/products',$newversion);
|
68 |
+
|
69 |
+
return true;
|
70 |
+
}
|
71 |
+
|
72 |
+
static private function createProduct($entity,$attributeSetId)
|
73 |
+
{
|
74 |
+
$website = Mage::getModel('core/website')->load($entity->LocationId,'iconnect_location_id');
|
75 |
+
//if we have no such website skip that product
|
76 |
+
if(!$website->getId())
|
77 |
+
return;
|
78 |
+
$store_id = $website->getDefaultStore()->getStoreId();
|
79 |
+
|
80 |
+
$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$entity->Sku);
|
81 |
+
|
82 |
+
// Does this product exist?
|
83 |
+
if(!$product){
|
84 |
+
// Product doesn't exist -- create it
|
85 |
+
$product = Mage::getModel('catalog/product')
|
86 |
+
->setStoreId($store_id)
|
87 |
+
->setWebsiteIds(array($website->getId())) //website ID the product is assigned to, as an array
|
88 |
+
->setAttributeSetId($attributeSetId) //ID of a attribute set named 'default'
|
89 |
+
->setTypeId('simple') //product type
|
90 |
+
->setCreatedAt(strtotime('now')) //product creation time
|
91 |
+
->setStatus(1) //product status (1 - enabled, 2 - disabled)
|
92 |
+
->setTaxClassId(0) //tax class (0 - none, 1 - default, 2 - taxable, 4 - shipping)
|
93 |
+
->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH) //catalog and search visibility
|
94 |
+
->setWeight(1.0000)
|
95 |
+
->setSku($entity->Sku)
|
96 |
+
->setName(ucwords(strtolower($entity->Name)))
|
97 |
+
->setPrice($entity->Price)
|
98 |
+
->setCost($entity->Cost)
|
99 |
+
->setStockData(array('use_config_manage_stock' => 1)) //'Use config settings' checkbox
|
100 |
+
->setData('iconnect_product_id',$entity->Id);
|
101 |
+
|
102 |
+
}
|
103 |
+
else
|
104 |
+
{
|
105 |
+
$website_ids = $product->getWebsiteIds();
|
106 |
+
if (!in_array($website->getId(),$website_ids))
|
107 |
+
array_push($website_ids,$website->getId());
|
108 |
+
|
109 |
+
$product->setWebsiteIds($website_ids);
|
110 |
+
//set iconnect product id
|
111 |
+
$product->setWebsiteIdId($website->getId());
|
112 |
+
$product->setStoreId($store_id);
|
113 |
+
$product->setData('iconnect_product_id',$entity->Id);
|
114 |
+
}
|
115 |
+
|
116 |
+
$product->setIsMassupdate(true)->setExcludeUrlRewrite(true);
|
117 |
+
$product->save();
|
118 |
+
|
119 |
+
return $product;
|
120 |
+
}
|
121 |
+
}
|
app/code/community/InspireSmart/IConnectSync/Model/Que.php
ADDED
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Queue model
|
4 |
+
*
|
5 |
+
* @category InspireSmart
|
6 |
+
* @package InspireSmart_IConnectSync
|
7 |
+
* @author Viacheslav Galanov (vgalanov@inspiresmart.com)
|
8 |
+
*/
|
9 |
+
class InspireSmart_IConnectSync_Model_Que extends Mage_Core_Model_Abstract
|
10 |
+
{
|
11 |
+
const ICONNECT_PUT_ORDERS_API = "api/putOrder?token=%s";
|
12 |
+
|
13 |
+
protected function _construct()
|
14 |
+
{
|
15 |
+
$this->_init("iconnectsync/que");
|
16 |
+
}
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Handle sync of data
|
20 |
+
*
|
21 |
+
* @param InspireSmart_IConnectSync_Model_Resource_Que_Collection $syncModel
|
22 |
+
*/
|
23 |
+
|
24 |
+
static public function doSync(InspireSmart_IConnectSync_Model_Resource_Que_Collection $syncModel)
|
25 |
+
{
|
26 |
+
$helper = Mage::helper('iconnectsync');
|
27 |
+
|
28 |
+
if ($helper->isSyncPaused()) {
|
29 |
+
return;
|
30 |
+
}
|
31 |
+
|
32 |
+
foreach ($syncModel as $sync) {
|
33 |
+
$order = Mage::getModel('sales/order')->load($sync->getEntityId());
|
34 |
+
try {
|
35 |
+
|
36 |
+
$fields = self::getOrderArray($order);
|
37 |
+
$results = $helper->sendData(self::ICONNECT_PUT_ORDERS_API,json_encode($fields));
|
38 |
+
|
39 |
+
$failed = array_filter(json_decode($results), function($item)
|
40 |
+
{
|
41 |
+
return !$item->IsSuccess;
|
42 |
+
});
|
43 |
+
|
44 |
+
$success = count($failed) == 0;
|
45 |
+
|
46 |
+
if($success) {
|
47 |
+
$order->addStatusToHistory('synchronized');
|
48 |
+
|
49 |
+
$sync->setSyncedAt(now())
|
50 |
+
->save();
|
51 |
+
}
|
52 |
+
else {
|
53 |
+
foreach($failed as $item){
|
54 |
+
if($item->Message){
|
55 |
+
$order->addStatusHistoryComment(
|
56 |
+
$helper->__($item->Message),
|
57 |
+
'synchronization_error'
|
58 |
+
);
|
59 |
+
}
|
60 |
+
}
|
61 |
+
}
|
62 |
+
} catch (Exception $e) {
|
63 |
+
$order->addStatusHistoryComment(
|
64 |
+
$helper->__('Order failed sync: %s', $e->getMessage()),
|
65 |
+
'synchronization_error'
|
66 |
+
);
|
67 |
+
}
|
68 |
+
$order->save();
|
69 |
+
}
|
70 |
+
}
|
71 |
+
|
72 |
+
static private function getOrderItemsArray($order)
|
73 |
+
{
|
74 |
+
$orderItems = array();
|
75 |
+
foreach($order->getItemsCollection() as $item)
|
76 |
+
{
|
77 |
+
$row=array();
|
78 |
+
$row['ProductID'] = -100001;
|
79 |
+
$row['Name'] = $item->getName();
|
80 |
+
$row['SKU'] = $item->getSku();
|
81 |
+
$row['CategoryName'] = 'Online Product';
|
82 |
+
$row['Price'] = floatval($item->getPrice());
|
83 |
+
$row['Cost'] = floatval($item->getCost());
|
84 |
+
$row['Quantity'] = intval($item->getQtyOrdered());
|
85 |
+
$row['Tax'] = $item->getTaxAmount();
|
86 |
+
$row['Discount'] = floatval($item->getDiscountAmount());
|
87 |
+
$row['AdditionalTaxes'] = array(
|
88 |
+
/*array(
|
89 |
+
'Id' => -100001,
|
90 |
+
'Amount' => $item->getTaxAmount()
|
91 |
+
)*/
|
92 |
+
);
|
93 |
+
|
94 |
+
$orderItems[]=$row;
|
95 |
+
}
|
96 |
+
return $orderItems;
|
97 |
+
}
|
98 |
+
|
99 |
+
static private function getOrderArray($order)
|
100 |
+
{
|
101 |
+
$location_id = $order->getStore()->getWebsite()->getData('iconnect_location_id');
|
102 |
+
$helper = Mage::helper('iconnectsync');
|
103 |
+
|
104 |
+
$orderItems = self::getOrderItemsArray($order);
|
105 |
+
//if shipping is more that 0 than add it as an item
|
106 |
+
if($order->getShippingAmount()>0)
|
107 |
+
{
|
108 |
+
$row=array();
|
109 |
+
|
110 |
+
$row['ProductID'] = -100001;
|
111 |
+
$row['Name'] = 'Shipping';
|
112 |
+
$row['CategoryName'] = 'Online Product';
|
113 |
+
$row['SKU'] = '000';
|
114 |
+
$row['Price'] = floatval($order->getShippingAmount());
|
115 |
+
$row['Quantity'] = 1;
|
116 |
+
$row['AdditionalTaxes'] = array();
|
117 |
+
|
118 |
+
$orderItems[]=$row;
|
119 |
+
}
|
120 |
+
|
121 |
+
$orderCompleteDate;
|
122 |
+
$commentCollection = $order->getStatusHistoryCollection();
|
123 |
+
foreach ($commentCollection as $comment) {
|
124 |
+
if ($comment->getStatus() === $helper->orderSyncStatus()) {
|
125 |
+
$orderCompleteDate = $comment->getCreatedAt();
|
126 |
+
}
|
127 |
+
}
|
128 |
+
|
129 |
+
$orders = array(array(
|
130 |
+
"LocationId" => $location_id,
|
131 |
+
"OrderSourceId" => 4,
|
132 |
+
"TemporaryOrderId" => $order->getTemporaryOrderId(),
|
133 |
+
"CustomerId" => null,//guest customer
|
134 |
+
"SubtotalInclTax" => $order->getSubtotal() + $order->getShippingAmount() + $order->getTaxAmount(),
|
135 |
+
"SubtotalExclTax" => $order->getSubtotal() + $order->getShippingAmount(),
|
136 |
+
"Discount"=> abs($order->getDiscountAmount()),
|
137 |
+
"Taxes" => $order->getTaxAmount(),
|
138 |
+
"Total" => $order->getGrandTotal(),
|
139 |
+
"CurrencyCode" => $order->getOrderCurrencyCode(),
|
140 |
+
"CreatedOn" => str_replace(' ','T', $orderCompleteDate),
|
141 |
+
"SalesPersonID" => -100001, //hardcoded value to map company admin
|
142 |
+
"Version" => "magento-".Mage::getVersion(),
|
143 |
+
"Items"=> $orderItems,
|
144 |
+
"Payments"=> array(
|
145 |
+
array(
|
146 |
+
"PaymentMethodID"=> 4,// outside
|
147 |
+
"PaymentStatusID"=> 10,// paid
|
148 |
+
"PaymentAmount"=> floatval($order->getTotalPaid()),
|
149 |
+
"SalesPersonID"=> -100001, //hardcoded value to map company admin
|
150 |
+
"CreatedOn"=> str_replace(' ','T',$orderCompleteDate)
|
151 |
+
)
|
152 |
+
),
|
153 |
+
"ShippingDetailsData" => array(),
|
154 |
+
"Discounts"=> array(),
|
155 |
+
"Tips"=> array(),
|
156 |
+
"EmployeeCommisions"=> array(),
|
157 |
+
"OrderTaxes"=> array(),
|
158 |
+
"OrderTaskItems"=>array(),
|
159 |
+
"OrderBookings"=> array(),
|
160 |
+
)
|
161 |
+
);
|
162 |
+
return $orders;
|
163 |
+
}
|
164 |
+
}
|
app/code/community/InspireSmart/IConnectSync/Model/Resource/Que.php
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
*
|
5 |
+
*
|
6 |
+
* @category InspireSmart
|
7 |
+
* @package InspireSmart_IConnectSync
|
8 |
+
* @author Viacheslav Galanov (vgalanov@inspiresmart.com)
|
9 |
+
*/
|
10 |
+
|
11 |
+
|
12 |
+
class InspireSmart_IConnectSync_Model_Resource_Que extends Mage_Core_Model_Resource_Db_Abstract
|
13 |
+
{
|
14 |
+
protected function _construct()
|
15 |
+
{
|
16 |
+
$this->_init("iconnectsync/que", "id");
|
17 |
+
}
|
18 |
+
}
|
app/code/community/InspireSmart/IConnectSync/Model/Resource/Que/Collection.php
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Queue collection
|
5 |
+
*
|
6 |
+
* @category InspireSmart
|
7 |
+
* @package InspireSmart_IConnectSync
|
8 |
+
* @author Viacheslav Galanov (vgalanov@inspiresmart.com)
|
9 |
+
*/
|
10 |
+
|
11 |
+
class InspireSmart_IConnectSync_Model_Resource_Que_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
|
12 |
+
{
|
13 |
+
public function _construct()
|
14 |
+
{
|
15 |
+
$this->_init("iconnectsync/que");
|
16 |
+
}
|
17 |
+
}
|
app/code/community/InspireSmart/IConnectSync/controllers/SynchronizeController.php
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class InspireSmart_IConnectSync_SynchronizeController extends Mage_Adminhtml_Controller_Action
|
3 |
+
{
|
4 |
+
public function indexAction ()
|
5 |
+
{
|
6 |
+
$this->loadLayout();
|
7 |
+
try {
|
8 |
+
|
9 |
+
// run product sync
|
10 |
+
InspireSmart_IConnectSync_Model_Cron::syncOrders(123);
|
11 |
+
|
12 |
+
$block = $this->getLayout()
|
13 |
+
->createBlock('core/text', 'example-block')
|
14 |
+
->setText('<h1>Job is done!</h1>');
|
15 |
+
|
16 |
+
$this->_addContent($block);
|
17 |
+
|
18 |
+
} catch (Exception $e) {
|
19 |
+
$errorBlock = $this->getLayout()
|
20 |
+
->createBlock('core/text', 'example-block')
|
21 |
+
->setText($e->getMessage());
|
22 |
+
|
23 |
+
$this->_addContent($errorBlock);
|
24 |
+
}
|
25 |
+
$this->renderLayout();
|
26 |
+
}
|
27 |
+
}
|
28 |
+
?>
|
app/code/community/InspireSmart/IConnectSync/etc/config.xml
ADDED
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" ?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<InspireSmart_IConnectSync>
|
5 |
+
<version>1.2.1.0</version>
|
6 |
+
</InspireSmart_IConnectSync>
|
7 |
+
</modules>
|
8 |
+
<global>
|
9 |
+
<models>
|
10 |
+
<iconnectsync>
|
11 |
+
<class>InspireSmart_IConnectSync_Model</class>
|
12 |
+
<resourceModel>iconnectsync_resource</resourceModel>
|
13 |
+
</iconnectsync>
|
14 |
+
<iconnectsync_resource>
|
15 |
+
<class>InspireSmart_IConnectSync_Model_Resource</class>
|
16 |
+
<entities>
|
17 |
+
<que>
|
18 |
+
<table>iconnectsync_que</table>
|
19 |
+
</que>
|
20 |
+
</entities>
|
21 |
+
</iconnectsync_resource>
|
22 |
+
</models>
|
23 |
+
<blocks>
|
24 |
+
<iconnectsync>
|
25 |
+
<class>InspireSmart_IConnectSync_Block</class>
|
26 |
+
</iconnectsync>
|
27 |
+
</blocks>
|
28 |
+
<helpers>
|
29 |
+
<iconnectsync>
|
30 |
+
<class>InspireSmart_IConnectSync_Helper</class>
|
31 |
+
</iconnectsync>
|
32 |
+
</helpers>
|
33 |
+
<resources>
|
34 |
+
<iconnectsync_setup>
|
35 |
+
<setup>
|
36 |
+
<module>InspireSmart_IConnectSync</module>
|
37 |
+
<class>Mage_Catalog_Model_Resource_Setup</class>
|
38 |
+
</setup>
|
39 |
+
<connection>
|
40 |
+
<use>core_setup</use>
|
41 |
+
</connection>
|
42 |
+
</iconnectsync_setup>
|
43 |
+
<iconnectsync_setup_write>
|
44 |
+
<connection>
|
45 |
+
<use>core_write</use>
|
46 |
+
</connection>
|
47 |
+
</iconnectsync_setup_write>
|
48 |
+
<iconnectsync_setup_read>
|
49 |
+
<connection>
|
50 |
+
<use>core_read</use>
|
51 |
+
</connection>
|
52 |
+
</iconnectsync_setup_read>
|
53 |
+
</resources>
|
54 |
+
<blocks>
|
55 |
+
<adminhtml>
|
56 |
+
<rewrite>
|
57 |
+
<system_store_edit_form>InspireSmart_IConnectSync_Block_Adminhtml_System_Store_Edit_Form</system_store_edit_form>
|
58 |
+
</rewrite>
|
59 |
+
</adminhtml>
|
60 |
+
</blocks>
|
61 |
+
<events>
|
62 |
+
<checkout_type_onepage_save_order>
|
63 |
+
<observers>
|
64 |
+
<iconnectsync_checkout_type_onepage_save_order>
|
65 |
+
<type>singleton</type>
|
66 |
+
<class>iconnectsync/observer</class>
|
67 |
+
<method>save_temporary_order_id</method>
|
68 |
+
</iconnectsync_checkout_type_onepage_save_order>
|
69 |
+
</observers>
|
70 |
+
</checkout_type_onepage_save_order>
|
71 |
+
<sales_order_place_after>
|
72 |
+
<observers>
|
73 |
+
<iconnectsync_sales_order_place_after>
|
74 |
+
<type>singleton</type>
|
75 |
+
<class>iconnectsync/observer</class>
|
76 |
+
<method>sales_order_place_after</method>
|
77 |
+
</iconnectsync_sales_order_place_after>
|
78 |
+
</observers>
|
79 |
+
</sales_order_place_after>
|
80 |
+
</events>
|
81 |
+
</global>
|
82 |
+
<crontab>
|
83 |
+
<jobs>
|
84 |
+
<iconnectsync_syncorders>
|
85 |
+
<schedule>
|
86 |
+
<cron_expr>*/15 * * * *</cron_expr>
|
87 |
+
</schedule>
|
88 |
+
<run>
|
89 |
+
<model>iconnectsync/cron::syncOrders</model>
|
90 |
+
</run>
|
91 |
+
</iconnectsync_syncorders>
|
92 |
+
<iconnectsync_clean>
|
93 |
+
<schedule>
|
94 |
+
<cron_expr>0 0 1 * *</cron_expr>
|
95 |
+
</schedule>
|
96 |
+
<run>
|
97 |
+
<model>iconnectsync/cron::clean</model>
|
98 |
+
</run>
|
99 |
+
</iconnectsync_clean>
|
100 |
+
</jobs>
|
101 |
+
</crontab>
|
102 |
+
<admin>
|
103 |
+
<routers>
|
104 |
+
<adminhtml>
|
105 |
+
<args>
|
106 |
+
<modules>
|
107 |
+
<InspireSmart_IConnectSync after="Mage_Adminhtml">InspireSmart_IConnectSync</InspireSmart_IConnectSync>
|
108 |
+
</modules>
|
109 |
+
</args>
|
110 |
+
</adminhtml>
|
111 |
+
<inspiresmart_iconnectsync>
|
112 |
+
<use>admin</use>
|
113 |
+
<args>
|
114 |
+
<module>InspireSmart_IConnectSync</module>
|
115 |
+
<frontName>iconnect</frontName>
|
116 |
+
</args>
|
117 |
+
</inspiresmart_iconnectsync>
|
118 |
+
</routers>
|
119 |
+
</admin>
|
120 |
+
<default>
|
121 |
+
<iconnectsync>
|
122 |
+
<general>
|
123 |
+
<pause_iconnectsync>1</pause_iconnectsync>
|
124 |
+
</general>
|
125 |
+
</iconnectsync>
|
126 |
+
</default>
|
127 |
+
<frontend>
|
128 |
+
<routers>
|
129 |
+
<iconnectsync>
|
130 |
+
<use>standard</use>
|
131 |
+
<args>
|
132 |
+
<module>InspireSmart_IConnectSync</module>
|
133 |
+
<frontName>IConnectSync</frontName>
|
134 |
+
</args>
|
135 |
+
</iconnectsync>
|
136 |
+
</routers>
|
137 |
+
<routers>
|
138 |
+
<routeurfrontend>
|
139 |
+
<use>standard</use>
|
140 |
+
<args>
|
141 |
+
<module>InspireSmart_IConnectSync</module>
|
142 |
+
<frontName>IConnectSync</frontName>
|
143 |
+
</args>
|
144 |
+
</routeurfrontend>
|
145 |
+
</routers>
|
146 |
+
</frontend>
|
147 |
+
<frontend>
|
148 |
+
<routers>
|
149 |
+
<routeurfrontend>
|
150 |
+
<use>standard</use>
|
151 |
+
<args>
|
152 |
+
<module>InspireSmart_IConnectSync</module>
|
153 |
+
<frontName>IConnectSync</frontName>
|
154 |
+
</args>
|
155 |
+
</routeurfrontend>
|
156 |
+
</routers>
|
157 |
+
</frontend>
|
158 |
+
<adminhtml>
|
159 |
+
<acl>
|
160 |
+
<resources>
|
161 |
+
<all>
|
162 |
+
<title>Allow Everything</title>
|
163 |
+
</all>
|
164 |
+
<admin>
|
165 |
+
<children>
|
166 |
+
<system>
|
167 |
+
<children>
|
168 |
+
<config>
|
169 |
+
<children>
|
170 |
+
<iconnectsync>
|
171 |
+
<title>iConnect Sync Settings</title>
|
172 |
+
</iconnectsync>
|
173 |
+
</children>
|
174 |
+
</config>
|
175 |
+
</children>
|
176 |
+
</system>
|
177 |
+
</children>
|
178 |
+
</admin>
|
179 |
+
</resources>
|
180 |
+
</acl>
|
181 |
+
</adminhtml>
|
182 |
+
</config>
|
app/code/community/InspireSmart/IConnectSync/etc/system.xml
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<config>
|
3 |
+
<tabs>
|
4 |
+
<iconnectsync_tab translate="label" module="iconnectsync">
|
5 |
+
<label>iConnect Sync</label>
|
6 |
+
<sort_order>100</sort_order>
|
7 |
+
</iconnectsync_tab>
|
8 |
+
</tabs>
|
9 |
+
<sections>
|
10 |
+
<iconnectsync translate="label" module="iconnectsync">
|
11 |
+
<label>iConnect Sync Settings</label>
|
12 |
+
<tab>iconnectsync_tab</tab>
|
13 |
+
<sort_order>1000</sort_order>
|
14 |
+
<show_in_default>1</show_in_default>
|
15 |
+
<show_in_website>1</show_in_website>
|
16 |
+
<show_in_store>1</show_in_store>
|
17 |
+
<groups>
|
18 |
+
<general translate="label" module="iconnectsync">
|
19 |
+
<label>iConnect Sync Settings</label>
|
20 |
+
<frontend_type>text</frontend_type>
|
21 |
+
<sort_order>1000</sort_order>
|
22 |
+
<show_in_default>1</show_in_default>
|
23 |
+
<fields>
|
24 |
+
<iconnect_api_url>
|
25 |
+
<label>API url: </label>
|
26 |
+
<comment>The iConnect API url</comment>
|
27 |
+
<frontend_type>text</frontend_type>
|
28 |
+
<sort_order>1</sort_order>
|
29 |
+
<show_in_default>1</show_in_default>
|
30 |
+
</iconnect_api_url>
|
31 |
+
<iconnect_api_token>
|
32 |
+
<label>API Token: </label>
|
33 |
+
<comment>The iConnect API token. You can get it here https://my.iconnectpos.com/GetAPI</comment>
|
34 |
+
<frontend_type>text</frontend_type>
|
35 |
+
<sort_order>2</sort_order>
|
36 |
+
<show_in_default>1</show_in_default>
|
37 |
+
</iconnect_api_token>
|
38 |
+
<pause_sync translate="label">
|
39 |
+
<label>Pause iconnect syncing</label>
|
40 |
+
<frontend_type>select</frontend_type>
|
41 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
42 |
+
<sort_order>3</sort_order>
|
43 |
+
<show_in_default>1</show_in_default>
|
44 |
+
<comment>Products and orders won't be synced until unpaused.</comment>
|
45 |
+
</pause_sync>
|
46 |
+
<sync_order_on_status translate="label">
|
47 |
+
<label>Sync order if state is</label>
|
48 |
+
<frontend_type>select</frontend_type>
|
49 |
+
<source_model>adminhtml/system_config_source_order_status</source_model>
|
50 |
+
<sort_order>4</sort_order>
|
51 |
+
<show_in_default>1</show_in_default>
|
52 |
+
<comment>Orders will be synced once their state will be equals to selected value. </comment>
|
53 |
+
</sync_order_on_status>
|
54 |
+
</fields>
|
55 |
+
</general>
|
56 |
+
</groups>
|
57 |
+
</iconnectsync>
|
58 |
+
</sections>
|
59 |
+
</config>
|
app/code/community/InspireSmart/IConnectSync/sql/iconnectsync_setup/install-1.0.0.php
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
$installer = $this;
|
3 |
+
$installer->startSetup();
|
4 |
+
|
5 |
+
$_setup = new Mage_Eav_Model_Entity_Setup('core_setup');
|
6 |
+
$_config = new Mage_Core_Model_Config();
|
7 |
+
$_config->saveConfig('iconnectsync/general/iconnect_api_url','https://publicapi.iconnectpos.com/');
|
8 |
+
$_config->saveConfig('iconnectsync/general/iconnect_api_token','');
|
9 |
+
$_config->saveConfig('iconnectsync/general/pause_sync','1');
|
10 |
+
$_config->saveConfig('iconnectsync/general/sync_order_on_status','complete');
|
11 |
+
//row versions
|
12 |
+
$_config->saveConfig('iconnectsync/versions/products','0');
|
13 |
+
|
14 |
+
//create product attribute to store iconnect product id
|
15 |
+
$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'iconnect_product_id', array(
|
16 |
+
'type' => 'int',
|
17 |
+
'label' => 'iConnect Product Id',
|
18 |
+
'input' => 'text',
|
19 |
+
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE,
|
20 |
+
'visible' => false,
|
21 |
+
'required' => false
|
22 |
+
));
|
23 |
+
//add column to order table to map iconnect orders and magento orders
|
24 |
+
$installer->getConnection()->addColumn($installer->getTable('sales/order'), 'temporary_order_id',
|
25 |
+
array('type' => Varien_Db_Ddl_Table::TYPE_TEXT,
|
26 |
+
'nullable' => true,
|
27 |
+
'length' => 36,
|
28 |
+
'comment' => 'Temporary Order Id',
|
29 |
+
'default' => null
|
30 |
+
));
|
31 |
+
|
32 |
+
//add columns to website entity
|
33 |
+
$webSiteTableName = $installer->getTable('core/website');
|
34 |
+
|
35 |
+
$installer->getConnection()->addColumn($webSiteTableName,'iconnect_location_id',
|
36 |
+
array('type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
|
37 |
+
'nullable' => true,
|
38 |
+
'comment' => 'iConnect Location Id',
|
39 |
+
'default' => null
|
40 |
+
));
|
41 |
+
$installer->getConnection()->addColumn($webSiteTableName,'synchronize_location',
|
42 |
+
array('type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
|
43 |
+
'nullable' => false,
|
44 |
+
'comment' => 'Synchronize Location',
|
45 |
+
'default' => 0
|
46 |
+
));
|
47 |
+
|
48 |
+
$table = $installer->getConnection()
|
49 |
+
->newTable($installer->getTable('iconnectsync_que'))
|
50 |
+
->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
|
51 |
+
'identity' => true,
|
52 |
+
'unsigned' => true,
|
53 |
+
'nullable' => false,
|
54 |
+
'primary' => true,
|
55 |
+
), 'Id')
|
56 |
+
->addColumn('increment_id', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array(
|
57 |
+
'nullable' => true,
|
58 |
+
), 'Order Increment Id')
|
59 |
+
->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
|
60 |
+
'unsigned' => true,
|
61 |
+
'nullable' => true,
|
62 |
+
), 'Magento Order Id')
|
63 |
+
->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_DATETIME, null, array(
|
64 |
+
'unsigned' => true,
|
65 |
+
'nullable' => true,
|
66 |
+
), 'Created')
|
67 |
+
->addColumn('synced_at', Varien_Db_Ddl_Table::TYPE_DATETIME, null, array(
|
68 |
+
'unsigned' => true,
|
69 |
+
'nullable' => true,
|
70 |
+
), 'Synced');
|
71 |
+
|
72 |
+
|
73 |
+
$installer->getConnection()->createTable($table);
|
74 |
+
|
75 |
+
$statusTable = $installer->getTable('sales/order_status');
|
76 |
+
$statusStateTable = $installer->getTable('sales/order_status_state');
|
77 |
+
|
78 |
+
// Insert statuses
|
79 |
+
$installer->getConnection()->insertArray(
|
80 |
+
$statusTable,
|
81 |
+
array(
|
82 |
+
'status',
|
83 |
+
'label'
|
84 |
+
),
|
85 |
+
array(
|
86 |
+
array('status' => 'synchronized', 'label' => 'Synchronized'),
|
87 |
+
array('status' => 'synchronization_error', 'label' => 'Sync Error')
|
88 |
+
)
|
89 |
+
);
|
90 |
+
|
91 |
+
// Insert states and mapping of statuses to states
|
92 |
+
$installer->getConnection()->insertArray(
|
93 |
+
$statusStateTable,
|
94 |
+
array(
|
95 |
+
'status',
|
96 |
+
'state',
|
97 |
+
'is_default'
|
98 |
+
),
|
99 |
+
array(
|
100 |
+
array(
|
101 |
+
'status' => 'synchronized',
|
102 |
+
'state' => 'complete',
|
103 |
+
'is_default' => 0
|
104 |
+
),
|
105 |
+
array(
|
106 |
+
'status' => 'synchronization_error',
|
107 |
+
'state' => 'complete',
|
108 |
+
'is_default' => 0
|
109 |
+
)
|
110 |
+
)
|
111 |
+
);
|
112 |
+
$installer->endSetup();
|
113 |
+
?>
|
app/etc/modules/InspireSmart_IConnectSync.xml
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" ?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<InspireSmart_IConnectSync>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>community</codePool>
|
7 |
+
<depends>
|
8 |
+
<Mage_Core/>
|
9 |
+
</depends>
|
10 |
+
</InspireSmart_IConnectSync>
|
11 |
+
</modules>
|
12 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>InspireSmart_IConnectSync</name>
|
4 |
+
<version>1.2.1.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license>Open Software License (OSL)</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>iConnect POS Sync allow you to synchronize orders from Magento into the iConnect POS.</summary>
|
10 |
+
<description>iConnect POS is the best iPad, Web POS system for businesses that want their technology to grow with them. Run your entire business from one POS app.</description>
|
11 |
+
<notes>- sync orders from Magento to iConnect POS</notes>
|
12 |
+
<authors><author><name>InspireSmart inc.</name><user>slgal</user><email>vgalanov@iconnectpos.com</email></author></authors>
|
13 |
+
<date>2016-07-14</date>
|
14 |
+
<time>16:00:26</time>
|
15 |
+
<contents><target name="magecommunity"><dir name="InspireSmart"><dir name="IConnectSync"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Store"><dir name="Edit"><file name="Form.php" hash="83332b3bf4dbb23efb80eda0716aa206"/></dir></dir></dir></dir><file name="Button.php" hash="7aa446cd878165554b4896ca5c38975f"/></dir><dir name="Helper"><file name="Data.php" hash="326acc4a62e1bb5cb5c8bbcd56e97978"/></dir><dir name="Model"><file name="Cron.php" hash="3b998f2cc4cd7332e5c936f8d46a11cd"/><file name="Observer.php" hash="cedc07515842a6c63d9903d998355ab6"/><file name="Product.php" hash="0b463ef8531a06a373c2876924f7e6ac"/><file name="Que.php" hash="28399dfb9e92ab719cc4bd11637fb58f"/><dir name="Resource"><dir name="Que"><file name="Collection.php" hash="03aecc7e49e8644ed3f475592539fe17"/></dir><file name="Que.php" hash="b534c0a231bff7b7816f2613ce2b9035"/></dir></dir><dir name="controllers"><file name="SynchronizeController.php" hash="264daa0657a98a87494c6037d6766fb6"/></dir><dir name="etc"><file name="config.xml" hash="50440b2d46cd0135afaef015808473fb"/><file name="system.xml" hash="4cf660c765ffd546dc8c51753a47031b"/></dir><dir name="sql"><dir name="iconnectsync_setup"><file name="install-1.0.0.php" hash="f9df92dc5fab3344bac436ad8318df4b"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="InspireSmart_IConnectSync.xml" hash="d34fce59f1d78e3612052cfb785c59cd"/></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies><required><php><min>5.4.0</min><max>7.1.0</max></php></required></dependencies>
|
18 |
+
</package>
|