Saleswarp_Oms - Version 0.1.3

Version Notes

Production version

Download this release

Release Info

Developer David Potts
Extension Saleswarp_Oms
Version 0.1.3
Comparing to
See all releases


Code changes from version 0.1.2 to 0.1.3

Files changed (36) hide show
  1. app/code/local/Saleswarp/Oms/Block/Adminhtml/System/Config/Form/Button.php +79 -79
  2. app/code/local/Saleswarp/Oms/Block/Adminhtml/System/Config/Form/Key.php +27 -27
  3. app/code/local/Saleswarp/Oms/Block/Form/Saleswarp.php +21 -21
  4. app/code/local/Saleswarp/Oms/Block/Info/Saleswarp.php +29 -29
  5. app/code/local/Saleswarp/Oms/Helper/Data.php +3 -3
  6. app/code/local/Saleswarp/Oms/Model/Category/Api.php +16 -16
  7. app/code/local/Saleswarp/Oms/Model/Config/Api.php +53 -53
  8. app/code/local/Saleswarp/Oms/Model/Customer/Api.php +34 -34
  9. app/code/local/Saleswarp/Oms/Model/Order/Api.php +580 -563
  10. app/code/local/Saleswarp/Oms/Model/Product/Api.php +362 -355
  11. app/code/local/Saleswarp/Oms/Model/Product/Attribute/Api.php +5 -5
  12. app/code/local/Saleswarp/Oms/Model/Product/Attribute/Media/Api.php +4 -4
  13. app/code/local/Saleswarp/Oms/Model/Saleswarp.php +53 -53
  14. app/code/local/Saleswarp/Oms/controllers/Adminhtml/GetkeyController.php +63 -63
  15. app/code/local/Saleswarp/Oms/controllers/FastapiController.php +136 -136
  16. app/code/local/Saleswarp/Oms/etc/adminhtml.xml +22 -22
  17. app/code/local/Saleswarp/Oms/etc/config.xml +92 -92
  18. app/code/local/Saleswarp/Oms/etc/system.xml +96 -96
  19. app/code/local/Saleswarp/Oms/sql/oms_setup/mysql4-install-0.1.1.php +265 -265
  20. app/code/local/Saleswarp/Oms/sql/oms_setup/mysql4-upgrade-0.1.2.php +28 -28
  21. app/code/local/Saleswarp/Publish/Helper/Data.php +5 -0
  22. app/code/local/Saleswarp/Publish/Model/Category/Api.php +326 -0
  23. app/code/local/Saleswarp/Publish/Model/Config/Api.php +83 -0
  24. app/code/local/Saleswarp/Publish/Model/Customer/Api.php +26 -0
  25. app/code/local/Saleswarp/Publish/Model/Product/Api.php +2191 -0
  26. app/code/local/Saleswarp/Publish/Model/Product/Attribute/Api.php +38 -0
  27. app/code/local/Saleswarp/Publish/Model/Product/Attribute/Media/Api.php +153 -0
  28. app/code/local/Saleswarp/Publish/etc/config.xml +30 -0
  29. app/code/local/Saleswarp/WhitelistIP/Helper/Data.php +5 -0
  30. app/code/local/Saleswarp/WhitelistIP/controllers/FastapiController.php +36 -0
  31. app/code/local/Saleswarp/WhitelistIP/etc/config.xml +19 -0
  32. app/code/local/Saleswarp/WhitelistIP/etc/system.xml +37 -0
  33. app/design/adminhtml/default/default/template/oms/form/saleswarp.phtml +16 -16
  34. app/design/adminhtml/default/default/template/oms/system/config/button.phtml +35 -35
  35. app/etc/modules/Saleswarp_Oms.xml +9 -9
  36. package.xml +5 -5
app/code/local/Saleswarp/Oms/Block/Adminhtml/System/Config/Form/Button.php CHANGED
@@ -1,80 +1,80 @@
1
- <?php
2
- /**
3
- * This module connects Magento to the SalesWarp Advanced Order Management System.
4
- *
5
- * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
- * @version 0.1.2
7
- * @author David Potts
8
- * @license http://www.saleswarp.com/license-saas
9
- * @category SalesWarp
10
- * @since File available since Release 0.1.2
11
- * @link https://www.SalesWarp.com
12
- *
13
- */
14
-
15
- class Saleswarp_Oms_Block_Adminhtml_System_Config_Form_Button extends Mage_Adminhtml_Block_System_Config_Form_Field
16
- {
17
- /*
18
- * Set template
19
- */
20
- protected function _construct()
21
- {
22
- parent::_construct();
23
- $this->setTemplate('oms/system/config/button.phtml');
24
- }
25
-
26
- /**
27
- * Return element html
28
- *
29
- * @param Varien_Data_Form_Element_Abstract $element
30
- * @return string
31
- */
32
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
33
- {
34
- return $this->_toHtml();
35
- }
36
-
37
- /**
38
- * Return ajax url for button
39
- *
40
- * @return string
41
- */
42
- public function getAjaxCheckUrl()
43
- {
44
- return Mage::helper('adminhtml')->getUrl('admin_oms/adminhtml_getkey');
45
- }
46
-
47
- /**
48
- * Generate button html
49
- *
50
- * @return string
51
- */
52
- public function getButtonHtml()
53
- {
54
- $button = $this->getLayout()->createBlock('adminhtml/widget_button')
55
- ->setData(array(
56
- 'id' => 'saleswarp_oms_button',
57
- 'label' => $this->helper('adminhtml')->__('Get Key'),
58
- 'onclick' => 'javascript:getKey(); return false;'
59
- ));
60
- return $button->toHtml();
61
- }
62
-
63
- public function isKeyAvailable() {
64
- $key = Mage::getStoreConfig('oms/registration/key');
65
- if($key && trim($key)) {
66
- return true;
67
- } else {
68
- return false;
69
- }
70
- }
71
-
72
- public function getKeyData() {
73
- $data = array();
74
- $data['key'] = Mage::getStoreConfig('oms/registration/key');
75
- $coreVariable = Mage::getModel('core/variable');
76
- $data['create_url'] = $coreVariable->loadByCode('saleswarp_create_url')->getValue('plain');
77
- $data['login_url'] = $coreVariable->loadByCode('saleswarp_login_url')->getValue('plain');
78
- return $data;
79
- }
80
  }
1
+ <?php
2
+ /**
3
+ * This module connects Magento to the SalesWarp Advanced Order Management System.
4
+ *
5
+ * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
+ * @version 0.1.2
7
+ * @author David Potts
8
+ * @license http://www.saleswarp.com/license-saas
9
+ * @category SalesWarp
10
+ * @since File available since Release 0.1.2
11
+ * @link https://www.SalesWarp.com
12
+ *
13
+ */
14
+
15
+ class Saleswarp_Oms_Block_Adminhtml_System_Config_Form_Button extends Mage_Adminhtml_Block_System_Config_Form_Field
16
+ {
17
+ /*
18
+ * Set template
19
+ */
20
+ protected function _construct()
21
+ {
22
+ parent::_construct();
23
+ $this->setTemplate('oms/system/config/button.phtml');
24
+ }
25
+
26
+ /**
27
+ * Return element html
28
+ *
29
+ * @param Varien_Data_Form_Element_Abstract $element
30
+ * @return string
31
+ */
32
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
33
+ {
34
+ return $this->_toHtml();
35
+ }
36
+
37
+ /**
38
+ * Return ajax url for button
39
+ *
40
+ * @return string
41
+ */
42
+ public function getAjaxCheckUrl()
43
+ {
44
+ return Mage::helper('adminhtml')->getUrl('admin_oms/adminhtml_getkey');
45
+ }
46
+
47
+ /**
48
+ * Generate button html
49
+ *
50
+ * @return string
51
+ */
52
+ public function getButtonHtml()
53
+ {
54
+ $button = $this->getLayout()->createBlock('adminhtml/widget_button')
55
+ ->setData(array(
56
+ 'id' => 'saleswarp_oms_button',
57
+ 'label' => $this->helper('adminhtml')->__('Get Key'),
58
+ 'onclick' => 'javascript:getKey(); return false;'
59
+ ));
60
+ return $button->toHtml();
61
+ }
62
+
63
+ public function isKeyAvailable() {
64
+ $key = Mage::getStoreConfig('oms/registration/key');
65
+ if($key && trim($key)) {
66
+ return true;
67
+ } else {
68
+ return false;
69
+ }
70
+ }
71
+
72
+ public function getKeyData() {
73
+ $data = array();
74
+ $data['key'] = Mage::getStoreConfig('oms/registration/key');
75
+ $coreVariable = Mage::getModel('core/variable');
76
+ $data['create_url'] = $coreVariable->loadByCode('saleswarp_create_url')->getValue('plain');
77
+ $data['login_url'] = $coreVariable->loadByCode('saleswarp_login_url')->getValue('plain');
78
+ return $data;
79
+ }
80
  }
app/code/local/Saleswarp/Oms/Block/Adminhtml/System/Config/Form/Key.php CHANGED
@@ -1,28 +1,28 @@
1
- <?php
2
- /**
3
- * This module connects Magento to the SalesWarp Advanced Order Management System.
4
- *
5
- * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
- * @version 0.1.2
7
- * @author David Potts
8
- * @license http://www.saleswarp.com/license-saas
9
- * @category SalesWarp
10
- * @since File available since Release 0.1.2
11
- * @link https://www.SalesWarp.com
12
- *
13
- */
14
-
15
- class Saleswarp_Oms_Block_Adminhtml_System_Config_Form_Key extends Mage_Adminhtml_Block_System_Config_Form_Field
16
- {
17
- /**
18
- * Return element html
19
- *
20
- * @param Varien_Data_Form_Element_Abstract $element
21
- * @return string
22
- */
23
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
24
- {
25
- $element->setDisabled('disabled');
26
- return parent::_getElementHtml($element);
27
- }
28
  }
1
+ <?php
2
+ /**
3
+ * This module connects Magento to the SalesWarp Advanced Order Management System.
4
+ *
5
+ * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
+ * @version 0.1.2
7
+ * @author David Potts
8
+ * @license http://www.saleswarp.com/license-saas
9
+ * @category SalesWarp
10
+ * @since File available since Release 0.1.2
11
+ * @link https://www.SalesWarp.com
12
+ *
13
+ */
14
+
15
+ class Saleswarp_Oms_Block_Adminhtml_System_Config_Form_Key extends Mage_Adminhtml_Block_System_Config_Form_Field
16
+ {
17
+ /**
18
+ * Return element html
19
+ *
20
+ * @param Varien_Data_Form_Element_Abstract $element
21
+ * @return string
22
+ */
23
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
24
+ {
25
+ $element->setDisabled('disabled');
26
+ return parent::_getElementHtml($element);
27
+ }
28
  }
app/code/local/Saleswarp/Oms/Block/Form/Saleswarp.php CHANGED
@@ -1,22 +1,22 @@
1
- <?php
2
- /**
3
- * This module connects Magento to the SalesWarp Advanced Order Management System.
4
- *
5
- * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
- * @version 0.1.2
7
- * @author David Potts
8
- * @license http://www.saleswarp.com/license-saas
9
- * @category SalesWarp
10
- * @since File available since Release 0.1.2
11
- * @link https://www.SalesWarp.com
12
- *
13
- */
14
-
15
- class Saleswarp_Oms_Block_Form_Saleswarp extends Mage_Payment_Block_Form
16
- {
17
- protected function _construct()
18
- {
19
- parent::_construct();
20
- $this->setTemplate('oms/form/saleswarp.phtml');
21
- }
22
  }
1
+ <?php
2
+ /**
3
+ * This module connects Magento to the SalesWarp Advanced Order Management System.
4
+ *
5
+ * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
+ * @version 0.1.2
7
+ * @author David Potts
8
+ * @license http://www.saleswarp.com/license-saas
9
+ * @category SalesWarp
10
+ * @since File available since Release 0.1.2
11
+ * @link https://www.SalesWarp.com
12
+ *
13
+ */
14
+
15
+ class Saleswarp_Oms_Block_Form_Saleswarp extends Mage_Payment_Block_Form
16
+ {
17
+ protected function _construct()
18
+ {
19
+ parent::_construct();
20
+ $this->setTemplate('oms/form/saleswarp.phtml');
21
+ }
22
  }
app/code/local/Saleswarp/Oms/Block/Info/Saleswarp.php CHANGED
@@ -1,30 +1,30 @@
1
- <?php
2
- /**
3
- * This module connects Magento to the SalesWarp Advanced Order Management System.
4
- *
5
- * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
- * @version 0.1.2
7
- * @author David Potts
8
- * @license http://www.saleswarp.com/license-saas
9
- * @category SalesWarp
10
- * @since File available since Release 0.1.2
11
- * @link https://www.SalesWarp.com
12
- *
13
- */
14
- class Saleswarp_Oms_Block_Info_Saleswarp extends Mage_Payment_Block_Info
15
- {
16
- protected function _prepareSpecificInformation($transport = null)
17
- {
18
- if (null !== $this->_paymentSpecificInformation) {
19
- return $this->_paymentSpecificInformation;
20
- }
21
- $info = $this->getInfo();
22
- $transport = new Varien_Object();
23
- $transport = parent::_prepareSpecificInformation($transport);
24
- $transport->addData(array(
25
- Mage::helper('payment')->__('Transaction No#') => $info->getTransctionNo(),
26
- Mage::helper('payment')->__('Payment Method') => $info->getPaymentMethod()
27
- ));
28
- return $transport;
29
- }
30
  }
1
+ <?php
2
+ /**
3
+ * This module connects Magento to the SalesWarp Advanced Order Management System.
4
+ *
5
+ * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
+ * @version 0.1.2
7
+ * @author David Potts
8
+ * @license http://www.saleswarp.com/license-saas
9
+ * @category SalesWarp
10
+ * @since File available since Release 0.1.2
11
+ * @link https://www.SalesWarp.com
12
+ *
13
+ */
14
+ class Saleswarp_Oms_Block_Info_Saleswarp extends Mage_Payment_Block_Info
15
+ {
16
+ protected function _prepareSpecificInformation($transport = null)
17
+ {
18
+ if (null !== $this->_paymentSpecificInformation) {
19
+ return $this->_paymentSpecificInformation;
20
+ }
21
+ $info = $this->getInfo();
22
+ $transport = new Varien_Object();
23
+ $transport = parent::_prepareSpecificInformation($transport);
24
+ $transport->addData(array(
25
+ Mage::helper('payment')->__('Transaction No#') => $info->getTransctionNo(),
26
+ Mage::helper('payment')->__('Payment Method') => $info->getPaymentMethod()
27
+ ));
28
+ return $transport;
29
+ }
30
  }
app/code/local/Saleswarp/Oms/Helper/Data.php CHANGED
@@ -1,4 +1,4 @@
1
- <?php
2
- class Saleswarp_Oms_Helper_Data extends Mage_Core_Helper_Abstract
3
- {
4
  }
1
+ <?php
2
+ class Saleswarp_Oms_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
  }
app/code/local/Saleswarp/Oms/Model/Category/Api.php CHANGED
@@ -1,17 +1,17 @@
1
- <?php
2
- /**
3
- * This module connects Magento to the SalesWarp Advanced Order Management System.
4
- *
5
- * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
- * @version 0.1.2
7
- * @author David Potts
8
- * @license http://www.saleswarp.com/license-saas
9
- * @category SalesWarp
10
- * @since File available since Release 0.1.2
11
- * @link https://www.SalesWarp.com
12
- *
13
- */
14
- class Saleswarp_Oms_Model_Category_Api extends Mage_Catalog_Model_Category_Api {
15
-
16
- }
17
  ?>
1
+ <?php
2
+ /**
3
+ * This module connects Magento to the SalesWarp Advanced Order Management System.
4
+ *
5
+ * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
+ * @version 0.1.2
7
+ * @author David Potts
8
+ * @license http://www.saleswarp.com/license-saas
9
+ * @category SalesWarp
10
+ * @since File available since Release 0.1.2
11
+ * @link https://www.SalesWarp.com
12
+ *
13
+ */
14
+ class Saleswarp_Oms_Model_Category_Api extends Mage_Catalog_Model_Category_Api {
15
+
16
+ }
17
  ?>
app/code/local/Saleswarp/Oms/Model/Config/Api.php CHANGED
@@ -1,53 +1,53 @@
1
- <?php
2
- /**
3
- * This module connects Magento to the SalesWarp Advanced Order Management System.
4
- *
5
- * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
- * @version 0.1.2
7
- * @author David Potts
8
- * @license http://www.saleswarp.com/license-saas
9
- * @category SalesWarp
10
- * @since File available since Release 0.1.2
11
- * @link https://www.SalesWarp.com
12
- *
13
- */
14
- /**
15
- * Use this API to get/set key config data for the storefronts
16
- */
17
- class Saleswarp_Oms_Model_Config_Api
18
- {
19
- /**
20
- * get Attribute id by attribute name
21
- * @params attribute name
22
- * @return attribute id
23
- */
24
- public function getProductAttributesId($attribute_code)
25
- {
26
- $resource = Mage::getSingleton('core/resource');
27
- $entity_type_id = Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId();
28
-
29
- $sql = "SELECT attribute_id from " . $resource->getTableName('eav_attribute') . "
30
- WHERE entity_type_id = :entityTypeId
31
- AND attribute_code = :attributeCode ";
32
-
33
- $binds = array(
34
- 'entityTypeId' => $entity_type_id,
35
- 'attributeCode' => $attribute_code
36
- );
37
- $att = $resource->getConnection('core_read')->fetchAll($sql, $binds);
38
- return $att;
39
- }
40
-
41
- /**
42
- * get website and store Id
43
- */
44
- public function getStoreIds()
45
- {
46
- $resource = Mage::getSingleton('core/resource');
47
- $sql = "SELECT str.*, web.* from " . $resource->getTableName('core_store') . " as str
48
- JOIN " . $resource->getTableName('core_website') . " as web ON str.website_id = web.website_id ";
49
- $stores = $resource->getConnection('core_read')->fetchAll($sql);
50
- return $stores;
51
- }
52
- }
53
- ?>
1
+ <?php
2
+ /**
3
+ * This module connects Magento to the SalesWarp Advanced Order Management System.
4
+ *
5
+ * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
+ * @version 0.1.2
7
+ * @author David Potts
8
+ * @license http://www.saleswarp.com/license-saas
9
+ * @category SalesWarp
10
+ * @since File available since Release 0.1.2
11
+ * @link https://www.SalesWarp.com
12
+ *
13
+ */
14
+ /**
15
+ * Use this API to get/set key config data for the storefronts
16
+ */
17
+ class Saleswarp_Oms_Model_Config_Api
18
+ {
19
+ /**
20
+ * get Attribute id by attribute name
21
+ * @params attribute name
22
+ * @return attribute id
23
+ */
24
+ public function getProductAttributesId($attribute_code)
25
+ {
26
+ $resource = Mage::getSingleton('core/resource');
27
+ $entity_type_id = Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId();
28
+
29
+ $sql = "SELECT attribute_id from " . $resource->getTableName('eav_attribute') . "
30
+ WHERE entity_type_id = :entityTypeId
31
+ AND attribute_code = :attributeCode ";
32
+
33
+ $binds = array(
34
+ 'entityTypeId' => $entity_type_id,
35
+ 'attributeCode' => $attribute_code
36
+ );
37
+ $att = $resource->getConnection('core_read')->fetchAll($sql, $binds);
38
+ return $att;
39
+ }
40
+
41
+ /**
42
+ * get website and store Id
43
+ */
44
+ public function getStoreIds()
45
+ {
46
+ $resource = Mage::getSingleton('core/resource');
47
+ $sql = "SELECT str.*, web.* from " . $resource->getTableName('core_store') . " as str
48
+ JOIN " . $resource->getTableName('core_website') . " as web ON str.website_id = web.website_id ";
49
+ $stores = $resource->getConnection('core_read')->fetchAll($sql);
50
+ return $stores;
51
+ }
52
+ }
53
+ ?>
app/code/local/Saleswarp/Oms/Model/Customer/Api.php CHANGED
@@ -1,35 +1,35 @@
1
- <?php
2
- /**
3
- * This module connects Magento to the SalesWarp Advanced Order Management System.
4
- *
5
- * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
- * @version 0.1.2
7
- * @author David Potts
8
- * @license http://www.saleswarp.com/license-saas
9
- * @category SalesWarp
10
- * @since File available since Release 0.1.2
11
- * @link https://www.SalesWarp.com
12
- *
13
- */
14
-
15
- /**
16
- * Use this API to get/set key config data for the storefronts
17
- */
18
- class Saleswarp_Oms_Model_Customer_Api extends Mage_Customer_Model_Customer_Api
19
- {
20
- /**
21
- * Get Customer Group name
22
- * @params group id
23
- * @return Group name
24
- */
25
- function get_customer_group_name_by_id($groupId)
26
- {
27
- $group = Mage::getModel('customer/group')->load($groupId);
28
- if ($group->getId()) {
29
- return $group->getCode();
30
- } else {
31
- return "Guest";
32
- }
33
- }
34
- }
35
  ?>
1
+ <?php
2
+ /**
3
+ * This module connects Magento to the SalesWarp Advanced Order Management System.
4
+ *
5
+ * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
+ * @version 0.1.2
7
+ * @author David Potts
8
+ * @license http://www.saleswarp.com/license-saas
9
+ * @category SalesWarp
10
+ * @since File available since Release 0.1.2
11
+ * @link https://www.SalesWarp.com
12
+ *
13
+ */
14
+
15
+ /**
16
+ * Use this API to get/set key config data for the storefronts
17
+ */
18
+ class Saleswarp_Oms_Model_Customer_Api extends Mage_Customer_Model_Customer_Api
19
+ {
20
+ /**
21
+ * Get Customer Group name
22
+ * @params group id
23
+ * @return Group name
24
+ */
25
+ function get_customer_group_name_by_id($groupId)
26
+ {
27
+ $group = Mage::getModel('customer/group')->load($groupId);
28
+ if ($group->getId()) {
29
+ return $group->getCode();
30
+ } else {
31
+ return "Guest";
32
+ }
33
+ }
34
+ }
35
  ?>
