sellonflubit - Version 0.2.8

Version Notes

- This initial release allows merchants to connect to the Flubit demand driven channels.

Functionalities include:

1 - Push Products to Flubit.
2 - Globally control inventory and prices.
3 - Assign a Flubit Base Price.
4 - As real time as possible inventory updates subject to Cron / Scheduled Tasks running
5 - As real time as possible Order Management and order status updates subject to Cron/ Scheduled Tasks running.

Download this release

Release Info

Developer Krishna
Extension sellonflubit
Version 0.2.8
Comparing to
See all releases


Version 0.2.8

Files changed (115) hide show
  1. app/code/community/Flubit/Flubit/Block/Adminhtml/Button.php +36 -0
  2. app/code/community/Flubit/Flubit/Block/Adminhtml/Flubit.php +28 -0
  3. app/code/community/Flubit/Flubit/Block/Adminhtml/Flubit/Grid.php +141 -0
  4. app/code/community/Flubit/Flubit/Block/Adminhtml/Notification.php +87 -0
  5. app/code/community/Flubit/Flubit/Block/Adminhtml/Widget/Grid/Column/Renderer/Inline.php +31 -0
  6. app/code/community/Flubit/Flubit/Block/Adminhtml/Widget/Grid/Column/Renderer/InlineCheckbox.php +33 -0
  7. app/code/community/Flubit/Flubit/Block/Adminhtml/Widget/Grid/Column/Renderer/InlineUpdateButton.php +31 -0
  8. app/code/community/Flubit/Flubit/Block/Flubit.php +41 -0
  9. app/code/community/Flubit/Flubit/Block/Sales/Order/View/Info.php +17 -0
  10. app/code/community/Flubit/Flubit/Helper/Data.php +66 -0
  11. app/code/community/Flubit/Flubit/Helper/Payment/Data.php +55 -0
  12. app/code/community/Flubit/Flubit/Model/Carrier/Flatrate.php +95 -0
  13. app/code/community/Flubit/Flubit/Model/Config.php +769 -0
  14. app/code/community/Flubit/Flubit/Model/Cron.php +20 -0
  15. app/code/community/Flubit/Flubit/Model/Flubit.php +1123 -0
  16. app/code/community/Flubit/Flubit/Model/Flubit/Chunk.php +28 -0
  17. app/code/community/Flubit/Flubit/Model/Flubit/Logdate.php +26 -0
  18. app/code/community/Flubit/Flubit/Model/Flubit/Logs.php +27 -0
  19. app/code/community/Flubit/Flubit/Model/Flubit/Order.php +29 -0
  20. app/code/community/Flubit/Flubit/Model/Flubit/Price.php +27 -0
  21. app/code/community/Flubit/Flubit/Model/Flubit/Rcd.php +25 -0
  22. app/code/community/Flubit/Flubit/Model/Flubit/Source.php +27 -0
  23. app/code/community/Flubit/Flubit/Model/Globalproduct.php +135 -0
  24. app/code/community/Flubit/Flubit/Model/Logs.php +25 -0
  25. app/code/community/Flubit/Flubit/Model/Logtype.php +67 -0
  26. app/code/community/Flubit/Flubit/Model/Mysql4/Flubit.php +20 -0
  27. app/code/community/Flubit/Flubit/Model/Mysql4/Flubit/Collection.php +21 -0
  28. app/code/community/Flubit/Flubit/Model/Mysql4/Globalproduct.php +20 -0
  29. app/code/community/Flubit/Flubit/Model/Mysql4/Globalproduct/Collection.php +21 -0
  30. app/code/community/Flubit/Flubit/Model/Mysql4/Logs.php +20 -0
  31. app/code/community/Flubit/Flubit/Model/Mysql4/Logs/Collection.php +21 -0
  32. app/code/community/Flubit/Flubit/Model/Mysql4/Order.php +20 -0
  33. app/code/community/Flubit/Flubit/Model/Mysql4/Order/Collection.php +21 -0
  34. app/code/community/Flubit/Flubit/Model/Mysql4/Ordertime.php +20 -0
  35. app/code/community/Flubit/Flubit/Model/Mysql4/Ordertime/Collection.php +21 -0
  36. app/code/community/Flubit/Flubit/Model/Observer.php +402 -0
  37. app/code/community/Flubit/Flubit/Model/Order.php +25 -0
  38. app/code/community/Flubit/Flubit/Model/Order/Pdf/Creditmemo.php +414 -0
  39. app/code/community/Flubit/Flubit/Model/Order/Pdf/Invoice.php +407 -0
  40. app/code/community/Flubit/Flubit/Model/Order/Pdf/Items/Creditmemo/Default.php +346 -0
  41. app/code/community/Flubit/Flubit/Model/Order/Pdf/Items/Invoice/Default.php +359 -0
  42. app/code/community/Flubit/Flubit/Model/Ordertime.php +25 -0
  43. app/code/community/Flubit/Flubit/Model/Payment/Method/Flubitterms.php +62 -0
  44. app/code/community/Flubit/Flubit/Model/Quote/Item.php +88 -0
  45. app/code/community/Flubit/Flubit/Model/Shipping.php +35 -0
  46. app/code/community/Flubit/Flubit/controllers/Adminhtml/FlubitController.php +234 -0
  47. app/code/community/Flubit/Flubit/controllers/FlubitController.php +31 -0
  48. app/code/community/Flubit/Flubit/etc/adminhtml.xml +23 -0
  49. app/code/community/Flubit/Flubit/etc/config.xml +343 -0
  50. app/code/community/Flubit/Flubit/etc/system.xml +177 -0
  51. app/code/community/Flubit/Flubit/sql/flubit_setup/mysql4-install-0.1.0.php +22 -0
  52. app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.1.0-0.1.1.php +122 -0
  53. app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.1.1-0.1.2.php +150 -0
  54. app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.1.2-0.1.3.php +22 -0
  55. app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.1.3-0.1.4.php +42 -0
  56. app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.1.4-0.1.5.php +19 -0
  57. app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.1.5-0.1.6.php +50 -0
  58. app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.1.6-0.1.7.php +22 -0
  59. app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.1.7-0.1.8.php +18 -0
  60. app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.1.8-0.1.9.php +18 -0
  61. app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.1.9-0.2.0.php +18 -0
  62. app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.2.0-0.2.1.php +18 -0
  63. app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.2.1-0.2.2.php +23 -0
  64. app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.2.2-0.2.3.php +49 -0
  65. app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.2.3-0.2.4.php +20 -0
  66. app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.2.4-0.2.5.php +20 -0
  67. app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.2.5-0.2.6.php +22 -0
  68. app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.2.6-0.2.7.php +42 -0
  69. app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.2.7-0.2.8.php +20 -0
  70. app/code/community/Flubit/Flubitlog/Block/Adminhtml/Flubitlog.php +28 -0
  71. app/code/community/Flubit/Flubitlog/Block/Adminhtml/Flubitlog/Detail.php +20 -0
  72. app/code/community/Flubit/Flubitlog/Block/Adminhtml/Flubitlog/Edit.php +44 -0
  73. app/code/community/Flubit/Flubitlog/Block/Adminhtml/Flubitlog/Edit/Form.php +26 -0
  74. app/code/community/Flubit/Flubitlog/Block/Adminhtml/Flubitlog/Edit/Tab/Form.php +43 -0
  75. app/code/community/Flubit/Flubitlog/Block/Adminhtml/Flubitlog/Edit/Tabs.php +37 -0
  76. app/code/community/Flubit/Flubitlog/Block/Adminhtml/Flubitlog/Grid.php +132 -0
  77. app/code/community/Flubit/Flubitlog/Block/Flubitlog.php +35 -0
  78. app/code/community/Flubit/Flubitlog/Helper/Data.php +6 -0
  79. app/code/community/Flubit/Flubitlog/Model/Flubitlog.php +17 -0
  80. app/code/community/Flubit/Flubitlog/Model/Mysql4/Flubitlog.php +24 -0
  81. app/code/community/Flubit/Flubitlog/Model/Mysql4/Flubitlog/Collection.php +23 -0
  82. app/code/community/Flubit/Flubitlog/Model/Status.php +28 -0
  83. app/code/community/Flubit/Flubitlog/controllers/Adminhtml/FlubitlogController.php +261 -0
  84. app/code/community/Flubit/Flubitlog/controllers/IndexController.php +18 -0
  85. app/code/community/Flubit/Flubitlog/etc/config.xml +128 -0
  86. app/code/community/Flubit/Flubitlog/sql/flubitlog_setup/mysql4-install-0.1.0.php +28 -0
  87. app/code/community/Flubit/Flubitlog/sql/flubitlog_setup/upgrade-0.1.0-0.2.0.php +19 -0
  88. app/code/community/Flubit/Flubitlog/sql/flubitlog_setup/upgrade-0.2.0-0.2.1.php +19 -0
  89. app/code/community/Flubit/Flubitlog/sql/flubitlog_setup/upgrade-0.2.1-0.2.2.php +15 -0
  90. app/design/adminhtml/default/default/layout/flubit.xml +115 -0
  91. app/design/adminhtml/default/default/layout/flubitlog.xml +14 -0
  92. app/design/adminhtml/default/default/template/flubit/cronnotofocation.phtml +6 -0
  93. app/design/adminhtml/default/default/template/flubit/inline-edit.phtml +155 -0
  94. app/design/adminhtml/default/default/template/flubit/sales/order/creditmemo/create/items.phtml +191 -0
  95. app/design/adminhtml/default/default/template/flubit/sales/order/creditmemo/create/items/renderer/defaultflubit.phtml +257 -0
  96. app/design/adminhtml/default/default/template/flubit/sales/order/creditmemo/create/totals/adjustmentsflubit.phtml +71 -0
  97. app/design/adminhtml/default/default/template/flubit/sales/order/creditmemo/view/items.phtml +68 -0
  98. app/design/adminhtml/default/default/template/flubit/sales/order/creditmemo/view/items/renderer/default.phtml +255 -0
  99. app/design/adminhtml/default/default/template/flubit/sales/order/flubittotals.phtml +153 -0
  100. app/design/adminhtml/default/default/template/flubit/sales/order/invoice/view/items.phtml +64 -0
  101. app/design/adminhtml/default/default/template/flubit/sales/order/invoice/view/items/renderer/default.phtml +242 -0
  102. app/design/adminhtml/default/default/template/flubit/sales/order/shipment/create/items.phtml +165 -0
  103. app/design/adminhtml/default/default/template/flubit/sales/order/view/flubititems.phtml +73 -0
  104. app/design/adminhtml/default/default/template/flubit/sales/order/view/info.phtml +180 -0
  105. app/design/adminhtml/default/default/template/flubit/sales/order/view/items/renderer/flubitdefault.phtml +259 -0
  106. app/design/adminhtml/default/default/template/flubitlog/logdetails.phtml +275 -0
  107. app/etc/modules/Flubit_Flubit.xml +10 -0
  108. app/etc/modules/Flubit_Flubitlog.xml +10 -0
  109. lib/Flubit/Flubit/Client.php +412 -0
  110. lib/Flubit/Flubit/ClientInterface.php +97 -0
  111. lib/Flubit/Flubit/ClientX.php +372 -0
  112. lib/Flubit/Flubit/MWSClient.php +277 -0
  113. package.xml +29 -0
  114. skin/adminhtml/default/default/images/flubit/logo.png +0 -0
  115. skin/adminhtml/default/default/images/flubit/pushonlogo.png +0 -0
app/code/community/Flubit/Flubit/Block/Adminhtml/Button.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Block Admin Button
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Block
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Block_Adminhtml_Button extends Mage_Adminhtml_Block_System_Config_Form_Field {
11
+
12
+ /**
13
+ * Method for Set Element
14
+ *
15
+ * @param Varien_Data_Form_Element_Abstract $element
16
+ * @return String
17
+ */
18
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
19
+ try {
20
+ $this->setElement($element);
21
+ $url = $this->getUrl('flubit/flubit/generateProductXML/');
22
+
23
+ $html = $this->getLayout()->createBlock('adminhtml/widget_button')
24
+ ->setType('button')
25
+ ->setClass('scalable')
26
+ ->setLabel('Sync')
27
+ ->setOnClick("setLocation('$url')")
28
+ ->toHtml();
29
+
30
+ return $html;
31
+ } catch (Exception $e) {
32
+ Mage::log(__LINE__ . 'Exception Flubit_Flubit_Block_Adminhtml_Button _getElementHtml ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
33
+ }
34
+ }
35
+
36
+ }
app/code/community/Flubit/Flubit/Block/Adminhtml/Flubit.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Block Admin Flubit
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Block
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Block_Adminhtml_Flubit extends Mage_Adminhtml_Block_Widget_Grid_Container {
11
+
12
+ /**
13
+ *
14
+ * Construct for autoload and set property
15
+ */
16
+ public function __construct() {
17
+ try {
18
+ $this->_controller = 'adminhtml_flubit';
19
+ $this->_blockGroup = 'flubit';
20
+ $this->_headerText = Mage::helper('flubit')->__('Flubit Product Manager');
21
+ parent::__construct();
22
+ $this->removeButton('add');
23
+ } catch (Exception $e) {
24
+ Mage::log(__LINE__ . 'Exception Flubit_Flubit_Block_Adminhtml_Flubit __construct ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
25
+ }
26
+ }
27
+
28
+ }
app/code/community/Flubit/Flubit/Block/Adminhtml/Flubit/Grid.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class admin Flubit Grid
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Block
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Block_Adminhtml_Flubit_Grid extends Mage_Adminhtml_Block_Widget_Grid {
11
+
12
+ /**
13
+ *
14
+ * Construct for autoload and set property
15
+ */
16
+ public function __construct() {
17
+ try {
18
+ parent::__construct();
19
+ $this->setId('flubitGrid');
20
+ $this->setDefaultSort('flubit_id');
21
+ $this->setDefaultDir('DESC');
22
+ $this->setSaveParametersInSession(true);
23
+ } catch (Exception $e) {
24
+ Mage::log(__LINE__ . 'Exception Flubit_Flubit_Block_Adminhtml_Flubit_Grid __construct ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
25
+ }
26
+ }
27
+
28
+ /**
29
+ *
30
+ * private method for prepare collection
31
+ */
32
+ protected function _prepareCollection() {
33
+ try {
34
+ $attributeModel = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'price');
35
+ $entity_id = $attributeModel->attribute_id;
36
+
37
+ $collection = Mage::getModel('flubit/flubit')->getCollection();
38
+
39
+ $this->setCollection($collection);
40
+ //custom code
41
+ $collection->getSelect()->join(array('product_entity' => Mage::getConfig()->getTablePrefix() . 'catalog_product_entity'), 'product_entity.sku = main_table.sku', array('product_entity.entity_id'));
42
+
43
+ $collection->getSelect()->join(array('product_price' => Mage::getConfig()->getTablePrefix() . 'catalog_product_entity_decimal'), 'product_price.entity_id = product_entity.entity_id and product_price.attribute_id = ' . $entity_id, array('mprice' => 'ROUND(product_price.`value`,2)'));
44
+ ;
45
+
46
+ return parent::_prepareCollection();
47
+ } catch (Exception $e) {
48
+ Mage::log(__LINE__ . 'Exception Flubit_Flubit_Block_Adminhtml_Flubit_Grid _prepareCollection ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
49
+ }
50
+ }
51
+
52
+ /**
53
+ *
54
+ * private method for prepare Columns
55
+ */
56
+ protected function _prepareColumns() {
57
+ $this->addColumn('flubit_id', array(
58
+ 'header' => Mage::helper('flubit')->__('ID'),
59
+ 'align' => 'right',
60
+ 'width' => '50px',
61
+ 'index' => 'flubit_id',
62
+ ));
63
+ $this->addColumn('sku', array(
64
+ 'header' => Mage::helper('flubit')->__('SKU'),
65
+ 'align' => 'left',
66
+ 'index' => 'sku',
67
+ 'width' => '200',
68
+ 'filter_index' => 'main_table.sku'
69
+ ));
70
+ $this->addColumn('name', array(
71
+ 'header' => Mage::helper('flubit')->__('Name'),
72
+ 'align' => 'left',
73
+ 'index' => 'name',
74
+ ));
75
+ $this->addColumn('active_status', array(
76
+ 'header' => Mage::helper('flubit')->__('Flubit Status'),
77
+ 'align' => 'left',
78
+ 'index' => 'active_status',
79
+ 'type' => 'options',
80
+ 'options' => array(
81
+ 0 => 'Inactive',
82
+ 1 => 'Active',
83
+ ),
84
+ ));
85
+ $this->addColumn('qty', array(
86
+ 'header' => Mage::helper('flubit')->__('Qty'),
87
+ 'width' => '150px',
88
+ 'index' => 'qty',
89
+ ));
90
+ $this->addColumn('mprice', array(
91
+ 'header' => Mage::helper('flubit')->__('Product Price'),
92
+ 'width' => '150px',
93
+ 'index' => 'mprice',
94
+ 'filter_index' => 'product_price.`value`'
95
+ ));
96
+ $this->addColumn('price', array(
97
+ 'header' => Mage::helper('flubit')->__('Flubit Price'),
98
+ 'width' => '150px',
99
+ 'renderer' => 'flubit/adminhtml_widget_grid_column_renderer_inline',
100
+ 'index' => 'price',
101
+ ));
102
+ $this->addColumn('use_global_price', array(
103
+ 'header' => Mage::helper('flubit')->__('Use Global Price'),
104
+ 'width' => '60px',
105
+ 'align' => 'center',
106
+ 'renderer' => 'flubit/adminhtml_widget_grid_column_renderer_inlineCheckbox',
107
+ 'index' => 'use_global_price',
108
+ 'filter' => false,
109
+ 'sortable' => false,
110
+ ));
111
+
112
+ $this->addColumn('action', array(
113
+ 'header' => Mage::helper('flubit')->__('Action'),
114
+ 'width' => '100',
115
+ 'align' => 'center',
116
+ 'renderer' => 'flubit/adminhtml_widget_grid_column_renderer_inlineUpdateButton',
117
+ 'filter' => false,
118
+ 'sortable' => false,
119
+ ));
120
+
121
+ return parent::_prepareColumns();
122
+ }
123
+
124
+ /**
125
+ * Method for Get Row Url
126
+ *
127
+ * @param Mixed $row
128
+ * @return String
129
+ */
130
+ public function getRowUrl($row) {
131
+ try {
132
+ if ($row['sku']) {
133
+ $productId = Mage::getModel('catalog/product')->getIdBySku($row['sku']);
134
+ return $this->getUrl('adminhtml/catalog_product/edit', array('id' => $productId));
135
+ }
136
+ } catch (Exception $e) {
137
+ Mage::log(__LINE__ . 'Exception Flubit_Flubit_Block_Adminhtml_Flubit_Grid _prepareCollection ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
138
+ }
139
+ }
140
+
141
+ }
app/code/community/Flubit/Flubit/Block/Adminhtml/Notification.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Block Admin Flubitbackend
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Block
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Block_Adminhtml_Notification extends Mage_Adminhtml_Block_Template {
11
+
12
+ /**
13
+ * Method to check if a scheduled cron is executed
14
+ *
15
+ * @return String
16
+ */
17
+ function checkScheduledCronExecution() {
18
+ $return_message = '';
19
+ try {
20
+ $cronTimedOut = false;
21
+ $time_now = date('Y-m-d H:i:s');
22
+ $threashhold_time = '+15 min';
23
+
24
+ //Mage::log('Time Now' . $time_now, NULL , 'CronTest.log' );
25
+
26
+ $crons = array(
27
+ 0 => 'flubit_products_cron',
28
+ 1 => 'flubit_orders_fetch_cron',
29
+ 2 => 'flubit_orders_dispatch_cron',
30
+ 3 => 'flubit_orders_cancel_cron',
31
+ 4 => 'flubit_orders_refund_cron'
32
+ );
33
+ //Products, Orders Fetch, Orders Dispatch, Orders Cancel, Orders Refund.
34
+ $crons_Redable = array(
35
+ 'flubit_products_cron' => 'Products Push',
36
+ 'flubit_orders_fetch_cron' => 'Fetching Orders',
37
+ 'flubit_orders_dispatch_cron' => 'Dispatch Orders',
38
+ 'flubit_orders_cancel_cron' => 'Cancel Orders',
39
+ 'flubit_orders_refund_cron' => 'Refund Orders'
40
+ );
41
+
42
+ $cron_stopped = array();
43
+ foreach ($crons as $cron) {
44
+ $cronCollection = Mage::getModel('cron/schedule')->getCollection()
45
+ ->addFieldToFilter('status', Mage_Cron_Model_Schedule::STATUS_SUCCESS)
46
+ ->addFieldToFilter('job_code', $cron)
47
+ ->addOrder('executed_at', 'DESC')
48
+ ->load();
49
+ $cronNotInitalized = FALSE;
50
+ $cronCollection->getSelect()->limit(1);
51
+ $cron_row = $cronCollection->getData();
52
+
53
+ if (count($cron_row)) {
54
+ $lastExecutedTime = $cron_row[0]['executed_at'];
55
+
56
+ $tot_time_now = strtotime($time_now);
57
+ $tot_executed_time = strtotime($threashhold_time . $lastExecutedTime);
58
+
59
+
60
+
61
+ if ($tot_time_now < $tot_executed_time) { /* do Something */
62
+
63
+ } else {
64
+
65
+ $cron_stopped[] = $crons_Redable[$cron];
66
+ $cronTimedOut = true;
67
+ }
68
+ } else {
69
+ $cron_stopped[] = $crons_Redable[$cron];
70
+ $cronNotInitalized = true;
71
+ }
72
+ }
73
+
74
+ if ($cronTimedOut) {
75
+ //Cron Execution has stopped! The following Cron jobs have been affected:
76
+ $return_message = 'Alert: Cron/Scheduled Tasks is either not setup or running.';
77
+ }
78
+ if ($cronNotInitalized) {
79
+ $return_message = 'Alert: Cron/Scheduled Tasks is either not setup or running.';
80
+ }
81
+ } catch (Exception $e) {
82
+ Mage::log('Cron Collection Fetch Exception :' . $e, NULL, 'CronTest.log');
83
+ }
84
+ return $return_message;
85
+ }
86
+
87
+ }
app/code/community/Flubit/Flubit/Block/Adminhtml/Widget/Grid/Column/Renderer/Inline.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Block Admin Widget Grid Column Renderer Inline
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Block
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Block_Adminhtml_Widget_Grid_Column_Renderer_Inline extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Input {
11
+ /**
12
+ * function to generate inline price textbox
13
+ * @param Varien_Object $row
14
+ * @return string
15
+ */
16
+ public function render(Varien_Object $row) {
17
+ try {
18
+ $html = parent::render($row);
19
+
20
+ $html = '<input type="text" ';
21
+ $html .= 'id="price_' . $row->getId() . '" ';
22
+ $html .= 'name="' . $this->getColumn()->getId() . '" ';
23
+ $html .= 'value="' . number_format($row->getData($this->getColumn()->getIndex()), 2, '.', '') . '"';
24
+ $html .= 'class="onenter validate-number input-text ' . $this->getColumn()->getInlineCss() . '" />';
25
+ return $html;
26
+ } catch (Exception $e) {
27
+ Mage::log(__LINE__ . 'Exception Flubit_Flubit_Block_Adminhtml_Widget_Grid_Column_Renderer_Inline render ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
28
+ }
29
+ }
30
+
31
+ }
app/code/community/Flubit/Flubit/Block/Adminhtml/Widget/Grid/Column/Renderer/InlineCheckbox.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Block Admin Widget Grid Column Renderer Inlinecheck
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Block
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Block_Adminhtml_Widget_Grid_Column_Renderer_InlineCheckbox extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Input {
11
+
12
+ /**
13
+ * method for ggenerating inline checkbox
14
+ *
15
+ * @param Varien_Object $row
16
+ * @return string
17
+ */
18
+ public function render(Varien_Object $row) {
19
+ try {
20
+ $html = parent::render($row);
21
+
22
+ $html = '<input type="checkbox" ';
23
+ $html .= 'id="checkbox_' . $row->getId() . '" ';
24
+ $html .= 'name="' . $this->getColumn()->getId() . '" ';
25
+ $html .= ($row->getData($this->getColumn()->getIndex()) == 1 ? 'checked="checked"' : '');
26
+ $html .= 'onclick="updateFlubitPriceCalculation(this, ' . $row->getId() . ', ' . $row->getPrice() . '); return false"/>';
27
+ return $html;
28
+ } catch (Exception $e) {
29
+ Mage::log(__LINE__ . 'Exception Flubit_Flubit_Block_Adminhtml_Widget_Grid_Column_Renderer_InlineCheckbox render ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
30
+ }
31
+ }
32
+
33
+ }
app/code/community/Flubit/Flubit/Block/Adminhtml/Widget/Grid/Column/Renderer/InlineUpdateButton.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Block Admin Widget Grid Column Renderer Inlineupdate
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Block
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Block_Adminhtml_Widget_Grid_Column_Renderer_InlineUpdateButton extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Input {
11
+
12
+ /**
13
+ * method for update price link
14
+ *
15
+ * @param Varien_Object $row
16
+ * @return string
17
+ */
18
+ public function render(Varien_Object $row) {
19
+ try {
20
+ $html = parent::render($row);
21
+
22
+ $html = '<a href="#" ';
23
+ $html .= ' id="link_' . $row->getId() . '" ';
24
+ $html .= 'onclick="updatePriceAndGlobalCalculator(' . $row->getId() . ', \'' . $row->getPrice() . '\',' . $row->getUseGlobalPrice() . '); return false">Update Price</a> ';
25
+ return $html;
26
+ } catch (Exception $e) {
27
+ Mage::log(__LINE__ . 'Exception Flubit_Flubit_Block_Adminhtml_Widget_Grid_Column_Renderer_InlineUpdateButton render ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
28
+ }
29
+ }
30
+
31
+ }
app/code/community/Flubit/Flubit/Block/Flubit.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Block Flubitnd
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Block
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Block_Flubit extends Mage_Core_Block_Template {
11
+
12
+ /**
13
+ * method for prepare layout
14
+ *
15
+ * @return type
16
+ */
17
+ public function _prepareLayout() {
18
+ try {
19
+ return parent::_prepareLayout();
20
+ } catch (Exception $e) {
21
+ Mage::log(__LINE__ . 'Exception Flubit_Flubit_Block_Flubit _prepareLayout ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
22
+ }
23
+ }
24
+
25
+ /**
26
+ * method for getFlubit
27
+ *
28
+ * @return string
29
+ */
30
+ public function getFlubit() {
31
+ try {
32
+ if (!$this->hasData('flubit')) {
33
+ $this->setData('flubit', Mage::registry('flubit'));
34
+ }
35
+ return $this->getData('flubit');
36
+ } catch (Exception $e) {
37
+ Mage::log(__LINE__ . 'Exception Flubit_Flubit_Block_Flubit _prepareLayout ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
38
+ }
39
+ }
40
+
41
+ }
app/code/community/Flubit/Flubit/Block/Sales/Order/View/Info.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Block Sales order view info
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Block
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Block_Sales_Order_View_Info extends Mage_Adminhtml_Block_Sales_Order_View_Info {
11
+
12
+ protected function _construct() {
13
+ parent::_construct();
14
+ $this->setTemplate('flubit/sales/order/view/info.phtml');
15
+ }
16
+
17
+ }
app/code/community/Flubit/Flubit/Helper/Data.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Helper Data
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Helper
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Helper_Data extends Mage_Core_Helper_Abstract {
11
+ /**
12
+ *
13
+ */
14
+
15
+ const FLUBIT_MISSING_CONFIG = 'flubit_missing_config.log';
16
+ const FLUBIT_CREATE_PRODUCT = 'flubit_create_product.log';
17
+ const FLUBIT_UPDATE_PRODUCT = 'flubit_update_product.log';
18
+ const FLUBIT_CHECK_FEED = 'flubit_check_feed.log';
19
+ const FLUBIT_EXCEPTIONS = 'flubit_exceptions.log';
20
+ const FLUBIT_CREATE_ORDER = 'flubit_magento_create_order.log';
21
+ const FLUBIT_DISPATCH_ORDER = 'flubit_magento_dispatch_order.log';
22
+ const FLUBIT_CANCEL_ORDER = 'flubit_magento_cancel_order.log';
23
+ const FLUBIT_REFUND_ORDER = 'flubit_magento_refund_order.log';
24
+ const FLUBIT_OBSERVER_DELETE = 'flubit_magento_delete_product.log';
25
+ const FLUBIT_FAILED_PRODUCT = 'flubit_failed_products.log';
26
+ const FLUBIT_FEED = 'flubit_product_feed.log';
27
+ const FLUBIT_ORDER_FETCH = 'Test_Order_Fetch.log';
28
+ const FLUBIT_COMMUNICATION = 'flubit_communication.log';
29
+
30
+ public function isFlubitOrder() {
31
+ $checkout = $this->getCheckout();
32
+ if ($checkout->getData('flubit_order')) {
33
+ return true;
34
+ } else {
35
+ return false;
36
+ }
37
+ }
38
+
39
+ public function getCheckout() {
40
+ return Mage::getSingleton('checkout/session');
41
+ }
42
+
43
+ public function logCommunicationErrors($request, $response, $feedid, $mode = '') {
44
+
45
+ if (($request != '') && ($response != '')) {
46
+ try {
47
+ $flubitlog = Mage::getModel('flubitlog/flubitlog');
48
+ $flubitlog->setData(
49
+ array(
50
+ 'request_xml' => $request,
51
+ 'feedid' => $feedid,
52
+ 'response_xml' => $response,
53
+ 'action' => '8',
54
+ 'datetime' => date('Y-m-d H:i:s'),
55
+ 'level' => '2'
56
+ )
57
+ )
58
+ ->save();
59
+ } catch (Exception $e) {
60
+ Mage::log('Exception saving log to flubit' . $e ,NULL,Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
61
+ }
62
+ }
63
+ }
64
+
65
+ }
66
+
app/code/community/Flubit/Flubit/Helper/Payment/Data.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Payment Helper Data
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Helper
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Helper_Payment_Data extends Mage_Payment_Helper_Data {
11
+
12
+ /**
13
+ * Get and sort available payment methods for specified or current store
14
+ *
15
+ * array structure:
16
+ * $index => Varien_Simplexml_Element
17
+ *
18
+ * @param mixed $store
19
+ * @param Mage_Sales_Model_Quote $quote
20
+ * @return array
21
+ */
22
+ public function getStoreMethods($store = null, $quote = null) {
23
+ $res = array();
24
+ foreach ($this->getPaymentMethods($store) as $code => $methodConfig) {
25
+ $prefix = self::XML_PATH_PAYMENT_METHODS . '/' . $code . '/';
26
+
27
+ //Custom
28
+ $flubitorder = Mage::helper('flubit')->isFlubitOrder();
29
+ $validation = false;
30
+ if ($flubitorder && $code == 'banktransfer') {
31
+ $validation = true;
32
+ }
33
+
34
+ if ((!$model = Mage::getStoreConfig($prefix . 'model', $store)) && !$validation) {
35
+ continue;
36
+ }
37
+ $methodInstance = Mage::getModel($model);
38
+ if (!$methodInstance) {
39
+ continue;
40
+ }
41
+ $methodInstance->setStore($store);
42
+ if (!$methodInstance->isAvailable($quote)) {
43
+ /* if the payment method cannot be used at this time */
44
+ continue;
45
+ }
46
+ $sortOrder = (int) $methodInstance->getConfigData('sort_order', $store);
47
+ $methodInstance->setSortOrder($sortOrder);
48
+ $res[] = $methodInstance;
49
+ }
50
+
51
+ usort($res, array($this, '_sortMethods'));
52
+ return $res;
53
+ }
54
+
55
+ }
app/code/community/Flubit/Flubit/Model/Carrier/Flatrate.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Flat rate shipping model
5
+ *
6
+ * @category Mage
7
+ * @package Mage_Shipping
8
+ * @author Magento Core Team <core@magentocommerce.com>
9
+ */
10
+ class Flubit_Flubit_Model_Carrier_Flatrate extends Mage_Shipping_Model_Carrier_Flatrate {
11
+
12
+ /**
13
+ * Enter description here...
14
+ *
15
+ * @param Mage_Shipping_Model_Rate_Request $data
16
+ * @return Mage_Shipping_Model_Rate_Result
17
+ */
18
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request) {
19
+ //if flubit order pass the flatrate shipping method
20
+ $flubitorder = Mage::helper('flubit')->isFlubitOrder();
21
+ if (!$this->getConfigFlag('active') && !$flubitorder) {
22
+ return false;
23
+ }
24
+
25
+ if ($flubitorder) {
26
+ $shipping_cost = Mage::getSingleton('checkout/session')->getData('shipping_price');
27
+ $result = Mage::getModel('shipping/rate_result');
28
+ $method = Mage::getModel('shipping/rate_result_method');
29
+ $method->setCarrier('flatrate');
30
+ $method->setCarrierTitle($this->getConfigData('title'));
31
+ $method->setMethod('flatrate');
32
+ $method->setMethodTitle($this->getConfigData('name'));
33
+ $method->setPrice($shipping_cost);
34
+ $method->setCost($shipping_cost);
35
+ $result->append($method);
36
+ return $result;
37
+ }
38
+
39
+
40
+ $freeBoxes = 0;
41
+ if ($request->getAllItems()) {
42
+ foreach ($request->getAllItems() as $item) {
43
+
44
+ if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
45
+ continue;
46
+ }
47
+
48
+ if ($item->getHasChildren() && $item->isShipSeparately()) {
49
+ foreach ($item->getChildren() as $child) {
50
+ if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
51
+ $freeBoxes += $item->getQty() * $child->getQty();
52
+ }
53
+ }
54
+ } elseif ($item->getFreeShipping()) {
55
+ $freeBoxes += $item->getQty();
56
+ }
57
+ }
58
+ }
59
+ $this->setFreeBoxes($freeBoxes);
60
+
61
+ $result = Mage::getModel('shipping/rate_result');
62
+ if ($this->getConfigData('type') == 'O') { // per order
63
+ $shippingPrice = $this->getConfigData('price');
64
+ } elseif ($this->getConfigData('type') == 'I') { // per item
65
+ $shippingPrice = ($request->getPackageQty() * $this->getConfigData('price')) - ($this->getFreeBoxes() * $this->getConfigData('price'));
66
+ } else {
67
+ $shippingPrice = false;
68
+ }
69
+
70
+ $shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice);
71
+
72
+ if ($shippingPrice !== false) {
73
+ $method = Mage::getModel('shipping/rate_result_method');
74
+
75
+ $method->setCarrier('flatrate');
76
+ $method->setCarrierTitle($this->getConfigData('title'));
77
+
78
+ $method->setMethod('flatrate');
79
+ $method->setMethodTitle($this->getConfigData('name'));
80
+
81
+ if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
82
+ $shippingPrice = '0.00';
83
+ }
84
+
85
+
86
+ $method->setPrice($shippingPrice);
87
+ $method->setCost($shippingPrice);
88
+
89
+ $result->append($method);
90
+ }
91
+
92
+ return $result;
93
+ }
94
+
95
+ }
app/code/community/Flubit/Flubit/Model/Config.php ADDED
@@ -0,0 +1,769 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Cron
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Config extends Flubit_Flubit_Client {
11
+
12
+ const CONSUMER_API = 'flubit_section/flubit_configuration/flubit_consumer_key';
13
+ const SECRET_KEY = 'flubit_section/flubit_configuration/flubit_secret';
14
+ const CONSUMER_URL = 'flubit_section/flubit_configuration/flubit_url';
15
+ const LOG_TYPE = 'flubit_section/flubit_setup/log_type_list';
16
+
17
+ /**
18
+ * Construct and autoload initModule
19
+ */
20
+ public function __construct() {
21
+
22
+ }
23
+
24
+ /**
25
+ * Method for initModule
26
+ */
27
+ public function initModule() {
28
+ return $this->_initModule();
29
+ }
30
+
31
+ /**
32
+ * Method for initModules
33
+ */
34
+ protected function _initModule() {
35
+ try {
36
+ $api = Mage::getStoreConfig(self::CONSUMER_API);
37
+ $key = Mage::getStoreConfig(self::SECRET_KEY);
38
+ $url = Mage::getStoreConfig(self::CONSUMER_URL);
39
+ if (!empty($api) && !empty($key)) {
40
+ $obj = new Flubit_Flubit_Client($api, $key, $url);
41
+ return $obj;
42
+ } else {
43
+ Mage::log('Missing Keys in configuration', null, Flubit_Flubit_Helper_Data::FLUBIT_MISSING_CONFIG);
44
+ }
45
+ } catch (Exception $e) {
46
+ Mage::log(__LINE__ . ' _initModule ', null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Method for Create Flubit Products
52
+ *
53
+ * @param Xml String $xml
54
+ * @return Xml String
55
+ */
56
+ public function createFlubitProducts($xml) {
57
+ try {
58
+ $flubit = $this->_initModule();
59
+ //Mage::log('Request Create XML :' . $xml, null, Flubit_Flubit_Helper_Data::FLUBIT_CREATE_PRODUCT);
60
+ $result = $flubit->createProducts($xml);
61
+ $result = new SimpleXMLElement($result);
62
+ //Mage::log('Response Create XML :' . $result->asXML(), null, Flubit_Flubit_Helper_Data::FLUBIT_CREATE_PRODUCT);
63
+ return $result;
64
+ } catch (Exception $e) {
65
+ Mage::log(__LINE__ . ' createFlubitProducts ', null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Method for Update Flubit Products
71
+ *
72
+ * @param Xml String $xml
73
+ * @return Xml String
74
+ */
75
+ public function updateFlubitProducts($xml) {
76
+ try {
77
+ $flubit = $this->_initModule();
78
+ //Mage::log('Request Update XML :' . $xml, null, Flubit_Flubit_Helper_Data::FLUBIT_UPDATE_PRODUCT);
79
+ $result = $flubit->updateProducts($xml);
80
+ $result = new SimpleXMLElement($result);
81
+ //Mage::log('Response Update XML :' . $result->asXML(), null, Flubit_Flubit_Helper_Data::FLUBIT_UPDATE_PRODUCT);
82
+ return $result;
83
+ } catch (Exception $e) {
84
+ Mage::log(__LINE__ . ' updateFlubitProducts ', null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Method for Get Flubit Orders
90
+ *
91
+ */
92
+ public function getFlubitOrders() {
93
+ try {
94
+ $flubit = $this->_initModule();
95
+ //get flubit last order fetched time
96
+ $from = new DateTime(date('m/d/Y', strtotime('-1 year')));
97
+
98
+ $timeLastRun = Mage::getModel('flubit/ordertime')->getCollection();
99
+
100
+ $timeLastRun->getSelect()->limit(1);
101
+ //Mage::log('Log last Timestamp' . print_r($timeLastRun->getData() ,true) , null , Flubit_Flubit_Helper_Data::FLUBIT_TEST);
102
+ foreach ($timeLastRun as $lastRun) {
103
+ $from = new DateTime($lastRun->date_time);
104
+ }
105
+
106
+ //$validStatuses = array('refunded', 'cancelled', 'dispatched', 'awaiting_dispatch');
107
+ $validStatuses = array('awaiting_dispatch');
108
+
109
+ foreach ($validStatuses as $status) {
110
+ $orderArray = $flubit->getOrders($from, $status);
111
+ //Mage::log('Log order Array ' . print_r($orderArray, true), null, 'orderarray.log');
112
+ $num_orders = count($orderArray);
113
+ //Mage::log('Log orders count ' . $num_orders , null , 'testlognoe.log');
114
+ if ($num_orders > 0) {
115
+ //Mage::log(print_r($orderArray,true) . 'Log orders count ' . $num_orders . print_r($from, True) , null , 'testlognoe.log');
116
+ try {
117
+ $order_last = end($orderArray);
118
+ $lasrOrderTimeRaw = $order_last['created_at'];
119
+
120
+ $lasrOrderTimeArr = explode('+', $lasrOrderTimeRaw);
121
+ $lasrOrderTimePre = $lasrOrderTimeArr[0];
122
+ $addOneSec = '';
123
+
124
+ if ($num_orders != 100)
125
+ $addOneSec = '+1 seconds ';
126
+
127
+ $lasrOrderTimeTot = strtotime($addOneSec . $lasrOrderTimePre);
128
+ $updateLastOrderTime = date('Y-m-d H:i:s', $lasrOrderTimeTot);
129
+ if (is_object($lastRun)) {
130
+ // insert the last order created time ignoring the timezone
131
+ $lastRun->setDateTime($updateLastOrderTime)
132
+ ->setFetchedOrders($num_orders)
133
+ ->save();
134
+ } else {
135
+ $first_run = Mage::getModel('flubit/ordertime');
136
+ $first_run->setDateTime($updateLastOrderTime)
137
+ ->setFetchedOrders($num_orders)
138
+ ->save();
139
+ }
140
+ } catch (Exception $e) {
141
+ Mage::log('Time Update Exception Log ' . $e, NULL, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
142
+ }
143
+ }
144
+ if (count($orderArray) > 0) {
145
+ $request = 'Requested Date Time ' . print_r($from, true) . '. Flubit Orders with Status :' . $status;
146
+ $this->logFlubitOrdersRequestResponse($request, $orderArray, 'fetchOrder', 0, 0);
147
+ }
148
+ if (!$this->createOrderInMagento($orderArray)) {
149
+ break;
150
+ }
151
+ }
152
+ } catch (Exception $e) {
153
+ Mage::log(__LINE__ . ' getFlubitOrders ', null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
154
+ }
155
+ }
156
+
157
+ /**
158
+ * Method for Inactive Products
159
+ *
160
+ * @param string $sku
161
+ * @param integer $status
162
+ * @return array
163
+ */
164
+ public function inactiveProduct($sku, $status = 0) {
165
+ try {
166
+ $flubit_products = Mage::getModel('flubit/flubit')->getCollection()
167
+ ->addfieldtofilter('sku', $sku);
168
+ foreach ($flubit_products as $flubitprd) {
169
+ $price = $flubitprd->getPrice();
170
+ $qty = $flubitprd->getQty();
171
+ }
172
+
173
+ $flubit = $this->_initModule();
174
+ $productXml = <<<EOH
175
+ <?xml version="1.0" encoding="UTF-8"?>
176
+ <products>
177
+ <product sku="$sku">
178
+ <is_active>false</is_active>
179
+ <base_price>$price</base_price>
180
+ <stock>$qty</stock>
181
+ </product>
182
+ </products>
183
+ EOH;
184
+ //Mage::log('Request Update XML :' . $productXml, null, Flubit_Flubit_Helper_Data::FLUBIT_UPDATE_PRODUCT);
185
+ $res = $flubit->updateProducts($productXml);
186
+ Mage::log($res . '______', null, 'hum.log');
187
+ $result = simplexml_load_string($res);
188
+ Mage::log($result, null, 'hum.log');
189
+ //Mage::log('Response Update XML :' . $result->asXML(), null, Flubit_Flubit_Helper_Data::FLUBIT_UPDATE_PRODUCT);
190
+ if ($result->getName() == 'id') {
191
+ $this->logFlubitOrdersRequestResponse($productXml, $result->asXML(), 'deleteProduct', 0, 0, $result[0]);
192
+ }
193
+ $json = json_encode($result);
194
+ $res_array = json_decode($json, TRUE);
195
+ return $res_array[0];
196
+ } catch (Exception $e) {
197
+ Mage::log(__LINE__ . ' inactiveProduct ', null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
198
+ }
199
+ }
200
+
201
+ /**
202
+ * Method for get Products Feed Status
203
+ *
204
+ * @param string $feed
205
+ * @param string $result
206
+ * @return array
207
+ */
208
+ public function getproductFeedStatus($feed, $result = '') {
209
+ try {
210
+ $flubit = $this->_initModule();
211
+ //Mage::log('Request Feed ID :' . $feed, null, Flubit_Flubit_Helper_Data::FLUBIT_CHECK_FEED);
212
+ $res = $flubit->getProductsFeed($feed);
213
+ Mage::log('Response :' . $res, null, Flubit_Flubit_Helper_Data::FLUBIT_CHECK_FEED);
214
+ Mage::log('Response Feed ID :' . $feed, null, Flubit_Flubit_Helper_Data::FLUBIT_CHECK_FEED);
215
+ if ($result == 'xml') {
216
+ return $res;
217
+ } else {
218
+ $result = simplexml_load_string($res);
219
+ $json = json_encode($result);
220
+ $res_array = json_decode($json, TRUE);
221
+ return $res_array['results']['updated'];
222
+ }
223
+ } catch (Exception $e) {
224
+ Mage::log('Exception Get Product Feed Status' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
225
+ }
226
+ }
227
+
228
+ /**
229
+ * Method for Create order in Magento
230
+ *
231
+ * @param array $orderArray
232
+ * @return boolean
233
+ */
234
+ public function createOrderInMagento($orderArray) {
235
+ foreach ($orderArray as $key => $value) {
236
+ try {
237
+ $outOfStock = FALSE;
238
+ $OrderFailing = FALSE;
239
+ if (trim(strtolower($value['status'])) != 'awaiting_dispatch') {
240
+ continue;
241
+ }
242
+ $ordersCollection = Mage::getModel('sales/order')->getCollection();
243
+ $ordersCollection->addFieldToFilter('flubit_order_id', $key);
244
+ Mage::log($ordersCollection->getData(), null, 'flubit_magento_create_order.log');
245
+ Mage::log(count($ordersCollection), null, 'flubit_magento_create_order.log');
246
+ Mage::log(count($ordersCollection), null, 'flubit_magento_create_order.log');
247
+ if (count($ordersCollection) != 0) {
248
+ if (count($orderArray["$key"]) > 0) {
249
+ //Mage::log(print_r($orderArray["$key"], true), null, 'flubit_magento_create_order.log');
250
+ //$request = 'Flubit order id <b>: ' . print_r($orderArray["$key"]) . '</b> Already Exist in Magento. ', true);
251
+ //$this->logFlubitOrdersRequestResponse($request, 'Order Exist in Magento Flubit order id is Order ID : ' . $key, 'insertOrder', 0, 1, $key);
252
+ }
253
+ continue;
254
+ }
255
+
256
+ $flubitOrderId = $key;
257
+ $quote = Mage::getModel('sales/quote');
258
+ $quote->setIsMultiShipping(false)
259
+ ->setStore(Mage::app()->getDefaultStoreView())
260
+ ->setIsSuperMode(true);
261
+ $subtotal = 0;
262
+ $shipping_amount = ($value['shipping_cost']) ? $value['shipping_cost'] : 0;
263
+ $tax_percentage = 0;
264
+ $data = array();
265
+ foreach ($value['products'] as $pValue) {
266
+ $sku = $pValue['@attributes']['sku'];
267
+ $taxRate = (($pValue['tax_rate'] / 100) + 1);
268
+
269
+ //Flubit customization at item row level
270
+ $price = $pValue['unit_price_sold_at'];
271
+ $tax_percentage = $pValue['tax_rate'];
272
+ $tax_amount = $price - ($price / $taxRate);
273
+ $original_price = $pValue['unit_base_price'];
274
+ $rowsubtotal = $price * $pValue['quantity'];
275
+ $discount = 0;
276
+ $row_total = $rowsubtotal + $tax_amount;
277
+
278
+ //Prepare totals
279
+ $subtotal+= $rowsubtotal;
280
+
281
+ $productid = Mage::getModel('catalog/product')->getIdBySku(trim($sku));
282
+ $product = Mage::getModel('catalog/product')->load($productid);
283
+
284
+ if (!$product->getId()) {
285
+ //$request = 'Flubit order id <b>: ' . print_r($orderArray["$key"]) . '</b> Already Exist in Magento. ', true);
286
+ $this->logFlubitOrdersRequestResponse(print_r($orderArray["$key"], true), 'Product SKU: <b>"' . trim($sku) . '</b>" does not exists in Magento for Flubit Order ID: ' . $key, 'insertOrder', 0, 1, 'Flubit order id :' . $key);
287
+ Mage::log('Product SKU: ' . trim($sku) . ' does not exists in Magento ', null, Flubit_Flubit_Helper_Data::FLUBIT_CREATE_ORDER);
288
+ $OrderFailing = TRUE;
289
+ continue;
290
+ }
291
+
292
+ $stock = $product->getStockItem();
293
+ if (!$stock->getIsInStock()) {
294
+ Mage::log('Product SKU: ' . $product->getSku() . ' is not in stock for Flubit Order ID: ' . $key, null, Flubit_Flubit_Helper_Data::FLUBIT_CREATE_ORDER);
295
+ $this->logFlubitOrdersRequestResponse(print_r($orderArray["$key"], true), 'Product SKU: <b>"' . $product->getSku() . '"</b> is not in stock for Flubit Order ID: ' . $key, 'insertOrder', 0, 1, 'Flubit order id :' . $key);
296
+ $outOfStock = TRUE;
297
+ $OrderFailing = TRUE;
298
+ continue;
299
+ }
300
+
301
+ //prepare items data
302
+ $data[trim($sku)]['unit_base_price'] = $original_price;
303
+ $data[trim($sku)]['unit_price_sold_at'] = $price;
304
+ $data[trim($sku)]['row_subtotal'] = $rowsubtotal;
305
+
306
+ $quote_item = Mage::getModel('flubit/quote_item');
307
+ $quote_item
308
+ ->setProduct($product)
309
+ ->setPrice($price)
310
+ ->setOriginalPrice($original_price)
311
+ ->setCustomPrice($price)
312
+ ->setOriginalCustomPrice($price)
313
+ ->setSubtotal($rowsubtotal)
314
+ ->setDiscountAmount($discount)
315
+ ->setRowTotal($rowsubtotal)
316
+ ->setQuote($quote)
317
+ ->setQty((integer) $pValue['quantity']);
318
+ $quote->addItem($quote_item);
319
+ }
320
+
321
+ if ($outOfStock || $OrderFailing) {
322
+ continue;
323
+ }
324
+
325
+ $shippingArray = $value['shipping_address'];
326
+ $name = explode(" ", (string) $shippingArray['name']);
327
+
328
+ $firstname = $name[0];
329
+ $lastname = isset($name[1]) ? $name[1] : '';
330
+ if (!isset($shippingArray['address1'])) {
331
+ Mage::log('address 1 ' . trim($shippingArray['address1']) . ' Missing for Flubit Order ID: ' . $key, null, Flubit_Flubit_Helper_Data::FLUBIT_CREATE_ORDER);
332
+ $this->logFlubitOrdersRequestResponse(print_r($orderArray["$key"], true), 'address 1 <b>"' . trim($shippingArray['address1']) . '"</b> Missing for Flubit Order ID: ' . $key, 'insertOrder', 0, 1, 'Flubit order id :' . $key);
333
+ continue;
334
+ }
335
+ /* set address1,address2,state as blank if user doesnot provide address1,address2 and state */
336
+ $address1 = ((count($shippingArray['address1']) > 0) ? (string) $shippingArray['address1'] : '');
337
+ $address2 = ((count($shippingArray['address2']) > 0) ? (string) $shippingArray['address2'] : '');
338
+
339
+ $state = ((count($shippingArray['state']) > 0) ? (string) $shippingArray['state'] : '');
340
+
341
+ $billingAddress = array(
342
+ 'firstname' => $firstname,
343
+ 'lastname' => $lastname,
344
+ //'company' => '',
345
+ 'email' => $shippingArray['email'],
346
+ 'street' => array(
347
+ $address1,
348
+ $address2
349
+ ),
350
+ 'city' => (string) $shippingArray['city'],
351
+ 'region_id' => '',
352
+ 'region' => $state,
353
+ 'postcode' => (string) $shippingArray['postal_code'],
354
+ 'country_id' => (string) $shippingArray['country_code'],
355
+ 'telephone' => $shippingArray['phone'],
356
+ 'customer_password' => '',
357
+ 'confirm_password' => '',
358
+ 'save_in_address_book' => '0',
359
+ 'use_for_shipping' => '1',
360
+ );
361
+
362
+ //set order is flubit
363
+ Mage::getSingleton('checkout/session')->setData('flubit_order', true);
364
+
365
+ $quote->getBillingAddress()
366
+ ->setShouldIgnoreValidation(true)
367
+ ->addData($billingAddress);
368
+
369
+ $quote->getShippingAddress()
370
+ ->setShouldIgnoreValidation(true)
371
+ ->addData($billingAddress);
372
+
373
+ // Create Shipment
374
+ $shipping_cost = $shipping_amount;
375
+
376
+ Mage::getSingleton('checkout/session')
377
+ ->setData('shipping_price', $shipping_cost);
378
+
379
+ $quote->getShippingAddress()
380
+ ->setShippingMethod('flatrate_flatrate')
381
+ ->setCollectShippingRates(true)
382
+ ->collectShippingRates();
383
+
384
+ $quote->setCheckoutMethod('guest')
385
+ ->setCustomerId(null)
386
+ ->setCustomerFirstname($firstname)
387
+ ->setCustomerLastname($lastname)
388
+ ->setCustomerEmail($quote->getBillingAddress()->getEmail())
389
+ ->setCustomerIsGuest(true)
390
+ ->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
391
+
392
+ // Create Payment
393
+ $quote->getShippingAddress()
394
+ ->setPaymentMethod('flubitterms');
395
+ $payment = $quote->getPayment();
396
+ $payment->importData(array('method' => 'flubitterms'));
397
+
398
+ $quote->collectTotals();
399
+ $quote->save();
400
+
401
+ //create order
402
+ if ($quote && ($quote instanceof Mage_Sales_Model_Quote)) {
403
+ $service = Mage::getModel('sales/service_quote', $quote);
404
+
405
+ $quote->setGrandTotal($subtotal + 0 + $shipping_cost);
406
+ $quote->setBaseGrandTotal($subtotal + 0 + $shipping_cost);
407
+ if (method_exists($service, 'submitAll')) {
408
+ $service->submitAll();
409
+ $order = $service->getOrder();
410
+ } else {
411
+ $order = $service->submit();
412
+ }
413
+
414
+ //check if order object present
415
+ if (!$order || !($order instanceof Mage_Sales_Model_Order)) {
416
+ Mage::log('Order Object is undefined for flubit order ' . $flubitOrderId, null, Flubit_Flubit_Helper_Data::FLUBIT_CREATE_ORDER);
417
+ continue;
418
+ }
419
+
420
+ $order->setGrandTotal(($subtotal + 0 + $shipping_cost));
421
+ $order->setBaseGrandTotal(($subtotal + 0 + $shipping_cost));
422
+ $order->setTaxAmount(0);
423
+ $order->setShippingAmount($shipping_cost);
424
+ $order->setBaseShippingAmount($shipping_cost);
425
+ $order->setShippingInclTax($shipping_cost);
426
+ $order->setBaseShippingInclTax($shipping_cost);
427
+ $order->setFlubitOrderId($flubitOrderId);
428
+ $order->setFlubitOrderTaxRate($tax_percentage)
429
+ ->save();
430
+
431
+ // FIX fields amount & taxes
432
+ $products = Mage::getResourceModel('sales/order_item_collection')
433
+ ->setOrderFilter($order->getId());
434
+ foreach ($products as $product) {
435
+ $product->setBasePrice($data[$product->getSku()]['unit_price_sold_at']);
436
+ $product->setPrice($data[$product->getSku()]['unit_price_sold_at']);
437
+ $product->setSubtotal($data[$product->getSku()]['row_subtotal']);
438
+ $product->setBaseSubtotal($data[$product->getSku()]['row_subtotal']);
439
+ $product->setRowTotal($data[$product->getSku()]['row_subtotal']);
440
+ $product->setBaseRowTotal($data[$product->getSku()]['row_subtotal']);
441
+ $product->setPriceInclTax($data[$product->getSku()]['row_subtotal']);
442
+ $product->setBasePriceInclTax($data[$product->getSku()]['row_subtotal']);
443
+ $product->setRowTotalInclTax($data[$product->getSku()]['row_subtotal']);
444
+ $product->setBaseRowTotalInclTax($data[$product->getSku()]['row_subtotal']);
445
+ $product->setBaseTaxAmount(0);
446
+ $product->setTaxAmount(0);
447
+ $product->save();
448
+ }
449
+ $order->setBaseTaxAmount(0);
450
+ $order->setTaxAmount(0);
451
+ $order->setBaseSubtotal($subtotal);
452
+ $order->setSubtotal($subtotal);
453
+ $order->setBaseSubtotalInclTax($subtotal);
454
+ $order->setSubtotalInclTax($subtotal);
455
+
456
+ $order->setBaseShippingTaxAmount(0);
457
+ $order->setShippingTaxAmount(0);
458
+ $order->save();
459
+
460
+ if ($order->canInvoice()) {
461
+ $invoiceId = Mage::getModel('sales/order_invoice_api')
462
+ ->create($order->getIncrementId(), array());
463
+ Mage::log('Invoice created for order ' . $order->getIncrementId() . '. Invoice Id is: ' . $invoiceId, null, 'flubitinvoice.log');
464
+ }
465
+ } else {
466
+ Mage::log('Quote object is undefined for order ' . $flubitOrderId, null, Flubit_Flubit_Helper_Data::FLUBIT_CREATE_ORDER);
467
+ continue;
468
+ }
469
+
470
+
471
+ try {
472
+ $flubitCollection = Mage::getModel('flubit/order')->getCollection();
473
+ $flubitCollection->addFieldToFilter('order_no', $order->getIncrementId());
474
+
475
+ if (count($flubitCollection) == 0) {
476
+ $flubitOrder = Mage::getModel('flubit/order');
477
+ $flubitOrder->setOrderNo($order->getIncrementId());
478
+ $flubitOrder->setStatus($order->getStatus());
479
+ $flubitOrder->setFlubitOrderId($flubitOrderId);
480
+ $flubitOrder->save();
481
+
482
+ $response = 'Flubit order ID : <b>"' . $flubitOrderId . '"</b> has been inserted successfully to Magento.';
483
+ //$request = 'Flubit order ID : ' . $flubitOrderId. ' has been inserted successfully to Magento.';
484
+ $feedid = 'Flubit order ID : "' . $flubitOrderId .'"';
485
+ $this->logFlubitOrdersRequestResponse(print_r($orderArray["$key"], true), $response, 'insertOrder', 0, 0, $feedid);
486
+ }
487
+ } catch (Exception $e) {
488
+ Mage::log('Order Insert into flubit table= ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_CREATE_ORDER);
489
+ }
490
+
491
+ Mage::getSingleton('checkout/session')->setData('flubit_order', false);
492
+ } catch (Exception $e) {
493
+ Mage::log('Order Exception = ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_CREATE_ORDER);
494
+ }
495
+ }
496
+ return true;
497
+ }
498
+
499
+ /**
500
+ *
501
+ * Method for Dispatch Flubit Orders
502
+ */
503
+ public function dispatchFlubitOrders() {
504
+ $flubit = $this->_initModule();
505
+ $collection = Mage::getModel('sales/order')->getCollection();
506
+ $collection->addFieldToFilter('main_table.status', 'complete');
507
+ $collection->addFieldToSelect('flubit_order_id');
508
+ $collection->addFieldToSelect('created_at');
509
+ $collection->getSelect()->join(array('flubit_order' => Mage::getConfig()->getTablePrefix() . 'flubit_order'), 'flubit_order.order_no = main_table.increment_id and flubit_order.dispatch = 0 and flubit_order.refund = 0', array('flubit_order.flubit_order_id', 'flubit_order.flubit_id'));
510
+
511
+ foreach ($collection as $order) {
512
+ $datetime = date("Y-m-d\TH:i:sP", strtotime($order->getCreatedAt()));
513
+ $response = $flubit->dispatchOrderByFlubitId($order->getFlubitOrderId(), $datetime, '');
514
+ $xmlObjRes = simplexml_load_string($response);
515
+ if ($xmlObjRes->getName() == 'success') {
516
+ $flubitorder = Mage::getModel('flubit/order')->load($order->getFlubitId());
517
+ if ($flubitorder->getId()) {
518
+ $flubitorder->setDispatch('1')
519
+ ->save();
520
+ }
521
+ Mage::log('Order Dispatched Response' . $response, null, Flubit_Flubit_Helper_Data::FLUBIT_DISPATCH_ORDER);
522
+ $request = 'Flubit order ID : <b>"' . $order->getFlubitOrderId() . '"</b> has been sent for dispatch.';
523
+ $feedid = 'Flubit order ID : "' . $order->getFlubitOrderId() .'"';
524
+ $this->logFlubitOrdersRequestResponse($request, $response, 'dispatchOrder', 1, 0, $feedid);
525
+ } else {
526
+ Mage::log('Order Dispatched Response' . $response, null, Flubit_Flubit_Helper_Data::FLUBIT_DISPATCH_ORDER);
527
+ $request = 'Flubit order ID : <b>"' . $order->getFlubitOrderId() . '"</b> has been sent for dispatch.';
528
+ $feedid = 'Flubit order ID : "' . $order->getFlubitOrderId() . '"';
529
+ $this->logFlubitOrdersRequestResponse($request, $response, 'dispatchOrder', 0, 1, $feedid);
530
+ }
531
+ }
532
+ }
533
+
534
+ /**
535
+ *
536
+ * Method for Cancel Flubit Orders
537
+ */
538
+ public function cancelFlubitOrders($flubitOrderId=0) {
539
+ $flubit = $this->_initModule();
540
+ if($flubitOrderId != 0) {
541
+ $response = $flubit->cancelOrderByFlubitId($flubitOrderId, 'Order cancelled');
542
+ $xmlObjRes = simplexml_load_string($response);
543
+ if ($xmlObjRes->getName() == 'success') {
544
+
545
+ $collection = Mage::getModel('flubit/order')->getCollection();
546
+ $collection->addFieldToFilter('flubit_order_id', $flubitOrderId);
547
+ $collection->addFieldToSelect('flubit_id');
548
+ foreach ($collection as $refund) {
549
+ $refund->setData(array('flubit_id' => $refund->getFlubitId(),'refund' => '1'))
550
+ ->save();
551
+ }
552
+
553
+ Mage::log('Order Cancel success Response' . $response, null, Flubit_Flubit_Helper_Data::FLUBIT_CANCEL_ORDER);
554
+ Mage::log('Order Cancel success Request' . $request, null, Flubit_Flubit_Helper_Data::FLUBIT_CANCEL_ORDER);
555
+ $request = 'Flubit order ID : "' . $flubitOrderId . '" has been sent for cancelled.';
556
+ $feedid = 'Flubit order ID : "' . $flubitOrderId . '"';
557
+ $this->logFlubitOrdersRequestResponse($request, $response, 'cancelOrder', 1, 0, $feedid);
558
+ } else {
559
+ Mage::log('Order Cancel Response' . $response, null, Flubit_Flubit_Helper_Data::FLUBIT_CANCEL_ORDER);
560
+ Mage::log('Order Cancel Request' . $request, null, Flubit_Flubit_Helper_Data::FLUBIT_CANCEL_ORDER);
561
+ $request = 'Flubit order ID : "' . $flubitOrderId . '" has been sent for cancelled.';
562
+ $feedid = 'Flubit order ID : "' . $flubitOrderId . '"';
563
+ $this->logFlubitOrdersRequestResponse($request, $response, 'cancelOrder', 0, 1, $feedid);
564
+ }
565
+ } else {
566
+ $collection = Mage::getModel('sales/order')->getCollection();
567
+ $collection->addFieldToFilter('main_table.status', 'closed');
568
+ $collection->addFieldToSelect('flubit_order_id');
569
+ $collection->addFieldToSelect('created_at');
570
+ $collection->getSelect()->join(array('flubit_order' => Mage::getConfig()->getTablePrefix() . 'flubit_order'), 'flubit_order.order_no = main_table.increment_id and flubit_order.dispatch = 0 and flubit_order.refund = 0', array('flubit_order.flubit_order_id', 'flubit_order.flubit_id'));
571
+
572
+ foreach ($collection as $order) {
573
+ $response = $flubit->cancelOrderByFlubitId($order->getFlubitOrderId(), 'Order cancelled');
574
+ $xmlObjRes = simplexml_load_string($response);
575
+ if ($xmlObjRes->getName() == 'success') {
576
+ $flubitorder = Mage::getModel('flubit/order')->load($order->getFlubitId());
577
+ if ($flubitorder->getId()) {
578
+ $flubitorder->setRefund('1')
579
+ ->save();
580
+ }
581
+ Mage::log('Order Cancel Success Response' . $response, null, Flubit_Flubit_Helper_Data::FLUBIT_CANCEL_ORDER);
582
+ Mage::log('Order Cancel Request' . $request, null, Flubit_Flubit_Helper_Data::FLUBIT_CANCEL_ORDER);
583
+ $request = 'Flubit order ID : "' . $order->getFlubitOrderId() . '" has been sent for cancelled.';
584
+ $feedid = 'Flubit order ID : "' . $order->getFlubitOrderId() . '"';
585
+ $this->logFlubitOrdersRequestResponse($request, $response, 'cancelOrder', 1, 0, $feedid);
586
+ } else {
587
+ Mage::log('Order Cancel Response' . $response, null, Flubit_Flubit_Helper_Data::FLUBIT_CANCEL_ORDER);
588
+ Mage::log('Order Cancel Request' . $request, null, Flubit_Flubit_Helper_Data::FLUBIT_CANCEL_ORDER);
589
+ $request = 'Flubit order ID : "' . $order->getFlubitOrderId() . '" has been sent for cancelled.';
590
+ $feedid = 'Flubit order ID : "' . $order->getFlubitOrderId() . '"';
591
+ $this->logFlubitOrdersRequestResponse($request, $response, 'cancelOrder', 0, 1, $feedid);
592
+ }
593
+ }
594
+ }
595
+
596
+
597
+ }
598
+
599
+
600
+ /**
601
+ *
602
+ * Method for Refund Flubit Orders
603
+ */
604
+ public function refundFlubitOrders($flubitOrderId=0) {
605
+
606
+ $flubit = $this->_initModule();
607
+ if($flubitOrderId != 0) {
608
+ $response = $flubit->refundOrderByFlubitId($flubitOrderId, 'Order Refunded');
609
+ $xmlObjRes = simplexml_load_string($response);
610
+ if ($xmlObjRes->getName() == 'success') {
611
+ $flubitorder = Mage::getModel('flubit/order')->load($order->getFlubitId());
612
+ if ($flubitorder->getId()) {
613
+ Mage::log($flubitorder->getId(), null, Flubit_Flubit_Helper_Data::FLUBIT_REFUND_ORDER);
614
+ $flubitorder->setRefund('1')
615
+ ->save();
616
+ }
617
+ //Mage::log('Order Dispatched for flubit ID:' . $order->getFlubitOrderId(), null, Flubit_Flubit_Helper_Data::FLUBIT_REFUND_ORDER);
618
+ Mage::log('Order Refunded Response' . $response, null, Flubit_Flubit_Helper_Data::FLUBIT_REFUND_ORDER);
619
+ $request = 'Flubit order ID : <b>"' . $order->getFlubitOrderId() . '"</b> has been sent for refund.';
620
+ $feedid = 'Flubit order ID : "' . $order->getFlubitOrderId() . '"';
621
+ $this->logFlubitOrdersRequestResponse($request, $response, 'refundOrder', 1, 0, $feedid);
622
+ } else if ($xmlObjRes->getName() == 'error') {
623
+ $flubitorder = Mage::getModel('flubit/order')->load($order->getFlubitId());
624
+ if ($flubitorder->getId()) {
625
+ $flubitorder->setRefund('1')
626
+ ->save();
627
+ }
628
+ Mage::log('Order Refunded Response' . $response, null, Flubit_Flubit_Helper_Data::FLUBIT_REFUND_ORDER);
629
+ $request = 'Flubit order ID : <b>"' . $order->getFlubitOrderId() . '"</b> has been sent for refund.';
630
+ $feedid = 'Flubit order ID : "' . $order->getFlubitOrderId() . '"';
631
+ $this->logFlubitOrdersRequestResponse($request, $response, 'refundOrder', 0, 1, $feedid);
632
+ } else {
633
+ Mage::log('Order Refunded Response' . $response, null, Flubit_Flubit_Helper_Data::FLUBIT_REFUND_ORDER);
634
+ $request = 'Flubit order ID : <b>"' . $order->getFlubitOrderId() . '"</b> has been sent for refund.';
635
+ $feedid = 'Flubit order ID : "' . $order->getFlubitOrderId() . '"';
636
+ $this->logFlubitOrdersRequestResponse($request, $response, 'refundOrder', 0, 1, $feedid);
637
+ }
638
+ } else {
639
+ $collection = Mage::getModel('sales/order')->getCollection();
640
+ $collection->addFieldToFilter('main_table.status', 'closed');
641
+ $collection->addFieldToSelect('flubit_order_id');
642
+ $collection->addFieldToSelect('created_at');
643
+ $collection->getSelect()->join(array('flubit_order' => Mage::getConfig()->getTablePrefix() . 'flubit_order'), 'flubit_order.order_no = main_table.increment_id and flubit_order.dispatch = 1 and flubit_order.refund = 0 ', array('flubit_order.flubit_order_id', 'flubit_order.flubit_id'));
644
+
645
+ foreach ($collection as $order) {
646
+ $response = $flubit->refundOrderByFlubitId($order->getFlubitOrderId(), 'Order Refunded');
647
+ $xmlObjRes = simplexml_load_string($response);
648
+ if ($xmlObjRes->getName() == 'success') {
649
+ $flubitorder = Mage::getModel('flubit/order')->load($order->getFlubitId());
650
+ if ($flubitorder->getId()) {
651
+ Mage::log($flubitorder->getId(), null, Flubit_Flubit_Helper_Data::FLUBIT_REFUND_ORDER);
652
+ $flubitorder->setRefund('1')
653
+ ->save();
654
+ }
655
+ //Mage::log('Order Dispatched for flubit ID:' . $order->getFlubitOrderId(), null, Flubit_Flubit_Helper_Data::FLUBIT_REFUND_ORDER);
656
+ Mage::log('Order Refunded Response' . $response, null, Flubit_Flubit_Helper_Data::FLUBIT_REFUND_ORDER);
657
+ $request = 'Flubit order ID : <b>"' . $order->getFlubitOrderId() . '"</b> has been sent for refund.';
658
+ $feedid = 'Flubit order ID : "' . $order->getFlubitOrderId() . '"';
659
+ $this->logFlubitOrdersRequestResponse($request, $response, 'refundOrder', 1, 0, $feedid);
660
+ } else if ($xmlObjRes->getName() == 'error') {
661
+ $flubitorder = Mage::getModel('flubit/order')->load($order->getFlubitId());
662
+ if ($flubitorder->getId()) {
663
+ $flubitorder->setRefund('1')
664
+ ->save();
665
+ }
666
+ Mage::log('Order Refunded Response' . $response, null, Flubit_Flubit_Helper_Data::FLUBIT_REFUND_ORDER);
667
+ $request = 'Flubit order ID : <b>"' . $order->getFlubitOrderId() . '"</b> has been sent for refund.';
668
+ $feedid = 'Flubit order ID : "' . $order->getFlubitOrderId() . '"';
669
+ $this->logFlubitOrdersRequestResponse($request, $response, 'refundOrder', 0, 1, $feedid);
670
+ } else {
671
+ Mage::log('Order Refunded Response' . $response, null, Flubit_Flubit_Helper_Data::FLUBIT_REFUND_ORDER);
672
+ $request = 'Flubit order ID : <b>"' . $order->getFlubitOrderId() . '"</b> has been sent for refund.';
673
+ $feedid = 'Flubit order ID : "' . $order->getFlubitOrderId() . '"';
674
+ $this->logFlubitOrdersRequestResponse($request, $response, 'refundOrder', 0, 1, $feedid);
675
+ }
676
+ }
677
+ }
678
+ }
679
+
680
+ /**
681
+ *
682
+ * @param integer $country_id
683
+ * @param integer $state
684
+ * @return array
685
+ */
686
+ public function getRegionCode($country_id = null, $state = null) {
687
+
688
+ $collection = Mage::getModel('directory/country')->getResourceCollection()->loadByStore();
689
+
690
+ return $collection;
691
+ }
692
+
693
+ /**
694
+ * Method to log fubit orders process
695
+ *
696
+ *
697
+ */
698
+ function logFlubitOrdersRequestResponse($request, $response, $mode, $parseResponse = 0, $error = 0, $ForderId = '') {
699
+
700
+ $level = 1;
701
+
702
+ if ($error == 1)
703
+ $level = 2;
704
+
705
+ if ($mode == 'fetchOrder') {
706
+ $type = 'Fetch Order';
707
+ } else if ($mode == 'dispatchOrder') {
708
+ $type = 'Dispatch Order';
709
+ } else if ($mode == 'refundOrder') {
710
+ $type = 'Refund Order';
711
+ } else if ($mode == 'cancelOrder') {
712
+ $type = 'Cancel Order';
713
+ } else if ($mode == 'insertOrder') {
714
+ $type = 'Order in Magento';
715
+ } else if ($mode == 'deleteProduct') {
716
+ $type = 'Delete Product';
717
+ }
718
+
719
+ $action = array(
720
+ 'fetchOrder' => 3,
721
+ 'dispatchOrder' => 4,
722
+ 'refundOrder' => 5,
723
+ 'cancelOrder' => 6,
724
+ 'insertOrder' => 7,
725
+ 'deleteProduct' => 9
726
+ );
727
+
728
+ if ((is_array($request)) || (is_object($request))) {
729
+ $request = print_r($request, TRUE);
730
+ }
731
+ if ((is_array($response)) || (is_object($response))) {
732
+ $response = print_r($response, TRUE);
733
+ }
734
+
735
+ if ($parseResponse == 1) {
736
+ $xml = simplexml_load_string($response);
737
+ //$xml = new SimpleXMLElement($response);
738
+ Mage::log('Xml Parse :' . $xml->asXML(), null, 'xmlparse.log');
739
+ if ($xml->getName() == 'error') {
740
+ $level = 2;
741
+ } else if (($xml->getName() == 'success')) {
742
+ $level = 1;
743
+ }
744
+ }
745
+ //Mage::log('Xml :' .$response , null, 'xmlparse-resp.log');
746
+ // if ($ForderId != '')
747
+ // $ForderId = 'Order ID ' . $ForderId;
748
+
749
+ if (($request != '') && ($response != '')) {
750
+ try {
751
+ $flubitlog = Mage::getModel('flubitlog/flubitlog');
752
+ $flubitlog->setData(
753
+ array(
754
+ 'request_xml' => $request,
755
+ 'feedid' => $ForderId,
756
+ 'response_xml' => $response,
757
+ 'action' => $action[$mode],
758
+ 'datetime' => date('Y-m-d H:i:s'),
759
+ 'level' => $level
760
+ )
761
+ )
762
+ ->save();
763
+ } catch (Exception $e) {
764
+ Mage::log('Log Saving Exception' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
765
+ }
766
+ }
767
+ }
768
+
769
+ }
app/code/community/Flubit/Flubit/Model/Cron.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Cron
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Cron {
11
+
12
+ /**
13
+ * Method for Product Update
14
+ *
15
+ */
16
+ public function productUpdate() {
17
+ //do something
18
+ }
19
+
20
+ }
app/code/community/Flubit/Flubit/Model/Flubit.php ADDED
@@ -0,0 +1,1123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Flubit
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Flubit extends Mage_Core_Model_Abstract {
11
+
12
+ const CONSUMER_API = 'flubit_section/flubit_configuration/flubit_consumer_key';
13
+ const SECRET_KEY = 'flubit_section/flubit_configuration/flubit_secret';
14
+ const CONSUMER_URL = 'flubit_section/flubit_configuration/flubit_url';
15
+ const LOG_TYPE = 'flubit_section/flubit_setup/log_type_list';
16
+ const LOGDATE_OLDER = 'flubit_section/flubit_setup/logdate_cron_settings';
17
+
18
+ /**
19
+ * Constructor for load Flubit Order
20
+ *
21
+ */
22
+ protected function _construct() {
23
+ try {
24
+ $this->_init("flubit/flubit");
25
+ } catch (Exception $e) {
26
+ Mage::log('_construct ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
27
+ }
28
+ }
29
+
30
+ /**
31
+ * Method to get Flubit Orders
32
+ */
33
+ public function getFlubitOrders() {
34
+ try {
35
+ $config = Mage::getModel('flubit/config');
36
+ $data = $config->getFlubitOrders();
37
+ } catch (Exception $e) {
38
+ Mage::log('getFlubitOrders ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Method to Process Flubit Orders
44
+ */
45
+ public function processFlubitOrders() {
46
+ try {
47
+ $this->refundFlubitOrders();
48
+ } catch (Exception $e) {
49
+ Mage::log('processFlubitOrders ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Method to Dispatch Flubit Orders
55
+ */
56
+ public function dispatchFlubitOrders() {
57
+ try {
58
+ $config = Mage::getModel('flubit/config');
59
+ $data = $config->dispatchFlubitOrders();
60
+ } catch (Exception $e) {
61
+ Mage::log('dispatchFlubitOrders ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Method to Cancel Flubit Orders
67
+ */
68
+ public function cancelFlubitOrders() {
69
+ try {
70
+ $config = Mage::getModel('flubit/config');
71
+ $data = $config->cancelFlubitOrders();
72
+ } catch (Exception $e) {
73
+ Mage::log('cancelFlubitOrders ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Method to Refund Flubit Orders
79
+ */
80
+ public function refundFlubitOrders() {
81
+ try {
82
+ $config = Mage::getModel('flubit/config');
83
+ $data = $config->refundFlubitOrders();
84
+ } catch (Exception $e) {
85
+ Mage::log('refundFlubitOrders ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Method to Send Product Feed
91
+ */
92
+ public function sendProductFeed() {
93
+ try {
94
+ $this->_updateFlubitPrices();
95
+ $this->_updateFlubitQty();
96
+ $this->generateProductXML();
97
+ } catch (Exception $e) {
98
+ Mage::log('sendProductFeed ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Method to delete log files and flubitlog table
104
+ */
105
+ public function archiveLog() {
106
+ //Mage::log('archive',null,'hum.log');
107
+ //$olderthen = Mage::getStoreConfig(self::LOGDATE_OLDER);
108
+ $logbefore = date('Y-m-d h:i:s', strtotime('-' . 30 . ' day'));
109
+ $flubitlogs = Mage::getModel('flubitlog/flubitlog')->getCollection();
110
+ $flubitlogs->addFieldToFilter('datetime', array('lteq' => $logbefore));
111
+ $flubitlogs->load();
112
+ foreach ($flubitlogs as $flubitlog) {
113
+ $flubitlog->delete();
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Method to Generate Product Xml
119
+ */
120
+ public function generateProductXML() { // generate product xml and send to flubit
121
+ $configure = $this->checkConfiguration();
122
+ if ($configure->error == 'true' && $configure->right == 'false') {
123
+ Mage::throwException('Missing Keys in configuration');
124
+ }
125
+ // end checking of configuration
126
+ $this->_checkPendingFeedStatus();
127
+
128
+ // get the configuration from the file
129
+ $chunkSize = 10; // define if chunk size is not defined
130
+ $errorString = ''; // define blank error string
131
+ $returnString = '';
132
+ $errorFeed = '';
133
+ $productCount = 0;
134
+ $error = FALSE;
135
+ try {
136
+ $chunkSize = Mage::getStoreConfig('flubit_section/flubit_setup/flubit_chunk');
137
+ } catch (Exception $e) {
138
+ Mage::log('Could not retrive chunk size ' . $e, NULL, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
139
+ }
140
+ $allSku = array();
141
+
142
+ // get flubit collection for the prodcuts which are needed to be pushed
143
+ try {
144
+ $flubit_products = Mage::getModel('flubit/flubit')->getCollection()
145
+ ->addFieldToFilter('status', '1')
146
+ ->addFieldToFilter('is_deleted', '0')
147
+ ->setOrder('flubit_id', 'ASC')
148
+ ->setPageSize($chunkSize);
149
+
150
+ if (is_object($flubit_products)) {
151
+ if (count($flubit_products) > 0) {
152
+
153
+ $create_feed_prodcut_xml = ''; // initialise the new product xml
154
+ $update_feed_prodcut_xml = ''; // initialise the update product xml
155
+
156
+ $store = Mage::app()->getStore(); // get deafult store
157
+ $tax_calculation_obj = Mage::getModel('tax/calculation')->getRateRequest(null, null, null, $store);
158
+
159
+ $newXML = '';
160
+ $updateXML = '';
161
+
162
+
163
+ foreach ($flubit_products as $flubit_Prodcut) {
164
+ // get magento product id for the given sku
165
+ if ($flubit_Prodcut->getSku() == '') { // we cannot proceed further if sku is missing
166
+ Mage::log('Missing SKU for flubit product ', NULL, Flubit_Flubit_Helper_Data::FLUBIT_CREATE_PRODUCT);
167
+ // save the status to zero so that its called next time only once its updated from backend
168
+ $flubit_Prodcut->setStatus('0')
169
+ ->save();
170
+ continue;
171
+ }
172
+ $product_id = Mage::getModel('catalog/product')->getIdBySku(trim($flubit_Prodcut->getSku()));
173
+ $product = Mage::getModel('catalog/product')->load($product_id);
174
+
175
+ // check if the prodcut exist in magento
176
+ if (!$product->getId()) {
177
+ Mage::log('Sku ' . $product->getSku() . ' does not found in Magento.', null, Flubit_Flubit_Helper_Data::FLUBIT_FAILED_PRODUCT);
178
+ $flubit_Prodcut->setStatus('0')
179
+ ->save();
180
+ continue;
181
+ }
182
+ // if there is no EAN, ASIN, ISBN or MPN we can't push it to Flubit
183
+ if (!$this->checkEanValidation($product)) {
184
+ if (is_object($product)) {
185
+
186
+ $errorString .= '<tr>
187
+ <td style="padding:4px;">' . $product->getName() . '</td>
188
+ <td style="padding:4px;">' . $product->getSku() . ' </td>
189
+ <td style="padding:4px;"> ' . 'Missing Identifiers. ' . '</td>
190
+ </tr>';
191
+
192
+ $response = 'Product SKU : <b>"' . $product->getSku() . '"</b> identifiers is blank. Please update the data where appropriate and send again. ';
193
+ $feedid = 'Product identifiers validation failed.';
194
+
195
+ $this->logFlubitProductsRequestResponse('', $response, 'Create Product', $feedid);
196
+
197
+ Mage::log($product->getSku() . ' missing identifiers', null, Flubit_Flubit_Helper_Data::FLUBIT_FAILED_PRODUCT);
198
+ // save the status to zero so that its called next time only once its updated from backend
199
+ $flubit_Prodcut->setStatus('0')
200
+ ->save();
201
+ } else {
202
+ Mage::log('Product was deleted from Magento SKU :' . $product->getSku(), null, Flubit_Flubit_Helper_Data::FLUBIT_FAILED_PRODUCT);
203
+ }
204
+ continue;
205
+ }
206
+ // if there is no image we can't push it to Flubit
207
+ if (!$this->checkImageValidation($product)) {
208
+
209
+ $errorString .= '<tr>
210
+ <td style="padding:4px;">' . $product->getName() . '</td>
211
+ <td style="padding:4px;">' . $product->getSku() . ' </td>
212
+ <td style="padding:4px;"> ' . 'No image is uploaded, so cannot be pushed to Flubit' . ' </td>
213
+ </tr>';
214
+
215
+ $response = 'Product SKU <b>"' . $product->getSku() . '"</b> image is not available. Please update the data where appropriate and send again. ';
216
+ $feedid = 'Product image validation failed.';
217
+ $this->logFlubitProductsRequestResponse('', $response, 'Create Product', $feedid);
218
+ Mage::log($product->getSku() . ' Image is not available. please update and send again.', null, Flubit_Flubit_Helper_Data::FLUBIT_FAILED_PRODUCT);
219
+ //the product has not been pushed and so should be treated as new
220
+ // save the status to zero so that its called next time only once its updated from backend
221
+ $flubit_Prodcut->setStatus('0')
222
+ ->save();
223
+ continue;
224
+ }
225
+
226
+
227
+ $flubit_stat = $product->getFlubitProduct(); // if product flubit stat is true
228
+ $status_stat = $product->getStatus(); // check if the product is active or inactive in magento
229
+ $stock = $product->getStockItem();
230
+ //Mage::log($stock->getData(), null, 'test.log');
231
+ $stock_status = $stock->getIsInStock();
232
+
233
+ $qtyStock = 0;
234
+ try {
235
+ $qtyStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty();
236
+ $taxclassid = $product->getData('tax_class_id');
237
+ $percent = Mage::getModel('tax/calculation')->getRate($tax_calculation_obj->setProductClassId($taxclassid));
238
+ } catch (Exception $e) {
239
+ Mage::log(__LINE__ . ' Exception getting cataloginventory/stock_item tax/calculation Model data ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
240
+ }
241
+
242
+ if ((floor($qtyStock) != $qtyStock)) { // check if the quantity is decimal
243
+ $errorString .= '<tr>
244
+ <td style="padding:4px;">' . $product->getName() . '</td>
245
+ <td style="padding:4px;">' . $product->getSku() . ' </td>
246
+ <td style="padding:4px;"> ' . 'Quantity is in decimal. Product cannot be pushed to Flubit.' . ' </td>
247
+ </tr>';
248
+
249
+ $response = 'Product SKU <b>"' . $product->getSku() . '"</b> quantity is in decimal. Please Insert it in integer only.';
250
+ $feedid = 'Product quantity validation failed.';
251
+ $this->logFlubitProductsRequestResponse('', $response, 'Create Product', $feedid);
252
+
253
+ Mage::log('quantity is in decimal = ' . $qtyStock, null, 'flubit_create_product.log');
254
+ $flubit_Prodcut->setStatus('0')
255
+ ->save();
256
+ continue;
257
+ }
258
+
259
+ if (($flubit_stat == 1) && ($status_stat == 1) && ($stock_status) && ($qtyStock > 0)) {
260
+ $status = 'true';
261
+ } else {
262
+ $status = 'false';
263
+ }
264
+
265
+ if ($flubit_Prodcut->getNew() == '1') {
266
+ if ($product->getSku() != '') { // check if prodcut SKU is not null
267
+ $newXML .= '<product sku="' . $product->getSku() . '">';
268
+ $newXML .= '<title><![CDATA[' . $product->getName() . ']]></title>';
269
+ $newXML .= "<is_active>$status</is_active>";
270
+ $newXML .= '<base_price>' . (number_format($flubit_Prodcut->getPrice(), 2, '.', '')) . '</base_price>';
271
+ $newXML .= '<stock>' . number_format((int) $qtyStock, 0, '.', '') . '</stock>';
272
+ $newXML .= '<description><![CDATA[' . $this->removeNonUtfCharacters($product->getDescription()) . ']]></description>';
273
+
274
+ if ($product->getImage() != 'no_selection') {
275
+ $newXML .= '<images>';
276
+ $image_path = Mage::helper('catalog/image')->init($product, 'image');
277
+ $newXML .= '<image><![CDATA[' . $image_path . ']]></image>';
278
+ $newXML .= ' </images>';
279
+ }
280
+ if ($product->getFlubitEan() || $product->getFlubitAsin() || $product->getFlubitIsbn() || $product->getFlubitMpn()) {
281
+ $newXML .= '<identifiers>';
282
+ if ($product->getFlubitEan())
283
+ $newXML .= '<identifier type="EAN">' . $product->getFlubitEan() . '</identifier>';
284
+ if ($product->getFlubitAsin())
285
+ $newXML .= '<identifier type="ASIN">' . $product->getFlubitAsin() . '</identifier>';
286
+ if ($product->getFlubitIsbn())
287
+ $newXML .= '<identifier type="ISBN">' . $product->getFlubitIsbn() . '</identifier>';
288
+ if ($product->getFlubitMpn())
289
+ $newXML .= '<identifier type="MPN">' . $product->getFlubitMpn() . '</identifier>';
290
+ $newXML .= '</identifiers>';
291
+ }
292
+ if ($product->getFlubitBrand())
293
+ $newXML .= '<brand>' . $product->getFlubitBrand() . '</brand>';
294
+ if ($product->getFlubitStandardDelivery() || $product->getFlubitExpressDelivery()) {
295
+ $newXML .= '<delivery_cost>';
296
+ if ($product->getFlubitStandardDelivery())
297
+ $newXML .= '<standard>' . number_format($product->getFlubitStandardDelivery(), 2, '.', '') . '</standard>';
298
+ if ($product->getFlubitExpressDelivery())
299
+ $newXML .= '<express>' . number_format($product->getFlubitExpressDelivery(), 2, '.', '') . '</express>';
300
+ $newXML .= '</delivery_cost>';
301
+ }
302
+ if ($product->getWeight())
303
+ $newXML .= '<weight>' . number_format($product->getWeight(), 1, '.', '') . '</weight>';
304
+ if ($percent)
305
+ $newXML .= '<tax_rate>' . number_format($percent, 2, '.', '') . '</tax_rate>';
306
+ $newXML .= '</product>';
307
+ }
308
+ } else {
309
+ $updateXML .= '<product sku="' . $product->getSku() . '">';
310
+ $updateXML .= "<is_active>$status</is_active>";
311
+ $updateXML .= '<base_price>' . (number_format($flubit_Prodcut->getPrice(), 2, '.', '')) . '</base_price>';
312
+ $updateXML .= '<stock>' . number_format($qtyStock, 0, '.', '') . '</stock>';
313
+ $updateXML .= '</product>';
314
+ }
315
+
316
+ // set the flubit product status in flubit
317
+
318
+ try {
319
+ $flubitActiveStatus = '0';
320
+ if ($status == 'true')
321
+ $flubitActiveStatus = '1';
322
+ if ($flubit_Prodcut->getActiveStatus() != $flubitActiveStatus) {
323
+ //$flubit_Prodcut->setData(array('flubit_id' => $flubit_Prodcut->getId(), 'active_status' => $flubitActiveStatus))
324
+ $flubit_Prodcut->setActiveStatus($flubitActiveStatus)
325
+ ->save();
326
+ }
327
+ } catch (Exception $e) {
328
+ Mage::log(__LINE__ . 'Exception Savingt flubit/flubit Model data ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
329
+ }
330
+ $allSku[] = $product->getSku();
331
+ //Mage::log('Prodcut ' . print_r($product->getData(), TRUE ) , NULL, 'optimise.log');
332
+ }
333
+ // end for each of product list generation
334
+
335
+ if ($newXML != '') {
336
+ $create_feed_prodcut_xml = '<?xml version="1.0" encoding="UTF-8"?><products>' . $newXML . '</products>';
337
+ }
338
+ if ($updateXML != '') {
339
+ $update_feed_prodcut_xml = '<?xml version="1.0" encoding="UTF-8"?><products>' . $updateXML . '</products>';
340
+ }
341
+ //Mage::log($create_feed_prodcut_xml, NULL, 'CreateProduct.xml');
342
+ //Mage::log($update_feed_prodcut_xml, NULL, 'UpdateProduct.xml');
343
+ //Mage::log(print_r($allSku, TRUE), NULL, 'allSku.xml');
344
+ // preparing error String to be displayed on press of sync button
345
+ $productCount = count($allSku);
346
+
347
+ if ($errorString != '') {
348
+ $errorString = '<div>Following product(s) has failed.</div><br/>
349
+ <style type="text/css">
350
+ #tableOuter1{
351
+ border-style: solid;
352
+ border-width: 1px;
353
+ border-collapse: collapse;
354
+ margin: 0;
355
+ padding:4;
356
+ width:100%;
357
+ }
358
+
359
+ #tableOuter1 th,#tableOuter1 td{
360
+ border-style: solid;
361
+ border-width: 0 1px 1px 0;
362
+ border-collapse: collapse;
363
+ margin: 0;
364
+ padding:4;
365
+ }
366
+ </style>
367
+ <table id="tableOuter1" cellspacing="0" cellpadding="0">
368
+ <tr>
369
+ <th width="250"><strong>Product Name</strong></th>
370
+ <th width="250"><strong>Product SKU</strong></th>
371
+ <th width="250"><strong>Error Message</strong></th>
372
+ </tr>
373
+ ' . $errorString . '
374
+ </table>';
375
+ }
376
+ $failed_sku_create = array();
377
+ $failed_sku_update = array();
378
+ $createFailedCount = 0;
379
+ $updateFailedCount = 0;
380
+ $feedError = '';
381
+ $feedStatus = '';
382
+ $feedMode = '';
383
+ $feedResponseXML = '';
384
+ // get model of config
385
+ $config = Mage::getModel('flubit/config');
386
+ // send the prodcuct create feed to flubit and save the id returned to log
387
+ if ($create_feed_prodcut_xml != '') { // if create product feed is not null send to flubit
388
+ $create_result = $config->createFlubitProducts($create_feed_prodcut_xml);
389
+ if ($create_result != '') {
390
+ Mage::log($create_result, NULL, 'createfeed.log');
391
+ if (is_object($create_result)) {
392
+ if ($create_result->getName() == 'id') {
393
+ $this->feedLog($create_result, 'Create');
394
+ $returnString .= 'Created Feed ID : ' . (String) $create_result . '<br/>';
395
+ // get the feed response if its a create feed
396
+ $feedCheckResponseCreate = $this->getFeedErrors($create_result);
397
+
398
+ $createFailedCount = $feedCheckResponseCreate->failedCount;
399
+ $errorString .= $feedCheckResponseCreate->html;
400
+ $failed_sku_create = $feedCheckResponseCreate->sku;
401
+ $feedError .= $feedCheckResponseCreate->error;
402
+ $feedResponseCreateXML = $feedCheckResponseCreate->responsexml;
403
+
404
+ $this->logFlubitProductsRequestResponse($create_feed_prodcut_xml, $feedResponseCreateXML, 'Create Product', $create_result);
405
+ // if feedresponse is fetched and is a success mark it to db as fetched
406
+ $feedResponseCreateXML = simplexml_load_string($feedResponseCreateXML);
407
+ if ($feedResponseCreateXML['status'] == 'processed') {
408
+ if ($feedResponseCreateXML->results->errors->total == 0) {
409
+ $this->feedResponseFetchedMarkToDb($create_result);
410
+ }
411
+ }
412
+ }
413
+ }
414
+ } else {
415
+ Mage::throwException('Response not received from flubit for create product request.');
416
+ }
417
+ }
418
+ // send the prodcuct uppdate feed to flubit and save the id returned to log
419
+ if ($update_feed_prodcut_xml != '') { // if create product feed is not null send to flubit
420
+ $update_result = $config->updateFlubitProducts($update_feed_prodcut_xml);
421
+ if ($update_result != '') {
422
+ Mage::log(print_r($update_result, true), NULL, 'updatefeed.log');
423
+ if (is_object($update_result)) {
424
+ if ($update_result->getName() == 'id') {
425
+ $this->feedLog($update_result, 'update');
426
+ $returnString .= 'Updated Feed ID : ' . (String) $update_result . '<br/>';
427
+ // get the feed response if its a update feed
428
+ $feedCheckResponseUpdate = $this->getFeedErrors($update_result);
429
+
430
+ $updateFailedCount = $feedCheckResponseUpdate->failedCount;
431
+ $errorString .= $feedCheckResponseUpdate->html;
432
+ $failed_sku_update = $feedCheckResponseUpdate->sku;
433
+ $feedError .= $feedCheckResponseUpdate->error;
434
+ $feedResponseupdateXML = $feedCheckResponseUpdate->responsexml;
435
+
436
+ $this->logFlubitProductsRequestResponse($update_feed_prodcut_xml, $feedResponseupdateXML, 'Update Product', $update_result);
437
+ // if feedresponse is fetched and is a success mark it to db as fetched
438
+ $feedResponseupdateXML = simplexml_load_string($feedResponseupdateXML);
439
+ if ($feedResponseupdateXML['status'] == 'processed') {
440
+ if ($feedResponseupdateXML->results->errors->total == 0) {
441
+ $this->feedResponseFetchedMarkToDb($update_result);
442
+ }
443
+ }
444
+ }
445
+ }
446
+ } else {
447
+ Mage::throwException('Response not received from flubit for update product request.');
448
+ }
449
+ }
450
+
451
+ // get differance of failed SKU from create and update
452
+ $allSku = array_diff($allSku, $failed_sku_create);
453
+ $allSku = array_diff($allSku, $failed_sku_update);
454
+
455
+ if ($errorFeed == '') {
456
+ try {
457
+ $flubits = Mage::getModel('flubit/flubit')->getCollection();
458
+ $flubits->addFieldToFilter('sku', array('in' => $allSku))
459
+ ;
460
+ foreach ($flubits as $flubit) {
461
+ $flubit
462
+ ->setStatus('2')
463
+ ->setNew('0')
464
+ ->save();
465
+ }
466
+ } catch (Exception $e) {
467
+ Mage::log(__LINE__ . ' Exception Savingt flubit/flubit Model data ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
468
+ }
469
+ }
470
+ }
471
+ }
472
+ } catch (Exception $e) {
473
+ $error = $e->getMessage();
474
+ Mage::log('Try getting flubit prodcuts data ' . $e, NULL, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
475
+ }
476
+
477
+ if (!$error) {
478
+ if ($productCount != 0) {
479
+ $returnString .= "\n\t<p>Total Products Pushed: " . ($productCount - $createFailedCount - $updateFailedCount ) . '</p>';
480
+ if ($errorString != '')
481
+ Mage::getSingleton('adminhtml/session')->addError($errorString);
482
+ } else if (($productCount == 0 ) && ($errorFeed != '')) {
483
+ $returnString = "<p>Prodcuts not pushed. Please Retry</p>";
484
+ } else {
485
+ $returnString = "<p>There are $productCount products to be pushed to Flubit.</p>";
486
+ if ($errorString != '')
487
+ Mage::getSingleton('adminhtml/session')->addError($errorString);
488
+ }
489
+ } else {
490
+ Mage::log('Error Occured ' . $error, null, Flubit_Flubit_Helper_Data::FLUBIT_FAILED_PRODUCT);
491
+ Mage::throwException($error);
492
+ }
493
+ return $returnString;
494
+ }
495
+
496
+ /**
497
+ * Method to check feed and insert into Logs table
498
+ * @param string
499
+ * @return None
500
+ */
501
+ public function feedLog($feedId, $type) {
502
+ if (($feedId != '') && ($type != '')) {
503
+ try {
504
+ $feedModel = Mage::getModel('flubit/logs');
505
+ $feedModel->setFeedType($type)
506
+ ->setFeedId($feedId)
507
+ ->setStatus('0')
508
+ ->setCreatedAt(date('Y-m-d H:i:s'))
509
+ ->save();
510
+ } catch (Exception $e) {
511
+ Mage::log(__LINE__ . ' Exception Flubit Feed Log ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
512
+ }
513
+ }
514
+ }
515
+
516
+ /**
517
+ * Method to check server side validation for blank check key & secret
518
+ * @param string
519
+ * @return boolean
520
+ */
521
+ public function checkConfiguration() {
522
+ $return = new stdClass();
523
+ $return->right = 'false';
524
+ $return->error = 'false';
525
+
526
+ try {
527
+ $api = Mage::getStoreConfig(self::CONSUMER_API);
528
+ $key = Mage::getStoreConfig(self::SECRET_KEY);
529
+ $url = Mage::getStoreConfig(self::CONSUMER_URL);
530
+
531
+ if (!empty($api) && !empty($key) && !empty($url)) {
532
+ $obj = new Flubit_Flubit_Client($api, $key, $url);
533
+
534
+ $return->right = 'true';
535
+ } else {
536
+ Mage::log('Missing Keys in configuration', null, Flubit_Flubit_Helper_Data::FLUBIT_MISSING_CONFIG);
537
+ $return->error = 'true';
538
+ }
539
+ } catch (Exception $e) {
540
+ Mage::log('Missing Keys in configuration', null, Flubit_Flubit_Helper_Data::FLUBIT_MISSING_CONFIG);
541
+ $return->error = 'true';
542
+ }
543
+ return $return;
544
+ }
545
+
546
+ /**
547
+ * Method to update global price according to configuration
548
+ * @param integer $product
549
+ * @return int
550
+ */
551
+ public function updateFlubitPrice() {
552
+ //Mage::log('price',null,'hum.log');
553
+ try {
554
+ $priceBasedOn = Mage::getStoreConfig('flubit_section/flubit_setup/price_based_on');
555
+ $globalPrice = Mage::getStoreConfig('flubit_section/flubit_setup/global_price');
556
+ $flubitCollection = Mage::getModel('flubit/flubit')->getCollection()
557
+ ->addfieldtofilter('use_global_price', '1')
558
+ ->addfieldtofilter('global_price_update', '0')
559
+ ->addFieldToSelect('sku')
560
+ ->addFieldToSelect('flubit_id')
561
+ ->addFieldToSelect('price')
562
+ ->setOrder('flubit_id', 'DESC')
563
+ ->setPageSize('200');
564
+ //Mage::log($flubitCollection->getData(), null, 'hum.log');
565
+ foreach ($flubitCollection as $flubit) {
566
+ $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $flubit->getSku());
567
+ if (is_object($product)) {
568
+ if ($priceBasedOn) {
569
+ $priceOfProduct = $product->getData($priceBasedOn); // Get price based on selected price
570
+ } else {
571
+ $priceOfProduct = $product->getPrice($priceBasedOn); // get default magento price
572
+ }
573
+
574
+ $flubitPrice = $priceOfProduct - ($priceOfProduct * ($globalPrice / 100));
575
+ $flubitPrice = number_format($flubitPrice, 2, '.', '');
576
+
577
+ if ($flubitPrice != $flubit->getPrice()) {
578
+ //updating the price in the main table
579
+ $flubit->setPrice($flubitPrice)
580
+ ->setGlobalPriceUpdate('1')
581
+ ->setStatus('1')
582
+ ->save();
583
+ }
584
+ } // product object check
585
+ }
586
+ } catch (Exception $e) {
587
+ Mage::log(__LINE__ . ' Exception get flubit price Model data ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
588
+ }
589
+ return 0;
590
+ }
591
+
592
+ /**
593
+ * Method to get Flubit Price
594
+ * @param integer $product
595
+ * @return int
596
+ */
597
+ public function getFlubitPrice($product) {
598
+ try {
599
+ $priceBasedOn = Mage::getStoreConfig('flubit_section/flubit_setup/price_based_on');
600
+ $globalPrice = Mage::getStoreConfig('flubit_section/flubit_setup/global_price');
601
+
602
+ if (is_object($product)) {
603
+
604
+ $flubitProduct = Mage::getModel('flubit/flubit')->getcollection()->addfieldtofilter('sku', $product->getSku());
605
+ $flubitPriceUseGlobal = 0; // set by default
606
+ foreach ($flubitProduct as $flubit) {
607
+ $flubitPriceUseGlobal = $flubit->getUseGlobalPrice();
608
+ }
609
+ // if global price is zero than calculate with the given conditions
610
+ if (($product->getFlubitBasePrice() != 0.00) && ($flubitPriceUseGlobal == 0))
611
+ return $product->getFlubitBasePrice(); // return default flubit price
612
+ else if ($priceBasedOn)
613
+ $priceBasedOn = $product->getData($priceBasedOn); // Get price based on selected price
614
+ else {
615
+ $priceBasedOn = $product->getPrice($priceBasedOn); // get default magento price
616
+ }
617
+ $flubitPrice = $priceBasedOn - ($priceBasedOn * ($globalPrice / 100));
618
+ $flubitPrice = number_format($flubitPrice, 2, '.', '');
619
+ //$product->setFlubitBasePrice($flubitPrice)->save();
620
+ if ($flubitPriceUseGlobal == 0) {
621
+ if (is_object($flubit)) {
622
+ $flubit->setUseGlobalPrice(1)
623
+ ->save();
624
+ }
625
+ }
626
+ return $flubitPrice;
627
+ }
628
+ } catch (Exception $e) {
629
+ Mage::log(__LINE__ . ' Exception get flubit price Model data ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
630
+ }
631
+ return 0;
632
+ }
633
+
634
+ /**
635
+ * Method to Update Flubit Price
636
+ */
637
+ private function _updateFlubitPrices() {
638
+ try {
639
+ $flubitCollection = Mage::getModel('flubit/flubit')->getCollection();
640
+
641
+ foreach ($flubitCollection as $flubit) {
642
+ $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $flubit->getSku());
643
+ if (is_object($product)) {
644
+ $flubitPrice = $this->getFlubitPrice($product);
645
+
646
+ if (($flubitPrice != $flubit->getPrice()) || ($product->getFlubitBasePrice() != $flubitPrice)) {
647
+ try {
648
+ //updating the price in the main table
649
+ $flubit->setPrice($flubitPrice)
650
+ ->setStatus('1')
651
+ ->save();
652
+ //updating the product attribute flubit base price
653
+ $product->setFlubitBasePrice($flubitPrice)
654
+ ->save();
655
+ } catch (Exception $e) {
656
+ Mage::log('Update Flubit Price Exception ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
657
+ }
658
+ }
659
+ }
660
+ }
661
+ } catch (Exception $e) {
662
+ Mage::log(__LINE__ . ' Exception updateFlubitPrices Model data ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
663
+ }
664
+ }
665
+
666
+ /**
667
+ * Method to Update Flubit Quantity
668
+ */
669
+ private function _updateFlubitQty() {
670
+ try {
671
+ $flubitCollection = Mage::getModel('flubit/flubit')->getCollection();
672
+
673
+ foreach ($flubitCollection as $flubit) {
674
+ $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $flubit->getSku());
675
+ $qty = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty();
676
+
677
+ if ($qty != (int) $flubit->getQty()) {
678
+ //updating the Qty in the main table
679
+ $flubit->setQty($qty)
680
+ ->setStatus('1')
681
+ ->save();
682
+ }
683
+ }
684
+ } catch (Exception $e) {
685
+ Mage::log(__LINE__ . ' Exception _updateFlubitQty ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
686
+ }
687
+ }
688
+
689
+ /**
690
+ * Method for Check Ean, Asin, Isbn, Mpn
691
+ *
692
+ * @param String $pr
693
+ * @return boolean
694
+ */
695
+ public function checkEanValidation($pr) {
696
+ try {
697
+ if (is_object($pr)) {
698
+ if ($pr->getFlubitEan() || $pr->getFlubitAsin() || $pr->getFlubitIsbn() || $pr->getFlubitMpn()) {
699
+ return true;
700
+ }
701
+ }
702
+ return false;
703
+ } catch (Exception $e) {
704
+ Mage::log(__LINE__ . ' Exception checkEanValidation ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
705
+ }
706
+ }
707
+
708
+ /**
709
+ * Method for Check Image not Blank
710
+ *
711
+ * @param String $pr
712
+ * @return boolean
713
+ */
714
+ public function checkImageValidation($pr) {
715
+ if ($pr->getImage() != 'no_selection') {
716
+ try {
717
+ $image_path = Mage::helper('catalog/image')->init($pr, 'image');
718
+ if ($image_path != '') {
719
+ return true;
720
+ }
721
+ } catch (Exception $e) {
722
+ Mage::log(__LINE__ . ' Exception Image Validation ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
723
+ }
724
+ }
725
+ return false;
726
+ }
727
+
728
+ /**
729
+ * Method for Check Image not Blank
730
+ *
731
+ * @param String $pr
732
+ * @return boolean
733
+ */
734
+ public function checkQuantityValidation($pr) {
735
+ //Mage::log($pr->getQty() , null, flubit_create_product.log);
736
+ if (is_int($pr->getQty())) {
737
+ return true;
738
+ }
739
+ return false;
740
+ }
741
+
742
+ /**
743
+ * Method to remove non utf character
744
+ *
745
+ * @param String $Str
746
+ * @return String
747
+ */
748
+ public function removeNonUtfCharacters($Str) {
749
+ try {
750
+ $StrArr = STR_SPLIT($Str);
751
+ $NewStr = '';
752
+ foreach ($StrArr as $Char) {
753
+ $CharNo = ORD($Char);
754
+ if ($CharNo == 163) {
755
+ $NewStr .= $Char;
756
+ continue;
757
+ } // keep £
758
+ if ($CharNo > 31 && $CharNo < 127) {
759
+ $NewStr .= $Char;
760
+ }
761
+ }
762
+ } catch (Exception $e) {
763
+ Mage::log(__LINE__ . ' Exception removeNonUtfCharacters ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
764
+ }
765
+ return $NewStr;
766
+ }
767
+
768
+ /**
769
+ * Method to check the status of the pushed feed
770
+ *
771
+ * @param SimpleXmlObject
772
+ * @param String mode
773
+ * @return Object
774
+ */
775
+ public function getFeedErrors($xmlObj) {
776
+ try {
777
+ //Mage::log('Check For feed id ' . $xmlObj, null, 'Test_Feed.log');
778
+ //sleep(5);
779
+ $return = new stdClass();
780
+ $return->failedCount = 0;
781
+ $return->html = '';
782
+ $return->sku = array();
783
+ $return->error = '';
784
+ $return->status = '';
785
+ $return->mode = '';
786
+ $return->responsexml = '';
787
+
788
+ try {
789
+ $config = Mage::getModel('flubit/config');
790
+ $xmlObjRes = $config->getproductFeedStatus($xmlObj, 'xml');
791
+ $return->responsexml = $xmlObjRes;
792
+ } catch (Exception $e) {
793
+ Mage::log('Exception Getting Feed Errors ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
794
+ }
795
+
796
+ $xmlObjRes = simplexml_load_string($xmlObjRes);
797
+ if (is_object($xmlObjRes)) {
798
+
799
+ if ($xmlObjRes->getName() == 'error') {
800
+ $errorCode = $xmlObjRes['code'];
801
+ $return->error = $xmlObjRes['message'];
802
+ $this->feedResponseFetchedMarkToDb($xmlObj); // feed response recived mark in database
803
+ Mage::log('Error: Code ' . $errorCode . ' Error Message : ' . $return->error, null, Flubit_Flubit_Helper_Data::FLUBIT_FEED);
804
+ } else if ($xmlObjRes->getName() == 'feed') {
805
+ if ($xmlObjRes['status'] == 'invalid') {
806
+ $return->error = 'Invalid Feed Sent to flubit';
807
+ $this->feedResponseFetchedMarkToDb($xmlObj); // feed response recived mark in database
808
+ }
809
+
810
+ if ($xmlObjRes['status'] == 'processing') {
811
+ Mage::log('Feed ID is Under Processing : ' . $xmlObj, null, Flubit_Flubit_Helper_Data::FLUBIT_FEED);
812
+ } else if ($xmlObjRes['status'] == 'processed') {
813
+ //Mage::log('hello afetr created check : ' . ' Feed Id = ' . $xmlObj , null, 'temptest.log' );
814
+ if (isset($xmlObjRes->results->created)) {
815
+ //Mage::log('afetr created check : ' . ' Feed Id = ' . $xmlObj , null, 'temptest.log' );
816
+ $return->mode = 'created';
817
+ $this->feedResponseFetchedMarkToDb($xmlObj); // feed response recived mark in database
818
+ //Mage::log('After Create mark db : ' . ' Feed Id = ' . $xmlObj , null, 'temptest.log' );
819
+ if (isset($xmlObjRes->results->errors->total)) {
820
+ if ($xmlObjRes->results->errors->total > 0) {
821
+ $return->failedCount = $xmlObjRes->results->errors->total;
822
+ $innerTable = '';
823
+ $productAlreadyExist = array();
824
+ foreach ($xmlObjRes->results->errors->sample->error as $error) {
825
+ $productName = '';
826
+ try {
827
+ $productNameObj = Mage::getModel('catalog/product')->loadByAttribute('sku', $error['sku']);
828
+ if (is_object($productNameObj))
829
+ $productName = $productNameObj->getName();
830
+ else {
831
+ Mage::log('Unable to get product Name for SKU: ' . $error['sku'], null, Flubit_Flubit_Helper_Data::FLUBIT_FEED);
832
+ }
833
+ } catch (Exception $e) {
834
+ Mage::log('Unable to get name of product Get Feed Errors ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
835
+ }
836
+ if ($error == 'Product already exists.') {
837
+ $productAlreadyExist[] = $error['sku'];
838
+ } else {
839
+ $return->sku[] = $error['sku'];
840
+ $innerTable .= '<tr>
841
+ <td style="padding:4px;">' . $productName . '</td>
842
+ <td style="padding:4px;">' . $error['sku'] . ' </td>
843
+ <td style="padding:4px;"> ' . $error . ' </td>
844
+ </tr>';
845
+ }
846
+ }
847
+ if ($innerTable != '')
848
+ $return->html = '<div>Following product(s) has failed to sync.</div><br/>
849
+ <style type="text/css">
850
+ #tableOuter{
851
+ border-style: solid;
852
+ border-width: 1px;
853
+ border-collapse: collapse;
854
+ margin: 0;
855
+ padding:4;
856
+ width:100%;
857
+ }
858
+
859
+ #tableOuter th,#tableOuter td{
860
+ border-style: solid;
861
+ border-width: 0 1px 1px 0;
862
+ border-collapse: collapse;
863
+ margin: 0;
864
+ padding:4;
865
+ }
866
+ </style>
867
+ <table id="tableOuter" cellspacing="0" cellpadding="0">
868
+ <tr>
869
+ <th width="250"><strong>Product Name</strong></th>
870
+ <th width="250"><strong>Product SKU</strong></th>
871
+ <th width="250"><strong>Error Message</strong></th>
872
+ </tr>
873
+ ' . $innerTable . '
874
+ </table>';
875
+ if (count($productAlreadyExist) > 0) {
876
+ $this->requeuFailedFeedSku($productAlreadyExist, '');
877
+ Mage::log('Update Product to be in create request :' . print_r($productAlreadyExist, true), null, 'up_error.log');
878
+ // since returned error is product already exist in list
879
+ // such that it goen in update Request
880
+ }
881
+ }
882
+ }
883
+ } else {
884
+ //Mage::log('Not Inside created block: ' . ' Feed Id = ' . $xmlObj , null, 'temptest.log' );
885
+ }
886
+ if (isset($xmlObjRes->results->updated)) {
887
+ $return->mode = 'updated';
888
+ if (isset($xmlObjRes->results->errors->total)) {
889
+ if ($xmlObjRes->results->errors->total > 0) {
890
+ $return->failedCount = $xmlObjRes->results->errors->total;
891
+ $UpdateFailedSku = array();
892
+ $innerTable = '';
893
+ foreach ($xmlObjRes->results->errors->sample->error as $error) {
894
+ $productName = '';
895
+ try {
896
+ $productName = Mage::getModel('catalog/product')->loadByAttribute('sku', $error['sku'])->getName();
897
+ } catch (Exception $e) {
898
+ Mage::log('Unable to get name of product Get Feed Errors ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
899
+ }
900
+
901
+ //$return->sku[] = $error['sku'];
902
+
903
+ if ($error == 'Product does not exist in cache.') // check if prodcut not in cache exists
904
+ $UpdateFailedSku[] = $error['sku'];
905
+ else
906
+ $return->sku[] = $error['sku'];
907
+
908
+ //Mage::log('Update Product Error :' . $error , null , 'up_error.log' );
909
+
910
+ $innerTable .= '<tr>
911
+ <td style="padding:4px;">' . $productName . '</td>
912
+ <td style="padding:4px;">' . $error['sku'] . ' </td>
913
+ <td style="padding:4px;"> ' . $error . ' </td>
914
+ </tr>';
915
+ }
916
+ if ($innerTable != '')
917
+ $return->html = '<div>Following product(s) Updates has failed to sync.</div><br/>
918
+ <style type="text/css">
919
+ #tableOuter2{
920
+ border-style: solid;
921
+ border-width: 1px;
922
+ border-collapse: collapse;
923
+ margin: 0;
924
+ padding:4;
925
+ width:100%;
926
+ }
927
+
928
+ #tableOuter2 th,#tableOuter2 td{
929
+ border-style: solid;
930
+ border-width: 0 1px 1px 0;
931
+ border-collapse: collapse;
932
+ margin: 0;
933
+ padding:4;
934
+ }
935
+ </style>
936
+ <table id="tableOuter2" cellspacing="0" cellpadding="0">
937
+ <tr>
938
+ <th width="250"><strong>Product Name</strong></th>
939
+ <th width="250"><strong>Product SKU</strong></th>
940
+ <th width="250"><strong>Error Message</strong></th>
941
+ </tr>
942
+ ' . $innerTable . '
943
+ </table>';
944
+ // update products to create new if the returned skus have not in cache error
945
+ if (count($UpdateFailedSku) > 0) {
946
+ $this->requeuFailedFeedSku($UpdateFailedSku, 'created');
947
+ //Mage::log('Update Product to be in create request :' . print_r($UpdateFailedSku,true) , null , 'up_error.log' );
948
+ // since returned error is not exist in cache we need to update product
949
+ // such that it goen in create request
950
+ }
951
+ }
952
+ }
953
+ $this->feedResponseFetchedMarkToDb($xmlObj);
954
+ // feed response recived mark in database
955
+ //Mage::log('After update mark db : ' . ' Feed Id = ' . $xmlObj , null, 'temptest.log' );
956
+ } else {
957
+ //Mage::log('Not Inside Updated Block : ' . ' Feed Id = ' . $xmlObj , null, 'temptest.log' );
958
+ }
959
+ }
960
+ } else {
961
+
962
+ }
963
+ }
964
+ return $return;
965
+ } catch (Exception $e) {
966
+ Mage::log(__LINE__ . ' Exception getFeedErrors ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
967
+ }
968
+ }
969
+
970
+ /**
971
+ * Method to mark the response of checked feed to DB
972
+ *
973
+ * @param String
974
+ * @return void
975
+ */
976
+ public function feedResponseFetchedMarkToDb($feedId) {
977
+ //Mage::log('Inside MArk feed response : ' . ' Feed Id = ' . $feedId , null, 'temptest.log' );
978
+ try {
979
+
980
+ $logs = Mage::getModel('flubit/logs')->getCollection()
981
+ ->addFieldToFilter('feed_id', $feedId);
982
+
983
+ foreach ($logs as $flb) {
984
+ //Mage::log('Save Feed Status As Fetched : ' . $flb->getId() . ' Feed Id = ' . $feedId , null, 'temptest.log' );
985
+ $flb->setData(array('flubit_id' => $flb->getId(), 'status' => 1))
986
+ ->save();
987
+ }
988
+ } catch (Exception $e) {
989
+ Mage::log('Error Saving to Database Flubit Log Exception : ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
990
+ }
991
+ }
992
+
993
+ /**
994
+ * Method to check all pending feeds whose status is not fetched
995
+ *
996
+ * @param void
997
+ * @return void
998
+ */
999
+ public function _checkPendingFeedStatus() {
1000
+ try {
1001
+ $logs = Mage::getModel('flubit/logs')->getCollection()
1002
+ ->addFieldToFilter('status', 0);
1003
+ //Mage::log(print_r($logs, true), null, 'flubit_product_feed.log');
1004
+ foreach ($logs as $flb) {
1005
+ Mage::log('Feeds Returned : ' . $flb->getFeedId(), null, 'temptest.log');
1006
+ $result = $this->getFeedErrors($flb->getFeedId());
1007
+ $this->logFlubitProductsRequestResponse('Request sent to check feed id: <b>"' . $flb->getFeedId() . '"</b>', $result->responsexml, 'Check Feed Response', $flb->getFeedId());
1008
+ if ($result->failedCount > 0) {
1009
+ Mage::log('Failed Count: ' . $result->failedCount . ' Mode = ' . $result->mode . ' SKU' . print_r($result->sku, true), null, 'temptest.log');
1010
+ $this->requeuFailedFeedSku($result->sku, $result->mode);
1011
+ }
1012
+ //Mage::log('Response : ' . print_r($result,true) , null, 'temptest.log' );
1013
+ }
1014
+ } catch (Exception $e) {
1015
+ Mage::log('Error Fetching Feeds : ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
1016
+ }
1017
+ }
1018
+
1019
+ /**
1020
+ * Method to requeue the products for create and update
1021
+ *
1022
+ * @param array
1023
+ * @param String
1024
+ *
1025
+ * @return void
1026
+ */
1027
+ public function requeuFailedFeedSku($sku, $mode) {
1028
+ try {
1029
+ if (is_array($sku)) {
1030
+ Mage::log('Requeue Failed Products: ' . print_r($sku, true), null, 'temptest.log');
1031
+ if (count($sku) > 0) {
1032
+ $new = 0;
1033
+
1034
+ if ($mode == 'created')
1035
+ $new = 1;
1036
+ foreach ($sku as $flsku) {
1037
+ $prod = Mage::getModel('flubit/flubit')->getCollection()
1038
+ ->addFieldToFilter('sku', $flsku);
1039
+ foreach ($prod as $flprod) {
1040
+ try {
1041
+ $flprod->setData(array('flubit_id' => $flprod->getId(), 'status' => 1, 'new' => $new))
1042
+ ->save();
1043
+ Mage::log('updated logs ' . $flprod->getId() . ' new = ' . $new, null, 'temptest.log');
1044
+ } catch (Exception $e) {
1045
+ Mage::log('Error Flubit product update Exception : ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
1046
+ }
1047
+ }
1048
+ }
1049
+ }
1050
+ }
1051
+ } catch (Exception $e) {
1052
+ Mage::log(__LINE__ . ' Exception getFeedErrors ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
1053
+ }
1054
+ }
1055
+
1056
+ /**
1057
+ * Method to Error logging the products for create and update and Check Feed Response
1058
+ *
1059
+ * @param array
1060
+ * @param String
1061
+ *
1062
+ * @return void
1063
+ */
1064
+ function logFlubitProductsRequestResponse($request, $response, $mode, $feedId) {
1065
+
1066
+ if ($mode == 'Create Product') {
1067
+ $action = 1;
1068
+ } else if ($mode == 'Update Product') {
1069
+ $action = 2;
1070
+ } else if ($mode == 'Check Feed Response') {
1071
+ $action = 10;
1072
+ }
1073
+ if ($request != '') {
1074
+ if ($action == 10) {
1075
+ $request = $request;
1076
+ } else {
1077
+ $dom = new DOMDocument;
1078
+ $dom->preserveWhiteSpace = FALSE;
1079
+ $dom->loadXML($request);
1080
+ $dom->formatOutput = TRUE;
1081
+ $request = $dom->saveXml();
1082
+ }
1083
+ }
1084
+ $level = 2;
1085
+
1086
+ if ($response != '' && $request != '') {
1087
+ $xmlObjResCreate = simplexml_load_string($response);
1088
+
1089
+ if ($xmlObjResCreate->getName() == 'feed') {
1090
+ if ($xmlObjResCreate['status'] == 'processing' || $xmlObjResCreate['status'] == 'awaiting_validation' || $xmlObjResCreate['status'] == 'awaiting_processing') {
1091
+ $level = 1;
1092
+ }
1093
+ if ($xmlObjResCreate['status'] == 'processed') {
1094
+ if ($xmlObjResCreate->results->errors->total == 0) {
1095
+ $level = 1;
1096
+ }
1097
+ }
1098
+ } //feed if close
1099
+ }
1100
+
1101
+
1102
+
1103
+ if (($request != '') || ($response != '')) {
1104
+ try {
1105
+ $flubitlog = Mage::getModel('flubitlog/flubitlog');
1106
+ $flubitlog->setData(
1107
+ array(
1108
+ 'request_xml' => $request,
1109
+ 'feedid' => $feedId,
1110
+ 'response_xml' => $response,
1111
+ 'action' => $action,
1112
+ 'datetime' => date('Y-m-d H:i:s'),
1113
+ 'level' => $level
1114
+ )
1115
+ )
1116
+ ->save();
1117
+ } catch (Exception $e) {
1118
+
1119
+ }
1120
+ }
1121
+ }
1122
+
1123
+ }
app/code/community/Flubit/Flubit/Model/Flubit/Chunk.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Flubit Chunk
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Flubit_Chunk {
11
+
12
+ /**
13
+ * Options getter
14
+ *
15
+ * @return array
16
+ */
17
+ public function toOptionArray() {
18
+ return array(
19
+ array('value' => "10", 'label' => Mage::helper('adminhtml')->__('10')),
20
+ array('value' => "20", 'label' => Mage::helper('adminhtml')->__('20')),
21
+ array('value' => "50", 'label' => Mage::helper('adminhtml')->__('50')),
22
+ array('value' => "100", 'label' => Mage::helper('adminhtml')->__('100')),
23
+ array('value' => "200", 'label' => Mage::helper('adminhtml')->__('200')),
24
+ array('value' => "300", 'label' => Mage::helper('adminhtml')->__('300')),
25
+ );
26
+ }
27
+
28
+ }
app/code/community/Flubit/Flubit/Model/Flubit/Logdate.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Flubit Source
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Flubit_Logdate {
11
+
12
+ /**
13
+ * Options getter
14
+ *
15
+ * @return array
16
+ */
17
+ public function toOptionArray() {
18
+ return array(
19
+ array('value' => "30", 'label' => Mage::helper('adminhtml')->__('1 Month')),
20
+ array('value' => "90", 'label' => Mage::helper('adminhtml')->__('3 Month')),
21
+ array('value' => "180", 'label' => Mage::helper('adminhtml')->__('6 Month')),
22
+ array('value' => "365", 'label' => Mage::helper('adminhtml')->__('12 Month')),
23
+ );
24
+ }
25
+
26
+ }
app/code/community/Flubit/Flubit/Model/Flubit/Logs.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Flubit Source
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Flubit_Logs {
11
+
12
+ /**
13
+ * Options getter
14
+ *
15
+ * @return array
16
+ */
17
+ public function toOptionArray() {
18
+ return array(
19
+ array('value' => "0 */24 * * *", 'label' => Mage::helper('adminhtml')->__('1day')),
20
+ array('value' => "0 0 */2 * *", 'label' => Mage::helper('adminhtml')->__('2day')),
21
+ array('value' => "0 0 */3 * *", 'label' => Mage::helper('adminhtml')->__('3day')),
22
+ array('value' => "0 0 */7 * *", 'label' => Mage::helper('adminhtml')->__('7day')),
23
+ array('value' => "0 0 */15 * *", 'label' => Mage::helper('adminhtml')->__('15day')),
24
+ );
25
+ }
26
+
27
+ }
app/code/community/Flubit/Flubit/Model/Flubit/Order.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Flubit Source
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Flubit_Order {
11
+
12
+ /**
13
+ * Options getter
14
+ *
15
+ * @return array
16
+ */
17
+ public function toOptionArray() {
18
+ return array(
19
+ array('value' => "*/3 * * * *", 'label' => Mage::helper('adminhtml')->__('3mins')),
20
+ array('value' => "*/7 * * * *", 'label' => Mage::helper('adminhtml')->__('7mins')),
21
+ array('value' => "*/14 * * * *", 'label' => Mage::helper('adminhtml')->__('14mins')),
22
+ array('value' => "*/21 * * * *", 'label' => Mage::helper('adminhtml')->__('21mins')),
23
+ array('value' => "*/28 * * * *", 'label' => Mage::helper('adminhtml')->__('28mins')),
24
+ array('value' => "*/56 * * * *", 'label' => Mage::helper('adminhtml')->__('56mins')),
25
+
26
+ );
27
+ }
28
+
29
+ }
app/code/community/Flubit/Flubit/Model/Flubit/Price.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Flubit Price
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Flubit_Price {
11
+
12
+ /**
13
+ * Options getter
14
+ *
15
+ * @return array
16
+ */
17
+ public function toOptionArray() {
18
+ return array(
19
+ array('value' => "", 'label' => ''),
20
+ array('value' => "price", 'label' => Mage::helper('adminhtml')->__('Price')),
21
+ array('value' => "special_price", 'label' => Mage::helper('adminhtml')->__('Special Price')),
22
+ array('value' => "cost", 'label' => Mage::helper('adminhtml')->__('Cost')),
23
+ array('value' => "rrp", 'label' => Mage::helper('adminhtml')->__('RRP')),
24
+ );
25
+ }
26
+
27
+ }
app/code/community/Flubit/Flubit/Model/Flubit/Rcd.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Flubit Source
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Flubit_Rcd {
11
+
12
+ /**
13
+ * Options getter
14
+ *
15
+ * @return array
16
+ */
17
+ public function toOptionArray() {
18
+ return array(
19
+ array('value' => "*/12 * * * *", 'label' => Mage::helper('adminhtml')->__('12mins')),
20
+ array('value' => "*/27 * * * *", 'label' => Mage::helper('adminhtml')->__('27mins')),
21
+ array('value' => "*/47 * * * *", 'label' => Mage::helper('adminhtml')->__('47mins')),
22
+ );
23
+ }
24
+
25
+ }
app/code/community/Flubit/Flubit/Model/Flubit/Source.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Flubit Source
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Flubit_Source {
11
+
12
+ /**
13
+ * Options getter
14
+ *
15
+ * @return array
16
+ */
17
+ public function toOptionArray() {
18
+ return array(
19
+ array('value' => "*/2 * * * *", 'label' => Mage::helper('adminhtml')->__('2mins')),
20
+ array('value' => "*/5 * * * *", 'label' => Mage::helper('adminhtml')->__('5mins')),
21
+ array('value' => "*/10 * * * *", 'label' => Mage::helper('adminhtml')->__('10mins')),
22
+ array('value' => "*/25 * * * *", 'label' => Mage::helper('adminhtml')->__('25mins')),
23
+ array('value' => "*/50 * * * *", 'label' => Mage::helper('adminhtml')->__('50mins')),
24
+ );
25
+ }
26
+
27
+ }
app/code/community/Flubit/Flubit/Model/Globalproduct.php ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Logs
5
+ *
6
+ * @package Flubit
7
+ * @category Global product update Model
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Globalproduct extends Mage_Core_Model_Abstract {
11
+
12
+ /**
13
+ * Constructor for load global update product
14
+ *
15
+ */
16
+ public function _construct() {
17
+ try {
18
+ parent::_construct();
19
+ $this->_init('flubit/globalproduct');
20
+ } catch (Exception $e) {
21
+ Mage::log(__LINE__ . 'Exception Flubit_Flubit_Model_Order _construct ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
22
+ }
23
+ }
24
+
25
+
26
+ /**
27
+ * Method to Collect Mass global update product and send in queqe
28
+ */
29
+ public function sendFlubitProductMassAttributeUpdate() {
30
+ //Mage::log('sendFlubitProductMassAttributeUpdate',null,'hum.log');
31
+ //Mage::log(print_r($observer, true));
32
+ $flubitCollection = Mage::getModel('flubit/globalproduct')->getCollection()
33
+ ->addfieldtofilter('update_status', '0')
34
+ ->addFieldToSelect('product_id')
35
+ ->addFieldToSelect('flubit_status')
36
+ ->addFieldToSelect('id')
37
+ ->setPageSize('200');
38
+ //Mage::log($flubitCollection->getData(), null, 'hum.log');
39
+ foreach ($flubitCollection as $flubitglobal) {
40
+ $product[] = $flubitglobal->getFlubitStatus() . '_' . $flubitglobal->getProductId();
41
+ $flubitglobal->setUpdateStatus('1')
42
+ ->save();
43
+ }
44
+ if(count($product) > 0)
45
+ $this->saveFlubitProductMassAttributeData($product);
46
+ }
47
+
48
+
49
+ /**
50
+ * Method for Mass Update Flubit Products
51
+ *
52
+ * @param Varien_Event_Observer $observer
53
+ * @return Boolean
54
+ */
55
+ public function saveFlubitProductMassAttributeData($productlist = array()) {
56
+ try {
57
+ foreach ($productlist as $product) {
58
+ $product = explode("_",$product);
59
+ $type = $product[0];
60
+ $product_id = $product[1];
61
+ $product = Mage::getModel('catalog/product')->load($product_id);
62
+ $flubit = Mage::getModel('flubit/flubit')->load($product->getSku(), 'sku');
63
+ if ($flubit->getId() != '') {
64
+ $flubit->setName($product->getName())
65
+ ->setStatus('1')
66
+ ->save();
67
+ } else {
68
+ if ($type == '1') {
69
+ //Mage::log(print_r($product->getData(),true), null, 'hum.log');
70
+ $this->_saveFlubitProductData($product);
71
+ }
72
+ }
73
+ }
74
+ return;
75
+ } catch (Exception $e) {
76
+ Mage::log(__LINE__ . 'saveFlubitProduct ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Method for Save Flubit Products
82
+ *
83
+ * @param Xml String $product
84
+ * @return array
85
+ */
86
+ private function _saveFlubitProductData($product) {
87
+ try {
88
+ if ($product->getSku() == '') {
89
+ Mage::log($product->getId() . ' no sku', null, 'hum.txt');
90
+ return;
91
+ }
92
+ Mage::log('SKU : ' . $product->getSku() . ' ID '. $product->getId(), null, 'hum.txt');
93
+ $flubit = Mage::getModel('flubit/flubit')->load($product->getSku(), 'sku');
94
+
95
+ $flubitObj = Mage::getModel('flubit/flubit');
96
+ //$flubitPrice = (number_format($flubitObj->getFlubitPrice($product), 2, '.', ''));
97
+
98
+ $qty = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty();//$flubitObj->getQty();
99
+ //Mage::log(print_r($qty, TRUE), null, 'hum.txt');
100
+ Mage::log('Quantity = ' . $qty, null, 'hum.txt');
101
+ if ($flubit->getId() == '') {
102
+ $flubit = Mage::getModel('flubit/flubit');
103
+ $flubit->setName($product->getName())
104
+ ->setSku($product->getSku())
105
+ ->setPrice(0)
106
+ ->setQty($qty)
107
+ ->setStatus('1')
108
+ ->setNew('1')
109
+ ->save();
110
+ } else {
111
+ if (($this->checkEanValidation($product) && $this->checkImageValidation($product))) {
112
+ $flubit->setName($product->getName())
113
+ ->setSku($product->getSku())
114
+ ->setPrice(0)
115
+ ->setQty($qty)
116
+ ->setStatus('1')
117
+ ->save();
118
+ }
119
+ }
120
+ } catch (Exception $e) {
121
+ Mage::log(__LINE__ . '_saveFlubitProductData ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
122
+ }
123
+ try {
124
+ if (is_object($flubit)) {
125
+ $flubitPrice = (number_format($flubitObj->getFlubitPrice($product), 2, '.', ''));
126
+ $flubit->setPrice($flubitPrice)
127
+ ->save();
128
+ }
129
+ } catch (Exception $e) {
130
+ Mage::log(__LINE__ . '_saveFlubitProductData ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
131
+ }
132
+ }
133
+
134
+
135
+ }
app/code/community/Flubit/Flubit/Model/Logs.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Logs
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Logs extends Mage_Core_Model_Abstract {
11
+
12
+ /**
13
+ * Constructor for Flubit logs
14
+ *
15
+ */
16
+ public function _construct() {
17
+ try {
18
+ parent::_construct();
19
+ $this->_init('flubit/logs');
20
+ } catch (Exception $e) {
21
+ Mage::log(__LINE__ . ' Flubit_Flubit_Model_Logs Exception _construct ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
22
+ }
23
+ }
24
+
25
+ }
app/code/community/Flubit/Flubit/Model/Logtype.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Logs
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model_Ordertime
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Logtype extends Mage_Core_Model_Abstract {
11
+ /**
12
+ * Constant define for logging type
13
+ *
14
+ */
15
+
16
+ const CPRODUCT = 'Create Product';
17
+ const UPRODUCT = 'Update Product';
18
+ const DPRODUCT = 'Delete Product';
19
+ const CFEED = 'Check Feed Response';
20
+ const FORDER = 'Fetch Order';
21
+ const DORDER = 'Dispatch Order';
22
+ const CORDER = 'Cancel Order';
23
+ const RORDER = 'Refund Order';
24
+ const MORDER = 'Order in Magento';
25
+ const CERROR = 'Communication Error';
26
+
27
+ /**
28
+ * Gets the list of type for the admin config dropdown
29
+ *
30
+ * @return array
31
+ */
32
+ public function toOptionArray() {
33
+ return array(
34
+ array(
35
+ 'value' => self::CPRODUCT,
36
+ 'label' => Mage::helper('flubit')->__('Create Product')),
37
+ array(
38
+ 'value' => self::UPRODUCT,
39
+ 'label' => Mage::helper('flubit')->__('Update Product')),
40
+ array(
41
+ 'value' => self::DPRODUCT,
42
+ 'label' => Mage::helper('flubit')->__('Delete Product')),
43
+ array(
44
+ 'value' => self::CFEED,
45
+ 'label' => Mage::helper('flubit')->__('Check Feed Response')),
46
+ array(
47
+ 'value' => self::FORDER,
48
+ 'label' => Mage::helper('flubit')->__('Fetch Order')),
49
+ array(
50
+ 'value' => self::DORDER,
51
+ 'label' => Mage::helper('flubit')->__('Dispatch Order')),
52
+ array(
53
+ 'value' => self::CORDER,
54
+ 'label' => Mage::helper('flubit')->__('Cancel Order')),
55
+ array(
56
+ 'value' => self::RORDER,
57
+ 'label' => Mage::helper('flubit')->__('Refund Order')),
58
+ array(
59
+ 'value' => self::MORDER,
60
+ 'label' => Mage::helper('flubit')->__('Create Order in Magento')),
61
+ array(
62
+ 'value' => self::CERROR,
63
+ 'label' => Mage::helper('flubit')->__('Communication Error'))
64
+ );
65
+ }
66
+
67
+ }
app/code/community/Flubit/Flubit/Model/Mysql4/Flubit.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Mysql Flubit
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Mysql4_Flubit extends Mage_Core_Model_Mysql4_Abstract {
11
+
12
+ /**
13
+ * Constructor for Flubit call
14
+ *
15
+ */
16
+ protected function _construct() {
17
+ $this->_init("flubit/flubit", "flubit_id");
18
+ }
19
+
20
+ }
app/code/community/Flubit/Flubit/Model/Mysql4/Flubit/Collection.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Mysql Flubit Collection
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Mysql4_Flubit_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
11
+
12
+ /**
13
+ * Constructor for Flubit call
14
+ *
15
+ */
16
+ public function _construct() {
17
+ $this->_init("flubit/flubit");
18
+ }
19
+
20
+ }
21
+
app/code/community/Flubit/Flubit/Model/Mysql4/Globalproduct.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Mysql Flubit OrderTime
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model_mysql14_Ordertime
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Mysql4_Globalproduct extends Mage_Core_Model_Mysql4_Abstract {
11
+
12
+ /**
13
+ * Constructor for Flubit logs
14
+ *
15
+ */
16
+ protected function _construct() {
17
+ $this->_init("flubit/globalproduct", "id");
18
+ }
19
+
20
+ }
app/code/community/Flubit/Flubit/Model/Mysql4/Globalproduct/Collection.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Mysql Flubit Ordertime
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model_mysql4_ordertime
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Mysql4_Globalproduct_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
11
+
12
+ /**
13
+ * Constructor for Flubit call
14
+ *
15
+ */
16
+ public function _construct() {
17
+ $this->_init("flubit/globalproduct");
18
+ }
19
+
20
+ }
21
+
app/code/community/Flubit/Flubit/Model/Mysql4/Logs.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Mysql Flubit Logs
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Mysql4_Logs extends Mage_Core_Model_Mysql4_Abstract {
11
+
12
+ /**
13
+ * Constructor for Flubit logs
14
+ *
15
+ */
16
+ protected function _construct() {
17
+ $this->_init("flubit/logs", "flubit_id");
18
+ }
19
+
20
+ }
app/code/community/Flubit/Flubit/Model/Mysql4/Logs/Collection.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Mysql Flubit Collection
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Mysql4_Logs_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
11
+
12
+ /**
13
+ * Constructor for Flubit call
14
+ *
15
+ */
16
+ public function _construct() {
17
+ $this->_init("flubit/logs");
18
+ }
19
+
20
+ }
21
+
app/code/community/Flubit/Flubit/Model/Mysql4/Order.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Mysql Flubit Logs
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Mysql4_Order extends Mage_Core_Model_Mysql4_Abstract {
11
+
12
+ /**
13
+ * Constructor for Flubit logs
14
+ *
15
+ */
16
+ protected function _construct() {
17
+ $this->_init("flubit/order", "flubit_id");
18
+ }
19
+
20
+ }
app/code/community/Flubit/Flubit/Model/Mysql4/Order/Collection.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Mysql Flubit Order
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Mysql4_Order_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
11
+
12
+ /**
13
+ * Constructor for Flubit call
14
+ *
15
+ */
16
+ public function _construct() {
17
+ $this->_init("flubit/order");
18
+ }
19
+
20
+ }
21
+
app/code/community/Flubit/Flubit/Model/Mysql4/Ordertime.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Mysql Flubit OrderTime
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model_mysql14_Ordertime
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Mysql4_Ordertime extends Mage_Core_Model_Mysql4_Abstract {
11
+
12
+ /**
13
+ * Constructor for Flubit logs
14
+ *
15
+ */
16
+ protected function _construct() {
17
+ $this->_init("flubit/ordertime", "id");
18
+ }
19
+
20
+ }
app/code/community/Flubit/Flubit/Model/Mysql4/Ordertime/Collection.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Mysql Flubit Ordertime
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model_mysql4_ordertime
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Mysql4_Ordertime_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
11
+
12
+ /**
13
+ * Constructor for Flubit call
14
+ *
15
+ */
16
+ public function _construct() {
17
+ $this->_init("flubit/ordertime");
18
+ }
19
+
20
+ }
21
+
app/code/community/Flubit/Flubit/Model/Observer.php ADDED
@@ -0,0 +1,402 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Observer
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Observer {
11
+
12
+ /**
13
+ * Method to observe save event of magento
14
+ *
15
+ * @param Varien_Event_Observer $observer
16
+ */
17
+ public function saveOrderAfter(Varien_Event_Observer $observer) {
18
+ try {
19
+ Mage::log('save run saveOrderAfter' , null, 'hum.txt');
20
+ $order = $observer->getOrder();
21
+ $order = Mage::getModel('sales/order')->loadByIncrementId($order->getIncrementId());
22
+
23
+ foreach ($order->getAllItems() as $item) {
24
+ $product = Mage::getModel('catalog/product')->load($item->getProductId());
25
+ if ($product->getFlubitProduct() != '1') {
26
+ continue;
27
+ }
28
+ $this->_saveFlubitProductData($product);
29
+ }
30
+ } catch (Exception $e) {
31
+ Mage::log(__LINE__ . 'saveOrderAfter ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Method for Lock Attributes
37
+ *
38
+ * @param Varien_Event_Observer $observer
39
+ */
40
+ public function lockAttributes(Varien_Event_Observer $observer) {
41
+ try {
42
+ $product = $observer->getProduct();
43
+ $product->lockAttribute('flubit_base_price');
44
+ } catch (Exception $e) {
45
+ Mage::log(__LINE__ . 'lockAttributes ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Method for Save Flubit Products
51
+ *
52
+ * @param Varien_Event_Observer $observer
53
+ * @return Boolean
54
+ */
55
+ public function saveFlubitProduct(Varien_Event_Observer $observer) {
56
+ try {
57
+ //Mage::log('save run saveFlubitProduct', null, 'hum.txt');
58
+ $product = $observer->getProduct();
59
+ $flubit = Mage::getModel('flubit/flubit')->load($product->getSku(), 'sku');
60
+ $flubit_stat = $product->getFlubitProduct(); // if product flubit stat is true
61
+
62
+ if ($flubit->getId() != '') {
63
+ if ($product->getFlubitProduct() == '1') {
64
+ $_product = Mage::getModel('catalog/product')->load($product->getId());
65
+ $status_stat = $_product->getStatus(); // check if the product is active or inactive in magento
66
+ $stock = $_product->getStockItem();
67
+ $stock_status = $stock->getIsInStock();
68
+
69
+ $qtyStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty();
70
+
71
+ if (($status_stat == 1) && ($stock_status) && ($qtyStock > 0)) {
72
+ $status = 1;
73
+ } else {
74
+ $status = 0;
75
+ }
76
+
77
+ $flubit->setName($product->getName())
78
+ ->setStatus('1')
79
+ ->setActiveStatus($status)
80
+ ->save();
81
+ } else {
82
+ $flubit->setName($product->getName())
83
+ ->setStatus('1')
84
+ ->setActiveStatus('0')
85
+ ->save();
86
+ }
87
+ $this->_saveFlubitProductData($product);
88
+ return;
89
+ } else {
90
+ if ($product->getFlubitProduct() == '1') {
91
+ $this->_saveFlubitProductData($product);
92
+ }
93
+ }
94
+
95
+ } catch (Exception $e) {
96
+ Mage::log(__LINE__ . 'saveFlubitProduct ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Method for Mass Update Flubit Products
102
+ *
103
+ * @param Varien_Event_Observer $observer
104
+ * @return Boolean
105
+ */
106
+ public function saveFlubitProductMassAttributeUpdate(Varien_Event_Observer $observer) {
107
+ //Mage::log($observer->getEvent()->getData(),null,'hum.log');
108
+ $attribute_data = $observer->getAttributesData();
109
+ $update_flubit_table = FALSE;
110
+ $flubit_stat = '';
111
+
112
+ if (isset($attribute_data['flubit_product'])) {
113
+ //Mage::log('flubit_product',null,'hum.log');
114
+ $update_flubit_table = TRUE;
115
+ $flubit_stat = $attribute_data['flubit_product'];
116
+ }
117
+
118
+ $product_ids = $observer->getProductIds();
119
+ $store_id = $observer->getStoreId();
120
+
121
+ if($flubit_stat == '') {
122
+ $update_flubit_table = TRUE;
123
+ }
124
+
125
+ try {
126
+ if ($update_flubit_table) {
127
+ Mage::log('inside update flubit product');
128
+ foreach ($product_ids as $product_id) {
129
+ if($flubit_stat == '') {
130
+ $flubit_status = Mage::getModel('catalog/product')->load($product_id)->getFlubitProduct();
131
+ } else {
132
+ $flubit_status = $flubit_stat;
133
+ }
134
+ //Mage::log($flubit_status . '--' . $product_id,null,'hum.log');
135
+ $flubitglobal = Mage::getModel('flubit/globalproduct');
136
+ $flubitglobal->setProductId($product_id)
137
+ ->setFlubitStatus($flubit_status)
138
+ ->setUpdateStatus('0')
139
+ ->setCreatedAt(date('Y-m-d H:i:s'))
140
+ ->save();
141
+ }
142
+ }
143
+ } catch (Exception $e) {
144
+ Mage::log(__LINE__ . 'saveFlubitProduct ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
145
+ }
146
+ }
147
+
148
+
149
+ /**
150
+ * Method for Save Flubit Products
151
+ *
152
+ * @param Xml String $product
153
+ * @return array
154
+ */
155
+ private function _saveFlubitProductData($product) {
156
+
157
+ try {
158
+ if ($product->getSku() == '') {
159
+ Mage::log($product->getId() . ' no sku', null, 'hum.txt');
160
+ return;
161
+ }
162
+ Mage::log('SKU : ' . $product->getSku() . ' ID '. $product->getId(), null, 'hum.log');
163
+ $_product = Mage::getModel('catalog/product')->load($product->getId());
164
+
165
+ $status_stat = $_product->getStatus(); // check if the product is active or inactive in magento
166
+ $stock = $_product->getStockItem();
167
+ $stock_status = $stock->getIsInStock();
168
+
169
+ $qty = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty();//$flubitObj->getQty();
170
+ if (($status_stat == 1) && ($stock_status) && ($qty > 0)) {
171
+ $status = 1;
172
+ } else {
173
+ $status = 0;
174
+ }
175
+ $flubit = Mage::getModel('flubit/flubit')->load($product->getSku(), 'sku');
176
+ $flubitObj = Mage::getModel('flubit/flubit');
177
+ //Mage::log(print_r($qty, TRUE), null, 'hum.txt');
178
+ Mage::log('Quantity = ' . $qty, null, 'hum.txt');
179
+ if ($flubit->getId() == '') {
180
+ $flubit = Mage::getModel('flubit/flubit');
181
+ $flubit->setName($product->getName())
182
+ ->setSku($product->getSku())
183
+ ->setPrice(0)
184
+ ->setQty($qty)
185
+ ->setStatus('1')
186
+ ->setActiveStatus($status)
187
+ ->setNew('1')
188
+ ->save();
189
+ } else {
190
+ $flubit->setName($product->getName())
191
+ ->setSku($product->getSku())
192
+ ->setPrice(0)
193
+ ->setQty($qty)
194
+ ->setStatus('1')
195
+ ->setActiveStatus($status)
196
+ ->save();
197
+ }
198
+ } catch (Exception $e) {
199
+ Mage::log(__LINE__ . '_saveFlubitProductData ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
200
+ }
201
+ try {
202
+ if (is_object($flubit)) {
203
+ $flubitPrice = (number_format($flubitObj->getFlubitPrice($product), 2, '.', ''));
204
+ $flubit->setPrice($flubitPrice)
205
+ ->save();
206
+ }
207
+ } catch (Exception $e) {
208
+ Mage::log(__LINE__ . '_saveFlubitProductData ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
209
+ }
210
+ }
211
+
212
+ /**
213
+ * Method for Check Ean, Asin, Isbn, Mpn
214
+ *
215
+ * @param string $pr
216
+ * @return boolean
217
+ */
218
+ private function checkEanValidation($pr) {
219
+ try {
220
+ if (is_object($pr)) {
221
+ if ($pr->getFlubitEan() || $pr->getFlubitAsin() || $pr->getFlubitIsbn() || $pr->getFlubitMpn()) {
222
+ return true;
223
+ }
224
+ }
225
+ return false;
226
+ } catch (Exception $e) {
227
+ Mage::log(__LINE__ . 'checkEanValidation ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
228
+ }
229
+ }
230
+
231
+ /**
232
+ * Method for Check Image Available or Not
233
+ * @param String $pr
234
+ * @return boolean
235
+ */
236
+ private function checkImageValidation($pr) {
237
+ try {
238
+ if ($pr->getImage() != 'no_selection') {
239
+ return true;
240
+ }
241
+ return false;
242
+ } catch (Exception $e) {
243
+ Mage::log(__LINE__ . 'checkImageValidation ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
244
+ }
245
+ }
246
+
247
+ /**
248
+ * Method for Save Flubit Quantity
249
+ *
250
+ * @param Integer $product
251
+ * @return None
252
+ */
253
+ private function _saveFlubitQty($product) {
254
+ try {
255
+ if ($product->getSku() == '') {
256
+ Mage::log($product->getId() . ' no sku', null, 'hum.txt');
257
+ return;
258
+ }
259
+ $qty = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty();
260
+ $flubit = Mage::getModel('flubit/flubit')->load($product->getSku(), 'sku');
261
+ $flubitObj = Mage::getModel('flubit/flubit');
262
+ if ($qty != $flubit->getQty()) {
263
+ $flubit->setQty($qty)
264
+ ->setStatus('1')
265
+ ->save();
266
+ }
267
+ } catch (Exception $e) {
268
+ Mage::log(__LINE__ . '_saveFlubitQty ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
269
+ }
270
+ }
271
+
272
+ /* @Method : cancleFlubitOrder
273
+ * @Parametere : None
274
+ * @return : None
275
+ */
276
+
277
+ public function cancelFlubitOrder(Varien_Event_Observer $observer)
278
+ {
279
+ try {
280
+ $orderid = $observer->getEvent()->getCreditmemo()->order_id;
281
+ Mage::log($orderid , null, Flubit_Flubit_Helper_Data::FLUBIT_OBSERVER_DELETE);
282
+ $flubitorder = Mage::getModel('sales/order')->getCollection();
283
+ $flubitorder->addFieldToFilter('main_table.entity_id', $orderid);
284
+ $flubitorder->addFieldToSelect('flubit_order_id');
285
+ //Mage::log(print_r($flubitorder->getData(),true) , null, Flubit_Flubit_Helper_Data::FLUBIT_OBSERVER_DELETE);
286
+ foreach ($flubitorder as $order) {
287
+ Mage::log($order->getData('flubit_order_id') , null, Flubit_Flubit_Helper_Data::FLUBIT_OBSERVER_DELETE);
288
+ $config = Mage::getModel('flubit/config');
289
+ $collection = Mage::getModel('flubit/order')->getCollection();
290
+ $collection->addFieldToFilter('flubit_order_id', $flubitOrderId);
291
+ $collection->addFieldToSelect('dispatch');
292
+ foreach ($collection as $dispatch) {
293
+
294
+ if($dispatch->getDispatch() == '1') {
295
+ $data = $config->refundFlubitOrders($order->getData('flubit_order_id'));
296
+ } else {
297
+ $data = $config->cancelFlubitOrders($order->getData('flubit_order_id'));
298
+ }
299
+ }
300
+
301
+
302
+ }
303
+ $order = Mage::getModel('sales/order')->load($orderid);
304
+ $items = $order->getAllItems();
305
+ foreach ($items as $itemId => $item)
306
+ {
307
+ $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $item->getSku());
308
+ $this->_saveFlubitQty($product);
309
+ }
310
+ } catch (Exception $e) {
311
+ Mage::log("Exception Cancel Flubit Order : " . $e->getCode() . " message" . $e->getMessage(), null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
312
+ }
313
+ }
314
+
315
+ /* @Method : deleteFlubitProduct
316
+ * @Parametere : None
317
+ * @return : None
318
+ */
319
+
320
+ public function deleteFlubitProduct(Varien_Event_Observer $observer) {
321
+ $product = $observer->getEvent()->getProduct();
322
+ $product_sku = $product->getData('sku');
323
+
324
+ try {
325
+ $data = Mage::getModel('flubit/flubit')->load($product_sku, 'sku');
326
+ $data->setIsDeleted('1')
327
+ ->save();
328
+ $config = Mage::getModel('flubit/config');
329
+ $data = $config->inactiveProduct($product_sku, 0);
330
+ //Mage::log($data . '------',null,'hum.log');
331
+ $xml = $config->getproductFeedStatus($data,'xml');
332
+ //Mage::log($xml . '+++++++',null,'hum.log');
333
+ if (!isset($xml)) {
334
+ Mage::log("Product is not deleted from flubit SKU :" . $product_sku , null, Flubit_Flubit_Helper_Data::FLUBIT_OBSERVER_DELETE);
335
+ } else {
336
+ $data = Mage::getModel('flubit/flubit')->load($product_sku, 'sku');
337
+ $data->delete()->save();
338
+ }
339
+ } catch (Exception $e) {
340
+ Mage::log("Exception Delete Failed : " . $e->getCode() . " message" . $e->getMessage(), null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
341
+ }
342
+ }
343
+
344
+
345
+ /**
346
+ * Remove send mail button in case of flubit order
347
+ *
348
+ * @param Varien_Event_Observer $observer
349
+ */
350
+ public function removeSendMailButton(Varien_Event_Observer $observer)
351
+ {
352
+ $block = $observer->getEvent()->getData( 'block' );
353
+
354
+ //Order view page
355
+ if (get_class($block) == 'Mage_Adminhtml_Block_Sales_Order_View' && $block->getRequest()->getControllerName() == 'sales_order') {
356
+ $order = $block->getOrder();
357
+ if($order->getId() && $order->getData('flubit_order_id')) {
358
+ $block->removeButton('send_notification');
359
+ return;
360
+ }
361
+ }
362
+
363
+ //Invoice view page
364
+ if (get_class($block) == 'Mage_Adminhtml_Block_Sales_Order_Invoice_View' && $block->getRequest()->getControllerName() == 'sales_order_invoice') {
365
+ $order = $block->getInvoice()->getOrder();
366
+ if($order->getId() && $order->getData('flubit_order_id')) {
367
+ $block->removeButton('send_notification');
368
+ return;
369
+ }
370
+ }
371
+
372
+ //Creditmemo view page
373
+ if (get_class($block) == 'Mage_Adminhtml_Block_Sales_Order_Creditmemo_View' && $block->getRequest()->getControllerName() == 'sales_order_creditmemo') {
374
+ $order = $block->getCreditmemo()->getOrder();
375
+ if($order->getId() && $order->getData('flubit_order_id')) {
376
+ $block->removeButton('send_notification');
377
+ return;
378
+ }
379
+ }
380
+
381
+ //Shipment view page
382
+ if (get_class($block) == 'Mage_Adminhtml_Block_Sales_Order_Shipment_View' && $block->getRequest()->getControllerName() == 'sales_order_shipment') {
383
+ $order = $block->getShipment()->getOrder();
384
+ if($order->getId() && $order->getData('flubit_order_id')) {
385
+ $block->removeButton('send_notification');
386
+ return;
387
+ }
388
+ }
389
+
390
+ }
391
+ public function saveConfigObserver () {
392
+ try {
393
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
394
+ $flubit_product_table = Mage::getSingleton('core/resource')->getTableName('flubit/flubit');
395
+ $write->query("UPDATE ".$flubit_product_table." SET `global_price_update` = '0'");
396
+ } catch (Exception $e) {
397
+ Mage::log(__LINE__ . ' Exception updateFlubitPrices Model data ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
398
+ }
399
+
400
+ }
401
+
402
+ }
app/code/community/Flubit/Flubit/Model/Order.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Logs
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Order extends Mage_Core_Model_Abstract {
11
+
12
+ /**
13
+ * Constructor for load Flubit Order
14
+ *
15
+ */
16
+ public function _construct() {
17
+ try {
18
+ parent::_construct();
19
+ $this->_init('flubit/order');
20
+ } catch (Exception $e) {
21
+ Mage::log(__LINE__ . 'Exception Flubit_Flubit_Model_Order _construct ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
22
+ }
23
+ }
24
+
25
+ }
app/code/community/Flubit/Flubit/Model/Order/Pdf/Creditmemo.php ADDED
@@ -0,0 +1,414 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Sales Order Creditmemo PDF model
4
+ *
5
+ * @category Mage
6
+ * @package Mage_Sales
7
+ * @author Magento Core Team <core@magentocommerce.com>
8
+ */
9
+ class Flubit_Flubit_Model_Order_Pdf_Creditmemo extends Mage_Sales_Model_Order_Pdf_Creditmemo
10
+ {
11
+ /**
12
+ * Draw table header for product items
13
+ *
14
+ * @param Zend_Pdf_Page $page
15
+ * @return void
16
+ */
17
+ protected function _drawHeader(Zend_Pdf_Page $page, Mage_Sales_Model_Order $order = NULL)
18
+ {
19
+ $magentoVersion = Mage::getVersion();
20
+ if (version_compare($magentoVersion, '1.7', '>=')) {
21
+ // if version is greater than 1.7
22
+
23
+ $this->_setFontRegular($page, 10);
24
+ $page->setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
25
+ $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
26
+ $page->setLineWidth(0.5);
27
+ $page->drawRectangle(25, $this->y, 570, $this->y - 30);
28
+ $this->y -= 10;
29
+ $page->setFillColor(new Zend_Pdf_Color_RGB(0, 0, 0));
30
+
31
+
32
+ if ($order && !$order->getData('flubit_order_id')) {
33
+ //columns headers
34
+ $lines[0][] = array(
35
+ 'text' => Mage::helper('sales')->__('Products'),
36
+ 'feed' => 35,
37
+ );
38
+
39
+ $lines[0][] = array(
40
+ 'text' => Mage::helper('core/string')->str_split(Mage::helper('sales')->__('SKU'), 12, true, true),
41
+ 'feed' => 255,
42
+ 'align' => 'right'
43
+ );
44
+
45
+ $lines[0][] = array(
46
+ 'text' => Mage::helper('core/string')->str_split(Mage::helper('sales')->__('Total (ex)'), 12, true, true),
47
+ 'feed' => 330,
48
+ 'align' => 'right',
49
+ //'width' => 50,
50
+ );
51
+
52
+ $lines[0][] = array(
53
+ 'text' => Mage::helper('core/string')->str_split(Mage::helper('sales')->__('Discount'), 12, true, true),
54
+ 'feed' => 380,
55
+ 'align' => 'right',
56
+ //'width' => 50,
57
+ );
58
+
59
+ $lines[0][] = array(
60
+ 'text' => Mage::helper('core/string')->str_split(Mage::helper('sales')->__('Qty'), 12, true, true),
61
+ 'feed' => 445,
62
+ 'align' => 'right',
63
+ //'width' => 30,
64
+ );
65
+
66
+ $lines[0][] = array(
67
+ 'text' => Mage::helper('core/string')->str_split(Mage::helper('sales')->__('Tax'), 12, true, true),
68
+ 'feed' => 495,
69
+ 'align' => 'right',
70
+ //'width' => 45,
71
+ );
72
+
73
+ $lines[0][] = array(
74
+ 'text' => Mage::helper('core/string')->str_split(Mage::helper('sales')->__('Total (inc)'), 12, true, true),
75
+ 'feed' => 565,
76
+ 'align' => 'right'
77
+ );
78
+ } else {
79
+ //columns headers for flubbit products
80
+ //flubit
81
+ $lines[0][] = array(
82
+ 'text' => Mage::helper('sales')->__('Products'),
83
+ 'feed' => 35,
84
+ );
85
+ //flubit
86
+ $lines[0][] = array(
87
+ 'text' => Mage::helper('core/string')->str_split(Mage::helper('sales')->__('SKU'), 12, true, true),
88
+ 'feed' => 180,
89
+ 'align' => 'right'
90
+ );
91
+ //flubit base price
92
+ $lines[0][] = array(
93
+ 'text' => Mage::helper('core/string')->str_split(Mage::helper('sales')->__('FBP'), 12, true, true),
94
+ 'feed' => 250,
95
+ 'align' => 'right',
96
+ //'width' => 50,
97
+ );
98
+ // flubit price sold at
99
+ $lines[0][] = array(
100
+ 'text' => Mage::helper('core/string')->str_split(Mage::helper('sales')->__('Price Sold At(VAT inc.)'), 30, true, true),
101
+ 'feed' => 360,
102
+ 'align' => 'right',
103
+ //'width' => 50,
104
+ );
105
+ // flubit qty
106
+
107
+ $lines[0][] = array(
108
+ 'text' => Mage::helper('core/string')->str_split(Mage::helper('sales')->__('Qty'), 12, true, true),
109
+ 'feed' => 380,
110
+ 'align' => 'right',
111
+ //'width' => 30,
112
+ );
113
+ // flubit tax rate
114
+ $lines[0][] = array(
115
+ 'text' => Mage::helper('core/string')->str_split(Mage::helper('sales')->__('Tax Rate'), 12, true, true),
116
+ 'feed' => 435,
117
+ 'align' => 'right',
118
+ //'width' => 30,
119
+ );
120
+ // actual price sold at
121
+ $lines[0][] = array(
122
+ 'text' => Mage::helper('core/string')->str_split(Mage::helper('sales')->__('Actual Price Sold At(VAT inc.)'), 30, true, true),
123
+ 'feed' => 565,
124
+ 'align' => 'right'
125
+ );
126
+ }
127
+ $lineBlock = array(
128
+ 'lines' => $lines,
129
+ 'height' => 10
130
+ );
131
+
132
+ $this->drawLineBlocks($page, array($lineBlock), array('table_header' => true));
133
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
134
+ $this->y -= 20;
135
+ } else {
136
+ $font = $page->getFont();
137
+ $size = $page->getFontSize();
138
+
139
+ if ($order && $order->getData('flubit_order_id')) {
140
+
141
+
142
+ $page->drawText(Mage::helper('sales')->__('Product'), $x = 35, $this->y, 'UTF-8');
143
+ $x += 140;
144
+
145
+ $page->drawText(Mage::helper('sales')->__('SKU'), $x, $this->y, 'UTF-8');
146
+ $x += 90;
147
+
148
+ $text = Mage::helper('sales')->__('FBP');
149
+ $page->drawText($text, $this->getAlignRight($text, $x, 10, $font, $size), $this->y, 'UTF-8');
150
+ $x += 40;
151
+
152
+ $text = Mage::helper('sales')->__('Price Sold At(VAT inc.)');
153
+ $page->drawText($text, $this->getAlignRight($text, $x, 50, $font, $size), $this->y, 'UTF-8');
154
+ $x += 50;
155
+
156
+ $text = Mage::helper('sales')->__('Qty');
157
+ $page->drawText($text, $this->getAlignCenter($text, $x, 30, $font, $size), $this->y, 'UTF-8');
158
+ $x += 45;
159
+
160
+ $text = Mage::helper('sales')->__('Tax Rate');
161
+ $page->drawText($text, $this->getAlignRight($text, $x, 45, $font, $size, 10), $this->y, 'UTF-8');
162
+ $x += 45;
163
+
164
+ $text = Mage::helper('sales')->__('Actual Price Sold At(VAT inc.)');
165
+ $page->drawText($text, $this->getAlignRight($text, $x, 570 - $x, $font, $size), $this->y, 'UTF-8');
166
+ } else {
167
+
168
+ $page->drawText(Mage::helper('sales')->__('Products'), $x = 35, $this->y, 'UTF-8');
169
+ $x += 220;
170
+
171
+ $page->drawText(Mage::helper('sales')->__('SKU'), $x, $this->y, 'UTF-8');
172
+ $x += 100;
173
+
174
+ $text = Mage::helper('sales')->__('Total (ex)');
175
+ $page->drawText($text, $this->getAlignRight($text, $x, 50, $font, $size), $this->y, 'UTF-8');
176
+ $x += 50;
177
+
178
+ $text = Mage::helper('sales')->__('Discount');
179
+ $page->drawText($text, $this->getAlignRight($text, $x, 50, $font, $size), $this->y, 'UTF-8');
180
+ $x += 50;
181
+
182
+ $text = Mage::helper('sales')->__('Qty');
183
+ $page->drawText($text, $this->getAlignCenter($text, $x, 30, $font, $size), $this->y, 'UTF-8');
184
+ $x += 30;
185
+
186
+ $text = Mage::helper('sales')->__('Tax');
187
+ $page->drawText($text, $this->getAlignRight($text, $x, 45, $font, $size, 10), $this->y, 'UTF-8');
188
+ $x += 45;
189
+
190
+ $text = Mage::helper('sales')->__('Total (inc)');
191
+ $page->drawText($text, $this->getAlignRight($text, $x, 570 - $x, $font, $size), $this->y, 'UTF-8');
192
+ }
193
+ }
194
+ }
195
+
196
+ /**
197
+ * Return PDF document
198
+ *
199
+ * @param array $creditmemos
200
+ * @return Zend_Pdf
201
+ */
202
+ public function getPdf($creditmemos = array())
203
+ {
204
+ $magentoVersion = Mage::getVersion();
205
+ if (version_compare($magentoVersion, '1.7', '>=')) {
206
+ $this->_beforeGetPdf();
207
+ $this->_initRenderer('creditmemo');
208
+
209
+ $pdf = new Zend_Pdf();
210
+ $this->_setPdf($pdf);
211
+ $style = new Zend_Pdf_Style();
212
+ $this->_setFontBold($style, 10);
213
+
214
+ foreach ($creditmemos as $creditmemo) {
215
+ if ($creditmemo->getStoreId()) {
216
+ Mage::app()->getLocale()->emulate($creditmemo->getStoreId());
217
+ Mage::app()->setCurrentStore($creditmemo->getStoreId());
218
+ }
219
+ $page = $this->newPage();
220
+ $order = $creditmemo->getOrder();
221
+ /* Add image */
222
+ $this->insertLogo($page, $creditmemo->getStore());
223
+ /* Add address */
224
+ $this->insertAddress($page, $creditmemo->getStore());
225
+ /* Add head */
226
+ $this->insertOrder(
227
+ $page,
228
+ $order,
229
+ Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_CREDITMEMO_PUT_ORDER_ID, $order->getStoreId())
230
+ );
231
+ /* Add document text and number */
232
+ $this->insertDocumentNumber(
233
+ $page,
234
+ Mage::helper('sales')->__('Credit Memo # ') . $creditmemo->getIncrementId()
235
+ );
236
+ /* Add table head */
237
+ $this->_drawHeader($page, $order);
238
+ /* Add body */
239
+ foreach ($creditmemo->getAllItems() as $item){
240
+ if ($item->getOrderItem()->getParentItem()) {
241
+ continue;
242
+ }
243
+ /* Draw item */
244
+ $this->_drawItem($item, $page, $order);
245
+ $page = end($pdf->pages);
246
+ }
247
+ /* Add totals */
248
+ $this->insertTotals($page, $creditmemo);
249
+ }
250
+ $this->_afterGetPdf();
251
+ if ($creditmemo->getStoreId()) {
252
+ Mage::app()->getLocale()->revert();
253
+ }
254
+ return $pdf;
255
+ } else {
256
+ //if version is smaller than 1.7
257
+ $this->_beforeGetPdf();
258
+ $this->_initRenderer('creditmemo');
259
+
260
+ $pdf = new Zend_Pdf();
261
+ $this->_setPdf($pdf);
262
+ $style = new Zend_Pdf_Style();
263
+ $this->_setFontBold($style, 10);
264
+
265
+ foreach ($creditmemos as $creditmemo) {
266
+ if ($creditmemo->getStoreId()) {
267
+ Mage::app()->getLocale()->emulate($creditmemo->getStoreId());
268
+ Mage::app()->setCurrentStore($creditmemo->getStoreId());
269
+ }
270
+ $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
271
+ $pdf->pages[] = $page;
272
+
273
+ $order = $creditmemo->getOrder();
274
+
275
+ /* Add image */
276
+ $this->insertLogo($page, $creditmemo->getStore());
277
+
278
+ /* Add address */
279
+ $this->insertAddress($page, $creditmemo->getStore());
280
+
281
+ /* Add head */
282
+ $this->insertOrder($page, $order, Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_CREDITMEMO_PUT_ORDER_ID, $order->getStoreId()));
283
+
284
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
285
+ $this->_setFontRegular($page);
286
+ $page->drawText(Mage::helper('sales')->__('Credit Memo # ') . $creditmemo->getIncrementId(), 35, 780, 'UTF-8');
287
+
288
+ /* Add table head */
289
+ $page->setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
290
+ $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
291
+ $page->setLineWidth(0.5);
292
+ $page->drawRectangle(25, $this->y, 570, $this->y - 15);
293
+ $this->y -=10;
294
+ $page->setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4));
295
+ $this->_drawHeader($page, $order);
296
+ $this->y -=15;
297
+
298
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
299
+
300
+ /* Add body */
301
+ foreach ($creditmemo->getAllItems() as $item) {
302
+ if ($item->getOrderItem()->getParentItem()) {
303
+ continue;
304
+ }
305
+
306
+ if ($this->y < 20) {
307
+ $page = $this->newPage(array('table_header' => true));
308
+ }
309
+
310
+ /* Draw item */
311
+ $page = $this->_drawItem($item, $page, $order);
312
+ }
313
+
314
+ /* Add totals */
315
+ $page = $this->insertTotals($page, $creditmemo);
316
+ }
317
+
318
+ $this->_afterGetPdf();
319
+
320
+ if ($creditmemo->getStoreId()) {
321
+ Mage::app()->getLocale()->revert();
322
+ }
323
+ return $pdf;
324
+ }
325
+ }
326
+
327
+ /**
328
+ * Create new page and assign to PDF object
329
+ *
330
+ * @param array $settings
331
+ * @return Zend_Pdf_Page
332
+ */
333
+ public function newPage(array $settings = array())
334
+ {
335
+ $page = parent::newPage($settings);
336
+ if (!empty($settings['table_header'])) {
337
+ $this->_drawHeader($page);
338
+ }
339
+ return $page;
340
+ }
341
+ /**
342
+ * Insert totals to pdf page
343
+ *
344
+ * @param Zend_Pdf_Page $page
345
+ * @param Mage_Sales_Model_Abstract $source
346
+ * @return Zend_Pdf_Page
347
+ */
348
+
349
+ protected function insertTotals($page, $source) {
350
+ $order = $source->getOrder();
351
+
352
+ //custom
353
+ $flubitOrder = $order->getFlubitOrderId();
354
+ $grandtotal_flag = false;
355
+
356
+
357
+ $totals = $this->_getTotalsList($source);
358
+ $lineBlock = array(
359
+ 'lines' => array(),
360
+ 'height' => 15
361
+ );
362
+ foreach ($totals as $total) {
363
+
364
+ //custom
365
+ if ($flubitOrder && !in_array($total->getData('source_field'), array('shipping_amount', 'grand_total'))) {
366
+ continue;
367
+ }
368
+
369
+ $total->setOrder($order)
370
+ ->setSource($source);
371
+
372
+ if ($total->canDisplay()) {
373
+ $total->setFontSize(10);
374
+ foreach ($total->getTotalsForDisplay() as $totalData) {
375
+ //custom : start
376
+ if ($flubitOrder && (strpos($totalData['label'], 'Tax:') !== false)) {
377
+ continue;
378
+ }
379
+
380
+ if ($flubitOrder && (strpos($totalData['label'], 'Grand Total') !== false)) {
381
+ if ($grandtotal_flag) {
382
+ continue;
383
+ } else {
384
+ $grandtotal_flag = true;
385
+ }
386
+ $totalData['label'] = 'Grand Total';
387
+ }
388
+ //custom : end
389
+
390
+ $lineBlock['lines'][] = array(
391
+ array(
392
+ 'text' => $totalData['label'],
393
+ 'feed' => 475,
394
+ 'align' => 'right',
395
+ 'font_size' => $totalData['font_size'],
396
+ 'font' => 'bold'
397
+ ),
398
+ array(
399
+ 'text' => $totalData['amount'],
400
+ 'feed' => 565,
401
+ 'align' => 'right',
402
+ 'font_size' => $totalData['font_size'],
403
+ 'font' => 'bold'
404
+ ),
405
+ );
406
+ }
407
+ }
408
+ }
409
+
410
+ $this->y -= 20;
411
+ $page = $this->drawLineBlocks($page, array($lineBlock));
412
+ return $page;
413
+ }
414
+ }
app/code/community/Flubit/Flubit/Model/Order/Pdf/Invoice.php ADDED
@@ -0,0 +1,407 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Flubit_Flubit_Model_Order_Pdf_Invoice extends Mage_Sales_Model_Order_Pdf_Invoice {
4
+
5
+ /**
6
+ * Draw header for item table
7
+ *
8
+ * @param Zend_Pdf_Page $page
9
+ * @return void
10
+ */
11
+ protected function _drawHeader(Zend_Pdf_Page $page, Mage_Sales_Model_Order $order) {
12
+
13
+ /* Add table head */
14
+ $this->_setFontRegular($page, 10);
15
+ $page->setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
16
+ $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
17
+ $page->setLineWidth(0.5);
18
+ $page->drawRectangle(25, $this->y, 570, $this->y - 15);
19
+ $this->y -= 10;
20
+ $page->setFillColor(new Zend_Pdf_Color_RGB(0, 0, 0));
21
+
22
+ if (!$order->getData('flubit_order_id')) {
23
+ //columns headers
24
+ $lines[0][] = array(
25
+ 'text' => Mage::helper('sales')->__('Products'),
26
+ 'feed' => 35
27
+ );
28
+
29
+ $lines[0][] = array(
30
+ 'text' => Mage::helper('sales')->__('SKU'),
31
+ 'feed' => 290,
32
+ 'align' => 'right'
33
+ );
34
+
35
+ $lines[0][] = array(
36
+ 'text' => Mage::helper('sales')->__('Qty'),
37
+ 'feed' => 435,
38
+ 'align' => 'right'
39
+ );
40
+
41
+ $lines[0][] = array(
42
+ 'text' => Mage::helper('sales')->__('Price'),
43
+ 'feed' => 360,
44
+ 'align' => 'right'
45
+ );
46
+
47
+ $lines[0][] = array(
48
+ 'text' => Mage::helper('sales')->__('Tax'),
49
+ 'feed' => 495,
50
+ 'align' => 'right'
51
+ );
52
+
53
+ $lines[0][] = array(
54
+ 'text' => Mage::helper('sales')->__('Subtotal'),
55
+ 'feed' => 565,
56
+ 'align' => 'right'
57
+ );
58
+
59
+ $lineBlock = array(
60
+ 'lines' => $lines,
61
+ 'height' => 5
62
+ );
63
+ } else {
64
+ //columns headers
65
+ $lines[0][] = array(
66
+ 'text' => Mage::helper('sales')->__('Products'),
67
+ 'feed' => 35
68
+ );
69
+
70
+ $lines[0][] = array(
71
+ 'text' => Mage::helper('sales')->__('SKU'),
72
+ 'feed' => 175,
73
+ 'align' => 'right'
74
+ );
75
+
76
+ $lines[0][] = array(
77
+ 'text' => Mage::helper('sales')->__('FBP'),
78
+ 'feed' => 250,
79
+ 'align' => 'right'
80
+ );
81
+
82
+ $lines[0][] = array(
83
+ 'text' => Mage::helper('sales')->__('Qty'),
84
+ 'feed' => 275,
85
+ 'align' => 'right'
86
+ );
87
+
88
+
89
+
90
+ $lines[0][] = array(
91
+ 'text' => Mage::helper('sales')->__('Price Sold At(VAT inc.)'),
92
+ 'feed' => 375,
93
+ 'align' => 'right'
94
+ );
95
+
96
+ $lines[0][] = array(
97
+ 'text' => Mage::helper('sales')->__('Tax Rate'),
98
+ 'feed' => 425,
99
+ 'align' => 'right'
100
+ );
101
+
102
+ $lines[0][] = array(
103
+ 'text' => Mage::helper('sales')->__('Actual Price Sold At(VAT inc.)'),
104
+ 'feed' => 550,
105
+ 'align' => 'right'
106
+ );
107
+
108
+
109
+ $lineBlock = array(
110
+ 'lines' => $lines,
111
+ 'height' => 5
112
+ );
113
+ }
114
+ $this->drawLineBlocks($page, array($lineBlock), array('table_header' => true));
115
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
116
+ $this->y -= 20;
117
+ }
118
+
119
+ /**
120
+ * Return PDF document
121
+ *
122
+ * @param array $invoices
123
+ * @return Zend_Pdf
124
+ */
125
+ public function getPdf($invoices = array()) {
126
+ $magentoVersion = Mage::getVersion();
127
+ if (version_compare($magentoVersion, '1.7', '>=')) {
128
+ //version is 1.7 or greater
129
+ $this->_beforeGetPdf();
130
+ $this->_initRenderer('invoice');
131
+
132
+ $pdf = new Zend_Pdf();
133
+ $this->_setPdf($pdf);
134
+ $style = new Zend_Pdf_Style();
135
+ $this->_setFontBold($style, 10);
136
+
137
+ foreach ($invoices as $invoice) {
138
+ if ($invoice->getStoreId()) {
139
+ Mage::app()->getLocale()->emulate($invoice->getStoreId());
140
+ Mage::app()->setCurrentStore($invoice->getStoreId());
141
+ }
142
+ $page = $this->newPage();
143
+ $order = $invoice->getOrder();
144
+ /* Add image */
145
+ $this->insertLogo($page, $invoice->getStore());
146
+ /* Add address */
147
+ $this->insertAddress($page, $invoice->getStore());
148
+ /* Add head */
149
+ $this->insertOrder(
150
+ $page, $order, Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID, $order->getStoreId())
151
+ );
152
+ /* Add document text and number */
153
+ $this->insertDocumentNumber(
154
+ $page, Mage::helper('sales')->__('Invoice # ') . $invoice->getIncrementId()
155
+ );
156
+ /* Add table */
157
+ $this->_drawHeader($page, $order);
158
+ /* Add body */
159
+ foreach ($invoice->getAllItems() as $item) {
160
+ if ($item->getOrderItem()->getParentItem()) {
161
+ continue;
162
+ }
163
+ /* Draw item */
164
+ $this->_drawItem($item, $page, $order);
165
+ $page = end($pdf->pages);
166
+ }
167
+ /* Add totals */
168
+ $this->insertTotals($page, $invoice);
169
+ if ($invoice->getStoreId()) {
170
+ Mage::app()->getLocale()->revert();
171
+ }
172
+ }
173
+ $this->_afterGetPdf();
174
+ } else {
175
+ // magento version is below 1.7
176
+ $this->_beforeGetPdf();
177
+ $this->_initRenderer('invoice');
178
+
179
+ $pdf = new Zend_Pdf();
180
+ $this->_setPdf($pdf);
181
+ $style = new Zend_Pdf_Style();
182
+ $this->_setFontBold($style, 10);
183
+
184
+ foreach ($invoices as $invoice) {
185
+ if ($invoice->getStoreId()) {
186
+ Mage::app()->getLocale()->emulate($invoice->getStoreId());
187
+ Mage::app()->setCurrentStore($invoice->getStoreId());
188
+ }
189
+ $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
190
+ $pdf->pages[] = $page;
191
+
192
+ $order = $invoice->getOrder();
193
+
194
+ /* Add image */
195
+ $this->insertLogo($page, $invoice->getStore());
196
+
197
+ /* Add address */
198
+ $this->insertAddress($page, $invoice->getStore());
199
+
200
+ /* Add head */
201
+ $this->insertOrder($page, $order, Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID, $order->getStoreId()));
202
+
203
+
204
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
205
+ $this->_setFontRegular($page);
206
+ $page->drawText(Mage::helper('sales')->__('Invoice # ') . $invoice->getIncrementId(), 35, 780, 'UTF-8');
207
+
208
+ /* Add table */
209
+ $page->setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
210
+ $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
211
+ $page->setLineWidth(0.5);
212
+
213
+ $page->drawRectangle(25, $this->y, 570, $this->y - 15);
214
+ $this->y -=10;
215
+ if ($order->getData('flubit_order_id')) {
216
+ /* Add table head */
217
+ $page->setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4));
218
+ $page->drawText(Mage::helper('sales')->__('Products'), 35, $this->y, 'UTF-8');
219
+ $page->drawText(Mage::helper('sales')->__('SKU'), 200, $this->y, 'UTF-8');
220
+ $page->drawText(Mage::helper('sales')->__('FBP'), 260, $this->y, 'UTF-8');
221
+ $page->drawText(Mage::helper('sales')->__('Price Sold At(VAT inc.)'), 300, $this->y, 'UTF-8');
222
+ $page->drawText(Mage::helper('sales')->__('Qty'), 385, $this->y, 'UTF-8');
223
+ $page->drawText(Mage::helper('sales')->__('Tax Rate'), 420, $this->y, 'UTF-8');
224
+ $page->drawText(Mage::helper('sales')->__('Actual Price Sold At(VAT inc.)'), 470, $this->y, 'UTF-8');
225
+ } else {
226
+ /* Add table head */
227
+ $page->setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4));
228
+ $page->drawText(Mage::helper('sales')->__('Products'), 35, $this->y, 'UTF-8');
229
+ $page->drawText(Mage::helper('sales')->__('SKU'), 255, $this->y, 'UTF-8');
230
+ $page->drawText(Mage::helper('sales')->__('Price'), 380, $this->y, 'UTF-8');
231
+ $page->drawText(Mage::helper('sales')->__('Qty'), 430, $this->y, 'UTF-8');
232
+ $page->drawText(Mage::helper('sales')->__('Tax'), 480, $this->y, 'UTF-8');
233
+ $page->drawText(Mage::helper('sales')->__('Subtotal'), 535, $this->y, 'UTF-8');
234
+ }
235
+
236
+ $this->y -=15;
237
+
238
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
239
+
240
+ /* Add body */
241
+ foreach ($invoice->getAllItems() as $item) {
242
+ if ($item->getOrderItem()->getParentItem()) {
243
+ continue;
244
+ }
245
+
246
+ if ($this->y < 15) {
247
+ $page = $this->newPage(array('table_header' => true));
248
+ }
249
+
250
+ /* Draw item */
251
+ $page = $this->_drawItem($item, $page, $order);
252
+ }
253
+
254
+ /* Add totals */
255
+ $page = $this->insertTotals($page, $invoice);
256
+
257
+ if ($invoice->getStoreId()) {
258
+ Mage::app()->getLocale()->revert();
259
+ }
260
+ }
261
+
262
+ $this->_afterGetPdf();
263
+ }
264
+
265
+ return $pdf;
266
+ }
267
+
268
+ /**
269
+ * Create new page and assign to PDF object
270
+ *
271
+ * @param array $settings
272
+ * @return Zend_Pdf_Page
273
+ */
274
+ public function newPage(array $settings = array()) {
275
+ $magentoVersion = Mage::getVersion();
276
+ if (version_compare($magentoVersion, '1.7', '>=')) {
277
+ //version is 1.7 or greater
278
+ /* Add new table head */
279
+ $page = $this->_getPdf()->newPage(Zend_Pdf_Page::SIZE_A4);
280
+ $this->_getPdf()->pages[] = $page;
281
+ $this->y = 800;
282
+
283
+ if (!empty($settings['table_header'])) {
284
+ $this->_setFontRegular($page);
285
+ $page->setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
286
+ $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
287
+ $page->setLineWidth(0.5);
288
+ $page->drawRectangle(25, $this->y, 570, $this->y - 15);
289
+ $this->y -=10;
290
+
291
+ $page->setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4));
292
+ $page->drawText(Mage::helper('sales')->__('Product'), 35, $this->y, 'UTF-8');
293
+ $page->drawText(Mage::helper('sales')->__('SKU'), 255, $this->y, 'UTF-8');
294
+ $page->drawText(Mage::helper('sales')->__('Price'), 380, $this->y, 'UTF-8');
295
+ $page->drawText(Mage::helper('sales')->__('Qty'), 430, $this->y, 'UTF-8');
296
+ $page->drawText(Mage::helper('sales')->__('Tax'), 480, $this->y, 'UTF-8');
297
+ $page->drawText(Mage::helper('sales')->__('Subtotal'), 535, $this->y, 'UTF-8');
298
+
299
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
300
+ $this->y -=20;
301
+ }
302
+ } else {
303
+ //version is below 1.7
304
+ /* Add new table head */
305
+ $page = $this->_getPdf()->newPage(Zend_Pdf_Page::SIZE_A4);
306
+ $this->_getPdf()->pages[] = $page;
307
+ $this->y = 800;
308
+
309
+ if (!empty($settings['table_header'])) {
310
+ $this->_setFontRegular($page);
311
+ $page->setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
312
+ $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
313
+ $page->setLineWidth(0.5);
314
+ $page->drawRectangle(25, $this->y, 570, $this->y - 15);
315
+ $this->y -=10;
316
+
317
+ $page->setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4));
318
+ $page->drawText(Mage::helper('sales')->__('Product'), 35, $this->y, 'UTF-8');
319
+ $page->drawText(Mage::helper('sales')->__('SKU'), 255, $this->y, 'UTF-8');
320
+ $page->drawText(Mage::helper('sales')->__('Price'), 380, $this->y, 'UTF-8');
321
+ $page->drawText(Mage::helper('sales')->__('Qty'), 430, $this->y, 'UTF-8');
322
+ $page->drawText(Mage::helper('sales')->__('Tax'), 480, $this->y, 'UTF-8');
323
+ $page->drawText(Mage::helper('sales')->__('Subtotal'), 535, $this->y, 'UTF-8');
324
+
325
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
326
+ $this->y -=20;
327
+ }
328
+ }
329
+
330
+
331
+ return $page;
332
+ }
333
+
334
+ /**
335
+ * Insert totals to pdf page
336
+ *
337
+ * @param Zend_Pdf_Page $page
338
+ * @param Mage_Sales_Model_Abstract $source
339
+ * @return Zend_Pdf_Page
340
+ */
341
+ protected function insertTotals($page, $source) {
342
+ $order = $source->getOrder();
343
+
344
+ //custom
345
+ $flubitOrder = $order->getFlubitOrderId();
346
+ $grandtotal_flag = false;
347
+
348
+
349
+ $totals = $this->_getTotalsList($source);
350
+ $lineBlock = array(
351
+ 'lines' => array(),
352
+ 'height' => 15
353
+ );
354
+ foreach ($totals as $total) {
355
+
356
+ //custom
357
+ if ($flubitOrder && !in_array($total->getData('source_field'), array('shipping_amount', 'grand_total'))) {
358
+ continue;
359
+ }
360
+
361
+ $total->setOrder($order)
362
+ ->setSource($source);
363
+
364
+ if ($total->canDisplay()) {
365
+ $total->setFontSize(10);
366
+ foreach ($total->getTotalsForDisplay() as $totalData) {
367
+ //custom : start
368
+ if ($flubitOrder && (strpos($totalData['label'], 'Tax:') !== false)) {
369
+ continue;
370
+ }
371
+
372
+ if ($flubitOrder && (strpos($totalData['label'], 'Grand Total') !== false)) {
373
+ if ($grandtotal_flag) {
374
+ continue;
375
+ } else {
376
+ $grandtotal_flag = true;
377
+ }
378
+ $totalData['label'] = 'Grand Total';
379
+ }
380
+ //custom : end
381
+
382
+ $lineBlock['lines'][] = array(
383
+ array(
384
+ 'text' => $totalData['label'],
385
+ 'feed' => 475,
386
+ 'align' => 'right',
387
+ 'font_size' => $totalData['font_size'],
388
+ 'font' => 'bold'
389
+ ),
390
+ array(
391
+ 'text' => $totalData['amount'],
392
+ 'feed' => 565,
393
+ 'align' => 'right',
394
+ 'font_size' => $totalData['font_size'],
395
+ 'font' => 'bold'
396
+ ),
397
+ );
398
+ }
399
+ }
400
+ }
401
+
402
+ $this->y -= 20;
403
+ $page = $this->drawLineBlocks($page, array($lineBlock));
404
+ return $page;
405
+ }
406
+
407
+ }
app/code/community/Flubit/Flubit/Model/Order/Pdf/Items/Creditmemo/Default.php ADDED
@@ -0,0 +1,346 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Sales Order Creditmemo Pdf default items renderer
4
+ *
5
+ * @category Mage
6
+ * @package Mage_Sales
7
+ * @author Magento Core Team <core@magentocommerce.com>
8
+ */
9
+ class Flubit_Flubit_Model_Order_Pdf_Items_Creditmemo_Default extends Mage_Sales_Model_Order_Pdf_Items_Creditmemo_Default
10
+ {
11
+ /**
12
+ * Draw process
13
+ */
14
+ public function draw()
15
+ {
16
+ $order = $this->getOrder();
17
+ $flubitOrder = False;
18
+
19
+ if ($order->getFlubitOrderId()) {
20
+ $flubitOrder = True;
21
+ }
22
+ $tax_percentage = $order->getFlubitOrderTaxRate();
23
+ $item = $this->getItem();
24
+ $original_price = '';
25
+ if($flubitOrder) {
26
+ $itemData = $item->getOrderItem()->getData();
27
+ $original_price = round($itemData['original_price'],2);
28
+ }
29
+ $price = $item->getPrice();
30
+ //$tax_amount = $price - ($price / $tax_rate);
31
+
32
+ $item = $this->getItem();
33
+ $pdf = $this->getPdf();
34
+ $page = $this->getPage();
35
+ $lines = array();
36
+
37
+ $magentoVersion = Mage::getVersion();
38
+ if (version_compare($magentoVersion, '1.7', '>=')) {
39
+ if(!$flubitOrder) {
40
+ // draw Product name
41
+ $lines[0] = array(array(
42
+ 'text' => Mage::helper('core/string')->str_split($item->getName(), 35, true, true),
43
+ 'feed' => 35,
44
+ ));
45
+
46
+ // draw SKU
47
+ $lines[0][] = array(
48
+ 'text' => Mage::helper('core/string')->str_split($this->getSku($item), 17),
49
+ 'feed' => 255,
50
+ 'align' => 'right'
51
+ );
52
+
53
+ // draw Total (ex)
54
+ $lines[0][] = array(
55
+ 'text' => $order->formatPriceTxt($item->getRowTotal()),
56
+ 'feed' => 330,
57
+ 'font' => 'bold',
58
+ 'align' => 'right',
59
+ );
60
+
61
+ // draw Discount
62
+ $lines[0][] = array(
63
+ 'text' => $order->formatPriceTxt(-$item->getDiscountAmount()),
64
+ 'feed' => 380,
65
+ 'font' => 'bold',
66
+ 'align' => 'right'
67
+ );
68
+
69
+ // draw QTY
70
+ $lines[0][] = array(
71
+ 'text' => $item->getQty() * 1,
72
+ 'feed' => 445,
73
+ 'font' => 'bold',
74
+ 'align' => 'right',
75
+ );
76
+
77
+ // draw Tax
78
+ $lines[0][] = array(
79
+ 'text' => $order->formatPriceTxt($item->getTaxAmount()),
80
+ 'feed' => 495,
81
+ 'font' => 'bold',
82
+ 'align' => 'right'
83
+ );
84
+
85
+ // draw Total (inc)
86
+ $subtotal = $item->getRowTotal() + $item->getTaxAmount() + $item->getHiddenTaxAmount()
87
+ - $item->getDiscountAmount();
88
+ $lines[0][] = array(
89
+ 'text' => $order->formatPriceTxt($subtotal),
90
+ 'feed' => 565,
91
+ 'font' => 'bold',
92
+ 'align' => 'right'
93
+ );
94
+ } else { // if flubit product
95
+ // draw flubit Product name
96
+ $lines[0] = array(array(
97
+ 'text' => Mage::helper('core/string')->str_split($item->getName(), 30, true, true),
98
+ 'feed' => 35,
99
+ ));
100
+
101
+ // draw flubit SKU
102
+ $lines[0][] = array(
103
+ 'text' => Mage::helper('core/string')->str_split($this->getSku($item), 15),
104
+ 'feed' => 220,
105
+ 'align' => 'right'
106
+ );
107
+
108
+ // draw FBP
109
+ $lines[0][] = array(
110
+ 'text' => $order->formatPriceTxt($original_price),
111
+ 'feed' => 265,
112
+ 'font' => 'bold',
113
+ 'align' => 'right',
114
+ );
115
+
116
+ // draw Price sold at
117
+ $lines[0][] = array(
118
+ 'text' => $order->formatPriceTxt($price),
119
+ 'feed' => 350,
120
+ 'font' => 'bold',
121
+ 'align' => 'right',
122
+ );
123
+
124
+ // flubit draw QTY
125
+ $lines[0][] = array(
126
+ 'text' => $item->getQty() * 1,
127
+ 'feed' => 375,
128
+ 'font' => 'bold',
129
+ 'align' => 'right',
130
+ );
131
+
132
+ // draw flubit Tax rate
133
+ $lines[0][] = array(
134
+ 'text' => $tax_percentage,
135
+ 'feed' => 420,
136
+ 'font' => 'bold',
137
+ 'align' => 'right'
138
+ );
139
+
140
+ // draw Total (inc)
141
+ $subtotal = $item->getRowTotal() + $item->getTaxAmount() + $item->getHiddenTaxAmount() - $item->getDiscountAmount();
142
+ $lines[0][] = array(
143
+ 'text' => $order->formatPriceTxt($subtotal),
144
+ 'feed' => 550,
145
+ 'font' => 'bold',
146
+ 'align' => 'right'
147
+ );
148
+
149
+ }
150
+
151
+ // draw options
152
+ $options = $this->getItemOptions();
153
+ if ($options) {
154
+ foreach ($options as $option) {
155
+ // draw options label
156
+ $lines[][] = array(
157
+ 'text' => Mage::helper('core/string')->str_split(strip_tags($option['label']), 40, true, true),
158
+ 'font' => 'italic',
159
+ 'feed' => 35
160
+ );
161
+
162
+ // draw options value
163
+ $_printValue = isset($option['print_value']) ? $option['print_value'] : strip_tags($option['value']);
164
+ $lines[][] = array(
165
+ 'text' => Mage::helper('core/string')->str_split($_printValue, 30, true, true),
166
+ 'feed' => 40
167
+ );
168
+ }
169
+ }
170
+
171
+ $lineBlock = array(
172
+ 'lines' => $lines,
173
+ 'height' => 20
174
+ );
175
+
176
+ $page = $pdf->drawLineBlocks($page, array($lineBlock), array('table_header' => true));
177
+ $this->setPage($page);
178
+ } else {
179
+ // if version is lower than 1.6
180
+ if ($flubitOrder) {
181
+ $leftBound = 35;
182
+ $rightBound = 565;
183
+ //flubit order
184
+ $x = $leftBound;
185
+ // draw Product name
186
+ $lines[0] = array(array(
187
+ 'text' => Mage::helper('core/string')->str_split($item->getName(), 60, true, true),
188
+ 'feed' => $x,
189
+ ));
190
+ //flubit order
191
+ $x += 140;
192
+ // draw SKU
193
+ $lines[0][] = array(
194
+ 'text' => Mage::helper('core/string')->str_split($this->getSku($item), 25),
195
+ 'feed' => $x
196
+ );
197
+ //flubit order
198
+ $x += 90;
199
+ // draw Total (ex)
200
+ $lines[0][] = array(
201
+ 'text' => $order->formatPriceTxt($original_price),
202
+ 'feed' => $x,
203
+ 'font' => 'bold',
204
+ 'align' => 'right',
205
+ 'width' => 10,
206
+ );
207
+
208
+ //flubit order
209
+ $x += 40;
210
+ // draw Discount flubit tax percentage
211
+ $lines[0][] = array(
212
+ 'text' => $order->formatPriceTxt($price),
213
+ 'feed' => $x,
214
+ 'font' => 'bold',
215
+ 'align' => 'right',
216
+ 'width' => 50,
217
+ );
218
+ //flubit order
219
+ $x += 50;
220
+ // draw QTY
221
+ $lines[0][] = array(
222
+ 'text' => $item->getQty() * 1,
223
+ 'feed' => $x,
224
+ 'font' => 'bold',
225
+ 'align' => 'center',
226
+ 'width' => 30,
227
+ );
228
+ //flubit order
229
+ $x += 30;
230
+ // draw flubit proice sold at
231
+ $lines[0][] = array(
232
+ 'text' => $tax_percentage,
233
+ 'feed' => $x,
234
+ 'font' => 'bold',
235
+ 'align' => 'right',
236
+ 'width' => 45,
237
+ );
238
+ //flubit order
239
+ $x += 45;
240
+ // draw Subtotal
241
+ $lines[0][] = array(
242
+ 'text' => $order->formatPriceTxt($price),
243
+ 'feed' => $rightBound,
244
+ 'font' => 'bold',
245
+ 'align' => 'right'
246
+ );
247
+ } else {
248
+ $leftBound = 35;
249
+ $rightBound = 560;
250
+
251
+ $x = $leftBound;
252
+ // draw Product name
253
+ $lines[0] = array(array(
254
+ 'text' => Mage::helper('core/string')->str_split($item->getName(), 60, true, true),
255
+ 'feed' => $x,
256
+ ));
257
+
258
+ $x += 220;
259
+ // draw SKU
260
+ $lines[0][] = array(
261
+ 'text' => Mage::helper('core/string')->str_split($this->getSku($item), 25),
262
+ 'feed' => $x
263
+ );
264
+
265
+ $x += 100;
266
+ // draw Total (ex)
267
+ $lines[0][] = array(
268
+ 'text' => $order->formatPriceTxt($item->getRowTotal()),
269
+ 'feed' => $x,
270
+ 'font' => 'bold',
271
+ 'align' => 'right',
272
+ 'width' => 50,
273
+ );
274
+
275
+ $x += 50;
276
+ // draw Discount
277
+ $lines[0][] = array(
278
+ 'text' => $order->formatPriceTxt(-$item->getDiscountAmount()),
279
+ 'feed' => $x,
280
+ 'font' => 'bold',
281
+ 'align' => 'right',
282
+ 'width' => 50,
283
+ );
284
+
285
+ $x += 50;
286
+ // draw QTY
287
+ $lines[0][] = array(
288
+ 'text' => $item->getQty() * 1,
289
+ 'feed' => $x,
290
+ 'font' => 'bold',
291
+ 'align' => 'center',
292
+ 'width' => 30,
293
+ );
294
+
295
+ $x += 30;
296
+ // draw Tax
297
+ $lines[0][] = array(
298
+ 'text' => $order->formatPriceTxt($item->getTaxAmount()),
299
+ 'feed' => $x,
300
+ 'font' => 'bold',
301
+ 'align' => 'right',
302
+ 'width' => 45,
303
+ );
304
+
305
+ $x += 45;
306
+ // draw Subtotal
307
+ $lines[0][] = array(
308
+ 'text' => $order->formatPriceTxt($item->getRowTotal() + $item->getTaxAmount() - $item->getDiscountAmount()),
309
+ 'feed' => $rightBound,
310
+ 'font' => 'bold',
311
+ 'align' => 'right'
312
+ );
313
+ }
314
+ // draw options
315
+ $options = $this->getItemOptions();
316
+ if ($options) {
317
+ foreach ($options as $option) {
318
+ // draw options label
319
+ $lines[][] = array(
320
+ 'text' => Mage::helper('core/string')->str_split(strip_tags($option['label']), 70, true, true),
321
+ 'font' => 'italic',
322
+ 'feed' => $leftBound
323
+ );
324
+
325
+ // draw options value
326
+ $_printValue = isset($option['print_value']) ? $option['print_value'] : strip_tags($option['value']);
327
+ $lines[][] = array(
328
+ 'text' => Mage::helper('core/string')->str_split($_printValue, 50, true, true),
329
+ 'feed' => $leftBound + 5
330
+ );
331
+ }
332
+ }
333
+
334
+ $lineBlock = array(
335
+ 'lines' => $lines,
336
+ 'height' => 10
337
+ );
338
+
339
+ $page = $pdf->drawLineBlocks($page, array($lineBlock), array('table_header' => true));
340
+ $this->setPage($page);
341
+
342
+
343
+ }
344
+ }
345
+
346
+ }
app/code/community/Flubit/Flubit/Model/Order/Pdf/Items/Invoice/Default.php ADDED
@@ -0,0 +1,359 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Sales Order Invoice Pdf default items renderer
5
+ *
6
+ * @category Flubit
7
+ * @package Flubit_Sales
8
+ */
9
+ class Flubit_Flubit_Model_Order_Pdf_Items_Invoice_Default extends Mage_Sales_Model_Order_Pdf_Items_Invoice_Default
10
+ {
11
+ /**
12
+ * Draw item line
13
+ */
14
+ public function draw()
15
+ {
16
+ $magentoVersion = Mage::getVersion();
17
+
18
+
19
+ $order = $this->getOrder();
20
+ $flubitOrder = False;
21
+
22
+ if ($order->getFlubitOrderId()) {
23
+ $flubitOrder = True;
24
+ }
25
+ $tax_percentage = $order->getFlubitOrderTaxRate();
26
+ //$tax_rate = (($tax_percentage / 100) + 1);
27
+ //$base_price = $_item->getBasePrice();
28
+ //$base_tax_amount = $base_price - ($base_price / $tax_rate);
29
+ $item = $this->getItem();
30
+ $original_price = '';
31
+ if($flubitOrder) {
32
+ $itemData = $item->getOrderItem()->getData();
33
+ $original_price = round($itemData['original_price'],2);
34
+ }
35
+ $price = $item->getPrice();
36
+ //$tax_amount = $price - ($price / $tax_rate);
37
+
38
+
39
+
40
+ $pdf = $this->getPdf();
41
+ $page = $this->getPage();
42
+ $lines = array();
43
+ if (version_compare($magentoVersion, '1.7', '>=')){
44
+ if(!$flubitOrder) {
45
+ // draw Product name
46
+ $lines[0] = array(array(
47
+ 'text' => Mage::helper('core/string')->str_split($item->getName(), 35, true, true),
48
+ 'feed' => 35,
49
+ ));
50
+
51
+ // draw SKU
52
+ $lines[0][] = array(
53
+ 'text' => Mage::helper('core/string')->str_split($this->getSku($item), 17),
54
+ 'feed' => 290,
55
+ 'align' => 'right'
56
+ );
57
+
58
+ // draw QTY
59
+ $lines[0][] = array(
60
+ 'text' => $item->getQty() * 1,
61
+ 'feed' => 435,
62
+ 'align' => 'right'
63
+ );
64
+
65
+ // draw item Prices
66
+ $i = 0;
67
+ $prices = $this->getItemPricesForDisplay();
68
+ $feedPrice = 395;
69
+ $feedSubtotal = $feedPrice + 170;
70
+ foreach ($prices as $priceData) {
71
+ if (isset($priceData['label'])) {
72
+ // draw Price label
73
+ $lines[$i][] = array(
74
+ 'text' => $priceData['label'],
75
+ 'feed' => $feedPrice,
76
+ 'align' => 'right'
77
+ );
78
+ // draw Subtotal label
79
+ $lines[$i][] = array(
80
+ 'text' => $priceData['label'],
81
+ 'feed' => $feedSubtotal,
82
+ 'align' => 'right'
83
+ );
84
+ $i++;
85
+ }
86
+ // draw Price
87
+ $lines[$i][] = array(
88
+ 'text' => $priceData['price'],
89
+ 'feed' => $feedPrice,
90
+ 'font' => 'bold',
91
+ 'align' => 'right'
92
+ );
93
+ // draw Subtotal
94
+ $lines[$i][] = array(
95
+ 'text' => $priceData['subtotal'],
96
+ 'feed' => $feedSubtotal,
97
+ 'font' => 'bold',
98
+ 'align' => 'right'
99
+ );
100
+ $i++;
101
+ }
102
+
103
+ // draw Tax
104
+ $lines[0][] = array(
105
+ 'text' => $order->formatPriceTxt($item->getTaxAmount()),
106
+ 'feed' => 495,
107
+ 'font' => 'bold',
108
+ 'align' => 'right'
109
+ );
110
+
111
+ } else {
112
+ // draw Product name
113
+ $lines[0] = array(array(
114
+ 'text' => Mage::helper('core/string')->str_split($item->getName(), 15, true, true),
115
+ 'feed' => 35,
116
+ ));
117
+
118
+ // draw SKU
119
+ $lines[0][] = array(
120
+ 'text' => Mage::helper('core/string')->str_split($this->getSku($item), 8),
121
+ 'feed' => 175,
122
+ 'align' => 'right'
123
+ );
124
+
125
+ // draw FBP
126
+ $lines[0][] = array(
127
+ 'text' => $order->formatPriceTxt($original_price),
128
+ 'feed' => 250,
129
+ 'align' => 'right'
130
+ );
131
+
132
+ // draw QTY
133
+ $lines[0][] = array(
134
+ 'text' => $item->getQty() * 1,
135
+ 'feed' => 275,
136
+ 'align' => 'right'
137
+ );
138
+
139
+ // draw item Prices
140
+ $i = 0;
141
+ $prices = $this->getItemPricesForDisplay();
142
+ $feedPrice = 375;
143
+ $feedSubtotal = $feedPrice + 170;
144
+ foreach ($prices as $priceData){
145
+ if (isset($priceData['label'])) {
146
+ // draw Price label
147
+ $lines[$i][] = array(
148
+ 'text' => $priceData['label'],
149
+ 'feed' => $feedPrice,
150
+ 'align' => 'right'
151
+ );
152
+ // draw Subtotal label
153
+ $lines[$i][] = array(
154
+ 'text' => $priceData['label'],
155
+ 'feed' => $feedSubtotal,
156
+ 'align' => 'right'
157
+ );
158
+ $i++;
159
+ }
160
+ // draw Price
161
+ $lines[$i][] = array(
162
+ 'text' => $priceData['price'],
163
+ 'feed' => $feedPrice,
164
+ 'font' => 'bold',
165
+ 'align' => 'right'
166
+ );
167
+ // draw Subtotal
168
+ $lines[$i][] = array(
169
+ 'text' => $priceData['subtotal'],
170
+ 'feed' => $feedSubtotal,
171
+ 'font' => 'bold',
172
+ 'align' => 'right'
173
+ );
174
+ $i++;
175
+ }
176
+
177
+ // draw Tax
178
+ $lines[0][] = array(
179
+ 'text' => $tax_percentage,
180
+ 'feed' => 425,
181
+ 'font' => 'bold',
182
+ 'align' => 'right'
183
+ );
184
+ }
185
+
186
+
187
+ // custom options
188
+ $options = $this->getItemOptions();
189
+ if ($options) {
190
+ foreach ($options as $option) {
191
+ // draw options label
192
+ $lines[][] = array(
193
+ 'text' => Mage::helper('core/string')->str_split(strip_tags($option['label']), 40, true, true),
194
+ 'font' => 'italic',
195
+ 'feed' => 35
196
+ );
197
+
198
+ if ($option['value']) {
199
+ if (isset($option['print_value'])) {
200
+ $_printValue = $option['print_value'];
201
+ } else {
202
+ $_printValue = strip_tags($option['value']);
203
+ }
204
+ $values = explode(', ', $_printValue);
205
+ foreach ($values as $value) {
206
+ $lines[][] = array(
207
+ 'text' => Mage::helper('core/string')->str_split($value, 30, true, true),
208
+ 'feed' => 40
209
+ );
210
+ }
211
+ }
212
+ }
213
+ }
214
+
215
+ $lineBlock = array(
216
+ 'lines' => $lines,
217
+ 'height' => 20
218
+ );
219
+ } else {
220
+ // Magento Version is smaller than 1.7
221
+ // draw Product name
222
+
223
+ if(!$flubitOrder) {
224
+
225
+ $lines[0] = array(array(
226
+ 'text' => Mage::helper('core/string')->str_split($item->getName(), 60, true, true),
227
+ 'feed' => 35,
228
+ ));
229
+
230
+ // draw SKU
231
+ $lines[0][] = array(
232
+ 'text' => Mage::helper('core/string')->str_split($this->getSku($item), 25),
233
+ 'feed' => 255
234
+ );
235
+
236
+ // draw QTY
237
+ $lines[0][] = array(
238
+ 'text' => $item->getQty()*1,
239
+ 'feed' => 435
240
+ );
241
+
242
+ // draw Price
243
+ $lines[0][] = array(
244
+ 'text' => $order->formatPriceTxt($item->getPrice()),
245
+ 'feed' => 395,
246
+ 'font' => 'bold',
247
+ 'align' => 'right'
248
+ );
249
+
250
+ // draw Tax
251
+ $lines[0][] = array(
252
+ 'text' => $order->formatPriceTxt($item->getTaxAmount()),
253
+ 'feed' => 495,
254
+ 'font' => 'bold',
255
+ 'align' => 'right'
256
+ );
257
+
258
+ // draw Subtotal
259
+ $lines[0][] = array(
260
+ 'text' => $order->formatPriceTxt($item->getRowTotal()),
261
+ 'feed' => 565,
262
+ 'font' => 'bold',
263
+ 'align' => 'right'
264
+ );
265
+
266
+ }
267
+ else {
268
+
269
+ $lines[0] = array(array(
270
+ 'text' => Mage::helper('core/string')->str_split($item->getName(), 30, true, true),
271
+ 'feed' => 35,
272
+ ));
273
+
274
+ // draw SKU
275
+ $lines[0][] = array(
276
+ 'text' => Mage::helper('core/string')->str_split($this->getSku($item), 15),
277
+ 'feed' => 190
278
+ );
279
+
280
+
281
+ // draw Original price
282
+ $lines[0][] = array(
283
+ 'text' => $order->formatPriceTxt($original_price),
284
+ 'feed' => 270,
285
+ 'font' => 'bold',
286
+ 'align' => 'right'
287
+ );
288
+
289
+ // draw Price
290
+ $lines[0][] = array(
291
+ 'text' => $order->formatPriceTxt($item->getPrice()),
292
+ 'feed' => 370,
293
+ 'font' => 'bold',
294
+ 'align' => 'right'
295
+ );
296
+
297
+ // draw QTY
298
+ $lines[0][] = array(
299
+ 'text' => $item->getQty()*1,
300
+ 'feed' => 390
301
+ );
302
+
303
+
304
+
305
+ // draw Tax
306
+ $lines[0][] = array(
307
+ 'text' => $tax_percentage,
308
+ 'feed' => 446,
309
+ 'font' => 'bold',
310
+ 'align' => 'right'
311
+ );
312
+
313
+ // draw Subtotal
314
+ $lines[0][] = array(
315
+ 'text' => $order->formatPriceTxt($item->getRowTotal()),
316
+ 'feed' => 564,
317
+ 'font' => 'bold',
318
+ 'align' => 'right'
319
+ );
320
+
321
+ }
322
+
323
+ // custom options
324
+ $options = $this->getItemOptions();
325
+ if ($options) {
326
+ foreach ($options as $option) {
327
+ // draw options label
328
+ $lines[][] = array(
329
+ 'text' => Mage::helper('core/string')->str_split(strip_tags($option['label']), 70, true, true),
330
+ 'font' => 'italic',
331
+ 'feed' => 35
332
+ );
333
+
334
+ if ($option['value']) {
335
+ $_printValue = isset($option['print_value']) ? $option['print_value'] : strip_tags($option['value']);
336
+ $values = explode(', ', $_printValue);
337
+ foreach ($values as $value) {
338
+ $lines[][] = array(
339
+ 'text' => Mage::helper('core/string')->str_split($value, 50, true, true),
340
+ 'feed' => 40
341
+ );
342
+ }
343
+ }
344
+ }
345
+ }
346
+
347
+ $lineBlock = array(
348
+ 'lines' => $lines,
349
+ 'height' => 20
350
+ );
351
+ } // end else of version check
352
+
353
+ $page = $pdf->drawLineBlocks($page, array($lineBlock), array('table_header' => true));
354
+ $this->setPage($page);
355
+ }
356
+ //} // end checking version
357
+
358
+ //}
359
+ }
app/code/community/Flubit/Flubit/Model/Ordertime.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Model Logs
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model_Ordertime
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Ordertime extends Mage_Core_Model_Abstract {
11
+
12
+ /**
13
+ * Constructor for load Flubit Order
14
+ *
15
+ */
16
+ public function _construct() {
17
+ try {
18
+ parent::_construct();
19
+ $this->_init('flubit/ordertime');
20
+ } catch (Exception $e) {
21
+ Mage::log("Exception Delete Failed : " . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
22
+ }
23
+ }
24
+
25
+ }
app/code/community/Flubit/Flubit/Model/Payment/Method/Flubitterms.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Flubit_Flubit_Model_Payment_Method_Flubitterms extends Mage_Payment_Model_Method_Checkmo {
4
+
5
+ protected $_code = 'flubitterms';
6
+
7
+ /**
8
+ * Check whether payment method can be used
9
+ *
10
+ * TODO: payment method instance is not supposed to know about quote
11
+ *
12
+ * @param Mage_Sales_Model_Quote|null $quote
13
+ *
14
+ * @return bool
15
+ */
16
+ public function isAvailable($quote = null) {
17
+ $checkResult = new StdClass;
18
+
19
+ //Custom
20
+ $flubitorder = Mage::helper('flubit')->isFlubitOrder();
21
+ $validation = false;
22
+ if ($flubitorder && $this->_code == 'flubitterms') {
23
+ $validation = true;
24
+ }
25
+
26
+ $isActive = (bool) (int) $this->getConfigData('active', $quote ? $quote->getStoreId() : null);
27
+
28
+ //Custom
29
+ if ($validation) {
30
+ $isActive = true;
31
+ } else {
32
+ $isActive = false;
33
+ }
34
+
35
+ $checkResult->isAvailable = $isActive;
36
+ $checkResult->isDeniedInConfig = !$isActive; // for future use in observers
37
+ Mage::dispatchEvent('payment_method_is_active', array(
38
+ 'result' => $checkResult,
39
+ 'method_instance' => $this,
40
+ 'quote' => $quote,
41
+ ));
42
+ $magentoVersion = Mage::getVersion();
43
+ if (version_compare($magentoVersion, '1.8', '>=')) {
44
+ if ($checkResult->isAvailable && $quote) {
45
+ $checkResult->isAvailable = $this->isApplicableToQuote($quote, self::CHECK_RECURRING_PROFILES);
46
+ }
47
+ } else if (version_compare($magentoVersion, '1.7', '>=')) {
48
+ if ($checkResult->isAvailable) {
49
+ $implementsRecurring = $this->canManageRecurringProfiles();
50
+ // the $quote->hasRecurringItems() causes big performance impact, thus it has to be called last
51
+ if ($quote && !$implementsRecurring && $quote->hasRecurringItems()) {
52
+ $checkResult->isAvailable = false;
53
+ }
54
+ }
55
+ } else {
56
+
57
+ }
58
+
59
+ return $checkResult->isAvailable;
60
+ }
61
+
62
+ }
app/code/community/Flubit/Flubit/Model/Quote/Item.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Flubit_Flubit_Model_Quote_Item
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Model
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Model_Quote_Item extends Mage_Sales_Model_Quote_Item {
11
+
12
+ public function initPrice($value) {
13
+ $store = $this->getQuote()->getStore();
14
+ if (!Mage::helper('tax')->priceIncludesTax($store)) {
15
+ // DEEE
16
+ $_deee_amount = 0;
17
+ if (!Mage::helper('tax')->priceIncludesTax($store)) {
18
+ $_helper_weee = Mage::helper('weee');
19
+ $_deee_amount = $_helper_weee->getAmount($this->getProduct());
20
+ }
21
+ $bAddress = $this->getQuote()->getBillingAddress();
22
+ $sAddress = $this->getQuote()->getShippingAddress();
23
+ $address = $this->getAddress();
24
+ if ($address) {
25
+ switch ($address->getAddressType()) {
26
+ case Mage_Sales_Model_Quote_Address::TYPE_BILLING:
27
+ $bAddress = $address;
28
+ break;
29
+ case Mage_Sales_Model_Quote_Address::TYPE_SHIPPING:
30
+ $sAddress = $address;
31
+ break;
32
+ }
33
+ }
34
+
35
+ if ($this->getProduct()->getIsVirtual()) {
36
+ $sAddress = $bAddress;
37
+ }
38
+
39
+ $priceExcludingTax = Mage::helper('tax')->getPrice(
40
+ $this->getProduct()->setTaxPercent(null), $value, false, $sAddress, $bAddress, $this->getQuote()->getCustomerTaxClassId(), $store, true
41
+ ) - $_deee_amount;
42
+ $this->setCustomPrice($priceExcludingTax);
43
+ $this->setOriginalCustomPrice($priceExcludingTax);
44
+ $this->setOriginalPrice($priceExcludingTax);
45
+
46
+ $priceIncludingTax = Mage::helper('tax')->getPrice(
47
+ $this->getProduct()->setTaxPercent(null), $value, true, $sAddress, $bAddress, $this->getQuote()->getCustomerTaxClassId(), $store, true
48
+ );
49
+ $qty = $this->getQty();
50
+ if ($this->getParentItem()) {
51
+ $qty = $qty * $this->getParentItem()->getQty();
52
+ }
53
+
54
+ //if (Mage::helper('tax')->displayCartPriceInclTax($store)) {
55
+ $rowTotal = $value * $qty;
56
+ $rowTotalExcTax = Mage::helper('tax')->getPrice(
57
+ $this->getProduct()->setTaxPercent(null), $rowTotal, false, $sAddress, $bAddress, $this->getQuote()->getCustomerTaxClassId(), $store, true
58
+ ) - ($_deee_amount * $qty);
59
+ $rowTotalIncTax = Mage::helper('tax')->getPrice(
60
+ $this->getProduct()->setTaxPercent(null), $rowTotal, true, $sAddress, $bAddress, $this->getQuote()->getCustomerTaxClassId(), $store, true
61
+ );
62
+ $totalBaseTax = $rowTotalIncTax - $rowTotalExcTax;
63
+ $this->setBaseRowTotal($rowTotal);
64
+ $this->setBaseRowTotalInclTax($rowTotal);
65
+ //} else {
66
+ $taxAmount = $priceIncludingTax - $priceExcludingTax;
67
+ $this->setTaxPercent($this->getProduct()->getTaxPercent());
68
+ $totalBaseTax = $taxAmount * $qty;
69
+ //}
70
+
71
+ $totalTax = $this->getStore()->convertPrice($totalBaseTax);
72
+ $this->setTaxBeforeDiscount($totalTax);
73
+ $this->setBaseTaxBeforeDiscount($totalBaseTax);
74
+
75
+ $this->setTaxAmount($totalTax);
76
+ $this->setBaseTaxAmount($totalBaseTax);
77
+ $this->setBaseOriginalPrice($priceExcludingTax);
78
+ $this->setTaxAmount($totalTax);
79
+ $this->setPrice($priceExcludingTax);
80
+ $this->setPriceInclTax($priceIncludingTax);
81
+ $this->setBasePriceInclTax($priceIncludingTax);
82
+ return $this;
83
+ } else {
84
+ return $this;
85
+ }
86
+ }
87
+
88
+ }
app/code/community/Flubit/Flubit/Model/Shipping.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Flubit_Flubit_Model_Shipping extends Mage_Shipping_Model_Shipping {
4
+
5
+ /**
6
+ * Get carrier by its code
7
+ *
8
+ * @param string $carrierCode
9
+ * @param null|int $storeId
10
+ * @return bool|Mage_Core_Model_Abstract
11
+ */
12
+ public function getCarrierByCode($carrierCode, $storeId = null) {
13
+ //if flubit order pass the flatrate shipping method
14
+ $flubitorder = Mage::helper('flubit')->isFlubitOrder();
15
+ $validation = false;
16
+ if ($flubitorder && $carrierCode == 'flatrate') {
17
+ $validation = true;
18
+ }
19
+
20
+ if (!Mage::getStoreConfigFlag('carriers/' . $carrierCode . '/' . $this->_availabilityConfigField, $storeId) && !$validation) {
21
+ return false;
22
+ }
23
+
24
+ $className = Mage::getStoreConfig('carriers/' . $carrierCode . '/model', $storeId);
25
+ if (!$className) {
26
+ return false;
27
+ }
28
+ $obj = Mage::getModel($className);
29
+ if ($storeId) {
30
+ $obj->setStore($storeId);
31
+ }
32
+ return $obj;
33
+ }
34
+
35
+ }
app/code/community/Flubit/Flubit/controllers/Adminhtml/FlubitController.php ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Adminhtml Flubit
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Adminhtml
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_Adminhtml_FlubitController extends Mage_Adminhtml_Controller_Action {
11
+
12
+ /**
13
+ * Method for InitAction Load
14
+ * @return \Flubit_Flubit_Adminhtml_FlubitController
15
+ */
16
+ protected function _initAction() {
17
+ try {
18
+ $this->loadLayout()
19
+ ->_setActiveMenu('flubit/items')
20
+ ->_addBreadcrumb(Mage::helper('adminhtml')->__('Items Manager'), Mage::helper('adminhtml')->__('Item Manager'));
21
+
22
+ return $this;
23
+ } catch (Exception $e) {
24
+ Mage::log(__LINE__ . 'Exception Flubit_Flubit_Adminhtml_FlubitController _initAction ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
25
+ }
26
+ }
27
+
28
+ /**
29
+ * Method for Index Method load Action and Render
30
+ *
31
+ */
32
+ public function indexAction() {
33
+ // Let's call our initAction method which will set some basic params for each action
34
+ try {
35
+ $this->_initAction()
36
+ ->renderLayout();
37
+ } catch (Exception $e) {
38
+ Mage::log(__LINE__ . 'Exception Flubit_Flubit_Adminhtml_FlubitController indexAction ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Method for Render to Edit
44
+ *
45
+ */
46
+ public function newAction() {
47
+ // We just forward the new action to a blank edit form
48
+ $this->_forward('edit');
49
+ }
50
+
51
+ /**
52
+ * Method for Render to Edit Action
53
+ *
54
+ * @return none
55
+ */
56
+ public function editAction() {
57
+ try {
58
+ $this->_initAction();
59
+
60
+ // Get id if available
61
+ $id = $this->getRequest()->getParam('id');
62
+ $model = Mage::getModel('flubit/flubit');
63
+
64
+ if ($id) {
65
+ // Load record
66
+ $model->load($id);
67
+
68
+ // Check if record is loaded
69
+ if (!$model->getId()) {
70
+ Mage::getSingleton('adminhtml/session')->addError($this->__('This baz no longer exists.'));
71
+ $this->_redirect('*/*/');
72
+
73
+ return;
74
+ }
75
+ }
76
+
77
+ $this->_title($model->getId() ? $model->getName() : $this->__('New Baz'));
78
+
79
+ $data = Mage::getSingleton('adminhtml/session')->getBazData(true);
80
+ if (!empty($data)) {
81
+ $model->setData($data);
82
+ }
83
+
84
+ Mage::register('flubit', $model);
85
+
86
+ $this->_initAction()
87
+ ->_addBreadcrumb($id ? $this->__('Edit Baz') : $this->__('New Baz'), $id ? $this->__('Edit Baz') : $this->__('New Baz'))
88
+ ->_addContent($this->getLayout()->createBlock('foo_bar/adminhtml_baz_edit')->setData('action', $this->getUrl('*/*/save')))
89
+ ->renderLayout();
90
+ } catch (Exception $e) {
91
+ Mage::log(__LINE__ . 'Exception Flubit_Flubit_Adminhtml_FlubitController editAction ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Method for Save Product Session Message
97
+ *
98
+ */
99
+ public function saveAction() {
100
+ try {
101
+ if ($postData = $this->getRequest()->getPost()) {
102
+ $model = Mage::getSingleton('foo_bar/baz');
103
+ $model->setData($postData);
104
+
105
+ try {
106
+ $model->save();
107
+
108
+ Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The baz has been saved.'));
109
+ $this->_redirect('*/*/');
110
+
111
+ return;
112
+ } catch (Mage_Core_Exception $e) {
113
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
114
+ } catch (Exception $e) {
115
+ Mage::getSingleton('adminhtml/session')->addError($this->__('An error occurred while saving this baz.'));
116
+ }
117
+
118
+ Mage::getSingleton('adminhtml/session')->setBazData($postData);
119
+ $this->_redirectReferer();
120
+ }
121
+ } catch (Exception $e) {
122
+ Mage::log(__LINE__ . 'Exception Flubit_Flubit_Adminhtml_FlubitController saveAction ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Method for Update Flubit Price
128
+ *
129
+ */
130
+ public function updateFlubitPriceAction() {
131
+ try {
132
+ $error = false;
133
+ $message = '';
134
+
135
+ $fieldId = (int) $this->getRequest()->getParam('id');
136
+ $price = number_format($this->getRequest()->getParam('price'), 2, '.', '');
137
+ $sku = $this->getRequest()->getParam('sku');
138
+ if ($fieldId) {
139
+ $collection = Mage::getModel('flubit/flubit')->getCollection();
140
+ $collection->addFieldToFilter('flubit_id', $fieldId);
141
+
142
+ foreach ($collection as $flubit) {
143
+ $sku = $flubit->getSku();
144
+ $flubit->setPrice($price)
145
+ ->setStatus(1)
146
+ ->save();
147
+ }
148
+ $message = Mage::helper('adminhtml')->__('Flubit Price overriden for "%s"', $flubit->getSku());
149
+ } else {
150
+ $error = true;
151
+ $message = 'An error occured. Please retry';
152
+ }
153
+ $return = array();
154
+ if ($error) {
155
+ $return['ERROR'] = 1;
156
+ } else {
157
+ $return['SUCCESS'] = 1;
158
+ $return['PRICE'] = $price;
159
+ }
160
+
161
+ $return['MESSAGE'] = $message;
162
+ return $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($return));
163
+ } catch (Exception $e) {
164
+ Mage::log(__LINE__ . 'Exception Flubit_Flubit_Adminhtml_FlubitController updateFlubitPriceAction ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
165
+ }
166
+ }
167
+
168
+ /**
169
+ * Method for Update Flubit Price Calculator
170
+ *
171
+ */
172
+ public function updateFlubitPriceCalculatorAction() {
173
+ try {
174
+ $error = false;
175
+ $message = '';
176
+ $fieldId = (int) $this->getRequest()->getParam('id');
177
+ $status = $this->getRequest()->getParam('status');
178
+ $priceBasedOn = Mage::getStoreConfig('flubit_section/flubit_setup/price_based_on');
179
+ $globalPrice = Mage::getStoreConfig('flubit_section/flubit_setup/global_price');
180
+ if ($fieldId && $status !== '') {
181
+ $collection = Mage::getModel('flubit/flubit')->getCollection()
182
+ ->addFieldToFilter('flubit_id', $fieldId)
183
+ ->addFieldToSelect('sku')
184
+ ->addFieldToSelect('flubit_id')
185
+ ->addFieldToSelect('price');
186
+ foreach ($collection as $flubit) {
187
+ $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $flubit->getSku());
188
+ if (is_object($product)) {
189
+ if ($priceBasedOn) {
190
+ $priceOfProduct = $product->getData($priceBasedOn); // Get price based on selected price
191
+ } else {
192
+ $priceOfProduct = $product->getPrice($priceBasedOn); // get default magento price
193
+ }
194
+
195
+ $flubitPrice = $priceOfProduct - ($priceOfProduct * ($globalPrice / 100));
196
+ $flubitPrice = number_format($flubitPrice, 2, '.', '');
197
+ //updating the price in the main table
198
+ if ($status == '1') {
199
+ $flubit->setPrice($flubitPrice)
200
+ ->setUseGlobalPrice('1')
201
+ ->setGlobalPriceUpdate('1')
202
+ ->setStatus('1')
203
+ ->save();
204
+ } else {
205
+ $flubit->setGlobalPriceUpdate('1')
206
+ ->setUseGlobalPrice('0')
207
+ ->setStatus('1')
208
+ ->save();
209
+ }
210
+ $message = Mage::helper('adminhtml')->__('Flubit Price overriden for "%s"', $flubit->getSku());
211
+ } // product object check
212
+ }
213
+ } else {
214
+ $error = true;
215
+ $message = Mage::helper('adminhtml')->__('Missing flubit row id or status.');
216
+ }
217
+
218
+ $return = array();
219
+ if ($error) {
220
+ $return['ERROR'] = 1;
221
+ } else {
222
+ $return['SUCCESS'] = 1;
223
+ $return['PRICE'] = $flubitPrice;
224
+ $return['ID'] = $fieldId;
225
+ }
226
+
227
+ $return['MESSAGE'] = $message;
228
+ return $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($return));
229
+ } catch (Exception $e) {
230
+ Mage::log(__LINE__ . 'Exception Flubit_Flubit_Adminhtml_FlubitController updateFlubitPriceCalculatorAction ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
231
+ }
232
+ }
233
+
234
+ }
app/code/community/Flubit/Flubit/controllers/FlubitController.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Adminhtml Flubit
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Flubit
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubit_FlubitController extends Mage_Adminhtml_Controller_Action {
11
+
12
+ public function generateProductXMLAction() {
13
+ $error = false;
14
+ try {
15
+ $result = Mage::getModel('flubit/flubit')->generateProductXML();
16
+ $message = $this->__($result);
17
+ } catch (Exception $e) {
18
+ $error = true;
19
+ $message = $this->__('%s', $e->getMessage());
20
+ }
21
+
22
+ if ($error) {
23
+ Mage::getSingleton('adminhtml/session')->addError($message);
24
+ } else {
25
+ Mage::getSingleton('adminhtml/session')->addSuccess($message);
26
+ }
27
+
28
+ $this->_redirect('adminhtml/system_config/edit');
29
+ }
30
+
31
+ }
app/code/community/Flubit/Flubit/etc/adminhtml.xml ADDED
@@ -0,0 +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
+ <flubit_section translate="title" module="flubit">
12
+ <title>Flubit Section</title>
13
+ <sort_order>0</sort_order>
14
+ </flubit_section>
15
+ </children>
16
+ </config>
17
+ </children>
18
+ </system>
19
+ </children>
20
+ </admin>
21
+ </resources>
22
+ </acl>
23
+ </config>
app/code/community/Flubit/Flubit/etc/config.xml ADDED
@@ -0,0 +1,343 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Flubit_Flubit>
5
+ <version>0.2.8</version>
6
+ </Flubit_Flubit>
7
+ </modules>
8
+ <frontend>
9
+ <routers>
10
+ <flubit>
11
+ <use>standard</use>
12
+ <args>
13
+ <module>Flubit_Flubit</module>
14
+ <frontName>flubit</frontName>
15
+ </args>
16
+ </flubit>
17
+ </routers>
18
+ </frontend>
19
+ <admin>
20
+ <routers>
21
+ <flubit>
22
+ <use>admin</use>
23
+ <args>
24
+ <module>Flubit_Flubit</module>
25
+ <frontName>flubit</frontName>
26
+ </args>
27
+ </flubit>
28
+ </routers>
29
+ </admin>
30
+ <adminhtml>
31
+ <menu>
32
+ <catalog>
33
+ <children>
34
+ <flubit translate="title" module="flubit">
35
+ <title>Flubit Products</title>
36
+ <action>flubit/adminhtml_flubit</action>
37
+ </flubit>
38
+ </children>
39
+ </catalog>
40
+ </menu>
41
+ <acl>
42
+ <resources>
43
+ <all>
44
+ <title>Allow Everything</title>
45
+ </all>
46
+ <admin>
47
+ <children>
48
+ <Flubit_Flubit>
49
+ <title>Flubit Module</title>
50
+ <sort_order>10</sort_order>
51
+ </Flubit_Flubit>
52
+ </children>
53
+ </admin>
54
+ </resources>
55
+ </acl>
56
+ <layout>
57
+ <updates>
58
+ <flubit>
59
+ <file>flubit.xml</file>
60
+ </flubit>
61
+ </updates>
62
+ </layout>
63
+ </adminhtml>
64
+ <global>
65
+ <models>
66
+ <flubit>
67
+ <class>Flubit_Flubit_Model</class>
68
+ <resourceModel>flubit_flubit_mysql4</resourceModel>
69
+ </flubit>
70
+
71
+ <sales>
72
+ <rewrite>
73
+ <order_pdf_invoice>Flubit_Flubit_Model_Order_Pdf_Invoice</order_pdf_invoice>
74
+ <order_pdf_items_invoice_default>Flubit_Flubit_Model_Order_Pdf_Items_Invoice_Default</order_pdf_items_invoice_default>
75
+ <order_pdf_creditmemo>Flubit_Flubit_Model_Order_Pdf_Creditmemo</order_pdf_creditmemo>
76
+ <order_pdf_items_creditmemo_default>Flubit_Flubit_Model_Order_Pdf_Items_Creditmemo_Default</order_pdf_items_creditmemo_default>
77
+ </rewrite>
78
+ </sales>
79
+ <shipping>
80
+ <rewrite>
81
+ <shipping>Flubit_Flubit_Model_Shipping</shipping>
82
+ <carrier_flatrate>Flubit_Flubit_Model_Carrier_Flatrate</carrier_flatrate>
83
+ </rewrite>
84
+ </shipping>
85
+ <flubit_flubit_mysql4>
86
+ <class>Flubit_Flubit_Model_Mysql4</class>
87
+ <entities>
88
+ <flubit>
89
+ <table>flubit_product_update</table>
90
+ </flubit>
91
+ <logs>
92
+ <table>flubit_feeds_log</table>
93
+ </logs>
94
+ <order>
95
+ <table>flubit_order</table>
96
+ </order>
97
+ <ordertime>
98
+ <table>flubit_ordertime</table>
99
+ </ordertime>
100
+ <globalproduct>
101
+ <table>flubit_global_product</table>
102
+ </globalproduct>
103
+ </entities>
104
+ </flubit_flubit_mysql4>
105
+ </models>
106
+ <resources>
107
+ <flubit_setup>
108
+ <setup>
109
+ <module>Flubit_Flubit</module>
110
+ </setup>
111
+ <connection>
112
+ <use>core_setup</use>
113
+ </connection>
114
+ </flubit_setup>
115
+ <flubit_write>
116
+ <connection>
117
+ <use>core_write</use>
118
+ </connection>
119
+ </flubit_write>
120
+ <flubit_read>
121
+ <connection>
122
+ <use>core_read</use>
123
+ </connection>
124
+ </flubit_read>
125
+ </resources>
126
+ <blocks>
127
+ <flubit>
128
+ <class>Flubit_Flubit_Block</class>
129
+ </flubit>
130
+ <flubit_renderer>
131
+ <class>Flubit_Flubit_Block_Adminhtml_Widget_Grid_Column_Renderer</class>
132
+ </flubit_renderer>
133
+ <adminhtml>
134
+ <rewrite>
135
+ <sales_order_view_info>Flubit_Flubit_Block_Sales_Order_View_Info</sales_order_view_info>
136
+ </rewrite>
137
+ </adminhtml>
138
+ </blocks>
139
+ <events>
140
+ <sales_order_creditmemo_save_after>
141
+ <observers>
142
+ <sales_order_creditmemo_save_after_flubit_handler>
143
+ <type>singleton</type>
144
+ <class>Flubit_Flubit_Model_Observer</class>
145
+ <method>cancelFlubitOrder</method>
146
+ </sales_order_creditmemo_save_after_flubit_handler>
147
+ </observers>
148
+ </sales_order_creditmemo_save_after>
149
+ <catalog_product_load_after>
150
+ <observers>
151
+ <catalog_product_load_after_flubit_handler>
152
+ <type>singleton</type>
153
+ <class>Flubit_Flubit_Model_Observer</class>
154
+ <method>lockAttributes</method>
155
+ </catalog_product_load_after_flubit_handler>
156
+ </observers>
157
+ </catalog_product_load_after>
158
+
159
+ <!--<catalog_product_save_before>
160
+ <observers>
161
+ <catalog_product_save_before_flubit_handler>
162
+ <type>singleton</type>
163
+ <class>Flubit_Flubit_Model_Observer</class>
164
+ <method>saveFlubitProduct</method>
165
+ </catalog_product_save_before_flubit_handler>
166
+ </observers>
167
+ </catalog_product_save_before>-->
168
+
169
+ <catalog_product_delete_before>
170
+ <observers>
171
+ <catalog_product_delete_before_flubit_handler>
172
+ <type>singleton</type>
173
+ <class>Flubit_Flubit_Model_Observer</class>
174
+ <method>deleteFlubitProduct</method>
175
+ </catalog_product_delete_before_flubit_handler>
176
+ </observers>
177
+ </catalog_product_delete_before>
178
+
179
+ <catalog_product_save_after>
180
+ <observers>
181
+ <catalog_product_save_after_flubit_handler>
182
+ <type>singleton</type>
183
+ <class>Flubit_Flubit_Model_Observer</class>
184
+ <method>saveFlubitProduct</method>
185
+ </catalog_product_save_after_flubit_handler>
186
+ </observers>
187
+ </catalog_product_save_after>
188
+
189
+ <sales_order_place_after>
190
+ <observers>
191
+ <sales_order_place_after_flubit_handler>
192
+ <type>singleton</type>
193
+ <class>Flubit_Flubit_Model_Observer</class>
194
+ <method>saveOrderAfter</method>
195
+ </sales_order_place_after_flubit_handler>
196
+ </observers>
197
+ </sales_order_place_after>
198
+
199
+ <core_block_abstract_to_html_before>
200
+ <observers>
201
+ <core_block_abstract_to_html_before_flubit_handler>
202
+ <class>Flubit_Flubit_Model_Observer</class>
203
+ <method>removeSendMailButton</method>
204
+ <type>model</type>
205
+ </core_block_abstract_to_html_before_flubit_handler>
206
+ </observers>
207
+ </core_block_abstract_to_html_before>
208
+ <catalog_product_attribute_update_before>
209
+ <observers>
210
+ <core_block_abstract_to_html_before_flubit_handler>
211
+ <class>Flubit_Flubit_Model_Observer</class>
212
+ <method>saveFlubitProductMassAttributeUpdate</method>
213
+ <type>model</type>
214
+ </core_block_abstract_to_html_before_flubit_handler>
215
+ </observers>
216
+ </catalog_product_attribute_update_before>
217
+
218
+ <admin_system_config_changed_section_flubit_section>
219
+ <observers>
220
+ <mymodule>
221
+ <type>model</type>
222
+ <class>Flubit_Flubit_Model_Observer</class>
223
+ <method>saveConfigObserver</method>
224
+ </mymodule>
225
+ </observers>
226
+ </admin_system_config_changed_section_flubit_section>
227
+ </events>
228
+ <helpers>
229
+ <flubit>
230
+ <class>Flubit_Flubit_Helper</class>
231
+ </flubit>
232
+
233
+ <payment>
234
+ <rewrite>
235
+ <data>Flubit_Flubit_Helper_Payment_Data</data>
236
+ </rewrite>
237
+ </payment>
238
+ </helpers>
239
+ </global>
240
+ <default>
241
+ <payment>
242
+ <flubitterms>
243
+ <model>flubit/payment_method_flubitterms</model>
244
+ <active>1</active>
245
+ <title>Custom Flubit Terms</title>
246
+ <order_status>pending</order_status>
247
+ </flubitterms>
248
+ </payment>
249
+ <flubit_section>
250
+ <flubit_setup>
251
+ <product_cron_settings>*/10 * * * *</product_cron_settings>
252
+ </flubit_setup>
253
+ </flubit_section>
254
+ <flubit_section>
255
+ <flubit_setup>
256
+ <order_cron_settings>*/10 * * * *</order_cron_settings>
257
+ </flubit_setup>
258
+ </flubit_section>
259
+ <flubit_section>
260
+ <flubit_setup>
261
+ <order_dispatch_cron_settings>*/10 * * * *</order_dispatch_cron_settings>
262
+ </flubit_setup>
263
+ </flubit_section>
264
+ <flubit_section>
265
+ <flubit_setup>
266
+ <order_cancel_cron_settings>*/10 * * * *</order_cancel_cron_settings>
267
+ </flubit_setup>
268
+ </flubit_section>
269
+ <flubit_section>
270
+ <flubit_setup>
271
+ <order_refund_cron_settings>*/10 * * * *</order_refund_cron_settings>
272
+ </flubit_setup>
273
+ </flubit_section>
274
+ </default>
275
+ <crontab>
276
+ <jobs>
277
+ <flubit_products_cron>
278
+ <schedule>
279
+ <config_path>flubit_section/flubit_setup/product_cron_settings</config_path>
280
+ </schedule>
281
+ <run>
282
+ <model>flubit/flubit::generateProductXML</model>
283
+ </run>
284
+ </flubit_products_cron>
285
+ <flubit_orders_fetch_cron>
286
+ <schedule>
287
+ <config_path>flubit_section/flubit_setup/order_cron_settings</config_path>
288
+ </schedule>
289
+ <run>
290
+ <model>flubit/flubit::getFlubitOrders</model>
291
+ </run>
292
+ </flubit_orders_fetch_cron>
293
+ <flubit_orders_dispatch_cron>
294
+ <schedule>
295
+ <config_path>flubit_section/flubit_setup/order_dispatch_cron_settings</config_path>
296
+ </schedule>
297
+ <run>
298
+ <model>flubit/flubit::dispatchFlubitOrders</model>
299
+ </run>
300
+ </flubit_orders_dispatch_cron>
301
+ <flubit_orders_cancel_cron>
302
+ <schedule>
303
+ <config_path>flubit_section/flubit_setup/order_cancel_cron_settings</config_path>
304
+ </schedule>
305
+ <run>
306
+ <model>flubit/flubit::cancelFlubitOrders</model>
307
+ </run>
308
+ </flubit_orders_cancel_cron>
309
+ <flubit_orders_refund_cron>
310
+ <schedule>
311
+ <config_path>flubit_section/flubit_setup/order_refund_cron_settings</config_path>
312
+ </schedule>
313
+ <run>
314
+ <model>flubit/flubit::refundFlubitOrders</model>
315
+ </run>
316
+ </flubit_orders_refund_cron>
317
+ <flubit_update_price>
318
+ <schedule>
319
+ <cron_expr>*/3 * * * *</cron_expr>
320
+ </schedule>
321
+ <run>
322
+ <model>flubit/flubit::updateFlubitPrice</model>
323
+ </run>
324
+ </flubit_update_price>
325
+ <Flubit_flubit_archive>
326
+ <schedule>
327
+ <cron_expr>* */24 * * *</cron_expr>
328
+ </schedule>
329
+ <run>
330
+ <model>flubit/flubit::archiveLog</model>
331
+ </run>
332
+ </Flubit_flubit_archive>
333
+ <Flubit_flubit_globalupdate>
334
+ <schedule>
335
+ <cron_expr>*/4 * * * *</cron_expr>
336
+ </schedule>
337
+ <run>
338
+ <model>flubit/globalproduct::sendFlubitProductMassAttributeUpdate</model>
339
+ </run>
340
+ </Flubit_flubit_globalupdate>
341
+ </jobs>
342
+ </crontab>
343
+ </config>
app/code/community/Flubit/Flubit/etc/system.xml ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <flubit_tab translate="label" module="flubit">
5
+ <!--<label>flubit</label>-->
6
+ <label><![CDATA[<div style="position: absolute;"><img id="flubit_logo" src="" alt="" border="0" /></div>&nbsp;<script>$('flubit_logo').src = SKIN_URL + "images/flubit/logo.png";</script>]]></label>
7
+ <sort_order>0</sort_order>
8
+ </flubit_tab>
9
+ </tabs>
10
+ <sections>
11
+ <flubit_section translate="label" module="flubit">
12
+ <label>Flubit</label>
13
+ <tab>flubit_tab</tab>
14
+ <frontend_type>text</frontend_type>
15
+ <sort_order>0</sort_order>
16
+ <show_in_default>1</show_in_default>
17
+ <show_in_website>1</show_in_website>
18
+ <show_in_store>1</show_in_store>
19
+ <groups>
20
+ <flubit_configuration translate="label">
21
+ <label>Flubit Configuration</label>
22
+ <frontend_type>text</frontend_type>
23
+ <sort_order>1</sort_order>
24
+ <show_in_default>1</show_in_default>
25
+ <show_in_website>1</show_in_website>
26
+ <show_in_store>1</show_in_store>
27
+ <comment><![CDATA[<span style="color:#2a6994;">
28
+ <strong style="color:#00AEED;">Disclaimer:</strong><br/>
29
+ In order for the extension to run please ensure that Crons/Scheduled Tasks are set up and executing on your hosted environment.<br/><br/>
30
+ If not the following functionalities will be affected.<br/>
31
+ <ul>
32
+ <li>1. Product Creation and Updates to the Flubit Channel.</li>
33
+ <li>2. Fetching Orders from Flubit.</li>
34
+ <li>3. Order Status Updates being sent to Flubit.</li>
35
+
36
+ </ul><br/>
37
+ <span style="color:#000;">Fields with * are Mandatory.</span>
38
+ </span><br/>
39
+ <br/>
40
+ ]]></comment>
41
+ <fields>
42
+ <flubit_consumer_key translate="label">
43
+ <label>Consumer Key*</label>
44
+ <frontend_type>text</frontend_type>
45
+ <sort_order>1</sort_order>
46
+ <show_in_default>1</show_in_default>
47
+ <show_in_website>1</show_in_website>
48
+ <show_in_store>1</show_in_store>
49
+ <validate>required-entry</validate>
50
+ <comment>Please enter your personal consumer key provided by Flubit.</comment>
51
+ </flubit_consumer_key>
52
+ <flubit_secret translate="label">
53
+ <label>Secret*</label>
54
+ <frontend_type>text</frontend_type>
55
+ <sort_order>2</sort_order>
56
+ <show_in_default>1</show_in_default>
57
+ <show_in_website>1</show_in_website>
58
+ <show_in_store>1</show_in_store>
59
+ <validate>required-entry</validate>
60
+ <comment>Please enter your personal secret key provided by Flubit.</comment>
61
+ </flubit_secret>
62
+ <flubit_url translate="label">
63
+ <label>URL*</label>
64
+ <frontend_type>text</frontend_type>
65
+ <sort_order>3</sort_order>
66
+ <show_in_default>1</show_in_default>
67
+ <show_in_website>1</show_in_website>
68
+ <show_in_store>1</show_in_store>
69
+ <validate>required-entry</validate>
70
+ <comment>Please enter the API URL</comment>
71
+ </flubit_url>
72
+ <run translate="label">
73
+ <frontend_type>button</frontend_type>
74
+ <frontend_model>Flubit_Flubit_Block_Adminhtml_Button</frontend_model>
75
+ <sort_order>20</sort_order>
76
+ <show_in_default>1</show_in_default>
77
+ <show_in_website>1</show_in_website>
78
+ <show_in_store>1</show_in_store>
79
+ </run>
80
+ </fields>
81
+ </flubit_configuration>
82
+ <flubit_setup translate="label">
83
+ <label>Flubit Setup</label>
84
+ <frontend_type>text</frontend_type>
85
+ <sort_order>2</sort_order>
86
+ <show_in_default>1</show_in_default>
87
+ <show_in_website>1</show_in_website>
88
+ <show_in_store>1</show_in_store>
89
+ <fields>
90
+ <product_cron_settings translate="label">
91
+ <label>Product Update Frequency</label>
92
+ <frontend_type>select</frontend_type>
93
+ <source_model>flubit/flubit_source</source_model>
94
+ <sort_order>1</sort_order>
95
+ <show_in_default>1</show_in_default>
96
+ <show_in_website>1</show_in_website>
97
+ <show_in_store>1</show_in_store>
98
+ <comment>How often do you want the cron to run?</comment>
99
+ </product_cron_settings>
100
+ <order_cron_settings translate="label">
101
+ <label>Order Fetch Freqency</label>
102
+ <frontend_type>select</frontend_type>
103
+ <source_model>flubit/flubit_order</source_model>
104
+ <sort_order>2</sort_order>
105
+ <show_in_default>1</show_in_default>
106
+ <show_in_website>1</show_in_website>
107
+ <show_in_store>1</show_in_store>
108
+ <comment>How often do you want the cron to run?</comment>
109
+ </order_cron_settings>
110
+ <order_dispatch_cron_settings translate="label">
111
+ <label>Dispatch Order Freqency</label>
112
+ <frontend_type>select</frontend_type>
113
+ <source_model>flubit/flubit_rcd</source_model>
114
+ <sort_order>3</sort_order>
115
+ <show_in_default>1</show_in_default>
116
+ <show_in_website>1</show_in_website>
117
+ <show_in_store>1</show_in_store>
118
+ <comment>How often do you want the cron to run?</comment>
119
+ </order_dispatch_cron_settings>
120
+ <order_cancel_cron_settings translate="label">
121
+ <label>Cancel Order Freqency</label>
122
+ <frontend_type>select</frontend_type>
123
+ <source_model>flubit/flubit_rcd</source_model>
124
+ <sort_order>4</sort_order>
125
+ <show_in_default>1</show_in_default>
126
+ <show_in_website>1</show_in_website>
127
+ <show_in_store>1</show_in_store>
128
+ <comment>How often do you want the cron to run?</comment>
129
+ </order_cancel_cron_settings>
130
+ <order_refund_cron_settings translate="label">
131
+ <label>Refund Order Freqency</label>
132
+ <frontend_type>select</frontend_type>
133
+ <source_model>flubit/flubit_rcd</source_model>
134
+ <sort_order>5</sort_order>
135
+ <show_in_default>1</show_in_default>
136
+ <show_in_website>1</show_in_website>
137
+ <show_in_store>1</show_in_store>
138
+ <comment>How often do you want the cron to run?</comment>
139
+ </order_refund_cron_settings>
140
+ <flubit_chunk translate="label">
141
+ <label>Product Chunk Size</label>
142
+ <frontend_type>select</frontend_type>
143
+ <source_model>flubit/flubit_chunk</source_model>
144
+ <sort_order>9</sort_order>
145
+ <show_in_default>1</show_in_default>
146
+ <show_in_website>1</show_in_website>
147
+ <show_in_store>1</show_in_store>
148
+ <validate>required-entry validate-greater-than-zero</validate>
149
+ <comment>Please select the maximum number of records you would like to push per request.</comment>
150
+ </flubit_chunk>
151
+ <price_based_on translate="label">
152
+ <label>FBP based On:*</label>
153
+ <frontend_type>select</frontend_type>
154
+ <source_model>flubit/flubit_price</source_model>
155
+ <sort_order>10</sort_order>
156
+ <show_in_default>1</show_in_default>
157
+ <show_in_website>1</show_in_website>
158
+ <show_in_store>1</show_in_store>
159
+ <validate>required-entry</validate>
160
+ <comment></comment>
161
+ </price_based_on>
162
+ <global_price translate="label">
163
+ <label>Percentage Calculation:(%)*</label>
164
+ <frontend_type>text</frontend_type>
165
+ <sort_order>11</sort_order>
166
+ <show_in_default>1</show_in_default>
167
+ <show_in_website>1</show_in_website>
168
+ <show_in_store>1</show_in_store>
169
+ <validate>required-entry validate-greater-than-zero</validate>
170
+ <comment>The above two fields allow you to apply a global percentage discount or surcharge based on either store price, special price, cost price or RRP. </comment>
171
+ </global_price>
172
+ </fields>
173
+ </flubit_setup>
174
+ </groups>
175
+ </flubit_section>
176
+ </sections>
177
+ </config>
app/code/community/Flubit/Flubit/sql/flubit_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Script for update product in flubit
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Sql
8
+ * @author Flubit team
9
+ */
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+ $sql = <<<SQLTEXT
13
+ create table {$this->getTable('flubit/flubit')}(flubit_id int not null auto_increment, name varchar(100), sku varchar(255) not null, price varchar(255) not null, qty int not null, primary key(flubit_id));
14
+
15
+ SQLTEXT;
16
+
17
+ $installer->run($sql);
18
+ //demo
19
+ //Mage::getModel('core/url_rewrite')->setId(null);
20
+ //demo
21
+ $installer->endSetup();
22
+
app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.1.0-0.1.1.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Script for update product Catalog
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Sql
8
+ * @author Flubit team
9
+ */
10
+ $this->startSetup();
11
+
12
+ /* @var $installer Mage_Catalog_Model_Resource_Eav_Mysql4_Setup */
13
+ $installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
14
+
15
+ if (!$installer->getAttributeId(Mage_Catalog_Model_Product::ENTITY, 'flubit_ean')) {
16
+ $installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'flubit_ean', array( // TABLE.COLUMN: DESCRIPTION:
17
+ 'label' => 'EAN', // eav_attribute.frontend_label admin input label
18
+ 'group' => 'Flubit', // (not a column) tab in product edit screen
19
+ 'sort_order' => 0, // eav_entity_attribute.sort_order sort order in group
20
+ 'type' => 'varchar', // eav_attribute.backend_type backend storage type (varchar, text etc)
21
+ 'input' => 'text', // eav_attribute.frontend_input admin input type (select, text, textarea etc)
22
+ 'required' => false, // eav_attribute.is_required required in admin
23
+ 'user_defined' => true, // eav_attribute.is_user_defined editable in admin attributes section, false for not
24
+ 'unique' => false, // eav_attribute.is_unique unique value required
25
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, // catalog_eav_attribute.is_global (products only) scope
26
+ 'visible' => true, // catalog_eav_attribute.is_visible (products only) visible on admin
27
+ 'visible_on_front' => false, // catalog_eav_attribute.is_visible_on_front (products only) visible on frontend (store) attribute table
28
+ 'used_in_product_listing' => true, // catalog_eav_attribute.used_in_product_listing (products only) made available in product listing
29
+ 'searchable' => true, // catalog_eav_attribute.is_searchable (products only) searchable via basic search
30
+ 'visible_in_advanced_search' => true, // catalog_eav_attribute.is_visible_in_advanced_search (products only) searchable via advanced search
31
+ 'filterable' => false, // catalog_eav_attribute.is_filterable (products only) use in layered nav
32
+ 'filterable_in_search' => false, // catalog_eav_attribute.is_filterable_in_search (products only) use in search results layered nav
33
+ 'comparable' => false, // catalog_eav_attribute.is_comparable (products only) comparable on frontend
34
+ 'is_html_allowed_on_front' => false, // catalog_eav_attribute.is_visible_on_front (products only) seems obvious, but also see visible
35
+ 'apply_to' => 'simple,configurable', // catalog_eav_attribute.apply_to (products only) which product types to apply to
36
+ 'is_configurable' => false, // catalog_eav_attribute.is_configurable (products only) used for configurable products or not
37
+ 'used_for_sort_by' => false, // catalog_eav_attribute.used_for_sort_by (products only) available in the 'sort by' menu
38
+ 'position' => 0, // catalog_eav_attribute.position (products only) position in layered naviagtion
39
+ 'used_for_promo_rules' => false, // catalog_eav_attribute.is_used_for_promo_rules (products only) available for use in promo rules
40
+ ));
41
+ }
42
+ if (!$installer->getAttributeId(Mage_Catalog_Model_Product::ENTITY, 'flubit_asin')) {
43
+ $installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'flubit_asin', array( // TABLE.COLUMN: DESCRIPTION:
44
+ 'label' => 'ASIN', // eav_attribute.frontend_label admin input label
45
+ 'group' => 'Flubit', // (not a column) tab in product edit screen
46
+ 'sort_order' => 1, // eav_entity_attribute.sort_order sort order in group
47
+ 'type' => 'varchar', // eav_attribute.backend_type backend storage type (varchar, text etc)
48
+ 'input' => 'text', // eav_attribute.frontend_input admin input type (select, text, textarea etc)
49
+ 'required' => false, // eav_attribute.is_required required in admin
50
+ 'user_defined' => true, // eav_attribute.is_user_defined editable in admin attributes section, false for not
51
+ 'unique' => false, // eav_attribute.is_unique unique value required
52
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, // catalog_eav_attribute.is_global (products only) scope
53
+ 'visible' => true, // catalog_eav_attribute.is_visible (products only) visible on admin
54
+ 'visible_on_front' => false, // catalog_eav_attribute.is_visible_on_front (products only) visible on frontend (store) attribute table
55
+ 'used_in_product_listing' => true, // catalog_eav_attribute.used_in_product_listing (products only) made available in product listing
56
+ 'searchable' => true, // catalog_eav_attribute.is_searchable (products only) searchable via basic search
57
+ 'visible_in_advanced_search' => true, // catalog_eav_attribute.is_visible_in_advanced_search (products only) searchable via advanced search
58
+ 'filterable' => false, // catalog_eav_attribute.is_filterable (products only) use in layered nav
59
+ 'filterable_in_search' => false, // catalog_eav_attribute.is_filterable_in_search (products only) use in search results layered nav
60
+ 'comparable' => false, // catalog_eav_attribute.is_comparable (products only) comparable on frontend
61
+ 'is_html_allowed_on_front' => false, // catalog_eav_attribute.is_visible_on_front (products only) seems obvious, but also see visible
62
+ 'apply_to' => 'simple,configurable', // catalog_eav_attribute.apply_to (products only) which product types to apply to
63
+ 'is_configurable' => false, // catalog_eav_attribute.is_configurable (products only) used for configurable products or not
64
+ 'used_for_sort_by' => false, // catalog_eav_attribute.used_for_sort_by (products only) available in the 'sort by' menu
65
+ 'position' => 1, // catalog_eav_attribute.position (products only) position in layered naviagtion
66
+ 'used_for_promo_rules' => false, // catalog_eav_attribute.is_used_for_promo_rules (products only) available for use in promo rules
67
+ ));
68
+ }
69
+ if (!$installer->getAttributeId(Mage_Catalog_Model_Product::ENTITY, 'flubit_isbn')) {
70
+ $installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'flubit_isbn', array( // TABLE.COLUMN: DESCRIPTION:
71
+ 'label' => 'ISBN', // eav_attribute.frontend_label admin input label
72
+ 'group' => 'Flubit', // (not a column) tab in product edit screen
73
+ 'sort_order' => 2, // eav_entity_attribute.sort_order sort order in group
74
+ 'type' => 'varchar', // eav_attribute.backend_type backend storage type (varchar, text etc)
75
+ 'input' => 'text', // eav_attribute.frontend_input admin input type (select, text, textarea etc)
76
+ 'required' => false, // eav_attribute.is_required required in admin
77
+ 'user_defined' => true, // eav_attribute.is_user_defined editable in admin attributes section, false for not
78
+ 'unique' => false, // eav_attribute.is_unique unique value required
79
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, // catalog_eav_attribute.is_global (products only) scope
80
+ 'visible' => true, // catalog_eav_attribute.is_visible (products only) visible on admin
81
+ 'visible_on_front' => false, // catalog_eav_attribute.is_visible_on_front (products only) visible on frontend (store) attribute table
82
+ 'used_in_product_listing' => true, // catalog_eav_attribute.used_in_product_listing (products only) made available in product listing
83
+ 'searchable' => true, // catalog_eav_attribute.is_searchable (products only) searchable via basic search
84
+ 'visible_in_advanced_search' => true, // catalog_eav_attribute.is_visible_in_advanced_search (products only) searchable via advanced search
85
+ 'filterable' => false, // catalog_eav_attribute.is_filterable (products only) use in layered nav
86
+ 'filterable_in_search' => false, // catalog_eav_attribute.is_filterable_in_search (products only) use in search results layered nav
87
+ 'comparable' => false, // catalog_eav_attribute.is_comparable (products only) comparable on frontend
88
+ 'is_html_allowed_on_front' => false, // catalog_eav_attribute.is_visible_on_front (products only) seems obvious, but also see visible
89
+ 'apply_to' => 'simple,configurable', // catalog_eav_attribute.apply_to (products only) which product types to apply to
90
+ 'is_configurable' => false, // catalog_eav_attribute.is_configurable (products only) used for configurable products or not
91
+ 'used_for_sort_by' => false, // catalog_eav_attribute.used_for_sort_by (products only) available in the 'sort by' menu
92
+ 'position' => 2, // catalog_eav_attribute.position (products only) position in layered naviagtion
93
+ 'used_for_promo_rules' => false, // catalog_eav_attribute.is_used_for_promo_rules (products only) available for use in promo rules
94
+ ));
95
+ }
96
+ if (!$installer->getAttributeId(Mage_Catalog_Model_Product::ENTITY, 'flubit_mpn')) {
97
+ $installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'flubit_mpn', array( // TABLE.COLUMN: DESCRIPTION:
98
+ 'label' => 'MPN', // eav_attribute.frontend_label admin input label
99
+ 'group' => 'Flubit', // (not a column) tab in product edit screen
100
+ 'sort_order' => 3, // eav_entity_attribute.sort_order sort order in group
101
+ 'type' => 'varchar', // eav_attribute.backend_type backend storage type (varchar, text etc)
102
+ 'input' => 'text', // eav_attribute.frontend_input admin input type (select, text, textarea etc)
103
+ 'required' => false, // eav_attribute.is_required required in admin
104
+ 'user_defined' => true, // eav_attribute.is_user_defined editable in admin attributes section, false for not
105
+ 'unique' => false, // eav_attribute.is_unique unique value required
106
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, // catalog_eav_attribute.is_global (products only) scope
107
+ 'visible' => true, // catalog_eav_attribute.is_visible (products only) visible on admin
108
+ 'visible_on_front' => false, // catalog_eav_attribute.is_visible_on_front (products only) visible on frontend (store) attribute table
109
+ 'used_in_product_listing' => true, // catalog_eav_attribute.used_in_product_listing (products only) made available in product listing
110
+ 'searchable' => true, // catalog_eav_attribute.is_searchable (products only) searchable via basic search
111
+ 'visible_in_advanced_search' => true, // catalog_eav_attribute.is_visible_in_advanced_search (products only) searchable via advanced search
112
+ 'filterable' => false, // catalog_eav_attribute.is_filterable (products only) use in layered nav
113
+ 'filterable_in_search' => false, // catalog_eav_attribute.is_filterable_in_search (products only) use in search results layered nav
114
+ 'comparable' => false, // catalog_eav_attribute.is_comparable (products only) comparable on frontend
115
+ 'is_html_allowed_on_front' => false, // catalog_eav_attribute.is_visible_on_front (products only) seems obvious, but also see visible
116
+ 'apply_to' => 'simple,configurable', // catalog_eav_attribute.apply_to (products only) which product types to apply to
117
+ 'is_configurable' => false, // catalog_eav_attribute.is_configurable (products only) used for configurable products or not
118
+ 'used_for_sort_by' => false, // catalog_eav_attribute.used_for_sort_by (products only) available in the 'sort by' menu
119
+ 'position' => 3, // catalog_eav_attribute.position (products only) position in layered naviagtion
120
+ 'used_for_promo_rules' => false, // catalog_eav_attribute.is_used_for_promo_rules (products only) available for use in promo rules
121
+ ));
122
+ }
app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.1.1-0.1.2.php ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Script for update product Delivery Standard, Express
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Sql
8
+ * @author Flubit team
9
+ */
10
+ $this->startSetup();
11
+
12
+ /* @var $installer Mage_Catalog_Model_Resource_Eav_Mysql4_Setup */
13
+ $installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
14
+
15
+ if (!$installer->getAttributeId(Mage_Catalog_Model_Product::ENTITY, 'flubit_brand')) {
16
+ $installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'flubit_brand', array( // TABLE.COLUMN: DESCRIPTION:
17
+ 'label' => 'Brand', // eav_attribute.frontend_label admin input label
18
+ 'group' => 'Flubit', // (not a column) tab in product edit screen
19
+ 'sort_order' => 4, // eav_entity_attribute.sort_order sort order in group
20
+ 'type' => 'varchar', // eav_attribute.backend_type backend storage type (varchar, text etc)
21
+ 'input' => 'text', // eav_attribute.frontend_input admin input type (select, text, textarea etc)
22
+ 'required' => false, // eav_attribute.is_required required in admin
23
+ 'user_defined' => true, // eav_attribute.is_user_defined editable in admin attributes section, false for not
24
+ 'unique' => false, // eav_attribute.is_unique unique value required
25
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, // catalog_eav_attribute.is_global (products only) scope
26
+ 'visible' => true, // catalog_eav_attribute.is_visible (products only) visible on admin
27
+ 'visible_on_front' => false, // catalog_eav_attribute.is_visible_on_front (products only) visible on frontend (store) attribute table
28
+ 'used_in_product_listing' => true, // catalog_eav_attribute.used_in_product_listing (products only) made available in product listing
29
+ 'searchable' => true, // catalog_eav_attribute.is_searchable (products only) searchable via basic search
30
+ 'visible_in_advanced_search' => true, // catalog_eav_attribute.is_visible_in_advanced_search (products only) searchable via advanced search
31
+ 'filterable' => false, // catalog_eav_attribute.is_filterable (products only) use in layered nav
32
+ 'filterable_in_search' => false, // catalog_eav_attribute.is_filterable_in_search (products only) use in search results layered nav
33
+ 'comparable' => false, // catalog_eav_attribute.is_comparable (products only) comparable on frontend
34
+ 'is_html_allowed_on_front' => false, // catalog_eav_attribute.is_visible_on_front (products only) seems obvious, but also see visible
35
+ 'apply_to' => 'simple,configurable', // catalog_eav_attribute.apply_to (products only) which product types to apply to
36
+ 'is_configurable' => false, // catalog_eav_attribute.is_configurable (products only) used for configurable products or not
37
+ 'used_for_sort_by' => false, // catalog_eav_attribute.used_for_sort_by (products only) available in the 'sort by' menu
38
+ 'position' => 4, // catalog_eav_attribute.position (products only) position in layered naviagtion
39
+ 'used_for_promo_rules' => false, // catalog_eav_attribute.is_used_for_promo_rules (products only) available for use in promo rules
40
+ ));
41
+ }
42
+ if (!$installer->getAttributeId(Mage_Catalog_Model_Product::ENTITY, 'flubit_standard_delivery')) {
43
+ $installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'flubit_standard_delivery', array( // TABLE.COLUMN: DESCRIPTION:
44
+ 'label' => 'Standard Delivery', // eav_attribute.frontend_label admin input label
45
+ 'group' => 'Flubit', // (not a column) tab in product edit screen
46
+ 'sort_order' => 5, // eav_entity_attribute.sort_order sort order in group
47
+ 'type' => 'varchar', // eav_attribute.backend_type backend storage type (varchar, text etc)
48
+ 'input' => 'text', // eav_attribute.frontend_input admin input type (select, text, textarea etc)
49
+ 'required' => false, // eav_attribute.is_required required in admin
50
+ 'user_defined' => true, // eav_attribute.is_user_defined editable in admin attributes section, false for not
51
+ 'unique' => false, // eav_attribute.is_unique unique value required
52
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, // catalog_eav_attribute.is_global (products only) scope
53
+ 'visible' => true, // catalog_eav_attribute.is_visible (products only) visible on admin
54
+ 'visible_on_front' => false, // catalog_eav_attribute.is_visible_on_front (products only) visible on frontend (store) attribute table
55
+ 'used_in_product_listing' => true, // catalog_eav_attribute.used_in_product_listing (products only) made available in product listing
56
+ 'searchable' => true, // catalog_eav_attribute.is_searchable (products only) searchable via basic search
57
+ 'visible_in_advanced_search' => true, // catalog_eav_attribute.is_visible_in_advanced_search (products only) searchable via advanced search
58
+ 'filterable' => false, // catalog_eav_attribute.is_filterable (products only) use in layered nav
59
+ 'filterable_in_search' => false, // catalog_eav_attribute.is_filterable_in_search (products only) use in search results layered nav
60
+ 'comparable' => false, // catalog_eav_attribute.is_comparable (products only) comparable on frontend
61
+ 'is_html_allowed_on_front' => false, // catalog_eav_attribute.is_visible_on_front (products only) seems obvious, but also see visible
62
+ 'apply_to' => 'simple,configurable', // catalog_eav_attribute.apply_to (products only) which product types to apply to
63
+ 'is_configurable' => false, // catalog_eav_attribute.is_configurable (products only) used for configurable products or not
64
+ 'used_for_sort_by' => false, // catalog_eav_attribute.used_for_sort_by (products only) available in the 'sort by' menu
65
+ 'position' => 5, // catalog_eav_attribute.position (products only) position in layered naviagtion
66
+ 'used_for_promo_rules' => false, // catalog_eav_attribute.is_used_for_promo_rules (products only) available for use in promo rules
67
+ ));
68
+ }
69
+ if (!$installer->getAttributeId(Mage_Catalog_Model_Product::ENTITY, 'flubit_express_delivery')) {
70
+ $installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'flubit_express_delivery', array( // TABLE.COLUMN: DESCRIPTION:
71
+ 'label' => 'Express Delivery', // eav_attribute.frontend_label admin input label
72
+ 'group' => 'Flubit', // (not a column) tab in product edit screen
73
+ 'sort_order' => 6, // eav_entity_attribute.sort_order sort order in group
74
+ 'type' => 'varchar', // eav_attribute.backend_type backend storage type (varchar, text etc)
75
+ 'input' => 'text', // eav_attribute.frontend_input admin input type (select, text, textarea etc)
76
+ 'required' => false, // eav_attribute.is_required required in admin
77
+ 'user_defined' => true, // eav_attribute.is_user_defined editable in admin attributes section, false for not
78
+ 'unique' => false, // eav_attribute.is_unique unique value required
79
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, // catalog_eav_attribute.is_global (products only) scope
80
+ 'visible' => true, // catalog_eav_attribute.is_visible (products only) visible on admin
81
+ 'visible_on_front' => false, // catalog_eav_attribute.is_visible_on_front (products only) visible on frontend (store) attribute table
82
+ 'used_in_product_listing' => true, // catalog_eav_attribute.used_in_product_listing (products only) made available in product listing
83
+ 'searchable' => true, // catalog_eav_attribute.is_searchable (products only) searchable via basic search
84
+ 'visible_in_advanced_search' => true, // catalog_eav_attribute.is_visible_in_advanced_search (products only) searchable via advanced search
85
+ 'filterable' => false, // catalog_eav_attribute.is_filterable (products only) use in layered nav
86
+ 'filterable_in_search' => false, // catalog_eav_attribute.is_filterable_in_search (products only) use in search results layered nav
87
+ 'comparable' => false, // catalog_eav_attribute.is_comparable (products only) comparable on frontend
88
+ 'is_html_allowed_on_front' => false, // catalog_eav_attribute.is_visible_on_front (products only) seems obvious, but also see visible
89
+ 'apply_to' => 'simple,configurable', // catalog_eav_attribute.apply_to (products only) which product types to apply to
90
+ 'is_configurable' => false, // catalog_eav_attribute.is_configurable (products only) used for configurable products or not
91
+ 'used_for_sort_by' => false, // catalog_eav_attribute.used_for_sort_by (products only) available in the 'sort by' menu
92
+ 'position' => 6, // catalog_eav_attribute.position (products only) position in layered naviagtion
93
+ 'used_for_promo_rules' => false, // catalog_eav_attribute.is_used_for_promo_rules (products only) available for use in promo rules
94
+ ));
95
+ }
96
+ if (!$installer->getAttributeId(Mage_Catalog_Model_Product::ENTITY, 'flubit_base_price')) {
97
+ $installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'flubit_base_price', array( // TABLE.COLUMN: DESCRIPTION:
98
+ 'label' => 'Flubit Base Price', // eav_attribute.frontend_label admin input label
99
+ 'group' => 'Flubit', // (not a column) tab in product edit screen
100
+ 'sort_order' => 7, // eav_entity_attribute.sort_order sort order in group
101
+ 'type' => 'varchar', // eav_attribute.backend_type backend storage type (varchar, text etc)
102
+ 'input' => 'text', // eav_attribute.frontend_input admin input type (select, text, textarea etc)
103
+ 'required' => false, // eav_attribute.is_required required in admin
104
+ 'user_defined' => true, // eav_attribute.is_user_defined editable in admin attributes section, false for not
105
+ 'unique' => false, // eav_attribute.is_unique unique value required
106
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, // catalog_eav_attribute.is_global (products only) scope
107
+ 'visible' => true, // catalog_eav_attribute.is_visible (products only) visible on admin
108
+ 'visible_on_front' => false, // catalog_eav_attribute.is_visible_on_front (products only) visible on frontend (store) attribute table
109
+ 'used_in_product_listing' => true, // catalog_eav_attribute.used_in_product_listing (products only) made available in product listing
110
+ 'searchable' => true, // catalog_eav_attribute.is_searchable (products only) searchable via basic search
111
+ 'visible_in_advanced_search' => true, // catalog_eav_attribute.is_visible_in_advanced_search (products only) searchable via advanced search
112
+ 'filterable' => false, // catalog_eav_attribute.is_filterable (products only) use in layered nav
113
+ 'filterable_in_search' => false, // catalog_eav_attribute.is_filterable_in_search (products only) use in search results layered nav
114
+ 'comparable' => false, // catalog_eav_attribute.is_comparable (products only) comparable on frontend
115
+ 'is_html_allowed_on_front' => false, // catalog_eav_attribute.is_visible_on_front (products only) seems obvious, but also see visible
116
+ 'apply_to' => 'simple,configurable', // catalog_eav_attribute.apply_to (products only) which product types to apply to
117
+ 'is_configurable' => false, // catalog_eav_attribute.is_configurable (products only) used for configurable products or not
118
+ 'used_for_sort_by' => false, // catalog_eav_attribute.used_for_sort_by (products only) available in the 'sort by' menu
119
+ 'position' => 7, // catalog_eav_attribute.position (products only) position in layered naviagtion
120
+ 'used_for_promo_rules' => false, // catalog_eav_attribute.is_used_for_promo_rules (products only) available for use in promo rules
121
+ ));
122
+ }
123
+ if (!$installer->getAttributeId(Mage_Catalog_Model_Product::ENTITY, 'flubit_product')) {
124
+ $installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'flubit_product', array(
125
+ 'label' => 'Flubit Product',
126
+ 'group' => 'General',
127
+ 'sort_order' => 99,
128
+ 'type' => 'int',
129
+ 'input' => 'boolean',
130
+ 'source' => 'eav/entity_attribute_source_table',
131
+ 'required' => false,
132
+ 'user_defined' => true,
133
+ 'unique' => false,
134
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
135
+ 'visible' => true,
136
+ 'visible_on_front' => false,
137
+ 'used_in_product_listing' => true,
138
+ 'searchable' => false,
139
+ 'visible_in_advanced_search' => false,
140
+ 'filterable' => false,
141
+ 'filterable_in_search' => false,
142
+ 'comparable' => false,
143
+ 'is_html_allowed_on_front' => false,
144
+ 'apply_to' => 'simple,configurable',
145
+ 'is_configurable' => false,
146
+ 'used_for_sort_by' => false,
147
+ 'position' => 99,
148
+ 'used_for_promo_rules' => false,
149
+ ));
150
+ }
app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.1.2-0.1.3.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Script for Create Flubit feeds log
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Sql
8
+ * @author Flubit team
9
+ */
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+ $sql=<<<SQLTEXT
13
+ create table {$this->getTable('flubit/logs')}(flubit_id int not null auto_increment, feed_id varchar(100), feed_type varchar(50) not null, status int(11) not null, created_at DATETIME DEFAULT NULL, primary key(flubit_id));
14
+
15
+ SQLTEXT;
16
+
17
+ $installer->run($sql);
18
+ //demo
19
+ //Mage::getModel('core/url_rewrite')->setId(null);
20
+ //demo
21
+ $installer->endSetup();
22
+
app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.1.3-0.1.4.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Script for Create Flubit feeds log
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Sql
8
+ * @author Flubit team
9
+ */
10
+ $this->startSetup();
11
+
12
+ /* @var $installer Mage_Catalog_Model_Resource_Eav_Mysql4_Setup */
13
+ $installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
14
+
15
+ if (!$installer->getAttributeId(Mage_Catalog_Model_Product::ENTITY, 'flubit_product')) {
16
+ $installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'flubit_product', array(
17
+ 'label' => 'Flubit Product',
18
+ 'group' => 'General',
19
+ 'sort_order' => 99,
20
+ 'type' => 'int',
21
+ 'input' => 'boolean',
22
+ 'source' => 'eav/entity_attribute_source_table',
23
+ 'required' => false,
24
+ 'user_defined' => true,
25
+ 'unique' => false,
26
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
27
+ 'visible' => true,
28
+ 'visible_on_front' => false,
29
+ 'used_in_product_listing' => true,
30
+ 'searchable' => false,
31
+ 'visible_in_advanced_search' => false,
32
+ 'filterable' => false,
33
+ 'filterable_in_search' => false,
34
+ 'comparable' => false,
35
+ 'is_html_allowed_on_front' => false,
36
+ 'apply_to' => 'simple,configurable',
37
+ 'is_configurable' => false,
38
+ 'used_for_sort_by' => false,
39
+ 'position' => 99,
40
+ 'used_for_promo_rules' => false,
41
+ ));
42
+ }
app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.1.4-0.1.5.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Script for Flubit Product Update
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Sql
8
+ * @author Flubit team
9
+ */
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+ $sql=<<<SQLTEXT
13
+ alter table {$this->getTable('flubit/flubit')} add column status varchar(50) null after qty;
14
+
15
+ SQLTEXT;
16
+
17
+ $installer->run($sql);
18
+ $installer->endSetup();
19
+
app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.1.5-0.1.6.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Script for Alter Flubit Table Column
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Sql
8
+ * @author Flubit team
9
+ */
10
+ $installer = $this;
11
+ /* @var $installer Mage_Sales_Model_Mysql4_Setup */
12
+
13
+ $installer->startSetup();
14
+
15
+ $resource = Mage::getResourceModel('sales/order_collection');
16
+ if(!method_exists($resource, 'getEntity')) {
17
+ $table = $this->getTable('sales/order');
18
+ $query = 'ALTER TABLE `' . $table . '` ADD COLUMN `flubit_order_id` varchar(50) DEFAULT NULL';
19
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
20
+ $connection->query($query);
21
+
22
+ } else {
23
+
24
+ // Get ID of the entity model 'sales/order'.
25
+ $sql = 'SELECT entity_type_id FROM '.$this->getTable('eav/entity_type').' WHERE entity_type_code="order"';
26
+ $row = Mage::getSingleton('core/resource')
27
+ ->getConnection('core_read')
28
+ ->fetchRow($sql);
29
+
30
+ // Create EAV-attribute for the order comment.
31
+ $c = array (
32
+ 'entity_type_id' => $row['entity_type_id'],
33
+ 'attribute_code' => 'flubit_order_id',
34
+ 'backend_type' => 'varchar', // MySQL-Datatype
35
+ 'frontend_input' => 'text', // Type of the HTML form element
36
+ 'is_global' => '1',
37
+ 'is_visible' => '1',
38
+ 'is_required' => '0',
39
+ 'is_user_defined' => '0',
40
+ 'frontend_label' => 'Flubit Order ID',
41
+ );
42
+ $attribute = new Mage_Eav_Model_Entity_Attribute();
43
+ $attribute->loadByCode($c['entity_type_id'], $c['attribute_code'])
44
+ ->setStoreId(0)
45
+ ->addData($c);
46
+ $attribute->save();
47
+
48
+ }
49
+
50
+ $installer->endSetup();
app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.1.6-0.1.7.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Script for Create Flubit Order
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Sql
8
+ * @author Flubit team
9
+ */
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+ $sql = <<<SQLTEXT
13
+ create table {$this->getTable('flubit/order')}(flubit_id int not null auto_increment, order_no varchar(20) null, flubit_order_id varchar(20) null, status varchar(20) null, primary key(flubit_id));
14
+
15
+ SQLTEXT;
16
+
17
+ $installer->run($sql);
18
+ //demo
19
+ //Mage::getModel('core/url_rewrite')->setId(null);
20
+ //demo
21
+ $installer->endSetup();
22
+
app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.1.7-0.1.8.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Script for Alter Flubit product update add new column
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Sql
8
+ * @author Flubit team
9
+ */
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+ $sql = <<<SQLTEXT
13
+ alter table {$this->getTable('flubit/flubit')} add column new char(5) null after status;
14
+
15
+ SQLTEXT;
16
+
17
+ $installer->run($sql);
18
+ $installer->endSetup();
app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.1.8-0.1.9.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Script for Alter Flubit product update add Global Price
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Sql
8
+ * @author Flubit team
9
+ */
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+ $sql = <<<SQLTEXT
13
+ alter table {$this->getTable('flubit/flubit')} add column use_global_price char(1) null DEFAULT 0 after status ;
14
+
15
+ SQLTEXT;
16
+
17
+ $installer->run($sql);
18
+ $installer->endSetup();
app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.1.9-0.2.0.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Script for Alter Flubit product Column isdeleted or not
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Sql
8
+ * @author Flubit team
9
+ */
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+ $sql = <<<SQLTEXT
13
+ alter table {$this->getTable('flubit/flubit')} add column is_deleted tinyint(1) not null DEFAULT 0 after status ;
14
+
15
+ SQLTEXT;
16
+
17
+ $installer->run($sql);
18
+ $installer->endSetup();
app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.2.0-0.2.1.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Script for Alter Flubit product Column acrtive status or not
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Sql
8
+ * @author Flubit team
9
+ */
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+ $sql = <<<SQLTEXT
13
+ alter table {$installer->getTable('flubit/flubit')} add column active_status tinyint(1) not null DEFAULT 1 after new ;
14
+
15
+ SQLTEXT;
16
+
17
+ $installer->run($sql);
18
+ $installer->endSetup();
app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.2.1-0.2.2.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Script for Alter Flubit product Column acrtive status or not
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Sql
8
+ * @author Flubit team
9
+ */
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+ $sql = <<<SQLTEXT
13
+ CREATE TABLE {$installer->getTable('flubit/ordertime')} (
14
+ `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
15
+ `date_time` DATETIME NOT NULL,
16
+ `fetched_orders` INTEGER UNSIGNED NOT NULL DEFAULT 0,
17
+ PRIMARY KEY (`id`)
18
+ );
19
+
20
+ SQLTEXT;
21
+
22
+ $installer->run($sql);
23
+ $installer->endSetup();
app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.2.2-0.2.3.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Script for Alter Flubit Table Column
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Sql
8
+ * @author Flubit team
9
+ */
10
+ $installer = $this;
11
+ /* @var $installer Mage_Sales_Model_Mysql4_Setup */
12
+
13
+ $installer->startSetup();
14
+
15
+ $resource = Mage::getResourceModel('sales/order_collection');
16
+ if(!method_exists($resource, 'getEntity')) {
17
+ $table = $this->getTable('sales/order');
18
+ $query = 'ALTER TABLE `' . $table . '` ADD COLUMN `flubit_order_tax_rate` varchar(50) DEFAULT NULL';
19
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
20
+ $connection->query($query);
21
+
22
+ } else {
23
+
24
+ // Get ID of the entity model 'sales/order'.
25
+ $sql = 'SELECT entity_type_id FROM '.$this->getTable('eav/entity_type').' WHERE entity_type_code="order"';
26
+ $row = Mage::getSingleton('core/resource')
27
+ ->getConnection('core_read')
28
+ ->fetchRow($sql);
29
+
30
+ // Create EAV-attribute for the order comment.
31
+ $c = array (
32
+ 'entity_type_id' => $row['entity_type_id'],
33
+ 'attribute_code' => 'flubit_order_tax_rate',
34
+ 'backend_type' => 'varchar', // MySQL-Datatype
35
+ 'frontend_input' => 'text', // Type of the HTML form element
36
+ 'is_global' => '1',
37
+ 'is_visible' => '1',
38
+ 'is_required' => '0',
39
+ 'is_user_defined' => '0',
40
+ 'frontend_label' => 'Flubit Order Tax Rate',
41
+ );
42
+ $attribute = new Mage_Eav_Model_Entity_Attribute();
43
+ $attribute->loadByCode($c['entity_type_id'], $c['attribute_code'])
44
+ ->setStoreId(0)
45
+ ->addData($c);
46
+ $attribute->save();
47
+
48
+ }
49
+ $installer->endSetup();
app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.2.3-0.2.4.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Script for Alter Flubit product Column acrtive status or not
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Sql
8
+ * @author Flubit team
9
+ */
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+
13
+
14
+ $installer->run("
15
+
16
+ ALTER TABLE {$installer->getTable('flubit/order')} ADD (`dispatch` tinyint ( 4 ) NOT NULL default '0',`refund` tinyint ( 4 ) NOT NULL default '0');
17
+
18
+ ");
19
+
20
+ $installer->endSetup();
app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.2.4-0.2.5.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Script for Alter Flubit product Column acrtive status or not
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Sql
8
+ * @author Flubit team
9
+ */
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+
13
+
14
+ $installer->run("
15
+
16
+ ALTER TABLE {$installer->getTable('flubit/flubit')} ADD (`global_price_update` tinyint ( 4 ) NOT NULL default '0');
17
+
18
+ ");
19
+
20
+ $installer->endSetup();
app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.2.5-0.2.6.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Script for Create Flubit Order
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Sql
8
+ * @author Flubit team
9
+ */
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+ $sql = <<<SQLTEXT
13
+ create table {$this->getTable('flubit/globalproduct')}(id int not null auto_increment, product_id int(20) not null, created_at DATETIME DEFAULT NULL, flubit_status int(11) not null, update_status int(11) not null, primary key(id));
14
+
15
+ SQLTEXT;
16
+
17
+ $installer->run($sql);
18
+ //demo
19
+ //Mage::getModel('core/url_rewrite')->setId(null);
20
+ //demo
21
+ $installer->endSetup();
22
+
app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.2.6-0.2.7.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Script for Create Flubit feeds log
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Sql
8
+ * @author Flubit team
9
+ */
10
+ $this->startSetup();
11
+
12
+ /* @var $installer Mage_Catalog_Model_Resource_Eav_Mysql4_Setup */
13
+ $installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
14
+
15
+ if ($installer->getAttributeId(Mage_Catalog_Model_Product::ENTITY, 'flubit_product')) {
16
+ $installer->updateAttribute(Mage_Catalog_Model_Product::ENTITY, 'flubit_product', array(
17
+ 'label' => 'Flubit Product',
18
+ 'group' => 'General',
19
+ 'sort_order' => 99,
20
+ 'type' => 'int',
21
+ 'input' => 'boolean',
22
+ 'source' => 'eav/entity_attribute_source_table',
23
+ 'required' => false,
24
+ 'user_defined' => true,
25
+ 'unique' => false,
26
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
27
+ 'visible' => true,
28
+ 'visible_on_front' => false,
29
+ 'used_in_product_listing' => true,
30
+ 'searchable' => false,
31
+ 'visible_in_advanced_search' => false,
32
+ 'filterable' => false,
33
+ 'filterable_in_search' => false,
34
+ 'comparable' => false,
35
+ 'is_html_allowed_on_front' => false,
36
+ 'apply_to' => 'simple',
37
+ 'is_configurable' => false,
38
+ 'used_for_sort_by' => false,
39
+ 'position' => 99,
40
+ 'used_for_promo_rules' => false,
41
+ ));
42
+ }
app/code/community/Flubit/Flubit/sql/flubit_setup/upgrade-0.2.7-0.2.8.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Script for Create Flubit feeds log
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Sql
8
+ * @author Flubit team
9
+ */
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+
13
+ $installer->run(
14
+ "DELETE FROM {$installer->getTable('flubit/order')} where refund=1;"
15
+ );
16
+ $installer->run(
17
+ "TRUNCATE TABLE {$installer->getTable('flubit/logs')} "
18
+ );
19
+
20
+ $installer->endSetup();
app/code/community/Flubit/Flubitlog/Block/Adminhtml/Flubitlog.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubitlog Block Admin Flubitlog
5
+ *
6
+ * @package Flubit
7
+ * @category Flubitlog_Block
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubitlog_Block_Adminhtml_Flubitlog extends Mage_Adminhtml_Block_Widget_Grid_Container {
11
+
12
+ public function __construct() {
13
+
14
+ $flubit_log = Mage::getModel('flubitlog/flubitlog')->getCollection()->getSize();
15
+ if($flubit_log > 0)
16
+ $DisplayString = 'Please note the logs are only available for last 30 days';
17
+ else
18
+ $DisplayString = 'There are no logs at this time';
19
+
20
+ $this->_controller = 'adminhtml_flubitlog';
21
+ $this->_blockGroup = 'flubitlog';
22
+ $this->_headerText = Mage::helper('flubitlog')->__('<span style="font-size:14px; font-weight:bold; color:#00AEED;">' . $DisplayString . '</span>');
23
+ $this->_addButtonLabel = Mage::helper('flubitlog')->__('Add Item');
24
+ parent::__construct();
25
+ $this->_removeButton('add');
26
+ }
27
+
28
+ }
app/code/community/Flubit/Flubitlog/Block/Adminhtml/Flubitlog/Detail.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * To change this template, choose Tools | Templates
5
+ * and open the template in the editor.
6
+ */
7
+ class Flubit_Flubitlog_Block_Adminhtml_Flubitlog_Detail extends Mage_Adminhtml_Block_Template {
8
+
9
+ /*
10
+ public function __construct() {
11
+ $this->_controller = 'adminhtml_flubitlog';
12
+ $this->_blockGroup = 'flubitlog';
13
+ $this->_headerText = Mage::helper('flubitlog')->__('Flubit Logs');
14
+ $this->_addButtonLabel = Mage::helper('flubitlog')->__('Add Item');
15
+ parent::__construct();
16
+ $this->_removeButton('add');
17
+ }*/
18
+
19
+ }
20
+
app/code/community/Flubit/Flubitlog/Block/Adminhtml/Flubitlog/Edit.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubitlog Block Flubitnd
5
+ *
6
+ * @package Flubit
7
+ * @category Flubitlog_Block
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubitlog_Block_Adminhtml_Flubitlog_Edit extends Mage_Adminhtml_Block_Widget_Form_Container {
11
+
12
+ /**
13
+ * Construct and autoload initModule
14
+ */
15
+ public function __construct() {
16
+ parent::__construct();
17
+
18
+ $this->_objectId = 'id';
19
+ $this->_blockGroup = 'flubitlog';
20
+ $this->_controller = 'adminhtml_flubitlog';
21
+
22
+ $this->_updateButton('save', 'label', Mage::helper('flubitlog')->__('Save Item'));
23
+ $this->_updateButton('delete', 'label', Mage::helper('flubitlog')->__('Delete Item'));
24
+ $this->_removeButton('delete');
25
+ $this->_removeButton('save');
26
+ $this->_removeButton('reset');
27
+
28
+ }
29
+
30
+ /**
31
+ * Method for Create Flubit logging
32
+ *
33
+ * @param data check String $xml
34
+ * @return Xml String
35
+ */
36
+ public function getHeaderText() {
37
+ if (Mage::registry('flubitlog_data') && Mage::registry('flubitlog_data')->getId()) {
38
+ return Mage::helper('flubitlog')->__("Log details ");
39
+ } else {
40
+ return Mage::helper('flubitlog')->__('Add Item');
41
+ }
42
+ }
43
+
44
+ }
app/code/community/Flubit/Flubitlog/Block/Adminhtml/Flubitlog/Edit/Form.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubitlog Block Flubitlog_Edit
5
+ *
6
+ * @package Flubit
7
+ * @category Flubitlog_Edit
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubitlog_Block_Adminhtml_Flubitlog_Edit_Form extends Mage_Adminhtml_Block_Widget_Form {
11
+
12
+ protected function _prepareForm() {
13
+ $form = new Varien_Data_Form(array(
14
+ 'id' => 'edit_form',
15
+ 'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
16
+ 'method' => 'post',
17
+ 'enctype' => 'multipart/form-data'
18
+ )
19
+ );
20
+
21
+ $form->setUseContainer(true);
22
+ $this->setForm($form);
23
+ return parent::_prepareForm();
24
+ }
25
+
26
+ }
app/code/community/Flubit/Flubitlog/Block/Adminhtml/Flubitlog/Edit/Tab/Form.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubitlog Block Flubitlog Edit Tab
5
+ *
6
+ * @package Flubit
7
+ * @category Flubitlog_Edit_Tab
8
+ * @author Flubit team
9
+ */
10
+
11
+ class Flubit_Flubitlog_Block_Adminhtml_Flubitlog_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
12
+ {
13
+ /**
14
+ * Method for Create Prepare Form
15
+ *
16
+ */
17
+ protected function _prepareForm()
18
+ {
19
+ $model = Mage::registry('flubitlog_data');
20
+ $form = new Varien_Data_Form();
21
+ $this->setForm($form);
22
+ $fieldset = $form->addFieldset('flubitlog_form', array('legend'=>Mage::helper('flubitlog')->__('Request')));
23
+ $fieldset->addField('request_xml', 'editor', array(
24
+ 'name' => 'request_xml',
25
+ 'style' => 'width:900px; height:250px;resize: none;',
26
+ 'wysiwyg' => false,
27
+ 'readonly' => true,
28
+ 'value' => $model['request_xml'],
29
+ ));
30
+
31
+ $fieldset->addField('response_xml', 'editor', array(
32
+ 'name' => 'response_xml',
33
+ 'style' => 'width:900px; height:250px;resize: none;',
34
+ 'wysiwyg' => false,
35
+ 'readonly' => true,
36
+ 'value' => $model['response_xml'],
37
+ ));
38
+
39
+ return parent::_prepareForm();
40
+ }
41
+
42
+
43
+ }
app/code/community/Flubit/Flubitlog/Block/Adminhtml/Flubitlog/Edit/Tabs.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Class Flubitlog Block Flubitlog Edit Tabs
4
+ *
5
+ * @package Flubit
6
+ * @category Flubitlog_Edit_Tabs
7
+ * @author Flubit team
8
+ */
9
+ class Flubit_Flubitlog_Block_Adminhtml_Flubitlog_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs {
10
+
11
+ /**
12
+ * Construct and autoload initModule
13
+ */
14
+ public function __construct() {
15
+ parent::__construct();
16
+ //$this->setId('flubitlog_tabs');
17
+ $this->setDestElementId('edit_form');
18
+ //$this->setTitle(Mage::helper('flubitlog')->__('Item Information'));
19
+ }
20
+
21
+ /**
22
+ * Method for Create Flubit logging
23
+ *
24
+ * @param data check String $xml
25
+ * @return Xml String
26
+ */
27
+ protected function _beforeToHtml() {
28
+ $this->addTab('form_section', array(
29
+ // 'label' => Mage::helper('flubitlog')->__('Item Information'),
30
+ // 'title' => Mage::helper('flubitlog')->__('Item Information'),
31
+ 'content' => $this->getLayout()->createBlock('flubitlog/adminhtml_flubitlog_edit_tab_form')->toHtml(),
32
+ ));
33
+
34
+ return parent::_beforeToHtml();
35
+ }
36
+
37
+ }
app/code/community/Flubit/Flubitlog/Block/Adminhtml/Flubitlog/Grid.php ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubitlog Block Flubitlog Grid
5
+ *
6
+ * @package Flubit
7
+ * @category Flubitlog_Grid
8
+ * @author Flubit team
9
+ */
10
+
11
+ class Flubit_Flubitlog_Block_Adminhtml_Flubitlog_Grid extends Mage_Adminhtml_Block_Widget_Grid {
12
+
13
+ /**
14
+ * Construct for autoload and set property
15
+ */
16
+ public function __construct() {
17
+ parent::__construct();
18
+ $this->setId('flubitlogGrid');
19
+ $this->setDefaultSort('flubitlog_id');
20
+ $this->setDefaultDir('DESC');
21
+ $this->setSaveParametersInSession(true);
22
+ }
23
+
24
+ /**
25
+ * Method for Create Prepare Collection
26
+ *
27
+ */
28
+ protected function _prepareCollection() {
29
+ $collection = Mage::getModel('flubitlog/flubitlog')->getCollection();
30
+ $this->setCollection($collection);
31
+ return parent::_prepareCollection();
32
+ }
33
+
34
+ /**
35
+ * Method for Create Prepare Columns
36
+ *
37
+ */
38
+ protected function _prepareColumns() {
39
+ $this->addColumn('flubitlog_id', array(
40
+ 'header' => Mage::helper('flubitlog')->__('Log ID'),
41
+ 'align' => 'right',
42
+ 'width' => '50px',
43
+ 'index' => 'flubitlog_id',
44
+ ));
45
+
46
+ $this->addColumn('feedid', array(
47
+ 'header' => Mage::helper('flubitlog')->__('Feed ID / Flubit Order ID'),
48
+ 'align' => 'right',
49
+ 'width' => '100px',
50
+ 'index' => 'feedid',
51
+ ));
52
+
53
+ $this->addColumn('level', array(
54
+ 'header' => Mage::helper('log')->__('Level'),
55
+ 'align' => 'left',
56
+ 'width' => '50px',
57
+ 'index' => 'level',
58
+ 'type' => 'options',
59
+ 'options' => array(
60
+ 1 => 'Success',
61
+ 2 => 'Error',
62
+ ),
63
+ ));
64
+
65
+ $this->addColumn('action', array(
66
+ 'header' => Mage::helper('log')->__('Action'),
67
+ 'align' => 'right',
68
+ 'width' => '100px',
69
+ 'index' => 'action',
70
+ 'type' => 'options',
71
+ 'options' => array(
72
+ 1 => 'Create Product',
73
+ 2 => 'Update Product',
74
+ 9 => 'Delete Product',
75
+ 3 => 'Fetch Order',
76
+ 4 => 'Order Status Dispatch',
77
+ 5 => 'Order Status Refund',
78
+ 6 => 'Order Status Cancel',
79
+ 7 => 'Create Order Magento',
80
+ 8 => 'Communication Error',
81
+ 10 => 'Check Feed Response',
82
+ ),
83
+ ));
84
+
85
+ $this->addColumn('datetime', array(
86
+ 'header' => Mage::helper('log')->__('Created at'),
87
+ 'width' => '100px',
88
+ 'index' => 'datetime',
89
+ 'type' => 'datetime',
90
+
91
+ ));
92
+
93
+ return parent::_prepareColumns();
94
+ }
95
+
96
+ /**
97
+ * Method for Create Flubit logging
98
+ *
99
+ * @param data check String $xml
100
+ * @return Xml String
101
+ */
102
+ protected function _prepareMassaction() {
103
+ $this->setMassactionIdField('flubitlog_id');
104
+ $this->getMassactionBlock()->setFormFieldName('flubitlog');
105
+ $this->getMassactionBlock()->addItem('delete', array(
106
+ 'label' => Mage::helper('flubitlog')->__('Delete'),
107
+ 'url' => $this->getUrl('*/*/massDelete'),
108
+ 'confirm' => Mage::helper('flubitlog')->__('Are you sure?')
109
+ ));
110
+
111
+ $statuses = Mage::getSingleton('flubitlog/status')->getOptionArray();
112
+
113
+ array_unshift($statuses, array('label'=>'', 'value'=>''));
114
+
115
+ return $this;
116
+ }
117
+
118
+ /**
119
+ * Method for Create Flubit logging
120
+ *
121
+ * @param data check String $xml
122
+ * @return Xml String
123
+ */
124
+ public function getRowUrl($row) {
125
+
126
+ if ($row['flubitlog_id']) {
127
+ // $Id = Mage::getModel('flubitlog/flubitlog')->getId($row['id']);
128
+ return $this->getUrl('*/*/detail', array('id' => $row['flubitlog_id']));
129
+ }
130
+ }
131
+
132
+ }
app/code/community/Flubit/Flubitlog/Block/Flubitlog.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Class Flubitlog Block Flubitnd
4
+ *
5
+ * @package Flubit
6
+ * @category Flubitlog_Block
7
+ * @author Flubit team
8
+ */
9
+
10
+ class Flubit_Flubitlog_Block_Flubitlog extends Mage_Core_Block_Template
11
+ {
12
+ /**
13
+ * method for prepare layout
14
+ *
15
+ * @return type
16
+ */
17
+ public function _prepareLayout()
18
+ {
19
+ return parent::_prepareLayout();
20
+ }
21
+
22
+ /**
23
+ * method for getFlubitlog
24
+ *
25
+ * @return string
26
+ */
27
+ public function getFlubitlog()
28
+ {
29
+ if (!$this->hasData('flubitlog')) {
30
+ $this->setData('flubitlog', Mage::registry('flubitlog'));
31
+ }
32
+ return $this->getData('flubitlog');
33
+
34
+ }
35
+ }
app/code/community/Flubit/Flubitlog/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Flubit_Flubitlog_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ }
app/code/community/Flubit/Flubitlog/Model/Flubitlog.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubitlog Flubitlog Model
5
+ *
6
+ * @package Flubit
7
+ * @category Flubitlog_Model_Flubitlog
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubitlog_Model_Flubitlog extends Mage_Core_Model_Abstract
11
+ {
12
+ public function _construct()
13
+ {
14
+ parent::_construct();
15
+ $this->_init('flubitlog/flubitlog');
16
+ }
17
+ }
app/code/community/Flubit/Flubitlog/Model/Mysql4/Flubitlog.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit_Flubitlog_Model_Status
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Flubitlog_Model_Mysql4_Flubitlog
8
+ * @author Flubit team
9
+ */
10
+
11
+ class Flubit_Flubitlog_Model_Mysql4_Flubitlog extends Mage_Core_Model_Mysql4_Abstract
12
+ {
13
+
14
+ /**
15
+ *
16
+ * Construct for autoload and set property
17
+ */
18
+
19
+ public function _construct()
20
+ {
21
+ // Note that the flubitlog_id refers to the key field in your database table.
22
+ $this->_init('flubitlog/flubitlog', 'flubitlog_id');
23
+ }
24
+ }
app/code/community/Flubit/Flubitlog/Model/Mysql4/Flubitlog/Collection.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit Flubitlog Model Mysql4 Flubitlog Collection
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Flubitlog_Model_Mysql4_Flubitlog_Collection
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubitlog_Model_Mysql4_Flubitlog_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
11
+ {
12
+
13
+ /**
14
+ *
15
+ * Construct for autoload and set property
16
+ */
17
+
18
+ public function _construct()
19
+ {
20
+ parent::_construct();
21
+ $this->_init('flubitlog/flubitlog');
22
+ }
23
+ }
app/code/community/Flubit/Flubitlog/Model/Status.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubit_Flubitlog_Model_Status
5
+ *
6
+ * @package Flubit
7
+ * @category Flubit_Flubitlog_Model_Status
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubitlog_Model_Status extends Varien_Object
11
+ {
12
+ const STATUS_ENABLED = 1;
13
+ const STATUS_DISABLED = 2;
14
+
15
+ /**
16
+ * Method to Enable & Disable the logging
17
+ *
18
+ * @return String
19
+ */
20
+
21
+ static public function getOptionArray()
22
+ {
23
+ return array(
24
+ self::STATUS_ENABLED => Mage::helper('flubitlog')->__('Enabled'),
25
+ self::STATUS_DISABLED => Mage::helper('flubitlog')->__('Disabled')
26
+ );
27
+ }
28
+ }
app/code/community/Flubit/Flubitlog/controllers/Adminhtml/FlubitlogController.php ADDED
@@ -0,0 +1,261 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubitlog Flubitlog Controller
5
+ *
6
+ * @package Flubit
7
+ * @category Flubitlog_FlubitlogController
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubitlog_Adminhtml_FlubitlogController extends Mage_Adminhtml_Controller_action {
11
+
12
+ /* @Method : initAction Autoloader
13
+ * @Parameter : None
14
+ * @return : None
15
+ */
16
+
17
+ protected function _initAction() {
18
+ $this->loadLayout()
19
+ ->_setActiveMenu('flubitlog/items')
20
+ ->_addBreadcrumb(Mage::helper('adminhtml')->__('Items Manager'), Mage::helper('adminhtml')->__('Item Manager'));
21
+
22
+ return $this;
23
+ }
24
+
25
+ /* @Method : indexAction
26
+ * @Parameter : None
27
+ * @return : None
28
+ */
29
+
30
+ public function indexAction() {
31
+ $this->_initAction()
32
+ ->renderLayout();
33
+ }
34
+
35
+ /* @Method : Method for particular logging details by auto Id
36
+ * @Parameter : string Id
37
+ * @return : ArrayString
38
+ */
39
+
40
+ public function detailAction() {
41
+ $id = $this->getRequest()->getParam('id');
42
+
43
+ $model = Mage::getModel('flubitlog/flubitlog')->load($id);
44
+ if ($model->getId() || $id == 0) {
45
+ $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
46
+ if (!empty($data)) {
47
+ $model->setData($data);
48
+ }
49
+ Mage::register('flubitlog_data', $model);
50
+ $this->loadLayout();
51
+ //$this->_setActiveMenu('flubitlog/logs');
52
+
53
+ //$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item Manager'), Mage::helper('adminhtml')->__('Item Manager'));
54
+ //$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));
55
+
56
+ $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
57
+
58
+ $this->_addContent($this->getLayout()->createBlock('flubitlog/adminhtml_flubitlog_detail'));
59
+
60
+ /*$this->_addContent($this->getLayout()->createBlock('flubitlog/adminhtml_flubitlog_edit'))
61
+ ->_addLeft($this->getLayout()->createBlock('flubitlog/adminhtml_flubitlog_edit_tabs'));*/
62
+
63
+ $this->renderLayout();
64
+ } else {
65
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('flubitlog')->__('Logs does not exist'));
66
+ $this->_redirect('*/*/');
67
+ }
68
+ }
69
+
70
+ public function newAction() {
71
+ $this->_forward('edit');
72
+ }
73
+
74
+ /* @Method : Method for particular logging for Save
75
+ * @Parameter : string Id
76
+ * @return : ArrayString
77
+ */
78
+ public function saveAction() {
79
+ if ($data = $this->getRequest()->getPost()) {
80
+
81
+ if (isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
82
+ try {
83
+ /* Starting upload */
84
+ $uploader = new Varien_File_Uploader('filename');
85
+
86
+ //Any extention would work
87
+ $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
88
+ $uploader->setAllowRenameFiles(false);
89
+
90
+ $uploader->setFilesDispersion(false);
91
+
92
+ // We set media as the upload dir
93
+ $path = Mage::getBaseDir('media') . DS;
94
+ $uploader->save($path, $_FILES['filename']['name']);
95
+ } catch (Exception $e) {
96
+
97
+ }
98
+
99
+ //this way the name is saved in DB
100
+ $data['filename'] = $_FILES['filename']['name'];
101
+ }
102
+
103
+ $model = Mage::getModel('flubitlog/flubitlog');
104
+ $model->setData($data)
105
+ ->setId($this->getRequest()->getParam('id'));
106
+
107
+ try {
108
+ if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
109
+ $model->setCreatedTime(now())
110
+ ->setUpdateTime(now());
111
+ } else {
112
+ $model->setUpdateTime(now());
113
+ }
114
+
115
+ $model->save();
116
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('flubitlog')->__('Item was successfully saved'));
117
+ Mage::getSingleton('adminhtml/session')->setFormData(false);
118
+
119
+ if ($this->getRequest()->getParam('back')) {
120
+ $this->_redirect('*/*/edit', array('id' => $model->getId()));
121
+ return;
122
+ }
123
+ $this->_redirect('*/*/');
124
+ return;
125
+ } catch (Exception $e) {
126
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
127
+ Mage::getSingleton('adminhtml/session')->setFormData($data);
128
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
129
+ return;
130
+ }
131
+ }
132
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('flubitlog')->__('Unable to find item to save'));
133
+ $this->_redirect('*/*/');
134
+ }
135
+
136
+ /* @Method : Method for delete logging by auto id
137
+ * @Parameter : string Id
138
+ * @return : ArrayString
139
+ */
140
+
141
+ public function deleteAction() {
142
+ if ($this->getRequest()->getParam('id') > 0) {
143
+ try {
144
+ $model = Mage::getModel('flubitlog/flubitlog');
145
+
146
+ $model->setId($this->getRequest()->getParam('id'))
147
+ ->delete();
148
+
149
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully deleted'));
150
+ $this->_redirect('*/*/');
151
+ } catch (Exception $e) {
152
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
153
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
154
+ }
155
+ }
156
+ $this->_redirect('*/*/');
157
+ }
158
+
159
+ /**
160
+ * Method for Delete Multiple Error logging
161
+ *
162
+ * @param string
163
+ * @return string
164
+ */
165
+
166
+ public function massDeleteAction() {
167
+ $flubitlogIds = $this->getRequest()->getParam('flubitlog');
168
+ if (!is_array($flubitlogIds)) {
169
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
170
+ } else {
171
+ try {
172
+ foreach ($flubitlogIds as $flubitlogId) {
173
+ $flubitlog = Mage::getModel('flubitlog/flubitlog')->load($flubitlogId);
174
+ $flubitlog->delete();
175
+ }
176
+ Mage::getSingleton('adminhtml/session')->addSuccess(
177
+ Mage::helper('adminhtml')->__(
178
+ 'Total of %d record(s) were successfully deleted', count($flubitlogIds)
179
+ )
180
+ );
181
+ } catch (Exception $e) {
182
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
183
+ }
184
+ }
185
+ $this->_redirect('*/*/index');
186
+ }
187
+
188
+ /**
189
+ * Method for Status Update Multiple Error logging
190
+ *
191
+ * @param string
192
+ * @return string
193
+ */
194
+
195
+ public function massStatusAction() {
196
+ $flubitlogIds = $this->getRequest()->getParam('flubitlog');
197
+ if (!is_array($flubitlogIds)) {
198
+ Mage::getSingleton('adminhtml/session')->addError($this->__('Please select item(s)'));
199
+ } else {
200
+ try {
201
+ foreach ($flubitlogIds as $flubitlogId) {
202
+ $flubitlog = Mage::getSingleton('flubitlog/flubitlog')
203
+ ->load($flubitlogId)
204
+ ->setStatus($this->getRequest()->getParam('status'))
205
+ ->setIsMassupdate(true)
206
+ ->save();
207
+ }
208
+ $this->_getSession()->addSuccess(
209
+ $this->__('Total of %d record(s) were successfully updated', count($flubitlogIds))
210
+ );
211
+ } catch (Exception $e) {
212
+ $this->_getSession()->addError($e->getMessage());
213
+ }
214
+ }
215
+ $this->_redirect('*/*/index');
216
+ }
217
+
218
+ /**
219
+ * Method for Export CSV files
220
+ *
221
+ * @param None
222
+ * @return xls
223
+ */
224
+ public function exportCsvAction() {
225
+ $fileName = 'flubitlog.csv';
226
+ $content = $this->getLayout()->createBlock('flubitlog/adminhtml_flubitlog_grid')
227
+ ->getCsv();
228
+
229
+ $this->_sendUploadResponse($fileName, $content);
230
+ }
231
+
232
+ /**
233
+ * Method for Export Xml files
234
+ *
235
+ * @param None
236
+ * @return stringxml
237
+ */
238
+ public function exportXmlAction() {
239
+ $fileName = 'flubitlog.xml';
240
+ $content = $this->getLayout()->createBlock('flubitlog/adminhtml_flubitlog_grid')
241
+ ->getXml();
242
+
243
+ $this->_sendUploadResponse($fileName, $content);
244
+ }
245
+
246
+ protected function _sendUploadResponse($fileName, $content, $contentType = 'application/octet-stream') {
247
+ $response = $this->getResponse();
248
+ $response->setHeader('HTTP/1.1 200 OK', '');
249
+ $response->setHeader('Pragma', 'public', true);
250
+ $response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
251
+ $response->setHeader('Content-Disposition', 'attachment; filename=' . $fileName);
252
+ $response->setHeader('Last-Modified', date('r'));
253
+ $response->setHeader('Accept-Ranges', 'bytes');
254
+ $response->setHeader('Content-Length', strlen($content));
255
+ $response->setHeader('Content-type', $contentType);
256
+ $response->setBody($content);
257
+ $response->sendResponse();
258
+ die;
259
+ }
260
+
261
+ }
app/code/community/Flubit/Flubitlog/controllers/IndexController.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Flubitlog Index Controller
5
+ *
6
+ * @package Flubit
7
+ * @category Flubitlog_IndexController
8
+ * @author Flubit team
9
+ */
10
+ class Flubit_Flubitlog_IndexController extends Mage_Core_Controller_Front_Action
11
+ {
12
+ public function indexAction()
13
+ {
14
+ $this->loadLayout();
15
+ $this->renderLayout();
16
+ }
17
+ }
18
+
app/code/community/Flubit/Flubitlog/etc/config.xml ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Flubit
5
+ * @package Flubit_Flubitlog
6
+ * @author ModuleCreator
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+ -->
10
+ <config>
11
+ <modules>
12
+ <Flubit_Flubitlog>
13
+ <version>0.2.2</version>
14
+ </Flubit_Flubitlog>
15
+ </modules>
16
+ <frontend>
17
+ <routers>
18
+ <flubitlog>
19
+ <use>standard</use>
20
+ <args>
21
+ <module>Flubit_Flubitlog</module>
22
+ <frontName>flubitlog</frontName>
23
+ </args>
24
+ </flubitlog>
25
+ </routers>
26
+ <layout>
27
+ <updates>
28
+ <flubitlog>
29
+ <file>flubitlog.xml</file>
30
+ </flubitlog>
31
+ </updates>
32
+ </layout>
33
+ </frontend>
34
+ <admin>
35
+ <routers>
36
+ <flubitlog>
37
+ <use>admin</use>
38
+ <args>
39
+ <module>Flubit_Flubitlog</module>
40
+ <frontName>flubitlog</frontName>
41
+ </args>
42
+ </flubitlog>
43
+ </routers>
44
+ </admin>
45
+ <adminhtml>
46
+ <menu>
47
+ <flubitlog module="flubitlog">
48
+ <title>Flubit Logs</title>
49
+ <sort_order>71</sort_order>
50
+ <children>
51
+ <items module="flubitlog">
52
+ <title>View Logs</title>
53
+ <sort_order>0</sort_order>
54
+ <action>flubitlog/adminhtml_flubitlog</action>
55
+ </items>
56
+ </children>
57
+ </flubitlog>
58
+ </menu>
59
+ <acl>
60
+ <resources>
61
+ <all>
62
+ <title>Allow Everything</title>
63
+ </all>
64
+ <admin>
65
+ <children>
66
+ <Flubit_Flubitlog>
67
+ <title>Flubitlog Module</title>
68
+ <sort_order>10</sort_order>
69
+ </Flubit_Flubitlog>
70
+ </children>
71
+ </admin>
72
+ </resources>
73
+ </acl>
74
+ <layout>
75
+ <updates>
76
+ <flubitlog>
77
+ <file>flubitlog.xml</file>
78
+ </flubitlog>
79
+ </updates>
80
+ </layout>
81
+ </adminhtml>
82
+ <global>
83
+ <models>
84
+ <flubitlog>
85
+ <class>Flubit_Flubitlog_Model</class>
86
+ <resourceModel>flubitlog_mysql4</resourceModel>
87
+ </flubitlog>
88
+ <flubitlog_mysql4>
89
+ <class>Flubit_Flubitlog_Model_Mysql4</class>
90
+ <entities>
91
+ <flubitlog>
92
+ <table>flubitlog</table>
93
+ </flubitlog>
94
+ </entities>
95
+ </flubitlog_mysql4>
96
+ </models>
97
+ <resources>
98
+ <flubitlog_setup>
99
+ <setup>
100
+ <module>Flubit_Flubitlog</module>
101
+ </setup>
102
+ <connection>
103
+ <use>core_setup</use>
104
+ </connection>
105
+ </flubitlog_setup>
106
+ <flubitlog_write>
107
+ <connection>
108
+ <use>core_write</use>
109
+ </connection>
110
+ </flubitlog_write>
111
+ <flubitlog_read>
112
+ <connection>
113
+ <use>core_read</use>
114
+ </connection>
115
+ </flubitlog_read>
116
+ </resources>
117
+ <blocks>
118
+ <flubitlog>
119
+ <class>Flubit_Flubitlog_Block</class>
120
+ </flubitlog>
121
+ </blocks>
122
+ <helpers>
123
+ <flubitlog>
124
+ <class>Flubit_Flubitlog_Helper</class>
125
+ </flubitlog>
126
+ </helpers>
127
+ </global>
128
+ </config>
app/code/community/Flubit/Flubitlog/sql/flubitlog_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Script for Error logging in flubit
4
+ *
5
+ * @package Flubit
6
+ * @category Flubit_Sql
7
+ * @author Flubit team
8
+ */
9
+ $installer = $this;
10
+
11
+ $installer->startSetup();
12
+
13
+ $installer->run("
14
+
15
+ -- DROP TABLE IF EXISTS {$this->getTable('flubitlog/flubitlog')} ;
16
+ CREATE TABLE {$this->getTable('flubitlog/flubitlog')} (
17
+ `flubitlog_id` int(11) unsigned NOT NULL auto_increment,
18
+ `request_xml` varchar(255) NOT NULL default '',
19
+ `response_xml` varchar(255) NOT NULL default '',
20
+ `action` int(11) NULL ,
21
+ `datetime` datetime NULL default '0000-00-00 00:00:00',
22
+ `level` int (11) NULL,
23
+ `update_time` datetime NULL,
24
+ PRIMARY KEY (`flubitlog_id`)
25
+ );
26
+ ");
27
+
28
+ $installer->endSetup();
app/code/community/Flubit/Flubitlog/sql/flubitlog_setup/upgrade-0.1.0-0.2.0.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Script for Alter Flubit log Column feedid
4
+ *
5
+ * @package Flubit
6
+ * @category Flubit_Sql
7
+ * @author Flubit team
8
+ */
9
+ $installer = $this;
10
+ $installer->startSetup();
11
+
12
+
13
+ $installer->run("
14
+
15
+ ALTER TABLE {$this->getTable('flubitlog/flubitlog')} ADD `feedid` VARCHAR( 50 ) NOT NULL default '';
16
+
17
+ ");
18
+
19
+ $installer->endSetup();
app/code/community/Flubit/Flubitlog/sql/flubitlog_setup/upgrade-0.2.0-0.2.1.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Script for Alter Flubit log Column requestxml and responseml datatype
4
+ *
5
+ * @package Flubit
6
+ * @category Flubit_Sql
7
+ * @author Flubit team
8
+ */
9
+ $installer = $this;
10
+ $installer->startSetup();
11
+
12
+ $installer->run("
13
+
14
+ ALTER TABLE {$this->getTable('flubitlog/flubitlog')}
15
+ MODIFY COLUMN `request_xml` LONGTEXT NOT NULL,
16
+ MODIFY COLUMN `response_xml` LONGTEXT NOT NULL;
17
+ ");
18
+
19
+ $installer->endSetup();
app/code/community/Flubit/Flubitlog/sql/flubitlog_setup/upgrade-0.2.1-0.2.2.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Script for Alter Flubit log Column requestxml and responseml datatype
4
+ *
5
+ * @package Flubit
6
+ * @category Flubit_Sql
7
+ * @author Flubit team
8
+ */
9
+ $installer = $this;
10
+ $installer->startSetup();
11
+
12
+ $installer->run(
13
+ "TRUNCATE TABLE {$installer->getTable('flubitlog/flubitlog')} "
14
+ );
15
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/flubit.xml ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <default>
4
+ <reference name="notifications">
5
+ <block type="flubit/adminhtml_notification" name="notification_flubit_cron" as="notification_flubit_cron" template="flubit/cronnotofocation.phtml"></block>
6
+ </reference>
7
+ </default>
8
+ <flubit_adminhtml_flubitbackend_index>
9
+ <reference name="content">
10
+ <block type="flubit/adminhtml_flubitbackend" name="flubitbackend" template="flubit/flubitbackend.phtml"/>
11
+ </reference>
12
+ </flubit_adminhtml_flubitbackend_index>
13
+ <flubit_adminhtml_flubit_index>
14
+ <reference name="content">
15
+ <block type="flubit/adminhtml_flubit" name="flubit" />
16
+ </reference>
17
+ </flubit_adminhtml_flubit_index>
18
+
19
+ <adminhtml_sales_order_view>
20
+ <reference name="order_info">
21
+ <action method="setTemplate">
22
+ <template>flubit/sales/order/view/info.phtml</template>
23
+ </action>
24
+ </reference>
25
+ <!--<block type="adminhtml/sales_order_invoice_totals" name="invoice_totals" template="sales/order/totals.phtml"></block>-->
26
+ <reference name="order_totals">
27
+ <action method="setTemplate">
28
+ <template>flubit/sales/order/flubittotals.phtml</template>
29
+ </action>
30
+ </reference>
31
+ <reference name="order_items">
32
+ <action method="setTemplate">
33
+ <template>flubit/sales/order/view/flubititems.phtml</template>
34
+ </action>
35
+ <action method="addItemRender">
36
+ <type>default</type>
37
+ <block>adminhtml/sales_order_view_items_renderer_default</block>
38
+ <template>flubit/sales/order/view/items/renderer/flubitdefault.phtml</template>
39
+ </action>
40
+ </reference>
41
+ </adminhtml_sales_order_view>
42
+ <adminhtml_sales_order_invoice_view>
43
+ <reference name="invoice_items">
44
+ <action method="setTemplate">
45
+ <template>flubit/sales/order/invoice/view/items.phtml</template>
46
+ </action>
47
+ <action method="addItemRender">
48
+ <type>default</type>
49
+ <block>adminhtml/sales_items_renderer_default</block>
50
+ <template>flubit/sales/order/invoice/view/items/renderer/default.phtml</template>
51
+ </action>
52
+ </reference>
53
+ <reference name="invoice_totals">
54
+ <action method="setTemplate">
55
+ <template>flubit/sales/order/flubittotals.phtml</template>
56
+ </action>
57
+ </reference>
58
+ </adminhtml_sales_order_invoice_view>
59
+
60
+ <flubit_adminhtml_flubit_index>
61
+ <reference name="js">
62
+ <block type="core/template" template="flubit/inline-edit.phtml" />
63
+ </reference>
64
+ </flubit_adminhtml_flubit_index>
65
+
66
+ <adminhtml_sales_order_shipment_new>
67
+ <reference name="order_items">
68
+ <action method="setTemplate">
69
+ <template>flubit/sales/order/shipment/create/items.phtml</template>
70
+ </action>
71
+ </reference>
72
+ </adminhtml_sales_order_shipment_new>
73
+
74
+ <adminhtml_sales_order_creditmemo_new>
75
+ <reference name="order_items">
76
+ <action method="setTemplate">
77
+ <template>flubit/sales/order/creditmemo/create/items.phtml</template>
78
+ </action>
79
+ <action method="addItemRender">
80
+ <type>default</type>
81
+ <block>adminhtml/sales_items_renderer_default</block>
82
+ <template>flubit/sales/order/creditmemo/create/items/renderer/defaultflubit.phtml</template>
83
+ </action>
84
+ </reference>
85
+
86
+ <reference name="adjustments">
87
+ <action method="setTemplate">
88
+ <template>flubit/sales/order/creditmemo/create/totals/adjustmentsflubit.phtml</template>
89
+ </action>
90
+ </reference>
91
+ <reference name="creditmemo_totals">
92
+ <action method="setTemplate">
93
+ <template>flubit/sales/order/flubittotals.phtml</template>
94
+ </action>
95
+ </reference>
96
+ </adminhtml_sales_order_creditmemo_new>
97
+ <adminhtml_sales_order_creditmemo_view>
98
+ <reference name="creditmemo_items">
99
+ <action method="setTemplate">
100
+ <template>flubit/sales/order/creditmemo/view/items.phtml</template>
101
+ </action>
102
+ <action method="addItemRender">
103
+ <type>default</type>
104
+ <block>adminhtml/sales_items_renderer_default</block>
105
+ <template>flubit/sales/order/creditmemo/view/items/renderer/default.phtml</template>
106
+ </action>
107
+ </reference>
108
+ <reference name="creditmemo_totals">
109
+ <action method="setTemplate">
110
+ <template>flubit/sales/order/flubittotals.phtml</template>
111
+ </action>
112
+ </reference>
113
+ </adminhtml_sales_order_creditmemo_view>
114
+
115
+ </layout>
app/design/adminhtml/default/default/layout/flubitlog.xml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <remove name="left" />
4
+ <flubitlog_adminhtml_flubitlog_index>
5
+ <reference name="content">
6
+ <block type="flubitlog/adminhtml_flubitlog" name="flubitlog" />
7
+ </reference>
8
+ </flubitlog_adminhtml_flubitlog_index>
9
+ <flubitlog_adminhtml_flubitlog_detail>
10
+ <reference name="content">
11
+ <block type="flubitlog/adminhtml_flubitlog_detail" name="flubitlog_detail" template="flubitlog/logdetails.phtml" />
12
+ </reference>
13
+ </flubitlog_adminhtml_flubitlog_detail>
14
+ </layout>
app/design/adminhtml/default/default/template/flubit/cronnotofocation.phtml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php $notice = $this->checkScheduledCronExecution(); ?>
2
+ <?php if($notice): ?>
3
+ <div class="notification-global">
4
+ <strong class="label">
5
+ Latest Message:</strong> <?php echo $notice ?></div>
6
+ <?php endif; ?>
app/design/adminhtml/default/default/template/flubit/inline-edit.phtml ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script type="text/javascript">
2
+ /**
3
+ *
4
+ * @param event domloaded
5
+ * @param function
6
+ *
7
+ */
8
+ document.observe("dom:loaded", function() {
9
+ $$('.onenter').each(function(elem) {
10
+ elem.observe("keypress", function(event) {
11
+ var fieldId = this.id;
12
+ var id = fieldId.replace(/^\D+/g, '');
13
+ if (event.keyCode == Event.KEY_RETURN || event.which == Event.KEY_RETURN) {
14
+ document.getElementById('link_' + id).click();
15
+ }
16
+ });
17
+ });
18
+ });
19
+ /**
20
+ * Function to update flubit price
21
+ *
22
+ * @param object button
23
+ * @param string fieldId
24
+ * @param string price
25
+ * @returns void
26
+ * */
27
+ function updateFlubitPrice(button, fieldId, price)
28
+ {
29
+ if (button.getValue() != price) {
30
+
31
+ if (button.getValue() > 0) {
32
+ var x;
33
+ var r = confirm("Warning! Are you sure that you want to manually update the Flubit Base Price? This will override the Global Price");
34
+ if (r == true) {
35
+ new Ajax.Request('<?php echo Mage::helper('adminhtml')->getUrl('*/*/updateFlubitPrice') ?>', {
36
+ method: 'post',
37
+ parameters: {id: fieldId, price: button.getValue()},
38
+ onSuccess: function(response) {
39
+ var data = response.responseText.evalJSON();
40
+ if (data.SUCCESS != null) {
41
+ alert(data.MESSAGE);
42
+ if(data.PRICE != ''){
43
+ button.setValue(data.PRICE);
44
+ }
45
+ }
46
+ if (data.ERROR != null) {
47
+ alert(data.MESSAGE);
48
+ }
49
+ }
50
+ });
51
+ }
52
+ else {
53
+ x = "You pressed Cancel!";
54
+ }
55
+ }
56
+ else {
57
+ alert('Price cannot be negative');
58
+ button.setValue(price);
59
+ }
60
+ }
61
+ }
62
+ /**
63
+ * function to update flubit flubit price calculation
64
+ *
65
+ * @param object checkbox
66
+ * @param string fieldId
67
+ * @param string price
68
+ * @returns void */
69
+ function updateFlubitPriceCalculation(checkbox, fieldId, price)
70
+ {
71
+ if (checkbox.checked == true) {
72
+ var x;
73
+ var r = confirm("Warning! Are you sure that you want to use global price calculator for the selected product? This will override the Manual Price");
74
+
75
+ if (r == true) {
76
+
77
+ new Ajax.Request('<?php echo Mage::helper('adminhtml')->getUrl('*/*/updateFlubitPriceCalculator') ?>', {
78
+ method: 'post',
79
+ parameters: {'id': fieldId, 'status': 1},
80
+ onSuccess: function(response) {
81
+ var data = response.responseText.evalJSON();
82
+ if (data.SUCCESS != null) {
83
+ alert(data.MESSAGE);
84
+ checkbox.checked = true;
85
+ $('price_' + data.ID).setValue(data.PRICE);
86
+ }
87
+ if (data.ERROR != null) {
88
+ alert(data.MESSAGE);
89
+ checkbox.checked = false;
90
+ }
91
+ }
92
+ });
93
+ }
94
+ else {
95
+ x = "You pressed Cancel!";
96
+ checkbox.checked = false;
97
+ }
98
+ }
99
+ else if (checkbox.checked == false) {
100
+ var x;
101
+ var r = confirm("Warning! Are you sure that you want to use manual price for the selected product? This will override the Global Price value");
102
+
103
+ if (r == true) {
104
+
105
+ new Ajax.Request('<?php echo Mage::helper('adminhtml')->getUrl('*/*/updateFlubitPriceCalculator') ?>', {
106
+ method: 'post',
107
+ parameters: {'id': fieldId, 'status': 0},
108
+ onSuccess: function(response) {
109
+ var data = response.responseText.evalJSON();
110
+ if (data.SUCCESS != null) {
111
+ alert(data.MESSAGE);
112
+ checkbox.checked = false;
113
+ }
114
+ if (data.ERROR != null) {
115
+ alert(data.MESSAGE);
116
+ checkbox.checked = true;
117
+ }
118
+ }
119
+ });
120
+ }
121
+ else {
122
+ x = "You pressed Cancel!";
123
+ checkbox.checked = true;
124
+ }
125
+ }
126
+ else {
127
+ }
128
+
129
+
130
+ }
131
+ /**
132
+ * function to initiate price and global calculator
133
+
134
+ * @param string id
135
+ * @param string price
136
+ * @param bool global_stat
137
+ * @returns void */
138
+ function updatePriceAndGlobalCalculator(id, price, global_stat) {
139
+
140
+ var priceBox = $('price_' + id).getValue();
141
+ var CheckBoxStat = $('checkbox_' + id).checked;
142
+
143
+ if (priceBox != price) {
144
+ if (CheckBoxStat == 1) {
145
+ alert('Uncheck “Use Global Price” Check box before updating Flubit Price for this product');
146
+ document.getElementById('price_' + id).value = price;
147
+ } else {
148
+ var button = document.getElementById('price_' + id);
149
+ updateFlubitPrice(button, id, price);
150
+ }
151
+ } else {
152
+ alert('No Change In Flubit Price Field');
153
+ }
154
+ }
155
+ </script>
app/design/adminhtml/default/default/template/flubit/sales/order/creditmemo/create/items.phtml ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category design
4
+ * @package default_default
5
+ * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
6
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
7
+ */
8
+ ?>
9
+ <?php $_items = $this->getCreditmemo()->getAllItems() ?>
10
+ <?php
11
+ $_order = $this->getOrder();
12
+
13
+ $flubitOrder = False;
14
+
15
+ if ($_order->getFlubitOrderId()) {
16
+ $flubitOrder = True;
17
+ }
18
+ ?>
19
+ <?php if (count($_items)) : ?>
20
+ <div class="grid np">
21
+ <div class="hor-scroll">
22
+ <table cellspacing="0" class="data order-tables">
23
+ <col />
24
+ <col width="1" />
25
+ <col width="1" />
26
+ <col width="1" />
27
+ <?php if ($this->canReturnToStock()) : ?><col width="1" /><?php endif; ?>
28
+ <col width="1" />
29
+ <col width="1" />
30
+ <col width="1" />
31
+ <col width="1" />
32
+ <thead>
33
+ <tr class="headings">
34
+ <th><?php echo $this->helper('sales')->__('Product') ?></th>
35
+ <?php if($flubitOrder) { ?>
36
+ <th><?php echo $this->helper('sales')->__('Flubit Base Price') ?></th>
37
+ <?php } ?>
38
+ <?php if($flubitOrder) { ?>
39
+ <th><?php echo $this->helper('sales')->__('Price Sold At(VAT inc.)') ?></th>
40
+ <?php } else { ?>
41
+ <th><?php echo $this->helper('sales')->__('Price') ?></th>
42
+ <?php } ?>
43
+ <th class="a-center"><?php echo $this->helper('sales')->__('Qty') ?></th>
44
+ <?php if ($this->canReturnToStock()) : ?>
45
+ <th><span class="nobr"><?php echo $this->helper('sales')->__('Return to Stock') ?></span></th>
46
+ <?php endif; ?>
47
+ <th><span class="nobr"><?php echo $this->helper('sales')->__('Qty to Refund') ?></span></th>
48
+ <?php if(!$flubitOrder) { ?>
49
+ <th><?php echo $this->helper('sales')->__('Subtotal') ?></th>
50
+ <?php } ?>
51
+ <?php if(!$flubitOrder) { ?>
52
+ <th><span class="nobr"><?php echo $this->helper('sales')->__('Tax Amount') ?></span></th>
53
+ <?php } else { ?>
54
+ <th><span class="nobr"><?php echo $this->helper('sales')->__('Tax Rate') ?></span></th>
55
+ <?php } ?>
56
+ <th><span class="nobr"><?php echo $this->helper('sales')->__('Discount Amount') ?></span></th>
57
+
58
+ <?php if(!$flubitOrder) { ?>
59
+ <th class="last"><span class="nobr"><?php echo $this->helper('sales')->__('Row Total') ?></span></th>
60
+ <?php } else { ?>
61
+ <th class="last"><span class="nobr"><?php echo $this->helper('sales')->__('Actual Price Sold At (VAT inc.)') ?></span></th>
62
+ <?php } ?>
63
+ </tr>
64
+ </thead>
65
+ <?php if ($this->canEditQty()): ?>
66
+ <tfoot>
67
+ <tr>
68
+ <td colspan="3">&nbsp;</td>
69
+ <td colspan="3" class="a-center">
70
+ <?php echo $this->getUpdateButtonHtml() ?>
71
+ </td>
72
+ <td colspan="3" class="last">&nbsp;</td>
73
+ </tr>
74
+ </tfoot>
75
+ <?php endif; ?>
76
+ <?php $i=0;foreach ($_items as $_item): ?>
77
+ <?php if ($_item->getOrderItem()->getParentItem()) continue; else $i++; ?>
78
+ <tbody class="<?php echo $i%2?'even':'odd' ?>">
79
+ <?php echo $this->getItemHtml($_item) ?>
80
+ <?php echo $this->getItemExtraInfoHtml($_item->getOrderItem()) ?>
81
+ </tbody>
82
+ <?php endforeach; ?>
83
+ </table>
84
+ </div>
85
+ </div>
86
+ <br />
87
+ <?php else : ?>
88
+ <div class="entry-edit">
89
+ <fieldset><div class="a-center"><?php echo $this->helper('sales')->__('No Items To Refund') ?></div></fieldset>
90
+ </div>
91
+ <?php endif; ?>
92
+
93
+ <div class="clear"></div>
94
+ <?php echo $this->getChildHtml('order_totalbar') ?>
95
+ <div class="clear"></div>
96
+
97
+ <input type="hidden" name="creditmemo[do_offline]" id="creditmemo_do_offline" value="0" />
98
+
99
+ <div class="box-left entry-edit">
100
+ <div class="entry-edit-head"><h4><?php echo Mage::helper('sales')->__('Credit Memo Comments') ?></h4></div>
101
+ <fieldset id="history_form">
102
+ <label class="normal" for="creditmemo_comment_text"><?php echo Mage::helper('sales')->__('Credit Memo Comments') ?></label><br/>
103
+ <textarea id="creditmemo_comment_text" name="creditmemo[comment_text]" rows="3" cols="5" style="width:98%;"><?php echo $this->getCreditmemo()->getCommentText(); ?></textarea>
104
+ </fieldset>
105
+ </div>
106
+ <div class="box-right entry-edit">
107
+ <div class="entry-edit-head"><h4><?php echo Mage::helper('sales')->__('Refund Totals') ?></h4></div>
108
+ <div class="order-totals">
109
+ <?php echo $this->getChildHtml('creditmemo_totals') ?>
110
+ <div class="order-totals-bottom">
111
+ <div class="divider"></div>
112
+ <p>
113
+ <label class="normal" for="notify_customer"><?php echo Mage::helper('sales')->__('Append Comments') ?></label>
114
+ <input id="notify_customer" name="creditmemo[comment_customer_notify]" value="1" type="checkbox" />
115
+ </p>
116
+ <?php if(!$flubitOrder) { ?>
117
+ <?php if ($this->canSendCreditmemoEmail()):?>
118
+ <p>
119
+ <label class="normal" for="send_email"><?php echo Mage::helper('sales')->__('Email Copy of Credit Memo') ?></label>
120
+ <input id="send_email" name="creditmemo[send_email]" value="1" type="checkbox" />
121
+ </p>
122
+ <?php endif; ?>
123
+ <?php } ?>
124
+ <?php echo $this->getChildHtml('submit_before') ?>
125
+ <?php echo $this->getChildHtml('submit_offline') ?>
126
+ <?php echo $this->getChildHtml('submit_button') ?>
127
+ <?php echo $this->getChildHtml('submit_after') ?>
128
+ </div>
129
+ </div>
130
+ </div>
131
+ <div class="clear"></div>
132
+
133
+ <script type="text/javascript">
134
+ //<![CDATA[
135
+ var submitButtons = $$('.submit-button');
136
+ var updateButtons = $$('.update-button');
137
+ var fields = $$('.qty-input');
138
+
139
+ updateButtons.each(function (elem) {elem.disabled=true;elem.addClassName('disabled');});
140
+
141
+ for(var i=0;i<fields.length;i++){
142
+ fields[i].observe('change', checkButtonsRelation)
143
+ fields[i].baseValue = fields[i].value;
144
+ }
145
+
146
+ function checkButtonsRelation() {
147
+ var hasChanges = false;
148
+ fields.each(function (elem) {
149
+ if (elem.baseValue != elem.value) {
150
+ hasChanges = true;
151
+ }
152
+ }.bind(this));
153
+ if (hasChanges) {
154
+ submitButtons.each(function (elem) {elem.disabled=true;elem.addClassName('disabled');});
155
+ updateButtons.each(function (elem) {elem.disabled=false;elem.removeClassName('disabled');});
156
+ }
157
+ else {
158
+ submitButtons.each(function (elem) {elem.disabled=false;elem.removeClassName('disabled');});
159
+ updateButtons.each(function (elem) {elem.disabled=true;elem.addClassName('disabled');});
160
+ }
161
+ }
162
+
163
+ function submitCreditMemo() {
164
+ if ($('creditmemo_do_offline')) $('creditmemo_do_offline').value=0;
165
+ editForm.submit()
166
+ }
167
+ function submitCreditMemoOffline() {
168
+ if ($('creditmemo_do_offline')) $('creditmemo_do_offline').value=1;
169
+ editForm.submit()
170
+ }
171
+
172
+ var sendEmailCheckbox = $('send_email');
173
+ if (sendEmailCheckbox) {
174
+ var notifyCustomerCheckbox = $('notify_customer');
175
+ var creditmemoCommentText = $('creditmemo_comment_text');
176
+ Event.observe(sendEmailCheckbox, 'change', bindSendEmail);
177
+ bindSendEmail();
178
+ }
179
+ function bindSendEmail()
180
+ {
181
+ if (sendEmailCheckbox.checked == true) {
182
+ notifyCustomerCheckbox.disabled = false;
183
+ //creditmemoCommentText.disabled = false;
184
+ }
185
+ else {
186
+ notifyCustomerCheckbox.disabled = true;
187
+ //creditmemoCommentText.disabled = true;
188
+ }
189
+ }
190
+ //]]>
191
+ </script>
app/design/adminhtml/default/default/template/flubit/sales/order/creditmemo/create/items/renderer/defaultflubit.phtml ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category design
4
+ * @package default_default
5
+ * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
6
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
7
+ */
8
+
9
+ ?>
10
+ <?php
11
+ $order = $this->getOrder();
12
+ $read_only_flag = $order->getData('flubit_order_id');
13
+ $tax_Rate = $order->getFlubitOrderTaxRate();
14
+ ?>
15
+ <?php
16
+ $flubitOrder = False;
17
+
18
+ if ($order->getFlubitOrderId()) {
19
+ $flubitOrder = True;
20
+ }
21
+ ?>
22
+ <?php
23
+ $_item = $this->getItem();
24
+ $original_price = '';
25
+ if($flubitOrder) {
26
+ $itemData = $_item->getOrderItem()->getData();
27
+ $original_price = $itemData['original_price'];
28
+ }
29
+ ?>
30
+ <?php $_item = $this->getItem() ?>
31
+ <?php $this->setPriceDataObject($_item); ?>
32
+ <tr class="border">
33
+ <td><?php echo $this->getColumnHtml($_item, 'name') ?></td>
34
+ <?php if($flubitOrder) { ?>
35
+ <td class="a-right"><?php echo $this->displayPrices($original_price, $original_price) ?></td>
36
+ <?php } ?>
37
+ <td class="a-right">
38
+ <?php if ($this->helper('tax')->displaySalesBothPrices() || $this->helper('tax')->displaySalesPriceExclTax()): ?>
39
+ <span class="price-excl-tax">
40
+ <?php if ($this->helper('tax')->displaySalesBothPrices()): ?>
41
+ <span class="label"><?php echo $this->__('Excl. Tax'); ?>:</span>
42
+ <?php endif; ?>
43
+
44
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales', $_item->getStoreId())): ?>
45
+ <?php
46
+ echo $this->displayPrices(
47
+ $_item->getBasePrice()+$_item->getBaseWeeeTaxAppliedAmount()+$_item->getBaseWeeeTaxDisposition(),
48
+ $_item->getPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition()
49
+ );
50
+ ?>
51
+ <?php else: ?>
52
+ <?php echo $this->displayPrices($_item->getBasePrice(), $_item->getPrice()) ?>
53
+ <?php endif; ?>
54
+
55
+
56
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
57
+ <br />
58
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales', $_item->getStoreId())): ?>
59
+ <small>
60
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
61
+ <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_amount'], $tax['amount']); ?></span>
62
+ <?php endforeach; ?>
63
+ </small>
64
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
65
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
66
+ <span class="nobr"><small><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_amount'], $tax['amount']); ?></small></span>
67
+ <?php endforeach; ?>
68
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales', $_item->getStoreId())): ?>
69
+ <small>
70
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
71
+ <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_amount'], $tax['amount']); ?></span>
72
+ <?php endforeach; ?>
73
+ </small>
74
+ <?php endif; ?>
75
+
76
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
77
+ <br />
78
+ <span class="nobr"><?php echo Mage::helper('weee')->__('Total'); ?>:<br />
79
+ <?php
80
+ echo $this->displayPrices(
81
+ $_item->getBasePrice()+$_item->getBaseWeeeTaxAppliedAmount()+$_item->getBaseWeeeTaxDisposition(),
82
+ $_item->getPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition()
83
+ );
84
+ ?>
85
+ </span>
86
+ <?php endif; ?>
87
+ <?php endif; ?>
88
+ </span>
89
+ <br />
90
+ <?php endif; ?>
91
+ <?php if ($this->helper('tax')->displaySalesBothPrices() || $this->helper('tax')->displaySalesPriceInclTax()): ?>
92
+ <span class="price-incl-tax">
93
+ <?php if ($this->helper('tax')->displaySalesBothPrices()): ?>
94
+ <span class="label"><?php echo $this->__('Incl. Tax'); ?>:</span>
95
+ <?php endif; ?>
96
+ <?php $_incl = $this->helper('checkout')->getPriceInclTax($_item); ?>
97
+ <?php $_baseIncl = $this->helper('checkout')->getBasePriceInclTax($_item); ?>
98
+
99
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales', $_item->getStoreId())): ?>
100
+ <?php echo $this->displayPrices($_baseIncl + Mage::helper('weee')->getBaseWeeeTaxInclTax($_item), $_incl + Mage::helper('weee')->getWeeeTaxInclTax($_item)); ?>
101
+ <?php else: ?>
102
+ <?php echo $this->displayPrices($_baseIncl-$_item->getBaseWeeeTaxDisposition(), $_incl-$_item->getWeeeTaxDisposition()) ?>
103
+ <?php endif; ?>
104
+
105
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
106
+ <br />
107
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales', $_item->getStoreId())): ?>
108
+ <small>
109
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
110
+ <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_amount_incl_tax'], $tax['amount_incl_tax']); ?></span>
111
+ <?php endforeach; ?>
112
+ </small>
113
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
114
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
115
+ <span class="nobr"><small><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_amount_incl_tax'], $tax['amount_incl_tax']); ?></small></span>
116
+ <?php endforeach; ?>
117
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales', $_item->getStoreId())): ?>
118
+ <small>
119
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
120
+ <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_amount_incl_tax'], $tax['amount_incl_tax']); ?></span>
121
+ <?php endforeach; ?>
122
+ </small>
123
+ <?php endif; ?>
124
+
125
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
126
+ <br />
127
+ <span class="nobr"><?php echo Mage::helper('weee')->__('Total'); ?>:<br /> <?php echo $this->displayPrices($_baseIncl + Mage::helper('weee')->getBaseWeeeTaxInclTax($_item) , $_incl + Mage::helper('weee')->getWeeeTaxInclTax($_item)); ?></span>
128
+ <?php endif; ?>
129
+ <?php endif; ?>
130
+ </span>
131
+ <?php endif; ?>
132
+ </td>
133
+ <td class="a-center"><?php echo $this->getColumnHtml($_item, 'qty') ?></td>
134
+ <?php if ($this->canParentReturnToStock($_item)) : ?>
135
+ <td class="a-center">
136
+ <?php if ($this->canReturnItemToStock($_item)) : ?>
137
+ <input type="checkbox" name="creditmemo[items][<?php echo $_item->getOrderItemId() ?>][back_to_stock]" value="1"<?php if ($_item->getBackToStock()):?> checked<?php endif;?>/>
138
+ <?php endif; ?>
139
+ </td>
140
+ <?php endif; ?>
141
+ <td class="a-center">
142
+ <?php if ($this->canEditQty()) : ?>
143
+ <input type="text" <?php if($read_only_flag!=NULL): ?>readonly="readonly"<?php endif; ?> class="input-text qty-input" name="creditmemo[items][<?php echo $_item->getOrderItemId() ?>][qty]" value="<?php echo $_item->getQty()*1 ?>"/>
144
+ <?php else : ?>
145
+ <?php echo $_item->getQty()*1 ?>
146
+ <?php endif; ?>
147
+ </td>
148
+ <?php if(!$flubitOrder) { ?>
149
+ <td class="a-right">
150
+ <?php if ($this->helper('tax')->displaySalesBothPrices() || $this->helper('tax')->displaySalesPriceExclTax()): ?>
151
+ <span class="price-excl-tax">
152
+ <?php if ($this->helper('tax')->displaySalesBothPrices()): ?>
153
+ <span class="label"><?php echo $this->__('Excl. Tax'); ?>:</span>
154
+ <?php endif; ?>
155
+
156
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales', $_item->getStoreId())): ?>
157
+ <?php
158
+ echo $this->displayPrices(
159
+ $_item->getBaseRowTotal()+$_item->getBaseWeeeTaxAppliedRowAmount()+$_item->getBaseWeeeTaxRowDisposition(),
160
+ $_item->getRowTotal()+$_item->getWeeeTaxAppliedRowAmount()+$_item->getWeeeTaxRowDisposition()
161
+ );
162
+ ?>
163
+ <?php else: ?>
164
+ <?php echo $this->displayPrices($_item->getBaseRowTotal(), $_item->getRowTotal()) ?>
165
+ <?php endif; ?>
166
+
167
+
168
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
169
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales', $_item->getStoreId())): ?>
170
+ <small>
171
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
172
+ <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_row_amount'], $tax['row_amount']); ?></span>
173
+ <?php endforeach; ?>
174
+ </small>
175
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
176
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
177
+ <span class="nobr"><small><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_row_amount'], $tax['row_amount']); ?></small></span>
178
+ <?php endforeach; ?>
179
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales', $_item->getStoreId())): ?>
180
+ <small>
181
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
182
+ <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_row_amount'], $tax['row_amount']); ?></span>
183
+ <?php endforeach; ?>
184
+ </small>
185
+ <?php endif; ?>
186
+
187
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
188
+ <br />
189
+ <span class="nobr"><?php echo Mage::helper('weee')->__('Total'); ?>:<br />
190
+ <?php
191
+ echo $this->displayPrices(
192
+ $_item->getBaseRowTotal()+$_item->getBaseWeeeTaxAppliedRowAmount()+$_item->getBaseWeeeTaxRowDisposition(),
193
+ $_item->getRowTotal()+$_item->getWeeeTaxAppliedRowAmount()+$_item->getWeeeTaxRowDisposition()
194
+ );
195
+ ?>
196
+ </span>
197
+ <?php endif; ?>
198
+ <?php endif; ?>
199
+ </span>
200
+ <br />
201
+ <?php endif; ?>
202
+ <?php if ($this->helper('tax')->displaySalesBothPrices() || $this->helper('tax')->displaySalesPriceInclTax()): ?>
203
+ <span class="price-incl-tax">
204
+ <?php if ($this->helper('tax')->displaySalesBothPrices()): ?>
205
+ <span class="label"><?php echo $this->__('Incl. Tax'); ?>:</span>
206
+ <?php endif; ?>
207
+ <?php $_incl = $this->helper('checkout')->getSubtotalInclTax($_item); ?>
208
+ <?php $_baseIncl = $this->helper('checkout')->getBaseSubtotalInclTax($_item); ?>
209
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales', $_item->getStoreId())): ?>
210
+ <?php echo $this->displayPrices($_baseIncl + Mage::helper('weee')->getBaseRowWeeeTaxInclTax($_item),$_incl + Mage::helper('weee')->getRowWeeeTaxInclTax($_item)); ?>
211
+ <?php else: ?>
212
+ <?php echo $this->displayPrices($_baseIncl-$_item->getBaseWeeeTaxRowDisposition(), $_incl-$_item->getWeeeTaxRowDisposition()) ?>
213
+ <?php endif; ?>
214
+
215
+
216
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
217
+
218
+ <br />
219
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales', $_item->getStoreId())): ?>
220
+ <small>
221
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
222
+ <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_row_amount_incl_tax'], $tax['row_amount_incl_tax']); ?></span>
223
+ <?php endforeach; ?>
224
+ </small>
225
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
226
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
227
+ <span class="nobr"><small><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_row_amount_incl_tax'], $tax['row_amount_incl_tax']); ?></small></span>
228
+ <?php endforeach; ?>
229
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales', $_item->getStoreId())): ?>
230
+ <small>
231
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
232
+ <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_row_amount_incl_tax'], $tax['row_amount_incl_tax']); ?></span>
233
+ <?php endforeach; ?>
234
+ </small>
235
+ <?php endif; ?>
236
+
237
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
238
+ <br /><span class="nobr"><?php echo Mage::helper('weee')->__('Total'); ?>:<br /> <?php echo $this->displayPrices($_baseIncl + Mage::helper('weee')->getBaseWeeeTaxInclTax($_item) , $_incl + Mage::helper('weee')->getWeeeTaxInclTax($_item)); ?></span>
239
+ <?php endif; ?>
240
+ <?php endif; ?>
241
+ </span>
242
+ <?php endif; ?>
243
+ </td>
244
+ <?php } ?>
245
+ <?php if(!$flubitOrder) { ?>
246
+ <td class="a-right"><?php echo $this->displayPriceAttribute('tax_amount') ?></td>
247
+ <?php } else { ?>
248
+ <td class="a-right"><?php echo $tax_Rate ?></td>
249
+ <?php } ?>
250
+ <td class="a-right"><?php echo $this->displayPriceAttribute('discount_amount') ?></td>
251
+ <td class="a-right last">
252
+ <?php echo $this->displayPrices(
253
+ $_item->getBaseRowTotal() + $_item->getBaseTaxAmount() + $_item->getBaseHiddenTaxAmount() + $_item->getBaseWeeeTaxAppliedRowAmount() - $_item->getBaseDiscountAmount(),
254
+ $_item->getRowTotal() + $_item->getTaxAmount() + $_item->getHiddenTaxAmount() + $_item->getWeeeTaxAppliedRowAmount() - $_item->getDiscountAmount()
255
+ ) ?>
256
+ </td>
257
+ </tr>
app/design/adminhtml/default/default/template/flubit/sales/order/creditmemo/create/totals/adjustmentsflubit.phtml ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category design
4
+ * @package default_default
5
+ * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
6
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
7
+ */
8
+ ?>
9
+ <?php $_source = $this->getSource() ?>
10
+
11
+ <?php
12
+ $order = $_source->getOrder();
13
+ $read_only_flag = $order->getData('flubit_order_id');
14
+ ?>
15
+
16
+ <?php if ($_source): ?>
17
+ <tr>
18
+ <td class="label"><?php echo $this->getShippingLabel() ?></td>
19
+ <td><input type="text" <?php if($read_only_flag!=NULL): ?>readonly="readonly"<?php endif; ?> name="creditmemo[shipping_amount]" value="<?php echo $this->getShippingAmount()?>" class="input-text not-negative-amount" style="width:60px;text-align:right" id="shipping_amount" /></td>
20
+ </tr>
21
+ <tr>
22
+ <td colspan="2"><div id="shipping_amount_adv"></div></td>
23
+ </tr>
24
+ <tr>
25
+ <td class="label"><?php echo $this->helper('sales')->__('Adjustment Refund') ?></td>
26
+ <td><input type="text" <?php if($read_only_flag!=NULL): ?>readonly="readonly"<?php endif; ?> name="creditmemo[adjustment_positive]" value="<?php echo $_source->getBaseAdjustmentFeePositive()*1 ?>" class="input-text not-negative-amount" style="width:60px;text-align:right" id="adjustment_positive" /></td>
27
+ </tr>
28
+ <tr>
29
+ <td colspan="2"><div id="adjustment_positive_adv"></div></td>
30
+ </tr>
31
+ <tr>
32
+ <td class="label"><?php echo $this->helper('sales')->__('Adjustment Fee') ?></td>
33
+ <td><input type="text" <?php if($read_only_flag!=NULL): ?>readonly="readonly"<?php endif; ?> name="creditmemo[adjustment_negative]" value="<?php echo $_source->getBaseAdjustmentFeeNegative()*1 ?>" class="input-text not-negative-amount" style="width:60px;text-align:right" id="adjustment_negative"/></td>
34
+ </tr>
35
+ <tr>
36
+ <td colspan="2"><div id="adjustment_negative_adv"></div></td>
37
+ </tr>
38
+ <script type="text/javascript">
39
+ //<![CDATA[
40
+ Validation.addAllThese([
41
+ ['not-negative-amount', '<?php echo $this->helper('sales')->__('Please enter positive number in this field.') ?>', function(v) {
42
+ if(v.length)
43
+ return /^\s*\d+([,.]\d+)*\s*%?\s*$/.test(v);
44
+ else
45
+ return true;
46
+ }]
47
+ ]);
48
+
49
+ if ($('shipping_amount')) {
50
+ $('shipping_amount').advaiceContainer = $('shipping_amount_adv');
51
+ unblockSubmit('shipping_amount');
52
+ }
53
+ if ($('adjustment_positive')) {
54
+ $('adjustment_positive').advaiceContainer = $('adjustment_positive_adv');
55
+ unblockSubmit('adjustment_positive');
56
+ }
57
+ if ($('adjustment_negative')) {
58
+ $('adjustment_negative').advaiceContainer = $('adjustment_negative_adv');
59
+ unblockSubmit('adjustment_negative');
60
+ }
61
+
62
+ function unblockSubmit(id) {
63
+ $(id).observe('focus', function(event) {
64
+ if ($$('button[class="scalable update-button disabled"]').size() > 0) {
65
+ enableElements('submit-button');
66
+ }
67
+ });
68
+ }
69
+ //]]>
70
+ </script>
71
+ <?php endif; ?>
app/design/adminhtml/default/default/template/flubit/sales/order/creditmemo/view/items.phtml ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+
4
+ * @category design
5
+ * @package default_default
6
+ * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
7
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
8
+ */
9
+ ?>
10
+ <?php
11
+ $_order = $this->getOrder();
12
+
13
+ $flubitOrder = False;
14
+
15
+ if ($_order->getFlubitOrderId()) {
16
+ $flubitOrder = True;
17
+ }
18
+ ?>
19
+ <?php $_items = $this->getCreditmemo()->getAllItems() ?>
20
+ <div class="grid np">
21
+ <div class="hor-scroll">
22
+ <table cellspacing="0" class="data order-tables">
23
+ <col />
24
+ <col width="1" />
25
+ <col width="1" />
26
+ <col width="1" />
27
+ <col width="1" />
28
+ <col width="1" />
29
+ <col width="1" />
30
+ <thead>
31
+ <tr class="headings">
32
+ <th><?php echo $this->helper('sales')->__('Product') ?></th>
33
+ <?php if($flubitOrder) { ?>
34
+ <th><?php echo $this->helper('sales')->__('Flubit Base Price') ?></th>
35
+ <?php }?>
36
+ <?php if($flubitOrder) { ?>
37
+ <th><?php echo $this->helper('sales')->__('Price Sold At(VAT inc.)') ?></th>
38
+ <?php } else { ?>
39
+ <th><?php echo $this->helper('sales')->__('Price') ?></th>
40
+ <?php } ?>
41
+ <th class="a-center"><?php echo $this->helper('sales')->__('Qty') ?></th>
42
+ <?php if(!$flubitOrder) { ?>
43
+ <th><?php echo $this->helper('sales')->__('Subtotal') ?></th>
44
+ <?php } ?>
45
+ <?php if($flubitOrder) { ?>
46
+ <th><span class="nobr"><?php echo $this->helper('sales')->__('Tax Rate') ?></span></th>
47
+ <?php } else { ?>
48
+ <th><span class="nobr"><?php echo $this->helper('sales')->__('Tax Amount') ?></span></th>
49
+ <?php } ?>
50
+ <th><span class="nobr"><?php echo $this->helper('sales')->__('Discount Amount') ?></span></th>
51
+ <?php if($flubitOrder) { ?>
52
+ <th class="last"><span class="nobr"><?php echo $this->helper('sales')->__('Actual Price Sold At (VAT inc.)') ?></span></th>
53
+ <?php } else { ?>
54
+ <th class="last"><span class="nobr"><?php echo $this->helper('sales')->__('Row Total') ?></span></th>
55
+ <?php } ?>
56
+ </tr>
57
+ </thead>
58
+ <?php $i=0;foreach ($_items as $_item): ?>
59
+ <?php if ($_item->getOrderItem()->getParentItem()) continue; else $i++; ?>
60
+ <tbody class="<?php echo $i%2?'even':'odd' ?>">
61
+ <?php echo $this->getItemHtml($_item) ?>
62
+ <?php echo $this->getItemExtraInfoHtml($_item->getOrderItem()) ?>
63
+ </tbody>
64
+ <?php endforeach; ?>
65
+ </table>
66
+ </div>
67
+ </div>
68
+ <br />
app/design/adminhtml/default/default/template/flubit/sales/order/creditmemo/view/items/renderer/default.phtml ADDED
@@ -0,0 +1,255 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+
4
+ * @category design
5
+ * @package default_default
6
+ * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
7
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
8
+ */
9
+ ?>
10
+ <?php $order = $this->getOrder(); ?>
11
+ <?php
12
+ $flubitOrder = False;
13
+
14
+ $tax_Rate = $order->getFlubitOrderTaxRate();
15
+ if($order->getFlubitOrderId()) {
16
+ $flubitOrder = True;
17
+ }
18
+ ?>
19
+ <?php $_item = $this->getItem() ?>
20
+ <?php
21
+ $original_price = '';
22
+ if($flubitOrder) {
23
+ $itemData = $_item->getOrderItem()->getData();
24
+ $original_price = $itemData['original_price'];
25
+ }
26
+ ?>
27
+ <?php $_item->setStoreId($_item->getCreditMemo()->getStoreId()) ?>
28
+ <?php $this->setPriceDataObject($_item) ?>
29
+ <tr class="border">
30
+ <td><?php echo $this->getColumnHtml($_item, 'name') ?></td>
31
+ <?php if($flubitOrder) { ?>
32
+ <td class="a-right"><?php echo $this->displayPrices($original_price,$original_price) ?></td>
33
+ <?php } ?>
34
+ <td class="a-right">
35
+ <?php if ($this->helper('tax')->displaySalesBothPrices() || $this->helper('tax')->displaySalesPriceExclTax()): ?>
36
+ <span class="price-excl-tax">
37
+ <?php if ($this->helper('tax')->displaySalesBothPrices()): ?>
38
+ <span class="label"><?php echo $this->__('Excl. Tax'); ?>:</span>
39
+ <?php endif; ?>
40
+
41
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales', $_item->getStoreId())): ?>
42
+ <?php
43
+ echo $this->displayPrices(
44
+ $_item->getBasePrice() + $_item->getBaseWeeeTaxAppliedAmount() + $_item->getBaseWeeeTaxDisposition(),
45
+ $_item->getPrice() + $_item->getWeeeTaxAppliedAmount() + $_item->getWeeeTaxDisposition()
46
+ );
47
+ ?>
48
+ <?php else: ?>
49
+ <?php echo $this->displayPrices($_item->getBasePrice(), $_item->getPrice()) ?>
50
+ <?php endif; ?>
51
+
52
+
53
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
54
+ <br/>
55
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales', $_item->getStoreId())): ?>
56
+ <small>
57
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
58
+ <span class="nobr"><?php echo $tax['title']; ?>
59
+ : <?php echo $this->displayPrices($tax['base_amount'], $tax['amount']); ?></span>
60
+ <?php endforeach; ?>
61
+ </small>
62
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
63
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
64
+ <span class="nobr"><small><?php echo $tax['title']; ?>
65
+ : <?php echo $this->displayPrices($tax['base_amount'], $tax['amount']); ?></small></span>
66
+ <?php endforeach; ?>
67
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales', $_item->getStoreId())): ?>
68
+ <small>
69
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
70
+ <span class="nobr"><?php echo $tax['title']; ?>
71
+ : <?php echo $this->displayPrices($tax['base_amount'], $tax['amount']); ?></span>
72
+ <?php endforeach; ?>
73
+ </small>
74
+ <?php endif; ?>
75
+
76
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
77
+ <br/>
78
+ <span class="nobr"><?php echo Mage::helper('weee')->__('Total'); ?>:<br/>
79
+ <?php
80
+ echo $this->displayPrices(
81
+ $_item->getBasePrice() + $_item->getBaseWeeeTaxAppliedAmount() + $_item->getBaseWeeeTaxDisposition(),
82
+ $_item->getPrice() + $_item->getWeeeTaxAppliedAmount() + $_item->getWeeeTaxDisposition()
83
+ );
84
+ ?>
85
+ </span>
86
+ <?php endif; ?>
87
+ <?php endif; ?>
88
+ </span>
89
+ <br/>
90
+ <?php endif; ?>
91
+ <?php if ($this->helper('tax')->displaySalesBothPrices() || $this->helper('tax')->displaySalesPriceInclTax()): ?>
92
+ <span class="price-incl-tax">
93
+ <?php if ($this->helper('tax')->displaySalesBothPrices()): ?>
94
+ <span class="label"><?php echo $this->__('Incl. Tax'); ?>:</span>
95
+ <?php endif; ?>
96
+ <?php $_incl = $this->helper('checkout')->getPriceInclTax($_item); ?>
97
+ <?php $_baseIncl = $this->helper('checkout')->getBasePriceInclTax($_item); ?>
98
+
99
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales', $_item->getStoreId())): ?>
100
+ <?php echo $this->displayPrices($_baseIncl + Mage::helper('weee')->getBaseWeeeTaxInclTax($_item), $_incl + Mage::helper('weee')->getWeeeTaxInclTax($_item)); ?>
101
+ <?php else: ?>
102
+ <?php echo $this->displayPrices($_baseIncl - $_item->getBaseWeeeTaxDisposition(), $_incl - $_item->getWeeeTaxDisposition()) ?>
103
+ <?php endif; ?>
104
+
105
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
106
+ <br/>
107
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales', $_item->getStoreId())): ?>
108
+ <small>
109
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
110
+ <span class="nobr"><?php echo $tax['title']; ?>
111
+ : <?php echo $this->displayPrices($tax['base_amount_incl_tax'], $tax['amount_incl_tax']); ?></span>
112
+ <?php endforeach; ?>
113
+ </small>
114
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
115
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
116
+ <span class="nobr"><small><?php echo $tax['title']; ?>
117
+ : <?php echo $this->displayPrices($tax['base_amount_incl_tax'], $tax['amount_incl_tax']); ?></small></span>
118
+ <?php endforeach; ?>
119
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales', $_item->getStoreId())): ?>
120
+ <small>
121
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
122
+ <span class="nobr"><?php echo $tax['title']; ?>
123
+ : <?php echo $this->displayPrices($tax['base_amount_incl_tax'], $tax['amount_incl_tax']); ?></span>
124
+ <?php endforeach; ?>
125
+ </small>
126
+ <?php endif; ?>
127
+
128
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
129
+ <br/>
130
+ <span class="nobr"><?php echo Mage::helper('weee')->__('Total'); ?>
131
+ :<br/> <?php echo $this->displayPrices($_baseIncl + Mage::helper('weee')->getBaseWeeeTaxInclTax($_item), $_incl + Mage::helper('weee')->getWeeeTaxInclTax($_item)); ?></span>
132
+ <?php endif; ?>
133
+ <?php endif; ?>
134
+ </span>
135
+ <?php endif; ?>
136
+
137
+ </td>
138
+ <td class="a-center"><?php echo $_item->getQty() * 1 ?></td>
139
+ <?php if(!$flubitOrder) { ?>
140
+ <td class="a-right">
141
+ <?php if ($this->helper('tax')->displaySalesBothPrices() || $this->helper('tax')->displaySalesPriceExclTax()): ?>
142
+ <span class="price-excl-tax">
143
+ <?php if ($this->helper('tax')->displaySalesBothPrices()): ?>
144
+ <span class="label"><?php echo $this->__('Excl. Tax'); ?>:</span>
145
+ <?php endif; ?>
146
+
147
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales', $_item->getStoreId())): ?>
148
+ <?php
149
+ echo $this->displayPrices(
150
+ $_item->getBaseRowTotal() + $_item->getBaseWeeeTaxAppliedRowAmount() + $_item->getBaseWeeeTaxRowDisposition(),
151
+ $_item->getRowTotal() + $_item->getWeeeTaxAppliedRowAmount() + $_item->getWeeeTaxRowDisposition()
152
+ );
153
+ ?>
154
+ <?php else: ?>
155
+ <?php echo $this->displayPrices($_item->getBaseRowTotal(), $_item->getRowTotal()) ?>
156
+ <?php endif; ?>
157
+
158
+
159
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
160
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales', $_item->getStoreId())): ?>
161
+ <small>
162
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
163
+ <span class="nobr"><?php echo $tax['title']; ?>
164
+ : <?php echo $this->displayPrices($tax['base_row_amount'], $tax['row_amount']); ?></span>
165
+ <?php endforeach; ?>
166
+ </small>
167
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
168
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
169
+ <span class="nobr"><small><?php echo $tax['title']; ?>
170
+ : <?php echo $this->displayPrices($tax['base_row_amount'], $tax['row_amount']); ?></small></span>
171
+ <?php endforeach; ?>
172
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales', $_item->getStoreId())): ?>
173
+ <small>
174
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
175
+ <span class="nobr"><?php echo $tax['title']; ?>
176
+ : <?php echo $this->displayPrices($tax['base_row_amount'], $tax['row_amount']); ?></span>
177
+ <?php endforeach; ?>
178
+ </small>
179
+ <?php endif; ?>
180
+
181
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
182
+ <br/>
183
+ <span class="nobr"><?php echo Mage::helper('weee')->__('Total'); ?>:<br/>
184
+ <?php
185
+ echo $this->displayPrices(
186
+ $_item->getBaseRowTotal() + $_item->getBaseWeeeTaxAppliedRowAmount() + $_item->getBaseWeeeTaxRowDisposition(),
187
+ $_item->getRowTotal() + $_item->getWeeeTaxAppliedRowAmount() + $_item->getWeeeTaxRowDisposition()
188
+ );
189
+ ?>
190
+ </span>
191
+ <?php endif; ?>
192
+ <?php endif; ?>
193
+ </span>
194
+ <br/>
195
+ <?php endif; ?>
196
+ <?php if ($this->helper('tax')->displaySalesBothPrices() || $this->helper('tax')->displaySalesPriceInclTax()): ?>
197
+ <span class="price-incl-tax">
198
+ <?php if ($this->helper('tax')->displaySalesBothPrices()): ?>
199
+ <span class="label"><?php echo $this->__('Incl. Tax'); ?>:</span>
200
+ <?php endif; ?>
201
+ <?php $_incl = $this->helper('checkout')->getSubtotalInclTax($_item); ?>
202
+ <?php $_baseIncl = $this->helper('checkout')->getBaseSubtotalInclTax($_item); ?>
203
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales', $_item->getStoreId())): ?>
204
+ <?php echo $this->displayPrices($_baseIncl + Mage::helper('weee')->getBaseRowWeeeTaxInclTax($_item), $_incl + Mage::helper('weee')->getRowWeeeTaxInclTax($_item)); ?>
205
+ <?php else: ?>
206
+ <?php echo $this->displayPrices($_baseIncl - $_item->getBaseWeeeTaxRowDisposition(), $_incl - $_item->getWeeeTaxRowDisposition()) ?>
207
+ <?php endif; ?>
208
+
209
+
210
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
211
+
212
+ <br/>
213
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales', $_item->getStoreId())): ?>
214
+ <small>
215
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
216
+ <span class="nobr"><?php echo $tax['title']; ?>
217
+ : <?php echo $this->displayPrices($tax['base_row_amount_incl_tax'], $tax['row_amount_incl_tax']); ?></span>
218
+ <?php endforeach; ?>
219
+ </small>
220
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
221
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
222
+ <span class="nobr"><small><?php echo $tax['title']; ?>
223
+ : <?php echo $this->displayPrices($tax['base_row_amount_incl_tax'], $tax['row_amount_incl_tax']); ?></small></span>
224
+ <?php endforeach; ?>
225
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales', $_item->getStoreId())): ?>
226
+ <small>
227
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
228
+ <span class="nobr"><?php echo $tax['title']; ?>
229
+ : <?php echo $this->displayPrices($tax['base_row_amount_incl_tax'], $tax['row_amount_incl_tax']); ?></span>
230
+ <?php endforeach; ?>
231
+ </small>
232
+ <?php endif; ?>
233
+
234
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
235
+ <br/><span class="nobr"><?php echo Mage::helper('weee')->__('Total'); ?>
236
+ :<br/> <?php echo $this->displayPrices($_baseIncl + Mage::helper('weee')->getBaseRowWeeeTaxInclTax($_item), $_incl + Mage::helper('weee')->getRowWeeeTaxInclTax($_item)); ?></span>
237
+ <?php endif; ?>
238
+ <?php endif; ?>
239
+ </span>
240
+ <?php endif; ?>
241
+ </td>
242
+ <?php } ?>
243
+ <?php if($flubitOrder) { ?>
244
+ <td class="a-right"><?php echo $tax_Rate ?></td>
245
+ <?php } else { ?>
246
+ <td class="a-right"><?php echo $this->displayPriceAttribute('tax_amount') ?></td>
247
+ <?php } ?>
248
+ <td class="a-right"><?php echo $this->displayPriceAttribute('discount_amount') ?></td>
249
+ <td class="a-right last">
250
+ <?php echo $this->displayPrices(
251
+ $_item->getBaseRowTotal() + $_item->getBaseTaxAmount() + $_item->getBaseHiddenTaxAmount() + $_item->getBaseWeeeTaxAppliedRowAmount() - $_item->getBaseDiscountAmount(),
252
+ $_item->getRowTotal() + $_item->getTaxAmount() + $_item->getHiddenTaxAmount() + $_item->getWeeeTaxAppliedRowAmount() - $_item->getDiscountAmount()
253
+ ) ?>
254
+ </td>
255
+ </tr>
app/design/adminhtml/default/default/template/flubit/sales/order/flubittotals.phtml ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package default_default
23
+ * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php
28
+ //Custom
29
+ $_order = $this->getOrder();
30
+ $flubitOrder = False;
31
+ if ($_order->getFlubitOrderId()) {
32
+ $flubitOrder = True;
33
+ }
34
+ ?>
35
+
36
+ <table cellspacing="0" width="100%">
37
+ <col />
38
+ <col width="1" />
39
+ <?php $_totals = $this->getTotals('footer')?>
40
+ <?php if ($_totals):?>
41
+ <tfoot>
42
+
43
+ <?php //Custom ?>
44
+ <?php $grandtotal_flag = false; ?>
45
+ <?php $shipping_flag = false; ?>
46
+ <?php foreach ($this->getTotals('footer') as $_code => $_total): ?>
47
+ <?php //Custom : START ?>
48
+ <?php if($flubitOrder && !in_array($_total->getData('code'), array('shipping', 'shipping_incl', 'refunded', 'grand_total', 'grand_total_incl', 'paid'))): ?>
49
+ <?php continue; ?>
50
+ <?php endif; ?>
51
+
52
+ <?php if($flubitOrder && ($_total->getData('code')=='shipping' || $_total->getData('code')=='shipping_incl')): ?>
53
+ <?php
54
+ if($shipping_flag) {
55
+ continue;
56
+ } else {
57
+ $shipping_flag = true;
58
+ }
59
+ ?>
60
+ <?php $_total->setLabel('Shipping & Handling') ?>
61
+ <?php endif; ?>
62
+
63
+ <?php if($flubitOrder && ($_total->getData('code')=='grand_total') || ($_total->getData('code')=='grand_total_incl')): ?>
64
+ <?php
65
+ if($grandtotal_flag) {
66
+ continue;
67
+ } else {
68
+ $grandtotal_flag = true;
69
+ }
70
+ ?>
71
+ <?php $_total->setLabel('Grand Total (Incl.Tax)') ?>
72
+ <?php endif; ?>
73
+ <?php //Custom : END ?>
74
+
75
+ <?php if ($_total->getBlockName()): ?>
76
+ <?php echo $this->getChildHtml($_total->getBlockName(), false); ?>
77
+ <?php else:?>
78
+ <tr class="<?php echo $_code?>">
79
+ <td <?php echo $this->getLabelProperties()?> class="label">
80
+ <strong><?php echo $this->escapeHtml($_total->getLabel()); ?></strong>
81
+ </td>
82
+ <td <?php echo $this->getValueProperties()?> class="emph">
83
+ <strong><?php echo $this->formatValue($_total) ?></strong>
84
+ </td>
85
+ </tr>
86
+ <?php endif?>
87
+ <?php endforeach?>
88
+ </tfoot>
89
+ <?php endif?>
90
+
91
+ <?php $_totals = $this->getTotals('')?>
92
+ <?php if ($_totals):?>
93
+ <tbody>
94
+
95
+ <?php //Custom ?>
96
+ <?php $grandtotal_flag = false; ?>
97
+ <?php $shipping_flag = false; ?>
98
+ <?php foreach ($_totals as $_code => $_total): ?>
99
+
100
+ <?php //Custom : START ?>
101
+ <?php if($flubitOrder && !in_array($_total->getData('code'), array('shipping', 'shipping_incl', 'grand_total', 'grand_total_incl', 'paid'))): ?>
102
+ <?php continue; ?>
103
+ <?php endif; ?>
104
+
105
+ <?php if($flubitOrder && ($_total->getData('code')=='shipping' || $_total->getData('code')=='shipping_incl')): ?>
106
+ <?php
107
+ if($shipping_flag) {
108
+ continue;
109
+ } else {
110
+ $shipping_flag = true;
111
+ }
112
+ ?>
113
+ <?php $_total->setLabel('Shipping & Handling') ?>
114
+ <?php endif; ?>
115
+
116
+ <?php if($flubitOrder && ($_total->getData('code')=='grand_total') || ($_total->getData('code')=='grand_total_incl')): ?>
117
+ <?php
118
+ if($grandtotal_flag) {
119
+ continue;
120
+ } else {
121
+ $grandtotal_flag = true;
122
+ }
123
+ ?>
124
+ <?php $_total->setLabel('Grand Total (Incl.Tax)') ?>
125
+ <?php endif; ?>
126
+ <?php //Custom : END ?>
127
+
128
+
129
+ <?php if ($_total->getBlockName()): ?>
130
+ <?php echo $this->getChildHtml($_total->getBlockName(), false); ?>
131
+ <?php else:?>
132
+ <tr class="<?php echo $_code?>">
133
+ <td <?php echo $this->getLabelProperties()?> class="label">
134
+ <?php if ($_total->getStrong()):?>
135
+ <strong><?php echo $this->escapeHtml($_total->getLabel()); ?></strong>
136
+ <?php else:?>
137
+ <?php echo $this->escapeHtml($_total->getLabel()); ?>
138
+ <?php endif?>
139
+ </td>
140
+ <?php if ($_total->getStrong()):?>
141
+ <td <?php echo $this->getValueProperties()?> class="emph">
142
+ <strong><?php echo $this->formatValue($_total) ?></strong>
143
+ <?php else:?>
144
+ <td <?php echo $this->getValueProperties()?>>
145
+ <?php echo $this->formatValue($_total) ?>
146
+ <?php endif?>
147
+ </td>
148
+ </tr>
149
+ <?php endif?>
150
+ <?php endforeach?>
151
+ </tbody>
152
+ <?php endif?>
153
+ </table>
app/design/adminhtml/default/default/template/flubit/sales/order/invoice/view/items.phtml ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Sales order invoice view
4
+ *
5
+ */
6
+ ?>
7
+ <?php $order = $this->getOrder(); ?>
8
+ <?php
9
+ $flubitOrder = False;
10
+
11
+ if($order->getFlubitOrderId()) {
12
+ $flubitOrder = True;
13
+ }
14
+ ?>
15
+ <div class="grid np">
16
+ <div class="hor-scroll">
17
+ <table cellspacing="0" class="data order-tables">
18
+ <col />
19
+ <col width="1" />
20
+ <col width="1" />
21
+ <col width="1" />
22
+ <col width="1" />
23
+ <col width="1" />
24
+ <col width="1" />
25
+ <thead>
26
+ <tr class="headings">
27
+ <th><?php echo $this->helper('sales')->__('Product') ?></th>
28
+ <?php if ($flubitOrder) { ?>
29
+ <th><?php echo $this->helper('sales')->__('Flubit Base Price') ?></th>
30
+ <?php } ?>
31
+ <?php if ($flubitOrder) { ?>
32
+ <th><?php echo $this->helper('sales')->__('Price Sold At(VAT inc.)') ?></th>
33
+ <?php } else { ?>
34
+ <th><?php echo $this->helper('sales')->__('Price') ?></th>
35
+ <?php } ?>
36
+ <th class="a-center"><?php echo $this->helper('sales')->__('Qty') ?></th>
37
+ <?php if (!$flubitOrder) { ?>
38
+ <th><?php echo $this->helper('sales')->__('Subtotal') ?></th>
39
+ <?php } ?>
40
+ <?php if (!$flubitOrder) { ?>
41
+ <th><span class="nobr"><?php echo $this->helper('sales')->__('Tax Amount') ?></span></th>
42
+ <?php } else { ?>
43
+ <th><span class="nobr"><?php echo $this->helper('sales')->__('Tax Rate') ?></span></th>
44
+ <?php } ?>
45
+ <th><span class="nobr"><?php echo $this->helper('sales')->__('Discount Amount') ?></span></th>
46
+ <?php if (!$flubitOrder) { ?>
47
+ <th class="last"><span class="nobr"><?php echo $this->helper('sales')->__('Row Total') ?></span></th>
48
+ <?php } else { ?>
49
+ <th class="last"><span class="nobr"><?php echo $this->helper('sales')->__('Actual Price Sold At (VAT inc.)') ?></span></th>
50
+ <?php } ?>
51
+ </tr>
52
+ </thead>
53
+ <?php $_items = $this->getInvoice()->getAllItems() ?>
54
+ <?php $i=0;foreach ($_items as $_item): ?>
55
+ <?php if ($_item->getOrderItem()->getParentItem()) continue; else $i++; ?>
56
+ <tbody class="<?php echo $i%2?'even':'odd' ?>">
57
+ <?php echo $this->getItemHtml($_item) ?>
58
+ <?php echo $this->getItemExtraInfoHtml($_item->getOrderItem()) ?>
59
+ </tbody>
60
+ <?php endforeach; ?>
61
+ </table>
62
+ </div>
63
+ </div>
64
+ <br />
app/design/adminhtml/default/default/template/flubit/sales/order/invoice/view/items/renderer/default.phtml ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Custom flubit sales order invoice view items renderer
5
+ */
6
+ ?>
7
+ <?php $order = $this->getOrder(); ?>
8
+ <?php
9
+
10
+ //$quote = $this->getQuote();
11
+ //print_r($quote);
12
+ $flubitOrder = False;
13
+
14
+ $tax_Rate = $order->getFlubitOrderTaxRate();
15
+ if($order->getFlubitOrderId()) {
16
+ $flubitOrder = True;
17
+ }
18
+ ?>
19
+
20
+ <?php
21
+ $_item = $this->getItem();
22
+ $original_price = '';
23
+ if($flubitOrder) {
24
+ $itemData = $_item->getOrderItem()->getData();
25
+ $original_price = $itemData['original_price'];
26
+ }
27
+ ?>
28
+ <?php $_item->setStoreId($_item->getInvoice()->getStoreId()) ?>
29
+ <?php $this->setPriceDataObject($_item) ?>
30
+ <tr class="border">
31
+ <td><?php echo $this->getColumnHtml($_item, 'name') ?></td>
32
+ <?php if($flubitOrder) { ?>
33
+ <td class="a-right"><?php echo $this->displayPrices($original_price,$original_price) ?></td>
34
+ <?php } ?>
35
+ <td class="a-right">
36
+ <?php if ($this->helper('tax')->displaySalesBothPrices() || $this->helper('tax')->displaySalesPriceExclTax()): ?>
37
+ <span class="price-excl-tax">
38
+ <?php if ($this->helper('tax')->displaySalesBothPrices()): ?>
39
+ <span class="label"><?php echo $this->__('Excl. Tax'); ?>:</span>
40
+ <?php endif; ?>
41
+
42
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales', $_item->getStoreId())): ?>
43
+ <?php
44
+ echo $this->displayPrices(
45
+ $_item->getBasePrice()+$_item->getBaseWeeeTaxAppliedAmount()+$_item->getBaseWeeeTaxDisposition(),
46
+ $_item->getPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition()
47
+ );
48
+ ?>
49
+ <?php else: ?>
50
+ <?php echo $this->displayPrices($_item->getBasePrice(), $_item->getPrice()) ?>
51
+ <?php endif; ?>
52
+
53
+
54
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
55
+ <br />
56
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales', $_item->getStoreId())): ?>
57
+ <small>
58
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
59
+ <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_amount'], $tax['amount']); ?></span>
60
+ <?php endforeach; ?>
61
+ </small>
62
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
63
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
64
+ <span class="nobr"><small><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_amount'], $tax['amount']); ?></small></span>
65
+ <?php endforeach; ?>
66
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales', $_item->getStoreId())): ?>
67
+ <small>
68
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
69
+ <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_amount'], $tax['amount']); ?></span>
70
+ <?php endforeach; ?>
71
+ </small>
72
+ <?php endif; ?>
73
+
74
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
75
+ <br />
76
+ <span class="nobr"><?php echo Mage::helper('weee')->__('Total'); ?>:<br />
77
+ <?php
78
+ echo $this->displayPrices(
79
+ $_item->getBasePrice()+$_item->getBaseWeeeTaxAppliedAmount()+$_item->getBaseWeeeTaxDisposition(),
80
+ $_item->getPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition()
81
+ );
82
+ ?>
83
+ </span>
84
+ <?php endif; ?>
85
+ <?php endif; ?>
86
+ </span>
87
+ <br />
88
+ <?php endif; ?>
89
+ <?php if ($this->helper('tax')->displaySalesBothPrices() || $this->helper('tax')->displaySalesPriceInclTax()): ?>
90
+ <span class="price-incl-tax">
91
+ <?php if ($this->helper('tax')->displaySalesBothPrices()): ?>
92
+ <span class="label"><?php echo $this->__('Incl. Tax'); ?>:</span>
93
+ <?php endif; ?>
94
+ <?php $_incl = $this->helper('checkout')->getPriceInclTax($_item); ?>
95
+ <?php $_baseIncl = $this->helper('checkout')->getBasePriceInclTax($_item); ?>
96
+
97
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales', $_item->getStoreId())): ?>
98
+ <?php echo $this->displayPrices($_baseIncl + Mage::helper('weee')->getBaseWeeeTaxInclTax($_item), $_incl + Mage::helper('weee')->getWeeeTaxInclTax($_item)); ?>
99
+ <?php else: ?>
100
+ <?php echo $this->displayPrices($_baseIncl-$_item->getBaseWeeeTaxDisposition(), $_incl-$_item->getWeeeTaxDisposition()) ?>
101
+ <?php endif; ?>
102
+
103
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
104
+ <br />
105
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales', $_item->getStoreId())): ?>
106
+ <small>
107
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
108
+ <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_amount_incl_tax'], $tax['amount_incl_tax']); ?></span>
109
+ <?php endforeach; ?>
110
+ </small>
111
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
112
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
113
+ <span class="nobr"><small><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_amount_incl_tax'], $tax['amount_incl_tax']); ?></small></span>
114
+ <?php endforeach; ?>
115
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales', $_item->getStoreId())): ?>
116
+ <small>
117
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
118
+ <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_amount_incl_tax'], $tax['amount_incl_tax']); ?></span>
119
+ <?php endforeach; ?>
120
+ </small>
121
+ <?php endif; ?>
122
+
123
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
124
+ <br />
125
+ <span class="nobr"><?php echo Mage::helper('weee')->__('Total'); ?>:<br /> <?php echo $this->displayPrices($_baseIncl + Mage::helper('weee')->getBaseWeeeTaxInclTax($_item) , $_incl + Mage::helper('weee')->getWeeeTaxInclTax($_item)); ?></span>
126
+ <?php endif; ?>
127
+ <?php endif; ?>
128
+ </span>
129
+ <?php endif; ?>
130
+
131
+ </td>
132
+ <td class="a-center"><?php echo $_item->getQty()*1 ?></td>
133
+ <?php if(!$flubitOrder) { ?>
134
+ <td class="a-right">
135
+ <?php if ($this->helper('tax')->displaySalesBothPrices() || $this->helper('tax')->displaySalesPriceExclTax()): ?>
136
+ <span class="price-excl-tax">
137
+ <?php if ($this->helper('tax')->displaySalesBothPrices()): ?>
138
+ <span class="label"><?php echo $this->__('Excl. Tax'); ?>:</span>
139
+ <?php endif; ?>
140
+
141
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales', $_item->getStoreId())): ?>
142
+ <?php
143
+ echo $this->displayPrices(
144
+ $_item->getBaseRowTotal()+$_item->getBaseWeeeTaxAppliedRowAmount()+$_item->getBaseWeeeTaxRowDisposition(),
145
+ $_item->getRowTotal()+$_item->getWeeeTaxAppliedRowAmount()+$_item->getWeeeTaxRowDisposition()
146
+ );
147
+ ?>
148
+ <?php else: ?>
149
+ <?php echo $this->displayPrices($_item->getBaseRowTotal(), $_item->getRowTotal()) ?>
150
+ <?php endif; ?>
151
+
152
+
153
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
154
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales', $_item->getStoreId())): ?>
155
+ <small>
156
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
157
+ <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_row_amount'], $tax['row_amount']); ?></span>
158
+ <?php endforeach; ?>
159
+ </small>
160
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
161
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
162
+ <span class="nobr"><small><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_row_amount'], $tax['row_amount']); ?></small></span>
163
+ <?php endforeach; ?>
164
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales', $_item->getStoreId())): ?>
165
+ <small>
166
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
167
+ <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_row_amount'], $tax['row_amount']); ?></span>
168
+ <?php endforeach; ?>
169
+ </small>
170
+ <?php endif; ?>
171
+
172
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
173
+ <br />
174
+ <span class="nobr"><?php echo Mage::helper('weee')->__('Total'); ?>:<br />
175
+ <?php
176
+ echo $this->displayPrices(
177
+ $_item->getBaseRowTotal()+$_item->getBaseWeeeTaxAppliedRowAmount()+$_item->getBaseWeeeTaxRowDisposition(),
178
+ $_item->getRowTotal()+$_item->getWeeeTaxAppliedRowAmount()+$_item->getWeeeTaxRowDisposition()
179
+ );
180
+ ?>
181
+ </span>
182
+ <?php endif; ?>
183
+ <?php endif; ?>
184
+ </span>
185
+ <br />
186
+ <?php endif; ?>
187
+ <?php if ($this->helper('tax')->displaySalesBothPrices() || $this->helper('tax')->displaySalesPriceInclTax()): ?>
188
+ <span class="price-incl-tax">
189
+ <?php if ($this->helper('tax')->displaySalesBothPrices()): ?>
190
+ <span class="label"><?php echo $this->__('Incl. Tax'); ?>:</span>
191
+ <?php endif; ?>
192
+ <?php $_incl = $this->helper('checkout')->getSubtotalInclTax($_item); ?>
193
+ <?php $_baseIncl = $this->helper('checkout')->getBaseSubtotalInclTax($_item); ?>
194
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales', $_item->getStoreId())): ?>
195
+ <?php echo $this->displayPrices($_baseIncl + Mage::helper('weee')->getBaseRowWeeeTaxInclTax($_item), $_incl + Mage::helper('weee')->getRowWeeeTaxInclTax($_item)); ?>
196
+ <?php else: ?>
197
+ <?php echo $this->displayPrices($_baseIncl-$_item->getBaseWeeeTaxRowDisposition(), $_incl-$_item->getWeeeTaxRowDisposition()) ?>
198
+ <?php endif; ?>
199
+
200
+
201
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
202
+
203
+ <br />
204
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales', $_item->getStoreId())): ?>
205
+ <small>
206
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
207
+ <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_row_amount_incl_tax'], $tax['row_amount_incl_tax']); ?></span>
208
+ <?php endforeach; ?>
209
+ </small>
210
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
211
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
212
+ <span class="nobr"><small><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_row_amount_incl_tax'], $tax['row_amount_incl_tax']); ?></small></span>
213
+ <?php endforeach; ?>
214
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales', $_item->getStoreId())): ?>
215
+ <small>
216
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
217
+ <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_row_amount_incl_tax'], $tax['row_amount_incl_tax']); ?></span>
218
+ <?php endforeach; ?>
219
+ </small>
220
+ <?php endif; ?>
221
+
222
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
223
+ <br /><span class="nobr"><?php echo Mage::helper('weee')->__('Total'); ?>:<br /> <?php echo $this->displayPrices($_baseIncl + Mage::helper('weee')->getBaseWeeeTaxInclTax($_item) , $_incl + Mage::helper('weee')->getWeeeTaxInclTax($_item)); ?></span>
224
+ <?php endif; ?>
225
+ <?php endif; ?>
226
+ </span>
227
+ <?php endif; ?>
228
+ </td>
229
+ <?php } ?>
230
+ <?php if($flubitOrder) { ?>
231
+ <td class="a-right"><?php echo $tax_Rate ?></td>
232
+ <?php } else { ?>
233
+ <td class="a-right"><?php echo $this->displayPriceAttribute('tax_amount') ?></td>
234
+ <?php } ?>
235
+ <td class="a-right"><?php echo $this->displayPriceAttribute('discount_amount') ?></td>
236
+ <td class="a-right last">
237
+ <?php echo $this->displayPrices(
238
+ $_item->getBaseRowTotal() + $_item->getBaseTaxAmount() + $_item->getBaseHiddenTaxAmount() + $_item->getBaseWeeeTaxAppliedRowAmount() - $_item->getBaseDiscountAmount(),
239
+ $_item->getRowTotal() + $_item->getTaxAmount() + $_item->getHiddenTaxAmount() + $_item->getWeeeTaxAppliedRowAmount() - $_item->getDiscountAmount()
240
+ ) ?>
241
+ </td>
242
+ </tr>
app/design/adminhtml/default/default/template/flubit/sales/order/shipment/create/items.phtml ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package default_default
23
+ * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php $_items = $this->getShipment()->getAllItems() ?>
28
+ <?php
29
+ $_order = $this->getOrder();
30
+ $flubitOrder = False;
31
+
32
+ if ($_order->getFlubitOrderId()) {
33
+ $flubitOrder = True;
34
+ }
35
+ ?>
36
+ <div class="grid np">
37
+ <div class="hor-scroll">
38
+ <table cellspacing="0" class="data order-tables">
39
+ <col />
40
+ <col width="1" />
41
+ <col width="1" />
42
+ <?php if (!$this->canShipPartiallyItem()): ?>
43
+ <col width="20" />
44
+ <?php endif; ?>
45
+ <thead>
46
+ <tr class="headings">
47
+ <th><?php echo $this->helper('sales')->__('Product') ?></th>
48
+ <th class="a-center"><?php echo $this->helper('sales')->__('Qty') ?></th>
49
+ <th<?php if ($this->isShipmentRegular()): ?> class="last"<?php endif; ?>><span class="nobr"><?php echo $this->helper('sales')->__('Qty to Ship') ?></span></th>
50
+
51
+ <?php if (!$this->canShipPartiallyItem()): ?>
52
+ <th class="a-center last"><span class="nobr"><?php echo $this->helper('sales')->__('Ship') ?></span></th>
53
+ <?php endif; ?>
54
+
55
+ </tr>
56
+ </thead>
57
+ <?php $_items = $this->getShipment()->getAllItems() ?>
58
+ <?php $_i=0;foreach ($_items as $_item): if ($_item->getOrderItem()->getIsVirtual() || $_item->getOrderItem()->getParentItem()): continue; endif; $_i++ ?>
59
+ <tbody class="<?php echo $_i%2?'odd':'even' ?>">
60
+ <?php echo $this->getItemHtml($_item) ?>
61
+ <?php echo $this->getItemExtraInfoHtml($_item->getOrderItem()) ?>
62
+ </tbody>
63
+ <?php endforeach; ?>
64
+ </table>
65
+ </div>
66
+ </div>
67
+ <br />
68
+ <div class="box-left entry-edit">
69
+ <div class="entry-edit-head"><h4><?php echo $this->__('Shipment Comments') ?></h4></div>
70
+ <fieldset>
71
+ <div id="order-history_form">
72
+ <span class="field-row">
73
+ <label class="normal" for="shipment_comment_text"><?php echo Mage::helper('sales')->__('Shipment Comments') ?></label>
74
+ <textarea id="shipment_comment_text" name="shipment[comment_text]" rows="3" cols="5" style="height:6em; width:99%;"><?php echo $this->getShipment()->getCommentText(); ?></textarea>
75
+ </span>
76
+ <div class="clear"></div>
77
+ </div>
78
+ </fieldset>
79
+ </div>
80
+
81
+ <div class="box-right entry-edit">
82
+ <div class="order-totals">
83
+ <div class="order-totals-bottom">
84
+ <?php if ($this->canCreateShippingLabel()): ?>
85
+ <p>
86
+ <label class="normal" for="create_shipping_label"><?php echo Mage::helper('sales')->__('Create Shipping Label') ?></label>
87
+ <input id="create_shipping_label" name="shipment[create_shipping_label]" value="1" type="checkbox" onclick="toggleCreateLabelCheckbox();" />
88
+ </p>
89
+ <?php endif ?>
90
+ <p>
91
+ <label class="normal" for="notify_customer"><?php echo Mage::helper('sales')->__('Append Comments') ?></label>
92
+ <input id="notify_customer" name="shipment[comment_customer_notify]" value="1" type="checkbox" />
93
+ </p>
94
+ <?php if(!$flubitOrder) { ?>
95
+ <?php if ($this->canSendShipmentEmail()): ?>
96
+ <p>
97
+ <label class="normal" for="send_email"><?php echo Mage::helper('sales')->__('Email Copy of Shipment') ?></label>
98
+ <input id="send_email" name="shipment[send_email]" value="1" type="checkbox" />
99
+ </p>
100
+ <?php endif; ?>
101
+ <?php } ?>
102
+ <div class="a-right">
103
+ <?php echo $this->getChildHtml('submit_button') ?>
104
+ </div>
105
+ </div>
106
+ </div>
107
+ </div>
108
+ <div class="clear"></div>
109
+ <script type="text/javascript">
110
+ //<![CDATA[
111
+ var sendEmailCheckbox = $('send_email');
112
+ if (sendEmailCheckbox) {
113
+ var notifyCustomerCheckbox = $('notify_customer');
114
+ var shipmentCommentText = $('shipment_comment_text');
115
+ Event.observe(sendEmailCheckbox, 'change', bindSendEmail);
116
+ bindSendEmail();
117
+ }
118
+ function bindSendEmail() {
119
+ if (sendEmailCheckbox.checked == true) {
120
+ notifyCustomerCheckbox.disabled = false;
121
+ //shipmentCommentText.disabled = false;
122
+ }
123
+ else {
124
+ notifyCustomerCheckbox.disabled = true;
125
+ //shipmentCommentText.disabled = true;
126
+ }
127
+ }
128
+ function toggleCreateLabelCheckbox() {
129
+ var checkbox = $('create_shipping_label');
130
+ var submitButton = checkbox.up('.order-totals').select('.submit-button span')[0];
131
+ if (checkbox.checked) {
132
+ submitButton.innerText += '...';
133
+ } else {
134
+ submitButton.innerText = submitButton.innerText.replace(/\.\.\.$/, '');
135
+ }
136
+ }
137
+ function submitShipment(btn) {
138
+ var checkbox = $(btn).up('.order-totals').select('#create_shipping_label')[0];
139
+
140
+ if (!validQtyItems()) {
141
+ return;
142
+ }
143
+
144
+ if (checkbox && checkbox.checked) {
145
+ packaging.showWindow();
146
+ } else if(editForm.submit()) {
147
+ disableElements('submit-button');
148
+ }
149
+ }
150
+
151
+ function validQtyItems() {
152
+ var valid = true;
153
+ var errorMessage = '<?php echo $this->helper('sales')->__('Invalid value(s) for Qty to Ship') ?>';
154
+ $$('.qty-item').each(function(item) {
155
+ var val = parseFloat(item.value);
156
+ if (isNaN(val) || val < 0) {
157
+ valid = false;
158
+ alert(errorMessage);
159
+ throw $break;
160
+ }
161
+ });
162
+ return valid;
163
+ }
164
+ //]]>
165
+ </script>
app/design/adminhtml/default/default/template/flubit/sales/order/view/flubititems.phtml ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * @category design
5
+ * @package default_default
6
+ * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
7
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
8
+ */
9
+ ?>
10
+ <?php
11
+ $_order = $this->getOrder();
12
+
13
+ $flubitOrder = False;
14
+
15
+ if($_order->getFlubitOrderId()) {
16
+ $flubitOrder = True;
17
+ }
18
+ ?>
19
+ <div class="grid np">
20
+ <div class="hor-scroll">
21
+ <table cellspacing="0" class="data order-tables">
22
+ <col />
23
+ <col width="1" />
24
+ <col width="1" />
25
+ <col width="1" />
26
+ <col width="1" />
27
+ <col width="1" />
28
+ <col width="1" />
29
+ <col width="1" />
30
+ <col width="1" />
31
+ <col width="1" />
32
+ <thead>
33
+ <tr class="headings">
34
+ <th><?php echo $this->helper('sales')->__('Product') ?></th>
35
+ <th><span class="nobr"><?php echo $this->helper('sales')->__('Item Status') ?></span></th>
36
+ <?php if($flubitOrder) { ?>
37
+ <th><span class="nobr"><?php echo $this->helper('sales')->__('Flubit Base Price') ?></span></th>
38
+ <?php } else { ?>
39
+ <th><span class="nobr"><?php echo $this->helper('sales')->__('Original Price') ?></span></th>
40
+ <?php } ?>
41
+ <?php if($flubitOrder) { ?>
42
+ <th><?php echo $this->helper('sales')->__('Price Sold At(VAT inc.)') ?></th>
43
+ <?php } else { ?>
44
+ <th><?php echo $this->helper('sales')->__('Price') ?></th>
45
+ <?php } ?>
46
+ <th class="a-center"><?php echo $this->helper('sales')->__('Qty') ?></th>
47
+ <?php if(!$flubitOrder) { ?>
48
+ <th><?php echo $this->helper('sales')->__('Subtotal') ?></th>
49
+ <?php } ?>
50
+ <?php if(!$flubitOrder) { ?>
51
+ <th><span class="nobr"><?php echo $this->helper('sales')->__('Tax Amount') ?></span></th>
52
+ <?php } ?>
53
+ <th><span class="nobr"><?php echo $this->helper('sales')->__('Tax Percent') ?></span></th>
54
+ <th><span class="nobr"><?php echo $this->helper('sales')->__('Discount Amount') ?></span></th>
55
+ <?php if($flubitOrder) { ?>
56
+ <th class="last"><span class="nobr"><?php echo $this->helper('sales')->__('Actual Price Sold At(VAT inc.)') ?></span></th>
57
+ <?php } else { ?>
58
+ <th class="last"><span class="nobr"><?php echo $this->helper('sales')->__('Row Total') ?></span></th>
59
+ <?php } ?>
60
+ </tr>
61
+ </thead>
62
+ <?php $_items = $this->getItemsCollection() ?>
63
+ <?php $i=0;foreach ($_items as $_item):?>
64
+ <?php if ($_item->getParentItem()) continue; else $i++;?>
65
+ <tbody class="<?php echo $i%2?'even':'odd' ?>">
66
+ <?php echo $this->getItemHtml($_item) ?>
67
+ <?php echo $this->getItemExtraInfoHtml($_item) ?>
68
+ </tbody>
69
+ <?php endforeach; ?>
70
+ </table>
71
+ </div>
72
+ </div>
73
+ <br />
app/design/adminhtml/default/default/template/flubit/sales/order/view/info.phtml ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+
4
+ * @category design
5
+ * @package default_default
6
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
7
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
8
+ */
9
+ ?>
10
+
11
+ <?php $_order = $this->getOrder() ?>
12
+ <?php
13
+ $orderAdminDate = $this->formatDate($_order->getCreatedAtDate(), 'medium', true);
14
+ $orderStoreDate = $this->formatDate($_order->getCreatedAtStoreDate(), 'medium', true);
15
+ ?>
16
+ <div class="box-left">
17
+ <!--Order Information-->
18
+ <div class="entry-edit">
19
+ <?php
20
+ if ($_order->getEmailSent()):
21
+ $_email = Mage::helper('sales')->__('the order confirmation email was sent');
22
+ else:
23
+ $_email = Mage::helper('sales')->__('the order confirmation email is not sent');
24
+ endif;
25
+ ?>
26
+ <div class="entry-edit-head">
27
+ <?php if ($this->getNoUseOrderLink()): ?>
28
+ <h4 class="icon-head head-account"><?php echo Mage::helper('sales')->__('Order # %s', $_order->getRealOrderId()) ?> (<?php echo $_email ?>)</h4>
29
+ <?php else: ?>
30
+ <a href="<?php echo $this->getViewUrl($_order->getId()) ?>"><?php echo Mage::helper('sales')->__('Order # %s', $_order->getRealOrderId()) ?></a>
31
+ <strong>(<?php echo $_email ?>)</strong>
32
+ <?php endif; ?>
33
+ </div>
34
+ <div class="fieldset">
35
+ <table cellspacing="0" class="form-list">
36
+ <tr>
37
+ <td class="label"><label><?php echo Mage::helper('sales')->__('Order Date') ?></label></td>
38
+ <td class="value"><strong><?php echo $orderAdminDate ?></strong></td>
39
+ </tr>
40
+ <?php if ($orderAdminDate != $orderStoreDate): ?>
41
+ <tr>
42
+ <td class="label"><label><?php echo Mage::helper('sales')->__('Order Date (%s)', $_order->getCreatedAtStoreDate()->getTimezone()) ?></label></td>
43
+ <td class="value"><strong><?php echo $orderStoreDate ?></strong></td>
44
+ </tr>
45
+ <?php endif; ?>
46
+ <tr>
47
+ <td class="label"><label><?php echo Mage::helper('sales')->__('Order Status') ?></label></td>
48
+ <td class="value"><strong><span id="order_status"><?php echo $_order->getStatusLabel() ?></span></strong></td>
49
+ </tr>
50
+ <tr>
51
+ <td class="label"><label><?php echo Mage::helper('sales')->__('Purchased From') ?></label></td>
52
+ <td class="value"><strong><?php echo $this->getOrderStoreName() ?></strong></td>
53
+ </tr>
54
+ <tr>
55
+ <td class="label"><label><?php echo Mage::helper('sales')->__('Flubit Order ID') ?></label></td>
56
+ <td class="value"><strong><?php echo $_order->getFlubitOrderId() ?></strong></td>
57
+ </tr>
58
+ <?php if ($_order->getRelationChildId()): ?>
59
+ <tr>
60
+ <td class="label"><label><?php echo Mage::helper('sales')->__('Link to the New Order') ?></label></td>
61
+ <td class="value"><a href="<?php echo $this->getViewUrl($_order->getRelationChildId()) ?>">
62
+ <?php echo $_order->getRelationChildRealId() ?>
63
+ </a></td>
64
+ </tr>
65
+ <?php endif; ?>
66
+ <?php if ($_order->getRelationParentId()): ?>
67
+ <tr>
68
+ <td class="label"><label><?php echo Mage::helper('sales')->__('Link to the Previous Order') ?></label></td>
69
+ <td class="value"><a href="<?php echo $this->getViewUrl($_order->getRelationParentId()) ?>">
70
+ <?php echo $_order->getRelationParentRealId() ?>
71
+ </a></td>
72
+ </tr>
73
+ <?php endif; ?>
74
+ <?php
75
+ $magentoVersion = Mage::getVersion();
76
+ if (version_compare($magentoVersion, '1.7', '>=')){
77
+ //version is 1.7 or greater
78
+ ?>
79
+ <?php if ($_order->getRemoteIp() && $this->shouldDisplayCustomerIp()): ?>
80
+ <tr>
81
+ <td class="label"><label><?php echo Mage::helper('sales')->__('Placed from IP') ?></label></td>
82
+ <td class="value"><strong><?php echo $_order->getRemoteIp();
83
+ echo ($_order->getXForwardedFor()) ? ' (' . $this->escapeHtml($_order->getXForwardedFor()) . ')' : ''; ?></strong></td>
84
+ </tr>
85
+ <?php endif; ?>
86
+ <?php } else { ?>
87
+ <?php if($_order->getRemoteIp()): ?>
88
+ <tr>
89
+ <td class="label"><label><?php echo Mage::helper('sales')->__('Placed from IP') ?></label></td>
90
+ <td class="value"><strong><?php echo $_order->getRemoteIp(); echo ($_order->getXForwardedFor())?' (' . $_order->getXForwardedFor() . ')':''; ?></strong></td>
91
+ </tr>
92
+ <?php endif; ?>
93
+ <?php } ?>
94
+
95
+ <?php if ($_order->getGlobalCurrencyCode() != $_order->getBaseCurrencyCode()): ?>
96
+ <tr>
97
+ <td class="label"><label><?php echo Mage::helper('sales')->__('%s / %s rate:', $_order->getGlobalCurrencyCode(), $_order->getBaseCurrencyCode()) ?></label></td>
98
+ <td class="value"><strong><?php echo $_order->getBaseToGlobalRate() ?></strong></td>
99
+ </tr>
100
+ <?php endif; ?>
101
+ <?php if ($_order->getBaseCurrencyCode() != $_order->getOrderCurrencyCode()): ?>
102
+ <tr>
103
+ <td class="label"><label><?php echo Mage::helper('sales')->__('%s / %s rate:', $_order->getOrderCurrencyCode(), $_order->getBaseCurrencyCode()) ?></label></td>
104
+ <td class="value"><strong><?php echo $_order->getBaseToOrderRate() ?></strong></td>
105
+ </tr>
106
+ <?php endif; ?>
107
+ </table>
108
+ </div>
109
+ </div>
110
+ </div>
111
+ <div class="box-right">
112
+ <!--Account Information-->
113
+ <div class="entry-edit">
114
+ <div class="entry-edit-head">
115
+ <h4 class="icon-head head-account"><?php echo Mage::helper('sales')->__('Account Information') ?></h4>
116
+ <div class="tools"><?php echo $this->getAccountEditLink() ?></div>
117
+ </div>
118
+ <div class="fieldset">
119
+ <div class="hor-scroll">
120
+ <table cellspacing="0" class="form-list">
121
+ <tr>
122
+ <td class="label"><label><?php echo Mage::helper('sales')->__('Customer Name') ?></label></td>
123
+ <td class="value">
124
+ <?php if ($_customerUrl = $this->getCustomerViewUrl()) : ?>
125
+ <a href="<?php echo $_customerUrl ?>" target="_blank"><strong><?php echo $this->htmlEscape($_order->getCustomerName()) ?></strong></a>
126
+ <?php else: ?>
127
+ <strong><?php echo $this->htmlEscape($_order->getCustomerName()) ?></strong>
128
+ <?php endif; ?>
129
+ </td>
130
+ </tr>
131
+ <tr>
132
+ <td class="label"><label><?php echo Mage::helper('sales')->__('Email') ?></label></td>
133
+ <td class="value"><a href="mailto:<?php echo $_order->getCustomerEmail() ?>"><strong><?php echo $_order->getCustomerEmail() ?></strong></a></td>
134
+ </tr>
135
+ <?php if ($_groupName = $this->getCustomerGroupName()) : ?>
136
+ <tr>
137
+ <td class="label"><label><?php echo Mage::helper('sales')->__('Customer Group') ?></label></td>
138
+ <td class="value"><strong><?php echo $_groupName ?></strong></td>
139
+ </tr>
140
+ <?php endif; ?>
141
+ <?php foreach ($this->getCustomerAccountData() as $data): ?>
142
+ <tr>
143
+ <td class="label"><label><?php echo $data['label'] ?></label></td>
144
+ <td class="value"><strong><?php echo $data['value'] ?></strong></td>
145
+ </tr>
146
+ <?php endforeach; ?>
147
+ </table>
148
+ </div>
149
+ </div>
150
+ </div>
151
+ </div>
152
+ <div class="clear"></div>
153
+
154
+ <div class="box-left">
155
+ <!--Billing Address-->
156
+ <div class="entry-edit">
157
+ <div class="entry-edit-head">
158
+ <h4 class="icon-head head-billing-address"><?php echo Mage::helper('sales')->__('Billing Address') ?></h4>
159
+ <div class="tools"><?php echo $this->getAddressEditLink($_order->getBillingAddress()) ?></div>
160
+ </div>
161
+ <fieldset>
162
+ <address><?php echo $_order->getBillingAddress()->getFormated(true) ?></address>
163
+ </fieldset>
164
+ </div>
165
+ </div>
166
+ <?php if (!$this->getOrder()->getIsVirtual()): ?>
167
+ <div class="box-right">
168
+ <!--Shipping Address-->
169
+ <div class="entry-edit">
170
+ <div class="entry-edit-head">
171
+ <h4 class="icon-head head-shipping-address"><?php echo Mage::helper('sales')->__('Shipping Address') ?></h4>
172
+ <div class="tools"><?php echo $this->getAddressEditLink($_order->getShippingAddress()) ?></div>
173
+ </div>
174
+ <fieldset>
175
+ <address><?php echo $_order->getShippingAddress()->getFormated(true) ?></address>
176
+ </fieldset>
177
+ </div>
178
+ </div>
179
+ <div class="clear"></div>
180
+ <?php endif; ?>
app/design/adminhtml/default/default/template/flubit/sales/order/view/items/renderer/flubitdefault.phtml ADDED
@@ -0,0 +1,259 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * @category design
6
+ * @package default_default
7
+ * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
8
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
9
+ */
10
+ ?>
11
+ <?php $_order = $this->getOrder() ?>
12
+ <?php
13
+ $flubitOrder = False;
14
+ if($_order->getFlubitOrderId()) {
15
+ $flubitOrder = True;
16
+ }
17
+ ?>
18
+ <?php $_item = $this->getItem() ?>
19
+ <?php $this->setPriceDataObject($_item) ?>
20
+ <tr<?php if (!$this->canDisplayGiftmessage()): ?> class="border"<?php endif; ?>>
21
+ <td>
22
+ <?php if ($this->canDisplayContainer()): ?>
23
+ <div id="<?php echo $this->getHtmlId() ?>" class="item-container">
24
+ <?php endif; ?>
25
+ <div class="item-text">
26
+ <?php echo $this->getColumnHtml($_item, 'name') ?>
27
+ </div>
28
+ <?php if ($this->canDisplayContainer()): ?>
29
+ </div>
30
+ <?php endif ?>
31
+ </td>
32
+ <td class="a-center"><?php echo $_item->getStatus() ?></td>
33
+ <td class="a-right"><?php echo $this->displayPriceAttribute('original_price') ?></td>
34
+ <td class="a-right">
35
+ <?php if ($this->helper('tax')->displaySalesBothPrices() || $this->helper('tax')->displaySalesPriceExclTax()): ?>
36
+ <span class="price-excl-tax">
37
+ <?php if ($this->helper('tax')->displaySalesBothPrices()): ?>
38
+ <span class="label"><?php echo $this->__('Excl. Tax'); ?>:</span>
39
+ <?php endif; ?>
40
+
41
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales', $_item->getStoreId())): ?>
42
+ <?php
43
+ echo $this->displayPrices(
44
+ $_item->getBasePrice()+$_item->getBaseWeeeTaxAppliedAmount()+$_item->getBaseWeeeTaxDisposition(),
45
+ $_item->getPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition()
46
+ );
47
+ ?>
48
+ <?php else: ?>
49
+ <?php echo $this->displayPrices($_item->getBasePrice(), $_item->getPrice()) ?>
50
+ <?php endif; ?>
51
+
52
+
53
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
54
+ <br />
55
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales', $_item->getStoreId())): ?>
56
+ <small>
57
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
58
+ <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_amount'], $tax['amount']); ?></span>
59
+ <?php endforeach; ?>
60
+ </small>
61
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
62
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
63
+ <span class="nobr"><small><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_amount'], $tax['amount']); ?></small></span>
64
+ <?php endforeach; ?>
65
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales', $_item->getStoreId())): ?>
66
+ <small>
67
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
68
+ <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_amount'], $tax['amount']); ?></span>
69
+ <?php endforeach; ?>
70
+ </small>
71
+ <?php endif; ?>
72
+
73
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
74
+ <br />
75
+ <span class="nobr"><?php echo Mage::helper('weee')->__('Total'); ?>:<br />
76
+ <?php
77
+ echo $this->displayPrices(
78
+ $_item->getBasePrice()+$_item->getBaseWeeeTaxAppliedAmount()+$_item->getBaseWeeeTaxDisposition(),
79
+ $_item->getPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition()
80
+ );
81
+ ?>
82
+ </span>
83
+ <?php endif; ?>
84
+ <?php endif; ?>
85
+ </span>
86
+ <br />
87
+ <?php endif; ?>
88
+ <?php if ($this->helper('tax')->displaySalesBothPrices() || $this->helper('tax')->displaySalesPriceInclTax()): ?>
89
+ <span class="price-incl-tax">
90
+ <?php if ($this->helper('tax')->displaySalesBothPrices()): ?>
91
+ <span class="label"><?php echo $this->__('Incl. Tax'); ?>:</span>
92
+ <?php endif; ?>
93
+ <?php $_incl = $this->helper('checkout')->getPriceInclTax($_item); ?>
94
+ <?php $_baseIncl = $this->helper('checkout')->getBasePriceInclTax($_item); ?>
95
+
96
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales', $_item->getStoreId())): ?>
97
+ <?php echo $this->displayPrices($_baseIncl + Mage::helper('weee')->getBaseWeeeTaxInclTax($_item), $_incl + Mage::helper('weee')->getWeeeTaxInclTax($_item)); ?>
98
+ <?php else: ?>
99
+ <?php echo $this->displayPrices($_baseIncl-$_item->getBaseWeeeTaxDisposition(), $_incl-$_item->getWeeeTaxDisposition()) ?>
100
+ <?php endif; ?>
101
+
102
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
103
+ <br />
104
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales', $_item->getStoreId())): ?>
105
+ <small>
106
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
107
+ <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_amount_incl_tax'], $tax['amount_incl_tax']); ?></span>
108
+ <?php endforeach; ?>
109
+ </small>
110
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
111
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
112
+ <span class="nobr"><small><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_amount_incl_tax'], $tax['amount_incl_tax']); ?></small></span>
113
+ <?php endforeach; ?>
114
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales', $_item->getStoreId())): ?>
115
+ <small>
116
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
117
+ <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_amount_incl_tax'], $tax['amount_incl_tax']); ?></span>
118
+ <?php endforeach; ?>
119
+ </small>
120
+ <?php endif; ?>
121
+
122
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
123
+ <br />
124
+ <span class="nobr"><?php echo Mage::helper('weee')->__('Total'); ?>:<br /> <?php echo $this->displayPrices($_baseIncl + Mage::helper('weee')->getBaseWeeeTaxInclTax($_item) , $_incl + Mage::helper('weee')->getWeeeTaxInclTax($_item)); ?></span>
125
+ <?php endif; ?>
126
+ <?php endif; ?>
127
+ </span>
128
+ <?php endif; ?>
129
+
130
+ </td>
131
+ <td><?php echo $this->getColumnHtml($_item, 'qty') ?></td>
132
+ <?php if(!$flubitOrder) { ?>
133
+ <td class="a-right">
134
+ <?php if ($this->helper('tax')->displaySalesBothPrices() || $this->helper('tax')->displaySalesPriceExclTax()): ?>
135
+ <span class="price-excl-tax">
136
+ <?php if ($this->helper('tax')->displaySalesBothPrices()): ?>
137
+ <span class="label"><?php echo $this->__('Excl. Tax'); ?>:</span>
138
+ <?php endif; ?>
139
+
140
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales', $_item->getStoreId())): ?>
141
+ <?php
142
+ echo $this->displayPrices(
143
+ $_item->getBaseRowTotal()+$_item->getBaseWeeeTaxAppliedRowAmount()+$_item->getBaseWeeeTaxRowDisposition(),
144
+ $_item->getRowTotal()+$_item->getWeeeTaxAppliedRowAmount()+$_item->getWeeeTaxRowDisposition()
145
+ );
146
+ ?>
147
+ <?php else: ?>
148
+ <?php echo $this->displayPrices($_item->getBaseRowTotal(), $_item->getRowTotal()) ?>
149
+ <?php endif; ?>
150
+
151
+
152
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
153
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales', $_item->getStoreId())): ?>
154
+ <small>
155
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
156
+ <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_row_amount'], $tax['row_amount']); ?></span>
157
+ <?php endforeach; ?>
158
+ </small>
159
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
160
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
161
+ <span class="nobr"><small><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_row_amount'], $tax['row_amount']); ?></small></span>
162
+ <?php endforeach; ?>
163
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales', $_item->getStoreId())): ?>
164
+ <small>
165
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
166
+ <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_row_amount'], $tax['row_amount']); ?></span>
167
+ <?php endforeach; ?>
168
+ </small>
169
+ <?php endif; ?>
170
+
171
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
172
+ <br />
173
+ <span class="nobr"><?php echo Mage::helper('weee')->__('Total'); ?>:<br />
174
+ <?php
175
+ echo $this->displayPrices(
176
+ $_item->getBaseRowTotal()+$_item->getBaseWeeeTaxAppliedRowAmount()+$_item->getBaseWeeeTaxRowDisposition(),
177
+ $_item->getRowTotal()+$_item->getWeeeTaxAppliedRowAmount()+$_item->getWeeeTaxRowDisposition()
178
+ );
179
+ ?>
180
+ </span>
181
+ <?php endif; ?>
182
+ <?php endif; ?>
183
+ </span>
184
+ <br />
185
+ <?php endif; ?>
186
+ <?php if ($this->helper('tax')->displaySalesBothPrices() || $this->helper('tax')->displaySalesPriceInclTax()): ?>
187
+ <span class="price-incl-tax">
188
+ <?php if ($this->helper('tax')->displaySalesBothPrices()): ?>
189
+ <span class="label"><?php echo $this->__('Incl. Tax'); ?>:</span>
190
+ <?php endif; ?>
191
+ <?php $_incl = $this->helper('checkout')->getSubtotalInclTax($_item); ?>
192
+ <?php $_baseIncl = $this->helper('checkout')->getBaseSubtotalInclTax($_item); ?>
193
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales', $_item->getStoreId())): ?>
194
+ <?php echo $this->displayPrices($_baseIncl + Mage::helper('weee')->getBaseRowWeeeTaxInclTax($_item), $_incl + Mage::helper('weee')->getRowWeeeTaxInclTax($_item)); ?>
195
+ <?php else: ?>
196
+ <?php echo $this->displayPrices($_baseIncl-$_item->getBaseWeeeTaxRowDisposition(), $_incl-$_item->getWeeeTaxRowDisposition()) ?>
197
+ <?php endif; ?>
198
+
199
+
200
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
201
+
202
+ <br />
203
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales', $_item->getStoreId())): ?>
204
+ <small>
205
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
206
+ <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_row_amount_incl_tax'], $tax['row_amount_incl_tax']); ?></span>
207
+ <?php endforeach; ?>
208
+ </small>
209
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
210
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
211
+ <span class="nobr"><small><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_row_amount_incl_tax'], $tax['row_amount_incl_tax']); ?></small></span>
212
+ <?php endforeach; ?>
213
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales', $_item->getStoreId())): ?>
214
+ <small>
215
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
216
+ <span class="nobr"><?php echo $tax['title']; ?>: <?php echo $this->displayPrices($tax['base_row_amount_incl_tax'], $tax['row_amount_incl_tax']); ?></span>
217
+ <?php endforeach; ?>
218
+ </small>
219
+ <?php endif; ?>
220
+
221
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales', $_item->getStoreId())): ?>
222
+ <br /><span class="nobr"><?php echo Mage::helper('weee')->__('Total'); ?>:<br /> <?php echo $this->displayPrices($_baseIncl + Mage::helper('weee')->getBaseRowWeeeTaxInclTax($_item),$_incl + Mage::helper('weee')->getRowWeeeTaxInclTax($_item)); ?></span>
223
+ <?php endif; ?>
224
+ <?php endif; ?>
225
+ </span>
226
+ <?php endif; ?>
227
+ </td>
228
+ <?php } ?>
229
+
230
+
231
+ <?php
232
+ /*
233
+ $tax_percentage = $_order->getFlubitOrderTaxRate();
234
+ $tax_rate = (($tax_percentage / 100) + 1);
235
+ $base_price = $_item->getBasePrice();
236
+ $base_tax_amount = $base_price - ($base_price / $tax_rate);
237
+
238
+ $price = $_item->getPrice();
239
+ $tax_amount = $price - ($price / $tax_rate);
240
+ *
241
+ */
242
+ ?>
243
+
244
+ <?php if(!$flubitOrder) { ?>
245
+ <td class="a-right"><?php echo $this->displayPriceAttribute('tax_amount') ?></td>
246
+ <?php } ?>
247
+ <?php if(!$flubitOrder) { ?>
248
+ <td class="a-right"><?php echo $this->displayTaxPercent($_item) ?></td>
249
+ <?php } else { ?>
250
+ <td class="a-right"><?php echo $_order->getFlubitOrderTaxRate(); ?></td>
251
+ <?php } ?>
252
+ <td class="a-right"><?php echo $this->displayPriceAttribute('discount_amount') ?></td>
253
+ <td class="a-right last">
254
+ <?php echo $this->displayPrices(
255
+ $_item->getBaseRowTotal() + $_item->getBaseTaxAmount() + $_item->getBaseHiddenTaxAmount() + $_item->getBaseWeeeTaxAppliedRowAmount() - $_item->getBaseDiscountAmount(),
256
+ $_item->getRowTotal() + $_item->getTaxAmount() + $_item->getHiddenTaxAmount() + $_item->getWeeeTaxAppliedRowAmount() - $_item->getDiscountAmount()
257
+ ); ?>
258
+ </td>
259
+ </tr>
app/design/adminhtml/default/default/template/flubitlog/logdetails.phtml ADDED
@@ -0,0 +1,275 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ //details page to be displayed from here
3
+
4
+ $data = Mage::registry('flubitlog_data')->getData();
5
+ /*
6
+ echo '<pre>';
7
+ echo print_r($data,true);
8
+ echo '</pre>';
9
+ $xml = simplexml_load_string($data['request_xml']);
10
+
11
+ echo '<pre>';
12
+ echo '<textarea width="100%">' . $xml->asXML() . '</textarea>';
13
+
14
+ echo '</pre>'; */
15
+ ?>
16
+
17
+ <div class="content-header">
18
+ <table cellspacing="0">
19
+ <tr>
20
+ <td style="<?php echo $this->getHeaderWidth() ?>"><?php //echo $this->getHeaderHtml() ?>Log Details</td>
21
+ <td class="form-buttons"><?php //echo $this->getButtonsHtml() ?>
22
+ <p class="content-buttons form-buttons">
23
+ <button id="" title="Back" type="button" class="scalable back"
24
+ onclick="setLocation('<?php echo Mage::app()->getRequest()->getServer('HTTP_REFERER'); ?>')" style="">
25
+ <span><span><span>Back</span></span></span>
26
+ </button>
27
+ </p>
28
+ </td>
29
+ </tr>
30
+ </table>
31
+ </div>
32
+
33
+ <?php
34
+ $event = $this->getCurrentEvent();
35
+ ?>
36
+
37
+ <div class="entry-edit">
38
+ <div class="entry-edit">
39
+ <?php if($data['action'] == '1' || $data['action'] == '2' || $data['action'] == '10'){ ?>
40
+ <div class="entry-edit-head">
41
+ <?php if($data['level'] == '1') {?>
42
+ <h4 class="icon-head head-edit-form fieldset-legend"><?php echo $this->__('Success Message'); ?></h4>
43
+ <?php } else { ?>
44
+ <h4 class="icon-head head-edit-form fieldset-legend"><?php echo $this->__('Error Reports'); ?></h4>
45
+ <?php } ?>
46
+ </div>
47
+
48
+ <div id="log_details_fieldset" class="log-details">
49
+ <?php
50
+ if($data['response_xml'] == '' && $data['action'] == '10') {
51
+ $return->html = $data['request_xml'];
52
+ echo ($return->html);
53
+ }
54
+ else if($data['request_xml'] == '') {
55
+ $return->html = $data['response_xml'];
56
+ echo ($return->html);
57
+ } else {
58
+ $xmlObjRes = simplexml_load_string($data['response_xml']);
59
+ if ($xmlObjRes->getName() == 'error') {
60
+
61
+ $errorCode = $xmlObjRes['code'];
62
+ $return->error = $xmlObjRes['message'];
63
+ $return->html = '<div>'.$xmlObjRes['message'].'</div>';
64
+ echo ($return->html);
65
+
66
+ } else if ($xmlObjRes->getName() == 'feed') {
67
+
68
+ if ($xmlObjRes['status'] == 'invalid') {
69
+ $return->error = 'Invalid Feed Sent to flubit';
70
+ $return->html = '<div> The feed sent to Flubit is Invalid, Please check the request, amend the data where appropriate and send again. </div>';
71
+ echo ($return->html);
72
+ }
73
+
74
+ if ($xmlObjRes['status'] == 'processing' || $xmlObjRes['status'] == 'awaiting_validation' || $xmlObjRes['status'] == 'awaiting_processing') {
75
+ $return->html = '<div> The Feed Id : <b>"' . $data['feedid'] . '"</b> is being processed. Please wait for the response. </div>';
76
+ echo ($return->html);
77
+ }
78
+ else if ($xmlObjRes['status'] == 'processed') {
79
+
80
+ if ($xmlObjRes->results->errors->total > 0) {
81
+
82
+ $return->failedCount = $xmlObjRes->results->errors->total;
83
+ $innerTable = '';
84
+ $productAlreadyExist = array();
85
+ foreach ($xmlObjRes->results->errors->sample->error as $error) {
86
+ $productName = '';
87
+ try {
88
+ $productNameObj = Mage::getModel('catalog/product')->loadByAttribute('sku', $error['sku']);
89
+ if (is_object($productNameObj))
90
+ $productName = $productNameObj->getName();
91
+ else {
92
+
93
+ }
94
+ } catch (Exception $e) {
95
+ Mage::log('Unable to get name of product Get Feed Errors ' . $e, null, Chetu_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
96
+ }
97
+ if ($error != '') {
98
+ $return->sku[] = $error['sku'];
99
+ $innerTable .= '<tr>
100
+ <td style="padding:4px;">' . $productName . '</td>
101
+ <td style="padding:4px;">' . $error['sku'] . ' </td>
102
+ <td style="padding:4px;"> ' . $error . ' </td>
103
+ </tr>';
104
+ }
105
+ }
106
+ if ($innerTable != '')
107
+ $return->html = '<div style="color:red;">Following product(s) has failed to sync.</div><br/>
108
+ <style type="text/css">
109
+ #tableOuter{
110
+ border-style: solid;
111
+ border-width: 1px;
112
+ border-collapse: collapse;
113
+ margin: 0;
114
+ padding:4;
115
+ color:red;
116
+ width:100%;
117
+ }
118
+
119
+ #tableOuter th,#tableOuter td{
120
+ border-style: solid;
121
+ border-width: 0 1px 1px 0;
122
+ border-collapse: collapse;
123
+ color:red;
124
+ margin: 0;
125
+ padding:4;
126
+ }
127
+ </style>
128
+ <table id="tableOuter" cellspacing="0" cellpadding="0">
129
+ <tr>
130
+ <th width="250" style="color:red; text-weight:bold;">Product Name</th>
131
+ <th width="250" style="color:red; text-weight:bold;">Product SKU</th>
132
+ <th width="250" style="color:red; text-weight:bold;">Error Message</th>
133
+ </tr>
134
+ ' . $innerTable . '
135
+ </table>';
136
+
137
+ echo ($return->html);
138
+ }
139
+ else {
140
+ $return->html = '<div> The Feed Id <b>"' . $data['feedid'] . '"</b> has been successfully updated. </div>';
141
+ echo ($return->html);
142
+ //Mage::log('Not Inside created block: ' . ' Feed Id = ' . $xmlObj , null, 'temptest.log' );
143
+ }
144
+ }
145
+ }
146
+ }
147
+ ?>
148
+ </div>
149
+
150
+ <?php }// end checking for create and update
151
+ //delete product
152
+ else if($data['action'] == '9') { ?>
153
+ <div class="entry-edit-head">
154
+
155
+ <h4 class="icon-head head-edit-form fieldset-legend"><?php echo $this->__('Success Message'); ?></h4>
156
+ </div>
157
+ <div id="log_details_fieldset" class="log-details">
158
+ <?php
159
+ $return->html = '<div> The Feed Id <b>"' . $data['feedid'] . '"</b> has been successfully deleted. </div>';
160
+ echo ($return->html);
161
+ echo '</div>';
162
+ }
163
+ //fetch order
164
+ else if($data['action'] == '3') { ?>
165
+ <div class="entry-edit-head">
166
+
167
+ <h4 class="icon-head head-edit-form fieldset-legend"><?php echo $this->__('Success Message'); ?></h4>
168
+ </div>
169
+ <div id="log_details_fieldset" class="log-details">
170
+ <?php
171
+ $return->html = '<div> Orders have been successfully fetched from Flubit. </div>';
172
+ echo ($return->html);
173
+ echo '</div>';
174
+ }
175
+ //dispatched order
176
+ else if($data['action'] == '4') { ?>
177
+ <div class="entry-edit-head">
178
+
179
+ <h4 class="icon-head head-edit-form fieldset-legend"><?php echo $this->__('Success Message'); ?></h4>
180
+ </div>
181
+ <div id="log_details_fieldset" class="log-details">
182
+ <?php
183
+ $xmlObjRes = simplexml_load_string($data['response_xml']);
184
+ if ($xmlObjRes->getName() == 'success') {
185
+ $return->html = '<div> Success : Flubit order has been dispatched successfully. </div>';
186
+ } else {
187
+ $return->html = '<div> Error occurred : For detailed information see response text field. </div>';
188
+ }
189
+ echo ($return->html);
190
+ echo '</div>';
191
+
192
+ }
193
+ //refunded order
194
+ else if($data['action'] == '5') {
195
+ $xmlObjRes = simplexml_load_string($data['response_xml']); ?>
196
+ <div class="entry-edit-head">
197
+ <h4 class="icon-head head-edit-form fieldset-legend"><?php if ($xmlObjRes->getName() == 'success') { echo $this->__('Success Message'); } else { echo $this->__('Error Reports'); } ?></h4>
198
+ </div>
199
+ <div id="log_details_fieldset" class="log-details">
200
+ <?php
201
+ if ($xmlObjRes->getName() == 'success') {
202
+ $return->html = '<div> Success : Flubit order has been refunded successfully.</div>';
203
+ } else {
204
+ $return->html = '<div> Error occurred : You might have refunded the order before shipment status reflected on the Flubit or You have generated credit memo before without shipment. </div>';
205
+ }
206
+
207
+ echo ($return->html);
208
+ echo '</div>';
209
+ }
210
+ //cancelled order
211
+ else if($data['action'] == '6') {
212
+ $xmlObjRes = simplexml_load_string($data['response_xml']);
213
+ ?>
214
+ <div class="entry-edit-head">
215
+
216
+ <h4 class="icon-head head-edit-form fieldset-legend"><?php if ($xmlObjRes->getName() == 'success') { echo $this->__('Success Message'); } else { echo $this->__('Error Reports'); } ?></h4>
217
+ </div>
218
+ <div id="log_details_fieldset" class="log-details">
219
+ <?php
220
+
221
+ if ($xmlObjRes->getName() == 'success') {
222
+ $return->html = '<div> Success : Flubit order has been cancelled successfully.</div>';
223
+ } else {
224
+ $return->html = '<div> Error occurred : Flubit order has been already cancelled. </div>';
225
+ }
226
+
227
+ echo ($return->html);
228
+ echo '</div>';
229
+ }
230
+
231
+ //create order in magento
232
+ else if($data['action'] == '7') { ?>
233
+ <div class="entry-edit-head">
234
+
235
+ <h4 class="icon-head head-edit-form fieldset-legend"><?php echo $this->__('Success Message'); ?></h4>
236
+ </div>
237
+ <div id="log_details_fieldset" class="log-details">
238
+ <?php
239
+ $return->html = '<div>' . $data['response_xml'] . '</div>';
240
+ echo ($return->html);
241
+ echo '</div>';
242
+ }
243
+ //Communication logs
244
+ else if($data['action'] == '8' && $feedid = '401 error') { ?>
245
+ <div class="entry-edit-head">
246
+ <h4 class="icon-head head-edit-form fieldset-legend"><?php echo $this->__('Error Report'); ?></h4>
247
+ </div>
248
+ <div id="log_details_fieldset" class="log-details">
249
+ <?php
250
+ $return->html = '<div> Please check your Consumer key and Secret as you could not be authenticated. Make sure you enter the correct Consumer key and Secret to Continue. </div>';
251
+ echo ($return->html);
252
+ echo '</div>';
253
+ } ?>
254
+ </div>
255
+
256
+ <div class="entry-edit">
257
+ <?php if($this->escapeHtml($data['request_xml'])) { ?>
258
+ <div class="entry-edit-head">
259
+ <h4 class="icon-head head-edit-form fieldset-legend"><?php echo $this->__('Request'); ?></h4>
260
+ </div>
261
+
262
+ <div id="log_details_fieldset" class="log-details">
263
+ <textarea readonly style="width:100%; height:300px"><?php if($data['action'] == '1' || $data['action'] == '2' || $data['action'] == '9'){ echo $this->escapeHtml($data['request_xml']); } else { echo $this->stripTags($data['request_xml']); }?></textarea>
264
+ </div>
265
+ <?php } ?>
266
+ <?php if($this->escapeHtml($data['response_xml'])) { ?>
267
+ <div class="entry-edit-head">
268
+ <h4 class="icon-head head-edit-form fieldset-legend"><?php echo $this->__('Response'); ?></h4>
269
+ </div>
270
+ <div id="log_details_fieldset" class="log-details">
271
+ <textarea readonly style="width:100%; height:300px"><?php if($data['action'] == '7'){ echo $this->stripTags($data['response_xml']); } else if($data['action'] == '1' && $data['request_xml'] == '') { echo $this->stripTags($data['response_xml']); } else { echo $this->escapeHtml($data['response_xml']); }?></textarea>
272
+ </div>
273
+ <?php } ?>
274
+ </div>
275
+ </div>
app/etc/modules/Flubit_Flubit.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Flubit_Flubit>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <version>0.2.3</version>
8
+ </Flubit_Flubit>
9
+ </modules>
10
+ </config>
app/etc/modules/Flubit_Flubitlog.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Flubit_Flubitlog>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <version>0.1.0</version>
8
+ </Flubit_Flubitlog>
9
+ </modules>
10
+ </config>
lib/Flubit/Flubit/Client.php ADDED
@@ -0,0 +1,412 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Flubit_Flubit_Client {
4
+ /* CONSTANTS */
5
+
6
+ const BASE_URI = 'http://api.sandbox.weflubit.com';
7
+ const METHOD_TYPE_GET = 'GET';
8
+ const METHOD_TYPE_POST = 'POST';
9
+
10
+ /* PRIVATE VARS */
11
+
12
+ private $client;
13
+ private $timestampFormat = "Y-m-d\TH:i:sO";
14
+ private $orderTimestampFormat = "Y-m-d\TH:i:sP";
15
+ private $apiKey;
16
+ private $apiSecret;
17
+ private $_domain;
18
+
19
+ /**
20
+ * @param string $apiKey
21
+ * @param string $apiSecret
22
+ * @param string $domain
23
+ */
24
+ public function __construct($apiKey, $apiSecret, $domain = 'http://api.sandbox.weflubit.com') {
25
+ $this->apiKey = $apiKey;
26
+ $this->apiSecret = $apiSecret;
27
+ $this->_domain = $domain;
28
+ }
29
+
30
+ /**
31
+ * Create HTTP auth header
32
+ *
33
+ * Uses new nonce and api signature each time it's called
34
+ *
35
+ * @return string
36
+ */
37
+ private function generateAuthToken() {
38
+ try{
39
+ $dateTime = new DateTime('UTC');
40
+ $time = $dateTime->format($this->timestampFormat);
41
+
42
+ $nonce = $this->generateNonce();
43
+
44
+ $signature = base64_encode(
45
+ sha1(
46
+ base64_decode($nonce) . $time . $this->apiSecret, true
47
+ )
48
+ );
49
+ return sprintf(
50
+ "key=\"%s\", signature=\"%s\", nonce=\"%s\", created=\"%s\"", $this->apiKey, $signature, $nonce, $time
51
+ );
52
+ } catch (Exception $e) {
53
+ Mage::log('Generate Authentication token Exception '. $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
54
+ }
55
+ }
56
+
57
+ private function generateNonce() {
58
+ try{
59
+ $nonce = md5(uniqid(mt_rand(), true));
60
+ return $nonce;
61
+ } catch (Exception $e) {
62
+ Mage::log('Post Request Exception ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
63
+ }
64
+ }
65
+
66
+ /**
67
+ *
68
+ * Create
69
+ *
70
+ */
71
+
72
+ /**
73
+ * Return a response from the API based on the uri provided
74
+ *
75
+ * @param mixed $uri
76
+ * @param mixed $payload
77
+ * @param mixed $queryParams
78
+ */
79
+ private function getPostRequest($uri, $payload = null, array $queryParams = array()) {
80
+ try{
81
+ $fields_string = '';
82
+
83
+ $ch = curl_init($this->_domain . '/1/' . $uri);
84
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('content-type: application/atom+xml', 'auth-token: ' . $this->generateAuthToken()));
85
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
86
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
87
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
88
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
89
+ curl_setopt($ch, CURLOPT_TIMEOUT, 20);
90
+
91
+ $response = curl_exec($ch);
92
+ $curl_info = curl_getinfo($ch);
93
+ $http_code = $curl_info['http_code'];
94
+ curl_close($ch);
95
+
96
+ if(($http_code == 200) || ($http_code == 202) || ($http_code == 304)) {
97
+ Mage::log('Post Request HTTP CODE Error ' . $http_code . print_r($curl_info, true) . $response, null, Flubit_Flubit_Helper_Data::FLUBIT_COMMUNICATION);
98
+ } else {
99
+ $helper = Mage::helper('flubit');
100
+ $response = print_r($response, true);
101
+ $feedid = $http_code . ' error';
102
+ $helper->logCommunicationErrors (print_r($curl_info,true),$response,$feedid,"Communication Error");
103
+ Mage::log('Post Request HTTP CODE Success ' . $http_code . print_r($curl_info, true) . $response, null, Flubit_Flubit_Helper_Data::FLUBIT_COMMUNICATION);
104
+ }
105
+
106
+ } catch (Exception $e) {
107
+ Mage::log('Post Request Exception ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
108
+ }
109
+ return $response;
110
+ }
111
+
112
+ /**
113
+ * Create a new product when given valid xml.
114
+ *
115
+ * @param mixed $productXml
116
+ */
117
+ public function createProducts($productXml) {
118
+ try{
119
+ return $this->getPostRequest('products/feed.xml?type=create', $productXml);
120
+ } catch (Exception $e) {
121
+ Mage::log('Post Request Exception ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
122
+ }
123
+ }
124
+
125
+ /**
126
+ *
127
+ * Read
128
+ *
129
+ */
130
+
131
+ /**
132
+ * Return a response from the API based on the uri provided
133
+ *
134
+ * @param mixed $uri
135
+ */
136
+ private function getGetRequest($uri) {
137
+ try{
138
+ $ch = curl_init($this->_domain . '/1/' . $uri);
139
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('content-type: application/atom+xml', 'auth-token: ' . $this->generateAuthToken()));
140
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
141
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
142
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
143
+ curl_setopt($ch, CURLOPT_TIMEOUT, 20);
144
+ //curl_setopt($ch, CURLOPT_HEADER, 1);
145
+ //curl_setopt($ch, CURLINFO_HEADER_OUT , 1);
146
+
147
+ $response = curl_exec($ch);
148
+ $curl_info = curl_getinfo($ch);
149
+ $http_code = $curl_info['http_code'];
150
+ curl_close($ch);
151
+
152
+ if(($http_code == 200) || ($http_code == 202) || ($http_code == 304)) {
153
+ Mage::log('Post Request HTTP CODE Success ' . $http_code . print_r($curl_info, true) . $response, null, Flubit_Flubit_Helper_Data::FLUBIT_COMMUNICATION);
154
+ } else {
155
+ $helper = Mage::helper('flubit');
156
+ $response = print_r($response, true);
157
+ $feedid = $http_code . ' error';
158
+ $helper->logCommunicationErrors (print_r($curl_info,true),$response,$feedid,"Communication Error");
159
+ Mage::log('Post Request HTTP CODE Success ' . $http_code . print_r($curl_info, true) . $response , null, Flubit_Flubit_Helper_Data::FLUBIT_COMMUNICATION);
160
+ }
161
+
162
+ } catch(Exception $e) {
163
+ Mage::log('Get Requsest ', null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
164
+ }
165
+ return $response;
166
+ }
167
+
168
+ /**
169
+ * Return the current user's account status, including number of active products
170
+ *
171
+ */
172
+ public function getAccountStatus() {
173
+ try{
174
+ return $this->getGetRequest('account/status.xml');
175
+ } catch (Exception $e) {
176
+ Mage::log('Post Request Exception ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
177
+ }
178
+ }
179
+
180
+ /**
181
+ * Get orders based on the provided time and status.
182
+ *
183
+ * @param DateTime $from date the order is from
184
+ * @param array $status 'refunded', 'cancelled','dispatched','awaiting_dispatch'
185
+ */
186
+ public function getOrders(DateTime $from, $status) {
187
+ try{
188
+ $orderArray = array();
189
+ $order = array();
190
+ $from = $from->format($this->orderTimestampFormat);
191
+ $data = $this->getGetRequest('orders/filter.xml?from=' .urlencode($from). '&status=' . $status);
192
+
193
+ $data = json_decode(json_encode((array) simplexml_load_string($data)), 1);
194
+
195
+ if (isset($data['order']['@attributes'])) {
196
+ foreach ($data as $order) {
197
+ $orderArray[$order['@attributes']['id']] = $order;
198
+ }
199
+ } else {
200
+ if(count($data['order']) > 0 )
201
+ foreach ($data['order'] as $order) {
202
+ $orderArray[$order['@attributes']['id']] = $order;
203
+ }
204
+ }
205
+ return $orderArray;
206
+ } catch (Exception $e) {
207
+ Mage::log('Get Orders ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
208
+ }
209
+ }
210
+
211
+ /**
212
+ * Get a list of products based on the provided values. If SKU is provided ignore other values.
213
+ *
214
+ * @param mixed $isActive
215
+ * @param mixed $limit
216
+ * @param mixed $page
217
+ * @param mixed $sku
218
+ */
219
+ public function getProducts($isActive, $limit, $page, $sku = null) {
220
+ try {
221
+ if ($sku) {
222
+ return $this->getGetRequest('products/filter.xml?is_active=' . $isActive . '&sku=' . $sku);
223
+ } else {
224
+ return $this->getGetRequest('products/filter.xml?is_active=' . $isActive . '&limit=' . $limit . '&page=' . $page);
225
+ }
226
+ } catch (Exception $e) {
227
+ Mage::log('Get Products ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
228
+ }
229
+ }
230
+
231
+ /**
232
+ * Get product feed by feed ID
233
+ *
234
+ * @param mixed $feedID
235
+ */
236
+ public function getProductsFeed($feedID) {
237
+ try {
238
+ if(($feedID != '') || ($feedID != null)) {
239
+ return $this->getGetRequest('products/feed/' . $feedID . '.xml');
240
+ }
241
+ } catch (Exception $e) {
242
+ Mage::log('Get Product Feed ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
243
+ }
244
+ }
245
+
246
+ /**
247
+ *
248
+ * Update
249
+ *
250
+ */
251
+
252
+ /**
253
+ * Update a product that is already in the system. The only values that can be updated here are is_active, base_price and stock
254
+ *
255
+ * @param mixed $productXml
256
+ */
257
+ public function updateProducts($productXml) {
258
+ try {
259
+ $xml = $this->getPostRequest('products/feed.xml', $productXml);
260
+ return $xml;
261
+ } catch (Exception $e) {
262
+ Mage::log('Update Products ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
263
+ }
264
+ }
265
+
266
+ /**
267
+ * Generate a dispatch order and post it to the api using the flubit ID
268
+ *
269
+ * @param mixed $id
270
+ * @param DateTime $dateTime
271
+ * @param mixed $params
272
+ */
273
+ public function dispatchOrderByFlubitId($id, $dateTime,$params) {
274
+ try {
275
+ if (($id != '') && ($dateTime != '')) {
276
+ if(!is_array($params))
277
+ $params = array();
278
+ $orderXML = $this->generateDispatchOrderPayload($dateTime, $params);
279
+ return $this->getPostRequest('orders/dispatch.xml?flubit_order_id=' . $id, $orderXML);
280
+ } else {
281
+ Mage::log('Id or datetime found blank. Id = ' . $id . ' Datetime' . $dateTime , null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
282
+ }
283
+
284
+ } catch (Exception $e) {
285
+ Mage::log('Dispatch Order By Flubit ID ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
286
+ }
287
+ }
288
+
289
+ /**
290
+ * Generate a dispatch order and post it to the api using the merchant order ID
291
+ * Params =
292
+ *
293
+ * @param mixed $id
294
+ * @param DateTime $dateTime
295
+ * @param mixed $params
296
+ */
297
+ public function dispatchOrderByMerchantOrderId($id, DateTime $dateTime, array $params) {
298
+ try{
299
+ $orderXML = $this->generateDispatchOrderPayload($dateTime, $params);
300
+ return $this->getPostRequest('orders/dispatch.xml?merchant_order_id=' . $id, $orderXML);
301
+ } catch (Exception $e) {
302
+ Mage::log('Dispatch Order By Merchant Order ID ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
303
+ }
304
+ }
305
+
306
+ /**
307
+ * {@inheritdoc}
308
+ */
309
+ public function cancelOrderByFlubitId($id, $reason) {
310
+ try{
311
+ if($id) {
312
+ $orderXML = $this->generateCancelOrderPayload($reason);
313
+ return $this->getPostRequest('orders/cancel.xml?flubit_order_id=' . $id, $orderXML);
314
+ } else {
315
+ Mage::log('Cancel order by flubit ID. Id found null. flubit ID ' . $id , null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
316
+ }
317
+
318
+ } catch (Exception $e) {
319
+ Mage::log('Cancel order by flubit ID ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
320
+ }
321
+ }
322
+
323
+ /**
324
+ * {@inheritdoc}
325
+ */
326
+ public function cancelOrderByMerchantOrderId($id, $reason) {
327
+ try {
328
+ $payload = $this->generateCancelOrderPayload($reason);
329
+
330
+ $request = $this->getPostRequest(
331
+ 'orders/cancel.xml', $payload, array(
332
+ 'merchant_order_id' => $id
333
+ )
334
+ );
335
+
336
+ return $this->call($request);
337
+ } catch (Exception $e) {
338
+ Mage::log('cancelOrderByMerchantOrderId ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
339
+ }
340
+ }
341
+
342
+ /**
343
+ * {@inheritdoc}
344
+ */
345
+ public function refundOrderByFlubitId($id, $reason) {
346
+ try {
347
+ $orderXML = $this->generateRefundOrderPayload($reason);
348
+ return $this->getPostRequest('orders/refund.xml?flubit_order_id=' . $id, $orderXML);
349
+ } catch (Exception $e) {
350
+ Mage::log('refundOrderByFlubitId ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
351
+ }
352
+ }
353
+
354
+ /**
355
+ * {@inheritdoc}
356
+ */
357
+ public function refundOrderByMerchantOrderId($id) {
358
+ try {
359
+ $request = $this->getPostRequest(
360
+ 'orders/refund.xml', null, array(
361
+ 'merchant_order_id' => $id
362
+ )
363
+ );
364
+
365
+ return $this->call($request);
366
+ } catch (Exception $e) {
367
+ Mage::log('refundOrderByMerchantOrderId ' . $e, null, Flubit_Flubit_Helper_Data::FLUBIT_EXCEPTIONS);
368
+ }
369
+ }
370
+
371
+ /**
372
+ * Generate the xml for a dispatch order
373
+ *
374
+ * @param DateTime $dateTime
375
+ * @param mixed $params
376
+ */
377
+ private function generateDispatchOrderPayload($dateTime, array $params) {
378
+ $courier = isset($params['courier']) ? $params['courier'] : '';
379
+ $consignmentNumber = isset($params['consignment_number']) ? $params['consignment_number'] : '';
380
+ $trackingUrl = isset($params['tracking_url']) ? $params['tracking_url'] : '';
381
+
382
+ return <<<EOH
383
+ <?xml version="1.0" encoding="UTF-8"?>
384
+ <dispatch>
385
+ <dispatched_at>{$dateTime}</dispatched_at>
386
+ <courier>{$courier}</courier>
387
+ <consignment_number>{$consignmentNumber}</consignment_number>
388
+ <tracking_url>{$trackingUrl}</tracking_url>
389
+ </dispatch>
390
+ EOH;
391
+ //$dateTime->format($this->timestampFormat)
392
+ }
393
+
394
+ private function generateCancelOrderPayload($reason) {
395
+ return <<<EOH
396
+ <?xml version="1.0" encoding="UTF-8"?>
397
+ <cancel>
398
+ <reason>{$reason}</reason>
399
+ </cancel>
400
+ EOH;
401
+ }
402
+
403
+ private function generateRefundOrderPayload($reason) {
404
+ return <<<EOH
405
+ <?xml version="1.0" encoding="UTF-8"?>
406
+ <refund>
407
+ <reason>{$reason}</reason>
408
+ </refund>
409
+ EOH;
410
+ }
411
+
412
+ }
lib/Flubit/Flubit/ClientInterface.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Flubit\Client;
4
+
5
+ class Flubit_Flubit_ClientInterface
6
+ {
7
+ /**
8
+ * @return \SimpleXMLElement
9
+ */
10
+ public function getAccountStatus(){}
11
+
12
+ /**
13
+ * @param string $id
14
+ * @param \DateTime $dateTime
15
+ * @param array $params
16
+ *
17
+ * @return \SimpleXMLElement
18
+ */
19
+ public function dispatchOrderByFlubitId($id, DateTime $dateTime, array $params){}
20
+
21
+ /**
22
+ * @param string $id
23
+ * @param \DateTime $dateTime
24
+ * @param array $params
25
+ *
26
+ * @return \SimpleXMLElement
27
+ */
28
+ public function dispatchOrderByMerchantOrderId($id, DateTime $dateTime, array $params){}
29
+
30
+ /**
31
+ * @param string $id
32
+ * @param string $reason
33
+ *
34
+ * @return \SimpleXMLElement
35
+ */
36
+ public function cancelOrderByFlubitId($id, $reason);
37
+
38
+ /**
39
+ * @param string $id
40
+ * @param string $reason
41
+ *
42
+ * @return \SimpleXMLElement
43
+ */
44
+ public function cancelOrderByMerchantOrderId($id, $reason);
45
+
46
+ /**
47
+ * @param string $id
48
+ *
49
+ * @return \SimpleXMLElement
50
+ */
51
+ public function refundOrderByFlubitId($id);
52
+
53
+ /**
54
+ * @param string $id
55
+ *
56
+ * @return \SimpleXMLElement
57
+ */
58
+ public function refundOrderByMerchantOrderId($id);
59
+
60
+ /**
61
+ * @param \DateTime $from
62
+ * @param string $status
63
+ *
64
+ * @return \SimpleXMLElement
65
+ */
66
+ public function getOrders(\DateTime $from, $status);
67
+
68
+ /**
69
+ * @param boolean $isActive
70
+ * @param integer $limit
71
+ * @param integer $page
72
+ *
73
+ * @return \SimpleXMLElement
74
+ */
75
+ public function getProducts($isActive, $limit, $page, $sku = null);
76
+
77
+ /**
78
+ * @param string $feedID
79
+ *
80
+ * @return \SimpleXMLElement
81
+ */
82
+ public function getProductsFeed($feedID);
83
+
84
+ /**
85
+ * @param $productXml
86
+ *
87
+ * @return \SimpleXMLElement
88
+ */
89
+ public function createProducts($productXml);
90
+
91
+ /**
92
+ * @param $productXml
93
+ *
94
+ * @return \SimpleXMLElement
95
+ */
96
+ public function updateProducts($productXml);
97
+ }
lib/Flubit/Flubit/ClientX.php ADDED
@@ -0,0 +1,372 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ //namespace flubitApi;
3
+ namespace Flubit\Client;
4
+
5
+ use Flubit\Exception\BadMethodCallException;
6
+ use Flubit\Exception\UnauthorizedException;
7
+ use Guzzle\Http\Client as GuzzleClient;
8
+ use Guzzle\Http\Exception\BadResponseException;
9
+ use Guzzle\Http\Message\RequestInterface;
10
+
11
+ //include_once('ClientInterface.php');
12
+ if (!class_exists('Flubit_Flubit_Client')){
13
+ class Flubit_Flubit_Client //implements Flubit_Flubit_ClientInterface
14
+ {
15
+
16
+ /* CONSTANTS */
17
+ const BASE_URI = 'api.sandbox.weflubit.com';
18
+ const METHOD_TYPE_GET = 'GET';
19
+ const METHOD_TYPE_POST = 'POST';
20
+
21
+ /* PRIVATE VARS */
22
+ /**
23
+ * @var \Guzzle\Http\Client
24
+ */
25
+ private $client;
26
+
27
+ /**
28
+ * @var string
29
+ */
30
+ private $timestampFormat = "Y-m-d\TH:i:sO";
31
+
32
+ /**
33
+ * @var string
34
+ */
35
+ private $apiKey;
36
+
37
+ /**
38
+ * @var string
39
+ */
40
+ private $apiSecret;
41
+
42
+ /**
43
+ * @param string $apiKey
44
+ * @param string $apiSecret
45
+ * @param string $domain
46
+ */
47
+ public function __construct($apiKey, $apiSecret, $domain = 'api.sandbox.weflubit.com')
48
+ {
49
+ $this->apiKey = $apiKey;
50
+ $this->apiSecret = $apiSecret;
51
+
52
+ $this->client = new GuzzleClient('http://{domain}/{version}', array(
53
+ 'domain' => $domain,
54
+ 'version' => '1'
55
+ ));
56
+ }
57
+
58
+ /**
59
+ * {@inheritdoc}
60
+ */
61
+ public function getAccountStatus()
62
+ {
63
+ $request = $this->getGetRequest('account/status.xml');
64
+
65
+ return $this->call($request);
66
+ }
67
+
68
+ /**
69
+ * {@inheritdoc}
70
+ */
71
+ public function dispatchOrderByFlubitId($id, DateTime $dateTime, array $params)
72
+ {
73
+ $payload = $this->generateDispatchOrderPayload($dateTime, $params);
74
+
75
+ $request = $this->getPostRequest(
76
+ 'orders/dispatch.xml',
77
+ $payload,
78
+ array(
79
+ 'flubit_order_id' => $id
80
+ )
81
+ );
82
+
83
+ return $this->call($request);
84
+ }
85
+
86
+ /**
87
+ * {@inheritdoc}
88
+ */
89
+ public function dispatchOrderByMerchantOrderId($id, DateTime $dateTime, array $params)
90
+ {
91
+ $payload = $this->generateDispatchOrderPayload($dateTime, $params);
92
+
93
+ $request = $this->getPostRequest(
94
+ 'orders/dispatch.xml',
95
+ $payload,
96
+ array(
97
+ 'merchant_order_id' => $id
98
+ )
99
+ );
100
+
101
+ return $this->call($request);
102
+ }
103
+
104
+ /**
105
+ * {@inheritdoc}
106
+ */
107
+ public function cancelOrderByFlubitId($id, $reason)
108
+ {
109
+ $payload = $this->generateCancelOrderPayload($reason);
110
+
111
+ $request = $this->getPostRequest(
112
+ 'orders/cancel.xml',
113
+ $payload,
114
+ array(
115
+ 'flubit_order_id' => $id
116
+ )
117
+ );
118
+
119
+ return $this->call($request);
120
+ }
121
+
122
+ /**
123
+ * {@inheritdoc}
124
+ */
125
+ public function cancelOrderByMerchantOrderId($id, $reason)
126
+ {
127
+ $payload = $this->generateCancelOrderPayload($reason);
128
+
129
+ $request = $this->getPostRequest(
130
+ 'orders/cancel.xml',
131
+ $payload,
132
+ array(
133
+ 'merchant_order_id' => $id
134
+ )
135
+ );
136
+
137
+ return $this->call($request);
138
+ }
139
+
140
+ /**
141
+ * {@inheritdoc}
142
+ */
143
+ public function refundOrderByFlubitId($id)
144
+ {
145
+ $request = $this->getPostRequest(
146
+ 'orders/refund.xml',
147
+ null,
148
+ array(
149
+ 'flubit_order_id' => $id
150
+ )
151
+ );
152
+
153
+ return $this->call($request);
154
+ }
155
+
156
+ /**
157
+ * {@inheritdoc}
158
+ */
159
+ public function refundOrderByMerchantOrderId($id)
160
+ {
161
+ $request = $this->getPostRequest(
162
+ 'orders/refund.xml',
163
+ null,
164
+ array(
165
+ 'merchant_order_id' => $id
166
+ )
167
+ );
168
+
169
+ return $this->call($request);
170
+ }
171
+
172
+ /**
173
+ * {@inheritdoc}
174
+ */
175
+ public function getOrders(DateTime $from, $status)
176
+ {
177
+ $request = $this->getGetRequest(
178
+ 'orders/filter.xml',
179
+ array(
180
+ 'from' => $from->format($this->timestampFormat),
181
+ 'status' => $status
182
+ )
183
+ );
184
+
185
+ return $this->call($request);
186
+ }
187
+
188
+ public function getProducts($isActive, $limit, $page, $sku = null)
189
+ {
190
+ $url = '/1/products/filter.xml';
191
+
192
+ if ($sku) {
193
+ $request = $this->getGetRequest(
194
+ $url,
195
+ array(
196
+ 'is_active' => $isActive,
197
+ 'sku' => $sku,
198
+ )
199
+ );
200
+ } else {
201
+ $request = $this->getGetRequest(
202
+ $url,
203
+ array(
204
+ 'is_active' => $isActive,
205
+ 'limit' => $limit,
206
+ 'page' => $page,
207
+ )
208
+ );
209
+ }
210
+
211
+ return $this->call($request);
212
+ }
213
+
214
+ /**
215
+ * {@inheritdoc}
216
+ */
217
+ public function getProductsFeed($feedID)
218
+ {
219
+ $request = $this->getGetRequest(
220
+ sprintf('products/feed/%s.xml', $feedID)
221
+ );
222
+
223
+ return $this->call($request);
224
+ }
225
+
226
+ /**
227
+ * {@inheritdoc}
228
+ */
229
+ public function createProducts($productXml)
230
+ {
231
+ Mage::log($productXml ,null, 'hum.txt');
232
+ $request = $this->getPostRequest(
233
+ 'products/feed.xml',
234
+ $productXml,
235
+ array(
236
+ 'type' => 'create'
237
+ )
238
+ );
239
+ Mage::log($request ,null, 'hum.txt');
240
+ return $this->call($request);
241
+ }
242
+
243
+ /**
244
+ * {@inheritdoc}
245
+ */
246
+ public function updateProducts($productXml)
247
+ {
248
+ $request = $this->getPostRequest(
249
+ 'products/feed.xml',
250
+ $productXml
251
+ );
252
+
253
+ return $this->call($request);
254
+ }
255
+
256
+ private function generateDispatchOrderPayload(DateTime $dateTime, array $params)
257
+ {
258
+ $courier = isset($params['courier']) ? $params['courier'] : '';
259
+ $consignmentNumber = isset($params['consignment_number']) ? $params['consignment_number'] : '';
260
+ $trackingUrl = isset($params['tracking_url']) ? $params['tracking_url'] : '';
261
+
262
+ return <<<EOH
263
+ <?xml version="1.0" encoding="UTF-8"?>
264
+ <dispatch>
265
+ <dispatched_at>{$dateTime->format($this->timestampFormat)}</dispatched_at>
266
+ <courier>{$courier}</courier>
267
+ <consignment_number>{$consignmentNumber}</consignment_number>
268
+ <tracking_url>{$trackingUrl}</tracking_url>
269
+ </dispatch>
270
+ EOH;
271
+ }
272
+
273
+ private function generateCancelOrderPayload($reason)
274
+ {
275
+ return <<<EOH
276
+ <?xml version="1.0" encoding="UTF-8"?>
277
+ <cancel>
278
+ <reason>{$reason}</reason>
279
+ </cancel>
280
+ EOH;
281
+ }
282
+
283
+ private function call(RequestInterface $request)
284
+ {
285
+ try {
286
+ return $request
287
+ ->send(array($request))
288
+ ->xml();
289
+
290
+ } catch (BadResponseException $e) {
291
+
292
+ $statusCode = $e->getResponse()->getStatusCode();
293
+ $xml = $e->getResponse()->xml();
294
+ $msg = (string)$xml['message'];
295
+
296
+ if ($statusCode === 401) {
297
+
298
+ throw new UnauthorizedException($msg, (int)$xml['code']);
299
+ } else {
300
+
301
+ throw new BadMethodCallException($msg, $statusCode);
302
+ }
303
+ }
304
+ }
305
+
306
+ private function getGetRequest($uri, array $queryParams = array())
307
+ {
308
+ return $this->client
309
+ ->get(
310
+ sprintf('%s?%s', $uri, http_build_query($queryParams)),
311
+ array(
312
+ 'accept' => 'application/xml',
313
+ 'auth-token' => $this->generateAuthToken()
314
+ ),
315
+ array('allow_redirects' => false)
316
+ );
317
+ }
318
+
319
+ private function getPostRequest($uri, $payload = null, array $queryParams = array())
320
+ {
321
+ return $this->client
322
+ ->post(
323
+ sprintf('%s?%s', $uri, http_build_query($queryParams)),
324
+ array(
325
+ 'accept' => 'application/xml',
326
+ 'auth-token' => $this->generateAuthToken()
327
+ ),
328
+ $payload,
329
+ array('allow_redirects' => false)
330
+ );
331
+ }
332
+
333
+ /**
334
+ * Create HTTP auth header
335
+ *
336
+ * Uses new nonce and api signature each time it's called
337
+ *
338
+ * @return string
339
+ */
340
+ private function generateAuthToken()
341
+ {
342
+ $dateTime = new DateTime('UTC');
343
+ $time = $dateTime->format($this->timestampFormat);
344
+ $nonce = $this->generateNonce();
345
+
346
+ $signature = base64_encode(
347
+ sha1(
348
+ base64_decode($nonce) . $time . $this->apiSecret,
349
+ true
350
+ )
351
+ );
352
+
353
+ return sprintf(
354
+ "key=\"%s\", signature=\"%s\", nonce=\"%s\", created=\"%s\"",
355
+ $this->apiKey,
356
+ $signature,
357
+ $nonce,
358
+ $time
359
+ );
360
+ }
361
+
362
+ /**
363
+ * @return string
364
+ */
365
+ private function generateNonce()
366
+ {
367
+ $nonce = md5(uniqid(mt_rand(), true));
368
+
369
+ return $nonce;
370
+ }
371
+ }
372
+ }
lib/Flubit/Flubit/MWSClient.php ADDED
@@ -0,0 +1,277 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ //namespace flubitApi;
3
+
4
+ class Flubit_Flubit_MWSClient
5
+ {
6
+
7
+ /* CONSTANTS */
8
+ const BASE_URI = 'api.sandbox.weflubit.com';
9
+ const METHOD_TYPE_GET = 'GET';
10
+ const METHOD_TYPE_POST = 'POST';
11
+
12
+ /* PRIVATE VARS */
13
+ private $apiKey;
14
+ private $apiSecret;
15
+ //private $timestampFormat = "Y-m-d\TH:i:sO";
16
+
17
+ /**
18
+ * Initial API call, establishes connection with seletced API call
19
+ *
20
+ * @param mixed $apiKey
21
+ * @param mixed $apiSecret
22
+ * @return flubitClient
23
+ */
24
+ public function __construct($apiKey, $apiSecret) {
25
+ $this->apiKey = $apiKey;
26
+ $this->apiSecret = $apiSecret;
27
+ }
28
+
29
+ /**
30
+ * Status is used to varify the account and will return either an staus message or product count.
31
+ *
32
+ * @param mixed $returnType
33
+ */
34
+ public function status($returnType) {
35
+ $flbStatus = $this->queryApi('1/account/status.xml', self::METHOD_TYPE_GET);
36
+ if($returnType == "message"){
37
+ $result = new SimpleXMLElement($flbStatus);
38
+ if(!$result['code']){
39
+ $flubitStatus = "Account Verified and Active!";
40
+ } else {
41
+ if($result['code'] == 144){
42
+ $flubitStatus = "Account Not Verified!";
43
+ } else{
44
+ $flubitStatus = "Error: ".$result['code'] ." - ". $result['message'];
45
+ }
46
+ }
47
+
48
+ return $flubitStatus;
49
+
50
+ } elseif($returnType == "count"){
51
+ $result = new SimpleXMLElement($flbStatus);
52
+ echo $result;
53
+ if(!$result['code']){
54
+ if($result['active_products'] == 0){$flubitStatus = "No Products";}
55
+ } else {
56
+ if($result['code'] == 144){
57
+ $flubitStatus = "Account Not Verified!";
58
+ } else{
59
+ $flubitStatus = "Error: ".$result['code'] ." - ". $result['message'];
60
+ }
61
+ }
62
+ return $flubitStatus;
63
+ } else {
64
+ return $flbStatus;
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Query API feed method in create mode
70
+ *
71
+ * @param string $xmlString
72
+ * @return string
73
+ */
74
+ public function createProduct($xmlString)
75
+ {
76
+ Mage::log($xmlString ,null, 'hum.txt');
77
+ $response = $this->queryApi(
78
+ '1/products/feed.xml?type=create',
79
+ self::METHOD_TYPE_POST,
80
+ $xmlString
81
+ );
82
+
83
+ Mage::log('Response: '.$response ,null, 'hum.txt');
84
+ return $response;
85
+ }
86
+
87
+ /**
88
+ * Query API feed method in update mode
89
+ *
90
+ * @param string $xmlString
91
+ * @return string
92
+ */
93
+ public function updateProduct($xmlString)
94
+ {
95
+ return $this->queryApi(
96
+ '1/products/feed.xml',
97
+ self::METHOD_TYPE_POST,
98
+ $xmlString
99
+ );
100
+ }
101
+
102
+ /**
103
+ * Query API feed method with feed ID
104
+ *
105
+ * @param integer $feedID
106
+ * @return string
107
+ */
108
+ public function getProductFeedStatus($feedID)
109
+ {
110
+ return $this->queryApi(
111
+ sprintf("1/products/feed/%s.xml", $feedID),
112
+ self::METHOD_TYPE_GET
113
+ );
114
+ }
115
+
116
+ /**
117
+ * Query API filter method
118
+ *
119
+ * @param string $from
120
+ * @param string $status
121
+ * @return string
122
+ */
123
+ public function filterOrders($from, $status=null)
124
+ {
125
+ $params = array('from' => $from, 'status' => $status);
126
+
127
+ return $this->queryApi(
128
+ '1/orders/filter.xml',
129
+ self::METHOD_TYPE_GET,
130
+ null,
131
+ $params
132
+ );
133
+ }
134
+
135
+ /**
136
+ * Query API dispatch method
137
+ *
138
+ * @param string $xmlString
139
+ * @param string $orderId
140
+ * @param string $type
141
+ * @return string
142
+ */
143
+ public function dispatchOrder($xmlString, $orderId, $type = 'flubit')
144
+ {
145
+ $orderTypeKey = sprintf('%s_order_id', $type);
146
+ $params = array($orderTypeKey => $orderId);
147
+
148
+ return $this->queryApi(
149
+ '1/orders/dispatch.xml',
150
+ self::METHOD_TYPE_POST,
151
+ $xmlString,
152
+ $params
153
+ );
154
+ }
155
+
156
+ /**
157
+ * Query API cancel method
158
+ *
159
+ * @param string $xmlString
160
+ * @param string $orderId
161
+ * @param string $type
162
+ * @return string
163
+ */
164
+ public function cancelOrder($xmlString, $orderId, $type = 'flubit')
165
+ {
166
+ $orderTypeKey = sprintf('%s_order_id', $type);
167
+ $params = array($orderTypeKey => $orderId);
168
+
169
+ return $this->queryApi(
170
+ '1/orders/cancel.xml',
171
+ self::METHOD_TYPE_POST,
172
+ $xmlString,
173
+ $params
174
+ );
175
+ }
176
+
177
+ /**
178
+ * Query API refund order method
179
+ *
180
+ * @param string $orderId
181
+ * @param string $type
182
+ * @return string
183
+ */
184
+ public function refundOrder($orderId, $type = 'flubit')
185
+ {
186
+ $orderTypeKey = sprintf('%s_order_id', $type);
187
+ $params = array($orderTypeKey => $orderId);
188
+
189
+ return $this->queryApi(
190
+ '1/orders/refund.xml',
191
+ self::METHOD_TYPE_POST,
192
+ null,
193
+ $params
194
+ );
195
+ }
196
+
197
+ /**
198
+ * Create HTTP auth header
199
+ *
200
+ * Uses new nonce and api signature each time it's called
201
+ *
202
+ * @return string
203
+ */
204
+ private function getDefaultHeaders() {
205
+ $timeOfCreation = date('Y-m-d\TH:i:s\Z');
206
+ $nonce = $this->generateNonce();
207
+ $signature = $this->generateApiSigniture($nonce, $timeOfCreation, $this->apiSecret);
208
+ $rawAuthString = "\tauth-token\n\tkey=\"%s\",\n\tsignature=\"%s\",\n\tnonce=\"%s\",\n\tcreated=\"%s\"";
209
+ $authString = sprintf($rawAuthString, $this->apiKey, $signature, $nonce, $timeOfCreation);
210
+
211
+ return $authString;
212
+ }
213
+
214
+ /**
215
+ * Create new API signature using given params
216
+ *
217
+ * @param string $nonce
218
+ * @param string $timeOfCreation
219
+ * @param string $apiSecret
220
+ * @return string
221
+ */
222
+ private function generateApiSigniture($nonce, $timeOfCreation, $apiSecret) {
223
+ return base64_encode(sha1(base64_decode($nonce) . $timeOfCreation . $apiSecret, true));
224
+ }
225
+
226
+ /**
227
+ * Create new nonce
228
+ *
229
+ * Uses the given string if supplied, or current timestamp if not
230
+ *
231
+ * @param string $randomString
232
+ * @return string
233
+ */
234
+ private function generateNonce($randomString = null) {
235
+ if (!$randomString) {$randomString = microtime();}
236
+ $nonce = md5($randomString);
237
+
238
+ return $nonce;
239
+ }
240
+
241
+ /**
242
+ * Query the API
243
+ *
244
+ * @param string $methodUri
245
+ * @param string $methodType
246
+ * @param string $postString
247
+ * @param array $params
248
+ * @return string
249
+ */
250
+ private function queryApi($methodUri, $methodType, $postString = null, array $params = null)
251
+ {
252
+ $queryUri = self::BASE_URI . $methodUri;
253
+
254
+ if ($params) {
255
+ $queryUri .= '?' . http_build_query($params);
256
+ }
257
+
258
+ $ch = curl_init($queryUri);
259
+
260
+ if ($methodType === self::METHOD_TYPE_POST) {
261
+ curl_setopt($ch, CURLOPT_POST, true);
262
+ curl_setopt($ch, CURLOPT_POSTFIELDS, "$postString");
263
+ }
264
+
265
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
266
+ 'Content-Type: text/xml',
267
+ 'auth-token: ' . $this->getDefaultHeaders()
268
+ )
269
+ );
270
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
271
+
272
+ $response = curl_exec($ch);
273
+ curl_close($ch);
274
+
275
+ return $response;
276
+ }
277
+ }
package.xml ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>sellonflubit</name>
4
+ <version>0.2.8</version>
5
+ <stability>stable</stability>
6
+ <license>GPL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Sell on Flubit extension enables merchants to integrate with WeFlubit API to sell on all Flubit Channels.</summary>
10
+ <description>The Sell On Flubit extension enables Merchants to integrate into Flubit via our Merchant Web Services API. It allows Merchants to send their inventory and inventory updates. Merchants can assign a global pricing rule to the full/selected Inventory or at a individual SKU level. Orders from Flubit Channels are automatically retrieved from Flubit into Merchant's Magento Sysem. And upon fulfilment and shipment order update status are sent to Flubit. &#xD;
11
+ &#xD;
12
+ All controlled by configurable cron jobs or Scheduled Tasks</description>
13
+ <notes>- This initial release allows merchants to connect to the Flubit demand driven channels. &#xD;
14
+ &#xD;
15
+ Functionalities include:&#xD;
16
+ &#xD;
17
+ 1 - Push Products to Flubit. &#xD;
18
+ 2 - Globally control inventory and prices.&#xD;
19
+ 3 - Assign a Flubit Base Price.&#xD;
20
+ 4 - As real time as possible inventory updates subject to Cron / Scheduled Tasks running&#xD;
21
+ 5 - As real time as possible Order Management and order status updates subject to Cron/ Scheduled Tasks running.&#xD;
22
+ </notes>
23
+ <authors><author><name>Krishna Pallerla</name><user>krishna</user><email>merchantintegrations@flubit.com</email></author></authors>
24
+ <date>2014-09-03</date>
25
+ <time>15:51:40</time>
26
+ <contents><target name="mageetc"><dir name="modules"><file name="Flubit_Flubit.xml" hash="ae41c32db70deae6cea6abefe8687367"/><file name="Flubit_Flubitlog.xml" hash="3c8cca9de2f076f8b548f235f1990de4"/></dir></target><target name="magecommunity"><dir name="Flubit"><dir name="Flubit"><dir name="Block"><dir name="Adminhtml"><file name="Button.php" hash="bd7d1accdb7fa7ac13140e9aad9b3680"/><dir name="Flubit"><file name="Grid.php" hash="49f6ee3abb7bcb8148c00e1331fbd6b6"/></dir><file name="Flubit.php" hash="017c95467ebebfbfc822b17a0e42605d"/><file name="Notification.php" hash="31490332a882d520ab1b2591c9ab56fe"/><dir name="Widget"><dir name="Grid"><dir name="Column"><dir name="Renderer"><file name="Inline.php" hash="2d457e533017850c5e34525e0d7347f1"/><file name="InlineCheckbox.php" hash="d97ed42053610984136d3c60b8cb129b"/><file name="InlineUpdateButton.php" hash="605fbc308d01b740c06ca94e23dc253a"/></dir></dir></dir></dir></dir><file name="Flubit.php" hash="a4a158f0960150042a4016b93ae33b48"/><dir name="Sales"><dir name="Order"><dir name="View"><file name="Info.php" hash="2b6bb256043efee3d829516f45a0f250"/></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="0839bf8334c3e3014765dd0b48293515"/><dir name="Payment"><file name="Data.php" hash="de7d2aac650b1c120a0eff5727fd5104"/></dir></dir><dir name="Model"><dir name="Carrier"><file name="Flatrate.php" hash="5ba2d161ee8f34786ac23e2de1e61d98"/></dir><file name="Config.php" hash="b65d2ff6b782408c712b7a85e9c6c898"/><file name="Cron.php" hash="9d0ad0b7f226d03b526ed17ffde89f12"/><dir name="Flubit"><file name="Chunk.php" hash="95c3c3a5e8ac39413ad7fae8ccba39a3"/><file name="Logdate.php" hash="c5e6c7c1fdac9784a480dbbdf04f9351"/><file name="Logs.php" hash="a5ec089428d563bc6bdf83826e465656"/><file name="Order.php" hash="d1cfc1da62bd55d82c60e10d5fa750bd"/><file name="Price.php" hash="47cc0b830ea77c26847e9ecc8e87ae55"/><file name="Rcd.php" hash="0c9e20ca8aae030eefe5c28190d979e5"/><file name="Source.php" hash="34fa9d221c1c5d205696843f7d80306b"/></dir><file name="Flubit.php" hash="c025f88adfc214660b690ed8e86beae9"/><file name="Globalproduct.php" hash="451cca7a0e9380b49ebd3a431e99c8e1"/><file name="Logs.php" hash="a9ce72f3ee296a698f2c5e99786cc95a"/><file name="Logtype.php" hash="1cdac7167543f5113ac6f0d726b6e8f0"/><dir name="Mysql4"><dir name="Flubit"><file name="Collection.php" hash="6991ef66959d26338b004160749bf65a"/></dir><file name="Flubit.php" hash="596e3fc791340d973f518a27beb86735"/><dir name="Globalproduct"><file name="Collection.php" hash="d43b62df7f721d02198372843e5687db"/></dir><file name="Globalproduct.php" hash="4859474fcc6d267b48804958f54cf727"/><dir name="Logs"><file name="Collection.php" hash="49c82d55f8b84f97452e29193c358957"/></dir><file name="Logs.php" hash="587b3880fbbd369515fe8ba0bef5f2f6"/><dir name="Order"><file name="Collection.php" hash="5af838cbcfdd5ecd0b2389e48b398a8d"/></dir><file name="Order.php" hash="c1eafd87edde44fd82c354826726e32b"/><dir name="Ordertime"><file name="Collection.php" hash="b28becabcc61210d2000585439c5ee4e"/></dir><file name="Ordertime.php" hash="45136f5e3d734de083aacb911449b652"/></dir><file name="Observer.php" hash="37c9cf883a9136ca69b1b4230e2931be"/><dir name="Order"><dir name="Pdf"><file name="Creditmemo.php" hash="5960dce8d419a37742b778aee3cd3513"/><file name="Invoice.php" hash="0871d94766e4d28229bd46287b4cceb6"/><dir name="Items"><dir name="Creditmemo"><file name="Default.php" hash="a54fef36fa0d76e8c9daf1b3fdc94ef0"/></dir><dir name="Invoice"><file name="Default.php" hash="81659dfd1c28fc6ecb5d29944992cbce"/></dir></dir></dir></dir><file name="Order.php" hash="1aee45050c45a7d4943e26f64dba7d7b"/><file name="Ordertime.php" hash="ba0f0b1a8843ebebc8b077fe0d7be05a"/><dir name="Payment"><dir name="Method"><file name="Flubitterms.php" hash="a3d76be1e9723152e8fa4f49e757b83f"/></dir></dir><dir name="Quote"><file name="Item.php" hash="9ba90dba195f34b686a57ee5ada02d8a"/></dir><file name="Shipping.php" hash="02e9d9ac200cd9faca48647396148817"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="FlubitController.php" hash="c0452ccd017432d608aaf053b234d755"/></dir><file name="FlubitController.php" hash="231fe90b8cf6b2dc836ccd1b9d8d05d8"/></dir><dir name="etc"><file name="adminhtml.xml" hash="a1b24cb6ef8b0cc83a8f20d3ce8c99f3"/><file name="config.xml" hash="f4aeabfc5c20bb3831f6e9181f2599ba"/><file name="system.xml" hash="a87bbee2c78981498d665d673c43e50d"/></dir><dir name="sql"><dir name="flubit_setup"><file name="mysql4-install-0.1.0.php" hash="c105bc208e4b7ffb1c4cde1d726542c7"/><file name="upgrade-0.1.0-0.1.1.php" hash="accce3c96345b2032ce31dd2bb1e886c"/><file name="upgrade-0.1.1-0.1.2.php" hash="89118cd4bed00af6c5c0879a04ff363f"/><file name="upgrade-0.1.2-0.1.3.php" hash="ab2a3a2c0ee7e284a46c165041ba643a"/><file name="upgrade-0.1.3-0.1.4.php" hash="3386896294f9331477b1772c04f4762d"/><file name="upgrade-0.1.4-0.1.5.php" hash="f4d574013dd817291166999ea6ba409b"/><file name="upgrade-0.1.5-0.1.6.php" hash="4da9c45e8322cc16b2f66b99476d697b"/><file name="upgrade-0.1.6-0.1.7.php" hash="dc25ca67f019126145b1de1752a514f6"/><file name="upgrade-0.1.7-0.1.8.php" hash="a0f803c9dd346b72895b59cc5aad1857"/><file name="upgrade-0.1.8-0.1.9.php" hash="aa3d98b81ffa33407862e7f1ed115f6d"/><file name="upgrade-0.1.9-0.2.0.php" hash="8434874ebfb9e80b328e50d0f214809b"/><file name="upgrade-0.2.0-0.2.1.php" hash="7c2101a65589a1a1235ad0337a991091"/><file name="upgrade-0.2.1-0.2.2.php" hash="390d86eb70780f35b57bf9aa53980653"/><file name="upgrade-0.2.2-0.2.3.php" hash="ed29b47b92ffc3e558d1ce0f24ec9bf9"/><file name="upgrade-0.2.3-0.2.4.php" hash="16186ad4f6cda0bec70f59351c70189a"/><file name="upgrade-0.2.4-0.2.5.php" hash="bc7a28e5dd523dbcc8c8a79e4c28332b"/><file name="upgrade-0.2.5-0.2.6.php" hash="2ec6e2e4ddc7e9db8e8b3cc149948159"/><file name="upgrade-0.2.6-0.2.7.php" hash="f4ac372521d21e039e81d82b417e5786"/><file name="upgrade-0.2.7-0.2.8.php" hash="5eae85c13c2536345dc2a4dcdb103bca"/></dir></dir></dir><dir name="Flubitlog"><dir name="Block"><dir name="Adminhtml"><dir name="Flubitlog"><file name="Detail.php" hash="8821dce99cb54736c565978d6c6319c3"/><dir name="Edit"><file name="Form.php" hash="34676e0dd3b5275ff652210c53d59b27"/><dir name="Tab"><file name="Form.php" hash="6d7bf2de46c04e408dfda67a833ec37c"/></dir><file name="Tabs.php" hash="2cc2ec2e7b53fd5c9731fc3c4feea8e4"/></dir><file name="Edit.php" hash="bee400c4c46485acbcd5d3569106cbe7"/><file name="Grid.php" hash="21d19a4110e7f09ac71b2a2bef94a213"/></dir><file name="Flubitlog.php" hash="68b44c36fadbe935d9de12ac94761edd"/></dir><file name="Flubitlog.php" hash="8ffcb27405a741567d8b5fba8652197c"/></dir><dir name="Helper"><file name="Data.php" hash="f6132f9876e8b3d74e7219ddab4e2cb1"/></dir><dir name="Model"><file name="Flubitlog.php" hash="6e974e00af84a901063ae7f2103cb1f6"/><dir name="Mysql4"><dir name="Flubitlog"><file name="Collection.php" hash="289e3e98586b34557c3aafeaadedaff9"/></dir><file name="Flubitlog.php" hash="e89466ece12379dda1df1dfee99e6fe1"/></dir><file name="Status.php" hash="3d04341124fe491394f2c360c38c3af9"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="FlubitlogController.php" hash="f3d26fab3bd230b16ff97c64a71b0f56"/></dir><file name="IndexController.php" hash="642b36eecb00647165998f1278019745"/></dir><dir name="etc"><file name="config.xml" hash="8f2dbe0685292ab75edcdb0f0136a97f"/></dir><dir name="sql"><dir name="flubitlog_setup"><file name="mysql4-install-0.1.0.php" hash="e47201271062fcd6fc4782f73c4f7465"/><file name="upgrade-0.1.0-0.2.0.php" hash="a6bb6782367e42882956dbc4b6fe915f"/><file name="upgrade-0.2.0-0.2.1.php" hash="0d44dd6b9ee6b656b5fdd988acde6722"/><file name="upgrade-0.2.1-0.2.2.php" hash="f56b2c43f82d09fdc08cf5366475b3d8"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="flubit.xml" hash="e66fcc7eb223a792c2c3a544218266d0"/><file name="flubitlog.xml" hash="9855a7d3b1ddda0ecac0d40b6022cbdb"/></dir><dir name="template"><dir name="flubit"><file name="cronnotofocation.phtml" hash="eba5f295aaecd72f34715af61718184b"/><file name="inline-edit.phtml" hash="448aa714b7c04da5d70332d78fb4f753"/><dir name="sales"><dir name="order"><dir name="creditmemo"><dir name="create"><dir name="items"><dir name="renderer"><file name="defaultflubit.phtml" hash="18b84e17657ed127fb09c4a54417bcdc"/></dir></dir><file name="items.phtml" hash="30998bc19afb64ec2169e0c9a58c3002"/><dir name="totals"><file name="adjustmentsflubit.phtml" hash="b0cff67be4fd84a04dc7e2e5d4f57833"/></dir></dir><dir name="view"><dir name="items"><dir name="renderer"><file name="default.phtml" hash="fa5cb9c64a3268be1376277863e2765b"/></dir></dir><file name="items.phtml" hash="7fea332d385bb54edf8e8d57a17aee3c"/></dir></dir><file name="flubittotals.phtml" hash="7401e649acb9b07e535cc92ba4bce0df"/><dir name="invoice"><dir name="view"><dir name="items"><dir name="renderer"><file name="default.phtml" hash="f51d5ca19b441446d038bbe535182d23"/></dir></dir><file name="items.phtml" hash="d31a04e8eb6e02a638a16e9025a902e2"/></dir></dir><dir name="shipment"><dir name="create"><file name="items.phtml" hash="a1dcb296799332d397906587439058fc"/></dir></dir><dir name="view"><file name="flubititems.phtml" hash="3d99ea1fafbf5bf6eedbd7dbe751eaef"/><file name="info.phtml" hash="a5bb96c5523189049c1962e77c264864"/><dir name="items"><dir name="renderer"><file name="flubitdefault.phtml" hash="3fd223afd8b5750ae5ced8d657d95173"/></dir></dir></dir></dir></dir></dir><dir name="flubitlog"><file name="logdetails.phtml" hash="c2695224dec521bdab65997677cab2ca"/></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="images"><dir name="flubit"><file name="logo.png" hash="b9476c105dbc159b72e3c31757a483c1"/><file name="pushonlogo.png" hash="eb7c1259d554bb75a6f2a64ae82a7b9f"/></dir></dir></dir></dir></dir></target><target name="magelib"><dir name="Flubit"><dir name="Flubit"><file name="Client.php" hash="d3530c543795bdec026f8db388ef6f6a"/><file name="ClientInterface.php" hash="ce1a6d84e186962b4f3ee14ac58f7d06"/><file name="ClientX.php" hash="78b9b30afaf04c23b10a7b7f4c8cc2d3"/><file name="MWSClient.php" hash="4ef815203140354df51da360558e183a"/></dir></dir></target></contents>
27
+ <compatible/>
28
+ <dependencies><required><php><min>5.2.10</min><max>5.5.10</max></php></required></dependencies>
29
+ </package>
skin/adminhtml/default/default/images/flubit/logo.png ADDED
Binary file
skin/adminhtml/default/default/images/flubit/pushonlogo.png ADDED
Binary file