app/code/local/Saleswarp/Oms/Model/Order/Api.php CHANGED
@@ -1,563 +1,580 @@
1
- <?php
2
- /**
3
- * This module connects Magento to the SalesWarp Advanced Order Management System.
4
- *
5
- * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
- * @version 0.1.2
7
- * @author David Potts
8
- * @license http://www.saleswarp.com/license-saas
9
- * @category SalesWarp
10
- * @since File available since Release 0.1.2
11
- * @link https://www.SalesWarp.com
12
- *
13
- */
14
- class Saleswarp_Oms_Model_Order_Api extends Mage_Sales_Model_Order_Api
15
- {
16
- const STATE_RETURN_REQUESTED = 'return_requested';
17
- const STATE_EXCHANGE = 'exchange';
18
- const STATE_ADVANCED_EXCHANGE = 'advanced_exchange';
19
- const STATE_RETURN_RECEIVED = 'return_received';
20
-
21
- /**
22
- * return a recent order list
23
- * if any parameter is set to zero then that will not be considered for order pull.
24
- */
25
-
26
- public function get_recent_order_list($limit = 0, $lastdays = 5, $offset = 0)
27
- {
28
- $daysOldQuery = '';
29
-
30
- // return a list of orders in the last X days
31
- if ($lastdays != 0) {
32
- $daysOldQuery = " WHERE created_at > '" . strftime('%Y-%m-%d %H:%M:%S', (time() - (24 * 60 * 60 * $lastdays))) . "'";
33
- }
34
-
35
- $limitQuery = '';
36
-
37
- // set limit for orders
38
- if ($limit != 0) {
39
- $limitQuery = " LIMIT $offset, $limit";
40
- }
41
-
42
- $salesFlatTable = Mage::getSingleton('core/resource')->getTableName('sales_flat_order');
43
- $sql = "select * from " . $salesFlatTable . $daysOldQuery . $limitQuery;
44
-
45
- $orders = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchAll($sql);
46
- return $orders;
47
- }
48
-
49
- /**
50
- * get active shipping methods
51
- */
52
- public function getActShipMethods()
53
- {
54
- $methods = Mage::getSingleton('shipping/config')->getActiveCarriers();
55
- $shipping = array();
56
- foreach ($methods as $_ccode => $_carrier) {
57
- if ($_methods = $_carrier->getAllowedMethods()) {
58
- if (!$_title = Mage::getStoreConfig("carriers/$_ccode/title")) {
59
- $_title = $_ccode;
60
- }
61
- foreach ($_methods as $_mcode => $_method) {
62
- $_code = $_ccode . '_' . $_mcode;
63
- $shipping[$_code] = array(
64
- 'title' => $_method,
65
- 'carrier' => $_title
66
- );
67
- }
68
- }
69
- }
70
- return $shipping;
71
- }
72
-
73
- /**
74
- * get active Payment methods
75
- * */
76
- function getActPayment()
77
- {
78
- $payments = Mage::getSingleton('payment/config')->getActiveMethods();
79
- foreach ($payments as $paymentCode => $paymentModel) {
80
- $paymentTitle[] = $paymentCode;
81
- }
82
- return $paymentTitle;
83
- }
84
-
85
- /**
86
- * Create order in magento
87
- */
88
- function create_order($data)
89
- {
90
- $logFileName = 'create_order.log';
91
- $customer = Mage::getModel('customer/customer');
92
- $quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore('default')->getId());
93
-
94
- $password = Mage::getModel('customer/customer')->generatePassword();
95
- if (!empty($data['BaseCustomer']['email'])) {
96
- $email = $data['BaseCustomer']['email'];
97
- } else {
98
- $email = 'customer_' . $data['BaseCustomer']['id'] . '@saleswarp.com';
99
- }
100
-
101
- if (!empty($data['ShippingAddress']['street'])) {
102
- $sStreet = $data['ShippingAddress']['street'];
103
- } else {
104
- $sStreet = '';
105
- }
106
-
107
- if (!empty($data['ShippingAddress']['street1'])) {
108
- $sStreet1 = $data['ShippingAddress']['street1'];
109
- } else {
110
- $sStreet1 = '';
111
- }
112
-
113
- if (!empty($data['BillingAddress']['street'])) {
114
- $bStreet = $data['BillingAddress']['street'];
115
- } else {
116
- $bStreet = '';
117
- }
118
- if (!empty($data['BillingAddress']['street1'])) {
119
- $bStreet1 = $data['BillingAddress']['street1'];
120
- } else {
121
- $bStreet1 = '';
122
- }
123
-
124
- if (!empty($data['ShippingAddress']['region_code']) && $data['ShippingAddress']['region_code'] != 'na') {
125
- $sregion_id = $data['ShippingAddress']['region_code'];
126
- } else {
127
- $sregion_id = '';
128
- }
129
-
130
- if (!empty($data['BillingAddress']['region_code']) && $data['BillingAddress']['region_code'] != 'na') {
131
- $bregion_id = $data['BillingAddress']['region_code'];
132
- } else {
133
- $bregion_id = '';
134
- }
135
-
136
- // customer address//
137
- if (!empty($data['BaseCustomer']['street'])) {
138
- $cStreet = $data['BaseCustomer']['street'];
139
- } else {
140
- $cStreet = '';
141
- }
142
- if (!empty($data['BaseCustomer']['street1'])) {
143
- $cStreet1 = $data['BaseCustomer']['street1'];
144
- } else {
145
- $cStreet1 = '';
146
- }
147
-
148
- if (!empty($data['BaseCustomer']['region_code']) && $data['BaseCustomer']['region_code'] != 'na') {
149
- $cregion_id = $data['BaseCustomer']['region_code'];
150
- } else {
151
- $cregion_id = '';
152
- }
153
-
154
- $shipAddressData = array(
155
- 'firstname' => (!empty($data['ShippingAddress']['first_name'])) ? $data['ShippingAddress']['first_name'] : '',
156
- 'lastname' => (!empty($data['ShippingAddress']['last_name'])) ? $data['ShippingAddress']['last_name'] : '',
157
- 'street' => array(
158
- '0' => $sStreet,
159
- '1' => $sStreet1
160
- ),
161
- 'city' => (!empty($data['ShippingAddress']['city'])) ? $data['ShippingAddress']['city'] : '',
162
- 'postcode' => (!empty($data['ShippingAddress']['post_code'])) ? $data['ShippingAddress']['post_code'] : '',
163
- 'telephone' => ($data['ShippingAddress']['phone']) ? $data['ShippingAddress']['phone'] : '111-111-1111',
164
- 'country_id' => (!empty($data['ShippingAddress']['country_code'])) ? $data['ShippingAddress']['country_code'] : 'US',
165
- 'region_id' => $sregion_id,
166
- 'region' => (!empty($data['ShippingAddress']['state'])) ? $data['ShippingAddress']['state'] : ''
167
- );
168
-
169
- $billAddressData = array(
170
- 'firstname' => (!empty($data['BillingAddress']['first_name'])) ? $data['BillingAddress']['first_name'] : '',
171
- 'lastname' => (!empty($data['BillingAddress']['last_name'])) ? $data['BillingAddress']['last_name'] : '',
172
- 'street' => array(
173
- '0' => $bStreet,
174
- '1' => $bStreet1
175
- ),
176
- 'city' => (!empty($data['BillingAddress']['city'])) ? $data['BillingAddress']['city'] : '',
177
- 'postcode' => (!empty($data['BillingAddress']['post_code'])) ? $data['BillingAddress']['post_code'] : '',
178
- 'telephone' => ($data['BillingAddress']['phone']) ? $data['BillingAddress']['phone'] : '111-111-1111',
179
- 'country_id' => (!empty($data['BillingAddress']['country_code'])) ? $data['BillingAddress']['country_code'] : 'US',
180
- 'region_id' => $bregion_id,
181
- 'region' => (!empty($data['BillingAddress']['state'])) ? $data['BillingAddress']['state'] : ''
182
- );
183
-
184
- $customerAddressData = array(
185
- 'firstname' => (!empty($data['BaseCustomer']['first_name'])) ? $data['BaseCustomer']['first_name'] : '',
186
- 'lastname' => (!empty($data['BaseCustomer']['last_name'])) ? $data['BaseCustomer']['last_name'] : '',
187
- 'street' => array(
188
- '0' => $cStreet,
189
- '1' => $cStreet1
190
- ),
191
- 'city' => (!empty($data['BaseCustomer']['city'])) ? $data['BaseCustomer']['city'] : '',
192
- 'postcode' => (!empty($data['BaseCustomer']['post_code'])) ? $data['BaseCustomer']['post_code'] : '',
193
- 'telephone' => ($data['BaseCustomer']['phone']) ? $data['BaseCustomer']['phone'] : '111-111-1111',
194
- 'country_id' => (!empty($data['BaseCustomer']['country_code'])) ? $data['BaseCustomer']['country_code'] : 'US',
195
- 'region_id' => $bregion_id,
196
- 'region' => (!empty($data['BaseCustomer']['state'])) ? $data['BaseCustomer']['state'] : ''
197
- );
198
-
199
- $customer_group_id = $this->get_customer_group_id_by_name($data['BaseCustomer']['group']);
200
- $customer->setWebsiteId(1);
201
- $customer->loadByEmail($email);
202
-
203
- if (!$customer->getId()) {
204
- $customer->setEmail($email);
205
- $customer->setWebsiteId(1);
206
- $customer->setFirstname($data['BaseCustomer']['first_name']);
207
- $customer->setLastname($data['BaseCustomer']['last_name']);
208
- $customer->setPassword($password);
209
- $customer->setGroupId($customer_group_id);
210
- try {
211
- $customer->save();
212
- $customer->setConfirmation(null);
213
- $customer->save();
214
- // save billing address//
215
- $address = Mage::getModel("customer/address");
216
- $address->setData($billAddressData)->setCustomerId($customer->getId())->setIsDefaultBilling('1')->setIsDefaultShipping('1')->setSaveInAddressBook('1');
217
-
218
- try {
219
- $address->save();
220
- }catch (Exception $ex) {
221
- Mage::log($ex->getMessage(), null, $logFileName);
222
- return false;
223
- }
224
-
225
- //Make a "login" of new customer
226
- Mage::getSingleton('customer/session')->loginById($customer->getId());
227
- $quote->assignCustomer($customer);
228
- }
229
- catch (Exception $ex) {
230
- Mage::log($ex->getMessage(), null, $logFileName);
231
- return false;
232
- }
233
- } else {
234
- $quote->assignCustomer($customer);
235
- }
236
-
237
- $store_id = $data['BaseOrder']['base_store_id'];
238
- $lineitem = $data['Lineitem'];
239
- foreach ($lineitem as $item) {
240
- // check whether item/product published or not
241
- $prod_id = $item['base_product_id'];
242
- $mage_prod_id = $item['mageProdId'];
243
- $prodId[$prod_id] = $item['mageProdId'];
244
- $qty_ordered = (int) $item['qty_ordered'];
245
- $buyInfo = array('qty' => $qty_ordered);
246
- $prod = Mage::getModel('catalog/product')->load($mage_prod_id);
247
- $prod->setPrice($item['price_after_discount']);
248
- $prod->setSpecialPrice($item['price_after_discount']);
249
- try {
250
- $quote->addProduct($prod, new Varien_Object($buyInfo));
251
- }
252
- catch (Exception $e) {
253
- Mage::log($e->getMessage(), null, $logFileName);
254
- continue;
255
- }
256
- }
257
-
258
- $shipMethod = 'flatrate_flatrate';
259
-
260
- try {
261
- $billingAddress = $quote->getBillingAddress()->addData($billAddressData);
262
- }
263
- catch (Exception $e) {
264
- Mage::log($e->getMessage(), null, $logFileName);
265
- }
266
- $shippingAddress = $quote->getShippingAddress()->addData($shipAddressData);
267
- $shippingAddress->setCollectShippingRates(true)->collectShippingRates()->setShippingMethod($shipMethod);
268
-
269
- $paymentMethod = array(
270
- 'method' => 'saleswarp',
271
- 'transction_no' => $data['Saleswarp']['transactionId'],
272
- 'payment_method' => $data['Saleswarp']['payMethodName']
273
- );
274
-
275
- try {
276
- $quote->getPayment()->importData($paymentMethod);
277
- }
278
- catch (Exception $e) {
279
- Mage::log($e->getMessage(), null, $logFileName);
280
- return false;
281
- }
282
- $quote->collectTotals()->save();
283
-
284
- $service = Mage::getModel('sales/service_quote', $quote);
285
-
286
- try {
287
- $service->submitAll();
288
- }
289
- catch (Exception $e) {
290
- Mage::log($e->getMessage(), null, $logFileName);
291
- return false;
292
- }
293
-
294
- try {
295
- $order = $service->getOrder();
296
- if ($order) {
297
- $morder_id = $order->getIncrementId();
298
- Mage::log("Created order: " . $morder_id, null, $logFileName);
299
- return $morder_id;
300
- }
301
- }
302
- catch (Exception $e) {
303
- Mage::log($e->getMessage(), null, $logFileName);
304
- return false;
305
- }
306
- }
307
-
308
- /**
309
- * Get Customer Group id by group name
310
- */
311
- function get_customer_group_id_by_name($name)
312
- {
313
- $write = Mage::getSingleton('core/resource')->getConnection('core_write');
314
- $type = addslashes($name);
315
-
316
- //check for existig group
317
- $customerGrpTable = Mage::getSingleton('core/resource')->getTableName('customer_group');
318
-
319
- $chk = $write->query("SELECT customer_group_id FROM " . $customerGrpTable . " WHERE customer_group_code = '" . $type . "'");
320
- $row = $chk->fetch(PDO::FETCH_ASSOC);
321
- if ($row) {
322
- return $row['customer_group_id'];
323
- }
324
- return false;
325
- }
326
-
327
- /**
328
- * * Cancel Order
329
- */
330
- function cancel_order($magento_orderId)
331
- {
332
- $orderModel = Mage::getModel('sales/order')->loadByIncrementId($magento_orderId);
333
- if ($orderModel->canCancel()) {
334
- $orderModel->setState(Mage_Sales_Model_Order::STATE_CANCELED, true)->save();
335
- return true;
336
- } else if($this->creditmemo_order($magento_orderId)) {
337
- return true;
338
- } else {
339
- return false;
340
- }
341
- }
342
-
343
- /**
344
- * Hold order
345
- */
346
- function hold_order($magento_orderId)
347
- {
348
- $orderModel = Mage::getModel('sales/order')->loadByIncrementId($magento_orderId);
349
- if ($orderModel->canHold()) {
350
- $orderModel->setState(Mage_Sales_Model_Order::STATE_HOLDED, true)->save();
351
- return true;
352
- } else {
353
- return false;
354
- }
355
- }
356
-
357
- /**
358
- * Create Credit memo
359
- */
360
- function creditmemo_order($magento_orderId)
361
- {
362
- Mage::getModel('sales/order_creditmemo_api')->create($magento_orderId);
363
- Mage::getModel('sales/order')->loadByIncrementId($magento_orderId)->setState(Mage_Sales_Model_Order::STATE_CLOSED, true)->save();
364
- return true;
365
- }
366
-
367
- /**
368
- * Add tracking information to a order
369
- */
370
- function create_ship_track($shipment_id, $carrier, $msg, $track_id)
371
- {
372
- $this->order_shipment = Mage::getSingleton('sales/order_shipment_api');
373
- return $this->order_shipment->addTrack($shipment_id, $carrier, $msg, $track_id);
374
- }
375
-
376
- /**
377
- * Send Shipment email to customer
378
- */
379
- function send_ship_email($newShipmentId, $comment)
380
- {
381
- $this->order_shipment = Mage::getSingleton('sales/order_shipment_api');
382
- return $this->order_shipment->sendInfo($newShipmentId, $comment);
383
- }
384
-
385
- /**
386
- * Add comment to a shipment
387
- */
388
-
389
- function create_ship_comment($shipment_id, $comment, $send_email, $include_comment)
390
- {
391
- $this->order_shipment = Mage::getSingleton('sales/order_shipment_api');
392
- return $this->order_shipment->addComment($shipment_id, $comment, $send_email, $include_comment);
393
- }
394
-
395
- /**
396
- * Add comment to Order
397
- */
398
- function create_order_comment($order_id, $comment, $status = "complete", $notify = true)
399
- {
400
- $this->order = Mage::getSingleton('sales/order_api');
401
- return $this->order->addComment($order_id, $comment, $status, $notify);
402
- }
403
-
404
- /**
405
- * Create order shipment
406
- */
407
- function create_order_shipment($order_id, $info, $message = "Shipped", $send_email = true, $include_comment = true)
408
- {
409
- $this->order_shipment = Mage::getSingleton('sales/order_shipment_api');
410
- return $this->order_shipment->create($order_id, $info, $message, $send_email, $include_comment);
411
- }
412
-
413
- /**
414
- * Retrieve full order information
415
- *
416
- * @param string $orderIncrementId
417
- * @return array
418
- */
419
- public function info($orderIncrementId)
420
- {
421
- $order = $this->_initOrder($orderIncrementId);
422
-
423
- if ($order->getGiftMessageId() > 0) {
424
- $order->setGiftMessage(Mage::getSingleton('giftmessage/message')->load($order->getGiftMessageId())->getMessage());
425
- }
426
-
427
- $result = $this->_getAttributes($order, 'order');
428
-
429
- $result['shipping_address'] = $this->_getAttributes($order->getShippingAddress(), 'order_address');
430
- $result['billing_address'] = $this->_getAttributes($order->getBillingAddress(), 'order_address');
431
- $result['items'] = array();
432
-
433
- foreach ($order->getAllItems() as $item) {
434
- if ($item->getGiftMessageId() > 0) {
435
- $item->setGiftMessage(Mage::getSingleton('giftmessage/message')->load($item->getGiftMessageId())->getMessage());
436
- }
437
-
438
- // We need to grab some saleswarp data from the related product
439
- $product = Mage::getModel('catalog/product')->load((int) $item['product_id']);
440
-
441
- foreach ($product->getData() as $k => $v) {
442
- if (strpos($k, 'saleswarp') !== false)
443
- $item[$k] = $v;
444
- }
445
- $item['prod_url'] = $product->getProductUrl();
446
-
447
- $result['items'][] = $this->_getAttributes($item, 'order_item');
448
- }
449
-
450
- $result['payment'] = $this->_getAttributes($order->getPayment(), 'order_payment');
451
- $result['status_history'] = array();
452
-
453
- foreach ($order->getAllStatusHistory() as $history) {
454
- $result['status_history'][] = $this->_getAttributes($history, 'order_status_history');
455
- }
456
-
457
- return $result;
458
- }
459
-
460
- /**
461
- * Genearate Refund for a order
462
- */
463
- function refund_invoice($magento_orderId, $data)
464
- {
465
- $order = Mage::getModel('sales/order')->loadByIncrementId($magento_orderId);
466
-
467
- $inv = true;
468
- if (isset($data['inv'])) {
469
- $inv = false;
470
- unset($data['inv']);
471
- }
472
- $creditmemo = $this->_initCreditmemo($data, $magento_orderId, $inv);
473
-
474
- if (isset($data['do_refund'])) {
475
- $creditmemo->setRefundRequested(true);
476
- }
477
- if (isset($data['do_offline'])) {
478
- $creditmemo->setOfflineRequested((bool) (int) $data['do_offline']);
479
- }
480
- $creditmemo->register();
481
- if (!empty($data['send_email'])) {
482
- $creditmemo->setEmailSent(true);
483
- }
484
- $creditmemo->getOrder()->setCustomerNoteNotify(!empty($data['send_email']));
485
- $this->_saveCreditmemo($creditmemo);
486
- return true;
487
- }
488
-
489
- protected function _saveCreditmemo($creditmemo)
490
- {
491
- $transactionSave = Mage::getModel('core/resource_transaction')->addObject($creditmemo)->addObject($creditmemo->getOrder());
492
- if ($creditmemo->getInvoice()) {
493
- $transactionSave->addObject($creditmemo->getInvoice());
494
- }
495
- $transactionSave->save();
496
- return $this;
497
- }
498
-
499
- protected function _initInvoice($order, $invoiceId)
500
- {
501
- if ($invoiceId) {
502
- $invoice = Mage::getModel('sales/order_invoice')->load($invoiceId)->setOrder($order);
503
- if ($invoice->getId()) {
504
- return $invoice;
505
- }
506
- }
507
- return false;
508
- }
509
-
510
- protected function _getItemData($data)
511
- {
512
- if (isset($data['items'])) {
513
- $qtys = $data['items'];
514
- } else {
515
- $qtys = array();
516
- }
517
- return $qtys;
518
- }
519
-
520
- protected function _initCreditmemo($data, $orderId, $inv = true)
521
- {
522
- $creditmemo = false;
523
- $creditmemoId = null;
524
- if ($creditmemoId) {
525
- $creditmemo = Mage::getModel('sales/order_creditmemo')->load($creditmemoId);
526
- } elseif ($orderId) {
527
- $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
528
- if ($inv === true) {
529
- foreach ($order->getInvoiceCollection() as $invoice) {
530
- if ($invoice->canRefund()) {
531
- $invoiceId = $invoice->getId();
532
- break;
533
- }
534
- }
535
- $invoice = $this->_initInvoice($order, $invoiceId);
536
- } else {
537
- $invoice = false;
538
- }
539
- $savedData = $this->_getItemData($data);
540
- $qtys = array();
541
- $backToStock = array();
542
- foreach ($savedData as $orderItemId => $itemData) {
543
- if (isset($itemData['qty'])) {
544
- $qtys[$orderItemId] = $itemData['qty'];
545
- }
546
- if (isset($itemData['back_to_stock'])) {
547
- $backToStock[$orderItemId] = true;
548
- }
549
- }
550
- $data['qtys'] = $qtys;
551
-
552
-
553
- $service = Mage::getModel('sales/service_order', $order);
554
- if ($invoice) {
555
- $creditmemo = $service->prepareInvoiceCreditmemo($invoice, $data);
556
- } else {
557
- $creditmemo = $service->prepareCreditmemo($data);
558
- }
559
- }
560
- Mage::register('current_creditmemo', $creditmemo);
561
- return $creditmemo;
562
- }
563
- } // Class end
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This module connects Magento to the SalesWarp Advanced Order Management System.
4
+ *
5
+ * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
+ * @version 0.1.2
7
+ * @author David Potts
8
+ * @license http://www.saleswarp.com/license-saas
9
+ * @category SalesWarp
10
+ * @since File available since Release 0.1.2
11
+ * @link https://www.SalesWarp.com
12
+ *
13
+ */
14
+ class Saleswarp_Oms_Model_Order_Api extends Mage_Sales_Model_Order_Api
15
+ {
16
+ const STATE_RETURN_REQUESTED = 'return_requested';
17
+ const STATE_EXCHANGE = 'exchange';
18
+ const STATE_ADVANCED_EXCHANGE = 'advanced_exchange';
19
+ const STATE_RETURN_RECEIVED = 'return_received';
20
+
21
+ /**
22
+ * return a recent order list
23
+ * if any parameter is set to zero then that will not be considered for order pull.
24
+ */
25
+ public function get_recent_order_list($limit = 0, $lastdays = 5, $offset = 0)
26
+ {
27
+ $storeId = Mage::app()->getStore()->getStoreId();
28
+ $conditions = ' WHERE store_id = ' . $storeId . ' AND ';
29
+
30
+ // return a list of orders in the last X days
31
+ if ($lastdays != 0) {
32
+ $conditions .= " created_at > '" . strftime('%Y-%m-%d %H:%M:%S', (time() - (24 * 60 * 60 * $lastdays))) . "'";
33
+ }
34
+
35
+ // set limit for orders
36
+ if ($limit != 0) {
37
+ $conditions .= " LIMIT $offset, $limit";
38
+ }
39
+
40
+ $salesFlatTable = Mage::getSingleton('core/resource')->getTableName('sales_flat_order');
41
+ $sql = "select * from " . $salesFlatTable . $conditions;
42
+
43
+ $orders = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchAll($sql);
44
+ return $orders;
45
+ }
46
+
47
+ /**
48
+ * get active shipping methods
49
+ */
50
+ public function getActShipMethods()
51
+ {
52
+ $methods = Mage::getSingleton('shipping/config')->getActiveCarriers();
53
+ $shipping = array();
54
+ foreach ($methods as $_ccode => $_carrier) {
55
+ if ($_methods = $_carrier->getAllowedMethods()) {
56
+ if (!$_title = Mage::getStoreConfig("carriers/$_ccode/title")) {
57
+ $_title = $_ccode;
58
+ }
59
+ foreach ($_methods as $_mcode => $_method) {
60
+ $_code = $_ccode . '_' . $_mcode;
61
+ $shipping[$_code] = array(
62
+ 'title' => $_method,
63
+ 'carrier' => $_title
64
+ );
65
+ }
66
+ }
67
+ }
68
+ return $shipping;
69
+ }
70
+
71
+ /**
72
+ * get active Payment methods
73
+ * */
74
+ function getActPayment()
75
+ {
76
+ $payments = Mage::getSingleton('payment/config')->getActiveMethods();
77
+ foreach ($payments as $paymentCode => $paymentModel) {
78
+ $paymentTitle[] = $paymentCode;
79
+ }
80
+ return $paymentTitle;
81
+ }
82
+
83
+ /**
84
+ * function to get lineitem id
85
+ * @param magento order id
86
+ * @return lineitems id
87
+ */
88
+ function getLineItem($mageOrderId)
89
+ {
90
+ // get the order id
91
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
92
+ $salesFlatTable = Mage::getSingleton( 'core/resource' )->getTableName( 'sales_flat_order' );
93
+ $orderItemTable = Mage::getSingleton( 'core/resource' )->getTableName( 'sales_flat_order_item' );
94
+
95
+ //check for existig group
96
+ $chk = $write->query("SELECT l.item_id, l.product_id FROM ". $salesFlatTable ." ord INNER JOIN
97
+ ". $orderItemTable ." l ON ord.entity_id = l.order_id WHERE ord.increment_id = '".(int)$mageOrderId."'");
98
+ $row = $chk->fetchAll(PDO::FETCH_ASSOC);
99
+ return $row;
100
+ }
101
+
102
+ /**
103
+ * Create order in magento
104
+ */
105
+ function create_order($data)
106
+ {
107
+ $logFileName = 'create_order.log';
108
+ $customer = Mage::getModel('customer/customer');
109
+ $quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore('default')->getId());
110
+
111
+ $password = Mage::getModel('customer/customer')->generatePassword();
112
+ if (!empty($data['BaseCustomer']['email'])) {
113
+ $email = $data['BaseCustomer']['email'];
114
+ } else {
115
+ $email = 'customer_' . $data['BaseCustomer']['id'] . '@saleswarp.com';
116
+ }
117
+
118
+ if (!empty($data['ShippingAddress']['street'])) {
119
+ $sStreet = $data['ShippingAddress']['street'];
120
+ } else {
121
+ $sStreet = '';
122
+ }
123
+
124
+ if (!empty($data['ShippingAddress']['street1'])) {
125
+ $sStreet1 = $data['ShippingAddress']['street1'];
126
+ } else {
127
+ $sStreet1 = '';
128
+ }
129
+
130
+ if (!empty($data['BillingAddress']['street'])) {
131
+ $bStreet = $data['BillingAddress']['street'];
132
+ } else {
133
+ $bStreet = '';
134
+ }
135
+ if (!empty($data['BillingAddress']['street1'])) {
136
+ $bStreet1 = $data['BillingAddress']['street1'];
137
+ } else {
138
+ $bStreet1 = '';
139
+ }
140
+
141
+ if (!empty($data['ShippingAddress']['region_code']) && $data['ShippingAddress']['region_code'] != 'na') {
142
+ $sregion_id = $data['ShippingAddress']['region_code'];
143
+ } else {
144
+ $sregion_id = '';
145
+ }
146
+
147
+ if (!empty($data['BillingAddress']['region_code']) && $data['BillingAddress']['region_code'] != 'na') {
148
+ $bregion_id = $data['BillingAddress']['region_code'];
149
+ } else {
150
+ $bregion_id = '';
151
+ }
152
+
153
+ // customer address//
154
+ if (!empty($data['BaseCustomer']['street'])) {
155
+ $cStreet = $data['BaseCustomer']['street'];
156
+ } else {
157
+ $cStreet = '';
158
+ }
159
+ if (!empty($data['BaseCustomer']['street1'])) {
160
+ $cStreet1 = $data['BaseCustomer']['street1'];
161
+ } else {
162
+ $cStreet1 = '';
163
+ }
164
+
165
+ if (!empty($data['BaseCustomer']['region_code']) && $data['BaseCustomer']['region_code'] != 'na') {
166
+ $cregion_id = $data['BaseCustomer']['region_code'];
167
+ } else {
168
+ $cregion_id = '';
169
+ }
170
+
171
+ $shipAddressData = array(
172
+ 'firstname' => (!empty($data['ShippingAddress']['first_name'])) ? $data['ShippingAddress']['first_name'] : '',
173
+ 'lastname' => (!empty($data['ShippingAddress']['last_name'])) ? $data['ShippingAddress']['last_name'] : '',
174
+ 'street' => array(
175
+ '0' => $sStreet,
176
+ '1' => $sStreet1
177
+ ),
178
+ 'city' => (!empty($data['ShippingAddress']['city'])) ? $data['ShippingAddress']['city'] : '',
179
+ 'postcode' => (!empty($data['ShippingAddress']['post_code'])) ? $data['ShippingAddress']['post_code'] : '',
180
+ 'telephone' => ($data['ShippingAddress']['phone']) ? $data['ShippingAddress']['phone'] : '111-111-1111',
181
+ 'country_id' => (!empty($data['ShippingAddress']['country_code'])) ? $data['ShippingAddress']['country_code'] : 'US',
182
+ 'region_id' => $sregion_id,
183
+ 'region' => (!empty($data['ShippingAddress']['state'])) ? $data['ShippingAddress']['state'] : ''
184
+ );
185
+
186
+ $billAddressData = array(
187
+ 'firstname' => (!empty($data['BillingAddress']['first_name'])) ? $data['BillingAddress']['first_name'] : '',
188
+ 'lastname' => (!empty($data['BillingAddress']['last_name'])) ? $data['BillingAddress']['last_name'] : '',
189
+ 'street' => array(
190
+ '0' => $bStreet,
191
+ '1' => $bStreet1
192
+ ),
193
+ 'city' => (!empty($data['BillingAddress']['city'])) ? $data['BillingAddress']['city'] : '',
194
+ 'postcode' => (!empty($data['BillingAddress']['post_code'])) ? $data['BillingAddress']['post_code'] : '',
195
+ 'telephone' => ($data['BillingAddress']['phone']) ? $data['BillingAddress']['phone'] : '111-111-1111',
196
+ 'country_id' => (!empty($data['BillingAddress']['country_code'])) ? $data['BillingAddress']['country_code'] : 'US',
197
+ 'region_id' => $bregion_id,
198
+ 'region' => (!empty($data['BillingAddress']['state'])) ? $data['BillingAddress']['state'] : ''
199
+ );
200
+
201
+ $customerAddressData = array(
202
+ 'firstname' => (!empty($data['BaseCustomer']['first_name'])) ? $data['BaseCustomer']['first_name'] : '',
203
+ 'lastname' => (!empty($data['BaseCustomer']['last_name'])) ? $data['BaseCustomer']['last_name'] : '',
204
+ 'street' => array(
205
+ '0' => $cStreet,
206
+ '1' => $cStreet1
207
+ ),
208
+ 'city' => (!empty($data['BaseCustomer']['city'])) ? $data['BaseCustomer']['city'] : '',
209
+ 'postcode' => (!empty($data['BaseCustomer']['post_code'])) ? $data['BaseCustomer']['post_code'] : '',
210
+ 'telephone' => ($data['BaseCustomer']['phone']) ? $data['BaseCustomer']['phone'] : '111-111-1111',
211
+ 'country_id' => (!empty($data['BaseCustomer']['country_code'])) ? $data['BaseCustomer']['country_code'] : 'US',
212
+ 'region_id' => $bregion_id,
213
+ 'region' => (!empty($data['BaseCustomer']['state'])) ? $data['BaseCustomer']['state'] : ''
214
+ );
215
+
216
+ $customer_group_id = $this->get_customer_group_id_by_name($data['BaseCustomer']['group']);
217
+ $customer->setWebsiteId(1);
218
+ $customer->loadByEmail($email);
219
+
220
+ if (!$customer->getId()) {
221
+ $customer->setEmail($email);
222
+ $customer->setWebsiteId(1);
223
+ $customer->setFirstname($data['BaseCustomer']['first_name']);
224
+ $customer->setLastname($data['BaseCustomer']['last_name']);
225
+ $customer->setPassword($password);
226
+ $customer->setGroupId($customer_group_id);
227
+ try {
228
+ $customer->save();
229
+ $customer->setConfirmation(null);
230
+ $customer->save();
231
+ // save billing address//
232
+ $address = Mage::getModel("customer/address");
233
+ $address->setData($billAddressData)->setCustomerId($customer->getId())->setIsDefaultBilling('1')->setIsDefaultShipping('1')->setSaveInAddressBook('1');
234
+
235
+ try {
236
+ $address->save();
237
+ }catch (Exception $ex) {
238
+ Mage::log($ex->getMessage(), null, $logFileName);
239
+ return false;
240
+ }
241
+
242
+ //Make a "login" of new customer
243
+ Mage::getSingleton('customer/session')->loginById($customer->getId());
244
+ $quote->assignCustomer($customer);
245
+ }
246
+ catch (Exception $ex) {
247
+ Mage::log($ex->getMessage(), null, $logFileName);
248
+ return false;
249
+ }
250
+ } else {
251
+ $quote->assignCustomer($customer);
252
+ }
253
+
254
+ $store_id = $data['BaseOrder']['base_store_id'];
255
+ $lineitem = $data['Lineitem'];
256
+ foreach ($lineitem as $item) {
257
+ // check whether item/product published or not
258
+ $prod_id = $item['base_product_id'];
259
+ $mage_prod_id = $item['mageProdId'];
260
+ $prodId[$prod_id] = $item['mageProdId'];
261
+ $qty_ordered = (int) $item['qty_ordered'];
262
+ $buyInfo = array('qty' => $qty_ordered);
263
+ $prod = Mage::getModel('catalog/product')->load($mage_prod_id);
264
+ $prod->setPrice($item['price_after_discount']);
265
+ $prod->setSpecialPrice($item['price_after_discount']);
266
+ try {
267
+ $quote->addProduct($prod, new Varien_Object($buyInfo));
268
+ }
269
+ catch (Exception $e) {
270
+ Mage::log($e->getMessage(), null, $logFileName);
271
+ continue;
272
+ }
273
+ }
274
+
275
+ $shipMethod = !empty($data['Saleswarp']['freightID']) ? $data['Saleswarp']['freightID'] : 'flatrate_flatrate';
276
+
277
+ try {
278
+ $billingAddress = $quote->getBillingAddress()->addData($billAddressData);
279
+ }
280
+ catch (Exception $e) {
281
+ Mage::log($e->getMessage(), null, $logFileName);
282
+ }
283
+ $shippingAddress = $quote->getShippingAddress()->addData($shipAddressData);
284
+ $shippingAddress->setCollectShippingRates(true)->collectShippingRates()->setShippingMethod($shipMethod);
285
+
286
+ $paymentMethod = array(
287
+ 'method' => 'saleswarp',
288
+ 'transction_no' => $data['Saleswarp']['transactionId'],
289
+ 'payment_method' => $data['Saleswarp']['payMethodName']
290
+ );
291
+
292
+ try {
293
+ $quote->getPayment()->importData($paymentMethod);
294
+ }
295
+ catch (Exception $e) {
296
+ Mage::log($e->getMessage(), null, $logFileName);
297
+ return false;
298
+ }
299
+ $quote->collectTotals()->save();
300
+
301
+ $service = Mage::getModel('sales/service_quote', $quote);
302
+
303
+ try {
304
+ $service->submitAll();
305
+ }
306
+ catch (Exception $e) {
307
+ Mage::log($e->getMessage(), null, $logFileName);
308
+ return false;
309
+ }
310
+
311
+ try {
312
+ $order = $service->getOrder();
313
+ if ($order) {
314
+ $morder_id = $order->getIncrementId();
315
+ Mage::log("Created order: " . $morder_id, null, $logFileName);
316
+ return $morder_id;
317
+ }
318
+ }
319
+ catch (Exception $e) {
320
+ Mage::log($e->getMessage(), null, $logFileName);
321
+ return false;
322
+ }
323
+ }
324
+
325
+ /**
326
+ * Get Customer Group id by group name
327
+ */
328
+ function get_customer_group_id_by_name($name)
329
+ {
330
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
331
+ $type = addslashes($name);
332
+
333
+ //check for existig group
334
+ $customerGrpTable = Mage::getSingleton('core/resource')->getTableName('customer_group');
335
+
336
+ $chk = $write->query("SELECT customer_group_id FROM " . $customerGrpTable . " WHERE customer_group_code = '" . $type . "'");
337
+ $row = $chk->fetch(PDO::FETCH_ASSOC);
338
+ if ($row) {
339
+ return $row['customer_group_id'];
340
+ }
341
+ return false;
342
+ }
343
+
344
+ /**
345
+ * * Cancel Order
346
+ */
347
+ function cancel_order($magento_orderId)
348
+ {
349
+ $orderModel = Mage::getModel('sales/order')->loadByIncrementId($magento_orderId);
350
+ if ($orderModel->canCancel()) {
351
+ $orderModel->setState(Mage_Sales_Model_Order::STATE_CANCELED, true)->save();
352
+ return true;
353
+ } else if($this->creditmemo_order($magento_orderId)) {
354
+ return true;
355
+ } else {
356
+ return false;
357
+ }
358
+ }
359
+
360
+ /**
361
+ * Hold order
362
+ */
363
+ function hold_order($magento_orderId)
364
+ {
365
+ $orderModel = Mage::getModel('sales/order')->loadByIncrementId($magento_orderId);
366
+ if ($orderModel->canHold()) {
367
+ $orderModel->setState(Mage_Sales_Model_Order::STATE_HOLDED, true)->save();
368
+ return true;
369
+ } else {
370
+ return false;
371
+ }
372
+ }
373
+
374
+ /**
375
+ * Create Credit memo
376
+ */
377
+ function creditmemo_order($magento_orderId)
378
+ {
379
+ Mage::getModel('sales/order_creditmemo_api')->create($magento_orderId);
380
+ Mage::getModel('sales/order')->loadByIncrementId($magento_orderId)->setState(Mage_Sales_Model_Order::STATE_CLOSED, true)->save();
381
+ return true;
382
+ }
383
+
384
+ /**
385
+ * Add tracking information to a order
386
+ */
387
+ function create_ship_track($shipment_id, $carrier, $msg, $track_id)
388
+ {
389
+ $this->order_shipment = Mage::getSingleton('sales/order_shipment_api');
390
+ return $this->order_shipment->addTrack($shipment_id, $carrier, $msg, $track_id);
391
+ }
392
+
393
+ /**
394
+ * Send Shipment email to customer
395
+ */
396
+ function send_ship_email($newShipmentId, $comment)
397
+ {
398
+ $this->order_shipment = Mage::getSingleton('sales/order_shipment_api');
399
+ return $this->order_shipment->sendInfo($newShipmentId, $comment);
400
+ }
401
+
402
+ /**
403
+ * Add comment to a shipment
404
+ */
405
+
406
+ function create_ship_comment($shipment_id, $comment, $send_email, $include_comment)
407
+ {
408
+ $this->order_shipment = Mage::getSingleton('sales/order_shipment_api');
409
+ return $this->order_shipment->addComment($shipment_id, $comment, $send_email, $include_comment);
410
+ }
411
+
412
+ /**
413
+ * Add comment to Order
414
+ */
415
+ function create_order_comment($order_id, $comment, $status = "complete", $notify = true)
416
+ {
417
+ $this->order = Mage::getSingleton('sales/order_api');
418
+ return $this->order->addComment($order_id, $comment, $status, $notify);
419
+ }
420
+
421
+ /**
422
+ * Create order shipment
423
+ */
424
+ function create_order_shipment($order_id, $info, $message = "Shipped", $send_email = true, $include_comment = true)
425
+ {
426
+ $this->order_shipment = Mage::getSingleton('sales/order_shipment_api');
427
+ return $this->order_shipment->create($order_id, $info, $message, $send_email, $include_comment);
428
+ }
429
+
430
+ /**
431
+ * Retrieve full order information
432
+ *
433
+ * @param string $orderIncrementId
434
+ * @return array
435
+ */
436
+ public function info($orderIncrementId)
437
+ {
438
+ $order = $this->_initOrder($orderIncrementId);
439
+
440
+ if ($order->getGiftMessageId() > 0) {
441
+ $order->setGiftMessage(Mage::getSingleton('giftmessage/message')->load($order->getGiftMessageId())->getMessage());
442
+ }
443
+
444
+ $result = $this->_getAttributes($order, 'order');
445
+
446
+ $result['shipping_address'] = $this->_getAttributes($order->getShippingAddress(), 'order_address');
447
+ $result['billing_address'] = $this->_getAttributes($order->getBillingAddress(), 'order_address');
448
+ $result['items'] = array();
449
+
450
+ foreach ($order->getAllItems() as $item) {
451
+ if ($item->getGiftMessageId() > 0) {
452
+ $item->setGiftMessage(Mage::getSingleton('giftmessage/message')->load($item->getGiftMessageId())->getMessage());
453
+ }
454
+
455
+ // We need to grab some saleswarp data from the related product
456
+ $product = Mage::getModel('catalog/product')->load((int) $item['product_id']);
457
+
458
+ foreach ($product->getData() as $k => $v) {
459
+ if (strpos($k, 'saleswarp') !== false)
460
+ $item[$k] = $v;
461
+ }
462
+ $item['prod_url'] = $product->getProductUrl();
463
+
464
+ $result['items'][] = $this->_getAttributes($item, 'order_item');
465
+ }
466
+
467
+ $result['payment'] = $this->_getAttributes($order->getPayment(), 'order_payment');
468
+ $result['status_history'] = array();
469
+
470
+ foreach ($order->getAllStatusHistory() as $history) {
471
+ $result['status_history'][] = $this->_getAttributes($history, 'order_status_history');
472
+ }
473
+
474
+ return $result;
475
+ }
476
+
477
+ /**
478
+ * Genearate Refund for a order
479
+ */
480
+ function refund_invoice($magento_orderId, $data)
481
+ {
482
+ $order = Mage::getModel('sales/order')->loadByIncrementId($magento_orderId);
483
+
484
+ $inv = true;
485
+ if (isset($data['inv'])) {
486
+ $inv = false;
487
+ unset($data['inv']);
488
+ }
489
+ $creditmemo = $this->_initCreditmemo($data, $magento_orderId, $inv);
490
+
491
+ if (isset($data['do_refund'])) {
492
+ $creditmemo->setRefundRequested(true);
493
+ }
494
+ if (isset($data['do_offline'])) {
495
+ $creditmemo->setOfflineRequested((bool) (int) $data['do_offline']);
496
+ }
497
+ $creditmemo->register();
498
+ if (!empty($data['send_email'])) {
499
+ $creditmemo->setEmailSent(true);
500
+ }
501
+ $creditmemo->getOrder()->setCustomerNoteNotify(!empty($data['send_email']));
502
+ $this->_saveCreditmemo($creditmemo);
503
+ return true;
504
+ }
505
+
506
+ protected function _saveCreditmemo($creditmemo)
507
+ {
508
+ $transactionSave = Mage::getModel('core/resource_transaction')->addObject($creditmemo)->addObject($creditmemo->getOrder());
509
+ if ($creditmemo->getInvoice()) {
510
+ $transactionSave->addObject($creditmemo->getInvoice());
511
+ }
512
+ $transactionSave->save();
513
+ return $this;
514
+ }
515
+
516
+ protected function _initInvoice($order, $invoiceId)
517
+ {
518
+ if ($invoiceId) {
519
+ $invoice = Mage::getModel('sales/order_invoice')->load($invoiceId)->setOrder($order);
520
+ if ($invoice->getId()) {
521
+ return $invoice;
522
+ }
523
+ }
524
+ return false;
525
+ }
526
+
527
+ protected function _getItemData($data)
528
+ {
529
+ if (isset($data['items'])) {
530
+ $qtys = $data['items'];
531
+ } else {
532
+ $qtys = array();
533
+ }
534
+ return $qtys;
535
+ }
536
+
537
+ protected function _initCreditmemo($data, $orderId, $inv = true)
538
+ {
539
+ $creditmemo = false;
540
+ $creditmemoId = null;
541
+ if ($creditmemoId) {
542
+ $creditmemo = Mage::getModel('sales/order_creditmemo')->load($creditmemoId);
543
+ } elseif ($orderId) {
544
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
545
+ if ($inv === true) {
546
+ foreach ($order->getInvoiceCollection() as $invoice) {
547
+ if ($invoice->canRefund()) {
548
+ $invoiceId = $invoice->getId();
549
+ break;
550
+ }
551
+ }
552
+ $invoice = $this->_initInvoice($order, $invoiceId);
553
+ } else {
554
+ $invoice = false;
555
+ }
556
+ $savedData = $this->_getItemData($data);
557
+ $qtys = array();
558
+ $backToStock = array();
559
+ foreach ($savedData as $orderItemId => $itemData) {
560
+ if (isset($itemData['qty'])) {
561
+ $qtys[$orderItemId] = $itemData['qty'];
562
+ }
563
+ if (isset($itemData['back_to_stock'])) {
564
+ $backToStock[$orderItemId] = true;
565
+ }
566
+ }
567
+ $data['qtys'] = $qtys;
568
+
569
+
570
+ $service = Mage::getModel('sales/service_order', $order);
571
+ if ($invoice) {
572
+ $creditmemo = $service->prepareInvoiceCreditmemo($invoice, $data);
573
+ } else {
574
+ $creditmemo = $service->prepareCreditmemo($data);
575
+ }
576
+ }
577
+ Mage::register('current_creditmemo', $creditmemo);
578
+ return $creditmemo;
579
+ }
580
+ } // Class end
app/code/local/Saleswarp/Oms/Model/Product/Api.php CHANGED
@@ -1,355 +1,362 @@
1
- <?php
2
- /**
3
- * This module connects Magento to the SalesWarp Advanced Order Management System.
4
- *
5
- * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
- * @version 0.1.2
7
- * @author David Potts
8
- * @license http://www.saleswarp.com/license-saas
9
- * @category SalesWarp
10
- * @since File available since Release 0.1.2
11
- * @link https://www.SalesWarp.com
12
- *
13
- */
14
- class Saleswarp_Oms_Model_Product_Api extends Mage_Catalog_Model_Product_Api
15
- {
16
- /**
17
- * function to update configurable swatches
18
- */
19
- function enableConfigurableSwatches()
20
- {
21
- $eavAttrTable = Mage::getSingleton('core/resource')->getTableName('eav_attribute');
22
- $catalogAttrTable = Mage::getSingleton('core/resource')->getTableName('catalog_eav_attribute');
23
- $read = Mage::getSingleton('core/resource')->getConnection('core_read');
24
-
25
- $sql = "SELECT `e`.`attribute_id` FROM `" . $eavAttrTable . "` as `e`
26
- JOIN `" . $catalogAttrTable . "` as `c` ON `e`.`attribute_id` = `c`.`attribute_id`
27
- WHERE `e`.`entity_type_id` = '4'
28
- AND `e`.`frontend_input` = 'select'
29
- AND `e`.`is_user_defined` = '1'
30
- AND `c`.`is_configurable` = 1 ";
31
- $result = $read->fetchAll($sql);
32
- if ($result) {
33
- $arr = array();
34
- foreach ($result as $id) {
35
- array_push($arr, $id['attribute_id']);
36
- }
37
- $ids = implode(',', $arr);
38
- if ($ids) {
39
- $configModel = new Mage_Core_Model_Config();
40
- $configModel->saveConfig('configswatches/general/enabled', "1", 'default', 0);
41
- $configModel->saveConfig('configswatches/general/swatch_attributes', $ids, 'default', 0);
42
- }
43
- }
44
- return $ids;
45
- }
46
-
47
- /**
48
- * function to disble configurable swatches
49
- */
50
- function disableConfigurableSwatches()
51
- {
52
- $configModel = new Mage_Core_Model_Config();
53
- $configModel->saveConfig('configswatches/general/enabled', "0", 'default', 0);
54
- $configModel->saveConfig('configswatches/general/swatch_attributes', "", 'default', 0);
55
- }
56
-
57
- /**
58
- * * Capture Offline payment
59
- * */
60
- public function capture_offline($orderId, $invoiceId)
61
- {
62
- $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
63
- if (!$order->canCreditmemo()) {
64
- if ($invoiceId) {
65
- $invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId($invoiceId)->setOrder($order);
66
-
67
- $capture_case = 'offline';
68
- $invoice->setRequestedCaptureCase($capture_case)->setCanVoidFlag(false)->pay();
69
-
70
- $transactionSave = Mage::getModel('core/resource_transaction')->addObject($invoice)->addObject($invoice->getOrder());
71
- $transactionSave->save();
72
- $this->order = Mage::getSingleton('sales/order_api');
73
- $this->order->addComment($order_id, 'processing', 'Captured Offlined successfully', false);
74
- return true;
75
- }
76
- } else {
77
- return false;
78
- }
79
- }
80
-
81
- /**
82
- * * Check invoice exists or not
83
- * * @param = order id
84
- * * return true or false
85
- * */
86
- public function check_invoice_exists($orderId)
87
- {
88
- $invoiceTable = Mage::getSingleton('core/resource')->getTableName('sales_flat_invoice');
89
- $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
90
- $Id = $order->getId();
91
- $sql = "select entity_id from " . $invoiceTable . "
92
- where order_id = '" . (int) $Id . "'";
93
-
94
- $invoice = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchRow($sql);
95
-
96
- if (!empty($invoice)) {
97
- return true;
98
- } else {
99
- return false;
100
- }
101
- }
102
-
103
- /**
104
- * * Create Order invoice *
105
- * **/
106
- public function create_invoice($order_id, $info, $message, $send_email, $include_comment)
107
- {
108
- $this->invoice = Mage::getSingleton('sales/order_invoice_api');
109
- $invoice = $this->invoice->create($order_id, $info, $message, $send_email, $include_comment);
110
- if ($invoice) {
111
- $this->order = Mage::getSingleton('sales/order_api');
112
- $this->order->addComment($order_id, 'processing', 'Invoice Created Successfully', false);
113
- }
114
- return $invoice;
115
- }
116
-
117
- /**
118
- * * function to get total product count ( type wise eg: simple, configured )
119
- *
120
- * * @params $type string Magento Product type eg: simple, configured
121
- * @params $modifiedAfter date product last modified date filter
122
- * * @return int number of products
123
- * */
124
- function get_total_prod_count($type, $modifiedAfter = null)
125
- {
126
- $collection = Mage::getModel('catalog/product')
127
- ->getCollection()
128
- ->addFieldToFilter('type_id', $type);
129
-
130
- if (!empty($modifiedAfter)) {
131
- $collection->addAttributeToFilter('updated_at', array('gteq' => $modifiedAfter));
132
- }
133
- return $collection->getSize();
134
- }
135
-
136
- /**
137
- * * function to get product collection with limit
138
- *
139
- * * @params $type int Magento Product type Id
140
- * * @params $offset int set current page
141
- * * @params $limit int products per page
142
- * * @params $modifiedAfter date product last modified date filter
143
- * * @return array products or bool(false)
144
- * */
145
- function get_product_collection($type, $offset = 1, $limit = 10, $modifiedAfter = null, $createdAfter = null)
146
- {
147
- $data = array();
148
- Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
149
-
150
- $collection = Mage::getModel('catalog/product')
151
- ->getCollection()
152
- ->addAttributeToSelect('*') // select all attributes
153
- ->addFieldToFilter('type_id', $type);
154
-
155
- if (!empty($modifiedAfter)) {
156
- $collection->addAttributeToFilter('updated_at', array('gteq' => $modifiedAfter));
157
- }
158
-
159
- if (!empty($createdAfter)) {
160
- $collection->addAttributeToFilter('updated_at', array('gteq' => $createdAfter));
161
- }
162
-
163
- $collection->setPageSize($limit) // limit number of results returned //
164
- ->setOrder('entity_id', 'DESC')
165
- ->setCurPage($offset);
166
-
167
- foreach ($collection as $product) {
168
- $stocklevel = Mage::getSingleton('cataloginventory/stock_item')
169
- ->loadByProduct($product)->getData();
170
-
171
- $data[] = array_merge(
172
- $product->getData(),
173
- array('prod_url' => $product->getProductUrl()),
174
- array('stock' => $stocklevel)
175
- );
176
- }
177
- return $data;
178
- }
179
-
180
- /**
181
- * * Get attribute name By ID
182
- * * @param attribute id
183
- * * @return attribute name
184
- * */
185
- function get_attr_name_by_id($id)
186
- {
187
- $entityTypeId = Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId();
188
- $attributeSetId = Mage::getModel('eav/entity_attribute_set')->getCollection()
189
- ->setEntityTypeFilter($entityTypeId)
190
- ->addFieldToFilter('attribute_set_id', $id)
191
- ->getFirstItem()
192
- ->getAttributeSetName();
193
- if ($attributeSetId) {
194
- return $attributeSetId;
195
- } else {
196
- return false;
197
- }
198
- }
199
-
200
- /**
201
- * * return allchildren product of magento product id
202
- * * @params Magento Product Id
203
- * * @return product data or bool(false)
204
- * */
205
- function get_child_product($entity_id)
206
- {
207
- $relTable = Mage::getSingleton('core/resource')->getTableName('catalog_product_relation');
208
- $sql = "SELECT child_id FROM `" . $relTable . "`
209
- WHERE parent_id = '" . (int) $entity_id . "'";
210
- $prods = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchAll($sql);
211
- if ($prods) {
212
- return $prods;
213
- } else {
214
- return false;
215
- }
216
- }
217
-
218
- /**
219
- * check product exists in target store using saleswarp_product_id in magento catalog_product_entity_in
220
- *
221
- * use this check_product_exists to query store by warehouse fields that are
222
- * known to not change (sku changes)
223
- *
224
- * @param mixed $attr_id - attribute id, get this after config lookup
225
- * @param mixed $base_product_id
226
- *
227
- * @todo seperate these functions into extension API once we debug issue with override extensions in Magento
228
- */
229
- public function check_product_exists($attr_id, $base_product_id)
230
- {
231
- $productIntTable = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int');
232
- $sql = "select entity_id from " . $productIntTable . "
233
- where attribute_id = '" . (int) $attr_id . "'
234
- and value = '" . (int) $base_product_id . "'";
235
- $prod = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchRow($sql);
236
- if (!empty($prod)) {
237
- $pid = $prod['entity_id'];
238
- unset($prod);
239
- return $pid;
240
- } else {
241
- return false;
242
- }
243
- }
244
-
245
- /**
246
- * light weight inventory update when product is detected out of stock or discontinued and full
247
- * update info (cogs, weight, price) not longer apply
248
- *
249
- * @param mixed $store_prod_id
250
- * @param mixed $store_qty
251
- * @param mixed $discontinued
252
- * @param mixed $status
253
- * @return mixed
254
- * */
255
- function update_inventory($store_prod_id, $store_qty, $discontinued, $attribute_id, $status = 1, $website_id = 1, $stock_id = 1)
256
- {
257
- $resource = Mage::getSingleton('core/resource');
258
- $invStockItemTable = $resource->getTableName('cataloginventory_stock_item');
259
- $invStockStatusTable = $resource->getTableName('cataloginventory_stock_status');
260
- $prodDateTimeTable = $resource->getTableName('catalog_product_entity_datetime');
261
-
262
- $write = $resource->getConnection('core_write');
263
- $read = $resource->getConnection('core_read');
264
-
265
- if ($store_qty <= 0 || $discontinued == 1) {
266
- $status = 0;
267
- } else {
268
- $status = 1;
269
- }
270
-
271
- if (is_null($store_qty)) {
272
- $store_qty = 0;
273
- $status = 0;
274
- }
275
-
276
- $sql = "UPDATE " . $invStockItemTable . "
277
- SET qty = :qty,
278
- is_in_stock = :is_in_stock
279
- WHERE product_id = :product_id ";
280
- $binds = array(
281
- 'qty' => $store_qty,
282
- 'is_in_stock' => $status,
283
- 'product_id' => $store_prod_id,
284
- );
285
- $result = $write->query($sql, $binds);
286
-
287
- $sql = "SELECT * FROM " . $invStockStatusTable . "
288
- WHERE product_id = :product_id
289
- AND website_id = :website_id
290
- AND stock_id = :stock_id ";
291
- $binds = array(
292
- 'product_id' => $store_prod_id,
293
- 'website_id' => $website_id,
294
- 'stock_id' => $stock_id,
295
- );
296
- $chk = $read->fetchRow($sql, $binds);
297
- if (empty($chk)) {
298
- $sql = "INSERT INTO " . $invStockStatusTable . "
299
- SET qty = :qty,
300
- stock_status = :stock_status,
301
- stock_id = :stock_id,
302
- website_id = :website_id,
303
- product_id = :product_id ";
304
-
305
- $binds = array(
306
- 'qty' => $store_qty,
307
- 'stock_status' => $status,
308
- 'stock_id' => $stock_id,
309
- 'website_id' => $website_id,
310
- 'product_id' => $store_prod_id,
311
- );
312
- $result2 = $write->query($sql, $binds);
313
- } else { // do update
314
- $sql = "UPDATE " . $invStockStatusTable . "
315
- SET qty = :qty, stock_status = :stock_status
316
- WHERE product_id = :product_id ";
317
- $binds = array(
318
- 'qty' => $store_qty,
319
- 'stock_status' => $status,
320
- 'product_id' => $store_prod_id,
321
- );
322
- $result2 = $write->query($sql, $binds);
323
- }
324
-
325
- // Update saleswarp_last_inventory_update fields
326
- $sql = "SELECT * FROM " . $prodDateTimeTable . "
327
- WHERE entity_type_id = 4
328
- AND entity_id = $store_prod_id
329
- AND attribute_id = $attribute_id";
330
- $chk = $read->fetchAll($sql);
331
-
332
- if (empty($chk)) { // insert it
333
- $sql = "INSERT INTO " . $prodDateTimeTable . "
334
- SET value = NOW(),
335
- entity_type_id = 4,
336
- store_id = 0,
337
- entity_id = $store_prod_id,
338
- attribute_id = $attribute_id";
339
- $insert_result = $write->query($sql);
340
- } else { // update it
341
- $sql = "UPDATE " . $prodDateTimeTable . "
342
- SET value = NOW()
343
- WHERE entity_type_id = 4
344
- AND entity_id = $store_prod_id
345
- AND attribute_id = $attribute_id";
346
- $update_result = $write->query($sql);
347
- }
348
-
349
- if ($result && $result2) {
350
- return "Saved inventory record";
351
- } else {
352
- return "FAILED save() inventory update";
353
- }
354
- }
355
- }
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This module connects Magento to the SalesWarp Advanced Order Management System.
4
+ *
5
+ * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
+ * @version 0.1.2
7
+ * @author David Potts
8
+ * @license http://www.saleswarp.com/license-saas
9
+ * @category SalesWarp
10
+ * @since File available since Release 0.1.2
11
+ * @link https://www.SalesWarp.com
12
+ *
13
+ */
14
+ class Saleswarp_Oms_Model_Product_Api extends Mage_Catalog_Model_Product_Api
15
+ {
16
+ /**
17
+ * function to update configurable swatches
18
+ */
19
+ function enableConfigurableSwatches()
20
+ {
21
+ $eavAttrTable = Mage::getSingleton('core/resource')->getTableName('eav_attribute');
22
+ $catalogAttrTable = Mage::getSingleton('core/resource')->getTableName('catalog_eav_attribute');
23
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
24
+
25
+ $sql = "SELECT `e`.`attribute_id` FROM `" . $eavAttrTable . "` as `e`
26
+ JOIN `" . $catalogAttrTable . "` as `c` ON `e`.`attribute_id` = `c`.`attribute_id`
27
+ WHERE `e`.`entity_type_id` = '4'
28
+ AND `e`.`frontend_input` = 'select'
29
+ AND `e`.`is_user_defined` = '1'
30
+ AND `c`.`is_configurable` = 1 ";
31
+ $result = $read->fetchAll($sql);
32
+ if ($result) {
33
+ $arr = array();
34
+ foreach ($result as $id) {
35
+ array_push($arr, $id['attribute_id']);
36
+ }
37
+ $ids = implode(',', $arr);
38
+ if ($ids) {
39
+ $configModel = new Mage_Core_Model_Config();
40
+ $configModel->saveConfig('configswatches/general/enabled', "1", 'default', 0);
41
+ $configModel->saveConfig('configswatches/general/swatch_attributes', $ids, 'default', 0);
42
+ }
43
+ }
44
+ return $ids;
45
+ }
46
+
47
+ /**
48
+ * function to disble configurable swatches
49
+ */
50
+ function disableConfigurableSwatches()
51
+ {
52
+ $configModel = new Mage_Core_Model_Config();
53
+ $configModel->saveConfig('configswatches/general/enabled', "0", 'default', 0);
54
+ $configModel->saveConfig('configswatches/general/swatch_attributes', "", 'default', 0);
55
+ }
56
+
57
+ /**
58
+ * * Capture Offline payment
59
+ * */
60
+ public function capture_offline($orderId, $invoiceId)
61
+ {
62
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
63
+ if (!$order->canCreditmemo()) {
64
+ if ($invoiceId) {
65
+ $invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId($invoiceId)->setOrder($order);
66
+
67
+ $capture_case = 'offline';
68
+ $invoice->setRequestedCaptureCase($capture_case)->setCanVoidFlag(false)->pay();
69
+
70
+ $transactionSave = Mage::getModel('core/resource_transaction')->addObject($invoice)->addObject($invoice->getOrder());
71
+ $transactionSave->save();
72
+ $this->order = Mage::getSingleton('sales/order_api');
73
+ $this->order->addComment($orderId, 'processing', 'Captured Offlined successfully', false);
74
+ return true;
75
+ }
76
+ } else {
77
+ return false;
78
+ }
79
+ }
80
+
81
+ /**
82
+ * * Check invoice exists or not
83
+ * * @param = order id
84
+ * * return true or false
85
+ * */
86
+ public function check_invoice_exists($orderId)
87
+ {
88
+ $invoiceTable = Mage::getSingleton('core/resource')->getTableName('sales_flat_invoice');
89
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
90
+ $Id = $order->getId();
91
+ $sql = "select entity_id from " . $invoiceTable . "
92
+ where order_id = '" . (int) $Id . "'";
93
+
94
+ $invoice = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchRow($sql);
95
+
96
+ if (!empty($invoice)) {
97
+ return true;
98
+ } else {
99
+ return false;
100
+ }
101
+ }
102
+
103
+ /**
104
+ * * Create Order invoice *
105
+ * **/
106
+ public function create_invoice($order_id, $info, $message, $send_email, $include_comment)
107
+ {
108
+ $this->invoice = Mage::getSingleton('sales/order_invoice_api');
109
+ $invoice = $this->invoice->create($order_id, $info, $message, $send_email, $include_comment);
110
+ if ($invoice) {
111
+ $this->order = Mage::getSingleton('sales/order_api');
112
+ $this->order->addComment($order_id, 'processing', 'Invoice Created Successfully', false);
113
+ }
114
+ return $invoice;
115
+ }
116
+
117
+ /**
118
+ * * function to get total product count ( type wise eg: simple, configured )
119
+ *
120
+ * * @params $type string Magento Product type eg: simple, configured
121
+ * @params $modifiedAfter date product last modified date filter
122
+ * * @return int number of products
123
+ * */
124
+ function get_total_prod_count($type, $modifiedAfter = null)
125
+ {
126
+ $collection = Mage::getModel('catalog/product')
127
+ ->getCollection()
128
+ ->addFieldToFilter('type_id', $type);
129
+
130
+ if (!empty($modifiedAfter)) {
131
+ $collection->addAttributeToFilter('updated_at', array('gteq' => $modifiedAfter));
132
+ }
133
+ return $collection->getSize();
134
+ }
135
+
136
+ /**
137
+ * * function to get product collection with limit
138
+ *
139
+ * * @params $type int Magento Product type Id
140
+ * * @params $offset int set current page
141
+ * * @params $limit int products per page
142
+ * * @params $modifiedAfter date product last modified date filter
143
+ * * @return array products or bool(false)
144
+ * */
145
+ function get_product_collection($type, $offset = 1, $limit = 10, $modifiedAfter = null, $createdAfter = null)
146
+ {
147
+ $data = array();
148
+ /* Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
149
+
150
+ $collection = Mage::getModel('catalog/product')
151
+ ->getCollection()
152
+ ->addAttributeToSelect('*') // select all attributes
153
+ ->addFieldToFilter('type_id', $type);
154
+ */
155
+ $storeId = Mage::app()->getStore()->getStoreId();
156
+
157
+ $collection = Mage::getResourceModel('catalog/product_collection')
158
+ ->addStoreFilter($storeId)
159
+ ->addAttributeToSelect('*')
160
+ ->addFieldToFilter('type_id', $type);
161
+
162
+ if (!empty($modifiedAfter)) {
163
+ $collection->addAttributeToFilter('updated_at', array('gteq' => $modifiedAfter));
164
+ }
165
+
166
+ if (!empty($createdAfter)) {
167
+ $collection->addAttributeToFilter('updated_at', array('gteq' => $createdAfter));
168
+ }
169
+
170
+ $collection->setPageSize($limit) // limit number of results returned //
171
+ ->setOrder('entity_id', 'DESC')
172
+ ->setCurPage($offset);
173
+
174
+ foreach ($collection as $product) {
175
+ $stocklevel = Mage::getSingleton('cataloginventory/stock_item')
176
+ ->loadByProduct($product)->getData();
177
+
178
+ $data[] = array_merge(
179
+ $product->getData(),
180
+ array('prod_url' => $product->getProductUrl()),
181
+ array('stock' => $stocklevel)
182
+ );
183
+ }
184
+ return $data;
185
+ }
186
+
187
+ /**
188
+ * * Get attribute name By ID
189
+ * * @param attribute id
190
+ * * @return attribute name
191
+ * */
192
+ function get_attr_name_by_id($id)
193
+ {
194
+ $entityTypeId = Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId();
195
+ $attributeSetId = Mage::getModel('eav/entity_attribute_set')->getCollection()
196
+ ->setEntityTypeFilter($entityTypeId)
197
+ ->addFieldToFilter('attribute_set_id', $id)
198
+ ->getFirstItem()
199
+ ->getAttributeSetName();
200
+ if ($attributeSetId) {
201
+ return $attributeSetId;
202
+ } else {
203
+ return false;
204
+ }
205
+ }
206
+
207
+ /**
208
+ * * return allchildren product of magento product id
209
+ * * @params Magento Product Id
210
+ * * @return product data or bool(false)
211
+ * */
212
+ function get_child_product($entity_id)
213
+ {
214
+ $relTable = Mage::getSingleton('core/resource')->getTableName('catalog_product_relation');
215
+ $sql = "SELECT child_id FROM `" . $relTable . "`
216
+ WHERE parent_id = '" . (int) $entity_id . "'";
217
+ $prods = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchAll($sql);
218
+ if ($prods) {
219
+ return $prods;
220
+ } else {
221
+ return false;
222
+ }
223
+ }
224
+
225
+ /**
226
+ * check product exists in target store using saleswarp_product_id in magento catalog_product_entity_in
227
+ *
228
+ * use this check_product_exists to query store by warehouse fields that are
229
+ * known to not change (sku changes)
230
+ *
231
+ * @param mixed $attr_id - attribute id, get this after config lookup
232
+ * @param mixed $base_product_id
233
+ *
234
+ * @todo seperate these functions into extension API once we debug issue with override extensions in Magento
235
+ */
236
+ public function check_product_exists($attr_id, $base_product_id)
237
+ {
238
+ $productIntTable = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int');
239
+ $sql = "select entity_id from " . $productIntTable . "
240
+ where attribute_id = '" . (int) $attr_id . "'
241
+ and value = '" . (int) $base_product_id . "'";
242
+ $prod = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchRow($sql);
243
+ if (!empty($prod)) {
244
+ $pid = $prod['entity_id'];
245
+ unset($prod);
246
+ return $pid;
247
+ } else {
248
+ return false;
249
+ }
250
+ }
251
+
252
+ /**
253
+ * light weight inventory update when product is detected out of stock or discontinued and full
254
+ * update info (cogs, weight, price) not longer apply
255
+ *
256
+ * @param mixed $store_prod_id
257
+ * @param mixed $store_qty
258
+ * @param mixed $discontinued
259
+ * @param mixed $status
260
+ * @return mixed
261
+ * */
262
+ function update_inventory($store_prod_id, $store_qty, $discontinued, $attribute_id, $status = 1, $website_id = 1, $stock_id = 1)
263
+ {
264
+ $resource = Mage::getSingleton('core/resource');
265
+ $invStockItemTable = $resource->getTableName('cataloginventory_stock_item');
266
+ $invStockStatusTable = $resource->getTableName('cataloginventory_stock_status');
267
+ $prodDateTimeTable = $resource->getTableName('catalog_product_entity_datetime');
268
+
269
+ $write = $resource->getConnection('core_write');
270
+ $read = $resource->getConnection('core_read');
271
+
272
+ if ($store_qty <= 0 || $discontinued == 1) {
273
+ $status = 0;
274
+ } else {
275
+ $status = 1;
276
+ }
277
+
278
+ if (is_null($store_qty)) {
279
+ $store_qty = 0;
280
+ $status = 0;
281
+ }
282
+
283
+ $sql = "UPDATE " . $invStockItemTable . "
284
+ SET qty = :qty,
285
+ is_in_stock = :is_in_stock
286
+ WHERE product_id = :product_id ";
287
+ $binds = array(
288
+ 'qty' => $store_qty,
289
+ 'is_in_stock' => $status,
290
+ 'product_id' => $store_prod_id,
291
+ );
292
+ $result = $write->query($sql, $binds);
293
+
294
+ $sql = "SELECT * FROM " . $invStockStatusTable . "
295
+ WHERE product_id = :product_id
296
+ AND website_id = :website_id
297
+ AND stock_id = :stock_id ";
298
+ $binds = array(
299
+ 'product_id' => $store_prod_id,
300
+ 'website_id' => $website_id,
301
+ 'stock_id' => $stock_id,
302
+ );
303
+ $chk = $read->fetchRow($sql, $binds);
304
+ if (empty($chk)) {
305
+ $sql = "INSERT INTO " . $invStockStatusTable . "
306
+ SET qty = :qty,
307
+ stock_status = :stock_status,
308
+ stock_id = :stock_id,
309
+ website_id = :website_id,
310
+ product_id = :product_id ";
311
+
312
+ $binds = array(
313
+ 'qty' => $store_qty,
314
+ 'stock_status' => $status,
315
+ 'stock_id' => $stock_id,
316
+ 'website_id' => $website_id,
317
+ 'product_id' => $store_prod_id,
318
+ );
319
+ $result2 = $write->query($sql, $binds);
320
+ } else { // do update
321
+ $sql = "UPDATE " . $invStockStatusTable . "
322
+ SET qty = :qty, stock_status = :stock_status
323
+ WHERE product_id = :product_id ";
324
+ $binds = array(
325
+ 'qty' => $store_qty,
326
+ 'stock_status' => $status,
327
+ 'product_id' => $store_prod_id,
328
+ );
329
+ $result2 = $write->query($sql, $binds);
330
+ }
331
+
332
+ // Update saleswarp_last_inventory_update fields
333
+ $sql = "SELECT * FROM " . $prodDateTimeTable . "
334
+ WHERE entity_type_id = 4
335
+ AND entity_id = $store_prod_id
336
+ AND attribute_id = $attribute_id";
337
+ $chk = $read->fetchAll($sql);
338
+
339
+ if (empty($chk)) { // insert it
340
+ $sql = "INSERT INTO " . $prodDateTimeTable . "
341
+ SET value = NOW(),
342
+ entity_type_id = 4,
343
+ store_id = 0,
344
+ entity_id = $store_prod_id,
345
+ attribute_id = $attribute_id";
346
+ $insert_result = $write->query($sql);
347
+ } else { // update it
348
+ $sql = "UPDATE " . $prodDateTimeTable . "
349
+ SET value = NOW()
350
+ WHERE entity_type_id = 4
351
+ AND entity_id = $store_prod_id
352
+ AND attribute_id = $attribute_id";
353
+ $update_result = $write->query($sql);
354
+ }
355
+
356
+ if ($result && $result2) {
357
+ return "Saved inventory record";
358
+ } else {
359
+ return "FAILED save() inventory update";
360
+ }
361
+ }
362
+ }
app/code/local/Saleswarp/Oms/Model/Product/Attribute/Api.php CHANGED
@@ -1,5 +1,5 @@
1
- <?php
2
- class Saleswarp_Oms_Model_Product_Attribute_Api extends Mage_Catalog_Model_Product_Attribute_Api
3
- {
4
-
5
- }
1
+ <?php
2
+ class Saleswarp_Oms_Model_Product_Attribute_Api extends Mage_Catalog_Model_Product_Attribute_Api
3
+ {
4
+
5
+ }
app/code/local/Saleswarp/Oms/Model/Product/Attribute/Media/Api.php CHANGED
@@ -1,5 +1,5 @@
1
- <?php
2
- class Saleswarp_Oms_Model_Product_Attribute_Media_Api extends Mage_Catalog_Model_Product_Attribute_Media_Api
3
- {
4
-
5
  }
1
+ <?php
2
+ class Saleswarp_Oms_Model_Product_Attribute_Media_Api extends Mage_Catalog_Model_Product_Attribute_Media_Api
3
+ {
4
+
5
  }
app/code/local/Saleswarp/Oms/Model/Saleswarp.php CHANGED
@@ -1,53 +1,53 @@
1
- <?php
2
- /**
3
- * This module connects Magento to the SalesWarp Advanced Order Management System.
4
- *
5
- * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
- * @version 0.1.2
7
- * @author David Potts
8
- * @license http://www.saleswarp.com/license-saas
9
- * @category SalesWarp
10
- * @since File available since Release 0.1.2
11
- * @link https://www.SalesWarp.com
12
- *
13
- */
14
- class Saleswarp_Oms_Model_Saleswarp extends Mage_Payment_Model_Method_Abstract
15
- {
16
- protected $_code = 'saleswarp';
17
- protected $_formBlockType = 'oms/form_saleswarp';
18
- protected $_infoBlockType = 'oms/info_saleswarp';
19
- protected $_canUseInternal = true;
20
- protected $_canUseCheckout = false;
21
-
22
- public function assignData($data)
23
- {
24
- if (!($data instanceof Varien_Object)) {
25
- $data = new Varien_Object($data);
26
- }
27
- $info = $this->getInfoInstance();
28
- $info->setTransctionNo($data->getTransctionNo())
29
- ->setPaymentMethod($data->getPaymentMethod());
30
- return $this;
31
- }
32
-
33
- public function validate()
34
- {
35
- parent::validate();
36
-
37
- $info = $this->getInfoInstance();
38
-
39
- $no = $info->getTransctionNo();
40
- $method = $info->getPaymentMethod();
41
- if(empty($no) || empty($method)){
42
- $errorCode = 'invalid_data';
43
- $errorMsg = $this->_getHelper()->__('Transaction No and Payment Method are required fields');
44
- }
45
-
46
- if($errorMsg){
47
- Mage::throwException($errorMsg);
48
- }
49
-
50
- return $this;
51
- }
52
- }
53
- ?>
1
+ <?php
2
+ /**
3
+ * This module connects Magento to the SalesWarp Advanced Order Management System.
4
+ *
5
+ * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
+ * @version 0.1.2
7
+ * @author David Potts
8
+ * @license http://www.saleswarp.com/license-saas
9
+ * @category SalesWarp
10
+ * @since File available since Release 0.1.2
11
+ * @link https://www.SalesWarp.com
12
+ *
13
+ */
14
+ class Saleswarp_Oms_Model_Saleswarp extends Mage_Payment_Model_Method_Abstract
15
+ {
16
+ protected $_code = 'saleswarp';
17
+ protected $_formBlockType = 'oms/form_saleswarp';
18
+ protected $_infoBlockType = 'oms/info_saleswarp';
19
+ protected $_canUseInternal = true;
20
+ protected $_canUseCheckout = false;
21
+
22
+ public function assignData($data)
23
+ {
24
+ if (!($data instanceof Varien_Object)) {
25
+ $data = new Varien_Object($data);
26
+ }
27
+ $info = $this->getInfoInstance();
28
+ $info->setTransctionNo($data->getTransctionNo())
29
+ ->setPaymentMethod($data->getPaymentMethod());
30
+ return $this;
31
+ }
32
+
33
+ public function validate()
34
+ {
35
+ parent::validate();
36
+
37
+ $info = $this->getInfoInstance();
38
+
39
+ $no = $info->getTransctionNo();
40
+ $method = $info->getPaymentMethod();
41
+ if(empty($no) || empty($method)){
42
+ $errorCode = 'invalid_data';
43
+ $errorMsg = $this->_getHelper()->__('Transaction No and Payment Method are required fields');
44
+ }
45
+
46
+ if($errorMsg){
47
+ Mage::throwException($errorMsg);
48
+ }
49
+
50
+ return $this;
51
+ }
52
+ }
53
+ ?>
app/code/local/Saleswarp/Oms/controllers/Adminhtml/GetkeyController.php CHANGED
@@ -1,64 +1,64 @@
1
- <?php
2
- /**
3
- * This module connects Magento to the SalesWarp Advanced Order Management System.
4
- *
5
- * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
- * @version 0.1.2
7
- * @author David Potts
8
- * @license http://www.saleswarp.com/license-saas
9
- * @category SalesWarp
10
- * @since File available since Release 0.1.2
11
- * @link https://www.SalesWarp.com
12
- *
13
- */
14
- class Saleswarp_Oms_Adminhtml_GetkeyController extends Mage_Adminhtml_Controller_Action
15
- {
16
- public function indexAction()
17
- {
18
- $return = array();
19
- $value = $this->makeKeyRequest();
20
- if($value) {
21
- $key = new Mage_Core_Model_Config();
22
- $key->saveConfig('oms/registration/key', $value);
23
-
24
- $return['success'] = 1;
25
- $return['key'] = $value;
26
- } else {
27
- $return['success'] = 0;
28
- }
29
- $return = Mage::helper('core')->jsonEncode($return);
30
- $this->getResponse()->setHeader('Content-type', 'application/json');
31
- $this->getResponse()->setBody($return);
32
- }
33
-
34
- public function makeKeyRequest() {
35
-
36
- $data = array();
37
- $data['BaseUrl'] = Mage::getBaseUrl();
38
-
39
- $admin = Mage::getSingleton('admin/session')->getUser()->getData();
40
- $data['admin']['username'] = $admin['username'];
41
- $data['admin']['email'] = $admin['email'];
42
-
43
- $url = Mage::getModel('core/variable')->loadByCode('saleswarp_api_url')->getValue('plain');
44
-
45
- $dataString = http_build_query($data);
46
- $ch = curl_init($url);
47
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
48
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
49
- curl_setopt($ch, CURLOPT_TIMEOUT, 6000);
50
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
51
- curl_setopt($ch, CURLOPT_POST, true);
52
- curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
53
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
54
-
55
- $return = curl_exec($ch);
56
-
57
- $info = curl_getinfo($ch);
58
- if($info['http_code'] == '200') {
59
- return $return;
60
- } else {
61
- return false;
62
- }
63
- }
64
  }
1
+ <?php
2
+ /**
3
+ * This module connects Magento to the SalesWarp Advanced Order Management System.
4
+ *
5
+ * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
+ * @version 0.1.2
7
+ * @author David Potts
8
+ * @license http://www.saleswarp.com/license-saas
9
+ * @category SalesWarp
10
+ * @since File available since Release 0.1.2
11
+ * @link https://www.SalesWarp.com
12
+ *
13
+ */
14
+ class Saleswarp_Oms_Adminhtml_GetkeyController extends Mage_Adminhtml_Controller_Action
15
+ {
16
+ public function indexAction()
17
+ {
18
+ $return = array();
19
+ $value = $this->makeKeyRequest();
20
+ if($value) {
21
+ $key = new Mage_Core_Model_Config();
22
+ $key->saveConfig('oms/registration/key', $value);
23
+
24
+ $return['success'] = 1;
25
+ $return['key'] = $value;
26
+ } else {
27
+ $return['success'] = 0;
28
+ }
29
+ $return = Mage::helper('core')->jsonEncode($return);
30
+ $this->getResponse()->setHeader('Content-type', 'application/json');
31
+ $this->getResponse()->setBody($return);
32
+ }
33
+
34
+ public function makeKeyRequest() {
35
+
36
+ $data = array();
37
+ $data['BaseUrl'] = Mage::getBaseUrl();
38
+
39
+ $admin = Mage::getSingleton('admin/session')->getUser()->getData();
40
+ $data['admin']['username'] = $admin['username'];
41
+ $data['admin']['email'] = $admin['email'];
42
+
43
+ $url = Mage::getModel('core/variable')->loadByCode('saleswarp_api_url')->getValue('plain');
44
+
45
+ $dataString = http_build_query($data);
46
+ $ch = curl_init($url);
47
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
48
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
49
+ curl_setopt($ch, CURLOPT_TIMEOUT, 6000);
50
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
51
+ curl_setopt($ch, CURLOPT_POST, true);
52
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
53
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
54
+
55
+ $return = curl_exec($ch);
56
+
57
+ $info = curl_getinfo($ch);
58
+ if($info['http_code'] == '200') {
59
+ return $return;
60
+ } else {
61
+ return false;
62
+ }
63
+ }
64
  }
app/code/local/Saleswarp/Oms/controllers/FastapiController.php CHANGED
@@ -1,137 +1,137 @@
1
- <?php
2
- /**
3
- * This module connects Magento to the SalesWarp Advanced Order Management System.
4
- *
5
- * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
- * @version 0.1.2
7
- * @author David Potts
8
- * @license http://www.saleswarp.com/license-saas
9
- * @category SalesWarp
10
- * @since File available since Release 0.1.2
11
- * @link https://www.SalesWarp.com
12
- *
13
- */
14
- class Saleswarp_Oms_FastapiController extends Mage_Core_Controller_Front_Action {
15
-
16
- public $authError = '';
17
-
18
- /**
19
- * * Receive API call and process API
20
- * *
21
- * * @param json encoded data
22
- * * @return json encode data
23
- * */
24
- public function IndexAction()
25
- {
26
- $response = array();
27
- $data = json_decode(@file_get_contents('php://input'), true);
28
-
29
- if (empty($data)) {
30
- $this->_redirect('/');
31
- return;
32
- }
33
-
34
- if (isset($data['hash']['key'])) {
35
- // authenticate
36
- if(!$this->ApiAuthentication($data['hash']['key'])) {
37
- $response['error_msg'] = $this->authError;
38
- $response['error_code'] = '2';
39
- echo json_encode($response);
40
- exit;
41
- }
42
- // call method api
43
- $response['data'] = $this->callFastApi($data);
44
- if(!$response['data']) {
45
- $response['error_msg'] = 'Invalid data';
46
- $response['error_code'] = '3';
47
- } else {
48
- $response['error_msg'] = '';
49
- $response['error_code'] = '0';
50
- }
51
- } else {
52
- $response['error_msg'] = 'Invalid data';
53
- $response['error_code'] = '1';
54
- }
55
- echo json_encode($response);
56
- exit;
57
- }
58
-
59
- /**
60
- * * Load fast api and call methods
61
- * *
62
- * * @param array of data
63
- * * @return array of data
64
- * */
65
- public function callFastApi($data = array())
66
- {
67
- if (empty($data)) {
68
- return false;
69
- } else {
70
- if (isset($data['api']) && strstr($data['api'], 'saleswarp_fastapi') !== false) {
71
- // load api
72
- $className = $data['api'];
73
-
74
- switch ($className) {
75
- case 'saleswarp_fastapi_model_order_api':
76
- $className = 'oms/order_api';
77
- break;
78
- case 'saleswarp_fastapi_model_product_api':
79
- $className = 'oms/product_api';
80
- break;
81
- case 'saleswarp_fastapi_model_category_api':
82
- $className = 'oms/category_api';
83
- break;
84
- case 'saleswarp_fastapi_model_config_api':
85
- $className = 'oms/config_api';
86
- break;
87
- case 'saleswarp_fastapi_model_product_attribute_media_api':
88
- $className = 'oms/product_attribute_media_api';
89
- break;
90
- case 'saleswarp_fastapi_model_customer_api':
91
- $className = 'oms/customer_api';
92
- break;
93
- }
94
-
95
- try {
96
- $mage = Mage::getModel($className);
97
- if(!method_exists($mage, $data['methodName'])) {
98
- throw new Exception('Class or Function does not exists');
99
- } else {
100
- $fastData = call_user_func_array(array($mage, $data['methodName']), $data['methodParams']);
101
- }
102
- } catch(Exception $e) {
103
- return [$e->getMessage()];
104
- }
105
-
106
- return $fastData;
107
- } else {
108
- return false;
109
- }
110
- }
111
- }
112
-
113
- /**
114
- * * Authentication API request
115
- * *
116
- * * @params string hash key
117
- * * @return bool(trur or false)
118
- * */
119
- public function ApiAuthentication($hash = null)
120
- {
121
- if(empty($hash)) {
122
- $this->authError = 'No hash key supplied';
123
- return false;
124
- } else {
125
- $mageHash = Mage::getStoreConfig('oms/registration/key');
126
-
127
- // get user ip address
128
- $remoteIP = Mage::helper('core/http')->getRemoteAddr(false);
129
- if (!empty($mageHash) && $hash == $mageHash) {
130
- return true;
131
- } else {
132
- $this->authError = 'Incorrect Hash key';
133
- return false;
134
- }
135
- }
136
- }
137
  }
1
+ <?php
2
+ /**
3
+ * This module connects Magento to the SalesWarp Advanced Order Management System.
4
+ *
5
+ * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
+ * @version 0.1.2
7
+ * @author David Potts
8
+ * @license http://www.saleswarp.com/license-saas
9
+ * @category SalesWarp
10
+ * @since File available since Release 0.1.2
11
+ * @link https://www.SalesWarp.com
12
+ *
13
+ */
14
+ class Saleswarp_Oms_FastapiController extends Mage_Core_Controller_Front_Action {
15
+
16
+ public $authError = '';
17
+
18
+ /**
19
+ * * Receive API call and process API
20
+ * *
21
+ * * @param json encoded data
22
+ * * @return json encode data
23
+ * */
24
+ public function IndexAction()
25
+ {
26
+ $response = array();
27
+ $data = json_decode(@file_get_contents('php://input'), true);
28
+
29
+ if (empty($data)) {
30
+ $this->_redirect('/');
31
+ return;
32
+ }
33
+
34
+ if (isset($data['hash']['key'])) {
35
+ // authenticate
36
+ if(!$this->ApiAuthentication($data['hash']['key'])) {
37
+ $response['error_msg'] = $this->authError;
38
+ $response['error_code'] = '2';
39
+ echo json_encode($response);
40
+ exit;
41
+ }
42
+ // call method api
43
+ $response['data'] = $this->callFastApi($data);
44
+ if(!$response['data']) {
45
+ $response['error_msg'] = 'Invalid data';
46
+ $response['error_code'] = '3';
47
+ } else {
48
+ $response['error_msg'] = '';
49
+ $response['error_code'] = '0';
50
+ }
51
+ } else {
52
+ $response['error_msg'] = 'Invalid data';
53
+ $response['error_code'] = '1';
54
+ }
55
+ echo json_encode($response);
56
+ exit;
57
+ }
58
+
59
+ /**
60
+ * * Load fast api and call methods
61
+ * *
62
+ * * @param array of data
63
+ * * @return array of data
64
+ * */
65
+ public function callFastApi($data = array())
66
+ {
67
+ if (empty($data)) {
68
+ return false;
69
+ } else {
70
+ if (isset($data['api']) && strstr($data['api'], 'saleswarp_fastapi') !== false) {
71
+ // load api
72
+ $className = $data['api'];
73
+
74
+ switch ($className) {
75
+ case 'saleswarp_fastapi_model_order_api':
76
+ $className = 'oms/order_api';
77
+ break;
78
+ case 'saleswarp_fastapi_model_product_api':
79
+ $className = 'oms/product_api';
80
+ break;
81
+ case 'saleswarp_fastapi_model_category_api':
82
+ $className = 'oms/category_api';
83
+ break;
84
+ case 'saleswarp_fastapi_model_config_api':
85
+ $className = 'oms/config_api';
86
+ break;
87
+ case 'saleswarp_fastapi_model_product_attribute_media_api':
88
+ $className = 'oms/product_attribute_media_api';
89
+ break;
90
+ case 'saleswarp_fastapi_model_customer_api':
91
+ $className = 'oms/customer_api';
92
+ break;
93
+ }
94
+
95
+ try {
96
+ $mage = Mage::getModel($className);
97
+ if(!method_exists($mage, $data['methodName'])) {
98
+ throw new Exception('Class or Function does not exists');
99
+ } else {
100
+ $fastData = call_user_func_array(array($mage, $data['methodName']), $data['methodParams']);
101
+ }
102
+ } catch(Exception $e) {
103
+ return [$e->getMessage()];
104
+ }
105
+
106
+ return $fastData;
107
+ } else {
108
+ return false;
109
+ }
110
+ }
111
+ }
112
+
113
+ /**
114
+ * * Authentication API request
115
+ * *
116
+ * * @params string hash key
117
+ * * @return bool(trur or false)
118
+ * */
119
+ public function ApiAuthentication($hash = null)
120
+ {
121
+ if(empty($hash)) {
122
+ $this->authError = 'No hash key supplied';
123
+ return false;
124
+ } else {
125
+ $mageHash = Mage::getStoreConfig('oms/registration/key');
126
+
127
+ // get user ip address
128
+ $remoteIP = Mage::helper('core/http')->getRemoteAddr(false);
129
+ if (!empty($mageHash) && $hash == $mageHash) {
130
+ return true;
131
+ } else {
132
+ $this->authError = 'Incorrect Hash key';
133
+ return false;
134
+ }
135
+ }
136
+ }
137
  }
app/code/local/Saleswarp/Oms/etc/adminhtml.xml CHANGED
@@ -1,23 +1,23 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <acl>
4
- <resources>
5
- <admin>
6
- <children>
7
- <system>
8
- <children>
9
- <config>
10
- <children>
11
- <oms translate="title" module="oms">
12
- <title>Saleswarp Oms Section</title>
13
- <sort_order>0</sort_order>
14
- </oms>
15
- </children>
16
- </config>
17
- </children>
18
- </system>
19
- </children>
20
- </admin>
21
- </resources>
22
- </acl>
23
  </config>
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <acl>
4
+ <resources>
5
+ <admin>
6
+ <children>
7
+ <system>
8
+ <children>
9
+ <config>
10
+ <children>
11
+ <oms translate="title" module="oms">
12
+ <title>Saleswarp Oms Section</title>
13
+ <sort_order>0</sort_order>
14
+ </oms>
15
+ </children>
16
+ </config>
17
+ </children>
18
+ </system>
19
+ </children>
20
+ </admin>
21
+ </resources>
22
+ </acl>
23
  </config>
app/code/local/Saleswarp/Oms/etc/config.xml CHANGED
@@ -1,93 +1,93 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <Saleswarp_Oms>
5
- <version>0.1.2</version>
6
- </Saleswarp_Oms>
7
- </modules>
8
- <frontend>
9
- <routers>
10
- <oms>
11
- <use>standard</use>
12
- <args>
13
- <module>Saleswarp_Oms</module>
14
- <frontName>customapi</frontName>
15
- </args>
16
- </oms>
17
- </routers>
18
- </frontend>
19
- <global>
20
- <helpers>
21
- <oms>
22
- <class>Saleswarp_Oms_Helper</class>
23
- </oms>
24
- </helpers>
25
- <blocks>
26
- <oms>
27
- <class>Saleswarp_Oms_Block</class>
28
- </oms>
29
- </blocks>
30
- <resources>
31
- <oms_setup>
32
- <setup>
33
- <module>Saleswarp_Oms</module>
34
- </setup>
35
- <connection>
36
- <use>core_setup</use>
37
- </connection>
38
- </oms_setup>
39
- <oms_write>
40
- <connection>
41
- <use>core_write</use>
42
- </connection>
43
- </oms_write>
44
- <oms_read>
45
- <connection>
46
- <use>core_read</use>
47
- </connection>
48
- </oms_read>
49
- </resources>
50
- <models>
51
- <oms>
52
- <class>Saleswarp_Oms_Model</class>
53
- </oms>
54
- <catalog>
55
- <rewrite>
56
- <product_api>Saleswarp_Oms_Model_Catalog_Product_Api</product_api>
57
- </rewrite>
58
- </catalog>
59
- </models>
60
- <fieldsets>
61
- <sales_convert_quote_payment>
62
- <transction_no>
63
- <to_order_payment>*</to_order_payment>
64
- </transction_no>
65
- <payment_method>
66
- <to_order_payment>*</to_order_payment>
67
- </payment_method>
68
- </sales_convert_quote_payment>
69
- </fieldsets>
70
- </global>
71
- <default>
72
- <payment>
73
- <saleswarp>
74
- <active>1</active>
75
- <model>oms/saleswarp</model>
76
- <order_status>processing</order_status>
77
- <title>Saleswarp Payment</title>
78
- <message>Used for Orders created in Saleswarp.</message>
79
- </saleswarp>
80
- </payment>
81
- </default>
82
- <admin>
83
- <routers>
84
- <oms>
85
- <use>admin</use>
86
- <args>
87
- <module>Saleswarp_Oms</module>
88
- <frontName>admin_oms</frontName>
89
- </args>
90
- </oms>
91
- </routers>
92
- </admin>
93
  </config>
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Saleswarp_Oms>
5
+ <version>0.1.2</version>
6
+ </Saleswarp_Oms>
7
+ </modules>
8
+ <frontend>
9
+ <routers>
10
+ <oms>
11
+ <use>standard</use>
12
+ <args>
13
+ <module>Saleswarp_Oms</module>
14
+ <frontName>customapi</frontName>
15
+ </args>
16
+ </oms>
17
+ </routers>
18
+ </frontend>
19
+ <global>
20
+ <helpers>
21
+ <oms>
22
+ <class>Saleswarp_Oms_Helper</class>
23
+ </oms>
24
+ </helpers>
25
+ <blocks>
26
+ <oms>
27
+ <class>Saleswarp_Oms_Block</class>
28
+ </oms>
29
+ </blocks>
30
+ <resources>
31
+ <oms_setup>
32
+ <setup>
33
+ <module>Saleswarp_Oms</module>
34
+ </setup>
35
+ <connection>
36
+ <use>core_setup</use>
37
+ </connection>
38
+ </oms_setup>
39
+ <oms_write>
40
+ <connection>
41
+ <use>core_write</use>
42
+ </connection>
43
+ </oms_write>
44
+ <oms_read>
45
+ <connection>
46
+ <use>core_read</use>
47
+ </connection>
48
+ </oms_read>
49
+ </resources>
50
+ <models>
51
+ <oms>
52
+ <class>Saleswarp_Oms_Model</class>
53
+ </oms>
54
+ <catalog>
55
+ <rewrite>
56
+ <product_api>Saleswarp_Oms_Model_Catalog_Product_Api</product_api>
57
+ </rewrite>
58
+ </catalog>
59
+ </models>
60
+ <fieldsets>
61
+ <sales_convert_quote_payment>
62
+ <transction_no>
63
+ <to_order_payment>*</to_order_payment>
64
+ </transction_no>
65
+ <payment_method>
66
+ <to_order_payment>*</to_order_payment>
67
+ </payment_method>
68
+ </sales_convert_quote_payment>
69
+ </fieldsets>
70
+ </global>
71
+ <default>
72
+ <payment>
73
+ <saleswarp>
74
+ <active>1</active>
75
+ <model>oms/saleswarp</model>
76
+ <order_status>processing</order_status>
77
+ <title>Saleswarp Payment</title>
78
+ <message>Used for Orders created in Saleswarp.</message>
79
+ </saleswarp>
80
+ </payment>
81
+ </default>
82
+ <admin>
83
+ <routers>
84
+ <oms>
85
+ <use>admin</use>
86
+ <args>
87
+ <module>Saleswarp_Oms</module>
88
+ <frontName>admin_oms</frontName>
89
+ </args>
90
+ </oms>
91
+ </routers>
92
+ </admin>
93
  </config>
app/code/local/Saleswarp/Oms/etc/system.xml CHANGED
@@ -1,97 +1,97 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <config>
3
- <tabs>
4
- <saleswarp translate="label" module="oms">
5
- <label>Saleswarp</label>
6
- <sort_order>10</sort_order>
7
- </saleswarp>
8
- </tabs>
9
- <sections>
10
- <oms translate="label" module="oms">
11
- <label>Settings</label>
12
- <tab>saleswarp</tab>
13
- <frontend_type>text</frontend_type>
14
- <sort_order>0</sort_order>
15
- <show_in_default>1</show_in_default>
16
- <show_in_website>1</show_in_website>
17
- <show_in_store>1</show_in_store>
18
- <groups>
19
- <registration translate="label">
20
- <label>Generate Unique SalesWarp Registration Key</label>
21
- <frontend_type>text</frontend_type>
22
- <sort_order>10</sort_order>
23
- <show_in_default>1</show_in_default>
24
- <show_in_website>0</show_in_website>
25
- <show_in_store>0</show_in_store>
26
- <fields>
27
- <key translate="label">
28
- <label>SalesWarp Registration Unique Key</label>
29
- <frontend_type>text</frontend_type>
30
- <frontend_model>Saleswarp_Oms_Block_Adminhtml_System_Config_Form_Key</frontend_model>
31
- <sort_order>10</sort_order>
32
- <show_in_default>1</show_in_default>
33
- <show_in_website>0</show_in_website>
34
- <show_in_store>0</show_in_store>
35
- </key>
36
- <check translate="label">
37
-                 <label> </label>
38
-                 <frontend_type>button</frontend_type>
39
-                 <frontend_model>Saleswarp_Oms_Block_Adminhtml_System_Config_Form_Button</frontend_model>
40
-                 <sort_order>20</sort_order>
41
-                 <show_in_default>1</show_in_default>
42
-                 <show_in_website>0</show_in_website>
43
-                 <show_in_store>0</show_in_store>
44
-             </check>
45
- </fields>
46
- </registration>
47
- </groups>
48
- </oms>
49
- <payment>
50
- <groups>
51
- <saleswarp translate="label">
52
- <label>Saleswarp Payment Module</label>
53
- <sort_order>670</sort_order>
54
- <show_in_default>1</show_in_default>
55
- <show_in_website>1</show_in_website>
56
- <show_in_store>0</show_in_store>
57
- <fields>
58
- <active translate="label">
59
- <label>Enabled</label>
60
- <frontend_type>select</frontend_type>
61
- <source_model>adminhtml/system_config_source_yesno</source_model>
62
- <sort_order>1</sort_order>
63
- <show_in_default>1</show_in_default>
64
- <show_in_website>1</show_in_website>
65
- <show_in_store>0</show_in_store>
66
- </active>
67
- <order_status translate="label">
68
- <label>New order status</label>
69
- <frontend_type>select</frontend_type>
70
- <source_model>adminhtml/system_config_source_order_status_processing</source_model>
71
- <sort_order>2</sort_order>
72
- <show_in_default>1</show_in_default>
73
- <show_in_website>1</show_in_website>
74
- <show_in_store>0</show_in_store>
75
- </order_status>
76
- <title translate="label">
77
- <label>Title</label>
78
- <frontend_type>text</frontend_type>
79
- <sort_order>3</sort_order>
80
- <show_in_default>1</show_in_default>
81
- <show_in_website>1</show_in_website>
82
- <show_in_store>0</show_in_store>
83
- </title>
84
- <message translate="label">
85
- <label>Displayed Message</label>
86
- <frontend_type>textarea</frontend_type>
87
- <sort_order>4</sort_order>
88
- <show_in_default>1</show_in_default>
89
- <show_in_website>1</show_in_website>
90
- <show_in_store>1</show_in_store>
91
- </message>
92
- </fields>
93
- </saleswarp>
94
- </groups>
95
- </payment>
96
- </sections>
97
  </config>
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <tabs>
4
+ <saleswarp translate="label" module="oms">
5
+ <label>Saleswarp</label>
6
+ <sort_order>10</sort_order>
7
+ </saleswarp>
8
+ </tabs>
9
+ <sections>
10
+ <oms translate="label" module="oms">
11
+ <label>Settings</label>
12
+ <tab>saleswarp</tab>
13
+ <frontend_type>text</frontend_type>
14
+ <sort_order>0</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>1</show_in_website>
17
+ <show_in_store>1</show_in_store>
18
+ <groups>
19
+ <registration translate="label">
20
+ <label>Generate Unique SalesWarp Registration Key</label>
21
+ <frontend_type>text</frontend_type>
22
+ <sort_order>10</sort_order>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>0</show_in_website>
25
+ <show_in_store>0</show_in_store>
26
+ <fields>
27
+ <key translate="label">
28
+ <label>SalesWarp Registration Unique Key</label>
29
+ <frontend_type>text</frontend_type>
30
+ <frontend_model>Saleswarp_Oms_Block_Adminhtml_System_Config_Form_Key</frontend_model>
31
+ <sort_order>10</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>0</show_in_website>
34
+ <show_in_store>0</show_in_store>
35
+ </key>
36
+ <check translate="label">
37
+                 <label> </label>
38
+                 <frontend_type>button</frontend_type>
39
+                 <frontend_model>Saleswarp_Oms_Block_Adminhtml_System_Config_Form_Button</frontend_model>
40
+                 <sort_order>20</sort_order>
41
+                 <show_in_default>1</show_in_default>
42
+                 <show_in_website>0</show_in_website>
43
+                 <show_in_store>0</show_in_store>
44
+             </check>
45
+ </fields>
46
+ </registration>
47
+ </groups>
48
+ </oms>
49
+ <payment>
50
+ <groups>
51
+ <saleswarp translate="label">
52
+ <label>Saleswarp Payment Module</label>
53
+ <sort_order>670</sort_order>
54
+ <show_in_default>1</show_in_default>
55
+ <show_in_website>1</show_in_website>
56
+ <show_in_store>0</show_in_store>
57
+ <fields>
58
+ <active translate="label">
59
+ <label>Enabled</label>
60
+ <frontend_type>select</frontend_type>
61
+ <source_model>adminhtml/system_config_source_yesno</source_model>
62
+ <sort_order>1</sort_order>
63
+ <show_in_default>1</show_in_default>
64
+ <show_in_website>1</show_in_website>
65
+ <show_in_store>0</show_in_store>
66
+ </active>
67
+ <order_status translate="label">
68
+ <label>New order status</label>
69
+ <frontend_type>select</frontend_type>
70
+ <source_model>adminhtml/system_config_source_order_status_processing</source_model>
71
+ <sort_order>2</sort_order>
72
+ <show_in_default>1</show_in_default>
73
+ <show_in_website>1</show_in_website>
74
+ <show_in_store>0</show_in_store>
75
+ </order_status>
76
+ <title translate="label">
77
+ <label>Title</label>
78
+ <frontend_type>text</frontend_type>
79
+ <sort_order>3</sort_order>
80
+ <show_in_default>1</show_in_default>
81
+ <show_in_website>1</show_in_website>
82
+ <show_in_store>0</show_in_store>
83
+ </title>
84
+ <message translate="label">
85
+ <label>Displayed Message</label>
86
+ <frontend_type>textarea</frontend_type>
87
+ <sort_order>4</sort_order>
88
+ <show_in_default>1</show_in_default>
89
+ <show_in_website>1</show_in_website>
90
+ <show_in_store>1</show_in_store>
91
+ </message>
92
+ </fields>
93
+ </saleswarp>
94
+ </groups>
95
+ </payment>
96
+ </sections>
97
  </config>
app/code/local/Saleswarp/Oms/sql/oms_setup/mysql4-install-0.1.1.php CHANGED
@@ -1,265 +1,265 @@
1
- <?php
2
- /**
3
- * This module connects Magento to the SalesWarp Advanced Order Management System.
4
- *
5
- * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
- * @version 0.1.2
7
- * @author David Potts
8
- * @license http://www.saleswarp.com/license-saas
9
- * @category SalesWarp
10
- * @since File available since Release 0.1.2
11
- * @link https://www.SalesWarp.com
12
- *
13
- */
14
-
15
- $installer = $this;
16
- $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
17
- $installer->startSetup();
18
-
19
- $constants = array(
20
- 'saleswarp_api_url' => 'http://accounts.saleswarp.com/key/get',
21
- 'saleswarp_create_url' => 'https://www.saleswarp.com/30-day-free-trial-sign-up/',
22
- 'saleswarp_login_url' => 'https://www.saleswarp.com/SMB_login',
23
- );
24
-
25
- foreach($constants as $code => $value) {
26
- Mage::getModel('core/variable')
27
- ->setCode($code)
28
- ->setName($code)
29
- ->setPlainValue($value)
30
- ->save();
31
- }
32
-
33
- $setup->addAttribute('catalog_product', 'saleswarp_prod_id', array(
34
- 'group' => 'SalesWarp',
35
- 'type' => 'int',
36
- 'input' => 'text',
37
- 'label' => 'SalesWarp ID',
38
- 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
39
- 'visible' => 1,
40
- 'required' => 0,
41
- 'visible_on_front' => 0,
42
- 'is_html_allowed_on_front' => 0,
43
- 'is_configurable' => 0,
44
- 'searchable' => 0,
45
- 'filterable' => 0,
46
- 'comparable' => 0,
47
- 'unique' => true,
48
- 'user_defined' => true,
49
- 'is_user_defined' => false,
50
- 'used_in_product_listing' => false
51
- ));
52
-
53
- $setup->addAttribute('catalog_product', 'saleswarp_prod_add_date', array(
54
- 'group' => 'SalesWarp',
55
- 'type' => 'datetime',
56
- 'input' => 'date',
57
- 'label' => 'SalesWarp Add Date',
58
- 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
59
- 'visible' => 1,
60
- 'required' => 0,
61
- 'visible_on_front' => 0,
62
- 'is_html_allowed_on_front' => 0,
63
- 'is_configurable' => 0,
64
- 'backend' => 'eav/entity_attribute_backend_datetime',
65
- 'searchable' => 0,
66
- 'filterable' => 0,
67
- 'comparable' => 0,
68
- 'unique' => false,
69
- 'user_defined' => true,
70
- 'is_user_defined' => false,
71
- 'used_in_product_listing' => false
72
- ));
73
-
74
- $setup->addAttribute('catalog_product', 'saleswarp_prod_code', array(
75
- 'group' => 'SalesWarp',
76
- 'type' => 'varchar',
77
- 'input' => 'text',
78
- 'label' => 'SalesWarp Code',
79
- 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
80
- 'visible' => 1,
81
- 'required' => 0,
82
- 'visible_on_front' => 0,
83
- 'is_html_allowed_on_front' => 0,
84
- 'is_configurable' => 0,
85
- 'searchable' => 0,
86
- 'filterable' => 0,
87
- 'comparable' => 0,
88
- 'unique' => false,
89
- 'user_defined' => true,
90
- 'is_user_defined' => false,
91
- 'used_in_product_listing' => false
92
- ));
93
-
94
- $setup->addAttribute('catalog_product', 'saleswarp_prod_sync_date', array(
95
- 'group' => 'SalesWarp',
96
- 'type' => 'datetime',
97
- 'input' => 'date',
98
- 'label' => 'SalesWarp Sync Date',
99
- 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
100
- 'visible' => 1,
101
- 'required' => 0,
102
- 'visible_on_front' => 0,
103
- 'is_html_allowed_on_front' => 0,
104
- 'is_configurable' => 0,
105
- 'backend' => 'eav/entity_attribute_backend_datetime',
106
- 'searchable' => 0,
107
- 'filterable' => 0,
108
- 'comparable' => 0,
109
- 'unique' => false,
110
- 'user_defined' => false,
111
- 'is_user_defined' => false,
112
- 'used_in_product_listing' => false
113
- ));
114
-
115
- $setup->addAttribute('catalog_product', 'saleswarp_prod_last_inv_upd', array(
116
- 'group' => 'SalesWarp',
117
- 'type' => 'datetime',
118
- 'input' => 'date',
119
- 'label' => 'SalesWarp Last Inventory Update',
120
- 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
121
- 'visible' => 1,
122
- 'required' => 0,
123
- 'visible_on_front' => 0,
124
- 'is_html_allowed_on_front' => 0,
125
- 'is_configurable' => 0,
126
- 'backend' => 'eav/entity_attribute_backend_datetime',
127
- 'searchable' => 0,
128
- 'filterable' => 0,
129
- 'comparable' => 0,
130
- 'unique' => false,
131
- 'user_defined' => false,
132
- 'is_user_defined' => false,
133
- 'used_in_product_listing' => false
134
- ));
135
-
136
- $setup->addAttribute('catalog_category', 'saleswarp_cat_id', array(
137
- 'group' => 'SalesWarp',
138
- 'type' => 'int',
139
- 'input' => 'text',
140
- 'label' => 'SalesWarp ID',
141
- 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
142
- 'visible' => 1,
143
- 'required' => 0,
144
- 'visible_on_front' => 0,
145
- 'is_html_allowed_on_front' => 0,
146
- 'is_configurable' => 0,
147
- 'searchable' => 0,
148
- 'filterable' => 0,
149
- 'comparable' => 0,
150
- 'unique' => false,
151
- 'user_defined' => false,
152
- 'is_user_defined' => false,
153
- 'used_in_product_listing' => false
154
- ));
155
-
156
- $setup->addAttribute('catalog_category', 'saleswarp_cat_name', array(
157
- 'group' => 'SalesWarp',
158
- 'type' => 'varchar',
159
- 'input' => 'text',
160
- 'label' => 'SalesWarp Name',
161
- 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
162
- 'visible' => 1,
163
- 'required' => 0,
164
- 'visible_on_front' => 0,
165
- 'is_html_allowed_on_front' => 0,
166
- 'is_configurable' => 0,
167
- 'searchable' => 0,
168
- 'filterable' => 0,
169
- 'comparable' => 0,
170
- 'unique' => false,
171
- 'user_defined' => false,
172
- 'is_user_defined' => false,
173
- 'used_in_product_listing' => false
174
- ));
175
-
176
- $setup->addAttribute('catalog_category', 'saleswarp_cat_code', array(
177
- 'group' => 'SalesWarp',
178
- 'type' => 'int',
179
- 'input' => 'text',
180
- 'label' => 'SalesWarp Code',
181
- 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
182
- 'visible' => 1,
183
- 'required' => 0,
184
- 'visible_on_front' => 0,
185
- 'is_html_allowed_on_front' => 0,
186
- 'is_configurable' => 0,
187
- 'searchable' => 0,
188
- 'filterable' => 0,
189
- 'comparable' => 0,
190
- 'unique' => false,
191
- 'user_defined' => false,
192
- 'is_user_defined' => false,
193
- 'used_in_product_listing' => false
194
- ));
195
-
196
- $setup->addAttribute('catalog_category', 'saleswarp_cat_add_date', array(
197
- 'group' => 'SalesWarp',
198
- 'type' => 'datetime',
199
- 'input' => 'date',
200
- 'label' => 'SalesWarp Add Date',
201
- 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
202
- 'visible' => 1,
203
- 'required' => 0,
204
- 'visible_on_front' => 0,
205
- 'is_html_allowed_on_front' => 0,
206
- 'is_configurable' => 0,
207
- 'backend' => 'eav/entity_attribute_backend_datetime',
208
- 'searchable' => 0,
209
- 'filterable' => 0,
210
- 'comparable' => 0,
211
- 'unique' => false,
212
- 'user_defined' => false,
213
- 'is_user_defined' => false,
214
- 'used_in_product_listing' => false
215
- ));
216
-
217
- $setup->addAttribute('catalog_category', 'saleswarp_cat_sync_date', array(
218
- 'group' => 'SalesWarp',
219
- 'type' => 'datetime',
220
- 'input' => 'date',
221
- 'label' => 'SalesWarp Sync Date',
222
- 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
223
- 'visible' => 1,
224
- 'required' => 0,
225
- 'visible_on_front' => 0,
226
- 'is_html_allowed_on_front' => 0,
227
- 'is_configurable' => 0,
228
- 'backend' => 'eav/entity_attribute_backend_datetime',
229
- 'searchable' => 0,
230
- 'filterable' => 0,
231
- 'comparable' => 0,
232
- 'unique' => false,
233
- 'user_defined' => false,
234
- 'is_user_defined' => false,
235
- 'used_in_product_listing' => false
236
- ));
237
-
238
-
239
- $productTable = $this->getTable('catalog_product_entity');
240
- // Add new text fields product tables
241
- $installer->getConnection()->addColumn($productTable, 'saleswarp_category_ids', 'varchar(64) NULL');
242
-
243
- // ADD SALESWARP ATTRIBUTES FOR PRODUCTS
244
- $setup->addAttribute('catalog_product', 'managed_by_saleswarp', array(
245
- 'group' => 'General',
246
- 'type' => 'int',
247
- 'input' => 'boolean',
248
- 'label' => 'Manage Product with SalesWarp',
249
- 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
250
- 'visible' => 1,
251
- 'default' => '0',
252
- 'required' => 1,
253
- 'visible_on_front' => 0,
254
- 'is_html_allowed_on_front' => 0,
255
- 'is_configurable' => 0,
256
- 'searchable' => 0,
257
- 'filterable' => 0,
258
- 'comparable' => 0,
259
- 'unique' => false,
260
- 'user_defined' => false,
261
- 'is_user_defined' => false,
262
- 'used_in_product_listing' => false
263
- ));
264
-
265
- $installer->endSetup();
1
+ <?php
2
+ /**
3
+ * This module connects Magento to the SalesWarp Advanced Order Management System.
4
+ *
5
+ * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
+ * @version 0.1.2
7
+ * @author David Potts
8
+ * @license http://www.saleswarp.com/license-saas
9
+ * @category SalesWarp
10
+ * @since File available since Release 0.1.2
11
+ * @link https://www.SalesWarp.com
12
+ *
13
+ */
14
+
15
+ $installer = $this;
16
+ $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
17
+ $installer->startSetup();
18
+
19
+ $constants = array(
20
+ 'saleswarp_api_url' => 'http://accounts.saleswarp.com/key/get',
21
+ 'saleswarp_create_url' => 'https://www.saleswarp.com/30-day-free-trial-sign-up/',
22
+ 'saleswarp_login_url' => 'https://www.saleswarp.com/SMB_login',
23
+ );
24
+
25
+ foreach($constants as $code => $value) {
26
+ Mage::getModel('core/variable')
27
+ ->setCode($code)
28
+ ->setName($code)
29
+ ->setPlainValue($value)
30
+ ->save();
31
+ }
32
+
33
+ $setup->addAttribute('catalog_product', 'saleswarp_prod_id', array(
34
+ 'group' => 'SalesWarp',
35
+ 'type' => 'int',
36
+ 'input' => 'text',
37
+ 'label' => 'SalesWarp ID',
38
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
39
+ 'visible' => 1,
40
+ 'required' => 0,
41
+ 'visible_on_front' => 0,
42
+ 'is_html_allowed_on_front' => 0,
43
+ 'is_configurable' => 0,
44
+ 'searchable' => 0,
45
+ 'filterable' => 0,
46
+ 'comparable' => 0,
47
+ 'unique' => true,
48
+ 'user_defined' => true,
49
+ 'is_user_defined' => false,
50
+ 'used_in_product_listing' => false
51
+ ));
52
+
53
+ $setup->addAttribute('catalog_product', 'saleswarp_prod_add_date', array(
54
+ 'group' => 'SalesWarp',
55
+ 'type' => 'datetime',
56
+ 'input' => 'date',
57
+ 'label' => 'SalesWarp Add Date',
58
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
59
+ 'visible' => 1,
60
+ 'required' => 0,
61
+ 'visible_on_front' => 0,
62
+ 'is_html_allowed_on_front' => 0,
63
+ 'is_configurable' => 0,
64
+ 'backend' => 'eav/entity_attribute_backend_datetime',
65
+ 'searchable' => 0,
66
+ 'filterable' => 0,
67
+ 'comparable' => 0,
68
+ 'unique' => false,
69
+ 'user_defined' => true,
70
+ 'is_user_defined' => false,
71
+ 'used_in_product_listing' => false
72
+ ));
73
+
74
+ $setup->addAttribute('catalog_product', 'saleswarp_prod_code', array(
75
+ 'group' => 'SalesWarp',
76
+ 'type' => 'varchar',
77
+ 'input' => 'text',
78
+ 'label' => 'SalesWarp Code',
79
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
80
+ 'visible' => 1,
81
+ 'required' => 0,
82
+ 'visible_on_front' => 0,
83
+ 'is_html_allowed_on_front' => 0,
84
+ 'is_configurable' => 0,
85
+ 'searchable' => 0,
86
+ 'filterable' => 0,
87
+ 'comparable' => 0,
88
+ 'unique' => false,
89
+ 'user_defined' => true,
90
+ 'is_user_defined' => false,
91
+ 'used_in_product_listing' => false
92
+ ));
93
+
94
+ $setup->addAttribute('catalog_product', 'saleswarp_prod_sync_date', array(
95
+ 'group' => 'SalesWarp',
96
+ 'type' => 'datetime',
97
+ 'input' => 'date',
98
+ 'label' => 'SalesWarp Sync Date',
99
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
100
+ 'visible' => 1,
101
+ 'required' => 0,
102
+ 'visible_on_front' => 0,
103
+ 'is_html_allowed_on_front' => 0,
104
+ 'is_configurable' => 0,
105
+ 'backend' => 'eav/entity_attribute_backend_datetime',
106
+ 'searchable' => 0,
107
+ 'filterable' => 0,
108
+ 'comparable' => 0,
109
+ 'unique' => false,
110
+ 'user_defined' => false,
111
+ 'is_user_defined' => false,
112
+ 'used_in_product_listing' => false
113
+ ));
114
+
115
+ $setup->addAttribute('catalog_product', 'saleswarp_prod_last_inv_upd', array(
116
+ 'group' => 'SalesWarp',
117
+ 'type' => 'datetime',
118
+ 'input' => 'date',
119
+ 'label' => 'SalesWarp Last Inventory Update',
120
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
121
+ 'visible' => 1,
122
+ 'required' => 0,
123
+ 'visible_on_front' => 0,
124
+ 'is_html_allowed_on_front' => 0,
125
+ 'is_configurable' => 0,
126
+ 'backend' => 'eav/entity_attribute_backend_datetime',
127
+ 'searchable' => 0,
128
+ 'filterable' => 0,
129
+ 'comparable' => 0,
130
+ 'unique' => false,
131
+ 'user_defined' => false,
132
+ 'is_user_defined' => false,
133
+ 'used_in_product_listing' => false
134
+ ));
135
+
136
+ $setup->addAttribute('catalog_category', 'saleswarp_cat_id', array(
137
+ 'group' => 'SalesWarp',
138
+ 'type' => 'int',
139
+ 'input' => 'text',
140
+ 'label' => 'SalesWarp ID',
141
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
142
+ 'visible' => 1,
143
+ 'required' => 0,
144
+ 'visible_on_front' => 0,
145
+ 'is_html_allowed_on_front' => 0,
146
+ 'is_configurable' => 0,
147
+ 'searchable' => 0,
148
+ 'filterable' => 0,
149
+ 'comparable' => 0,
150
+ 'unique' => false,
151
+ 'user_defined' => false,
152
+ 'is_user_defined' => false,
153
+ 'used_in_product_listing' => false
154
+ ));
155
+
156
+ $setup->addAttribute('catalog_category', 'saleswarp_cat_name', array(
157
+ 'group' => 'SalesWarp',
158
+ 'type' => 'varchar',
159
+ 'input' => 'text',
160
+ 'label' => 'SalesWarp Name',
161
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
162
+ 'visible' => 1,
163
+ 'required' => 0,
164
+ 'visible_on_front' => 0,
165
+ 'is_html_allowed_on_front' => 0,
166
+ 'is_configurable' => 0,
167
+ 'searchable' => 0,
168
+ 'filterable' => 0,
169
+ 'comparable' => 0,
170
+ 'unique' => false,
171
+ 'user_defined' => false,
172
+ 'is_user_defined' => false,
173
+ 'used_in_product_listing' => false
174
+ ));
175
+
176
+ $setup->addAttribute('catalog_category', 'saleswarp_cat_code', array(
177
+ 'group' => 'SalesWarp',
178
+ 'type' => 'int',
179
+ 'input' => 'text',
180
+ 'label' => 'SalesWarp Code',
181
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
182
+ 'visible' => 1,
183
+ 'required' => 0,
184
+ 'visible_on_front' => 0,
185
+ 'is_html_allowed_on_front' => 0,
186
+ 'is_configurable' => 0,
187
+ 'searchable' => 0,
188
+ 'filterable' => 0,
189
+ 'comparable' => 0,
190
+ 'unique' => false,
191
+ 'user_defined' => false,
192
+ 'is_user_defined' => false,
193
+ 'used_in_product_listing' => false
194
+ ));
195
+
196
+ $setup->addAttribute('catalog_category', 'saleswarp_cat_add_date', array(
197
+ 'group' => 'SalesWarp',
198
+ 'type' => 'datetime',
199
+ 'input' => 'date',
200
+ 'label' => 'SalesWarp Add Date',
201
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
202
+ 'visible' => 1,
203
+ 'required' => 0,
204
+ 'visible_on_front' => 0,
205
+ 'is_html_allowed_on_front' => 0,
206
+ 'is_configurable' => 0,
207
+ 'backend' => 'eav/entity_attribute_backend_datetime',
208
+ 'searchable' => 0,
209
+ 'filterable' => 0,
210
+ 'comparable' => 0,
211
+ 'unique' => false,
212
+ 'user_defined' => false,
213
+ 'is_user_defined' => false,
214
+ 'used_in_product_listing' => false
215
+ ));
216
+
217
+ $setup->addAttribute('catalog_category', 'saleswarp_cat_sync_date', array(
218
+ 'group' => 'SalesWarp',
219
+ 'type' => 'datetime',
220
+ 'input' => 'date',
221
+ 'label' => 'SalesWarp Sync Date',
222
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
223
+ 'visible' => 1,
224
+ 'required' => 0,
225
+ 'visible_on_front' => 0,
226
+ 'is_html_allowed_on_front' => 0,
227
+ 'is_configurable' => 0,
228
+ 'backend' => 'eav/entity_attribute_backend_datetime',
229
+ 'searchable' => 0,
230
+ 'filterable' => 0,
231
+ 'comparable' => 0,
232
+ 'unique' => false,
233
+ 'user_defined' => false,
234
+ 'is_user_defined' => false,
235
+ 'used_in_product_listing' => false
236
+ ));
237
+
238
+
239
+ $productTable = $this->getTable('catalog_product_entity');
240
+ // Add new text fields product tables
241
+ $installer->getConnection()->addColumn($productTable, 'saleswarp_category_ids', 'varchar(64) NULL');
242
+
243
+ // ADD SALESWARP ATTRIBUTES FOR PRODUCTS
244
+ $setup->addAttribute('catalog_product', 'managed_by_saleswarp', array(
245
+ 'group' => 'General',
246
+ 'type' => 'int',
247
+ 'input' => 'boolean',
248
+ 'label' => 'Manage Product with SalesWarp',
249
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
250
+ 'visible' => 1,
251
+ 'default' => '0',
252
+ 'required' => 1,
253
+ 'visible_on_front' => 0,
254
+ 'is_html_allowed_on_front' => 0,
255
+ 'is_configurable' => 0,
256
+ 'searchable' => 0,
257
+ 'filterable' => 0,
258
+ 'comparable' => 0,
259
+ 'unique' => false,
260
+ 'user_defined' => false,
261
+ 'is_user_defined' => false,
262
+ 'used_in_product_listing' => false
263
+ ));
264
+
265
+ $installer->endSetup();
app/code/local/Saleswarp/Oms/sql/oms_setup/mysql4-upgrade-0.1.2.php CHANGED
@@ -1,28 +1,28 @@
1
- <?php
2
- /**
3
- * This module connects Magento to the SalesWarp Advanced Order Management System.
4
- *
5
- * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
- * @version 0.1.2
7
- * @author David Potts
8
- * @license http://www.saleswarp.com/license-saas
9
- * @category SalesWarp
10
- * @since File available since Release 0.1.2
11
- * @link https://www.SalesWarp.com
12
- *
13
- */
14
-
15
- $installer = $this;
16
- /* @var $installer Mage_Customer_Model_Entity_Setup */
17
-
18
- $installer->startSetup();
19
- $installer->run("
20
-
21
- ALTER TABLE `{$installer->getTable('sales/quote_payment')}` ADD `transction_no` VARCHAR( 255 ) NOT NULL ;
22
- ALTER TABLE `{$installer->getTable('sales/quote_payment')}` ADD `payment_method` VARCHAR( 255 ) NOT NULL ;
23
-
24
- ALTER TABLE `{$installer->getTable('sales/order_payment')}` ADD `transction_no` VARCHAR( 255 ) NOT NULL ;
25
- ALTER TABLE `{$installer->getTable('sales/order_payment')}` ADD `payment_method` VARCHAR( 255 ) NOT NULL ;
26
-
27
- ");
28
- $installer->endSetup();
1
+ <?php
2
+ /**
3
+ * This module connects Magento to the SalesWarp Advanced Order Management System.
4
+ *
5
+ * @copyright Copyright (c) 2015 6th Street Inc, dba SalesWarp.
6
+ * @version 0.1.2
7
+ * @author David Potts
8
+ * @license http://www.saleswarp.com/license-saas
9
+ * @category SalesWarp
10
+ * @since File available since Release 0.1.2
11
+ * @link https://www.SalesWarp.com
12
+ *
13
+ */
14
+
15
+ $installer = $this;
16
+ /* @var $installer Mage_Customer_Model_Entity_Setup */
17
+
18
+ $installer->startSetup();
19
+ $installer->run("
20
+
21
+ ALTER TABLE `{$installer->getTable('sales/quote_payment')}` ADD `transction_no` VARCHAR( 255 ) NOT NULL ;
22
+ ALTER TABLE `{$installer->getTable('sales/quote_payment')}` ADD `payment_method` VARCHAR( 255 ) NOT NULL ;
23
+
24
+ ALTER TABLE `{$installer->getTable('sales/order_payment')}` ADD `transction_no` VARCHAR( 255 ) NOT NULL ;
25
+ ALTER TABLE `{$installer->getTable('sales/order_payment')}` ADD `payment_method` VARCHAR( 255 ) NOT NULL ;
26
+
27
+ ");
28
+ $installer->endSetup();
app/code/local/Saleswarp/Publish/Helper/Data.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ class Saleswarp_Publish_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ }
5
+
app/code/local/Saleswarp/Publish/Model/Category/Api.php ADDED
@@ -0,0 +1,326 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * CUSTOM API EXTENSION - 6th Street Inc
4
+ * @author David Potts
5
+ * @copyright 6th Street Inc.
6
+ * @license none
7
+ *
8
+ */
9
+ class Saleswarp_Publish_Model_Category_Api extends Saleswarp_Oms_Model_Category_Api
10
+ {
11
+ public $category_required_storeIds = array();
12
+
13
+ /**
14
+ * Update saleswarp Category Id in Magento
15
+ *
16
+ * @params Magento Product Id, Saleswarp categroy Id
17
+ * @return bool( TRUE|FALSE)
18
+ */
19
+ public function update_slwp_category_id($entityId, $slwpCatId)
20
+ {
21
+ return $this->rest_save_attribute($entityId, 'saleswarp_cat_id', $slwpCatId);
22
+ }
23
+
24
+ /**
25
+ * Update catalog/category attribute value
26
+ *
27
+ * @params Magento Product id, attibure name, value
28
+ * @return query response
29
+ */
30
+ function rest_save_attribute($entity_id, $code, $value, $store_id = 0)
31
+ {
32
+ $resource = Mage::getSingleton('core/resource');
33
+
34
+ $entity_type_id = Mage::getModel('eav/entity')->setType('catalog_category')->getTypeId();
35
+
36
+ $query = "SELECT attribute_id, backend_type, frontend_input FROM `" . $resource->getTableName('eav_attribute') . "`
37
+ WHERE `attribute_code` LIKE :code AND entity_type_id = :entityTypeId";
38
+
39
+ $binds = array(
40
+ 'code' => $code,
41
+ 'entityTypeId' => $entity_type_id
42
+ );
43
+
44
+ $result = $resource->getConnection('core_read')->query($query, $binds);
45
+ $row = $result->fetch(PDO::FETCH_ASSOC);
46
+ return $this->save_attribute($row, $entity_id, $entity_type_id, $code, $value, $store_id);
47
+ }
48
+
49
+
50
+ /**
51
+ * special attribute saves for select and multiselect types (frontend_type in Magento)
52
+ *
53
+ * @param mixed $product_id
54
+ * @param mixed $attribute_id
55
+ * @param mixed $attribute_code
56
+ */
57
+ function save_attribute($row, $entity_id, $entity_type_id, $attribute_code, $value, $store_id)
58
+ {
59
+ $resource = Mage::getSingleton('core/resource');
60
+ $write = $resource->getConnection('core_write');
61
+ $read = $resource->getConnection('core_read');
62
+
63
+
64
+ if ((!empty($row)) && ($row['backend_type'] != '') && ($row['backend_type'] != null)) {
65
+
66
+ $categroyBakTable = $resource->getTableName('catalog_category_entity_' . $row['backend_type']);
67
+
68
+ // does this exist
69
+ $query = "SELECT * FROM `" . $categroyBakTable . "`
70
+ WHERE attribute_id = :attributeId
71
+ AND entity_id = :entityId
72
+ AND store_id = 0
73
+ AND entity_type_id = :entityTypeId";
74
+ $binds = array(
75
+ 'attributeId' => $row['attribute_id'],
76
+ 'entityId' => $entity_id,
77
+ 'entityTypeId' => $entity_type_id
78
+ );
79
+
80
+ $result = $read->query($query, $binds);
81
+ $chk = $result->fetch(PDO::FETCH_ASSOC);
82
+
83
+ if (empty($chk)) {
84
+ // If key is in array $this->product_required_storeIds, then create an Admin store_id entry (store_id = 0)
85
+ if (!empty($value) && $value != "") {
86
+ $key1 = "catalog_category_entity_" . $row['backend_type'];
87
+ if (array_key_exists($key1, $this->category_required_storeIds)) {
88
+
89
+ $sql = "INSERT INTO `" . $categroyBakTable . "` (value_id, entity_type_id, attribute_id, store_id, entity_id, value)
90
+ VALUES (NULL ,:etype,:attr,0,:eid,:val) ";
91
+ $binds = array(
92
+ 'etype' => $entity_type_id,
93
+ 'attr' => $row['attribute_id'],
94
+ 'eid' => $entity_id,
95
+ 'val' => $value
96
+ );
97
+
98
+ $write->query($sql, $binds);
99
+ }
100
+ }
101
+ } else { // update
102
+ $sql = "UPDATE `" . $categroyBakTable . "`
103
+ SET value = :value
104
+ WHERE value_id = :value_id";
105
+
106
+ $binds = array(
107
+ 'value' => $value,
108
+ 'value_id' => $chk['value_id']
109
+ );
110
+ $result = $write->query($sql, $binds);
111
+ }
112
+
113
+ // check for store id = 1
114
+ $query = "SELECT * FROM `" . $categroyBakTable . "`
115
+ WHERE attribute_id = :attributeId
116
+ AND entity_id = :entityId
117
+ AND store_id = :storeId
118
+ AND entity_type_id = :entityTypeId";
119
+ $binds = array(
120
+ 'attributeId' => $row['attribute_id'],
121
+ 'entityId' => $entity_id,
122
+ 'storeId' => $store_id,
123
+ 'entityTypeId' => $entity_type_id
124
+ );
125
+ $result = $read->query($query, $binds);
126
+ $chk = $result->fetch(PDO::FETCH_ASSOC);
127
+
128
+ if (empty($chk)) {
129
+ if (!empty($value) && $value != "") {
130
+ $sql = "INSERT INTO `" . $categroyBakTable . "` (value_id, entity_type_id, attribute_id, store_id, entity_id, value)
131
+ VALUES (NULL , :entity_type_id, :attribute_id, :store_id, :entity_id,:value)";
132
+
133
+ $binds = array(
134
+ 'entity_type_id'=> $entity_type_id,
135
+ 'attribute_id' => $row['attribute_id'],
136
+ 'store_id' => $store_id,
137
+ 'entity_id' => $entity_id,
138
+ 'value' => $value
139
+ );
140
+
141
+ $write->query($sql, $binds);
142
+ }
143
+ } else { // update
144
+ if (!empty($value) && $value != "") {
145
+ $sql = "UPDATE `" . $categroyBakTable . "`
146
+ SET value = :value
147
+ WHERE value_id = :value_id";
148
+
149
+ $binds = array(
150
+ 'value' => $value,
151
+ 'value_id' => $chk['value_id']
152
+ );
153
+ $result = $write->query($sql, $binds);
154
+ }
155
+ }
156
+ }
157
+ return "pass";
158
+ }
159
+
160
+
161
+ /**
162
+ * Get category collection by default root category
163
+ *
164
+ * @params Magento root category Id
165
+ * @return Mage Category Collection
166
+ */
167
+ public function get_category_collection($mageRootId)
168
+ {
169
+ Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
170
+ $collection = Mage::getModel('catalog/category')
171
+ ->getCollection()
172
+ ->addAttributeToSelect('entity_id')
173
+ ->addAttributeToSelect('name')
174
+ ->addAttributeToSelect('saleswarp_cat_id')
175
+ ->addFieldToFilter('parent_id', $mageRootId);
176
+
177
+ if ($collection) {
178
+ $data = array();
179
+ foreach ($collection as $category) {
180
+ $data[] = $category->getData();
181
+ }
182
+ return $data;
183
+ }
184
+ return false;
185
+ }
186
+
187
+
188
+ /**
189
+ * Check if category exists in magento ( serach by name )
190
+ *
191
+ * @params id and saleswarp value
192
+ * @return bool
193
+ */
194
+ public function check_category_exists($attr_id, $warehouse_cat_code)
195
+ {
196
+ $resource = Mage::getSingleton('core/resource');
197
+ $entity_type_id = Mage::getModel('eav/entity')->setType('catalog_category')->getTypeId();
198
+
199
+ $sql = "SELECT * FROM " . $resource->getTableName('catalog_category_entity_int') . "
200
+ WHERE attribute_id = :attributeId
201
+ and value = :value
202
+ and entity_type_id = :entityTypeId";
203
+ $binds = array(
204
+ 'attributeId' => $attr_id,
205
+ 'value' => $warehouse_cat_code,
206
+ 'entityTypeId' => $entity_type_id
207
+ );
208
+ $cat = $resource->getConnection('core_read')->fetchAll($sql, $binds);
209
+
210
+ if (!empty($cat)) {
211
+ return $cat[0]['entity_id'];
212
+ } else {
213
+ return false;
214
+ }
215
+ }
216
+
217
+ /**
218
+ * Get category names
219
+ *
220
+ * @param mixed $store_cat_id
221
+ * @return mixed
222
+ */
223
+ public function get_category_name($cat_ids)
224
+ {
225
+ $resource = Mage::getSingleton('core/resource');
226
+ $category = '';
227
+
228
+ foreach ($cat_ids as $cat_id) {
229
+ $sql = "SELECT value from " . $resource->getTableName('catalog_category_entity_varchar') . " as a
230
+ JOIN " . $resource->getTableName('eav_attribute') . " as b ON a.attribute_id = b.attribute_id
231
+ WHERE a.entity_id = :catId AND b.attribute_code = 'name'";
232
+
233
+ $binds = array(
234
+ 'catId' => $cat_id
235
+ );
236
+ $cats = $resource->getConnection('core_read')->fetchAll($sql, $binds);
237
+ $category = $cats[0]['value'] . ',' . $category;
238
+ }
239
+
240
+ $category = substr_replace($category, "", -1);
241
+ return $category;
242
+ }
243
+
244
+ /**
245
+ * Check_Category_Exists_Id:
246
+ *
247
+ * @param mixed $store_cat_id
248
+ * @return mixed
249
+ */
250
+ public function check_parent_cat($store_cat_id, $root_cat_id)
251
+ {
252
+ $resource = Mage::getSingleton('core/resource');
253
+ $sql = "SELECT path FROM " . $resource->getTableName('catalog_category_entity') . "
254
+ WHERE entity_id = :catId ";
255
+ $binds = array(
256
+ 'catId' => $store_cat_id
257
+ );
258
+ $cats = $resource->getConnection('core_read')->fetchRow($sql, $binds);
259
+
260
+ $parent_cat = array();
261
+ if ($cats) {
262
+ $catIds = substr($cats['path'], 4);
263
+ $parent_cat = explode('/', $catIds);
264
+ return $parent_cat;
265
+ } else {
266
+ return false;
267
+ }
268
+ }
269
+
270
+ /**
271
+ * Get all categories by parent category
272
+ *
273
+ * @params category id and root category id
274
+ * @return category (array)
275
+ */
276
+ public function check_parent_cat_new($store_cat_id, $root_cat_id)
277
+ {
278
+ $resource = Mage::getSingleton('core/resource');
279
+
280
+ $sql = "SELECT path FROM " . $resource->getConnection('core_read') . "
281
+ WHERE entity_id = :catId ";
282
+ $binds = array(
283
+ 'catId' => $store_cat_id
284
+ );
285
+ $cats = $resource->getConnection('core_read')->fetchRow($sql, $binds);
286
+
287
+ $parent_cat = array();
288
+ if ($cats) {
289
+ $parent_cat = explode('/', $cats['path']);
290
+ $i = 0;
291
+ foreach ($parent_cat as $cats) {
292
+ if ($i > 1) {
293
+ $cat[] = $cats;
294
+ }
295
+ $i++;
296
+ }
297
+ return $cat;
298
+ } else {
299
+ return false;
300
+ }
301
+ }
302
+
303
+ /**
304
+ * Check_Category_Exists_Id:
305
+ *
306
+ * @param mixed $store_cat_id
307
+ * @return mixed
308
+ */
309
+ public function check_category_exists_id($store_cat_id)
310
+ {
311
+ $resource = Mage::getSingleton('core/resource');
312
+
313
+ $sql = "SELECT * FROM " . $resource->getTableName('catalog_category_entity') . "
314
+ WHERE entity_id = :catId ";
315
+ $binds = array(
316
+ 'catId' => $store_cat_id
317
+ );
318
+ $cats = $resource->getConnection('core_read')->fetchAll($sql, $binds);
319
+ if (!empty($cat)) {
320
+ return true;
321
+ } else {
322
+ return false;
323
+ }
324
+ }
325
+ }
326
+ ?>
app/code/local/Saleswarp/Publish/Model/Config/Api.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Use this API to get/set key config data for the storefronts
4
+ */
5
+ class Saleswarp_Publish_Model_Config_Api extends Saleswarp_Oms_Model_Config_Api
6
+ {
7
+ public $activeStoreId = null;
8
+
9
+ /**
10
+ * get all attributes in form of saleswarp_xxx and xxx_saleswarp
11
+ */
12
+ public function getSaleswarpAttributeIds()
13
+ {
14
+ $resource = Mage::getSingleton('core/resource');
15
+ $sql = "SELECT * from " . $resource->getTableName('eav_attribute') . " WHERE attribute_code = %saleswarp%";
16
+ $atts = $resource->getConnection('core_read')->fetchAll($sql);
17
+ return $atts;
18
+ }
19
+
20
+ /**
21
+ * get all product attributes
22
+ */
23
+ public function getProductAttributesIds()
24
+ {
25
+ $eavAttrTable = Mage::getSingleton( 'core/resource' )->getTableName( 'eav_attribute' );
26
+ $entity_type_id = Mage::getModel('eav/entity')
27
+ ->setType('catalog_product')
28
+ ->getTypeId();
29
+ $sql = "SELECT * from ". $eavAttrTable ."
30
+ WHERE entity_type_id = '".(int)$entity_type_id."' ";
31
+ $atts = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchAll($sql);
32
+ return $atts;
33
+ }
34
+
35
+ /**
36
+ * Get all category attibute id
37
+ */
38
+ public function getCategoryAttributesIds()
39
+ {
40
+ $resource = Mage::getSingleton('core/resource');
41
+ $entity_type_id = Mage::getModel('eav/entity')->setType('catalog_category')->getTypeId();
42
+ $sql = "SELECT * from " . $resource->getTableName('eav_attribute') . "
43
+ WHERE entity_type_id = '" . (int) $entity_type_id . "'";
44
+ $atts = $resource->getConnection('core_read')->fetchAll($sql);
45
+ return $atts;
46
+ }
47
+
48
+ /**
49
+ * with Magento EAV architecture we need to retrieve key Attributes Key ID's before publishing any
50
+ * product or category info
51
+ *
52
+ */
53
+ public function getAttributeIds()
54
+ {
55
+ $resource = Mage::getSingleton('core/resource');
56
+ $sql = "SELECT * from " . $resource->getTableName('eav_entity_type') . " WHERE 1";
57
+ $entities = $resource->getConnection('core_read')->fetchAll($sql);
58
+ return $entities;
59
+ }
60
+
61
+ /**
62
+ * Function Not in use
63
+ */
64
+ public function getStoreInfo($storeId = null)
65
+ {
66
+ if ($storeId == null) {
67
+ if ($this->activeStoreId != null) {
68
+ $storeId = $this->activeStoreId;
69
+ } else {
70
+ return false;
71
+ }
72
+ }
73
+ }
74
+
75
+ /**
76
+ * get Store configs
77
+ */
78
+ public function getSetupConfigs()
79
+ {
80
+ return Mage::getSingleton('core/resource')->getConnection('core_read')->getConfig();
81
+ }
82
+ }
83
+ ?>
app/code/local/Saleswarp/Publish/Model/Customer/Api.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Use this API to get/set key config data for the storefronts
4
+ */
5
+ class Saleswarp_Publish_Model_Customer_Api extends Saleswarp_Oms_Model_Customer_Api
6
+ {
7
+
8
+ public $activeStoreId = null;
9
+
10
+ /**
11
+ * Test function
12
+ */
13
+ public function customer_api_test()
14
+ {
15
+ return "called Saleswarp_Publish_Model_Customer_Api, method->customer_api_test";
16
+ }
17
+
18
+ /**
19
+ * Get Items
20
+ */
21
+ public function items()
22
+ {
23
+ return parent::items();
24
+ }
25
+ }
26
+ ?>
app/code/local/Saleswarp/Publish/Model/Product/Api.php ADDED
@@ -0,0 +1,2191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @copyright 2011 6th Street Inc, all rights reserved
4
+ * @author David Potts
5
+ * @version 1.0
6
+ * @package SalesWarp
7
+ * @subpackage Product_API
8
+ *
9
+ * @license commercial, unauthorized copies are prohibited
10
+ *
11
+ *
12
+ * Attributes needed in Magento
13
+ *
14
+ * warehouse_id: warehouse_prod_id
15
+ * warehouse_prod_add_date: w_prod_add_date
16
+ * warehouse_prod_code: warehouse_prod_code
17
+ * warehouse_prod_sync_date: w_prod_sync_date
18
+ *
19
+ * supplier_id: supplier_id
20
+ * supplier_name: Seller
21
+ *
22
+ * last_inventory_update: last_inventory_update
23
+ * last_price_update: last_price_update
24
+ * last_update: last_update
25
+ *
26
+ * CREATE WAREHOUSE ATTRIBUTE SET.
27
+ *
28
+ * @todo - set enable_logs and log_filename as API config in system.xml
29
+ *
30
+ *
31
+ */
32
+
33
+ class Saleswarp_Publish_Model_Product_Api extends Saleswarp_Oms_Model_Product_Api
34
+ {
35
+ var $enable_logs = true;
36
+ var $log_level = 2;
37
+ var $log_filename = 'saleswarp_product_api.log';
38
+ var $truncate_test = array('catalog_product_entity');
39
+ var $product_tables = array(
40
+ 'catalogindex_eav' => 'entity_id',
41
+ 'cataloginventory_stock_item' => 'product_id',
42
+ 'cataloginventory_stock_status' => 'product_id',
43
+ 'cataloginventory_stock_status_idx' => 'product_id',
44
+ 'catalogrule_product' => 'product_id',
45
+ 'catalogrule_product_price' => 'product_id',
46
+ 'catalogsearch_fulltext' => 'product_id',
47
+ 'catalogsearch_result' => 'product_id',
48
+ 'catalog_product_enabled_index' => 'product_id',
49
+ 'catalog_product_entity' => 'entity_id',
50
+ 'catalog_product_entity_datetime' => 'entity_id',
51
+ 'catalog_product_entity_decimal' => 'entity_id',
52
+ 'catalog_product_entity_gallery' => 'entity_id',
53
+ 'catalog_product_entity_int' => 'entity_id',
54
+ 'catalog_product_entity_media_gallery' => 'entity_id',
55
+ 'catalog_product_entity_text' => 'entity_id',
56
+ 'catalog_product_entity_tier_price' => 'entity_id',
57
+ 'catalog_product_entity_varchar' => 'entity_id',
58
+ 'catalog_product_index_eav' => 'entity_id',
59
+ 'catalog_product_index_eav_decimal' => 'entity_id',
60
+ 'catalog_product_index_eav_decimal_idx' => 'entity_id',
61
+ 'catalog_product_index_eav_idx' => 'entity_id',
62
+ 'catalog_product_index_price' => 'entity_id',
63
+ 'catalog_product_index_price_bundle_idx' => 'entity_id',
64
+ 'catalog_product_index_price_bundle_opt_idx' => 'entity_id',
65
+ 'catalog_product_index_price_bundle_sel_idx' => 'entity_id',
66
+ 'catalog_product_index_price_cfg_opt_agr_idx' => 'parent_id',
67
+ 'catalog_product_index_price_cfg_opt_idx' => 'entity_id',
68
+ 'catalog_product_index_price_downlod_idx' => 'entity_id',
69
+ 'catalog_product_index_price_final_idx' => 'entity_id',
70
+ 'catalog_product_index_price_idx' => 'entity_id',
71
+ 'catalog_product_index_price_opt_agr_idx' => 'entity_id',
72
+ 'catalog_product_index_price_opt_idx' => 'entity_id',
73
+ 'catalog_product_index_tier_price' => 'entity_id',
74
+ 'catalog_product_relation' => 'child_id',
75
+ 'catalog_product_website' => 'product_id',
76
+ 'catalog_category_product' => 'product_id',
77
+ 'catalog_category_product_index' => 'product_id',
78
+ 'catalog_compare_item' => 'product_id'
79
+ );
80
+
81
+ var $product_required_storeIds = array(
82
+ 'catalog_product_entity_datetime' => '0',
83
+ 'catalog_product_entity_decimal' => '0',
84
+ 'catalog_product_entity_int' => '0',
85
+ 'catalog_product_entity_text' => '0',
86
+ 'catalog_product_entity_varchar' => '0',
87
+ );
88
+
89
+ var $product_required_websiteIds = array(
90
+ 'catalog_product_entity_tier_price' => '1',
91
+ 'catalog_product_index_price' => '1',
92
+ 'catalog_product_index_price_bundle_idx' => '1',
93
+ 'catalog_product_index_price_bundle_opt_idx' => '1',
94
+ 'catalog_product_index_price_bundle_sel_idx' => '1',
95
+ 'catalog_product_index_price_cfg_opt_idx' => '1',
96
+ 'catalog_product_index_price_downlod_idx' => '1',
97
+ 'catalog_product_index_price_final_idx' => '1',
98
+ 'catalog_product_index_price_idx' => '1',
99
+ 'catalog_product_index_price_opt_agr_idx' => '1',
100
+ 'catalog_product_index_price_opt_idx' => '1',
101
+ 'catalog_product_index_tier_price' => '1',
102
+ 'catalog_product_website' => '1',
103
+ 'cataloginventory_stock_status' => '1',
104
+ 'cataloginventory_stock_status_idx' => '1'
105
+ );
106
+
107
+ /**
108
+ * Get Attribute Id By name
109
+ *
110
+ */
111
+ public function get_attr_id_by_name($attributeSetName = 'Default')
112
+ {
113
+ $entityTypeId = Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId();
114
+ //$attributeSetName = 'Default';
115
+ $attributeSetId = Mage::getModel('eav/entity_attribute_set')->getCollection()->setEntityTypeFilter($entityTypeId)->addFieldToFilter('attribute_set_name', $attributeSetName)->getFirstItem()->getAttributeSetId();
116
+ if ($attributeSetId) {
117
+ return $attributeSetId;
118
+ } else {
119
+ return false;
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Update Product
125
+ * @param product data array
126
+ */
127
+ function product_slwp_update($data)
128
+ {
129
+ if (empty($data)) {
130
+ return 'no data';
131
+ }
132
+ $code = 'saleswarp_prod_id';
133
+ foreach ($data as $prod) {
134
+ $prod = $prod['BaseProductsBaseStore'];
135
+ if ($this->check_prod_exists($prod['merchant_sku'])) {
136
+ $this->rest_save_attribute($prod['merchant_sku'], $code, $prod['base_product_id'], 1);
137
+ }
138
+ }
139
+ return "success";
140
+ }
141
+
142
+
143
+ /**
144
+ * Read and populate product entity
145
+ */
146
+ function product_list($type = 'simple', $offset = 0, $limit = 50000)
147
+ {
148
+ $productTable = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity');
149
+ $sql = "select entity_id,sku,attribute_set_id from " . $productTable . "
150
+ where type_id = '" . $type . "'
151
+ order by entity_id asc limit $offset,$limit";
152
+ $data = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchAll($sql);
153
+ return $data;
154
+ }
155
+
156
+
157
+
158
+ /**
159
+ * Check if Configurable Product Exists
160
+ *
161
+ **/
162
+ function check_configurable_option_exists($attribute_code, $saleswp_option)
163
+ {
164
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
165
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
166
+
167
+ $eavAttrOptValTable = Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value');
168
+ $eavAttrOptTable = Mage::getSingleton('core/resource')->getTableName('eav_attribute_option');
169
+ $eavAttrTable = Mage::getSingleton('core/resource')->getTableName('eav_attribute');
170
+
171
+ $sql_option = "SELECT b.option_id FROM " . $eavAttrOptValTable . " as a
172
+ JOIN " . $eavAttrOptTable . " as b ON a.option_id = b.option_id
173
+ JOIN " . $eavAttrTable . " as c ON b.attribute_id = c.attribute_id
174
+ WHERE a.value = :saleswp_option AND c.attribute_code = :attribute_code ";
175
+ $binds = array(
176
+ 'saleswp_option' => $saleswp_option,
177
+ 'attribute_code' => $attribute_code
178
+ );
179
+
180
+ $connection = $read->fetchAll($sql_option, $binds);
181
+
182
+ if (!empty($connection)) {
183
+ $value = $connection[0]['option_id'];
184
+ } else {
185
+ $attr_model = Mage::getModel('catalog/resource_eav_attribute');
186
+ $attr = $attr_model->loadByCode('catalog_product', $attribute_code);
187
+
188
+ $attr_id = $attr->getAttributeId();
189
+
190
+ $option = array();
191
+
192
+ $sql = 'INSERT INTO ' . $eavAttrOptTable . '(attribute_id, sort_order) VALUES (' . (int) $attr_id . ',0)';
193
+ $write->query($sql);
194
+
195
+ $lastInsertId = $write->lastInsertId();
196
+
197
+ $sql2 = "INSERT INTO " . $eavAttrOptValTable . "(option_id, store_id , value) VALUES (:lastInsertId, 0, :saleswp_option)";
198
+ $binds2 = array(
199
+ 'lastInsertId' => $lastInsertId,
200
+ 'saleswp_option' => $saleswp_option
201
+ );
202
+ $attr_value_insertion = $write->query($sql2, $binds2);
203
+
204
+ $value = $lastInsertId;
205
+ }
206
+
207
+ return $value;
208
+ }
209
+
210
+ /**
211
+ * Create Product Option in MAGENTO
212
+ */
213
+ function add_product_option($product_id, $attribute_code, $value)
214
+ {
215
+ $product = Mage::getModel("catalog/product")->load($product_id);
216
+ $product->setData($attribute_code, $value);
217
+ if($product->save()) {
218
+ return true;
219
+ } else {
220
+ return false;
221
+ }
222
+ }
223
+
224
+ /**
225
+ * Create Configurable Attributes in magento
226
+ */
227
+ function create_configurable_attribute($code, $label, $attribute_type, $product_type)
228
+ {
229
+ $_attribute_data = array(
230
+ 'attribute_code' => $code,
231
+ 'is_global' => '1',
232
+ 'frontend_input' => $attribute_type, //'boolean',
233
+ 'default_value_text' => '',
234
+ 'default_value_yesno' => '0',
235
+ 'default_value_date' => '',
236
+ 'default_value_textarea' => '',
237
+ 'is_unique' => '1',
238
+ 'is_required' => '0',
239
+ 'apply_to' => $product_type, //array('grouped')
240
+ 'is_configurable' => '1',
241
+ 'is_searchable' => '1',
242
+ 'is_filterable' => '1',
243
+ 'is_visible_in_advanced_search' => '0',
244
+ 'is_comparable' => '0',
245
+ 'is_used_for_price_rules' => '0',
246
+ 'is_wysiwyg_enabled' => '0',
247
+ 'is_html_allowed_on_front' => '1',
248
+ 'is_visible_on_front' => '0',
249
+ 'used_in_product_listing' => '0',
250
+ 'used_for_sort_by' => '0',
251
+ 'frontend_label' => array(
252
+ $label
253
+ )
254
+ );
255
+
256
+ $model = Mage::getModel('catalog/resource_eav_attribute');
257
+
258
+
259
+ if (is_null($model->getIsUserDefined()) || $model->getIsUserDefined() != 0) {
260
+ $_attribute_data['backend_type'] = $model->getBackendTypeByInput($_attribute_data['frontend_input']);
261
+ }
262
+
263
+ $defaultValueField = $model->getDefaultValueByInput($_attribute_data['frontend_input']);
264
+
265
+ if ($defaultValueField) {
266
+ $_attribute_data['default_value'] = $this->getRequest()->getParam($defaultValueField);
267
+ }
268
+
269
+ $model->addData($_attribute_data);
270
+ $model->setEntityTypeId(Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId());
271
+ $model->setIsUserDefined(1);
272
+
273
+ try {
274
+ $model->save();
275
+ return true;
276
+ }
277
+ catch (Exception $e) {
278
+ $msg = "error : " . $e->getMessage();
279
+ Mage::log($msg, null, "product_api.log", true);
280
+ $this->_fault($msg, $e->getMessage());
281
+ return false;
282
+ }
283
+ }
284
+
285
+ /**
286
+ * Create Configure Product
287
+ */
288
+ function create_product_configurable($configurable_product_id, $configurable_child_id)
289
+ {
290
+ $msg = "Parent conf Id:" . $configurable_product_id;
291
+ Mage::log($msg, $this->log_level, $this->log_filename);
292
+ $config_product = Mage::getModel('catalog/product')->load($configurable_product_id);
293
+ $new_ids = array();
294
+ $used_products = $config_product->getTypeInstance()->getUsedProductIds();
295
+
296
+ foreach ($used_products as $used_product) {
297
+ $current_ids[] = $used_product;
298
+ }
299
+
300
+ $current_ids[] = $configurable_child_id;
301
+ $current_ids = array_unique($current_ids);
302
+
303
+ foreach ($current_ids as $temp_id) {
304
+ parse_str("position=", $new_ids[$temp_id]);
305
+ }
306
+ $config_product->setConfigurableProductsData($new_ids)->save();
307
+ }
308
+
309
+ /**
310
+ * Create Configure Product super attributes
311
+ *
312
+ * @params $data array super attribute data array
313
+ *
314
+ * Note :: This is not the magento recomended way, as there are alot of API calls eecuted in order to save the
315
+ * single configurable product. Therefore writing the custom query in order to achieve the expected functionality.
316
+ */
317
+ public function create_configurable_product_super_attribute($data) {
318
+ $return = [];
319
+
320
+ foreach($data as $sku => $super_attributes) {
321
+ $product_id = Mage::getModel('catalog/product')->getIdBySku($sku);
322
+ if($product_id) {
323
+ $return[$product_id] = [];
324
+ foreach($super_attributes as $code => $pricing) {
325
+ $attribute = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', $code);
326
+ $attribute_id = $attribute->getId();
327
+
328
+ if($attribute_id) {
329
+ $return[$product_id][$code]['attribute_id'] = $attribute_id;
330
+ $values = Mage::getResourceModel('eav/entity_attribute_option_collection')
331
+ ->setStoreFilter($storeId)
332
+ ->setAttributeFilter($attribute_id)
333
+ ->toOptionArray();
334
+
335
+ $pricing = array_change_key_case($pricing);
336
+
337
+ foreach($values as $value) {
338
+ if(isset($pricing[strtolower($value['label'])])) {
339
+ $return[$product_id][$code]['pricing'][$value['value']] = $pricing[strtolower($value['label'])];
340
+ }
341
+ }
342
+ }
343
+ }
344
+ } else {
345
+ $return[$sku] = 'Product not found';
346
+ }
347
+ }
348
+
349
+ foreach($return as $product_id => $attributes) {
350
+ foreach($attributes as $code => $attribute) {
351
+ $attribute_id = $attribute['attribute_id'];
352
+ $product_super_attribute_id = $this->getProductSuperAttributeId($product_id, $attribute_id);
353
+
354
+ $value_id = $this->createCatalogProductSuperAttributeLabel($product_super_attribute_id, $code);
355
+
356
+ foreach($attribute['pricing'] as $value_index => $pricing_value) {
357
+ $this->createCatalogProductSuperAttributePricing($product_super_attribute_id, $value_index, $pricing_value);
358
+ }
359
+ }
360
+ }
361
+ return $return;
362
+ }
363
+
364
+
365
+ /**
366
+ * Inserting the pricing values corresponding to the configurable attributes
367
+ *
368
+ * @params $product_super_attribute_id int magento configurable product super attribute id
369
+ * @params $value_index int magento product attribute option id
370
+ * @params $pricing_value int magento configurable product price value
371
+ *
372
+ * Note :: This is not the magento recomended way, as there are alot of API calls eecuted in order to save the
373
+ * single configurable product. Therefore writing the custom query in order to achieve the expected functionality.
374
+ */
375
+ private function createCatalogProductSuperAttributePricing($product_super_attribute_id, $value_index, $pricing_value) {
376
+ $resource = Mage::getSingleton('core/resource');
377
+ $dbSource = $resource->getConnection('core_write');
378
+
379
+ $catalog_product_super_attribute_pricing = $resource->getTableName('catalog_product_super_attribute_pricing');
380
+
381
+ $sql = "SELECT * FROM `" . $catalog_product_super_attribute_pricing . "`
382
+ WHERE `product_super_attribute_id` = '" . $product_super_attribute_id . "'
383
+ and value_index = '" . $value_index . "' ";
384
+ $value_id = $dbSource->fetchOne($sql);
385
+
386
+ if($value_id) {
387
+ $sql = "update " . $catalog_product_super_attribute_pricing . "
388
+ set pricing_value = '".$pricing_value."'
389
+ WHERE `product_super_attribute_id` = '" . $product_super_attribute_id . "'
390
+ and value_index = '" . $value_index . "' ";
391
+ $dbSource->query($sql);
392
+ } else {
393
+ $sql = "Insert into " . $catalog_product_super_attribute_pricing . "(product_super_attribute_id, value_index, is_percent, pricing_value, website_id)
394
+ values('".$product_super_attribute_id."', '".$value_index."', '0', '".$pricing_value."', '0')";
395
+ $dbSource->query($sql);
396
+ }
397
+ }
398
+
399
+ /**
400
+ * Get the configurable product supper attribute id
401
+ *
402
+ * @params $product_id int magento product id
403
+ * @params $attribute_id int magento product attribute id
404
+ *
405
+ * Note :: This is not the magento recomended way, as there are alot of API calls eecuted in order to save the
406
+ * single configurable product. Therefore writing the custom query in order to achieve the expected functionality.
407
+ */
408
+ private function getProductSuperAttributeId($product_id, $attribute_id) {
409
+ $resource = Mage::getSingleton('core/resource');
410
+ $dbSource = $resource->getConnection('core_write');
411
+
412
+ $catalog_product_super_attribute = $resource->getTableName('catalog_product_super_attribute');
413
+
414
+ $sql = "SELECT * FROM `" . $catalog_product_super_attribute . "`
415
+ WHERE `product_id` = '" . $product_id . "'
416
+ and attribute_id = '" . $attribute_id . "' ";
417
+ $product_super_attribute_id = $dbSource->fetchOne($sql);
418
+ if($product_super_attribute_id) {
419
+ return $product_super_attribute_id;
420
+ } else {
421
+ $sql = "Insert into " . $catalog_product_super_attribute . "(product_id, attribute_id, position) values('".$product_id."', '".$attribute_id."', '0')";
422
+ $dbSource->query($sql);
423
+
424
+ $sql = "SELECT * FROM `" . $catalog_product_super_attribute . "`
425
+ WHERE `product_id` = '" . $product_id . "'
426
+ and attribute_id = '" . $attribute_id . "' ";
427
+ return $dbSource->fetchOne($sql);
428
+ }
429
+ }
430
+
431
+ /**
432
+ * Generating configurable product supper attribute label
433
+ *
434
+ * @params $product_super_attribute_id int magento configurable product super atribute id
435
+ * @params $value string attribute label
436
+ *
437
+ * Note :: This is not the magento recomended way, as there are alot of API calls eecuted in order to save the
438
+ * single configurable product. Therefore writing the custom query in order to achieve the expected functionality.
439
+ */
440
+ private function createCatalogProductSuperAttributeLabel($product_super_attribute_id, $value) {
441
+ $resource = Mage::getSingleton('core/resource');
442
+ $dbSource = $resource->getConnection('core_write');
443
+
444
+ $catalog_product_super_attribute_label = $resource->getTableName('catalog_product_super_attribute_label');
445
+
446
+ $sql = "SELECT * FROM `" . $catalog_product_super_attribute_label . "`
447
+ WHERE `product_super_attribute_id` = '" . $product_super_attribute_id . "'
448
+ and value = '" . $value . "' ";
449
+ $value_id = $dbSource->fetchOne($sql);
450
+ if($value_id) {
451
+ return $value_id;
452
+ } else {
453
+ $sql = "Insert into " . $catalog_product_super_attribute_label . "(product_super_attribute_id, store_id, value) values('".$product_super_attribute_id."', '0', '".$value."')";
454
+ $dbSource->query($sql);
455
+ }
456
+ }
457
+
458
+ /**
459
+ * Check Attribute Exists
460
+ */
461
+ function check_attribute_exists($attr_code)
462
+ {
463
+ $attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attr_code);
464
+
465
+ if ($attribute) {
466
+ return $attribute->getData('attribute_id');
467
+ } else {
468
+ return false;
469
+ }
470
+ }
471
+
472
+ /**
473
+ * a comprehensive delete function for products, checks all related tables for hanging entity_ids and
474
+ * does full clean
475
+ *
476
+ * relies on array of tables & corresponding product key; usually product_id or entity_id. affected
477
+ * tables varies by both Magento release and customizations to the store, ie. if a table is added
478
+ * by any extensions, it can be cleaned up easily through delete_full
479
+ *
480
+ * @param mixed $productId
481
+ * @param mixed $identifierType
482
+ **/
483
+ public function delete_full($productId, $identifierType = null)
484
+ // load array of tables & fields to check for matching data
485
+ {
486
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
487
+ $datetime = strftime('%Y-%m-%d %H:%M:%S', time());
488
+ $cnt = 0;
489
+ foreach ($this->product_tables as $table => $field) {
490
+ $table = Mage::getSingleton('core/resource')->getTableName($table);
491
+ $sql = "DELETE FROM " . $table . " WHERE " . $field . " = '" . (int) $productId . "'";
492
+ $msg = "Calling delete_full: sql = " . $sql;
493
+ Mage::log($msg, null, "product_api.log");
494
+ try {
495
+ $result = $write->query($sql);
496
+ $cnt++;
497
+ }
498
+ catch (Mage_Core_Exception $e) {
499
+ $msg = "error : " . $e->getMessage();
500
+ Mage::log($msg, null, "product_api.log", true);
501
+ $msg = 'inside delete full, not_deleted on table: ' . $table . ', product_id: ' . $productId;
502
+ $this->_fault($msg, $e->getMessage());
503
+ Mage::log($msg, null, "product_api.log", true);
504
+ }
505
+ }
506
+ return $cnt;
507
+ }
508
+
509
+ /**
510
+ * Add new attribute to a set
511
+ */
512
+ function add_configurable_attribute_to_default($attribute_set_name, $group_name, $attribute_code)
513
+ {
514
+ $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
515
+
516
+ //-------------- add attribute to set and group
517
+ $attribute_set_id = $setup->getAttributeSetId('catalog_product', $attribute_set_name);
518
+ $attribute_group_id = $setup->getAttributeGroupId('catalog_product', $attribute_set_id, $group_name);
519
+ $attribute_id = $setup->getAttributeId('catalog_product', $attribute_code);
520
+ $setup->addAttributeToSet('catalog_product', $attribute_set_id, $attribute_group_id, $attribute_id);
521
+ }
522
+
523
+ /**
524
+ * To check configured product exists or not
525
+ */
526
+ public function check_configured_exists($attr_id, $base_product_id)
527
+ {
528
+ $productTable = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity');
529
+ $sql = "select m.entity_id,m.type_id from " . $productTable . " m
530
+ left join catalog_product_entity_int mi ON m.entity_id = mi.entity_id
531
+ where mi.attribute_id = '" . (int) $attr_id . "'
532
+ and mi.value = '" . (int) $base_product_id . "'";
533
+ $prod = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchRow($sql);
534
+
535
+ if (!empty($prod)) {
536
+ $pid = $prod['entity_id'];
537
+ unset($prod);
538
+ return $pid;
539
+ } else {
540
+ return false;
541
+ }
542
+ }
543
+
544
+ /**
545
+ * public function to check configured product exists or not
546
+ */
547
+ public function check_configured_exists_by_group_string($attr_id, $groupString)
548
+ {
549
+ $productTable = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity');
550
+ $sql = "SELECT m.entity_id,m.type_id FROM " . $productTable . " m
551
+ LEFT JOIN catalog_product_entity_text mi ON m.entity_id = mi.entity_id
552
+ WHERE mi.attribute_id = :attr_id AND mi.value = :groupString ";
553
+ $binds = array(
554
+ 'attr_id' => $attr_id,
555
+ 'groupString' => $groupString
556
+ );
557
+ $prod = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchRow($sql, $binds);
558
+
559
+ if (!empty($prod)) {
560
+ $pid = $prod['entity_id'];
561
+ unset($prod);
562
+ return $pid;
563
+ } else {
564
+ return false;
565
+ }
566
+ }
567
+
568
+ /**
569
+ * update update_category_product table with this product_id and category_id
570
+ *
571
+ * @param mixed $entity_id
572
+ * @param int|array $cat_ids
573
+ */
574
+ public function update_category_product($entity_id, $cat_ids)
575
+ {
576
+ // Ensure $cat_ids is an array because we may receive an array
577
+ // No matter what, we're only dealing with the primary category here, and assuming its index is 0
578
+ if (!is_array($cat_ids)) {
579
+ $cat_ids = array($cat_ids);
580
+ }
581
+
582
+ $categoryProdTable = Mage::getSingleton('core/resource')->getTableName('catalog_category_product');
583
+ foreach ($cat_ids as $cat_id) {
584
+ $sql = sprintf("select * from " . $categoryProdTable . " WHERE product_id = '%d' AND category_id = '%d';", $entity_id, $cat_id);
585
+ $prod = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchAll($sql);
586
+ if (!empty($prod)) {
587
+ return true;
588
+ } else {
589
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
590
+ $datetime = strftime('%Y-%m-%d %H:%M:%S', time());
591
+ $sql = sprintf("INSERT INTO `" . $categoryProdTable . "` (product_id, category_id, position) VALUES ('%d', '%d', 0);", $entity_id, $cat_id);
592
+ $result = $write->query($sql);
593
+ }
594
+ }
595
+ return true;
596
+ }
597
+
598
+ /**
599
+ * update the catalog_category_product_index tables for this product and category
600
+ *
601
+ * @param mixed $prod_id
602
+ * @param int|array $cat_ids
603
+ * @param mixed $store_id
604
+ */
605
+ public function update_cat_prod_indx($prod_id, $cat_ids, $store_id = 1)
606
+ {
607
+ // $cat_ids will be assumed to be an array
608
+ if (!is_array($cat_ids)) {
609
+ $cat_ids = array($cat_ids);
610
+ }
611
+
612
+ $categoryTable = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity');
613
+ $categoryIndxTable = Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index');
614
+ $sql = sprintf("select * from " . $categoryTable . " WHERE entity_id ='%d' LIMIT 1", $cat_ids[0]);
615
+ $prod = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchAll($sql);
616
+
617
+ if (empty($prod)) {
618
+ echo "ERROR Category-Entity NOT found. \n";
619
+ return false;
620
+ }
621
+
622
+ $path1 = explode('/', $prod[0]['path']);
623
+
624
+ foreach ($path1 as $path) {
625
+ if ($path != 1) {
626
+ $is_parent = ($path == $cat_ids[0]) ? 1 : 0;
627
+
628
+ $sql = sprintf("select * from " . $categoryIndxTable . " WHERE product_id = '%d' AND category_id = '%d' AND store_id = '%d'", $prod_id, $path, $store_id);
629
+ $prod = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchAll($sql);
630
+
631
+ if (!empty($prod)) {
632
+ // skip
633
+ echo "Category-Product-Index confirmed. <br>\n";
634
+ } else {
635
+ // echo "no existing Category-Product found, continuing insert. <br>\n";
636
+ $w = Mage::getSingleton('core/resource')->getConnection('core_write');
637
+
638
+ $datetime = strftime('%Y-%m-%d %H:%M:%S', time());
639
+ $sql = "INSERT INTO `" . $categoryIndxTable . "` (product_id, category_id, position, store_id, is_parent, visibility) VALUES (%d, %d, 0, %d, %d, 4);";
640
+ $result = $w->query(sprintf($sql, $prod_id, $path, $store_id, $is_parent));
641
+ }
642
+ } // end $path !=1
643
+ }
644
+ return true;
645
+ }
646
+
647
+ /**
648
+ * Create New Product in magento
649
+ */
650
+ public function create_fast($type, $attr_set_id, $sku, $productData, $qty, $websites, $cat_id, $store = 0)
651
+ {
652
+ $this->log_filename = 'create_fast.log';
653
+ if ($this->enable_logs) {
654
+ $starttime = time();
655
+ $msg = "Called saleswarp_product_api -> create_fast";
656
+ $msg .= "\n TIMESTAMP CREATE START: " . time();
657
+ Mage::log($msg, $this->log_level, $this->log_filename);
658
+ }
659
+
660
+ $msg = "prod type=" . $type;
661
+ Mage::log($msg, $this->log_level, $this->log_filename);
662
+
663
+ try {
664
+ /**
665
+ * $out = array('status'=>"pass",
666
+ 'id'=>$entity_id,
667
+ 'msg'=>"passed insert into catalog_product_entity");
668
+ *
669
+ * @var mixed
670
+ */
671
+ $result = $this->fast_save($type, $sku, $productData, $qty, $attr_set_id, $websites, $cat_id);
672
+
673
+ // update category_ids
674
+ if ($result['status'] == "pass") {
675
+ $new_id = $result['id'];
676
+ $this->update_category_ids($new_id, $cat_id);
677
+ } else {
678
+ return $result;
679
+ }
680
+
681
+ if ($this->enable_logs) {
682
+ $msg = "After SAVE TIMESTAMP: " . time();
683
+ $msg .= "\n ELAPSE TIME: " . (time() - $starttime);
684
+ Mage::log($msg, $this->log_level, $this->log_filename);
685
+ }
686
+
687
+ }
688
+ catch (Mage_Core_Exception $e) {
689
+ if ($this->enable_logs) {
690
+ $msg = "EXCEPTION CAUGHT in CREATE_FAST. ErrorMsg = " . $e->getMessage();
691
+ Mage::log($msg, $this->log_level, $this->log_filename);
692
+ }
693
+ $this->_fault('data_invalid', $e->getMessage());
694
+ }
695
+ return $result;
696
+ }
697
+
698
+ /**
699
+ * use this to assign product to single or muliple category_ids
700
+ */
701
+ function update_category_ids($store_product_id, $category_ids)
702
+ {
703
+ $w = Mage::getSingleton('core/resource')->getConnection('core_write');
704
+
705
+ // Ensure we have an array for category_ids
706
+ if (!$category_ids) {
707
+ return false;
708
+ }
709
+
710
+ if (!is_array($category_ids)) {
711
+ $category_ids = array($category_ids);
712
+ }
713
+
714
+ $productTable = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity');
715
+ $sql = "UPDATE `" . $productTable . "`
716
+ SET `saleswarp_category_ids` = '" . (int) $category_ids[0] . "'
717
+ WHERE `entity_id` = '" . (int) $store_product_id . "'";
718
+ $result = $w->query($sql);
719
+ if (!$result) {
720
+ return false;
721
+ }
722
+
723
+ // Update Catalog_Category_Product
724
+ $r1 = $this->update_category_product($store_product_id, $category_ids);
725
+
726
+ // Update Catalog_Category_Product_Indx
727
+ $r2 = $this->update_cat_prod_indx($store_product_id, $category_ids);
728
+
729
+ return $r1 && $r2;
730
+ }
731
+
732
+ /**
733
+ * Update Product Qty to 1
734
+ *
735
+ */
736
+ function set_in_stock($store_product_id, $stock_id, $status)
737
+ {
738
+ $invStockItemTable = Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item');
739
+ $sql = "UPDATE " . $invStockItemTable . " SET is_in_stock = '1' WHERE product_id = '" . (int) $store_product_id . "'";
740
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
741
+ $connection->query($sql);
742
+ return true;
743
+ }
744
+
745
+ /**
746
+ * function get attibute details
747
+ */
748
+ function get_attribute_details($attribute_code)
749
+ {
750
+ $attribute_details = Mage::getSingleton("eav/config")->getAttribute("catalog_product", $attribute_code);
751
+ $options = $attribute_details->getSource()->getAllOptions(false);
752
+ return $options;
753
+ }
754
+
755
+ /**
756
+ * Set Product ATTRIBUTE
757
+ */
758
+ function set_product_config_attr($product_id, $configAttrCodes)
759
+ {
760
+ $configProduct = Mage::getModel("catalog/product")->load($product_id);
761
+ $attr_ids = [];
762
+ foreach ($configAttrCodes as $attrCode) {
763
+ $super_attribute= Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', $attrCode);
764
+ $attr_ids[] = $super_attribute->getId();
765
+ }
766
+ $configProduct->getTypeInstance()->setUsedProductAttributeIds($attr_ids);
767
+ $configurableAttributesData = $configProduct->getTypeInstance()->getConfigurableAttributesAsArray();
768
+ $configProduct->setCanSaveConfigurableAttributes(true);
769
+ $configProduct->setConfigurableAttributesData($configurableAttributesData);
770
+ $configProduct->save();
771
+ return true;
772
+ }
773
+
774
+ /**
775
+ * Save Product Data
776
+ */
777
+ function fast_save($product_type, $sku, $data, $qty = 0, $attribute_set_id = 4, $websites, $cat_ids, $store_id = 1, $entity_type_id = 10)
778
+ {
779
+ $entity_type_id = Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId();
780
+ if (!is_array($cat_ids)) {
781
+ $cat_ids = array(
782
+ $cat_ids
783
+ );
784
+ }
785
+
786
+ $w = Mage::getSingleton('core/resource')->getConnection('core_write');
787
+
788
+ $out = array(
789
+ 'status' => "fail",
790
+ 'id' => 0,
791
+ 'msg' => ""
792
+ );
793
+ $datetime = strftime('%Y-%m-%d %H:%M:%S', time());
794
+
795
+ if ($this->enable_logs) {
796
+ $msg = "Inside fast_save, calling first catalog_product_entity insert";
797
+ ;
798
+ Mage::log($msg, $this->log_level, $this->log_filename);
799
+ }
800
+
801
+ $productTable = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity');
802
+
803
+ $sql = "INSERT INTO `" . $productTable . "` (entity_id, entity_type_id, attribute_set_id,
804
+ type_id, sku, saleswarp_category_ids, created_at, updated_at, has_options) VALUES (NULL, %d, %d, '%s', '%s', %d, '%s', '%s', 0);";
805
+
806
+ $sql = sprintf($sql, $entity_type_id, $attribute_set_id, $product_type, $sku, $cat_ids[0], $datetime, $datetime);
807
+
808
+ Mage::log($sql, $this->log_level, $this->log_filename);
809
+ $result = $w->query($sql);
810
+
811
+ $result = $w->query(sprintf("select entity_id from " . $productTable . " where sku ='%s';", $sku));
812
+ if (!$result) {
813
+ if ($this->enable_logs) {
814
+ $msg = "FAILED: INSERT PRODUCT INTO CATALOG_PRODUCT ENTITY FAILED";
815
+ Mage::log($msg, $this->log_level, $this->log_filename);
816
+ }
817
+ return $out;
818
+ } else {
819
+ $row = $result->fetch(PDO::FETCH_ASSOC);
820
+ $entity_id = $row['entity_id'];
821
+ $out = array(
822
+ 'status' => "pass",
823
+ 'id' => $entity_id,
824
+ 'msg' => "passed insert into catalog_product_entity"
825
+ );
826
+ }
827
+
828
+ if ($this->enable_logs) {
829
+ $msg = "PASSED: INSERT PRODUCT INTO CATALOG_PRODUCT ENTITY ";
830
+ Mage::log($msg, $this->log_level, $this->log_filename);
831
+ }
832
+
833
+ if ($entity_id == null) {
834
+ var_dump($row);
835
+ die('epic fail');
836
+ }
837
+ $eavAttrTable = Mage::getSingleton('core/resource')->getTableName('eav_attribute');
838
+
839
+ foreach ($data as $code => $value) {
840
+ switch ($code) {
841
+ // Add special groups here
842
+ case "age_groups":
843
+ foreach ($value as $v) {
844
+ $code = "age_group";
845
+ $result = $w->query("SELECT attribute_id, backend_type, frontend_input
846
+ FROM `" . $eavAttrTable . "` WHERE `attribute_code` LIKE '" . $code . "'
847
+ AND entity_type_id = '" . $entity_type_id . "'");
848
+ $row = $result->fetch(PDO::FETCH_ASSOC);
849
+
850
+ $result = $this->save_attribute_multiselect($row, $entity_id, $entity_type_id, $code, $v, $store_id);
851
+ if ($result != "pass") {
852
+ $out = array(
853
+ 'status' => "fail",
854
+ 'id' => $entity_id,
855
+ 'msg' => "failed during age_group attribute save"
856
+ );
857
+ return $out;
858
+ }
859
+ }
860
+ break;
861
+ default:
862
+ if ($this->enable_logs) {
863
+ $msg = "Inserting attributes: attribute_code = " . $code . ", value = " . $value . ", entity_type_id = " . $entity_type_id;
864
+ Mage::log($msg, $this->log_level, $this->log_filename);
865
+ }
866
+
867
+ $result = $w->query("SELECT attribute_id, backend_type, frontend_input, is_user_defined FROM `" . $eavAttrTable . "`
868
+ WHERE `attribute_code` LIKE '" . $code . "'
869
+ AND entity_type_id = '" . $entity_type_id . "'");
870
+ $row = $result->fetch(PDO::FETCH_ASSOC);
871
+
872
+
873
+ if ($row['frontend_input'] == 'select') {
874
+ $result = $this->save_attribute_select($row, $entity_id, $entity_type_id, $code, $value, $store_id, $row['is_user_defined']);
875
+
876
+ if ($result != "pass") {
877
+ $out = array(
878
+ 'status' => "fail",
879
+ 'id' => $entity_id,
880
+ 'msg' => "failed during save_attribute_select for code: $code; value: $value"
881
+ );
882
+ return $out;
883
+ }
884
+
885
+ } elseif ($row['frontend_input'] == 'multiselect') {
886
+ $result = $this->save_attribute_multiselect($row, $entity_id, $entity_type_id, $code, $value, $store_id);
887
+ if ($result != "pass") {
888
+ $out = array(
889
+ 'status' => "fail",
890
+ 'id' => $entity_id,
891
+ 'msg' => "failed during save_attribute_multiselect for code: $code; value: $value"
892
+ );
893
+ return $out;
894
+ }
895
+ } else {
896
+ $result = $this->save_attribute($row, $entity_id, $entity_type_id, $code, $value, $store_id);
897
+ if ($result != "pass") {
898
+ $out = array(
899
+ 'status' => "fail",
900
+ 'id' => $entity_id,
901
+ 'msg' => "failed during save_attribute for code: $code; value: $value"
902
+ );
903
+ return $out;
904
+ }
905
+ }
906
+ break;
907
+
908
+ }
909
+ }
910
+
911
+ $invStockItemTable = Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item');
912
+
913
+ if ($qty > 0) {
914
+ try {
915
+ if ($this->enable_logs) {
916
+ $msg = "calling cataloginventory_stock_item insert";
917
+ ;
918
+ Mage::log($msg, $this->log_level, $this->log_filename);
919
+ }
920
+
921
+ $w->query("INSERT INTO `" . $invStockItemTable . "`
922
+ (`product_id` ,`stock_id`,qty,
923
+ is_in_stock,
924
+ manage_stock,
925
+ use_config_min_qty,
926
+ use_config_min_sale_qty,
927
+ use_config_backorders,
928
+ use_config_notify_stock_qty,
929
+ use_config_manage_stock)VALUES($entity_id,1,$qty,1,1,1,1,1,1,0)");
930
+
931
+ $this->update_inventory($entity_id, $qty, 0, 1, 1, 1);
932
+ }
933
+ catch (Exception $e) {
934
+ if ($this->enable_logs) {
935
+ $msg = "EXCEPTION CAUGHT in FAST_SAVE, cataloginventory_stock_item QTY > 0. ErrorMsg = " . $e->getMessage();
936
+ Mage::log($msg, $this->log_level, $this->log_filename);
937
+ }
938
+ $out = array(
939
+ 'status' => "fail",
940
+ 'id' => $entity_id,
941
+ 'msg' => "failed during update_inventory, Exception " . $e->getMessage()
942
+ );
943
+ return $out;
944
+ }
945
+ } else {
946
+ try {
947
+ $w->query("INSERT INTO `" . $invStockItemTable . "`
948
+ (`product_id` ,`stock_id`,qty,is_in_stock,manage_stock,use_config_min_qty,
949
+ use_config_min_sale_qty, use_config_backorders, use_config_notify_stock_qty,
950
+ use_config_manage_stock)VALUES($entity_id,1,$qty,0,1,1,1,1,1,0)");
951
+
952
+ $this->update_inventory($entity_id, 0, 0, 1, 1, 1);
953
+ }
954
+ catch (Exception $e) {
955
+ if ($this->enable_logs) {
956
+ $msg = "EXCEPTION CAUGHT in FAST_SAVE, cataloginventory_stock_item QTY = 0. ErrorMsg = " . $e->getMessage();
957
+ Mage::log($msg, $this->log_level, $this->log_filename);
958
+ }
959
+ $out = array(
960
+ 'status' => "fail",
961
+ 'id' => $entity_id,
962
+ 'msg' => "failed during update_inventory, Exception " . $e->getMessage()
963
+ );
964
+ return $out;
965
+ }
966
+ }
967
+
968
+ try {
969
+ foreach ($websites as $website_id) {
970
+ // sometimes the entity_id & website_id combo already exists as Magento
971
+ // does not do a good job cleaning via Magento Admin, check for existing
972
+ // and reuse it if it exists
973
+ if ($this->enable_logs) {
974
+ $msg = "checking for catalog_product_website exists for product_id: " . $entity_id . ", website_id = " . $website_id;
975
+ Mage::log($msg, $this->log_level, $this->log_filename);
976
+ }
977
+ $webTable = Mage::getSingleton('core/resource')->getTableName('catalog_product_website');
978
+ $sql = "select * from
979
+ " . $webTable . "
980
+ WHERE product_id = '" . (int) $entity_id . "'
981
+ AND website_id = '" . (int) $website_id . "'";
982
+ $chk10 = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchAll($sql);
983
+
984
+ if (empty($chk10)) {
985
+ if ($this->enable_logs) {
986
+ $msg = "calling catalog_product_website insert";
987
+ Mage::log($msg, $this->log_level, $this->log_filename);
988
+ }
989
+
990
+ $w->query("INSERT INTO `" . $webTable . "` (`product_id`,`website_id`)VALUES($entity_id, $website_id)");
991
+ }
992
+ }
993
+ }
994
+ catch (Exception $e) {
995
+ if ($this->enable_logs) {
996
+ $msg = "EXCEPTION CAUGHT in FAST_SAVE, catalog_product_website. ErrorMsg = " . $e->getMessage();
997
+ Mage::log($msg, $this->log_level, $this->log_filename);
998
+ }
999
+ $out = array(
1000
+ 'status' => "fail",
1001
+ 'id' => $entity_id,
1002
+ 'msg' => "failed during Website update, Exception " . $e->getMessage()
1003
+ );
1004
+ return $out;
1005
+ }
1006
+ return $out;
1007
+ }
1008
+
1009
+ /**
1010
+ * get media image gallery for a entity id
1011
+ * @params $entityId int Magento Product Id
1012
+ * @return product data or bool(false)
1013
+ */
1014
+ function get_product_image_collection($entityId)
1015
+ {
1016
+ $data = array();
1017
+ $collection = Mage::getModel('catalog/product')->load($entityId)->getMediaGalleryImages();
1018
+ if ($collection) {
1019
+ foreach ($collection as $img) {
1020
+ $data[] = $img->getData();
1021
+ }
1022
+ return $data;
1023
+ }
1024
+ return false;
1025
+ }
1026
+
1027
+ /**
1028
+ * get category ids for a entity id
1029
+ *
1030
+ * @params $entityId int Magento Product Id
1031
+ * @return array category ids
1032
+ */
1033
+ function get_category_for_product($entityId)
1034
+ {
1035
+ $prod = Mage::getModel('catalog/product')->load($entityId);
1036
+ $catIds = $prod->getCategoryIds();
1037
+ return $catIds;
1038
+ }
1039
+
1040
+ /**
1041
+ * get quantity by entity id
1042
+ *
1043
+ * @params $entityId int Magento Product Id
1044
+ * @return int quantity of product
1045
+ */
1046
+ function get_qty_by_product($entityId)
1047
+ {
1048
+ $prod = Mage::getModel('catalog/product')->load($entityId);
1049
+ $qty = Mage::getModel('cataloginventory/stock_item')->loadByProduct($prod)->getQty();
1050
+ return $qty;
1051
+ }
1052
+
1053
+
1054
+
1055
+ /**
1056
+ * function to get product by sku
1057
+ *
1058
+ * @params $mageSku string Magento Product Sku
1059
+ * @return array products data
1060
+ */
1061
+ function getProductBySKU($mageSku)
1062
+ {
1063
+ $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $mageSku);
1064
+ $data = $product->getData();
1065
+ return $data;
1066
+ }
1067
+
1068
+
1069
+
1070
+ /**
1071
+ * check product exists in magento
1072
+ *
1073
+ * @params $entity_id int Magento Product id
1074
+ * @return boolean
1075
+ */
1076
+ function check_prod_exists($entity_id)
1077
+ {
1078
+ $productTable = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity');
1079
+ $sql = "select entity_id from " . $productTable . "
1080
+ where entity_id = '" . (int) $entity_id . "'";
1081
+ $prod = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchRow($sql);
1082
+ if ($prod) {
1083
+ return true;
1084
+ } else {
1085
+ return false;
1086
+ }
1087
+ }
1088
+
1089
+ /**
1090
+ * Save product attribute value
1091
+ *
1092
+ * @params $entity_id int Magento Product id
1093
+ * @params $code string Magento product attribute code
1094
+ * @params $value string Magento product attribute value
1095
+ * @params $store_id int Magento Product store id
1096
+ * @return boolean
1097
+ */
1098
+ function rest_save_attribute($entity_id, $code, $value, $store_id)
1099
+ {
1100
+ $entity_type_id = Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId();
1101
+ $eavAttrTable = Mage::getSingleton('core/resource')->getTableName('eav_attribute');
1102
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
1103
+
1104
+ $sql = "SELECT attribute_id, backend_type, frontend_input FROM `" . $eavAttrTable . "`
1105
+ WHERE `attribute_code` LIKE :code
1106
+ AND entity_type_id = :entity_type_id ";
1107
+
1108
+ $binds = array(
1109
+ 'code' => $code,
1110
+ 'entity_type_id' => $entity_type_id
1111
+ );
1112
+
1113
+ $result = $read->query($sql, $binds);
1114
+
1115
+ $row = $result->fetch(PDO::FETCH_ASSOC);
1116
+ return $this->save_attribute($row, $entity_id, $entity_type_id, $code, $value, $store_id);
1117
+ }
1118
+
1119
+ /**
1120
+ * special attribute saves for select and multiselect types (frontend_type in Magento)
1121
+ *
1122
+ * @params $row string
1123
+ * @params $entity_id string Magento product id
1124
+ * @params $entity_type_id string Magento product type
1125
+ * @params $attribute_code string Magento product attribute code
1126
+ * @params $value string Magento product attribute value
1127
+ * @params $store_id int Magento Product store id
1128
+ * @return boolean
1129
+ */
1130
+ function save_attribute($row, $entity_id, $entity_type_id, $attribute_code, $value, $store_id)
1131
+ {
1132
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
1133
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
1134
+
1135
+ if ((!empty($row)) && ($row['backend_type'] != '') && ($row['backend_type'] != null)) {
1136
+
1137
+ $msg = "Backend_Type = " . $row['backend_type'];
1138
+ Mage::log($msg, $this->log_level, $this->log_filename);
1139
+
1140
+ // does this exist
1141
+ $productBakTable = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_' . $row['backend_type']);
1142
+ $sql = "SELECT * FROM `" . $productBakTable . "`
1143
+ WHERE attribute_id = :attribute_id
1144
+ AND entity_id = :entity_id
1145
+ AND store_id = 0
1146
+ AND entity_type_id = :entity_type_id ";
1147
+ $binds = array(
1148
+ 'attribute_id' => $row['attribute_id'],
1149
+ 'entity_id' => $entity_id,
1150
+ 'entity_type_id' => $entity_type_id
1151
+ );
1152
+
1153
+ $result = $read->query($sql, $binds);
1154
+ $chk = $result->fetch(PDO::FETCH_ASSOC);
1155
+
1156
+ if (empty($chk)) {
1157
+ // If key is in array $this->product_required_storeIds, then create an Admin store_id entry (store_id = 0)
1158
+ if (!empty($value) && $value != "") {
1159
+ $key1 = "catalog_product_entity_" . $row['backend_type'];
1160
+
1161
+
1162
+ if (array_key_exists($key1, $this->product_required_storeIds)) {
1163
+ $sql = "INSERT INTO `" . $productBakTable . "` (value_id, entity_type_id, attribute_id, store_id, entity_id,value)
1164
+ VALUES (NULL ,:etype,:attr,0,:eid,:val) ";
1165
+
1166
+ $binds = array(
1167
+ 'etype' => $entity_type_id,
1168
+ 'attr' => $row['attribute_id'],
1169
+ 'eid' => $entity_id,
1170
+ 'val' => $value
1171
+ );
1172
+
1173
+ $msg = "SQL QUERY = " . $sql;
1174
+ Mage::log($msg, $this->log_level, $this->log_filename);
1175
+ $write->query($sql, $binds);
1176
+ }
1177
+ }
1178
+ } else { // update
1179
+ $sql = "UPDATE `" . $productBakTable . "`
1180
+ SET value = :value
1181
+ WHERE value_id = :value_id ";
1182
+
1183
+ $binds = array(
1184
+ 'value' => $value,
1185
+ 'value_id' => $chk['value_id']
1186
+ );
1187
+
1188
+ $write->query($sql, $binds);
1189
+ }
1190
+ // does this exist
1191
+
1192
+ $sql = "SELECT * FROM `" . $productBakTable . "`
1193
+ WHERE attribute_id = :attribute_id
1194
+ AND entity_id = :entity_id
1195
+ AND store_id = :store_id
1196
+ AND entity_type_id = :entity_type_id ";
1197
+
1198
+ $binds = array(
1199
+ 'attribute_id' => $row['attribute_id'],
1200
+ 'entity_id' => $entity_id,
1201
+ 'store_id' => $store_id,
1202
+ 'entity_type_id' => $entity_type_id
1203
+ );
1204
+
1205
+ $result = $write->query($sql, $binds);
1206
+ $chk = $result->fetch(PDO::FETCH_ASSOC);
1207
+
1208
+ if (empty($chk)) {
1209
+ if (!empty($value) && $value != "") {
1210
+ $sql = "INSERT INTO `" . $productBakTable . "` (value_id, entity_type_id, attribute_id, store_id, entity_id, value)
1211
+ VALUES (NULL, :etype, :attr, :sid, :eid, :val) ";
1212
+
1213
+ $binds = array(
1214
+ 'etype' => $entity_type_id,
1215
+ 'attr' => $row['attribute_id'],
1216
+ 'sid' => $store_id,
1217
+ 'eid' => $entity_id,
1218
+ 'val' => $value
1219
+ );
1220
+
1221
+ $msg = "SQL QUERY = " . $sql;
1222
+ Mage::log($msg, $this->log_level, $this->log_filename);
1223
+
1224
+ $write->query($sql, $binds);
1225
+ }
1226
+ } else { // update
1227
+ if (!empty($value) && $value != "") {
1228
+ $sql = "UPDATE `" . $productBakTable . "`
1229
+ SET value = :value
1230
+ WHERE value_id = :value_id ";
1231
+
1232
+ $binds = array(
1233
+ 'value' => $value,
1234
+ 'value_id' => $chk['value_id']
1235
+ );
1236
+
1237
+ $result = $write->query($sql, $binds);
1238
+ }
1239
+ }
1240
+
1241
+ }
1242
+ return "pass";
1243
+ }
1244
+
1245
+ /**
1246
+ * special attribute saves for select and multiselect types (frontend_type in Magento)
1247
+ *
1248
+ * @params $row string
1249
+ * @params $entity_id string Magento product id
1250
+ * @params $entity_type_id string Magento product type
1251
+ * @params $attribute_code string Magento product attribute code
1252
+ * @params $value string Magento product attribute value
1253
+ * @params $store_id int Magento Product store id
1254
+ * @params $isCustomAttribute boolean Is the field a custom attribute or core field
1255
+ * @return boolean
1256
+ */
1257
+ function save_attribute_select($row, $entity_id, $entity_type_id, $attribute_code, $value, $store_id, $isCustomAttribute = null)
1258
+ {
1259
+ $result = "pass";
1260
+
1261
+ // The switch statment is not really nedded anymore becuase we just need to know
1262
+ // if the field is a custom or core field, but keeping it there for backwards compatibility
1263
+ // if the $isCustomAttribute is not passed in
1264
+ if (null !== $isCustomAttribute && !$isCustomAttribute) {
1265
+ $this->save_attribute($row, $entity_id, $entity_type_id, $attribute_code, $value, $store_id);
1266
+ return $result;
1267
+ }
1268
+
1269
+ // Magento hard codes values for some selects
1270
+ switch ($attribute_code) {
1271
+ case "tax_class_id":
1272
+ $this->save_attribute($row, $entity_id, $entity_type_id, $attribute_code, $value, $store_id);
1273
+ break;
1274
+ case "status":
1275
+ $this->save_attribute($row, $entity_id, $entity_type_id, $attribute_code, $value, $store_id);
1276
+ break;
1277
+ case "visibility":
1278
+ $this->save_attribute($row, $entity_id, $entity_type_id, $attribute_code, $value, $store_id);
1279
+ break;
1280
+ case "enable_googlecheckout":
1281
+ $this->save_attribute($row, $entity_id, $entity_type_id, $attribute_code, $value, $store_id);
1282
+ break;
1283
+ default:
1284
+ $result = $this->save_attribute_select2($row, $entity_id, $entity_type_id, $attribute_code, $value, $store_id);
1285
+ break;
1286
+ }
1287
+ return $result;
1288
+ }
1289
+
1290
+ /**
1291
+ * special attribute saves for select and multiselect types (frontend_type in Magento)
1292
+ *
1293
+ * @params $row string
1294
+ * @params $entity_id string Magento product id
1295
+ * @params $entity_type_id string Magento product type
1296
+ * @params $attribute_code string Magento product attribute code
1297
+ * @params $value string Magento product attribute value
1298
+ * @params $store_id int Magento Product store id
1299
+ * @return string pass
1300
+ */
1301
+ function save_attribute_select2($row, $entity_id, $entity_type_id, $attribute_code, $value, $store_id)
1302
+ {
1303
+ $eavAttrTable = Mage::getSingleton('core/resource')->getTableName('eav_attribute');
1304
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
1305
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
1306
+
1307
+ // First get attribute_id
1308
+ $sql = "SELECT attribute_id, backend_type FROM " . $eavAttrTable . "
1309
+ WHERE attribute_code LIKE :attribute_code
1310
+ AND entity_type_id = :entity_type_id ";
1311
+
1312
+ $binds = array(
1313
+ 'attribute_code' => $attribute_code,
1314
+ 'entity_type_id' => $entity_type_id
1315
+ );
1316
+ $result = $read->query($sql, $binds);
1317
+ $row1 = $result->fetch(PDO::FETCH_ASSOC);
1318
+
1319
+ $eavAttrOptTable = Mage::getSingleton('core/resource')->getTableName('eav_attribute_option');
1320
+ $eavAttrOptValTable = Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value');
1321
+
1322
+ $sql = "SELECT EAOV.*, EAO.*
1323
+ FROM " . $eavAttrOptValTable . " as EAOV, " . $eavAttrOptTable . " as EAO
1324
+ WHERE EAO.attribute_id = :attribute_id
1325
+ AND EAOV.option_id = EAO.option_id";
1326
+
1327
+ $binds = array(
1328
+ 'attribute_id' => $row1['attribute_id']
1329
+ );
1330
+ $result = $read->query($sql, $binds);
1331
+ $row2 = $result->fetchAll(); // correct, returns all option_values in array
1332
+
1333
+ // LOOK FOR A MATCH, THEN ADD THIS OPTION TO THE PRODUCT
1334
+ $match = false;
1335
+ $matchId = null;
1336
+ $value = trim($value);
1337
+
1338
+ foreach ($row2 as $selectOption) {
1339
+ if (strcasecmp($selectOption['value'], $value) == 0) {
1340
+ $match = true;
1341
+ $matchId = $selectOption['option_id'];
1342
+ }
1343
+ }
1344
+
1345
+ // if we coulden't find a matching value by checking the label name
1346
+ // attempt to find matching option ID
1347
+ if (!$match) {
1348
+ foreach ($row2 as $selectOption) {
1349
+ if ($value == $selectOption['option_id']) {
1350
+ $match = true;
1351
+ $matchId = $selectOption['option_id'];
1352
+ }
1353
+ }
1354
+ }
1355
+
1356
+ if ($match) {
1357
+ // IF Match
1358
+ // catalog_product_index_eav.value - one for each value
1359
+
1360
+ // query for existing entry in catalog_product_index_eav
1361
+ $prodIndxEavTable = Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav');
1362
+
1363
+ $sql = "SELECT * FROM " . $prodIndxEavTable . "
1364
+ WHERE attribute_id = :attribute_id
1365
+ AND entity_id = :entity_id
1366
+ AND value = :matchId
1367
+ AND store_id = :store_id ";
1368
+ $binds = array(
1369
+ 'attribute_id' => $row1['attribute_id'],
1370
+ 'entity_id' => $entity_id,
1371
+ 'matchId' => $matchId,
1372
+ 'store_id' => $store_id
1373
+ );
1374
+
1375
+ $result = $read->query($sql, $binds);
1376
+ $chk2 = $result->fetch(PDO::FETCH_ASSOC);
1377
+
1378
+ if (empty($chk2)) { // none, existing, insert it
1379
+ if (!empty($matchId) && $matchId != "") {
1380
+ $sql = "INSERT INTO " . $prodIndxEavTable . "(entity_id, attribute_id, store_id, value )
1381
+ VALUES (:entity_id, :attribute_id, :store_id, :value)";
1382
+ $binds = array(
1383
+ 'entity_id' => $entity_id,
1384
+ 'attribute_id' => $row1['attribute_id'],
1385
+ 'store_id' => $store_id,
1386
+ 'value' => $matchId
1387
+ );
1388
+ $result = $write->query($sql, $binds);
1389
+ }
1390
+ } else {
1391
+ if (!empty($matchId) && $matchId != "") {
1392
+ $sql = "UPDATE " . $prodIndxEavTable . "
1393
+ SET value = :value
1394
+ WHERE entity_id = :entity_id
1395
+ AND store_id = :store_id
1396
+ AND attribute_id = :attribute_id ";
1397
+ $binds = array(
1398
+ 'entity_id' => $entity_id,
1399
+ 'attribute_id' => $row1['attribute_id'],
1400
+ 'store_id' => $store_id,
1401
+ 'value' => $matchId
1402
+ );
1403
+ $result = $write->query($sql, $binds);
1404
+ }
1405
+ }
1406
+
1407
+ // Insert Select into catalog_product_ent_int
1408
+ // query for existing entry in catalog_product_index_eav
1409
+ $productIntTable = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int');
1410
+ $sql = "SELECT * FROM " . $productIntTable . "
1411
+ WHERE attribute_id = :attribute_id
1412
+ AND entity_id = :entity_id
1413
+ AND store_id = 0 ";
1414
+
1415
+ $binds = array(
1416
+ 'entity_id' => $entity_id,
1417
+ 'attribute_id' => $row1['attribute_id']
1418
+ );
1419
+
1420
+ $result = $read->query($sql, $binds);
1421
+ // AND value = '" . $matchId . "'");
1422
+ $chk3 = $result->fetch(PDO::FETCH_ASSOC);
1423
+
1424
+ if (empty($chk3)) { // none, existing, insert it
1425
+ if (!empty($matchId) && $matchId != "") {
1426
+ $sql = "INSERT INTO " . $productIntTable . " (value_id, entity_type_id, attribute_id, store_id, entity_id, value)
1427
+ VALUES (NULL, :entity_type_id, :attribute_id, 0, :entity_id, :matchId)";
1428
+
1429
+ $binds = array(
1430
+ 'entity_type_id' => $entity_type_id,
1431
+ 'attribute_id' => $row1['attribute_id'],
1432
+ 'entity_id' => $entity_id,
1433
+ 'matchId' => $matchId
1434
+ );
1435
+ $result = $write->query($sql, $binds);
1436
+ }
1437
+ } else { //update it
1438
+ if (!empty($matchId) && $matchId != "") {
1439
+ $sql = "UPDATE " . $productIntTable . "
1440
+ SET value = :value
1441
+ WHERE value_id = :value_id ";
1442
+
1443
+ $binds = array(
1444
+ 'value' => $matchId,
1445
+ 'value_id' => $chk3['value_id']
1446
+ );
1447
+ $result = $write->query($sql, $binds);
1448
+ }
1449
+ }
1450
+ } else { // NO MATCH, LOG IT IN MISSING OPTION VALUES LOG
1451
+ if (!empty($value) && ($value != " " || $value != "")) {
1452
+ $msg = "<h2>This OPTION is not defined in your storefront and may need added manually,
1453
+ you need to review your Magento attributes for consistency.</h2><br>";
1454
+ $msg .= "<h1>OPTION: " . $attribute_code . "</h1><h1>VALUE = " . $value . "</h1><hr>";
1455
+ }
1456
+ }
1457
+ return "pass";
1458
+ }
1459
+
1460
+ /**
1461
+ * special attribute saves for select and multiselect types (frontend_type in Magento)
1462
+ *
1463
+ * @params $row string
1464
+ * @params $entity_id string Magento product id
1465
+ * @params $entity_type_id string Magento product type
1466
+ * @params $attribute_code string Magento product attribute code
1467
+ * @params $value string Magento product attribute value
1468
+ * @params $store_id int Magento Product store id
1469
+ * @return string pass
1470
+ */
1471
+ function save_attribute_multiselect($row, $entity_id, $entity_type_id, $attribute_code, $value, $store_id)
1472
+ {
1473
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
1474
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
1475
+
1476
+ // First get attribute_id, but
1477
+ $eavAttrTable = Mage::getSingleton('core/resource')->getTableName('eav_attribute');
1478
+
1479
+ $sql = "SELECT attribute_id, backend_type FROM " . $eavAttrTable . "
1480
+ WHERE attribute_code LIKE :attribute_code
1481
+ AND entity_type_id = :entity_type_id ";
1482
+
1483
+ $binds = array(
1484
+ 'attribute_code' => $attribute_code,
1485
+ 'entity_type_id' => $entity_type_id
1486
+ );
1487
+ $result = $read->query($sql, $binds);
1488
+ $row1 = $result->fetch(PDO::FETCH_ASSOC);
1489
+
1490
+ $eavAttrOptTable = Mage::getSingleton('core/resource')->getTableName('eav_attribute_option');
1491
+ $eavAttrOptValTable = Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value');
1492
+ $sql = "SELECT EAOV.*, EAO.*
1493
+ FROM " . $eavAttrOptValTable . " as EAOV, " . $eavAttrOptTable . " as EAO
1494
+ WHERE EAO.attribute_id = :attribute_id
1495
+ AND EAOV.option_id = EAO.option_id";
1496
+ $binds = array(
1497
+ 'attribute_id' => $row1['attribute_id']
1498
+ );
1499
+
1500
+ $result = $read->query($sql, $binds);
1501
+ $row2 = $result->fetchAll(); // correct, returns all option_values in array
1502
+
1503
+ // LOOK FOR A MATCH, THEN ADD THIS OPTION TO THE PRODUCT
1504
+ $match = false;
1505
+ $matchId = null;
1506
+ foreach ($row2 as $r) {
1507
+ if (strcasecmp($r['value'], rtrim(ltrim($value))) == 0) {
1508
+ $match = true;
1509
+ $matchId = $r['option_id'];
1510
+ }
1511
+ }
1512
+
1513
+ $productVarTable = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar');
1514
+
1515
+ if ($match && $matchId != null) {
1516
+ // IF Match
1517
+ // catalog_product_entity_varchar.value - one listing with all options
1518
+ // catalog_product_index_eav.value - one for each value
1519
+ // STORE 0 first
1520
+ // query for existing entry in catalog_product_entity_varchar
1521
+ $sql = "SELECT * FROM " . $productVarTable . "
1522
+ WHERE attribute_id = :attribute_id
1523
+ AND entity_type_id = :entity_type_id
1524
+ AND entity_id = :entity_id
1525
+ AND store_id = 0";
1526
+ $binds = array(
1527
+ 'attribute_id' => $row1['attribute_id'],
1528
+ 'entity_type_id' => $entity_type_id,
1529
+ 'entity_id' => $entity_id
1530
+ );
1531
+ $result = $read->query($sql, $binds);
1532
+ $chk = $result->fetch(PDO::FETCH_ASSOC);
1533
+
1534
+ if (empty($chk)) { // none, existing, insert it
1535
+ if (!empty($value) && $value != "") {
1536
+ echo "doing insert on catalog_product_entity_varchar: " . " attribute_id = " . $row1['attribute_id'] . " entity_id = " . $entity_id . " store_id = 0" . " value/MatchId = " . $matchId . "<br>";
1537
+
1538
+ $sql = "INSERT INTO " . $productVarTable . " (value_id, entity_type_id, attribute_id, store_id, entity_id, value)
1539
+ VALUES (NULL, :entity_type_id, :attribute_id, 0, :entity_id, :value)";
1540
+
1541
+ $binds = array(
1542
+ 'entity_type_id' => $entity_type_id,
1543
+ 'attribute_id' => $row1['attribute_id'],
1544
+ 'entity_id' => $entity_id,
1545
+ 'value' => $matchId
1546
+ );
1547
+
1548
+ $result = $write->query($sql, $binds);
1549
+ }
1550
+ } else { // explode the value, see if this one is included, update if needed
1551
+ $vals = explode(',', $chk['value']);
1552
+
1553
+ $match2 = false;
1554
+ foreach ($vals as $val) {
1555
+ if (strcasecmp($val, $matchId) == 0) {
1556
+ $match2 = true;
1557
+ }
1558
+ }
1559
+
1560
+ // If Match2 == false; append it
1561
+ if ($match2 == false) {
1562
+ if (!empty($matchId) && $matchId != "") {
1563
+ $new_value = $chk['value'] . "," . $matchId;
1564
+
1565
+ echo "doing UPDATE on catalog_product_entity_varchar with new_value = " . $new_value . "<br>";
1566
+
1567
+ $sql = "UPDATE " . $productVarTable . "
1568
+ SET value = :value
1569
+ WHERE value_id = :value_id ";
1570
+
1571
+ $binds = array(
1572
+ 'value' => $new_value,
1573
+ 'value_id' => $chk['value_id']
1574
+ );
1575
+ $result = $write->query($sql, $binds);
1576
+ }
1577
+ } else {
1578
+ echo "found match in catalog_entity_varchar for StoreID: 0, no update needed. <br> ";
1579
+ }
1580
+
1581
+ }
1582
+
1583
+
1584
+ // TARGET STORE NEXT
1585
+ // query for existing entry in catalog_product_entity_varchar
1586
+ $sql = "SELECT * FROM " . $productVarTable . "
1587
+ WHERE attribute_id = :attribute_id
1588
+ AND entity_type_id = :entity_type_id
1589
+ AND entity_id = :entity_id
1590
+ AND store_id = :store_id ";
1591
+ $binds = array(
1592
+ 'attribute_id' => $row1['attribute_id'],
1593
+ 'entity_type_id' => $entity_type_id,
1594
+ 'entity_id' => $entity_id,
1595
+ 'store_id' => $store_id
1596
+ );
1597
+
1598
+ $result = $read->query($sql, $binds);
1599
+ $chk = $result->fetch(PDO::FETCH_ASSOC);
1600
+
1601
+ if (empty($chk)) { // none, existing, insert it
1602
+ if (!empty($value) && $value != "") {
1603
+ echo "doing insert on catalog_product_entity_varchar: " . " attribute_id = " . $row1['attribute_id'] . " entity_id = " . $entity_id . " store_id = " . $store_id . " value/MatchId = " . $matchId . "<br>";
1604
+
1605
+ $sql = "INSERT INTO " . $productVarTable . " (value_id, entity_type_id, attribute_id, store_id, entity_id, value)
1606
+ VALUES (NULL, :entity_type_id, :attribute_id, :store_id, :entity_id, :value)";
1607
+ $binds = array(
1608
+ 'entity_type_id' => $entity_type_id,
1609
+ 'attribute_id' => $row1['attribute_id'],
1610
+ 'store_id' => $store_id,
1611
+ 'entity_id' => $entity_id,
1612
+ 'value' => $matchId
1613
+ );
1614
+ $result = $write->query($sql, $binds);
1615
+ }
1616
+ } else { // explode the value, see if this one is included, update if needed
1617
+ $vals = explode(',', $chk['value']);
1618
+
1619
+ $match2 = false;
1620
+ foreach ($vals as $val) {
1621
+ if (strcasecmp($val, $matchId) == 0) {
1622
+ $match2 = true;
1623
+ }
1624
+ }
1625
+
1626
+ // If Match2 == false; append it
1627
+ if ($match2 == false) {
1628
+ if (!empty($matchId) && $matchId != "") {
1629
+ $new_value = $chk['value'] . "," . $matchId;
1630
+
1631
+ echo "doing UPDATE on catalog_product_entity_varchar with new_value = " . $new_value . "<br>";
1632
+
1633
+ $sql = "UPDATE " . $productVarTable . "
1634
+ SET value = '" . $new_value . "'
1635
+ WHERE value_id = :value_id ";
1636
+
1637
+ $binds = array(
1638
+ 'value_id' => $chk['value_id']
1639
+ );
1640
+ $result = $write->query($sql, $binds);
1641
+ }
1642
+
1643
+ } else {
1644
+ echo "found match in catalog_entity_varchar for StoreID: $store_id, no update needed. <br> ";
1645
+ }
1646
+
1647
+ }
1648
+ $prodIndxEavTable = Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav');
1649
+
1650
+ // query for existing entry in catalog_product_index_eav
1651
+ $sql = "SELECT * FROM " . $prodIndxEavTable . "
1652
+ WHERE attribute_id = :attribute_id
1653
+ AND entity_id = :entity_id
1654
+ AND value = :value
1655
+ AND store_id = :store_id ";
1656
+
1657
+ $binds = array(
1658
+ 'attribute_id' => $row1['attribute_id'],
1659
+ 'entity_id' => $entity_id,
1660
+ 'value' => $matchId,
1661
+ 'store_id' => $store_id
1662
+ );
1663
+ $result = $read->query($sql, $binds);
1664
+ $chk2 = $result->fetch(PDO::FETCH_ASSOC);
1665
+
1666
+ if (empty($chk2)) { // none, existing, insert it
1667
+ if (!empty($matchId) && $matchId != "") {
1668
+ echo "doing insert on catalog_product_index_eav,
1669
+ entity_id = $entity_id, attribute = " . $row1['attribute_id'] . " store_id = $store_id , matchid = $matchId<br>";
1670
+
1671
+ $sql = "INSERT INTO " . $prodIndxEavTable . "(entity_id, attribute_id, store_id, value)
1672
+ VALUES(:entity_id, :attribute_id, :store_id, :value)";
1673
+ $binds = array(
1674
+ 'entity_id' => $entity_id,
1675
+ 'attribute_id' => $row1['attribute_id'],
1676
+ 'store_id' => $store_id,
1677
+ 'value' => $matchId
1678
+ );
1679
+ $result = $write->query($sql, $binds);
1680
+ echo "complete catalog_product_index_eav insert<br>";
1681
+ }
1682
+ } else { // exist, update only
1683
+ if (!empty($matchId) && $matchId != "") {
1684
+ echo "doing UDPATE on catalog_product_index_eav,
1685
+ entity_id = $entity_id, attribute = " . $row1['attribute_id'] . " store_id = $store_id , matchid = $matchId<br>";
1686
+ $sql = "UPDATE " . $prodIndxEavTable . "
1687
+ SET value = :value
1688
+ WHERE entity_id = :entity_id
1689
+ AND store_id = :store_id
1690
+ AND attribute_id = :attribute_id ";
1691
+
1692
+ $binds = array(
1693
+ 'value' => $matchId,
1694
+ 'entity_id' => $entity_id,
1695
+ 'store_id' => $store_id,
1696
+ 'attribute_id' => $row1['attribute_id']
1697
+ );
1698
+ $result = $write->query($sql, $binds);
1699
+ echo "complete catalog_product_index_eav<br>";
1700
+ }
1701
+ }
1702
+ } else { // NO MATCH, LOG IT IN MISSING OPTION VALUES LOG
1703
+ if (!empty($value) && ($value != " " || $value != "")) {
1704
+ $msg = "<h2>This OPTION is not defined in your storefront and may need added manually,
1705
+ you need to review your Magento attributes for consistency.</h2><br>";
1706
+ $msg .= "<h1>OPTION: " . $attribute_code . "</h1><h1> VALUE = " . $value . "</h1><hr>";
1707
+ echo $msg;
1708
+ Mage::log($msg, $this->log_level, "ERROR_saleswarp_product_api-missing_options.log");
1709
+ }
1710
+ }
1711
+ return "pass";
1712
+ }
1713
+
1714
+ /**
1715
+ * update product name
1716
+ *
1717
+ * @param $store_prod_id int product id
1718
+ * @param $store_id int store id
1719
+ * @param $value string attribute value
1720
+ * @param $code string attribute code
1721
+ * @param $entity_type_id int entity type id
1722
+ * @return
1723
+ */
1724
+ function update_name($store_prod_id, $store_id, $value, $code = "name", $entity_type_id = 4)
1725
+ {
1726
+ $eavAttrTable = Mage::getSingleton('core/resource')->getTableName('eav_attribute');
1727
+
1728
+ if ($this->enable_logs) {
1729
+ $msg = "Updating Name: attribute_code = " . $code . ", value = " . $value . ", entity_type_id = " . $entity_type_id;
1730
+ Mage::log($msg, $this->log_level, $this->log_filename);
1731
+ }
1732
+
1733
+ $w = Mage::getSingleton('core/resource')->getConnection('core_write');
1734
+ $datetime = strftime('%Y-%m-%d %H:%M:%S', time());
1735
+
1736
+ $result = $w->query("SELECT attribute_id, backend_type, frontend_input FROM `" . $eavAttrTable . "`
1737
+ WHERE `attribute_code` LIKE '" . $code . "'
1738
+ AND entity_type_id = '" . $entity_type_id . "'");
1739
+ $row = $result->fetch(PDO::FETCH_ASSOC);
1740
+
1741
+ $result = $this->save_attribute($row, $store_prod_id, $entity_type_id, $code, $value, $store_id);
1742
+ if ($result != "pass") {
1743
+ return "fail";
1744
+ }
1745
+ return $result;
1746
+ }
1747
+
1748
+ /**
1749
+ * update product name
1750
+ *
1751
+ * @param $store_prod_id int product id
1752
+ * @param $store_id int store id
1753
+ * @param $value string attribute value
1754
+ * @param $code string attribute code
1755
+ * @param $entity_type_id int entity type id
1756
+ * @return
1757
+ */
1758
+ function update_description($store_prod_id, $store_id, $value, $code = "description", $entity_type_id = 4)
1759
+ {
1760
+ $eavAttrTable = Mage::getSingleton('core/resource')->getTableName('eav_attribute');
1761
+
1762
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
1763
+
1764
+ $sql = "SELECT attribute_id, backend_type, frontend_input FROM `" . $eavAttrTable . "`
1765
+ WHERE `attribute_code` LIKE :attribute_code
1766
+ AND entity_type_id = :entity_type_id ";
1767
+
1768
+ $binds = array(
1769
+ 'attribute_code' => $attribute_code,
1770
+ 'entity_type_id' => $entity_type_id
1771
+ );
1772
+ $result = $read->query($sql, $binds);
1773
+ $row = $result->fetch(PDO::FETCH_ASSOC);
1774
+
1775
+
1776
+ $result = $this->save_attribute($row, $store_prod_id, $entity_type_id, $code, $value, $store_id);
1777
+ if ($result != "pass") {
1778
+ return "fail";
1779
+ }
1780
+ return $result;
1781
+ }
1782
+
1783
+ /**
1784
+ * update product name
1785
+ *
1786
+ * @param $store_prod_id int product id
1787
+ * @param $store_id int store id
1788
+ * @param $value string attribute value
1789
+ * @param $code string attribute code
1790
+ * @param $entity_type_id int entity type id
1791
+ * @return
1792
+ */
1793
+ function update_short_description($store_prod_id, $store_id, $value, $code = "short_description", $entity_type_id = 4)
1794
+ {
1795
+ $eavAttrTable = Mage::getSingleton('core/resource')->getTableName('eav_attribute');
1796
+
1797
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
1798
+
1799
+ $sql = "SELECT attribute_id, backend_type, frontend_input FROM `" . $eavAttrTable . "`
1800
+ WHERE `attribute_code` LIKE :attribute_code
1801
+ AND entity_type_id = :entity_type_id ";
1802
+
1803
+ $binds = array(
1804
+ 'attribute_code' => $attribute_code,
1805
+ 'entity_type_id' => $entity_type_id
1806
+ );
1807
+ $result = $read->query($sql, $binds);
1808
+
1809
+ $row = $result->fetch(PDO::FETCH_ASSOC);
1810
+
1811
+
1812
+ $result = $this->save_attribute($row, $store_prod_id, $entity_type_id, $code, $value, $store_id);
1813
+ if ($result != "pass") {
1814
+ return "fail";
1815
+ }
1816
+ return $result;
1817
+ }
1818
+
1819
+ /**
1820
+ * update product price
1821
+ *
1822
+ * @param $store_prod_id int product id
1823
+ * @param $store_id int store id
1824
+ * @param $msrp float market selling price
1825
+ * @param $saleprice float sale price
1826
+ * @param $salefrom date sale from date
1827
+ * @param $saleto date sale to date
1828
+ * @param $entity_type_id int entity type id
1829
+ * @return
1830
+ */
1831
+ function update_prices($store_prod_id, $store_id, $msrp, $saleprice, $salefrom = null, $saleto = null, $entity_type_id = 4)
1832
+ {
1833
+ $eavAttrTable = Mage::getSingleton('core/resource')->getTableName('eav_attribute');
1834
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
1835
+ $datetime = strftime('%Y-%m-%d %H:%M:%S', time());
1836
+
1837
+ // Price first
1838
+ $code = "price";
1839
+ $sql = "SELECT attribute_id, backend_type, frontend_input FROM `" . $eavAttrTable . "`
1840
+ WHERE `attribute_code` LIKE :attribute_code
1841
+ AND entity_type_id = :entity_type_id ";
1842
+
1843
+ $binds = array(
1844
+ 'attribute_code' => $code,
1845
+ 'entity_type_id' => $entity_type_id
1846
+ );
1847
+ $result = $read->query($sql, $binds);
1848
+ $row = $result->fetch(PDO::FETCH_ASSOC);
1849
+
1850
+ $result = $this->save_attribute($row, $store_prod_id, $entity_type_id, $code, $msrp, $store_id);
1851
+
1852
+ if ($result != "pass") {
1853
+ return "fail";
1854
+ }
1855
+ // SalePrice
1856
+ $code = "special_price";
1857
+ $sql = "SELECT attribute_id, backend_type, frontend_input FROM `" . $eavAttrTable . "`
1858
+ WHERE `attribute_code` LIKE :attribute_code
1859
+ AND entity_type_id = :entity_type_id ";
1860
+
1861
+ $binds = array(
1862
+ 'attribute_code' => $code,
1863
+ 'entity_type_id' => $entity_type_id
1864
+ );
1865
+ $result = $read->query($sql, $binds);
1866
+ $row = $result->fetch(PDO::FETCH_ASSOC);
1867
+
1868
+ $result = $this->save_attribute($row, $store_prod_id, $entity_type_id, $code, $saleprice, $store_id);
1869
+ if ($result != "pass") {
1870
+ return "fail";
1871
+ }
1872
+
1873
+ if ($salefrom != null) { // special_from_date
1874
+ $code = "special_from_date";
1875
+ $sql = "SELECT attribute_id, backend_type, frontend_input FROM `" . $eavAttrTable . "`
1876
+ WHERE `attribute_code` LIKE :attribute_code
1877
+ AND entity_type_id = :entity_type_id ";
1878
+
1879
+ $binds = array(
1880
+ 'attribute_code' => $code,
1881
+ 'entity_type_id' => $entity_type_id
1882
+ );
1883
+ $result = $read->query($sql, $binds);
1884
+ $row = $result->fetch(PDO::FETCH_ASSOC);
1885
+
1886
+ $result = $this->save_attribute($row, $store_prod_id, $entity_type_id, $code, $salefrom, $store_id);
1887
+ if ($result != "pass") {
1888
+ return "fail";
1889
+ }
1890
+ }
1891
+
1892
+ if ($saleto != null) {
1893
+ // special_from_date
1894
+ $code = "special_to_date";
1895
+ $sql = "SELECT attribute_id, backend_type, frontend_input FROM `" . $eavAttrTable . "`
1896
+ WHERE `attribute_code` LIKE :attribute_code
1897
+ AND entity_type_id = :entity_type_id ";
1898
+
1899
+ $binds = array(
1900
+ 'attribute_code' => $code,
1901
+ 'entity_type_id' => $entity_type_id
1902
+ );
1903
+ $result = $read->query($sql, $binds);
1904
+ $row = $result->fetch(PDO::FETCH_ASSOC);
1905
+
1906
+ $result = $this->save_attribute($row, $store_prod_id, $entity_type_id, $code, $saleto, $store_id);
1907
+ if ($result != "pass") {
1908
+ return "fail";
1909
+ }
1910
+ }
1911
+
1912
+ return $result;
1913
+ }
1914
+
1915
+ /**
1916
+ * update codes
1917
+ *
1918
+ * @param $store_prod_id int product id
1919
+ * @param $store_id int store id
1920
+ * @param $codes array attribute and value
1921
+ * @param $entity_type_id int entity type id
1922
+ * @return
1923
+ */
1924
+ function update_codes($store_prod_id, $store_id, $codes, $entity_type_id = 4)
1925
+ {
1926
+ $eavAttrTable = Mage::getSingleton('core/resource')->getTableName('eav_attribute');
1927
+
1928
+ $pass = "pass";
1929
+ $entity_id = $store_prod_id;
1930
+
1931
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
1932
+
1933
+ foreach ($codes as $code => $value) {
1934
+
1935
+ $sql = "SELECT attribute_id, backend_type, frontend_input FROM `" . $eavAttrTable . "`
1936
+ WHERE `attribute_code` LIKE :attribute_code
1937
+ AND entity_type_id = :entity_type_id ";
1938
+
1939
+ $binds = array(
1940
+ 'attribute_code' => $code,
1941
+ 'entity_type_id' => $entity_type_id
1942
+ );
1943
+ $result = $read->query($sql, $binds);
1944
+ $row = $result->fetch(PDO::FETCH_ASSOC);
1945
+
1946
+ $result = $this->save_attribute($row, $entity_id, $entity_type_id, $code, $value, $store_id);
1947
+ if ($result != "pass") {
1948
+ return "fail";
1949
+ }
1950
+
1951
+ }
1952
+ return $pass;
1953
+
1954
+ }
1955
+
1956
+
1957
+ /**
1958
+ * update attributes
1959
+ *
1960
+ * @param $store_prod_id int product id
1961
+ * @param $store_id int store id
1962
+ * @param $attributes array attribute and value
1963
+ * @param $entity_type_id int entity type id
1964
+ * @return
1965
+ */
1966
+ function update_attributes($store_prod_id, $store_id, $attributes, $entity_type_id = 4)
1967
+ {
1968
+ $eavAttrTable = Mage::getSingleton('core/resource')->getTableName('eav_attribute');
1969
+
1970
+
1971
+ $result = "pass";
1972
+ $entity_id = $store_prod_id;
1973
+
1974
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
1975
+ $datetime = strftime('%Y-%m-%d %H:%M:%S', time());
1976
+
1977
+ foreach ($attributes as $code => $value) {
1978
+
1979
+ switch ($code) { // Add special groups here
1980
+ case "age_groups":
1981
+ foreach ($value as $v) {
1982
+ if (!empty($v) && $v != '') {
1983
+ $code = "age_group";
1984
+
1985
+ $sql = "SELECT attribute_id, backend_type, frontend_input FROM `" . $eavAttrTable . "`
1986
+ WHERE `attribute_code` LIKE :attribute_code
1987
+ AND entity_type_id = :entity_type_id ";
1988
+
1989
+ $binds = array(
1990
+ 'attribute_code' => $code,
1991
+ 'entity_type_id' => $entity_type_id
1992
+ );
1993
+ $result = $read->query($sql, $binds);
1994
+ $row = $result->fetch(PDO::FETCH_ASSOC);
1995
+ if ($this->enable_logs) {
1996
+ $msg = "calling save_attribute_multiselect for Age Groups, Code : " . $code . "; Value: " . $v;
1997
+ Mage::log($msg, $this->log_level, "saleswarp_update_products");
1998
+ }
1999
+
2000
+ $result = $this->save_attribute_multiselect($row, $entity_id, $entity_type_id, $code, $v, $store_id);
2001
+ if ($result != "pass") {
2002
+ return "fail";
2003
+ }
2004
+ }
2005
+ }
2006
+ break;
2007
+ default:
2008
+ if (!empty($value) && $value != '') {
2009
+
2010
+ $sql = "SELECT attribute_id, backend_type, frontend_input, is_user_defined FROM `" . $eavAttrTable . "`
2011
+ WHERE `attribute_code` LIKE :attribute_code
2012
+ AND entity_type_id = :entity_type_id ";
2013
+
2014
+ $binds = array(
2015
+ 'attribute_code' => $code,
2016
+ 'entity_type_id' => $entity_type_id
2017
+ );
2018
+ $result = $read->query($sql, $binds);
2019
+ $row = $result->fetch(PDO::FETCH_ASSOC);
2020
+
2021
+ if ($row['frontend_input'] == 'select') {
2022
+
2023
+ $result = $this->save_attribute_select($row, $entity_id, $entity_type_id, $code, $value, $store_id, $row['is_user_defined']);
2024
+ if ($result != "pass") {
2025
+ return "fail";
2026
+ }
2027
+
2028
+ } elseif ($row['frontend_input'] == 'multiselect') {
2029
+
2030
+ $result = $this->save_attribute_multiselect($row, $entity_id, $entity_type_id, $code, $value, $store_id);
2031
+ if ($result != "pass") {
2032
+ return "fail";
2033
+ }
2034
+
2035
+ } else {
2036
+ $result = $this->save_attribute($row, $entity_id, $entity_type_id, $code, $value, $store_id);
2037
+ if ($result != "pass") {
2038
+ return "fail";
2039
+ }
2040
+ }
2041
+ }
2042
+ break;
2043
+ }
2044
+ }
2045
+ return $result;
2046
+ }
2047
+
2048
+ /**
2049
+ * light weight inventory update when product is detected out of stock or discontinued and full
2050
+ * update info (cogs, weight, price) not longer apply
2051
+ *
2052
+ * @param mixed $store_prod_id
2053
+ * @param mixed $store_qty
2054
+ * @param mixed $discontinued
2055
+ * @param mixed $status
2056
+ * @return mixed
2057
+ */
2058
+ function update_inventory($store_prod_id, $store_qty, $discontinued, $attribute_id, $status = 1, $website_id = 1, $stock_id = 1)
2059
+ {
2060
+ $invStockItemTable = Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item');
2061
+ $invStockStatusTable = Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_status');
2062
+ $prodDateTimeTable = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_datetime');
2063
+
2064
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
2065
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
2066
+
2067
+ if ($store_qty <= 0 || $discontinued == 1) {
2068
+ $status = 0;
2069
+ } else {
2070
+ $status = 1;
2071
+ }
2072
+
2073
+ if (is_null($store_qty)) {
2074
+ $store_qty = 0;
2075
+ $status = 0;
2076
+ }
2077
+
2078
+ $sql = "UPDATE " . $invStockItemTable . "
2079
+ SET qty = :qty,
2080
+ is_in_stock = :is_in_stock
2081
+ WHERE product_id = :product_id ";
2082
+ $binds = array(
2083
+ 'qty' => $store_qty,
2084
+ 'is_in_stock' => $status,
2085
+ 'product_id' => $store_prod_id
2086
+ );
2087
+ $result = $write->query($sql, $binds);
2088
+
2089
+ $sql = "SELECT * FROM " . $invStockStatusTable . "
2090
+ WHERE product_id = :product_id
2091
+ AND website_id = :website_id
2092
+ AND stock_id = :stock_id ";
2093
+ $binds = array(
2094
+ 'product_id' => $store_prod_id,
2095
+ 'website_id' => $website_id,
2096
+ 'stock_id' => $stock_id
2097
+ );
2098
+ $chk = $read->fetchRow($sql, $binds);
2099
+ if (empty($chk)) {
2100
+ $sql = "INSERT INTO " . $invStockStatusTable . "
2101
+ SET qty = :qty,
2102
+ stock_status = :stock_status,
2103
+ stock_id = :stock_id,
2104
+ website_id = :website_id,
2105
+ product_id = :product_id ";
2106
+
2107
+ $binds = array(
2108
+ 'qty' => $store_qty,
2109
+ 'stock_status' => $status,
2110
+ 'stock_id' => $stock_id,
2111
+ 'website_id' => $website_id,
2112
+ 'product_id' => $store_prod_id
2113
+ );
2114
+ $result2 = $write->query($sql, $binds);
2115
+ } else { // do update
2116
+ $sql = "UPDATE " . $invStockStatusTable . "
2117
+ SET qty = :qty, stock_status = :stock_status
2118
+ WHERE product_id = :product_id ";
2119
+ $binds = array(
2120
+ 'qty' => $store_qty,
2121
+ 'stock_status' => $status,
2122
+ 'product_id' => $store_prod_id
2123
+ );
2124
+ $result2 = $write->query($sql, $binds);
2125
+ }
2126
+
2127
+ // Update saleswarp_last_inventory_update fields
2128
+ $sql = "SELECT * FROM " . $prodDateTimeTable . "
2129
+ WHERE entity_type_id = 4
2130
+ AND entity_id = $store_prod_id
2131
+ AND attribute_id = $attribute_id";
2132
+ $chk = $read->fetchAll($sql);
2133
+
2134
+ if (empty($chk)) { // insert it
2135
+ $sql = "INSERT INTO " . $prodDateTimeTable . "
2136
+ SET value = NOW(),
2137
+ entity_type_id = 4,
2138
+ store_id = 0,
2139
+ entity_id = $store_prod_id,
2140
+ attribute_id = $attribute_id";
2141
+ $insert_result = $write->query($sql);
2142
+ } else { // update it
2143
+ $sql = "UPDATE " . $prodDateTimeTable . "
2144
+ SET value = NOW()
2145
+ WHERE entity_type_id = 4
2146
+ AND entity_id = $store_prod_id
2147
+ AND attribute_id = $attribute_id";
2148
+ $update_result = $write->query($sql);
2149
+ }
2150
+
2151
+ if ($result && $result2) {
2152
+ return "Saved inventory record";
2153
+ } else {
2154
+ return "FAILED save() inventory update";
2155
+ }
2156
+ }
2157
+
2158
+ /**
2159
+ * get default store root category id
2160
+ */
2161
+ public function get_default_store_root_cat_id()
2162
+ {
2163
+ $coreStorGroupTable = Mage::getSingleton('core/resource')->getTableName('core_store_group');
2164
+ $coreWebTable = Mage::getSingleton('core/resource')->getTableName('core_website');
2165
+
2166
+ $sql = "SELECT s.root_category_id FROM " . $coreStorGroupTable . " s
2167
+ LEFT JOIN " . $coreWebTable . " w ON s.website_id=w.website_id
2168
+ WHERE w.is_default=1";
2169
+ $prods = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchRow($sql);
2170
+ return $prods['root_category_id'];
2171
+ }
2172
+
2173
+ /**
2174
+ * superadmin feature, don't keep on in production or you will regret it...
2175
+ */
2176
+ function super_scary_fast_magento_delete_all_products()
2177
+ {
2178
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
2179
+ $cnt = 0;
2180
+ $write->query('SET FOREIGN_KEY_CHECKS = 0');
2181
+ foreach ($this->product_truncate_all_tables as $t1) {
2182
+ $tmpTable = Mage::getSingleton('core/resource')->getTableName($t1);
2183
+ // truncate this table
2184
+ echo "truncating table : " . $t1 . "<br>";
2185
+ $result2 = $write->query('TRUNCATE ' . $tmpTable . ';');
2186
+ $cnt++;
2187
+ }
2188
+ $w1->query('SET FOREIGN_KEY_CHECKS = 1');
2189
+ return "products have been cleared, # tables cleared = " . $cnt;
2190
+ }
2191
+ }
app/code/local/Saleswarp/Publish/Model/Product/Attribute/Api.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Saleswarp_Publish_Model_Product_Attribute_Api extends Saleswarp_Oms_Model_Product_Attribute_Api
3
+ {
4
+ /**
5
+ * Add manufacturer
6
+ **/
7
+ function add_manf($attributeId = 102, $saleswarp_manf_name, $store_id = 0)
8
+ {
9
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
10
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
11
+
12
+ $sql = "select option_id from eav_attribute_option_value
13
+ where value = :saleswarp_manf_name AND store_id = :store_id ";
14
+
15
+ $binds = array(
16
+ 'saleswarp_manf_name' => $saleswarp_manf_name,
17
+ 'store_id' => $store_id
18
+ );
19
+ $data = $read->fetchAll($sql, $binds);
20
+
21
+ if (count($data) == 0) {
22
+ $write->query("insert into eav_attribute_option (attribute_id) values (" . (int) $attributeId . ")");
23
+ $option_id = $connection->lastInsertId();
24
+ $sql = "insert into eav_attribute_option_value(option_id,value,store_id)
25
+ values(:option_id, :saleswarp_manf_name, :store_id)";
26
+
27
+ $binds = array(
28
+ 'option_id' => $option_id,
29
+ 'saleswarp_manf_name' => $saleswarp_manf_name,
30
+ 'store_id' => $store_id
31
+ );
32
+ $write->query($sql, $binds);
33
+ } else {
34
+ $option_id = $data[0]['option_id'];
35
+ }
36
+ return $option_id;
37
+ }
38
+ }
app/code/local/Saleswarp/Publish/Model/Product/Attribute/Media/Api.php ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Saleswarp_Publish_Model_Product_Attribute_Media_Api extends Saleswarp_Oms_Model_Product_Attribute_Media_Api
3
+ {
4
+ /**
5
+ * QUICK Update image data
6
+ * CAUTION: removed check for existing image, useful for mass ports
7
+ *
8
+ * @author David Potts, 6th Street Inc.
9
+ *
10
+ * @param int|string $productId
11
+ * @param string $file
12
+ * @param array $data
13
+ * @param string|int $store
14
+ * @return boolean
15
+ */
16
+ public function quick_update($attr_id, $productId, $file, $img_type, $position = 0, $store = 0)
17
+ {
18
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
19
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
20
+
21
+ $result = true;
22
+ $sql = "select value_id from catalog_product_entity_media_gallery
23
+ where attribute_id = :attrId
24
+ and value = :file
25
+ and entity_id = :productId ";
26
+ $binds = array(
27
+ 'attrId' => $attr_id,
28
+ 'file' => $file,
29
+ 'productId' => $productId
30
+ );
31
+ $data = $read->fetchAll($sql, $binds);
32
+
33
+ if (count($data) == 0) {
34
+ if ($img_type == 'image' || $img_type == 'alt_image') {
35
+ // only include image & alt_image in media gallery
36
+ $disable = 0;
37
+ } else {
38
+ $disable = 1;
39
+ }
40
+
41
+ $sql = "insert into catalog_product_entity_media_gallery(value_id, attribute_id, entity_id, value)
42
+ values(value_id, :attrId, :productId, :file)";
43
+
44
+ $write->query($sql, $binds);
45
+ $value_id = $write->lastInsertId();
46
+
47
+ $sql = "insert into catalog_product_entity_media_gallery_value(value_id, store_id, label, position, disabled)
48
+ values(:valueId, :store, :imgType, :position, :disable)";
49
+ unset($binds);
50
+ $binds = array(
51
+ 'valueId' => $value_id,
52
+ 'store' => $store,
53
+ 'imgType' => $img_type,
54
+ 'position' => $position,
55
+ 'disable' => $disable
56
+ );
57
+ $write->query($sql, $binds);
58
+
59
+ // put in thumbnail & base references
60
+ switch ($img_type) {
61
+ case "image":
62
+ $upd1 = $this->update_entity_varchar("4", "85", $store, $productId, $file);
63
+ // check store 0 as
64
+ $upd2 = $this->update_entity_varchar("4", "85", "0", $productId, $file);
65
+
66
+ if ($upd1 == false || $upd2 == false) {
67
+ $result = false;
68
+ }
69
+ break;
70
+ case "thumbnail":
71
+ $upd1 = $this->update_entity_varchar("4", "87", $store, $productId, $file);
72
+ $upd2 = $this->update_entity_varchar("4", "87", "0", $productId, $file);
73
+ if ($upd1 == false || $upd2 == false) {
74
+ $result = false;
75
+ }
76
+ break;
77
+ case "small_image":
78
+ $upd1 = $this->update_entity_varchar("4", "86", $store, $productId, $file);
79
+ $upd2 = $this->update_entity_varchar("4", "86", "0", $productId, $file);
80
+ if ($upd1 == false || $upd2 == false) {
81
+ $result = false;
82
+ }
83
+ break;
84
+ default:
85
+ $upd1 = $this->update_entity_varchar("4", "85", $store, $productId, $file);
86
+ $upd2 = $this->update_entity_varchar("4", "85", "0", $productId, $file);
87
+ if ($upd1 == false || $upd2 == false) {
88
+ $result = false;
89
+ }
90
+ break;
91
+ }
92
+ }
93
+ return $result;
94
+ }
95
+
96
+ protected function update_entity_varchar($entity_type_id, $attribute_id, $store_id, $entity_id, $value)
97
+ {
98
+ $result = true;
99
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
100
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
101
+ $sql = "select value_id from catalog_product_entity_varchar
102
+ where entity_type_id = :entityTypeId
103
+ and attribute_id = :attributeId
104
+ and store_id = :storeId
105
+ and entity_id = :entityId ";
106
+
107
+ $binds = array(
108
+ 'entityTypeId' => $entity_type_id,
109
+ 'attributeId' => $attribute_id,
110
+ 'storeId' => $store_id,
111
+ 'entityId' => $entity_id
112
+ );
113
+
114
+ $data1 = $read->fetchRow($sql, $binds);
115
+ if (empty($data1)) {
116
+ $sql = "insert into catalog_product_entity_varchar(value_id, entity_type_id, attribute_id, store_id, entity_id, value)
117
+ values(value_id, :entityTypeId, :attributeId, :storeId, :entityId, :value) ";
118
+ $binds = array(
119
+ 'entityTypeId' => $entity_type_id,
120
+ 'attributeId' => $attribute_id,
121
+ 'storeId' => $store_id,
122
+ 'entityId' => $entity_id,
123
+ 'value' => $value
124
+ );
125
+ $qresult = $write->query($sql, $binds);
126
+ if ($qresult == false) {
127
+ $result = false;
128
+ }
129
+ } else {
130
+ // do an update only
131
+ $value_id = $data1['value_id'];
132
+ $sql = "UPDATE catalog_product_entity_varchar
133
+ SET
134
+ entity_type_id = :entityTypeId,
135
+ attribute_id = :attributeId,
136
+ store_id = :storeId,
137
+ entity_id = :entityId,
138
+ value = :value
139
+ WHERE value_id = :valueId LIMIT 1";
140
+ $binds = array(
141
+ 'entityTypeId' => $entity_type_id,
142
+ 'attributeId' => $attribute_id,
143
+ 'storeId' => $store_id,
144
+ 'entityId' => $entity_id,
145
+ 'value' => $value,
146
+ 'valueId' => $value_id
147
+ );
148
+ $qresult = $write->query($sql, $binds);
149
+ }
150
+ return $result;
151
+ }
152
+ }
153
+ ?>
app/code/local/Saleswarp/Publish/etc/config.xml ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Saleswarp_Publish>
5
+ <version>0.1.0</version>
6
+ </Saleswarp_Publish>
7
+ </modules>
8
+ <global>
9
+ <helpers>
10
+ <publish>
11
+ <class>Saleswarp_Publish_Helper</class>
12
+ </publish>
13
+ </helpers>
14
+ <models>
15
+ <publish>
16
+ <class>Saleswarp_Publish_Model</class>
17
+ </publish>
18
+ <oms>
19
+ <rewrite>
20
+ <config_api>Saleswarp_Publish_Model_Config_Api</config_api>
21
+ <product_api>Saleswarp_Publish_Model_Product_Api</product_api>
22
+ <category_api>Saleswarp_Publish_Model_Category_Api</category_api>
23
+ <customer_api>Saleswarp_Publish_Model_Customer_Api</customer_api>
24
+ <product_attribute_api>Saleswarp_Publish_Model_Product_Attribute_Media_Api</product_attribute_api>
25
+ <product_attribute_media_api>Saleswarp_Publish_Model_Product_Attribute_Media_Api</product_attribute_media_api>
26
+ </rewrite>
27
+ </oms>
28
+ </models>
29
+ </global>
30
+ </config>
app/code/local/Saleswarp/WhitelistIP/Helper/Data.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ class Saleswarp_WhitelistIP_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ }
5
+
app/code/local/Saleswarp/WhitelistIP/controllers/FastapiController.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once Mage::getModuleDir('controllers', 'Saleswarp_Oms') . DS . "FastapiController.php";
3
+
4
+ class Saleswarp_WhitelistIP_FastapiController extends Saleswarp_Oms_FastapiController {
5
+
6
+ /**
7
+ * Authentication API request
8
+ *
9
+ * @params string hash key
10
+ * @return bool(trur or false)
11
+ */
12
+ public function ApiAuthentication($hash = null)
13
+ {
14
+ if(empty($hash)) {
15
+ $this->authError = 'No hash key supplied';
16
+ return false;
17
+ } else {
18
+ $mageHash = Mage::getStoreConfig('oms/registration/key');
19
+ $useIpWhitelist = Mage::getStoreConfig('oms/ipwhitelist/enable');
20
+ $allowedIPs = Mage::getStoreConfig('oms/ipwhitelist/list');
21
+
22
+ // get user ip address
23
+ $remoteIP = Mage::helper('core/http')->getRemoteAddr(false);
24
+ if (!empty($mageHash) && $hash == $mageHash) {
25
+ if ($useIpWhitelist && !in_array($remoteIP, explode(',',$allowedIPs))) {
26
+ $this->authError = 'IP not allowed';
27
+ return false;
28
+ }
29
+ return true;
30
+ } else {
31
+ $this->authError = 'Incorrect Hash key';
32
+ return false;
33
+ }
34
+ }
35
+ }
36
+ }
app/code/local/Saleswarp/WhitelistIP/etc/config.xml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Saleswarp_WhitelistIP>
5
+ <version>0.1.0</version>
6
+ </Saleswarp_WhitelistIP>
7
+ </modules>
8
+ <frontend>
9
+ <routers>
10
+ <oms>
11
+ <args>
12
+ <modules>
13
+ <saleswarp_whitelistip before="Saleswarp_Oms">Saleswarp_WhitelistIP</saleswarp_whitelistip>
14
+ </modules>
15
+ </args>
16
+ </oms>
17
+ </routers>
18
+ </frontend>
19
+ </config>
app/code/local/Saleswarp/WhitelistIP/etc/system.xml ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <oms translate="label">
5
+ <groups>
6
+ <ipwhitelist translate="label">
7
+ <label>IP Whitelist</label>
8
+ <frontend_type>text</frontend_type>
9
+ <sort_order>100</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>0</show_in_website>
12
+ <show_in_store>0</show_in_store>
13
+ <fields>
14
+ <enable translate="label">
15
+ <label>Enable IP Whitelist</label>
16
+ <frontend_type>select</frontend_type>
17
+ <source_model>adminhtml/system_config_source_yesno</source_model>
18
+ <sort_order>10</sort_order>
19
+ <show_in_default>1</show_in_default>
20
+ <show_in_website>0</show_in_website>
21
+ <show_in_store>0</show_in_store>
22
+ </enable>
23
+ <list translate="label">
24
+ <label>Allowed IPs:</label>
25
+ <frontend_type>text</frontend_type>
26
+ <sort_order>20</sort_order>
27
+ <show_in_default>1</show_in_default>
28
+ <show_in_website>0</show_in_website>
29
+ <show_in_store>0</show_in_store>
30
+ <comment>Enter IP List( 8.8.8.8, 4.4.4.4)</comment>
31
+ </list>
32
+ </fields>
33
+ </ipwhitelist>
34
+ </groups>
35
+ </oms>
36
+ </sections>
37
+ </config>
app/design/adminhtml/default/default/template/oms/form/saleswarp.phtml CHANGED
@@ -1,17 +1,17 @@
1
- <div class="form-list" id="payment_form_<?php echo $this->getMethodCode() ?>" style="display:none;">
2
- <div>
3
- <label><?php echo $this->__('Transction No') ?>*</label>
4
- <span>
5
- <input type="text" title="<?php echo $this->__('Transction No') ?>" name="payment[transction_no]" value="<?php echo $this->htmlEscape($this->getInfoData('transction_no')) ?>" />
6
- </span>
7
- </div>
8
- <div>
9
- <label><?php echo $this->__('Payment Method') ?>*</label>
10
- <span>
11
- <input type="text" title="<?php echo $this->__('Payment Method') ?>" name="payment[payment_method]" value="<?php echo $this->htmlEscape($this->getInfoData('payment_method')) ?>" />
12
- </span>
13
- </div>
14
- </div>
15
- <div>
16
- <?php echo $this->getMethod()->getConfigData('message');?>
17
  </div>
1
+ <div class="form-list" id="payment_form_<?php echo $this->getMethodCode() ?>" style="display:none;">
2
+ <div>
3
+ <label><?php echo $this->__('Transction No') ?>*</label>
4
+ <span>
5
+ <input type="text" title="<?php echo $this->__('Transction No') ?>" name="payment[transction_no]" value="<?php echo $this->htmlEscape($this->getInfoData('transction_no')) ?>" />
6
+ </span>
7
+ </div>
8
+ <div>
9
+ <label><?php echo $this->__('Payment Method') ?>*</label>
10
+ <span>
11
+ <input type="text" title="<?php echo $this->__('Payment Method') ?>" name="payment[payment_method]" value="<?php echo $this->htmlEscape($this->getInfoData('payment_method')) ?>" />
12
+ </span>
13
+ </div>
14
+ </div>
15
+ <div>
16
+ <?php echo $this->getMethod()->getConfigData('message');?>
17
  </div>
app/design/adminhtml/default/default/template/oms/system/config/button.phtml CHANGED
@@ -1,36 +1,36 @@
1
- <?php if($this->isKeyAvailable()) { ?>
2
- <?php $data = $this->getKeyData(); ?>
3
- <a href="<?php echo $data['create_url']; ?>" target="_blank">Create New Account</a>
4
- &nbsp;|&nbsp;
5
- <a href="<?php echo $data['login_url']; ?>" target="_blank">Login to existing Account</a>
6
- <?php } else { ?>
7
- <script type="text/javascript">
8
- //<![CDATA[
9
- function getKey() {
10
- new Ajax.Request('<?php echo $this->getAjaxCheckUrl() ?>', {
11
- method: 'get',
12
- onSuccess: function(transport){
13
- var data = transport.responseText.evalJSON(true);
14
- if (data.success == 1) {
15
- $('layer_get_key').innerHTML = "";
16
- $('layer_get_key_links').style.display = 'block';
17
- $('oms_registration_key').value = data.key;
18
- configForm.submit();
19
- } else {
20
- alert('Error while making the key request, kindly confirm that the api URL and other details under custom variables.');
21
- }
22
- }
23
- });
24
- }
25
- //]]>
26
- </script>
27
- <div id="layer_get_key">
28
- <?php echo $this->getButtonHtml() ?>
29
- </div>
30
- <div id="layer_get_key_links" style="display:none;">
31
- <?php $data = $this->getKeyData(); ?>
32
- <a href="<?php echo $data['create_url']; ?>" target="_blank">Create New Account</a>
33
- &nbsp;|&nbsp;
34
- <a href="<?php echo $data['login_url']; ?>" target="_blank">Login to existing Account</a>
35
- </div>
36
  <?php } ?>
1
+ <?php if($this->isKeyAvailable()) { ?>
2
+ <?php $data = $this->getKeyData(); ?>
3
+ <a href="<?php echo $data['create_url']; ?>" target="_blank">Create New Account</a>
4
+ &nbsp;|&nbsp;
5
+ <a href="<?php echo $data['login_url']; ?>" target="_blank">Login to existing Account</a>
6
+ <?php } else { ?>
7
+ <script type="text/javascript">
8
+ //<![CDATA[
9
+ function getKey() {
10
+ new Ajax.Request('<?php echo $this->getAjaxCheckUrl() ?>', {
11
+ method: 'get',
12
+ onSuccess: function(transport){
13
+ var data = transport.responseText.evalJSON(true);
14
+ if (data.success == 1) {
15
+ $('layer_get_key').innerHTML = "";
16
+ $('layer_get_key_links').style.display = 'block';
17
+ $('oms_registration_key').value = data.key;
18
+ configForm.submit();
19
+ } else {
20
+ alert('Error while making the key request, kindly confirm that the api URL and other details under custom variables.');
21
+ }
22
+ }
23
+ });
24
+ }
25
+ //]]>
26
+ </script>
27
+ <div id="layer_get_key">
28
+ <?php echo $this->getButtonHtml() ?>
29
+ </div>
30
+ <div id="layer_get_key_links" style="display:none;">
31
+ <?php $data = $this->getKeyData(); ?>
32
+ <a href="<?php echo $data['create_url']; ?>" target="_blank">Create New Account</a>
33
+ &nbsp;|&nbsp;
34
+ <a href="<?php echo $data['login_url']; ?>" target="_blank">Login to existing Account</a>
35
+ </div>
36
  <?php } ?>
app/etc/modules/Saleswarp_Oms.xml CHANGED
@@ -1,10 +1,10 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <Saleswarp_Oms>
5
- <active>true</active>
6
- <codePool>local</codePool>
7
- <version>0.1.0</version>
8
- </Saleswarp_Oms>
9
- </modules>
10
  </config>
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Saleswarp_Oms>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ <version>0.1.0</version>
8
+ </Saleswarp_Oms>
9
+ </modules>
10
  </config>
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Saleswarp_Oms</name>
4
- <version>0.1.2</version>
5
  <stability>stable</stability>
6
- <license uri="https://www.saleswarp.com/license-saas/">Commercial</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Saleswarp Order Management System</summary>
10
  <description>This module connects Magento to the Saleswarp Advanced Order Management Software for omnichannel management. See our website for more details.</description>
11
  <notes>Production version</notes>
12
  <authors><author><name>David Potts</name><user>David</user><email>sales@saleswarp.com</email></author></authors>
13
- <date>2016-02-03</date>
14
- <time>21:37:43</time>
15
- <contents><target name="mageetc"><dir name="modules"><file name="Saleswarp_Oms.xml" hash="d7517f57c7067f8dbe22fd1dcab808f0"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="oms"><dir name="form"><file name="saleswarp.phtml" hash="bbad1f2cd7a051e94ccedd746dea792f"/></dir><dir name="system"><dir name="config"><file name="button.phtml" hash="a56213475969648e407ebcaa7876b543"/></dir></dir></dir></dir></dir></dir></dir></target><target name="magelocal"><dir name="Saleswarp"><dir name="Oms"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Form"><file name="Button.php" hash="98b0800abe8bfc2e134a8c6a3105f456"/><file name="Key.php" hash="9c214ab80440d4f8616e3be453c68648"/></dir></dir></dir></dir><dir name="Form"><file name="Saleswarp.php" hash="b30ec57de4d6b99ddaeada14f9336ffe"/></dir><dir name="Info"><file name="Saleswarp.php" hash="c45c80aa79fcc26a64740ae0fa68de6e"/></dir></dir><dir name="Helper"><file name="Data.php" hash="56d7205458e363668c92f6c854c1148a"/></dir><dir name="Model"><dir name="Category"><file name="Api.php" hash="e95fff09bbb0db173ca2a00bd9aba7af"/></dir><dir name="Config"><file name="Api.php" hash="0c8aadaf4c9a35e00c0c77027e3e9087"/></dir><dir name="Customer"><file name="Api.php" hash="f6964b711ee3ff52e4ad5171923c3fa1"/></dir><dir name="Order"><file name="Api.php" hash="746a7a2625781718cd8bb903b42912b4"/></dir><dir name="Product"><file name="Api.php" hash="94e8ff8435f41fd5a49356c0ee97fee6"/><dir name="Attribute"><file name="Api.php" hash="7c14c8799326c044cfed0106633e3818"/><dir name="Media"><file name="Api.php" hash="2deb5295ebd54133195d21497d23e2a2"/></dir></dir></dir><file name="Saleswarp.php" hash="f571feaf9cb2f9f1cee17da426bc9181"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="GetkeyController.php" hash="5df8d8b4ab7fd86519bb145d2ead3687"/></dir><file name="FastapiController.php" hash="1e1bc36e9043b4a12ba6f74c5b6e1602"/></dir><dir name="etc"><file name="adminhtml.xml" hash="8fe0febceef7c236000fd538d6061a8e"/><file name="config.xml" hash="292f1aacb300ab70cc771ba2d7fd6859"/><file name="system.xml" hash="f09a337b4731e8b569eb5720aff4e8b2"/></dir><dir name="sql"><dir name="oms_setup"><file name="mysql4-install-0.1.1.php" hash="fe7c9448c3e5f0e1ca853c77faa7478f"/><file name="mysql4-upgrade-0.1.2.php" hash="5441c7565508f4f5ad7310635b1edd37"/></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Saleswarp_Oms</name>
4
+ <version>0.1.3</version>
5
  <stability>stable</stability>
6
+ <license uri="https://www.saleswarp.com/license-saas/">commercial</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Saleswarp Order Management System</summary>
10
  <description>This module connects Magento to the Saleswarp Advanced Order Management Software for omnichannel management. See our website for more details.</description>
11
  <notes>Production version</notes>
12
  <authors><author><name>David Potts</name><user>David</user><email>sales@saleswarp.com</email></author></authors>
13
+ <date>2017-01-06</date>
14
+ <time>17:45:59</time>
15
+ <contents><target name="magelocal"><dir name="Saleswarp"><dir name="Oms"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Form"><file name="Button.php" hash="fcb650f22b9d384b31b90405000d5b56"/><file name="Key.php" hash="4a8e3c9111fee50573c6e07fc56d0153"/></dir></dir></dir></dir><dir name="Form"><file name="Saleswarp.php" hash="965669ba0523ccb8ecc5677bb249924f"/></dir><dir name="Info"><file name="Saleswarp.php" hash="600aefd58cdf840fb7a5019563621993"/></dir></dir><dir name="Helper"><file name="Data.php" hash="87e8f9369c3a149fda35b50630d0315f"/></dir><dir name="Model"><dir name="Category"><file name="Api.php" hash="dc0a5ffc89fab4ac0465907f947c301e"/></dir><dir name="Config"><file name="Api.php" hash="b25087d2a3607663158a10eaa8eccae1"/></dir><dir name="Customer"><file name="Api.php" hash="cd09e73655269bf8a76461010c0ece7a"/></dir><dir name="Order"><file name="Api.php" hash="c8bd9f3fcc60e61550bb25021766d47e"/></dir><dir name="Product"><file name="Api.php" hash="11bd9d9c46efcdc9a23b57963e123f35"/><dir name="Attribute"><file name="Api.php" hash="52a64badb47619eb3a15a7f2ed6b6a40"/><dir name="Media"><file name="Api.php" hash="7333cf13a3500779a737bfee9f4fe676"/></dir></dir></dir><file name="Saleswarp.php" hash="7227d0c22a4aadf06b0cfa59895062ee"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="GetkeyController.php" hash="a110882cd28cebe8354a9a2788c8252b"/></dir><file name="FastapiController.php" hash="8b1c8c5a832630402fde8400fd195ebf"/></dir><dir name="etc"><file name="adminhtml.xml" hash="065c0883d726cf19b87b19509859f668"/><file name="config.xml" hash="57af03d54703905462369b9caf510f5d"/><file name="system.xml" hash="b38eeac0d69ea52d857dcae421f57644"/></dir><dir name="sql"><dir name="oms_setup"><file name="mysql4-install-0.1.1.php" hash="44d2a6b20d56f29001c02c739d02bb51"/><file name="mysql4-upgrade-0.1.2.php" hash="e02de13c86fae519a362a9951881f055"/></dir></dir></dir><dir name="Publish"><dir name="Helper"><file name="Data.php" hash="c89ac5bf5870771030f2b0a320683ad4"/></dir><dir name="Model"><dir name="Category"><file name="Api.php" hash="e75c88dc2f9fc17556a27bed43c43daa"/></dir><dir name="Config"><file name="Api.php" hash="563ffd735d56faf8421c510aeb3c397e"/></dir><dir name="Customer"><file name="Api.php" hash="34dcdfed7c4bcefde4bf438b4311d705"/></dir><dir name="Product"><file name="Api.php" hash="fc7822a6da6e74b059e6944433ab6696"/><dir name="Attribute"><file name="Api.php" hash="b3d99a16223c88b721a338943722d26f"/><dir name="Media"><file name="Api.php" hash="f94406d8cf2afc06304bbfcd0f0a592f"/></dir></dir></dir></dir><dir name="etc"><file name="config.xml" hash="9488190e3433b6794682b3df613bd366"/></dir></dir><dir name="WhitelistIP"><dir name="Helper"><file name="Data.php" hash="8540c7d74bff5a7498f6263625b2dcd1"/></dir><dir name="controllers"><file name="FastapiController.php" hash="8deea48340058253fc765d909e190727"/></dir><dir name="etc"><file name="config.xml" hash="e65962723b4151a92c01f484f78c874b"/><file name="system.xml" hash="ba40514d68fdc6d30456c3622e9b1f40"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="oms"><dir name="form"><file name="saleswarp.phtml" hash="a4cf6bc4ceb31feb254701d57710ad4d"/></dir><dir name="system"><dir name="config"><file name="button.phtml" hash="0914b2e4793fed8f54b9fd033d05575e"/></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Saleswarp_Oms.xml" hash="798e9d50c381b103bde3958dd3a87580"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>