Innobyte_EmagMarketplace - Version 1.0.0

Version Notes

-

Download this release

Release Info

Developer Florin Mihai Savici
Extension Innobyte_EmagMarketplace
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

Files changed (179) hide show
  1. README.md +204 -0
  2. app/code/local/Innobyte/Core/Block/Shop.php +234 -0
  3. app/code/local/Innobyte/Core/Block/System/Config/Button.php +57 -0
  4. app/code/local/Innobyte/Core/Block/System/Config/Form/Fieldset/Extensions.php +7 -0
  5. app/code/local/Innobyte/Core/Block/System/Config/Form/Fieldset/Shop.php +11 -0
  6. app/code/local/Innobyte/Core/Block/System/Config/Form/Renderer/Field.php +37 -0
  7. app/code/local/Innobyte/Core/Block/System/Config/Form/Renderer/Website.php +75 -0
  8. app/code/local/Innobyte/Core/Helper/Config.php +9 -0
  9. app/code/local/Innobyte/Core/Helper/Data.php +8 -0
  10. app/code/local/Innobyte/Core/Helper/Versions.php +272 -0
  11. app/code/local/Innobyte/Core/Model/Data.php +91 -0
  12. app/code/local/Innobyte/Core/Model/Debug.php +248 -0
  13. app/code/local/Innobyte/Core/Model/Feed.php +249 -0
  14. app/code/local/Innobyte/Core/Model/Source/Config/Enabledisable.php +31 -0
  15. app/code/local/Innobyte/Core/Model/Source/Feed/Type.php +72 -0
  16. app/code/local/Innobyte/Core/controllers/Adminhtml/IndexController.php +34 -0
  17. app/code/local/Innobyte/Core/etc/config.xml +135 -0
  18. app/code/local/Innobyte/Core/etc/system.xml +145 -0
  19. app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Catalog/Product/Edit.php +109 -0
  20. app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Catalog/Product/Edit/Tab/EmagMarketplace.php +758 -0
  21. app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Category.php +54 -0
  22. app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Category/Grid.php +239 -0
  23. app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Form/Element/Barcodes.php +62 -0
  24. app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Form/Element/File.php +71 -0
  25. app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Form/Field/LocalityId.php +97 -0
  26. app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Locality.php +54 -0
  27. app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Locality/Grid.php +239 -0
  28. app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Sales/Order/Create/Billing/Method/Form.php +44 -0
  29. app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Sales/Order/Create/Items/Grid.php +57 -0
  30. app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Sales/Order/Create/Shipping/Method/Form.php +39 -0
  31. app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Sales/Order/Create/Totals/Voucher.php +22 -0
  32. app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Sales/Order/View/Comment.php +36 -0
  33. app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Sales/Order/View/Invoice/Popup.php +15 -0
  34. app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Sales/Order/View/Invoice/Upload.php +41 -0
  35. app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Sales/Order/View/Invoice/Upload/Form.php +90 -0
  36. app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Vat.php +54 -0
  37. app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Vat/Grid.php +140 -0
  38. app/code/local/Innobyte/EmagMarketplace/Exception.php +12 -0
  39. app/code/local/Innobyte/EmagMarketplace/Helper/Data.php +416 -0
  40. app/code/local/Innobyte/EmagMarketplace/Model/Api/Abstract.php +553 -0
  41. app/code/local/Innobyte/EmagMarketplace/Model/Api/Awb.php +441 -0
  42. app/code/local/Innobyte/EmagMarketplace/Model/Api/Category.php +276 -0
  43. app/code/local/Innobyte/EmagMarketplace/Model/Api/Locality.php +172 -0
  44. app/code/local/Innobyte/EmagMarketplace/Model/Api/Order.php +80 -0
  45. app/code/local/Innobyte/EmagMarketplace/Model/Api/Product.php +596 -0
  46. app/code/local/Innobyte/EmagMarketplace/Model/Api/Response.php +109 -0
  47. app/code/local/Innobyte/EmagMarketplace/Model/Api/Vat.php +148 -0
  48. app/code/local/Innobyte/EmagMarketplace/Model/Catalog/Product/Observer.php +448 -0
  49. app/code/local/Innobyte/EmagMarketplace/Model/Category.php +148 -0
  50. app/code/local/Innobyte/EmagMarketplace/Model/Category/Characteristic.php +35 -0
  51. app/code/local/Innobyte/EmagMarketplace/Model/Category/Familytype.php +85 -0
  52. app/code/local/Innobyte/EmagMarketplace/Model/Cron.php +422 -0
  53. app/code/local/Innobyte/EmagMarketplace/Model/Customer/Attributes.php +118 -0
  54. app/code/local/Innobyte/EmagMarketplace/Model/Customer/Form.php +110 -0
  55. app/code/local/Innobyte/EmagMarketplace/Model/Invoice/Pdf/Total/Voucher.php +58 -0
  56. app/code/local/Innobyte/EmagMarketplace/Model/Locality.php +34 -0
  57. app/code/local/Innobyte/EmagMarketplace/Model/Locality/Flag.php +73 -0
  58. app/code/local/Innobyte/EmagMarketplace/Model/Order/Convert/Abstract.php +419 -0
  59. app/code/local/Innobyte/EmagMarketplace/Model/Order/Convert/Emag.php +768 -0
  60. app/code/local/Innobyte/EmagMarketplace/Model/Order/Convert/Emag/Update.php +296 -0
  61. app/code/local/Innobyte/EmagMarketplace/Model/Order/Convert/Magento.php +1066 -0
  62. app/code/local/Innobyte/EmagMarketplace/Model/Payment/Method/Banktransfer.php +34 -0
  63. app/code/local/Innobyte/EmagMarketplace/Model/Payment/Method/Cashondelivery.php +34 -0
  64. app/code/local/Innobyte/EmagMarketplace/Model/Payment/Method/Cc.php +34 -0
  65. app/code/local/Innobyte/EmagMarketplace/Model/Payment/Method/Unknown.php +34 -0
  66. app/code/local/Innobyte/EmagMarketplace/Model/Product.php +395 -0
  67. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Category.php +111 -0
  68. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Category/Characteristic.php +20 -0
  69. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Category/Characteristic/Collection.php +39 -0
  70. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Category/Collection.php +172 -0
  71. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Category/Familytype.php +112 -0
  72. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Category/Familytype/Collection.php +40 -0
  73. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Locality.php +36 -0
  74. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Locality/Collection.php +81 -0
  75. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Product.php +212 -0
  76. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Product/Collection.php +75 -0
  77. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Abstract.php +166 -0
  78. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Address/Abstract.php +50 -0
  79. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Invoice.php +23 -0
  80. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Invoice/Collection.php +39 -0
  81. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Item/Abstract.php +50 -0
  82. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Order.php +30 -0
  83. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Order/Address.php +30 -0
  84. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Order/Item.php +30 -0
  85. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Order/Item/Collection.php +30 -0
  86. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Order/Voucher.php +23 -0
  87. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Order/Voucher/Collection.php +39 -0
  88. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Quote.php +30 -0
  89. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Quote/Address.php +30 -0
  90. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Quote/Voucher.php +23 -0
  91. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Quote/Voucher/Collection.php +39 -0
  92. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Voucher/Abstract.php +35 -0
  93. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Vat.php +37 -0
  94. app/code/local/Innobyte/EmagMarketplace/Model/Resource/Vat/Collection.php +81 -0
  95. app/code/local/Innobyte/EmagMarketplace/Model/Sales/Abstract.php +83 -0
  96. app/code/local/Innobyte/EmagMarketplace/Model/Sales/Address/Abstract.php +28 -0
  97. app/code/local/Innobyte/EmagMarketplace/Model/Sales/Invoice.php +170 -0
  98. app/code/local/Innobyte/EmagMarketplace/Model/Sales/Item/Abstract.php +28 -0
  99. app/code/local/Innobyte/EmagMarketplace/Model/Sales/Observer.php +934 -0
  100. app/code/local/Innobyte/EmagMarketplace/Model/Sales/Order.php +147 -0
  101. app/code/local/Innobyte/EmagMarketplace/Model/Sales/Order/Address.php +39 -0
  102. app/code/local/Innobyte/EmagMarketplace/Model/Sales/Order/Creditmemo/Total.php +51 -0
  103. app/code/local/Innobyte/EmagMarketplace/Model/Sales/Order/Invoice/Total.php +51 -0
  104. app/code/local/Innobyte/EmagMarketplace/Model/Sales/Order/Item.php +39 -0
  105. app/code/local/Innobyte/EmagMarketplace/Model/Sales/Order/Status.php +32 -0
  106. app/code/local/Innobyte/EmagMarketplace/Model/Sales/Order/Voucher.php +39 -0
  107. app/code/local/Innobyte/EmagMarketplace/Model/Sales/Quote.php +38 -0
  108. app/code/local/Innobyte/EmagMarketplace/Model/Sales/Quote/Address.php +39 -0
  109. app/code/local/Innobyte/EmagMarketplace/Model/Sales/Quote/Address/Total/Voucher.php +87 -0
  110. app/code/local/Innobyte/EmagMarketplace/Model/Sales/Quote/Voucher.php +39 -0
  111. app/code/local/Innobyte/EmagMarketplace/Model/Sales/Voucher/Abstract.php +116 -0
  112. app/code/local/Innobyte/EmagMarketplace/Model/Shipping/Carrier/Emag.php +193 -0
  113. app/code/local/Innobyte/EmagMarketplace/Model/Source/Category.php +103 -0
  114. app/code/local/Innobyte/EmagMarketplace/Model/Source/CommissionTypes.php +92 -0
  115. app/code/local/Innobyte/EmagMarketplace/Model/Source/Customer/Address/Attributes/Legalentity.php +36 -0
  116. app/code/local/Innobyte/EmagMarketplace/Model/Source/FamilyType.php +96 -0
  117. app/code/local/Innobyte/EmagMarketplace/Model/Source/OfferStatus.php +64 -0
  118. app/code/local/Innobyte/EmagMarketplace/Model/Source/Vat.php +95 -0
  119. app/code/local/Innobyte/EmagMarketplace/Model/System/Config/Backend/Prefix/Abstract.php +156 -0
  120. app/code/local/Innobyte/EmagMarketplace/Model/System/Config/Backend/Prefix/Creditmemo.php +32 -0
  121. app/code/local/Innobyte/EmagMarketplace/Model/System/Config/Backend/Prefix/Invoice.php +32 -0
  122. app/code/local/Innobyte/EmagMarketplace/Model/Vat.php +34 -0
  123. app/code/local/Innobyte/EmagMarketplace/controllers/Adminhtml/Emag/CategoryController.php +125 -0
  124. app/code/local/Innobyte/EmagMarketplace/controllers/Adminhtml/Emag/LocalityController.php +283 -0
  125. app/code/local/Innobyte/EmagMarketplace/controllers/Adminhtml/Emag/ProductController.php +517 -0
  126. app/code/local/Innobyte/EmagMarketplace/controllers/Adminhtml/Emag/VatController.php +123 -0
  127. app/code/local/Innobyte/EmagMarketplace/controllers/Adminhtml/Emag/VoucherController.php +71 -0
  128. app/code/local/Innobyte/EmagMarketplace/controllers/Adminhtml/Sales/Invoice/UploadController.php +211 -0
  129. app/code/local/Innobyte/EmagMarketplace/controllers/Adminhtml/Sales/OrderController.php +175 -0
  130. app/code/local/Innobyte/EmagMarketplace/controllers/InvoiceController.php +136 -0
  131. app/code/local/Innobyte/EmagMarketplace/data/innobyte_emag_marketplace_setup/data-install-1.0.0.php +38 -0
  132. app/code/local/Innobyte/EmagMarketplace/docs/eMAG Markeplace API documentation v3.6.docx +0 -0
  133. app/code/local/Innobyte/EmagMarketplace/etc/adminhtml.xml +105 -0
  134. app/code/local/Innobyte/EmagMarketplace/etc/config.xml +564 -0
  135. app/code/local/Innobyte/EmagMarketplace/etc/jstranslator.xml +36 -0
  136. app/code/local/Innobyte/EmagMarketplace/etc/system.xml +468 -0
  137. app/code/local/Innobyte/EmagMarketplace/sql/innobyte_emag_marketplace_setup/install-1.0.0.php +1744 -0
  138. app/design/adminhtml/default/default/layout/innobyte/core.xml +8 -0
  139. app/design/adminhtml/default/default/layout/innobyte/emag_marketplace.xml +337 -0
  140. app/design/adminhtml/default/default/template/innobyte/core/button.phtml +23 -0
  141. app/design/adminhtml/default/default/template/innobyte/core/debugger_email/cron.phtml +49 -0
  142. app/design/adminhtml/default/default/template/innobyte/core/debugger_email/disabled_extensions.phtml +13 -0
  143. app/design/adminhtml/default/default/template/innobyte/core/debugger_email/general.phtml +11 -0
  144. app/design/adminhtml/default/default/template/innobyte/core/debugger_email/inno_config_data.phtml +20 -0
  145. app/design/adminhtml/default/default/template/innobyte/core/debugger_email/inno_extensions.phtml +13 -0
  146. app/design/adminhtml/default/default/template/innobyte/core/debugger_email/rewrites.phtml +31 -0
  147. app/design/adminhtml/default/default/template/innobyte/core/shop.phtml +37 -0
  148. app/design/adminhtml/default/default/template/innobyte/emag_marketplace/catalog/product/edit.phtml +144 -0
  149. app/design/adminhtml/default/default/template/innobyte/emag_marketplace/catalog/product/edit/tab/emag_marketplace_form_after.phtml +15 -0
  150. app/design/adminhtml/default/default/template/innobyte/emag_marketplace/sales/order/create/form/address.phtml +134 -0
  151. app/design/adminhtml/default/default/template/innobyte/emag_marketplace/sales/order/create/items/grid.phtml +557 -0
  152. app/design/adminhtml/default/default/template/innobyte/emag_marketplace/sales/order/create/shipping/method/form.phtml +126 -0
  153. app/design/adminhtml/default/default/template/innobyte/emag_marketplace/sales/order/create/totals/voucher.phtml +46 -0
  154. app/design/adminhtml/default/default/template/innobyte/emag_marketplace/sales/order/emag_edit/city-autocomplete.phtml +22 -0
  155. app/design/adminhtml/default/default/template/innobyte/emag_marketplace/sales/order/shipment/packaging/popup.phtml +302 -0
  156. app/design/adminhtml/default/default/template/innobyte/emag_marketplace/sales/order/totals.phtml +16 -0
  157. app/design/adminhtml/default/default/template/innobyte/emag_marketplace/sales/order/view/comment.phtml +10 -0
  158. app/design/adminhtml/default/default/template/innobyte/emag_marketplace/sales/order/view/invoice/popup.phtml +53 -0
  159. app/design/adminhtml/default/default/template/innobyte/emag_marketplace/sales/order/view/tab/info.phtml +119 -0
  160. app/etc/modules/Innobyte_Core.xml +9 -0
  161. app/etc/modules/Innobyte_EmagMarketplace.xml +15 -0
  162. app/locale/en_US/Innobyte_EmagMarketplace.csv +279 -0
  163. app/locale/en_US/template/email/innobyte/core/debug.html +99 -0
  164. app/locale/en_US/template/email/innobyte/emag_marketplace/errors.html +10 -0
  165. js/innobyte/core/init.js +11 -0
  166. package.xml +19 -0
  167. skin/adminhtml/default/default/css/innobyte/emag_marketplace/style.css +37 -0
  168. skin/adminhtml/default/default/images/innobyte/core/error_msg_icon.gif +0 -0
  169. skin/adminhtml/default/default/images/innobyte/core/icon-enabled.png +0 -0
  170. skin/adminhtml/default/default/images/innobyte/core/note_msg_icon.gif +0 -0
  171. skin/adminhtml/default/default/images/innobyte/emag_marketplace/pdf_icon.png +0 -0
  172. skin/adminhtml/default/default/images/innobyte/emag_marketplace/trash.png +0 -0
  173. skin/adminhtml/default/default/js/innobyte/emag_marketplace/category.js +72 -0
  174. skin/adminhtml/default/default/js/innobyte/emag_marketplace/locality.js +262 -0
  175. skin/adminhtml/default/default/js/innobyte/emag_marketplace/packaging.js +57 -0
  176. skin/adminhtml/default/default/js/innobyte/emag_marketplace/product.js +264 -0
  177. skin/adminhtml/default/default/js/innobyte/emag_marketplace/protolicius/README.rdoc +72 -0
  178. skin/adminhtml/default/default/js/innobyte/emag_marketplace/protolicius/event.simulate.js +64 -0
  179. skin/adminhtml/default/default/js/innobyte/emag_marketplace/vat.js +72 -0
README.md ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ eMAG Marketplace [1.0.0]
2
+ ========================
3
+
4
+ ### 1. Description
5
+ - This module integrantes eMAG Marketplace API into Magento.
6
+ - DEMO: http://demo.innobyte.com/emag_marketplace
7
+
8
+ ### 2. Features
9
+ - Enable/Disable eMAG Marketplace module.
10
+ - Supports different eMAG vendors (per store).
11
+ - Import eMAG categories, VATs, localities (from `eMAG Marketplace` admin menu).
12
+ - New tab on product edit page available on store view level for saving eMAG product data.
13
+ - Entire product documentation sending or just offer sending.
14
+ - Autocomplete city available on order edit page / system config shipping settings origin city.
15
+ - AWB generation through eMAG for an order (settings must be first set from `System` -> `Configuration` -> `eMAG Marketplace` -> `Shipping Settings`)
16
+
17
+ ### 3. Compatible with
18
+ - Magento CE >= 1.7.0.2
19
+
20
+ ### 4. Usage
21
+ 1. Go to `System`->`Configuration`->`Innobyte Extensions`->`eMAG Marketplace` fill in the licence key and set extension options. Be aware that some/most of the options are available only on store view level.
22
+ 2. Refresh your cache and verify if everything works as described (go to admin `eMAG Marketplace` menu and import vats, categories, localities, then go to catalog and send some products to eMAG. After some orders have been placed on eMAG platform, cron should read them and orders should appear also in Magento).
23
+
24
+
25
+ ### 5. Technical specification
26
+ API Integration documentation can be found in `docs/` folder.
27
+ ###### Rewrites
28
+ - Models
29
+ - *customer_form*: remove eMAG attributes from forms if emag_order_id is not available
30
+ - *sales_order_status*: added eventPrefix and eventObject properties
31
+ - *sales_resource_order_item_collection*: added eventPrefix and eventObject properties
32
+ - Blocks
33
+ - *adminhtml_catalog_product_edit*: added 3 more buttons on product edit page
34
+
35
+ ###### Event observers
36
+ - *sales_quote_save_after*: save eMAG quote attributes to database
37
+ - *sales_order_save_after*: save eMAG order attributes to database
38
+ - *sales_order_creditmemo_save_after*: update eMAG order with storno invoice
39
+ - *sales_quote_load_after*: add eMAG quote attribute to quote collection
40
+ - *sales_order_load_after*: add eMAG order attribute to order collection
41
+ - *sales_order_invoice_load_after*: attach vouchers to invoice
42
+ - *sales_order_creditmemo_load_after*: attach vouchers to creditmemo
43
+ - *sales_quote_address_save_after*: save eMAG quote address attributes to database
44
+ - *sales_order_address_save_after*: save eMAG order address attributes to database
45
+ - *sales_quote_address_collection_load_after*: add eMAG quote address attribute to quote address collection
46
+ - *sales_order_address_collection_load_after*: add eMAG order address attribute to order address collection
47
+ - *core_copy_fieldset_customer_account_to_quote*: copy eMAG customer attributes to quote
48
+ - *core_copy_fieldset_customer_address_to_quote_address*: copy eMAG customer address attributes to quote address
49
+ - *core_copy_fieldset_sales_convert_quote_to_order*: copy eMAG attributes from quote to order
50
+ - *core_copy_fieldset_sales_convert_quote_address_to_order_address*: copy eMAG attributes from quote address to order address
51
+ - *core_copy_fieldset_sales_convert_quote_address_to_customer_address*: copy eMAG attributes from quote address to customer address
52
+ - *core_copy_fieldset_checkout_onepage_quote_to_customer*: copy eMAG attributes from quote to customer
53
+ - *core_copy_fieldset_sales_copy_order_to_edit*: copy eMAG attributes from original order to new order
54
+ - *core_copy_fieldset_sales_convert_order_to_invoice*: copy eMAG attributes from order to invoice
55
+ - *core_copy_fieldset_sales_convert_order_to_cm*: copy eMAG attributes from order to creditmemo
56
+ - *core_copy_fieldset_sales_copy_order_billing_address_to_order*: copy eMAG attributes from billing address to order
57
+ - *core_copy_fieldset_sales_copy_order_shipping_address_to_order*: copy eMAG attributes from shipping address to order
58
+ - *catalog_product_save_after*: saves eMAG specific product data.
59
+ - *adminhtml_catalog_product_grid_prepare_massaction*: add 3 more mass actions on products grid.
60
+
61
+ ###### Cron jobs
62
+ - `innobyte_emag_marketplace_cron`: pull orders from eMAG API (runs every 5 minutes)
63
+
64
+ ###### Dispatched events
65
+ - `innobyte_emag_marketplace_compute_api_product_data` is dispatched in *Innobyte_EmagMarketplace_Model_Api_Product* class in order to customize (if needed by clients) product data sent for a product to eMAG API.
66
+ - `innobyte_emag_marketplace_compute_api_offer_data` is dispatched in *Innobyte_EmagMarketplace_Model_Api_Product* class in order to customize (if needed by clients) product offer data sent for a product to eMAG API.
67
+ - `innobyte_emag_marketplace_prepare_emag_product_form` is dispatched in *Innobyte_EmagMarketplace_Block_Adminhtml_Catalog_Product_Edit_Tab_EmagMarketplace* class in order to customize (if needed by clients) eMAG product form fields.
68
+ - `innobyte_emag_marketplace_compute_api_awb_data` is dispatched in *Innobyte_EmagMarketplace_Model_Api_Awb* class in order to customize (if needed by clients) AWB data to be sent to eMAG API.
69
+
70
+ ###### Api Settings:
71
+ - Admin->*System*->*Configuration*->*eMAG Marketplace*->*API Settings* (store view level):
72
+ - api url: marketplace API URL
73
+ - api username: vendor 's username
74
+ - api password: vendor 's password
75
+ - client code: vendor 's code
76
+
77
+ ###### eMAG Statuses:
78
+ - Add 6 new statuses for eMAG and map the with corresponding magento states (emag_status[magento_state]):
79
+ - emag_new[new]
80
+ - emag_in_progress[processing]
81
+ - emag_prepared[processing]
82
+ - emag_finalized[processing]
83
+ - emag_canceled[processing]
84
+ - emag_returned[closed]
85
+
86
+ ###### Vouchers:
87
+ - New tables:
88
+ - innobyte_emag_marketplace_sales_flat_order_voucher
89
+ - innobyte_emag_marketplace_sales_flat_quote_voucher
90
+ Columns:
91
+ - id: ID
92
+ - entity_id: Entity Id, quote/order
93
+ - emag_id: eMAG ID
94
+ - emag_voucher_id: eMAG Voucher ID
95
+ - emag_voucher_name: eMAG Voucher Name
96
+ - emag_sale_price: eMAG Sale Price
97
+ - base_emag_sale_price: eMAG Sale Price in base currency
98
+ - emag_sale_price_vat: eMAG Sale Price VAT
99
+ - base_emag_sale_price_vat: eMAG Sale Price VAT in base currency
100
+ - emag_status: eMAG Status
101
+ - emag_vat: eMAG VAT
102
+ - emag_created: eMAG Creation Time
103
+ - emag_modified: eMAG Modification Time
104
+ - Added custom layout for admin to show eMAG vouchers in order/invoice/creditmemo totals.
105
+ - New PDF Total model to display voucher discount in invoice PDF.
106
+
107
+ ###### Attibutes:
108
+ - Customer attributes: (visible in forms: adminhtml_customer)
109
+ - emag_order_id
110
+ - emag_customer_id
111
+ - emag_customer_comment
112
+ - emag_customer_gender
113
+ - emag_payment_status
114
+ - emag_order_date
115
+ - Customer address attributes: (visible in forms: adminhtml_customer_address)
116
+ - emag_company_code
117
+ - emag_company_reg_no
118
+ - emag_bank
119
+ - emag_iban
120
+ - emag_legal_entity
121
+ - emag_is_vat_payer
122
+ - emag_telephone_2
123
+ - emag_telephone_3
124
+ - emag_locality_id
125
+
126
+ ###### Invoice:
127
+ - Added system config field for invoice and creditmemo incement prefix. It updates increment_id column from eav_entity_store table. Can only be edited at store level.
128
+ - Added new button in admin order view page:
129
+ - invoice upload
130
+ - invoice download
131
+ - invoice delete
132
+ - Added custom layout to modify invoice totals
133
+ - New model for <global><sales><order_invoice><totals> that handles vouchers and applies correct grand total
134
+
135
+ ###### Refunds:
136
+ - New model for <global><sales><order_creditmemo><totals> that handles vouchers and applies correct grand total
137
+ - Added custom layout to modify creditmemo totals
138
+
139
+ ###### Api:
140
+ - Models for each resource containing all 4 methods:
141
+ - read
142
+ - save
143
+ - count
144
+ - acknowledge
145
+ For those resources that do not have the method implemented exception will be thrown.
146
+ - Api response model
147
+
148
+ ###### Orders:
149
+ - Sync:
150
+ - convert to magento order:
151
+ - reserve increment id for new order and set eMAG order id, store id, date and status
152
+ - apply global, base, store, order currency to order
153
+ - prepare currency rates that will be applied to order
154
+ - convert eMAG order products into magento order items and set order totals according to each product price
155
+ - if product currency does not match store currency sync will fail
156
+ - if product is canceled do not add it to magento order
157
+ - if product could not be loaded(missing from magento or wrong id from eMAG) sync will fail
158
+ - apply eMAG vouchers to magento order and recalculate totals based on voucher values
159
+ - apply guest customer to magento order(set dummy email address as email is not provided by eMAG)
160
+ - assign billing address
161
+ - assign shipping address
162
+ - apply shipping cost to magento order and recalculate totals
163
+ - prepare payment method
164
+ - apply customer comment to magento order
165
+ - automatically generate order invoice if eMAG payment method is credit card and status is "paid"
166
+ - convert to eMAG order:
167
+ - set eMAG order id, status, date
168
+ - assign customer data
169
+ - convert magento billing address to eMAG address
170
+ - convert magento shipping address to eMAG address
171
+ - convert order products to eMAG products
172
+ - assign invoices/creditmemos to eMAG order
173
+ - assign vouchers to eMAG order
174
+ - apply payment
175
+ - apply customer comment
176
+ - add attachements
177
+ - Edit:
178
+ - new model for <global><sales><quote><totals> that handles vouchers and applies correct grand total
179
+ - added custom layout to modify order product grid in order to display product prices from original order
180
+ - added custom layout to modify order totals
181
+ - View:
182
+ - new model for <global><sales><quote><totals> that handles vouchers and applies correct grand total
183
+ - added eMAG statuses buttons
184
+ - added custom layout to add customer comments
185
+ - added custom layout to modify order totals
186
+
187
+ ###### Shipping:
188
+ New shipping method with custom price (visible only in admin)
189
+
190
+ ###### Payment:
191
+ New payment methods added for eMAG(visible only in admin):
192
+ - bank transfer
193
+ - cash on delivery
194
+ - credit card
195
+ - unknown (used for exceptions, when eMAG payment is not available on eMAG order)
196
+
197
+ ###### Catalog Product
198
+ - On edit page, on store view level, *eMAG Marketplace* tab should be available for simple & configurable products.
199
+ - Edit block is rewritten, also its template file has been changed (added 3 more buttons) from layout.
200
+ - On configurable products, an extra field 'Family Type' is present, it represents the modality of grouping some products (its associated products) on eMAG. When a configurable product is sent to eMAG all it 's associated products are sent with family type - the family type of parent configurable product, family name - the name of parent configurable product, family id - the magento id of the parent configurable product. Be aware that if you sent an associated product from it 's own edit page, no family will be set for it.
201
+
202
+ ### 6. Install
203
+ - Copy files / folders (design/skin files should be put in the default theme of your current package)
204
+ - Refresh your cache, log out from admin and log back in.
app/code/local/Innobyte/Core/Block/Shop.php ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Innobyte_Core_Block_Shop extends Mage_Adminhtml_Block_Template
3
+ {
4
+ public $configPage = '';
5
+ private $_extensionsCache = array();
6
+ private $_shopData = null;
7
+
8
+
9
+ protected function _prepareLayout()
10
+ {
11
+ $this->configPage = $this->getAction()->getRequest()
12
+ ->getParam('section', false);
13
+ if ($this->configPage == 'innobyte_core') {
14
+ $this->getLayout()
15
+ ->getBlock('head')
16
+ ->addJs('innobyte/core/init.js')
17
+ ;
18
+ $this->setData('extensions', $this->_initExtensions());
19
+ } elseif ($this->configPage == 'innobyte_shop') {
20
+ // Innobyte extensions shop
21
+ $this->getLayout()
22
+ ->getBlock('head')
23
+ ->addJs('innobyte/core/init.js')
24
+ ;
25
+ $this->setData('shop_data', $this->_getShopData());
26
+ }
27
+ parent::_prepareLayout();
28
+ }
29
+
30
+ protected function _toHtml()
31
+ {
32
+ if ($this->configPage == 'innobyte_core' || $this->configPage == 'innobyte_shop') {
33
+ return parent::_toHtml();
34
+ } else {
35
+ return '';
36
+ }
37
+ }
38
+
39
+ protected function _initExtensions()
40
+ {
41
+ $extensions = array();
42
+
43
+ $modules = array_keys((array)Mage::getConfig()->getNode('modules')->children());
44
+ sort($modules);
45
+
46
+ foreach ($modules as $moduleName) {
47
+ if ($moduleName == 'Innobyte_Core') {
48
+ continue;
49
+ }
50
+ if (strstr($moduleName, 'Innobyte_') === false) {
51
+ continue;
52
+ }
53
+
54
+ // Detect extension platform
55
+ try {
56
+ $platform = Mage::getConfig()->getNode('modules/'.$moduleName.'/platform');
57
+ if ($platform) {
58
+ $platform = strtolower($platform);
59
+ $ignore_platform = false;
60
+ } else {
61
+ throw new Exception();
62
+ }
63
+ } catch (Exception $e) {
64
+ $platform = 'ce';
65
+ $ignore_platform = true;
66
+ }
67
+ $platform = Innobyte_Core_Helper_Versions::convertPlatform($platform);
68
+
69
+ // Detect installed version
70
+ $ver = Mage::getConfig()->getModuleConfig($moduleName)->version;
71
+ $isPlatformValid = false;
72
+ if ($platform >= $this->getPlatform()) {
73
+ $isPlatformValid = true;
74
+ }
75
+ $feedInfo = $this->getExtensionInfo($moduleName);
76
+
77
+ if ( ! $feedInfo->getData() ) {
78
+ $feedInfo->setDisplayName($moduleName);
79
+ $feedInfo->setUrl('http://shop.innobyte.com');
80
+ $feedInfo->setVersion($ver);
81
+ }
82
+
83
+ $feedExtensionVersion = $this->_convertVersion($feedInfo->getLatestVersion());
84
+ $installedExtVersion = $this->_convertVersion($ver);
85
+ $upgradeAvailable = false;
86
+ if (($feedExtensionVersion - $installedExtVersion) > 0) {
87
+ $upgradeAvailable = true;
88
+ }
89
+
90
+ $extensionData = array(
91
+ 'version' => $ver,
92
+ 'name' => $moduleName,
93
+ 'is_platform_valid' => $isPlatformValid,
94
+ 'platform' => $platform,
95
+ 'feed_info' => $feedInfo,
96
+ 'upgrade_available' => $upgradeAvailable
97
+ );
98
+ $extensions[] = new Varien_Object($extensionData);
99
+ }
100
+
101
+ return $extensions;
102
+ }
103
+
104
+ /**
105
+ * Convert version to comparable integer
106
+ * @param $version
107
+ * @return int
108
+ */
109
+ protected function _convertVersion($version)
110
+ {
111
+ $digits = @explode(".", $version);
112
+ $version = 0;
113
+ if (is_array($digits)) {
114
+ foreach ($digits as $k => $version) {
115
+ $version += ($version * pow(10, max(0, (3 - $k))));
116
+ }
117
+ }
118
+ return $version;
119
+ }
120
+
121
+
122
+ /**
123
+ * Get extension info from cached feed
124
+ * @param $moduleName
125
+ * @return bool|Varien_Object
126
+ */
127
+ public function getExtensionInfo($moduleName)
128
+ {
129
+ if (!sizeof($this->_extensionsCache)) {
130
+ // Mage::app()->removeCache('innobytecore_extensions_feed');
131
+ $displayNames = Mage::app()->loadCache('innobytecore_extensions_feed');
132
+ if ($displayNames) {
133
+ $this->_extensionsCache = @unserialize($displayNames);
134
+ } else {
135
+ $model = Mage::getModel('innobyte_core/feed')
136
+ ->refreshExtensions();
137
+ if ($model) {
138
+ $displayNames = Mage::app()->loadCache('innobytecore_extensions_feed');
139
+ if ($displayNames) {
140
+ $this->_extensionsCache = @unserialize($displayNames);
141
+ }
142
+ }
143
+ }
144
+ }
145
+ if (array_key_exists($moduleName, $this->_extensionsCache)) {
146
+ $data = array(
147
+ 'url' => @$this->_extensionsCache[$moduleName]['url'],
148
+ 'display_name' => @$this->_extensionsCache[$moduleName]['display_name'],
149
+ 'latest_version' => @$this->_extensionsCache[$moduleName]['version']
150
+ );
151
+ return new Varien_Object($data);
152
+ }
153
+ return new Varien_Object();
154
+ }
155
+
156
+ /**
157
+ * Return icon for installed extension
158
+ * @param $extension
159
+ * @return Varien_Object
160
+ */
161
+ public function getIcon($extension)
162
+ {
163
+ if ($extension->getUpgradeAvailable()) {
164
+ $iconPic = 'images/innobyte/core/error_msg_icon.gif';
165
+ $title = "Update available";
166
+ } elseif (!$extension->getIsPlatformValid()) {
167
+ $iconPic = 'images/innobyte/core/note_msg_icon.gif';
168
+ $title = "Wrong Extension Platform";
169
+ } else {
170
+ $iconPic = 'images/innobyte/core/icon-enabled.png';
171
+ $title = "Installed and up to date";
172
+ }
173
+ $icon = new Varien_Object();
174
+ $data = array(
175
+ 'title' => $title,
176
+ 'source' => $this->getSkinUrl($iconPic));
177
+ $icon->setData($data);
178
+ return $icon;
179
+ }
180
+
181
+ /**
182
+ * Fetch store data and return as Varien Object
183
+ * @return Varien_Object
184
+ */
185
+ protected function _getShopData()
186
+ {
187
+ if (!is_null($this->_shopData)) {
188
+ return $this->_shopData;
189
+ }
190
+ $connection = $this->_getShopConnection();
191
+ $shopResponse = $connection->read();
192
+
193
+ if ($shopResponse !== false) {
194
+ $shopResponse = preg_split('/^\r?$/m', $shopResponse, 2);
195
+ $shopResponse = trim($shopResponse[1]);
196
+ Mage::app()->saveCache($shopResponse, Innobyte_Core_Helper_Config::SHOP_CACHE_KEY);
197
+ }
198
+ else {
199
+ $shopResponse = Mage::app()->loadCache(Innobyte_Core_Helper_Config::SHOP_CACHE_KEY);
200
+ if (!$shopResponse) {
201
+ Mage::getSingleton('adminhtml/session')
202
+ ->addError($this->__('Sorry, but Extensions Shop is not available now. Please try again in a few minutes.'));
203
+ }
204
+ }
205
+
206
+ $connection->close();
207
+ $this->_shopData = new Varien_Object(array('text_response' => $shopResponse));
208
+ return $this->_shopData;
209
+ }
210
+
211
+ /**
212
+ * Returns URL to store
213
+ * @return Varien_Http_Adapter_Curl
214
+ */
215
+ protected function _getShopConnection()
216
+ {
217
+ $params = array();
218
+ $url = array();
219
+ foreach ($params as $k => $v) {
220
+ $url[] = urlencode($k) . "=" . urlencode($v);
221
+ }
222
+ $url = rtrim(Innobyte_Core_Helper_Config::SHOP_URL)
223
+ . (sizeof($url) ? ("?" . implode("&", $url)) : "");
224
+
225
+ $curl = new Varien_Http_Adapter_Curl();
226
+ $curl->setConfig(array('timeout' => 5));
227
+ $curl->write(Zend_Http_Client::GET, $url, '1.0');
228
+
229
+ return $curl;
230
+ }
231
+
232
+
233
+ }
234
+
app/code/local/Innobyte/Core/Block/System/Config/Button.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * System Configuration Button Block
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_Core
8
+ * @author Daniel Horobeanu <daniel.horobeanu@innobyte.com>
9
+ */
10
+ class Innobyte_Core_Block_System_Config_Button
11
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
12
+ {
13
+
14
+ protected function _construct()
15
+ {
16
+ parent::_construct();
17
+ $this->setTemplate('innobyte/core/button.phtml');
18
+ }
19
+
20
+ /**
21
+ * Return element html
22
+ *
23
+ * @param Varien_Data_Form_Element_Abstract $element
24
+ * @return string
25
+ */
26
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
27
+ {
28
+ return $this->_toHtml();
29
+ }
30
+
31
+ /**
32
+ * Return ajax url for button
33
+ *
34
+ * @return string
35
+ */
36
+ public function getAjaxSendReportUrl()
37
+ {
38
+ return Mage::helper('adminhtml')->getUrl('adminhtml/adminhtml_index/innoCoreSendReport', array('_current' => true));
39
+ }
40
+
41
+ /**
42
+ * "Send email" button html
43
+ *
44
+ * @return string
45
+ */
46
+ public function getButtonHtml()
47
+ {
48
+ $button = $this->getLayout()->createBlock('adminhtml/widget_button')
49
+ ->setData(array(
50
+ 'id' => 'innobyte_core_send_email_button',
51
+ 'label' => $this->helper('adminhtml')->__('Send email'),
52
+ 'onclick' => 'inno.core.sendReport(); return false;'
53
+ ));
54
+ return $button->toHtml();
55
+ }
56
+
57
+ }
app/code/local/Innobyte/Core/Block/System/Config/Form/Fieldset/Extensions.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Innobyte_Core_Block_System_Config_Form_Fieldset_Extensions
4
+ extends Mage_Adminhtml_Block_System_Config_Form_Fieldset
5
+ {
6
+
7
+ }
app/code/local/Innobyte/Core/Block/System/Config/Form/Fieldset/Shop.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Innobyte_Core_Block_System_Config_Form_Fieldset_Shop
4
+ extends Mage_Adminhtml_Block_System_Config_Form_Fieldset
5
+ {
6
+
7
+ public function render(Varien_Data_Form_Element_Abstract $element)
8
+ {
9
+ return '<div id="' . $element->getId() . '"></div>';
10
+ }
11
+ }
app/code/local/Innobyte/Core/Block/System/Config/Form/Renderer/Field.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Innobyte_Core_Block_System_Config_Form_Renderer_Field
4
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
5
+ {
6
+
7
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
8
+ {
9
+ $value = 1;
10
+ Mage::register('inno-',$element->getHint());
11
+ $websites = Mage::helper('innobyte_core/versions')
12
+ ->getAvailableWebsites($element->getHint());
13
+ if (!empty($websites)) {
14
+ $scopeWebsiteCode = $this->getRequest()->getParam('website');
15
+ $scopeWebsite = Mage::getModel('core/website')
16
+ ->load($this->getRequest()->getParam('website'), 'code');
17
+ $url = $scopeWebsite->getConfig('web/unsecure/base_url');
18
+ $domain = trim(preg_replace('/^.*?\\/\\/(.*)?\\//', '$1', $url));
19
+ if ($domain && $scopeWebsite && in_array($domain, $websites)) {
20
+ $html = '<strong class="ok">' . $this->__('Licensed') . '</strong>';
21
+ } elseif (!$scopeWebsiteCode) {
22
+ $domains = Mage::helper('innobyte_core/versions')->getAllStoreDomains();
23
+ $html = '<strong class="ok">' . $this->__('Licensed') . '</strong>';
24
+ } elseif ($scopeWebsiteCode && in_array($scopeWebsiteCode, $websites)) {
25
+ $html = '<strong class="ok">' . $this->__('Licensed') .$scopeWebsiteCode. '</strong>';
26
+ } else {
27
+ $html = '<strong class="required">' . $this->__('Please buy additional licence for the domain :') .'<br/>'.$domain. '</strong>';
28
+ }
29
+ } else {
30
+ Mage::getModel('core/config')->saveConfig(Innobyte_Core_Helper_Versions::INSTALLED.$element->getHint(), $value );
31
+ Mage::getConfig()->reinit();
32
+ Mage::app()->reinitStores();
33
+ $html = '<strong class="required">' . $this->__('Please enter a valid key') . '</strong>';
34
+ }
35
+ return $html;
36
+ }
37
+ }
app/code/local/Innobyte/Core/Block/System/Config/Form/Renderer/Website.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Innobyte_Core_Block_System_Config_Form_Renderer_Website
4
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
5
+ {
6
+
7
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
8
+ {
9
+ $html = '';
10
+ $r = Mage::getStoreConfig($element->getHint().'/license/ar');
11
+ $value = explode(',', str_replace($r, '', Mage::helper('core')->decrypt($element->getValue())));
12
+
13
+ $nameprefix = $element->getName();
14
+ $idprefix = $element->getId();
15
+
16
+ $element->setName($nameprefix . '[]');
17
+ $info = Mage::helper('innobyte_core/versions')->avs($element->getHint());
18
+
19
+ if (isset($info['d']) && isset($info['c']) && intval($info['c']) > 0) {
20
+ foreach (Mage::app()->getWebsites() as $website) {
21
+ $element->setChecked(false);
22
+
23
+ $id = $website->getId();
24
+ $name = $website->getName();
25
+
26
+ $element->setId($idprefix . '_' . $id);
27
+ $element->setValue($id);
28
+ $element->setClass('innobyte-available-sites');
29
+
30
+ if (in_array($id, $value) !== false) {
31
+ $element->setChecked(true);
32
+ }
33
+
34
+ if ($id != 0) {
35
+ $html .= '<div><label>' . $element->getElementHtml() . ' ' . $name . ' </label></div>';
36
+ }
37
+ }
38
+
39
+ $html .= '
40
+ <input id="' . $idprefix . '_diasbled" type="hidden" disabled="disabled" name="' . $nameprefix . '" />
41
+ <script type="text/javascript">
42
+
43
+ function updateInnobyteWebsites(){
44
+ $("' . $idprefix . '_diasbled").disabled = "disabled";
45
+ if($$(".innobyte-available-sites:checked").length >= ' . intval($info['c']) . '){
46
+ $$(".innobyte-available-sites").each(function(e){
47
+ if(!e.checked){
48
+ e.disabled = "disabled";
49
+ }
50
+ });
51
+ }else {
52
+ $$(".innobyte-available-sites").each(function(e){
53
+ if(!e.checked){
54
+ e.disabled = "";
55
+ }
56
+ });
57
+ if($$(".innobyte-available-sites:checked").length == 0){
58
+ $("' . $idprefix . '_diasbled").disabled = "";
59
+ }
60
+ }
61
+ }
62
+ $$(".innobyte-available-sites").each(function(e){
63
+ e.observe("click", function(){
64
+ updateInnobyteWebsites();
65
+ });
66
+ });
67
+ updateInnobyteWebsites();
68
+ </script>';
69
+ } else {
70
+ $html = sprintf('<strong class="required">%s</strong>', $this->__('Please enter a valid key'));
71
+ }
72
+
73
+ return $html;
74
+ }
75
+ }
app/code/local/Innobyte/Core/Helper/Config.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Innobyte_Core_Helper_Config extends Mage_Core_Helper_Abstract
4
+ {
5
+ const SHOP_URL = 'shop.innobyte.com/feeds/shop.html';
6
+ const SHOP_CACHE_KEY = 'innobyte_core_shop_cache_key';
7
+ const UPDATES_FEED_URL = 'http://shop.innobyte.com/feeds/updates.xml';
8
+ const EXTENSIONS_FEED_URL = 'http://shop.innobyte.com/feeds/extensions.xml';
9
+ }
app/code/local/Innobyte/Core/Helper/Data.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Innobyte_Core_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+
5
+
6
+ }
7
+
8
+
app/code/local/Innobyte/Core/Helper/Versions.php ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Innobyte_Core_Helper_Versions extends Mage_Core_Helper_Abstract
5
+ {
6
+ const EE_PLATFORM = 2;
7
+ const PE_PLATFORM = 1;
8
+ const CE_PLATFORM = 0;
9
+ const ENTERPRISE = 'Enterprise';
10
+ const ENTERPRISE_DETECT_EXTENSION = 'Enterprise';
11
+ const ENTERPRISE_DESIGN_NAME = "enterprise";
12
+ const PROFESSIONAL_DESIGN_NAME = "pro";
13
+ const INSTALLED = 'advanced/modules_disable_output/';
14
+
15
+ protected static $_platform = -1;
16
+ protected $_m = 'innobyte_core';
17
+
18
+ private function _e($m)
19
+ {
20
+ $se = $m;
21
+ if (!Mage::getStoreConfig($se.'/license/installed')
22
+ || (intval(Mage::getStoreConfig($se.'/license/count')) > 20
23
+ )) {
24
+ return array();
25
+ }
26
+
27
+ $timeToUpdate = 60 * 60 * 24 * 15;
28
+
29
+ $r = Mage::getStoreConfig($se.'/license/ar');
30
+ $t = Mage::getStoreConfig($se.'/license/time');
31
+ $s = Mage::getStoreConfig($se.'/license/websites');
32
+
33
+ $lastCheck = str_replace($r, '', Mage::helper('core')->decrypt($t));
34
+
35
+ $allsites = explode(',', str_replace($r, '', Mage::helper('core')->decrypt($s)));
36
+ $allsites = array_diff($allsites, array(""));
37
+
38
+ if (($lastCheck + $timeToUpdate) < time()) {
39
+ $key = Mage::getStoreConfig($se.'/license/key');
40
+ $this->a($key, intval(Mage::getStoreConfig($m.'/license/count')), $s, $se);
41
+ }
42
+
43
+ return $allsites;
44
+ }
45
+
46
+ public static function getPlatform()
47
+ {
48
+ if (self::$_platform == -1) {
49
+ $pathToClaim = BP . DS . "app" . DS . "etc" . DS . "modules"
50
+ . DS . self::ENTERPRISE . "_"
51
+ . self::ENTERPRISE_DETECT_EXTENSION . ".xml";
52
+ $pathToEEConfig = BP . DS . "app" . DS . "code" . DS . "core"
53
+ . DS . self::ENTERPRISE . DS
54
+ . self::ENTERPRISE_DETECT_EXTENSION . DS . "etc"
55
+ . DS . "config.xml";
56
+ $isCommunity = !file_exists($pathToClaim) || !file_exists($pathToEEConfig);
57
+ if ($isCommunity) {
58
+ self::$_platform = self::CE_PLATFORM;
59
+ } else {
60
+ $_xml = @simplexml_load_file($pathToEEConfig,'SimpleXMLElement', LIBXML_NOCDATA);
61
+ if(!$_xml===FALSE) {
62
+ $package = (string)$_xml->default->design->package->name;
63
+ $theme = (string)$_xml->install->design->theme->default;
64
+ $skin = (string)$_xml->stores->admin->design->theme->skin;
65
+ $isProffessional = ($package == self::PROFESSIONAL_DESIGN_NAME) && ($theme == self::PROFESSIONAL_DESIGN_NAME) && ($skin == self::PROFESSIONAL_DESIGN_NAME);
66
+ if ($isProffessional) {
67
+ self::$_platform = self::PE_PLATFORM;
68
+ return self::$_platform;
69
+ }
70
+ }
71
+ self::$_platform = self::EE_PLATFORM;
72
+ }
73
+ }
74
+ return self::$_platform;
75
+ }
76
+
77
+ /**
78
+ * Convert platform from string to int and backwards
79
+ * @static
80
+ * @param $platformCode
81
+ * @return int|string
82
+ */
83
+ public static function convertPlatform($platformCode)
84
+ {
85
+ if (is_numeric($platformCode)) {
86
+ // Convert predefined to letters code
87
+ $platform = ($platformCode == self::EE_PLATFORM ? 'ee' : ($platformCode == self::PE_PLATFORM ? 'pe'
88
+ : 'ce'));
89
+ } else if (is_string($platformCode)) {
90
+ $platformCode = strtolower($platformCode);
91
+ $platform = ($platformCode == 'ee' ? self::EE_PLATFORM : ($platformCode == 'pe' ? self::PE_PLATFORM
92
+ : self::CE_PLATFORM));
93
+ }else{$platform = self::CE_PLATFORM;}
94
+ return $platform;
95
+ }
96
+
97
+ public function getAvailableWebsites($m)
98
+ {
99
+ return $this->_e($m);
100
+ }
101
+
102
+
103
+ public static function convertVersion($v)
104
+ {
105
+ $digits = @explode(".", $v);
106
+ $version = 0;
107
+ if (is_array($digits)) {
108
+ foreach ($digits as $k => $v) {
109
+ $version += ($v * pow(10, max(0, (3 - $k))));
110
+ }
111
+
112
+ }
113
+ return $version;
114
+ }
115
+
116
+ public function a($k, $c = 0, $s = '', $m = '')
117
+ {
118
+ $value = 1;
119
+ if (!$this->_m || $this->_m == 'innobyte_core'){
120
+ $this->_m = $m;
121
+ }
122
+
123
+ if (!$k) {
124
+ $e = Mage::helper('core');
125
+ $se = $this->_m;
126
+ $value1 = Mage::getStoreConfig($se.'/license/ar');
127
+ $value2 =(string) '';//Mage::getStoreConfig($se.'/license/websites');
128
+ $groups = array(
129
+ 'license' => array(
130
+ 'fields' => array(
131
+ 'ar' => array('value' => $value1),
132
+ 'websites' => array('value' => $value2),
133
+ 'enabled' => array('value' => !$value),
134
+ 'time' => array(
135
+ 'value' => (string) $e->encrypt($value1 . (time() - (60 * 60 * 24 * 15 - 1800)) . $value1)
136
+ ),
137
+ 'count' => array('value' => $value)
138
+ )
139
+ )
140
+ );
141
+
142
+ Mage::getModel('adminhtml/config_data')
143
+ ->setSection($se)
144
+ ->setGroups($groups)
145
+ ->save();
146
+ Mage::getModel('core/config')->saveConfig(self::INSTALLED.$this->_m, $value );
147
+ Mage::getConfig()->reinit();
148
+ Mage::app()->reinitStores();
149
+ return;
150
+ }
151
+
152
+ try {
153
+ $ch = curl_init();
154
+ curl_setopt($ch, CURLOPT_URL, sprintf('http://shop.innobyte.com/feeds/l.php'));
155
+ curl_setopt($ch, CURLOPT_POST, true);
156
+ curl_setopt($ch, CURLOPT_POSTFIELDS, 'k='.urlencode($k)
157
+ . '&m='.$this->_m.'&d='
158
+ . urlencode(implode(',', $this->getAllStoreDomains()))
159
+ . '&p='.$this->getPlatform()
160
+ . '&x='.((Mage::getStoreConfigFlag(self::INSTALLED.$this->_m)==1)?'0':'1')
161
+ );
162
+ curl_setopt($ch, CURLOPT_TIMEOUT, 7);
163
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
164
+
165
+ $content = curl_exec($ch);
166
+ if (false === $content) {
167
+ Mage::throwException(curl_error($ch));
168
+ }
169
+
170
+ $r = Zend_Json::decode($content);
171
+ } catch (Exception $e){
172
+ Mage::throwException($this->__('Please try again later. '.$e->getMessage()));
173
+ return;
174
+ }
175
+
176
+ $e = Mage::helper('core');
177
+ $se = $this->_m;
178
+
179
+ $value = 1;
180
+ if (empty($r)) {
181
+ $value1 = Mage::getStoreConfig($se.'/license/ar');
182
+ $value2 =(string) '';
183
+ $groups = array(
184
+ 'license' => array(
185
+ 'fields' => array(
186
+ 'ar' => array('value' => $value1),
187
+ 'websites' => array('value' => $value2),
188
+ 'enabled' => array('value' => !$value),
189
+ 'time' => array(
190
+ 'value' => (string) $e->encrypt($value1 . (time() - (60 * 60 * 24 * 15 - 1800)) . $value1)
191
+ ),
192
+ 'count' => array('value' => $c + 1)
193
+ )
194
+ )
195
+ );
196
+
197
+
198
+ Mage::getModel('adminhtml/config_data')
199
+ ->setSection($se)
200
+ ->setGroups($groups)
201
+ ->save();
202
+ Mage::getModel('core/config')->saveConfig('advanced/modules_disable_output/'.$this->_m, $value );
203
+ Mage::getConfig()->reinit();
204
+ Mage::app()->reinitStores();
205
+
206
+ return;
207
+ }
208
+
209
+ $value1 = '';
210
+ $value2 = '';
211
+ if (isset($r['d']) && isset($r['c'])) {
212
+ $value1 = $e->encrypt(base64_encode(Zend_Json::encode($r)));
213
+ if (!$s) {
214
+ $s = Mage::getStoreConfig($se.'/license/websites');
215
+ }
216
+ $s = array_slice(explode(',', $r['d']), 0, $r['c']);
217
+ $value2 = $e->encrypt($value1 . implode(',', $s) . $value1);
218
+ $value = 0;
219
+ Mage::getModel('core/config')->saveConfig('advanced/modules_disable_output/'.$this->_m, 0 );
220
+ }
221
+ $groups = array(
222
+ 'license' => array(
223
+ 'fields' => array(
224
+ 'ar' => array('value' => $value1),
225
+ 'websites' => array('value' => (string) $value2),
226
+ 'time' => array(
227
+ 'value' => (string) $e->encrypt($value1 . time() . $value1)
228
+ ),
229
+ 'enabled' => array('value' => !$value),
230
+ 'installed' => array('value' => 1),
231
+ 'count' => array('value' => 0)
232
+ )
233
+ )
234
+ );
235
+
236
+ Mage::getModel('adminhtml/config_data')
237
+ ->setSection($se)
238
+ ->setGroups($groups)
239
+ ->save();
240
+
241
+ Mage::getConfig()->reinit();
242
+ Mage::app()->reinitStores();
243
+ }
244
+
245
+ public function getAllStoreDomains()
246
+ {
247
+ $domains = array();
248
+ foreach (Mage::app()->getWebsites() as $website) {
249
+ $url = $website->getConfig('web/unsecure/base_url');
250
+ if($domain = trim(preg_replace('/^.*?\\/\\/(.*)?\\//', '$1', $url))){
251
+ $domains[] = $domain;
252
+ }
253
+ $url = $website->getConfig('web/secure/base_url');
254
+ if($domain = trim(preg_replace('/^.*?\\/\\/(.*)?\\//', '$1', $url))){
255
+ $domains[] = $domain;
256
+ }
257
+ }
258
+
259
+ return array_unique($domains);
260
+ }
261
+
262
+ public function getAvailabelsWebsites($m = null)
263
+ {
264
+ $this->_m = $m;
265
+ return $this->_e($m);
266
+ }
267
+
268
+ public function avs($m)
269
+ {
270
+ return Zend_Json::decode(base64_decode(Mage::helper('core')->decrypt(Mage::getStoreConfig($m.'/license/ar'))));
271
+ }
272
+ }
app/code/local/Innobyte/Core/Model/Data.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Data model
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_Core
7
+ * @author Daniel Horobeanu <daniel.horobeanu@innobyte.com>
8
+ */
9
+ class Innobyte_Core_Model_Data extends Mage_Core_Model_Abstract
10
+ {
11
+ private $_extensionsCache = array();
12
+
13
+ public function install($event)
14
+ {
15
+ $s = $event->getEvent()->getSection();
16
+
17
+ $displayNames = Mage::app()->loadCache('innobytecore_extensions_feed');
18
+ if ($displayNames) {
19
+ $this->_extensionsCache = @unserialize($displayNames);
20
+ } else {
21
+ $model = Mage::getModel('innobyte_core/feed')
22
+ ->refreshExtensions();
23
+ if ($model) {
24
+ $displayNames = Mage::app()->loadCache('innobytecore_extensions_feed');
25
+ if ($displayNames) {
26
+ $this->_extensionsCache = @unserialize($displayNames);
27
+ }
28
+ }
29
+ }
30
+
31
+ if (array_key_exists(strtolower($s), array_change_key_case($this->_extensionsCache))) {
32
+ $j = Mage::getStoreConfig($s.'/license/key');
33
+ $c = 0;
34
+ // $c = Mage::getStoreConfig($s.'/license/count');
35
+ Mage::helper('innobyte_core/versions')->a($j, $c, '', $s);
36
+ }
37
+ }
38
+
39
+ public function init($event)
40
+ {
41
+ if ($event->getEvent()->getObject()->getData('section') == 'advanced') {
42
+ $g = $event->getEvent()->getObject()->getData('groups');
43
+ $ms = $g['modules_disable_output']['fields'];
44
+ $displayNames = Mage::app()->loadCache('innobytecore_extensions_feed');
45
+ if ($displayNames) {
46
+ $this->_extensionsCache = @unserialize($displayNames);
47
+ } else {
48
+ $model = Mage::getModel('innobyte_core/feed')
49
+ ->refreshExtensions();
50
+ if ($model) {
51
+ $displayNames = Mage::app()->loadCache('innobytecore_extensions_feed');
52
+ if ($displayNames) {
53
+ $this->_extensionsCache = @unserialize($displayNames);
54
+ }
55
+ }
56
+ }
57
+
58
+ $data = $event->getEvent()->getObject()->getData();
59
+ foreach ($ms as $m=>$v) {
60
+
61
+
62
+ if ($m == 'Innobyte_Core') {
63
+ continue;
64
+ }
65
+ if (strstr($m, 'Innobyte_') === false) {
66
+ continue;
67
+ }
68
+ if (array_key_exists(strtolower($m), array_change_key_case($this->_extensionsCache))) {
69
+ $j = Mage::getStoreConfig($m.'/license/key');
70
+ $info = Mage::helper('innobyte_core/versions')->avs($m);
71
+ $r = Mage::getStoreConfig($m.'/license/enabled');
72
+
73
+ if (isset($info['d']) && isset($info['c']) && intval($info['c']) > 0) {
74
+ foreach (Mage::app()->getWebsites() as $website) {
75
+ $id = $website->getId();
76
+ if ($r !== '1') {
77
+ $data['groups']['modules_disable_output']['fields'][$m]['value'] = '1';
78
+ break;
79
+ }
80
+ }
81
+ } else {
82
+ if ( ! $r ) {
83
+ $data['groups']['modules_disable_output']['fields'][$m]['value'] = '1';
84
+ }
85
+ }
86
+ }
87
+ }
88
+ $event->getEvent()->getObject()->setData($data);
89
+ }
90
+ }
91
+ }
app/code/local/Innobyte/Core/Model/Debug.php ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Debugger model.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_Core
7
+ * @author Daniel Horobeanu <daniel.horobeanu@innobyte.com>
8
+ */
9
+ class Innobyte_Core_Model_Debug
10
+ extends Mage_Core_Model_Abstract
11
+ {
12
+ const XML_RECIPIENTS_EMAIL_PATH = 'innobyte_core/debugger/email';
13
+
14
+ public function sendEmail($message)
15
+ {
16
+ $templateId = Mage::getStoreConfig('innobyte_core/debugger/email_template');
17
+ if (!$templateId) {
18
+ $templateId = 'innobyte_core_debugger_email_template';
19
+ }
20
+
21
+ $sender = $this->getSenderInfo();
22
+ $recepientEmail = $this->getRecipients();
23
+ $recepientName = '';
24
+ // Set variables that can be used in email template
25
+ $vars = $this->getEmailVars($message);
26
+
27
+ // Send Transactional Email
28
+ $translate = Mage::getSingleton('core/translate');
29
+ $mailTemplate = Mage::getModel('core/email_template');
30
+ // add attachments
31
+ $folder = Mage::getBaseDir('var').'/log/';
32
+ $files = glob($folder.'*');
33
+ foreach ($files as $file) {
34
+ $mailTemplate->getMail()->createAttachment(
35
+ file_get_contents($file),
36
+ Zend_Mime::TYPE_OCTETSTREAM,
37
+ Zend_Mime::DISPOSITION_ATTACHMENT,
38
+ Zend_Mime::ENCODING_BASE64,
39
+ basename($file)
40
+ );
41
+ }
42
+ $mailTemplate->sendTransactional($templateId, $sender, $recepientEmail, $recepientName, $vars);
43
+ $translate->setTranslateInline(true);
44
+ }
45
+
46
+ public function getSenderInfo()
47
+ {
48
+ $senderName = 'Innobyte Debugger';
49
+ $senderEmail = Mage::getStoreConfig('trans_email/ident_general/email');
50
+ $sender = array(
51
+ 'name' => $senderName,
52
+ 'email' => $senderEmail
53
+ );
54
+
55
+ return $sender;
56
+ }
57
+
58
+ /**
59
+ * Get email receivers.
60
+ *
61
+ * @param null $storeId
62
+ * @return string
63
+ */
64
+ public function getRecipients()
65
+ {
66
+ $configInfo = Mage::getStoreConfig(self::XML_RECIPIENTS_EMAIL_PATH);
67
+ $recipients = explode(',', $configInfo);
68
+ if (!empty($recipients[0])) {
69
+ return $recipients;
70
+ }
71
+ return false;
72
+ }
73
+
74
+
75
+ public function getEmailVars($message)
76
+ {
77
+ $magento = array (
78
+ 'edition' => 'NA / assuming Community',
79
+ 'version' => Mage::getVersion(),
80
+ 'domains' => Mage::helper('innobyte_core/versions')->getAllStoreDomains(),
81
+ 'compilation' => $this->getCompilerStatus(),
82
+ 'inno_extensions' => $this->getInnobyteExtensions(),
83
+ 'inno_extensions_info' => $this->getConfigInnoData(),
84
+ 'disabled_modules' => $this->getDisabledModules(),
85
+ 'rewrites' => $this->getRewrites(),
86
+ 'crontab' => $this->getCrontabInfo(),
87
+ 'crons' => $this->getCrons(),
88
+ );
89
+
90
+ if (method_exists('Mage','getEdition')) {
91
+ $magento['edition'] = Mage::getEdition();
92
+ }
93
+
94
+ ob_start();
95
+ phpinfo();
96
+ $phpInfo = ob_get_contents();
97
+ ob_get_clean();
98
+
99
+ $vars = array(
100
+ 'php_info' => $phpInfo,
101
+ 'magento' => $magento,
102
+ 'explanation_message' => $message,
103
+ );
104
+
105
+ return $vars;
106
+ }
107
+
108
+ public function getCompilerStatus()
109
+ {
110
+ if (defined('COMPILER_INCLUDE_PATH')) {
111
+ return '<span style="color:green">Enabled</span>';
112
+ } else {
113
+ return 'Disabled';
114
+ }
115
+ }
116
+
117
+ public function getInnobyteExtensions()
118
+ {
119
+ $extensions = array();
120
+
121
+ $modules = array_keys((array)Mage::getConfig()->getNode('modules')->children());
122
+ sort($modules);
123
+
124
+ foreach ($modules as $moduleName) {
125
+ if (strstr($moduleName, 'Innobyte_') === false) {
126
+ continue;
127
+ }
128
+
129
+ // Detect installed version
130
+ $ver = Mage::getConfig()->getModuleConfig($moduleName)->version;
131
+ $extensionData = array(
132
+ 'version' => $ver,
133
+ 'name' => $moduleName,
134
+ );
135
+ $extensions[] = $extensionData;
136
+ }
137
+
138
+ return $extensions;
139
+ }
140
+
141
+ public function getDisabledModules()
142
+ {
143
+ $modules = array_keys((array)Mage::getConfig()->getNode('modules')->children());
144
+ $dispatchResult = new Varien_Object($modules);
145
+ $modules = $dispatchResult->toArray();
146
+
147
+ sort($modules);
148
+ $disabledModules = array();
149
+ foreach ($modules as $moduleName) {
150
+ $path = 'advanced/modules_disable_output/'.$moduleName;
151
+ if (Mage::getStoreConfig($path)) {
152
+ $disabledModules[] = $moduleName;
153
+ }
154
+ }
155
+
156
+ return $disabledModules;
157
+ }
158
+
159
+ public function getRewrites()
160
+ {
161
+ $folders = array('app/code/local/', 'app/code/community/');
162
+ $configFiles = array();
163
+ foreach ($folders as $folder){
164
+ $files = glob($folder.'*/*/etc/config.xml');
165
+ $configFiles = array_merge($configFiles, $files);
166
+ }
167
+ $rewrites = array();
168
+
169
+ foreach ($configFiles as $file){
170
+ $dom = new DOMDocument;
171
+ $dom->loadXML(file_get_contents($file));
172
+ $xpath = new DOMXPath($dom);
173
+ $path = '//rewrite/*';
174
+ $text = $xpath->query($path);
175
+ foreach ($text as $rewriteElement){
176
+ //what is overwritten (model, block, helper)
177
+ $type = $rewriteElement->parentNode->parentNode->parentNode->tagName;
178
+ //module identifier that is being rewritten (core, catalog, sales, ...)
179
+ $parent = $rewriteElement->parentNode->parentNode->tagName;
180
+ //element that is rewritten (layout, product, category, order)
181
+ $name = $rewriteElement->tagName;
182
+ foreach ($rewriteElement->childNodes as $element){
183
+ $rewrites[$type][$parent.'/'.$name][] = $element->textContent;//class that rewrites it
184
+ }
185
+ }
186
+ }
187
+ return $rewrites;
188
+ }
189
+
190
+ public function getCrons()
191
+ {
192
+ $results = array();
193
+ $jobs = (array)Mage::getConfig()->getNode('crontab/jobs');
194
+ $collection = Mage::getResourceModel('cron/schedule_collection');
195
+ foreach ($collection as $item) {
196
+ $job = $jobs[$item['job_code']];
197
+ $results[$item['job_code']]['info'] = array (
198
+ 'cron_expr' => $job->schedule->cron_expr,
199
+ 'model' => $job->run->model
200
+ );
201
+ $results[$item['job_code']]['schedule'] = array(
202
+ 'messages' => $item['messages'],
203
+ 'created_at' => $item['created_at'],
204
+ 'scheduled_at' => $item['scheduled_at'],
205
+ 'executed_at' => $item['executed_at'],
206
+ 'finished_at' => $item['finished_at'],
207
+ 'status' => $item['status'],
208
+ );
209
+ }
210
+
211
+ return $results;
212
+ }
213
+
214
+ public function getCrontabInfo()
215
+ {
216
+ $result = array();
217
+ if(function_exists('exec')) {
218
+ exec('crontab -l', $result);
219
+ $user = array();
220
+ exec('whoami', $user);
221
+ if (!isset($user[0])) {
222
+ $user[0] = '';
223
+ }
224
+ if(!count($result)) {
225
+ $result[] = 'No cron jobs found in crontab - for web server user "'.$user[0].'"... maybe is added on other user';
226
+ }
227
+ } else {
228
+ $result[] = 'EXEC is disabled so we cannot see if Magento cron is active';
229
+ }
230
+ return $result;
231
+ }
232
+
233
+ public function getConfigInnoData()
234
+ {
235
+ $collection = Mage::getModel('core/config_data')->getCollection()
236
+ ->addFieldToFilter('path', array('like' => '%innobyte%'))
237
+ ->load();
238
+ $results = array();
239
+ foreach($collection as $item){
240
+ $results[$item->getConfigId()] = array(
241
+ 'path' => $item->getPath(),
242
+ 'value' => $item->getValue(),
243
+ );
244
+ }
245
+
246
+ return $results;
247
+ }
248
+ }
app/code/local/Innobyte/Core/Model/Feed.php ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * AdminNotification Feed model
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_Core
7
+ * @author Daniel Horobeanu <daniel.horobeanu@innobyte.com>
8
+ */
9
+ class Innobyte_Core_Model_Feed extends Mage_AdminNotification_Model_Feed
10
+ {
11
+ const XML_USE_HTTPS_PATH = 'innobyte_core/adminnotification/use_https';
12
+ const XML_FEED_URL_PATH = 'innobyte_core/adminnotification/url';
13
+ const XML_FREQUENCY_PATH = 'innobyte_core/adminnotification/frequency';
14
+ const XML_LAST_UPDATE_PATH = 'innobyte_core/adminnotification/last_update';
15
+
16
+ /**
17
+ * Get news from Innobyte Magento blog posts feed
18
+ *
19
+ * @return Mage_AdminNotification_Model_Feed
20
+ */
21
+ public function news()
22
+ {
23
+ if (($this->getFrequency() + $this->getLastUpdate()) > time()) {
24
+ return $this;
25
+ }
26
+ $feedData = array();
27
+ $feedXml = $this->getFeedData();
28
+ if ($feedXml && $feedXml->channel && $feedXml->channel->item) {
29
+ foreach ($feedXml->channel->item as $item) {
30
+ $feedData[] = array(
31
+ 'severity' => (int)$item->severity?(int)$item->severity:Mage_AdminNotification_Model_Inbox::SEVERITY_NOTICE,
32
+ 'date_added' => $this->getDate((string)$item->pubDate),
33
+ 'title' => (string)$item->title,
34
+ 'description' => (string)$item->description,
35
+ 'url' => (string)$item->link,
36
+ );
37
+ }
38
+ if ($feedData) {
39
+ Mage::getModel('adminnotification/inbox')
40
+ ->parse(array_reverse($feedData));
41
+ }
42
+ }
43
+ $this->setLastUpdate();
44
+
45
+ return $this;
46
+ }
47
+
48
+
49
+ public function checkExtensions()
50
+ {
51
+ $passedTime = time() - Mage::app()->loadCache('innobytecore_extensions_lastcheck');
52
+ if (!(Mage::app()->loadCache('innobytecore_extensions_feed'))
53
+ || $passedTime > Mage::getStoreConfig(self::XML_FREQUENCY_PATH)) {
54
+ $this->refreshExtensions();
55
+ }
56
+ }
57
+
58
+ public function refreshExtensions()
59
+ {
60
+ $exts = array();
61
+ try {
62
+ $node = $this->getFeedData(Innobyte_Core_Helper_Config::EXTENSIONS_FEED_URL);
63
+ if (!$node){
64
+ return false;
65
+ }
66
+ foreach ($node->children() as $ext) {
67
+ $exts[(string)$ext->name] = array(
68
+ 'display_name' => (string)$ext->display_name,
69
+ 'version' => (string)$ext->version,
70
+ 'url' => (string)$ext->url
71
+ );
72
+ }
73
+
74
+ Mage::app()->saveCache(serialize($exts), 'innobytecore_extensions_feed');
75
+ Mage::app()->saveCache(time(), 'innobytecore_extensions_lastcheck');
76
+ return true;
77
+ } catch (Exception $e) {
78
+ return false;
79
+ }
80
+ }
81
+
82
+
83
+ public function checkUpdates()
84
+ {
85
+ $passedTime = time() - Mage::app()->loadCache('innobytecore_updates_lastcheck');
86
+ if ($passedTime > Mage::getStoreConfig(self::XML_FREQUENCY_PATH)) {
87
+ $this->refreshUpdates();
88
+ }
89
+ }
90
+
91
+ public function refreshUpdates()
92
+ {
93
+ $feedData = array();
94
+ try {
95
+ $node = $this->getFeedData(Innobyte_Core_Helper_Config::UPDATES_FEED_URL);
96
+ if (!$node) {
97
+ return false;
98
+ }
99
+ foreach ($node->children() as $item) {
100
+ if ($this->isInteresting($item)) {
101
+ $date = strtotime((string)$item->date);
102
+ if (!Mage::getStoreConfig('innobyte_core/install/run')
103
+ || (Mage::getStoreConfig('innobyte_core/install/run') < $date)
104
+ ) {
105
+ $feedData[] = array(
106
+ 'severity' => (int)$item->severity?(int)$item->severity:Mage_AdminNotification_Model_Inbox::SEVERITY_NOTICE,
107
+ 'date_added' => $this->getDate((string)$item->date),
108
+ 'title' => (string)$item->title,
109
+ 'description' => (string)$item->content,
110
+ 'url' => (string)$item->url,
111
+ );
112
+ }
113
+ }
114
+ }
115
+
116
+ $adminnotificationModel = Mage::getModel('adminnotification/inbox');
117
+ if ($feedData && is_object($adminnotificationModel)) {
118
+ $adminnotificationModel->parse($feedData);
119
+ }
120
+
121
+ Mage::app()->saveCache(time(), 'innobytecore_updates_lastcheck');
122
+ return true;
123
+ } catch (Exception $e) {
124
+ return false;
125
+ }
126
+ }
127
+
128
+ public function isInteresting($item)
129
+ {
130
+ $interests = @explode(',', Mage::getStoreConfig('innobyte_core/adminnotification/feeds'));
131
+
132
+ $types = @explode(",", (string)$item->type);
133
+ $exts = @explode(",", (string)$item->extensions);
134
+
135
+ foreach($types as $type){
136
+ if(array_search($type, $interests) !== false){
137
+ return true;
138
+ }
139
+ if($type == Innobyte_Core_Model_Source_Feed_Type::TYPE_RELEASE){
140
+ foreach($exts as $ext){
141
+ if ($this->isExtensionInstalled($ext)) {
142
+ return true;
143
+ }
144
+ }
145
+ }
146
+ }
147
+ return false;
148
+ }
149
+
150
+ public function isExtensionInstalled($code)
151
+ {
152
+ $modules = array_keys((array)Mage::getConfig()->getNode('modules')->children());
153
+
154
+ foreach ($modules as $moduleName) {
155
+ if ($moduleName == $code) {
156
+ return true;
157
+ }
158
+ }
159
+ return false;
160
+ }
161
+
162
+ /**
163
+ * Retrieve DB date from RSS date
164
+ *
165
+ * @param string $rssDate
166
+ * @return string YYYY-MM-DD YY:HH:SS
167
+ */
168
+ public function getDate($rssDate)
169
+ {
170
+ return gmdate('Y-m-d H:i:s', strtotime($rssDate));
171
+ }
172
+
173
+ /**
174
+ * Retrieve Update Frequency
175
+ *
176
+ * @return int
177
+ */
178
+ public function getFrequency()
179
+ {
180
+ return Mage::getStoreConfig(self::XML_FREQUENCY_PATH) * 3600;
181
+ }
182
+
183
+ public function getLastUpdate()
184
+ {
185
+ return Mage::app()->loadCache('innobytecore_notifications_lastcheck');
186
+ }
187
+
188
+ public function setLastUpdate()
189
+ {
190
+ Mage::app()->saveCache(time(), 'innobytecore_notifications_lastcheck');
191
+
192
+ return $this;
193
+ }
194
+
195
+ /**
196
+ * Retrieve feed data as XML element
197
+ *
198
+ * @return SimpleXMLElement
199
+ */
200
+ public function getFeedData($url = null)
201
+ {
202
+ if (!$url){
203
+ $url = $this->getFeedUrl();
204
+ }
205
+ $curl = new Varien_Http_Adapter_Curl();
206
+ $curl->setConfig(array(
207
+ 'timeout' => 2
208
+ ));
209
+ $curl->write(Zend_Http_Client::GET, $url, '1.0');
210
+ $data = $curl->read();
211
+
212
+ if (Zend_Http_Response::extractCode($data) != 200){
213
+ $url = 'www.innobyte.com/blog/category/magento/feed/';
214
+ $curl->write(Zend_Http_Client::GET, $url, '1.0');
215
+ $data = $curl->read();
216
+ }
217
+
218
+ if (Zend_Http_Response::extractCode($data) != 200){
219
+ return false;
220
+ }
221
+ if ($data === false) {
222
+ return false;
223
+ }
224
+ $data = preg_split('/^\r?$/m', $data, 2);
225
+ $data = trim($data[1]);
226
+ $curl->close();
227
+
228
+ try {
229
+ libxml_use_internal_errors(true);
230
+ $xml = new SimpleXMLElement($data);
231
+ } catch (Exception $e) {
232
+ return false;
233
+ }
234
+
235
+ return $xml;
236
+ }
237
+
238
+ public function getFeedUrl()
239
+ {
240
+ if (is_null($this->_feedUrl)) {
241
+ $prot = 'http://';
242
+ if (Mage::getStoreConfigFlag(self::XML_USE_HTTPS_PATH)) {
243
+ $prot = 'https://';
244
+ }
245
+ $this->_feedUrl = $prot.Mage::getStoreConfig(self::XML_FEED_URL_PATH);
246
+ }
247
+ return $this->_feedUrl;
248
+ }
249
+ }
app/code/local/Innobyte/Core/Model/Source/Config/Enabledisable.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Innobyte_Core_Model_Source_Config_Enabledisable {
4
+
5
+ /**
6
+ * Options getter
7
+ *
8
+ * @return int
9
+ */
10
+ public function toOptionArray()
11
+ {
12
+ $options = array(
13
+ array(
14
+ 'value' => 0,
15
+ 'label' => Mage::helper('innobyte_core')->__('No')),
16
+ );
17
+
18
+ $ext = Mage::registry('inno-');
19
+ if ($ext) {
20
+ $websites = Mage::helper('innobyte_core/versions')->getAvailabelsWebsites($ext);
21
+ }
22
+ if (empty($websites)) {
23
+ $options[] = array(
24
+ 'value' => 1,
25
+ 'label' => Mage::helper('innobyte_core')->__('Yes')
26
+ );
27
+ }
28
+
29
+ return $options;
30
+ }
31
+ }
app/code/local/Innobyte/Core/Model/Source/Feed/Type.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Innobyte_Core_Model_Source_Feed_Type
3
+ extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
4
+ {
5
+
6
+ const TYPE_INFO = 'info'; // Innobyte info
7
+ const TYPE_PROMO = 'promo'; // Promotions/Discounts
8
+ const TYPE_RELEASE = 'release'; // New Releases
9
+ const TYPE_UPDATE = 'update'; // Extensions updates
10
+
11
+
12
+ public function toOptionArray()
13
+ {
14
+ return array(
15
+ array(
16
+ 'value' => self::TYPE_UPDATE,
17
+ 'label' => Mage::helper('innobyte_core')->__('Extensions updates')),
18
+ array(
19
+ 'value' => self::TYPE_RELEASE,
20
+ 'label' => Mage::helper('innobyte_core')->__('New Releases')),
21
+ array(
22
+ 'value' => self::TYPE_PROMO,
23
+ 'label' => Mage::helper('innobyte_core')->__('Promotions/Discounts')),
24
+ array(
25
+ 'value' => self::TYPE_INFO,
26
+ 'label' => Mage::helper('innobyte_core')->__('Other information'))
27
+ );
28
+ }
29
+
30
+ /**
31
+ * Retrive all attribute options
32
+ *
33
+ * @return array
34
+ */
35
+ public function getAllOptions()
36
+ {
37
+ return $this->toOptionArray();
38
+ }
39
+
40
+
41
+ /**
42
+ * Returns label for value
43
+ *
44
+ * @param string $value
45
+ * @return string
46
+ */
47
+ public function getLabel($value)
48
+ {
49
+ $options = $this->toOptionArray();
50
+ foreach ($options as $v) {
51
+ if ($v['value'] == $value) {
52
+ return $v['label'];
53
+ }
54
+ }
55
+ return '';
56
+ }
57
+
58
+ /**
59
+ * Returns array ready for use by grid
60
+ *
61
+ * @return array
62
+ */
63
+ public function getGridOptions()
64
+ {
65
+ $items = $this->getAllOptions();
66
+ $out = array();
67
+ foreach ($items as $item) {
68
+ $out[$item['value']] = $item['label'];
69
+ }
70
+ return $out;
71
+ }
72
+ }
app/code/local/Innobyte/Core/controllers/Adminhtml/IndexController.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml Core IndexController.
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_Core
8
+ * @author Daniel Horobeanu <daniel.horobeanu@innobyte.com>
9
+ *
10
+ */
11
+ class Innobyte_Core_Adminhtml_IndexController
12
+ extends Mage_Adminhtml_Controller_Action
13
+ {
14
+
15
+ /**
16
+ * Send report
17
+ */
18
+ public function innoCoreSendReportAction()
19
+ {
20
+ $result['code'] = 'success';
21
+ $result['message'] = 'Report was successfully sent.';
22
+ try {
23
+ $message = $this->getRequest()->getPost('message', 'No message');
24
+ $model = Mage::getModel('innobyte_core/debug');
25
+ $model->sendEmail($message);
26
+ } catch (Exception $e) {
27
+ $result['code'] = 'error';
28
+ $result['message'] = $e->getMessage();
29
+ }
30
+
31
+ Mage::app()->getResponse()->setBody(json_encode($result));
32
+ }
33
+
34
+ }
app/code/local/Innobyte/Core/etc/config.xml ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Innobyte_Core>
5
+ <version>0.0.1</version>
6
+ </Innobyte_Core>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <innobyte_core>
11
+ <class>Innobyte_Core_Model</class>
12
+ </innobyte_core>
13
+ </models>
14
+ <helpers>
15
+ <innobyte_core>
16
+ <class>Innobyte_Core_Helper</class>
17
+ </innobyte_core>
18
+ </helpers>
19
+ <blocks>
20
+ <innobyte_core>
21
+ <class>Innobyte_Core_Block</class>
22
+ </innobyte_core>
23
+ </blocks>
24
+ <template>
25
+ <email>
26
+ <innobyte_core_debugger_email_template translate="label" module="innobyte_core">
27
+ <label>Innobyte Core - Debug</label>
28
+ <file>innobyte/core/debug.html</file>
29
+ <type>html</type>
30
+ </innobyte_core_debugger_email_template>
31
+ </email>
32
+ </template>
33
+ </global>
34
+ <default>
35
+ <innobyte_core>
36
+ <adminnotification>
37
+ <url>www.innobyte.com/category/magento/feed/</url>
38
+ <use_https>0</use_https>
39
+ <frequency>86400</frequency>
40
+ <enabled>1</enabled>
41
+ <feeds>info,promo,update,release</feeds>
42
+ </adminnotification>
43
+ <debugger>
44
+ <email>shop@innobyte.com</email>
45
+ <explanation_message>No message</explanation_message>
46
+ </debugger>
47
+ </innobyte_core>
48
+ </default>
49
+ <admin>
50
+ <routers>
51
+ <adminhtml>
52
+ <args>
53
+ <modules>
54
+ <innobyte_core after="Mage_Adminhtml">Innobyte_Core</innobyte_core>
55
+ </modules>
56
+ </args>
57
+ </adminhtml>
58
+ </routers>
59
+ </admin>
60
+ <adminhtml>
61
+ <layout>
62
+ <updates>
63
+ <innobyte_core module="Innobyte_Core">
64
+ <file>innobyte/core.xml</file>
65
+ </innobyte_core>
66
+ </updates>
67
+ </layout>
68
+
69
+ <acl>
70
+ <resources>
71
+ <all>
72
+ <title>Allow Everything</title>
73
+ </all>
74
+ <admin>
75
+ <children>
76
+ <system>
77
+ <children>
78
+ <config>
79
+ <children>
80
+ <innobyte_core>
81
+ <title>Innobyte - All</title>
82
+ </innobyte_core>
83
+ <innobyte_shop>
84
+ <title>Innobyte - Shop</title>
85
+ </innobyte_shop>
86
+ </children>
87
+ </config>
88
+ </children>
89
+ </system>
90
+ </children>
91
+ </admin>
92
+ </resources>
93
+ </acl>
94
+ <events>
95
+ <controller_action_predispatch>
96
+ <observers>
97
+ <innobyte_core_feed>
98
+ <type>singleton</type>
99
+ <class>innobyte_core/feed</class>
100
+ <method>news</method>
101
+ </innobyte_core_feed>
102
+ <innobyte_core_updates>
103
+ <type>singleton</type>
104
+ <class>innobyte_core/feed</class>
105
+ <method>checkUpdates</method>
106
+ </innobyte_core_updates>
107
+ <innobyte_core_extensions>
108
+ <type>singleton</type>
109
+ <class>innobyte_core/feed</class>
110
+ <method>checkExtensions</method>
111
+ </innobyte_core_extensions>
112
+ </observers>
113
+ </controller_action_predispatch>
114
+
115
+ <admin_system_config_section_save_after>
116
+ <observers>
117
+ <innobyte_core_install>
118
+ <type>model</type>
119
+ <class>innobyte_core/data</class>
120
+ <method>install</method>
121
+ </innobyte_core_install>
122
+ </observers>
123
+ </admin_system_config_section_save_after>
124
+ <model_config_data_save_before>
125
+ <observers>
126
+ <innobyte_core_init_setup>
127
+ <type>model</type>
128
+ <class>innobyte_core/data</class>
129
+ <method>init</method>
130
+ </innobyte_core_init_setup>
131
+ </observers>
132
+ </model_config_data_save_before>
133
+ </events>
134
+ </adminhtml>
135
+ </config>
app/code/local/Innobyte/Core/etc/system.xml ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <innobyte_core translate="label" module="innobyte_core">
5
+ <label>Innobyte Extensions</label>
6
+ <sort_order>1</sort_order>
7
+ </innobyte_core>
8
+ </tabs>
9
+ <sections>
10
+ <innobyte_core translate="label" module="innobyte_core">
11
+ <label>Info</label>
12
+ <tab>innobyte_core</tab>
13
+ <frontend_type>text</frontend_type>
14
+ <sort_order>99999</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>1</show_in_website>
17
+ <show_in_store>1</show_in_store>
18
+ <groups>
19
+ <extensions translate="label">
20
+ <label>Installed Innobyte Extensions</label>
21
+ <frontend_type>text</frontend_type>
22
+ <frontend_model>innobyte_core/system_config_form_fieldset_extensions</frontend_model>
23
+ <sort_order>2</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
+ </extensions>
28
+ <adminnotification>
29
+ <label>Innobyte Notifications</label>
30
+ <frontend_type>text</frontend_type>
31
+ <sort_order>60</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>1</show_in_website>
34
+ <show_in_store>1</show_in_store>
35
+ <fields>
36
+ <feeds translate="label">
37
+ <label>I'd like to be informed about:</label>
38
+ <comment></comment>
39
+ <frontend_type>multiselect</frontend_type>
40
+ <sort_order>100</sort_order>
41
+ <show_in_default>1</show_in_default>
42
+ <show_in_website>1</show_in_website>
43
+ <show_in_store>1</show_in_store>
44
+ <can_be_empty>1</can_be_empty>
45
+ <source_model>innobyte_core/source_feed_type</source_model>
46
+ </feeds>
47
+
48
+ </fields>
49
+ </adminnotification>
50
+ <debugger>
51
+ <label>Debugger / Contact Us</label>
52
+ <frontend_type>text</frontend_type>
53
+ <sort_order>70</sort_order>
54
+ <show_in_default>1</show_in_default>
55
+ <show_in_website>1</show_in_website>
56
+ <show_in_store>1</show_in_store>
57
+ <fields>
58
+ <email translate="label">
59
+ <label>Send Debug Info to</label>
60
+ <comment><![CDATA[
61
+ email address that will receive the debug report. You have to "Save Config" first then "Send email".
62
+ ]]>
63
+ </comment>
64
+ <frontend_type>text</frontend_type>
65
+ <sort_order>100</sort_order>
66
+ <show_in_default>1</show_in_default>
67
+ <show_in_website>0</show_in_website>
68
+ <show_in_store>0</show_in_store>
69
+ <can_be_empty>1</can_be_empty>
70
+ <source_model>innobyte_core/source_feed_type</source_model>
71
+ </email>
72
+
73
+ <email_template translate="label">
74
+ <label>Email Template</label>
75
+ <frontend_type>select</frontend_type>
76
+ <source_model>adminhtml/system_config_source_email_template</source_model>
77
+ <sort_order>110</sort_order>
78
+ <show_in_default>1</show_in_default>
79
+ <show_in_website>0</show_in_website>
80
+ <show_in_store>0</show_in_store>
81
+ <comment>
82
+ <![CDATA[
83
+ if you create and select a custom email template (not recommended). You have to "Save Config" first then "Send email".
84
+ ]]>
85
+ </comment>
86
+ </email_template>
87
+
88
+ <explanation_message translate="label">
89
+ <label>Message</label>
90
+ <frontend_type>textarea</frontend_type>
91
+ <sort_order>120</sort_order>
92
+ <show_in_default>1</show_in_default>
93
+ <show_in_website>0</show_in_website>
94
+ <show_in_store>0</show_in_store>
95
+ <comment>
96
+ <![CDATA[
97
+ this message will help us better understand your problem.
98
+ ]]>
99
+ </comment>
100
+ </explanation_message>
101
+
102
+ <send_now translate="label comment">
103
+ <label></label>
104
+ <frontend_type>button</frontend_type>
105
+ <frontend_model>innobyte_core/system_config_button</frontend_model>
106
+ <sort_order>140</sort_order>
107
+ <show_in_default>1</show_in_default>
108
+ <show_in_website>0</show_in_website>
109
+ <show_in_store>0</show_in_store>
110
+ <comment>
111
+ <![CDATA[
112
+ it will instantly send a troubleshooter report to the above email address.
113
+ The email contains information regarding your Magento edition, version, rewrites, cron jobs,
114
+ PHP information, Innobyte extensions configuration data and all the log files found in Magento log folder.
115
+ ]]>
116
+ </comment>
117
+ </send_now>
118
+
119
+ </fields>
120
+ </debugger>
121
+ </groups>
122
+ </innobyte_core>
123
+ <innobyte_shop>
124
+ <label>Shop</label>
125
+ <tab>innobyte_core</tab>
126
+ <class>innobyte-shop</class>
127
+ <frontend_type>text</frontend_type>
128
+ <sort_order>9999</sort_order>
129
+ <show_in_default>1</show_in_default>
130
+ <show_in_website>1</show_in_website>
131
+ <show_in_store>1</show_in_store>
132
+ <groups>
133
+ <extensions translate="label">
134
+ <label>Innobyte Extensions Shop</label>
135
+ <frontend_type>text</frontend_type>
136
+ <frontend_model>innobyte_core/system_config_form_fieldset_shop</frontend_model>
137
+ <sort_order>2</sort_order>
138
+ <show_in_default>1</show_in_default>
139
+ <show_in_website>1</show_in_website>
140
+ <show_in_store>1</show_in_store>
141
+ </extensions>
142
+ </groups>
143
+ </innobyte_shop>
144
+ </sections>
145
+ </config>
app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Catalog/Product/Edit.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Rewrite catalog product edit block.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Block_Adminhtml_Catalog_Product_Edit
11
+ extends Mage_Adminhtml_Block_Catalog_Product_Edit
12
+ {
13
+ /**
14
+ * @Override Added 3 more buttons, noting else changed.
15
+ */
16
+ protected function _prepareLayout()
17
+ {
18
+ $helper = Mage::helper('innobyte_emag_marketplace');
19
+ if (!$helper->isProductActionValid($this->getProduct())) {
20
+ return parent::_prepareLayout();
21
+ }
22
+ $storeId = $helper->getCurrStoreId();
23
+ $emagProduct = Mage::getModel('innobyte_emag_marketplace/product')
24
+ ->loadByProdIdAndStore($this->getProductId(), $storeId);
25
+
26
+ $productTabsBlock = $this->getLayout()->getBlock('product_tabs');
27
+ $tabsContainerId = $productTabsBlock ?
28
+ $productTabsBlock->getId() : 'product_info_tabs';
29
+ $canMakeApiCall = $helper->canMakeApiCall($storeId);
30
+ $syncBtnDisabled = $emagProduct->getId() && $canMakeApiCall ? 0 : 1;
31
+ $offerBtnDisabled = 1;
32
+ if (($emagProduct->isSynced() || $emagProduct->getPartNumberKey())
33
+ && $canMakeApiCall) {
34
+ $offerBtnDisabled = 0;
35
+ }
36
+ $title = $helper->__(
37
+ 'Please configure extension from System -> Configuration -> eMAG Marketplace'
38
+ );
39
+ $this->setChild(
40
+ 'emag_send_product_btn',
41
+ $this->getLayout()->createBlock('adminhtml/widget_button')
42
+ ->setData(
43
+ array(
44
+ 'label' => $helper->__('Send eMAG product'),
45
+ 'onclick' => 'inno.emagMarketplace.send(\''
46
+ . $tabsContainerId
47
+ . '\',\''
48
+ . Mage::helper('adminhtml')->escapeUrl(
49
+ Mage::helper('adminhtml')->getUrl(
50
+ 'adminhtml/emag_product/send',
51
+ array('_current' => 1, 'send' => 'product')
52
+ )
53
+ )
54
+ . '\', \'product\')',
55
+ 'class' => 'go',
56
+ 'disabled' => $syncBtnDisabled,
57
+ 'title' => !$canMakeApiCall ? $title : '',
58
+ )
59
+ )
60
+ ->setDisabled($syncBtnDisabled)
61
+ );
62
+ $this->setChild(
63
+ 'emag_send_offer_btn',
64
+ $this->getLayout()->createBlock('adminhtml/widget_button')
65
+ ->setData(
66
+ array(
67
+ 'label' => $helper->__('Send eMAG offer'),
68
+ 'onclick' => 'inno.emagMarketplace.send(\''
69
+ . $tabsContainerId
70
+ . '\',\''
71
+ . Mage::helper('adminhtml')->escapeUrl(
72
+ Mage::helper('adminhtml')->getUrl(
73
+ 'adminhtml/emag_product/send',
74
+ array('_current' => 1, 'send' => 'offer')
75
+ )
76
+ )
77
+ . '\', \'offer\')',
78
+ 'class' => 'go',
79
+ 'disabled' => $offerBtnDisabled,
80
+ 'title' => !$canMakeApiCall ? $title : '',
81
+ )
82
+ )
83
+ );
84
+ $this->setChild(
85
+ 'emag_deactivate_offer_btn',
86
+ $this->getLayout()->createBlock('adminhtml/widget_button')
87
+ ->setData(
88
+ array(
89
+ 'label' => $helper->__('Deactivate eMAG offer'),
90
+ 'onclick' => 'inno.emagMarketplace.send(\''
91
+ . $tabsContainerId
92
+ . '\',\''
93
+ . Mage::helper('adminhtml')->escapeUrl(
94
+ Mage::helper('adminhtml')->getUrl(
95
+ 'adminhtml/emag_product/deactivateOffer',
96
+ array('_current' => 1)
97
+ )
98
+ )
99
+ . '\', \'deactivate-offer\')',
100
+ 'class' => 'go',
101
+ 'disabled' => $offerBtnDisabled,
102
+ 'title' => !$canMakeApiCall ? $title : '',
103
+ )
104
+ )
105
+ );
106
+
107
+ return parent::_prepareLayout();
108
+ }
109
+ }
app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Catalog/Product/Edit/Tab/EmagMarketplace.php ADDED
@@ -0,0 +1,758 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG tab on product page.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Block_Adminhtml_Catalog_Product_Edit_Tab_EmagMarketplace
11
+ extends Mage_Adminhtml_Block_Widget_Form
12
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
13
+ {
14
+ /**
15
+ * Current store scope.
16
+ *
17
+ * @var int
18
+ */
19
+ protected $_storeId;
20
+
21
+ /**
22
+ * eMAG category.
23
+ *
24
+ * @var Innobyte_EmagMarketplace_Model_Category
25
+ */
26
+ protected $_category;
27
+
28
+ /**
29
+ * eMAG Family Type.
30
+ *
31
+ * @var Innobyte_EmagMarketplace_Model_Category_Familytype
32
+ */
33
+ protected $_familyType;
34
+
35
+
36
+
37
+ /**
38
+ * @Override
39
+ */
40
+ protected function _construct()
41
+ {
42
+ parent::_construct();
43
+ $this->_storeId = Mage::helper('innobyte_emag_marketplace')
44
+ ->getCurrStoreId();
45
+ }
46
+
47
+
48
+
49
+ /**
50
+ * @Override
51
+ */
52
+ public function getTabLabel()
53
+ {
54
+ return $this->__('eMAG Marketplace');
55
+ }
56
+
57
+
58
+
59
+ /**
60
+ * @Override
61
+ */
62
+ public function getTabTitle()
63
+ {
64
+ return $this->__(
65
+ 'Click here to set eMAG Marketplace info for this product'
66
+ );
67
+ }
68
+
69
+
70
+
71
+ /**
72
+ * @Override
73
+ */
74
+ public function canShowTab()
75
+ {
76
+ return $this->helper('innobyte_emag_marketplace')
77
+ ->isProductActionValid(Mage::registry('current_product'));
78
+ }
79
+
80
+
81
+
82
+ /**
83
+ * @Override
84
+ */
85
+ public function isHidden()
86
+ {
87
+ return !$this->canShowTab();
88
+ }
89
+
90
+
91
+
92
+ /**
93
+ * Retrieve the class name of the tab
94
+ * Return 'ajax' here if you want the tab to be loaded via Ajax
95
+ *
96
+ * return string
97
+ */
98
+ public function getTabClass()
99
+ {
100
+ return 'ajax';
101
+ }
102
+
103
+
104
+
105
+ /**
106
+ * Determine whether to generate content on load or via AJAX
107
+ * If true, the tab's content won't be loaded until the tab is clicked
108
+ * You will need to setup a controller to handle the tab request
109
+ *
110
+ * @return bool
111
+ */
112
+ public function getSkipGenerateContent()
113
+ {
114
+ return true;
115
+ }
116
+
117
+
118
+
119
+ /**
120
+ * Retrieve the URL used to load the tab content
121
+ * Return the URL here used to load the content by Ajax
122
+ * see self::getSkipGenerateContent & self::getTabClass
123
+ *
124
+ * @return string
125
+ */
126
+ public function getTabUrl()
127
+ {
128
+ $storeId = $this->helper('innobyte_emag_marketplace')->getCurrStoreId();
129
+ return $this->helper('adminhtml')->getUrl(
130
+ 'adminhtml/emag_product/index',
131
+ array(
132
+ 'store' => $storeId,
133
+ 'id' => $this->getRequest()->getParam('id'),
134
+ )
135
+ );
136
+ }
137
+
138
+
139
+
140
+ /**
141
+ * @Override
142
+ */
143
+ public function _prepareForm()
144
+ {
145
+ $form = new Varien_Data_Form();
146
+ $form->setFieldNameSuffix('product[inno_emag_mktp]');
147
+ $form->setHtmlIdPrefix('innoemag_');
148
+
149
+ $this->_prepareGeneralInfoFieldset($form)
150
+ ->_prepareCategoryFieldset($form)
151
+ ->_prepareOfferFieldset($form);
152
+
153
+ // set commision value based on direct call to getCommissionValue()
154
+ $this->getEmagProduct()->setData(
155
+ 'commission_value',
156
+ $this->getEmagProduct()->getCommissionValue()
157
+ );
158
+ $form->setValues($this->getEmagProduct()->getData());
159
+
160
+ // set default values for name & brand & desc if new emag product
161
+ if (!$this->getEmagProduct()->getId()
162
+ && !$this->getEmagProduct()->getName()
163
+ && $this->getMageProduct()->getName()
164
+ && ($nameElem = $form->getElement('name'))) {
165
+ $nameElem->setValue($this->getMageProduct()->getName());
166
+ }
167
+ if (!$this->getEmagProduct()->getId()
168
+ && !$this->getEmagProduct()->getBrand()
169
+ && $this->getMageProduct()->getResource()->getAttribute('manufacturer')
170
+ && ($brandElem = $form->getElement('brand'))) {
171
+ $brandElem->setValue($this->getMageProduct()->getAttributeText('manufacturer'));
172
+ }
173
+ if (!$this->getEmagProduct()->getId()
174
+ && !$this->getEmagProduct()->getDescription()
175
+ && $this->getMageProduct()->getDescription()
176
+ && ($descElem = $form->getElement('description'))) {
177
+ $descElem->setValue($this->getMageProduct()->getDescription());
178
+ }
179
+
180
+ $this->setForm($form);
181
+
182
+ $this->setChild(
183
+ 'form_after',
184
+ $this->getLayout()->createBlock('adminhtml/template')
185
+ ->setTemplate('innobyte/emag_marketplace/catalog/product/edit/tab/emag_marketplace_form_after.phtml')
186
+ );
187
+
188
+ // dispatch event in case customization needs to be made by clients
189
+ Mage::dispatchEvent(
190
+ 'innobyte_emag_marketplace_prepare_emag_product_form',
191
+ array('form_block' => $this)
192
+ );
193
+
194
+ return parent::_prepareForm();
195
+ }
196
+
197
+
198
+
199
+ /**
200
+ * Prepare "General Information" fieldset.
201
+ *
202
+ * @param Varien_Data_Form $form
203
+ * @return Innobyte_EmagMarketplace_Block_Adminhtml_Catalog_Product_Edit_Tab_EmagMarketplace
204
+ */
205
+ protected function _prepareGeneralInfoFieldset(Varien_Data_Form $form)
206
+ {
207
+ $fieldsetGeneral = $form->addFieldset(
208
+ 'inno_emag_data_general',
209
+ array(
210
+ 'legend' => $this->__('General Information'),
211
+ )
212
+ );
213
+ $fieldsetGeneral->addField(
214
+ 'name',
215
+ 'text',
216
+ array(
217
+ 'label' => $this->__('Name') . ':',
218
+ 'title' => $this->__('Name'),
219
+ 'name' => 'name',
220
+ 'required' => !strlen($this->getEmagProduct()->getPartNumberKey()),
221
+ 'maxlength' => 255,
222
+ 'class' => 'validate-length minimum-length-1 maximum-length-255',
223
+ 'note' => $this->__(
224
+ 'Should be consistent with eMAG Product Documentation Standard.'
225
+ ),
226
+ )
227
+ );
228
+ $fieldsetGeneral->addField(
229
+ 'brand',
230
+ 'text',
231
+ array(
232
+ 'label' => $this->__('Brand') . ':',
233
+ 'title' => $this->__('Brand'),
234
+ 'name' => 'brand',
235
+ 'required' => !strlen($this->getEmagProduct()->getPartNumberKey()),
236
+ 'maxlength' => 255,
237
+ 'class' => 'validate-length minimum-length-1 maximum-length-255',
238
+ 'note' => $this->__(
239
+ 'Should be consistent with eMAG Product Documentation Standard.'
240
+ ),
241
+ )
242
+ );
243
+ $fieldsetGeneral->addField(
244
+ 'description',
245
+ 'textarea',
246
+ array(
247
+ 'label' => $this->__('Description') . ':',
248
+ 'title' => $this->__('Description'),
249
+ 'name' => 'description',
250
+ 'required' => false,
251
+ 'style' => 'width: 500px; height: 150px;',
252
+ 'note' => $this->__(
253
+ 'Should be consistent with eMAG Product Documentation Standard. Can contain basic HTML tags.'
254
+ ),
255
+ 'after_element_html' => $this->_getWysiwygEditorButton(
256
+ 'innoemag_description'
257
+ ),
258
+ )
259
+ );
260
+ $fieldsetGeneral->addType(
261
+ 'barcodes',
262
+ Mage::getConfig()->getBlockClassName(
263
+ 'innobyte_emag_marketplace/adminhtml_form_element_barcodes'
264
+ )
265
+ );
266
+ $fieldsetGeneral->addField(
267
+ 'barcodes',
268
+ 'barcodes',
269
+ array(
270
+ 'label' => $this->__('Barcode(s)') . ':',
271
+ 'title' => $this->__('Barcode(s)'),
272
+ 'name' => 'barcodes',
273
+ 'required' => false,
274
+ 'maxlength' => 20,
275
+ 'class' => 'validate-length minimum-length-1 maximum-length-20 f-left',
276
+ 'note' => $this->__(
277
+ 'Product barcode identifier (EAN, UPC, ISBN, GTIN). Please use the supplier barcode, not your internal barcodes.'
278
+ ),
279
+ )
280
+ );
281
+ return $this;
282
+ }
283
+
284
+
285
+
286
+ /**
287
+ * Prepare "Category" fieldset.
288
+ *
289
+ * @param Varien_Data_Form $form
290
+ * @return Innobyte_EmagMarketplace_Block_Adminhtml_Catalog_Product_Edit_Tab_EmagMarketplace
291
+ */
292
+ protected function _prepareCategoryFieldset(Varien_Data_Form $form)
293
+ {
294
+ $fieldset = $form->addFieldset(
295
+ 'inno_emag_data_category',
296
+ array(
297
+ 'legend' => $this->__('Category'),
298
+ )
299
+ );
300
+
301
+ $optCategory = Mage::getSingleton('innobyte_emag_marketplace/source_category')
302
+ ->toOptionArray($this->_storeId, true, $this->areFamilyTypesRequired());
303
+ $fieldset->addField(
304
+ 'category_id',
305
+ 'select',
306
+ array(
307
+ 'label' => $this->__('Category') . ':',
308
+ 'title' => $this->__('Category'),
309
+ 'name' => 'category_id',
310
+ 'required' => !strlen($this->getEmagProduct()->getPartNumberKey()),
311
+ 'values' => $optCategory,
312
+ 'onchange' => 'inno.emagMarketplace.changeCategory(\''
313
+ . $this->getUrl(
314
+ 'adminhtml/emag_product/getCategoryData',
315
+ array('store' => $this->_storeId)
316
+ )
317
+ . '\', '
318
+ . ($this->areFamilyTypesRequired() ? 'true' : 'false')
319
+ . ')"'
320
+ )
321
+ );
322
+
323
+ if ($this->getCategory()->getId() > 0
324
+ && $this->areFamilyTypesRequired()
325
+ && is_array($this->getCategory()->getFamilyTypes())) {
326
+ $optFamType = Mage::getSingleton('innobyte_emag_marketplace/source_familyType')
327
+ ->toOptionArray($this->getEmagProduct()->getCategoryId());
328
+ $fieldset->addField(
329
+ 'family_type_id',
330
+ 'select',
331
+ array(
332
+ 'label' => $this->__('Family Type') . ':',
333
+ 'title' => $this->__('Family Type'),
334
+ 'name' => 'family_type_id',
335
+ 'required' => true,
336
+ 'values' => $optFamType,
337
+ 'onchange' => 'inno.emagMarketplace.changeFamilyType()',
338
+ 'after_element_html' => '<script type="text/javascript">
339
+ //<![CDATA[
340
+ inno.emagMarketplace.familyTypesCharacteristics = \''
341
+ . $this->getFamilyTypesCharacteristicsJs()
342
+ . '\'.evalJSON();'
343
+ . '//]]>
344
+ </script>',
345
+ )
346
+ );
347
+ }
348
+
349
+ if ($this->getCategory()->getId() > 0
350
+ && is_array($this->getCategory()->getCharacteristics())) {
351
+ $ftCharacteristics = $this->getFamilyTypeCharacteristics();
352
+ foreach ($this->getCategory()->getCharacteristics() as $characteristic) {
353
+ $isCurrFamilyTypeChar = in_array(
354
+ $characteristic->getId(),
355
+ $ftCharacteristics
356
+ );
357
+ $fieldset->addField(
358
+ 'category_characteristic' . $characteristic->getId(),
359
+ 'text',
360
+ array(
361
+ 'label' => $this->__($characteristic->getName()),
362
+ 'title' => $this->__($characteristic->getName()),
363
+ 'name' => 'category_characteristic' . $characteristic->getId(),
364
+ 'required' => true,
365
+ 'maxlength' => 255,
366
+ 'class' => 'validate-length minimum-length-1 maximum-length-255'
367
+ . ($isCurrFamilyTypeChar ? ' disabled' : ''),
368
+ 'disabled' => $isCurrFamilyTypeChar,
369
+ 'note' => $isCurrFamilyTypeChar ? $this->__(
370
+ 'This attribute will have to be set on associated products individually'
371
+ ) : null,
372
+ )
373
+ );
374
+ }
375
+ }
376
+
377
+ return $this;
378
+ }
379
+
380
+
381
+
382
+ /**
383
+ * Prepare "Product Offer" fieldset.
384
+ *
385
+ * @param Varien_Data_Form $form
386
+ * @return Innobyte_EmagMarketplace_Block_Adminhtml_Catalog_Product_Edit_Tab_EmagMarketplace
387
+ */
388
+ protected function _prepareOfferFieldset(Varien_Data_Form $form)
389
+ {
390
+ $fieldset = $form->addFieldset(
391
+ 'inno_emag_data_offer',
392
+ array(
393
+ 'legend' => $this->__('Product Offer'),
394
+ )
395
+ );
396
+
397
+ $fieldset->addField(
398
+ 'part_number_key',
399
+ 'text',
400
+ array(
401
+ 'label' => $this->__('Part Number Key') . ':',
402
+ 'title' => $this->__('Part Number Key'),
403
+ 'name' => 'part_number_key',
404
+ 'required' => false,
405
+ 'onchange' => 'inno.emagMarketplace.changePartNumberKey()',
406
+ 'note' => $this->__(
407
+ 'Used for attaching a product offer to an existing product in eMAG platform.<br />If you want to create new product, don\'t set this key.'
408
+ ) . '<br />' . $this->__(
409
+ 'Ex: for product http://www.emag.ro/telefon-mobil-nokia-105-black-105-black/pd/D5DD9BBBM/ the part_number_key is D5DD9BBBM.'
410
+ ),
411
+ )
412
+ );
413
+
414
+ $optStatus = Mage::getSingleton('innobyte_emag_marketplace/source_offerStatus')
415
+ ->toOptionArray();
416
+ $fieldset->addField(
417
+ 'status',
418
+ 'select',
419
+ array(
420
+ 'label' => $this->__('Offer Status') . ':',
421
+ 'title' => $this->__('Offer Status'),
422
+ 'name' => 'status',
423
+ 'required' => true,
424
+ 'values' => $optStatus,
425
+ )
426
+ );
427
+
428
+ $fieldset->addField(
429
+ 'warranty',
430
+ 'text',
431
+ array(
432
+ 'label' => $this->__('Warranty') . ':',
433
+ 'title' => $this->__('Warranty'),
434
+ 'name' => 'warranty',
435
+ 'required' => false,
436
+ 'class' => 'validate-not-negative-number validate-digits-range digits-range-0-255',
437
+ 'note' => $this->__('The warranty offered in months.'),
438
+ )
439
+ );
440
+
441
+ $optCommType = Mage::getSingleton('innobyte_emag_marketplace/source_commissionTypes')
442
+ ->toOptionArray();
443
+ $fieldset->addField(
444
+ 'commission_type',
445
+ 'select',
446
+ array(
447
+ 'label' => $this->__('Commission Type') . ':',
448
+ 'title' => $this->__('Commission Type'),
449
+ 'name' => 'commission_type',
450
+ 'required' => true,
451
+ 'values' => $optCommType,
452
+ 'onchange' => 'inno.emagMarketplace.changeCommissionType()',
453
+ 'note' => $this->__(
454
+ 'The type of commission for a finalized order containing the offer.'
455
+ ),
456
+ )
457
+ );
458
+
459
+ $percentsClass = '';
460
+ try {
461
+ $commissionType = Innobyte_EmagMarketplace_Model_Source_CommissionTypes::getEmagCommissionType(
462
+ $this->getEmagProduct()->getCommissionType()
463
+ );
464
+ if (Innobyte_EmagMarketplace_Model_Source_CommissionTypes::TYPE_PERCENTAGE == $commissionType) {
465
+ $percentsClass .= ' validate-percents';
466
+ }
467
+ } catch (Innobyte_EmagMarketplace_Exception $iemEx) {
468
+ //no need to log, for example for new emag products it will get here
469
+ }
470
+ $fieldset->addField(
471
+ 'commission_value',
472
+ 'text',
473
+ array(
474
+ 'label' => $this->__('Commission Value') . ':',
475
+ 'title' => $this->__('Commission Value'),
476
+ 'name' => 'commission_value',
477
+ 'required' => true,
478
+ 'class' => 'validate-not-negative-number' . $percentsClass,
479
+ 'note' => $this->__(
480
+ 'If type is percentage the value should be between 0 and 100, otherwise a float with 4 decimals and without VAT.'
481
+ ),
482
+ )
483
+ );
484
+
485
+ $fieldset->addField(
486
+ 'handling_time',
487
+ 'text',
488
+ array(
489
+ 'label' => $this->__('Handling Time') . ':',
490
+ 'title' => $this->__('Handling Time'),
491
+ 'name' => 'handling_time',
492
+ 'required' => false,
493
+ 'class' => 'validate-not-negative-number validate-digits-range digits-range-0-255',
494
+ 'note' => $this->__(
495
+ 'Handling time, in number of days counted from the day the order was received. If handling_time = 0 the order will be shipped the same day it is received.'
496
+ ),
497
+ )
498
+ );
499
+
500
+ $startDateElem = $fieldset->addField(
501
+ 'start_date',
502
+ 'date',
503
+ array(
504
+ 'label' => $this->__('Start Date') . ':',
505
+ 'title' => $this->__('Start Date'),
506
+ 'name' => 'start_date',
507
+ 'required' => false,
508
+ 'image' => $this->getSkinUrl('images/grid-cal.gif'),
509
+ 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT,
510
+ 'format' => Mage::app()->getLocale()->getDateFormat(
511
+ Mage_Core_Model_Locale::FORMAT_TYPE_SHORT
512
+ ),
513
+ 'class' => 'validate-emag-date',
514
+ 'note' => $this->__(
515
+ 'If it\'s a new offer, it represents the date your offer will be available from.<br />For offer updates, it schedules value updates for the following data: sale_price, recommended_price, stock, handling_time, commission, vat_id, warranty, status, availability.<br />All other data will be updated on the fly.<br />Using Start Date, for example, you can schedule the inactivation of an offer, a price update, etc.'
516
+ ),
517
+ )
518
+ );
519
+ $startDateElem->setAfterElementHtml(
520
+ '<script type="text/javascript">
521
+ //<![CDATA[
522
+ Validation.add(
523
+ "validate-emag-date",
524
+ "'
525
+ . $this->__(
526
+ 'Date can be as far as 60 days in the future and cannot be earlier than tomorrow.'
527
+ ) . '",
528
+ function(date){
529
+ if (date === "") {
530
+ return true;
531
+ }
532
+ var dateObj = null;
533
+ // check func defined in js/calendar/calendar.js
534
+ if (typeof (Date.parseDate) === "function") {
535
+ dateObj = Date.parseDate(date, "'
536
+ . Varien_Date::convertZendToStrFtime(
537
+ $startDateElem->getFormat(),
538
+ true,
539
+ (bool) $startDateElem->getTime()
540
+ ) . '");
541
+ }
542
+ if (null === dateObj) {
543
+ return true; // validate server side
544
+ }
545
+ var minDate = new Date(
546
+ new Date().getTime()
547
+ +
548
+ 1 * 24 * 60 * 60 * 1000
549
+ ); // tomorrow
550
+ minDate.setHours(0);
551
+ minDate.setMinutes(0);
552
+ minDate.setSeconds(0);
553
+ minDate.setMilliseconds(0);
554
+ var maxDate = new Date(
555
+ new Date().getTime()
556
+ +
557
+ 60 * 24 * 60 * 60 * 1000
558
+ ); // 60 days from now
559
+ maxDate.setHours(0);
560
+ maxDate.setMinutes(0);
561
+ maxDate.setSeconds(0);
562
+ maxDate.setMilliseconds(0);
563
+ return (dateObj >= minDate && dateObj <= maxDate);
564
+ }
565
+ );
566
+ //]]>
567
+ </script>'
568
+ );
569
+
570
+ $optVat = Mage::getSingleton('innobyte_emag_marketplace/source_vat')
571
+ ->toOptionArray($this->_storeId);
572
+ $fieldset->addField(
573
+ 'vat_id',
574
+ 'select',
575
+ array(
576
+ 'label' => $this->__('VAT') . ':',
577
+ 'title' => $this->__('VAT'),
578
+ 'name' => 'vat_id',
579
+ 'required' => false,
580
+ 'values' => $optVat,
581
+ 'note' => $this->__(
582
+ 'If not set, will be automatically calculated based on product \'s class tax and store shipping origin address.'
583
+ ),
584
+ )
585
+ );
586
+
587
+ return $this;
588
+ }
589
+
590
+
591
+
592
+ /**
593
+ * Retrieve eMAG product.
594
+ *
595
+ * @return Innobyte_EmagMarketplace_Model_Product
596
+ */
597
+ public function getEmagProduct()
598
+ {
599
+ return Mage::registry('current_emag_product');
600
+ }
601
+
602
+
603
+
604
+ /**
605
+ * Retrieve magento product.
606
+ *
607
+ * @return Mage_Catalog_Model_Product
608
+ */
609
+ public function getMageProduct()
610
+ {
611
+ return Mage::registry('current_product');
612
+ }
613
+
614
+
615
+
616
+ /**
617
+ * Retrieve family type object
618
+ *
619
+ * @return Innobyte_EmagMarketplace_Model_Category_Familytype
620
+ */
621
+ public function getFamilyType()
622
+ {
623
+ if (is_null($this->_familyType)) {
624
+ $this->_familyType = Mage::getModel(
625
+ 'innobyte_emag_marketplace/category_familytype'
626
+ )->load($this->getEmagProduct()->getFamilyTypeId());
627
+ }
628
+ return $this->_familyType;
629
+ }
630
+
631
+
632
+
633
+ /**
634
+ * Retrieve category model.
635
+ *
636
+ * @return Innobyte_EmagMarketplace_Model_Category
637
+ */
638
+ public function getCategory()
639
+ {
640
+ if (is_null($this->_category)) {
641
+ $this->_category = Mage::getModel('innobyte_emag_marketplace/category')
642
+ ->load($this->getEmagProduct()->getCategoryId());
643
+ }
644
+ return $this->_category;
645
+ }
646
+
647
+
648
+
649
+ /**
650
+ * Retrieve family type 's characteristics magento ids.
651
+ *
652
+ * @return array
653
+ */
654
+ public function getFamilyTypeCharacteristics()
655
+ {
656
+ $returnValue = array();
657
+ if (is_array($this->getFamilyType()->getCharacteristics())) {
658
+ foreach ($this->getFamilyType()->getCharacteristics() as $ftChar) {
659
+ $returnValue[] = $ftChar->getMageIdEmagChar();
660
+ }
661
+ }
662
+ return $returnValue;
663
+ }
664
+
665
+
666
+
667
+ /**
668
+ * Check if family types are required.
669
+ *
670
+ * @return boolean
671
+ */
672
+ public function areFamilyTypesRequired()
673
+ {
674
+ return $this->getMageProduct() instanceof Mage_Catalog_Model_Product
675
+ && $this->getMageProduct()->isConfigurable();
676
+ }
677
+
678
+
679
+
680
+ /**
681
+ * Retrieve characteristics of families js.
682
+ *
683
+ * @return string
684
+ */
685
+ public function getFamilyTypesCharacteristicsJs()
686
+ {
687
+ $returnValue = array();
688
+ if ($this->getCategory()->getId()
689
+ && is_array($this->getCategory()->getFamilyTypes())) {
690
+ foreach ($this->getCategory()->getFamilyTypes() as $ft) {
691
+ $chars = array();
692
+ foreach ($ft->getCharacteristics() as $char) {
693
+ $chars[] = $char->getMageIdEmagChar();
694
+ }
695
+ $returnValue[$ft->getId()] = $chars;
696
+ }
697
+ }
698
+ return Zend_Json::encode($returnValue);
699
+ }
700
+
701
+
702
+
703
+
704
+ /**
705
+ * @Override Load tiny mce js
706
+ */
707
+ protected function _prepareLayout() {
708
+ if ($this->_isWysiwygEnabled()
709
+ && $this->getLayout()->getBlock('head')) {
710
+ $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
711
+ }
712
+ return parent::_prepareLayout();
713
+ }
714
+
715
+
716
+
717
+ /**
718
+ * Retrieve wysiwyg button.
719
+ *
720
+ * @return string
721
+ */
722
+ protected function _getWysiwygEditorButton($fieldId)
723
+ {
724
+ if (!$this->_isWysiwygEnabled()) {
725
+ return '';
726
+ }
727
+ return Mage::getSingleton('core/layout')
728
+ ->createBlock(
729
+ 'adminhtml/widget_button',
730
+ '',
731
+ array(
732
+ 'label' => Mage::helper('catalog')->__('WYSIWYG Editor'),
733
+ 'type' => 'button',
734
+ 'class' => 'btn-wysiwyg',
735
+ 'onclick' => 'catalogWysiwygEditor.open(\''
736
+ . Mage::helper('adminhtml')->getUrl(
737
+ 'adminhtml/catalog_product/wysiwyg'
738
+ ) . '\', \''. $fieldId .'\')',
739
+ )
740
+ )
741
+ ->toHtml();
742
+ }
743
+
744
+
745
+
746
+ /**
747
+ * Check whether wysiwyg enabled or not
748
+ *
749
+ * @return boolean
750
+ */
751
+ protected function _isWysiwygEnabled()
752
+ {
753
+ if ($this->helper('core')->isModuleEnabled('Mage_Cms')) {
754
+ return (bool) Mage::getSingleton('cms/wysiwyg_config')->isEnabled();
755
+ }
756
+ return false;
757
+ }
758
+ }
app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Category.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG categories grid container.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Block_Adminhtml_Category
11
+ extends Mage_Adminhtml_Block_Widget_Grid_Container
12
+ {
13
+ /**
14
+ * @Override
15
+ */
16
+ public function __construct()
17
+ {
18
+ $this->_objectId = 'id';
19
+ $this->_blockGroup = 'innobyte_emag_marketplace';
20
+ $this->_controller = 'adminhtml_category';
21
+ $this->_headerText = $this->__('eMAG Categories');
22
+
23
+ parent::__construct();
24
+
25
+ $helper = Mage::helper('innobyte_emag_marketplace');
26
+ $storeId = $helper->getCurrStoreId();
27
+ $canMakeApiCall = $helper->canMakeApiCall($storeId);
28
+ if ($helper->isExtensionEnabled($storeId)
29
+ && $storeId != Mage_Core_Model_App::ADMIN_STORE_ID) {
30
+ $this->_updateButton(
31
+ 'add',
32
+ null,
33
+ array(
34
+ 'label' => $this->__('Synchronize categories'),
35
+ 'onclick' => 'inno.emagMarketplace.syncCategories(\''
36
+ . $this->escapeUrl(
37
+ $this->getUrl(
38
+ '*/*/syncCategories',
39
+ array('_current' => 1)
40
+ )
41
+ )
42
+ . '\')',
43
+ 'sort_order' => 100,
44
+ 'disabled' => !$canMakeApiCall,
45
+ 'title' => !$canMakeApiCall ? $helper->__(
46
+ 'Please configure extension from System -> Configuration -> eMAG Marketplace'
47
+ ) : '',
48
+ )
49
+ );
50
+ } else {
51
+ $this->_removeButton('add');
52
+ }
53
+ }
54
+ }
app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Category/Grid.php ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG categories grid.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Block_Adminhtml_Category_Grid
11
+ extends Mage_Adminhtml_Block_Widget_Grid
12
+ {
13
+ /**
14
+ * Constructor.
15
+ *
16
+ * @Override
17
+ */
18
+ public function __construct()
19
+ {
20
+ parent::__construct();
21
+ $this->setId('innoEmagCategoriesGrid');
22
+ $this->setDefaultSort('main_table.emag_id');
23
+ $this->setDefaultDir('DESC');
24
+ $this->setUseAjax(true);
25
+ $this->setSaveParametersInSession(true);
26
+ }
27
+
28
+
29
+
30
+ /**
31
+ * Setup the collection to show in the grid.
32
+ *
33
+ * @Override
34
+ * @return Innobyte_EmagMarketplace_Block_Adminhtml_Category_Grid
35
+ */
36
+ protected function _prepareCollection()
37
+ {
38
+ $collection = Mage::getResourceModel(
39
+ 'innobyte_emag_marketplace/category_collection'
40
+ )->addStoreFilter(
41
+ Mage::helper('innobyte_emag_marketplace')->getCurrStoreId()
42
+ );
43
+
44
+ $charTable = $collection->getTable(
45
+ 'innobyte_emag_marketplace/category_characteristic'
46
+ );
47
+ $famTypesTable = $collection->getTable(
48
+ 'innobyte_emag_marketplace/category_familytype'
49
+ );
50
+ $collection->getSelect()->joinLeft(
51
+ array('characteristics' => $charTable),
52
+ 'characteristics.category_id = main_table.id',
53
+ new Zend_Db_Expr(
54
+ 'GROUP_CONCAT('
55
+ . 'DISTINCT characteristics.name '
56
+ . 'ORDER BY characteristics.display_order ASC '
57
+ . "SEPARATOR ', '"
58
+ . ') AS characteristics'
59
+ )
60
+ )->joinLeft(
61
+ array('familytypes' => $famTypesTable),
62
+ 'familytypes.category_id = main_table.id',
63
+ new Zend_Db_Expr(
64
+ 'GROUP_CONCAT('
65
+ . 'DISTINCT familytypes.name '
66
+ . "SEPARATOR ', '"
67
+ . ') AS family_types'
68
+ )
69
+ )->group('main_table.id');
70
+
71
+ $this->setCollection($collection);
72
+ return parent::_prepareCollection();
73
+ }
74
+
75
+
76
+
77
+ /**
78
+ * Setup the shown columns.
79
+ *
80
+ * @Override
81
+ * @return Innobyte_EmagMarketplace_Block_Adminhtml_Category_Grid
82
+ */
83
+ protected function _prepareColumns()
84
+ {
85
+ $this->addColumn(
86
+ 'emag_id',
87
+ array(
88
+ 'header' => $this->__('eMAG ID'),
89
+ 'align' => 'left',
90
+ 'type' => 'number',
91
+ 'index' => 'emag_id',
92
+ 'filter_index' => 'main_table.emag_id',
93
+ 'width' => '50px',
94
+ )
95
+ );
96
+ $this->addColumn(
97
+ 'name',
98
+ array(
99
+ 'header' => $this->__('Name'),
100
+ 'align' => 'left',
101
+ 'type' => 'text',
102
+ 'index' => 'name',
103
+ 'filter_index' => 'main_table.name',
104
+ )
105
+ );
106
+ $this->addColumn(
107
+ 'characteristics',
108
+ array(
109
+ 'header' => $this->__('Characteristics'),
110
+ 'align' => 'left',
111
+ 'type' => 'text',
112
+ 'index' => 'characteristics',
113
+ 'sortable' => false,
114
+ 'filter_condition_callback' => array(
115
+ $this,
116
+ '_filterCharacteristics'
117
+ ),
118
+ )
119
+ );
120
+ $this->addColumn(
121
+ 'family_types',
122
+ array(
123
+ 'header' => $this->__('Family Types'),
124
+ 'align' => 'left',
125
+ 'type' => 'text',
126
+ 'index' => 'family_types',
127
+ 'sortable' => false,
128
+ 'filter_condition_callback' => array(
129
+ $this,
130
+ '_filterFamilytypes'
131
+ ),
132
+ )
133
+ );
134
+ if (!Mage::app()->isSingleStoreMode()) {
135
+ $this->addColumn(
136
+ 'store_id',
137
+ array(
138
+ 'header' => Mage::helper('sales')->__('Store'),
139
+ 'index' => 'store_id',
140
+ 'filter_index' => 'main_table.store_id',
141
+ 'type' => 'store',
142
+ 'store_view' => true,
143
+ )
144
+ );
145
+ }
146
+ $this->addColumn(
147
+ 'updated_at',
148
+ array(
149
+ 'header' => $this->__('Updated at'),
150
+ 'align' => 'center',
151
+ 'type' => 'datetime',
152
+ 'index' => 'updated_at',
153
+ 'filter_index' => 'main_table.updated_at',
154
+ 'width' => '100px',
155
+ )
156
+ );
157
+ $this->addColumn(
158
+ 'created_at',
159
+ array(
160
+ 'header' => $this->__('Created at'),
161
+ 'align' => 'center',
162
+ 'type' => 'datetime',
163
+ 'index' => 'created_at',
164
+ 'filter_index' => 'main_table.created_at',
165
+ 'width' => '100px',
166
+ )
167
+ );
168
+
169
+ return parent::_prepareColumns();
170
+ }
171
+
172
+
173
+
174
+ /**
175
+ * Disable edit mode.
176
+ *
177
+ * @Override
178
+ * @param object $row
179
+ * @return boolean
180
+ */
181
+ public function getRowUrl($row)
182
+ {
183
+ return false;
184
+ }
185
+
186
+
187
+
188
+ /**
189
+ * Get grid 's url.
190
+ *
191
+ * @Override
192
+ * @return string
193
+ */
194
+ public function getGridUrl()
195
+ {
196
+ return Mage::helper('adminhtml')->getUrl(
197
+ '*/*/index',
198
+ array('_current' => 1)
199
+ );
200
+ }
201
+
202
+
203
+
204
+ /**
205
+ * Custom filter for characteristics.
206
+ *
207
+ * @param Mage_Core_Model_Resource_Db_Collection_Abstract $collection
208
+ * @param type $column
209
+ * @return Innobyte_EmagMarketplace_Block_Adminhtml_Category_Grid
210
+ */
211
+ protected function _filterCharacteristics($collection, $column)
212
+ {
213
+ if (!$value = $column->getFilter()->getValue()) {
214
+ return $this;
215
+ }
216
+ $this->getCollection()->getSelect()
217
+ ->where('characteristics.name LIKE ?', "%$value%");
218
+ return $this;
219
+ }
220
+
221
+
222
+
223
+ /**
224
+ * Custom filter for characteristics.
225
+ *
226
+ * @param Mage_Core_Model_Resource_Db_Collection_Abstract $collection
227
+ * @param type $column
228
+ * @return Innobyte_EmagMarketplace_Block_Adminhtml_Category_Grid
229
+ */
230
+ protected function _filterFamilytypes($collection, $column)
231
+ {
232
+ if (!$value = $column->getFilter()->getValue()) {
233
+ return $this;
234
+ }
235
+ $this->getCollection()->getSelect()
236
+ ->where('familytypes.name LIKE ?', "%$value%");
237
+ return $this;
238
+ }
239
+ }
app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Form/Element/Barcodes.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG custom form element renderer for barcodes.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Block_Adminhtml_Form_Element_Barcodes
11
+ extends Varien_Data_Form_Element_Text
12
+ {
13
+ /**
14
+ * @Override
15
+ * @return string
16
+ */
17
+ public function getElementHtml()
18
+ {
19
+ $returnValue = '';
20
+ $helper = Mage::helper('innobyte_emag_marketplace');
21
+ if (is_array($this->getValue()) && count($this->getValue())) {
22
+ $i = 0;
23
+ foreach ($this->getValue() as $key => $value) {
24
+ $returnValue .= '<input id="' . $this->getHtmlId()
25
+ .'" name="' . $this->getName() . '[]'
26
+ .'" value="' . $this->getEscapedValue($key) . '" '
27
+ . $this->serialize($this->getHtmlAttributes()) . '/>'
28
+ . "\n";
29
+ if (!$i) {
30
+ $returnValue .= '<span class="innoemag-addremove-item" '
31
+ . 'title="' . $helper->__('Add New')
32
+ . '" onclick="inno.emagMarketplace.addNewBarcode()">'
33
+ . ' + '
34
+ . '</span>';
35
+ $i = 1;
36
+ } else {
37
+ $returnValue .= '<span class="innoemag-addremove-item" '
38
+ . 'title="' . $helper->__('Remove')
39
+ . '" onclick="inno.emagMarketplace.removeBarcode(this)">'
40
+ . ' - '
41
+ . '</span>';
42
+ }
43
+ $returnValue .= '<br style="clear: both;"/>' . "\n";
44
+ }
45
+ } else {
46
+ $returnValue .= '<span class="innoemag-addremove-item" '
47
+ . 'title="' . $helper->__('Add New')
48
+ . '" onclick="inno.emagMarketplace.addNewBarcode()">'
49
+ . ' + '
50
+ . '</span>'
51
+ . '<input id="' . $this->getHtmlId()
52
+ . '" name="' . $this->getName() . '[]'
53
+ . '" value="" '
54
+ . $this->serialize($this->getHtmlAttributes()) . '/>'
55
+ . "<br style='clear: both; '/>\n";
56
+ }
57
+
58
+ $returnValue .= $this->getAfterElementHtml();
59
+
60
+ return $returnValue;
61
+ }
62
+ }
app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Form/Element/File.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Block_Adminhtml_Form_Element_File
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Block_Adminhtml_Form_Element_File
12
+ extends Mage_Adminhtml_Block_Customer_Form_Element_File
13
+ {
14
+
15
+ /**
16
+ * Return File preview link HTML
17
+ *
18
+ * @return string
19
+ */
20
+ protected function _getPreviewHtml()
21
+ {
22
+ $values = $this->getValue();
23
+
24
+ $html = '';
25
+ foreach ($values as $invoiceId => $value) {
26
+ if ($value && !is_array($value)) {
27
+ $image = array(
28
+ 'alt' => $value,
29
+ 'title' => $value,
30
+ 'src' => Mage::getDesign()->getSkinUrl('images/innobyte/emag_marketplace/pdf_icon.png'),
31
+ 'class' => 'v-middle'
32
+ );
33
+ $url = Mage::helper('adminhtml')->getUrl('adminhtml/sales_invoice_upload/download', array(
34
+ 'file' => Mage::helper('core')->urlEncode($value)
35
+ ));
36
+ $html .= '<div>';
37
+ $html .= '<a href="' . $url . '">' . $this->_drawElementHtml('img', $image) . '</a> ';
38
+ $html .= '<a href="' . $url . '">' . $value . '</a>';
39
+ $html .= $this->_getDeleteHtml($invoiceId);
40
+ $html .= '</div>';
41
+ }
42
+ }
43
+
44
+ return $html;
45
+ }
46
+
47
+ /**
48
+ * Get delete url
49
+ *
50
+ * @param $invoiceId
51
+ * @return mixed
52
+ */
53
+ protected function _getDeleteHtml($invoiceId)
54
+ {
55
+ $image = array(
56
+ 'alt' => Mage::helper('innobyte_emag_marketplace')->__('Delete'),
57
+ 'title' => Mage::helper('innobyte_emag_marketplace')->__('Delete'),
58
+ 'src' => Mage::getDesign()->getSkinUrl('images/innobyte/emag_marketplace/trash.png'),
59
+ 'class' => 'v-middle'
60
+ );
61
+ $url = Mage::helper('adminhtml')->getUrl('adminhtml/sales_invoice_upload/delete', array(
62
+ '_current' => true,
63
+ 'invoice_id' => $invoiceId
64
+ ));
65
+
66
+ $html = '<a href="' . $url . '">' . $this->_drawElementHtml('img', $image) . '</a>';
67
+
68
+ return $html;
69
+ }
70
+
71
+ }
app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Form/Field/LocalityId.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Custom system config field renderer.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Block_Adminhtml_Form_Field_LocalityId
11
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
12
+ {
13
+ /**
14
+ * Return element html.
15
+ *
16
+ * @Override
17
+ * @param Varien_Data_Form_Element_Abstract $elem
18
+ * @return string
19
+ */
20
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $elem)
21
+ {
22
+ return $elem->getElementHtml() . $this->getAutocompleteJs();
23
+ }
24
+
25
+
26
+
27
+ /**
28
+ * Return localities url.
29
+ *
30
+ * @return string
31
+ */
32
+ public function getLocalitiesUrl()
33
+ {
34
+ return Mage::helper('adminhtml')->getUrl(
35
+ 'adminhtml/emag_locality/getCities',
36
+ array('_secure' => 1)
37
+ );
38
+ }
39
+
40
+
41
+
42
+ /**
43
+ * Retrieve javascript code for button.
44
+ *
45
+ * @return string
46
+ */
47
+ public function getAutocompleteJs()
48
+ {
49
+ return '<script type="text/javascript" src="'
50
+ . $this->escapeUrl(
51
+ $this->getSkinUrl('js/innobyte/emag_marketplace/locality.js')
52
+ )
53
+ . '"></script>'
54
+ . '<script type="text/javascript">
55
+ //<![CDATA[
56
+
57
+ // load css
58
+ var innoEmagMktpCss = document.createElement("link")
59
+ innoEmagMktpCss.setAttribute("rel", "stylesheet")
60
+ innoEmagMktpCss.setAttribute("type", "text/css")
61
+ innoEmagMktpCss.setAttribute("href", "'
62
+ . $this->escapeUrl(
63
+ $this->getSkinUrl('css/innobyte/emag_marketplace/style.css')
64
+ )
65
+ . '")
66
+ document.getElementsByTagName("head")[0]
67
+ .appendChild(innoEmagMktpCss);
68
+
69
+ // attach autocomplete for city
70
+ inno.emagMarketplace.attachAutocompleteEmagCity('
71
+ . '\'' . $this->escapeUrl($this->getLocalitiesUrl()) . '\','
72
+ . '\'shipping_origin\','
73
+ .'\'' . $this->escapeUrl(
74
+ $this->getSkinUrl('images/ajax-loader.gif')
75
+ ) . '\''
76
+ .');
77
+
78
+ //]]>
79
+ </script>';
80
+ }
81
+
82
+
83
+
84
+ /**
85
+ * Decorate field row html
86
+ *
87
+ * @Override Added style display none.
88
+ * @param Varien_Data_Form_Element_Abstract $element
89
+ * @param string $html
90
+ * @return string
91
+ */
92
+ protected function _decorateRowHtml($element, $html)
93
+ {
94
+ return '<tr id="row_' . $element->getHtmlId()
95
+ . '" style="display: none;">' . $html . '</tr>';
96
+ }
97
+ }
app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Locality.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG localities grid container.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Block_Adminhtml_Locality
11
+ extends Mage_Adminhtml_Block_Widget_Grid_Container
12
+ {
13
+ /**
14
+ * @Override
15
+ */
16
+ public function __construct()
17
+ {
18
+ $this->_objectId = 'id';
19
+ $this->_blockGroup = 'innobyte_emag_marketplace';
20
+ $this->_controller = 'adminhtml_locality';
21
+ $this->_headerText = $this->__('eMAG Localities');
22
+
23
+ parent::__construct();
24
+
25
+ $helper = Mage::helper('innobyte_emag_marketplace');
26
+ $storeId = $helper->getCurrStoreId();
27
+ $canMakeApiCall = $helper->canMakeApiCall($storeId);
28
+ if ($helper->isExtensionEnabled($storeId)
29
+ && $storeId != Mage_Core_Model_App::ADMIN_STORE_ID) {
30
+ $this->_updateButton(
31
+ 'add',
32
+ null,
33
+ array(
34
+ 'label' => $this->__('Synchronize localities'),
35
+ 'onclick' => 'inno.emagMarketplace.syncLocalities(\''
36
+ . $this->escapeUrl(
37
+ $this->getUrl(
38
+ '*/*/syncLocalities',
39
+ array('_current' => 1)
40
+ )
41
+ )
42
+ . '\')',
43
+ 'sort_order' => 100,
44
+ 'disabled' => !$canMakeApiCall,
45
+ 'title' => !$canMakeApiCall ? $helper->__(
46
+ 'Please configure extension from System -> Configuration -> eMAG Marketplace'
47
+ ) : '',
48
+ )
49
+ );
50
+ } else {
51
+ $this->_removeButton('add');
52
+ }
53
+ }
54
+ }
app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Locality/Grid.php ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG localities grid.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Block_Adminhtml_Locality_Grid
11
+ extends Mage_Adminhtml_Block_Widget_Grid
12
+ {
13
+ /**
14
+ * Constructor.
15
+ *
16
+ * @Override
17
+ */
18
+ public function __construct()
19
+ {
20
+ parent::__construct();
21
+ $this->setId('innoEmagLocalitiesGrid');
22
+ $this->setDefaultSort('main_table.emag_id');
23
+ $this->setDefaultDir('DESC');
24
+ $this->setUseAjax(true);
25
+ $this->setSaveParametersInSession(true);
26
+ }
27
+
28
+
29
+
30
+ /**
31
+ * Setup the collection to show in the grid.
32
+ *
33
+ * @Override
34
+ * @return Innobyte_EmagMarketplace_Block_Adminhtml_Locality_Grid
35
+ */
36
+ protected function _prepareCollection()
37
+ {
38
+ $collection = Mage::getResourceModel(
39
+ 'innobyte_emag_marketplace/locality_collection'
40
+ )->addStoreFilter(
41
+ Mage::helper('innobyte_emag_marketplace')->getCurrStoreId()
42
+ );
43
+ $this->setCollection($collection);
44
+ return parent::_prepareCollection();
45
+ }
46
+
47
+
48
+
49
+ /**
50
+ * Setup the shown columns.
51
+ *
52
+ * @Override
53
+ * @return Innobyte_EmagMarketplace_Block_Adminhtml_Locality_Grid
54
+ */
55
+ protected function _prepareColumns()
56
+ {
57
+ $this->addColumn(
58
+ 'emag_id',
59
+ array(
60
+ 'header' => $this->__('eMAG ID'),
61
+ 'align' => 'left',
62
+ 'type' => 'number',
63
+ 'index' => 'emag_id',
64
+ 'width' => '50px',
65
+ )
66
+ );
67
+ $this->addColumn(
68
+ 'name',
69
+ array(
70
+ 'header' => $this->__('Name'),
71
+ 'align' => 'left',
72
+ 'type' => 'text',
73
+ 'index' => 'name',
74
+ )
75
+ );
76
+ $this->addColumn(
77
+ 'name_latin',
78
+ array(
79
+ 'header' => $this->__('Name Latin'),
80
+ 'align' => 'left',
81
+ 'type' => 'text',
82
+ 'index' => 'name',
83
+ )
84
+ );
85
+ $this->addColumn(
86
+ 'region1',
87
+ array(
88
+ 'header' => $this->__('Region 1'),
89
+ 'align' => 'left',
90
+ 'type' => 'text',
91
+ 'index' => 'region1',
92
+ )
93
+ );
94
+ $this->addColumn(
95
+ 'region2',
96
+ array(
97
+ 'header' => $this->__('Region 2'),
98
+ 'align' => 'left',
99
+ 'type' => 'text',
100
+ 'index' => 'region2',
101
+ )
102
+ );
103
+ $this->addColumn(
104
+ 'region3',
105
+ array(
106
+ 'header' => $this->__('Region 3'),
107
+ 'align' => 'left',
108
+ 'type' => 'text',
109
+ 'index' => 'region3',
110
+ )
111
+ );
112
+ $this->addColumn(
113
+ 'region4',
114
+ array(
115
+ 'header' => $this->__('Region 4'),
116
+ 'align' => 'left',
117
+ 'type' => 'text',
118
+ 'index' => 'region4',
119
+ )
120
+ );
121
+ $this->addColumn(
122
+ 'region1_latin',
123
+ array(
124
+ 'header' => $this->__('Region 1 Latin'),
125
+ 'align' => 'left',
126
+ 'type' => 'text',
127
+ 'index' => 'region1_latin',
128
+ )
129
+ );
130
+ $this->addColumn(
131
+ 'region2_latin',
132
+ array(
133
+ 'header' => $this->__('Region 2 Latin'),
134
+ 'align' => 'left',
135
+ 'type' => 'text',
136
+ 'index' => 'region2_latin',
137
+ )
138
+ );
139
+ $this->addColumn(
140
+ 'region3_latin',
141
+ array(
142
+ 'header' => $this->__('Region 3 Latin'),
143
+ 'align' => 'left',
144
+ 'type' => 'text',
145
+ 'index' => 'region3_latin',
146
+ )
147
+ );
148
+ $this->addColumn(
149
+ 'region4_latin',
150
+ array(
151
+ 'header' => $this->__('Region 4 Latin'),
152
+ 'align' => 'left',
153
+ 'type' => 'text',
154
+ 'index' => 'region4_latin',
155
+ )
156
+ );
157
+ $this->addColumn(
158
+ 'geoid',
159
+ array(
160
+ 'header' => $this->__('Geoid'),
161
+ 'type' => 'text',
162
+ 'index' => 'geoid',
163
+ )
164
+ );
165
+ $this->addColumn(
166
+ 'emag_modified',
167
+ array(
168
+ 'header' => $this->__('eMAG last modified'),
169
+ 'align' => 'center',
170
+ 'type' => 'datetime',
171
+ 'index' => 'emag_modified',
172
+ 'width' => '150px',
173
+ )
174
+ );
175
+ if (!Mage::app()->isSingleStoreMode()) {
176
+ $this->addColumn(
177
+ 'store_id',
178
+ array(
179
+ 'header' => Mage::helper('sales')->__('Store'),
180
+ 'index' => 'store_id',
181
+ 'type' => 'store',
182
+ 'store_view' => true,
183
+ )
184
+ );
185
+ }
186
+ $this->addColumn(
187
+ 'updated_at',
188
+ array(
189
+ 'header' => $this->__('Updated at'),
190
+ 'align' => 'center',
191
+ 'type' => 'datetime',
192
+ 'index' => 'updated_at',
193
+ 'width' => '150px',
194
+ )
195
+ );
196
+ $this->addColumn(
197
+ 'created_at',
198
+ array(
199
+ 'header' => $this->__('Created at'),
200
+ 'align' => 'center',
201
+ 'type' => 'datetime',
202
+ 'index' => 'created_at',
203
+ 'width' => '150px',
204
+ )
205
+ );
206
+
207
+ return parent::_prepareColumns();
208
+ }
209
+
210
+
211
+
212
+ /**
213
+ * Disable edit mode.
214
+ *
215
+ * @Override
216
+ * @param object $row
217
+ * @return boolean
218
+ */
219
+ public function getRowUrl($row)
220
+ {
221
+ return false;
222
+ }
223
+
224
+
225
+
226
+ /**
227
+ * Get grid 's url.
228
+ *
229
+ * @Override
230
+ * @return string
231
+ */
232
+ public function getGridUrl()
233
+ {
234
+ return Mage::helper('adminhtml')->getUrl(
235
+ '*/*/index',
236
+ array('_current' => 1)
237
+ );
238
+ }
239
+ }
app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Sales/Order/Create/Billing/Method/Form.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Block_Adminhtml_Sales_Order_Create_Billing_Method_Form
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Block_Adminhtml_Sales_Order_Create_Billing_Method_Form
12
+ extends Mage_Adminhtml_Block_Sales_Order_Create_Billing_Method_Form
13
+ {
14
+
15
+ /**
16
+ * Retrieve availale payment methods
17
+ * - remove eMAG payment methods if emag_order_id is not available
18
+ * - remove Magento default payment methods if emag_order_id is available
19
+ *
20
+ * @return array
21
+ */
22
+ public function getMethods()
23
+ {
24
+ parent::getMethods();
25
+
26
+ $methods = $this->getData('methods');
27
+ if (!empty($methods)) {
28
+ foreach ($methods as $key => $method) {
29
+ if (
30
+ (!$this->getQuote()->getEmagOrderId() && strpos($method->getCode(), 'emag') !== false)
31
+ || $method->getCode() == 'emag_unknown'
32
+ ) {
33
+ unset($methods[$key]);
34
+ } elseif ($this->getQuote()->getEmagOrderId() && strpos($method->getCode(), 'emag') === false) {
35
+ unset($methods[$key]);
36
+ }
37
+ }
38
+ $this->setData('methods', $methods);
39
+ }
40
+
41
+ return $methods;
42
+ }
43
+
44
+ }
app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Sales/Order/Create/Items/Grid.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Block_Adminhtml_Sales_Order_Create_Items_Grid
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Block_Adminhtml_Sales_Order_Create_Items_Grid
12
+ extends Mage_Adminhtml_Block_Sales_Order_Create_Items_Grid
13
+ {
14
+
15
+ /**
16
+ * Get quote's origin order id
17
+ *
18
+ * @return Mage_Sales_Model_Order
19
+ */
20
+ public function getOrder()
21
+ {
22
+ $orderId = Mage::getSingleton('adminhtml/session_quote')->getOrderId();
23
+ $order = Mage::getModel('sales/order')
24
+ ->load($orderId);
25
+
26
+ return $order;
27
+ }
28
+
29
+ /**
30
+ * Get original item based on quote order id and quote item product id
31
+ *
32
+ * @param Mage_Sales_Model_Order_Item $quoteItem
33
+ * @return null|Mage_Sales_Model_Order_Item
34
+ */
35
+ public function getOriginalItem($quoteItem)
36
+ {
37
+ $order = $this->getOrder();
38
+
39
+ // skip if not eMAG order
40
+ if(!$order->getEmagOrderId()) {
41
+ return null;
42
+ }
43
+
44
+ /** @var $collection Mage_Sales_Model_Entity_Order_Item_Collection */
45
+ $collection = Mage::getResourceModel('sales/order_item_collection');
46
+ $collection
47
+ ->addFieldToFilter('order_id', $order->getId())
48
+ ->addFieldToFilter('product_id', $quoteItem->getProductId());
49
+
50
+ if($collection->getSize()) {
51
+ return $collection->getFirstItem();
52
+ }
53
+
54
+ return null;
55
+ }
56
+
57
+ }
app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Sales/Order/Create/Shipping/Method/Form.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Block_Adminhtml_Sales_Order_Create_Shipping_Method_Form
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Block_Adminhtml_Sales_Order_Create_Shipping_Method_Form
12
+ extends Mage_Adminhtml_Block_Sales_Order_Create_Shipping_Method_Form
13
+ {
14
+
15
+ /**
16
+ * Retrieve array of shipping rates groups
17
+ * - remove eMAG shipping methods if emag_order_id is not available
18
+ * - remove Magento default shipping methods if emag_order_id is available
19
+ *
20
+ * @return array
21
+ */
22
+ public function getShippingRates()
23
+ {
24
+ parent::getShippingRates();
25
+
26
+ if (!empty($this->_rates)) {
27
+ foreach ($this->_rates as $code => $_rates) {
28
+ if (!$this->getQuote()->getEmagOrderId() && strpos($code, 'emag') !== false) {
29
+ unset($this->_rates[$code]);
30
+ } elseif ($this->getQuote()->getEmagOrderId() && strpos($code, 'emag') === false) {
31
+ unset($this->_rates[$code]);
32
+ }
33
+ }
34
+ }
35
+
36
+ return $this->_rates;
37
+ }
38
+
39
+ }
app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Sales/Order/Create/Totals/Voucher.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobytye_Emag_Marketplace_Block_Adminhtml_Sales_Order_Create_Totals_Voucher
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Block_Adminhtml_Sales_Order_Create_Totals_Voucher
12
+ extends Mage_Adminhtml_Block_Sales_Order_Create_Totals_Default
13
+ {
14
+
15
+ /**
16
+ * Template
17
+ *
18
+ * @var string
19
+ */
20
+ protected $_template = 'innobyte/emag_marketplace/sales/order/create/totals/voucher.phtml';
21
+
22
+ }
app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Sales/Order/View/Comment.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Block_Adminhtml_Sales_Order_View_Comment
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Block_Adminhtml_Sales_Order_View_Comment
12
+ extends Mage_Adminhtml_Block_Template
13
+ {
14
+
15
+ /**
16
+ * Retrieve order model
17
+ *
18
+ * @return Mage_Sales_Model_Order
19
+ */
20
+ public function getOrder()
21
+ {
22
+ return Mage::registry('sales_order');
23
+ }
24
+
25
+ /**
26
+ * Get eMAG customer comments
27
+ */
28
+ public function getCustomerComment()
29
+ {
30
+ $comment = $this->getOrder()->getEmagCustomerComment();
31
+
32
+ return $comment;
33
+
34
+ }
35
+
36
+ }
app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Sales/Order/View/Invoice/Popup.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Block_Adminhtml_Sales_Order_View_Invoice_Popup
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Block_Adminhtml_Sales_Order_View_Invoice_Popup
12
+ extends Mage_Adminhtml_Block_Template
13
+ {
14
+
15
+ }
app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Sales/Order/View/Invoice/Upload.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Block_Adminhtml_Sales_Order_View_Invoice_Upload
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Block_Adminhtml_Sales_Order_View_Invoice_Upload
12
+ extends Mage_Adminhtml_Block_Widget_Form_Container
13
+ {
14
+
15
+ /**
16
+ * Configure form container
17
+ */
18
+ public function __construct()
19
+ {
20
+ parent::__construct();
21
+
22
+ $this->_objectId = 'id';
23
+ $this->_blockGroup = 'innobyte_emag_marketplace';
24
+ $this->_controller = 'adminhtml_sales_order';
25
+
26
+ $this->_removeButton('back');
27
+ $this->_removeButton('reset');
28
+ $this->_updateButton('save', 'label', Mage::helper('innobyte_emag_marketplace')->__('Upload'));
29
+ }
30
+
31
+ /**
32
+ * Get form container header text
33
+ *
34
+ * @return string
35
+ */
36
+ public function getHeaderText()
37
+ {
38
+ return Mage::helper('innobyte_emag_marketplace')->__('eMAG Upload Invoice');
39
+ }
40
+
41
+ }
app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Sales/Order/View/Invoice/Upload/Form.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Block_Adminhtml_Sales_Order_View_Invoice_Upload_Form
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Block_Adminhtml_Sales_Order_View_Invoice_Upload_Form
12
+ extends Mage_Adminhtml_Block_Widget_Form
13
+ {
14
+
15
+ /**
16
+ * Get current order
17
+ *
18
+ * @return Mage_Sales_Model_Order
19
+ */
20
+ public function getOrder()
21
+ {
22
+ return Mage::getModel('sales/order')
23
+ ->load($this->getRequest()->getParam('order_id'));
24
+ }
25
+
26
+ /**
27
+ * Prepare form
28
+ *
29
+ * @return Mage_Adminhtml_Block_Widget_Form
30
+ */
31
+ protected function _prepareForm()
32
+ {
33
+ $data = array(
34
+ 'invoice' => $this->_prepareInvoiceValues(),
35
+ 'is_storno' => '1'
36
+ );
37
+
38
+ $form = new Varien_Data_Form(
39
+ array(
40
+ 'id' => 'edit_form',
41
+ 'action' => $this->getUrl('*/sales_invoice_upload/save', array('_current' => true)),
42
+ 'method' => 'post',
43
+ 'enctype' => 'multipart/form-data',
44
+ )
45
+ );
46
+
47
+ $form->setHtmlIdPrefix('emag_invoice_');
48
+ $form->setUseContainer(true);
49
+
50
+ $fieldset = $form->addFieldset('emag_invoice_form', array(
51
+ 'legend' => Mage::helper('innobyte_emag_marketplace')->__('Upload File'),
52
+ 'class' => 'fieldset'
53
+ ));
54
+
55
+ $fieldset->addType('invoice_file', 'Innobyte_EmagMarketplace_Block_Adminhtml_Form_Element_File');
56
+
57
+ $fieldset->addField('invoice', 'invoice_file', array(
58
+ 'label' => Mage::helper('innobyte_emag_marketplace')->__('Invoice'),
59
+ 'disabled' => false,
60
+ 'readonly' => true,
61
+ 'required' => true,
62
+ 'name' => 'invoice'
63
+ ));
64
+
65
+ $fieldset->addField('is_storno', 'checkbox', array(
66
+ 'label' => Mage::helper('innobyte_emag_marketplace')->__('Is Storno'),
67
+ 'name' => 'is_storno',
68
+ 'checked' => false,
69
+ 'disabled' => false,
70
+ 'value' => '1'
71
+ ));
72
+
73
+ $this->setForm($form);
74
+ $form->setValues($data);
75
+
76
+ return parent::_prepareForm();
77
+ }
78
+
79
+ /**
80
+ * Get order invoices
81
+ *
82
+ * @return array
83
+ */
84
+ protected function _prepareInvoiceValues()
85
+ {
86
+ return Mage::getModel('innobyte_emag_marketplace/sales_invoice')
87
+ ->getEmagThirdPartyInvoices($this->getRequest()->getParam('order_id'));
88
+ }
89
+
90
+ }
app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Vat.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG VATs grid container.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Block_Adminhtml_Vat
11
+ extends Mage_Adminhtml_Block_Widget_Grid_Container
12
+ {
13
+ /**
14
+ * @Override
15
+ */
16
+ public function __construct()
17
+ {
18
+ $this->_objectId = 'id';
19
+ $this->_blockGroup = 'innobyte_emag_marketplace';
20
+ $this->_controller = 'adminhtml_vat';
21
+ $this->_headerText = $this->__('eMAG VATs');
22
+
23
+ parent::__construct();
24
+
25
+ $helper = Mage::helper('innobyte_emag_marketplace');
26
+ $storeId = $helper->getCurrStoreId();
27
+ $canMakeApiCall = $helper->canMakeApiCall($storeId);
28
+ if ($helper->isExtensionEnabled($storeId)
29
+ && $storeId != Mage_Core_Model_App::ADMIN_STORE_ID) {
30
+ $this->_updateButton(
31
+ 'add',
32
+ null,
33
+ array(
34
+ 'label' => $this->__('Synchronize VATs'),
35
+ 'onclick' => 'inno.emagMarketplace.syncVats(\''
36
+ . $this->escapeUrl(
37
+ $this->getUrl(
38
+ '*/*/syncVats',
39
+ array('_current' => 1)
40
+ )
41
+ )
42
+ . '\')',
43
+ 'sort_order' => 100,
44
+ 'disabled' => !$canMakeApiCall,
45
+ 'title' => !$canMakeApiCall ? $helper->__(
46
+ 'Please configure extension from System -> Configuration -> eMAG Marketplace'
47
+ ) : '',
48
+ )
49
+ );
50
+ } else {
51
+ $this->_removeButton('add');
52
+ }
53
+ }
54
+ }
app/code/local/Innobyte/EmagMarketplace/Block/Adminhtml/Vat/Grid.php ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG categories grid.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Block_Adminhtml_Vat_Grid
11
+ extends Mage_Adminhtml_Block_Widget_Grid
12
+ {
13
+ /**
14
+ * Constructor.
15
+ *
16
+ * @Override
17
+ */
18
+ public function __construct()
19
+ {
20
+ parent::__construct();
21
+ $this->setId('innoEmagVatsGrid');
22
+ $this->setDefaultSort('id');
23
+ $this->setDefaultDir('DESC');
24
+ $this->setUseAjax(true);
25
+ $this->setSaveParametersInSession(true);
26
+ }
27
+
28
+
29
+
30
+ /**
31
+ * Setup the collection to show in the grid.
32
+ *
33
+ * @Override
34
+ * @return Innobyte_EmagMarketplace_Block_Adminhtml_Vat_Grid
35
+ */
36
+ protected function _prepareCollection()
37
+ {
38
+ $collection = Mage::getResourceModel(
39
+ 'innobyte_emag_marketplace/vat_collection'
40
+ )->addStoreFilter(
41
+ Mage::helper('innobyte_emag_marketplace')->getCurrStoreId()
42
+ );
43
+ $this->setCollection($collection);
44
+ return parent::_prepareCollection();
45
+ }
46
+
47
+
48
+
49
+ /**
50
+ * Setup the shown columns.
51
+ *
52
+ * @Override
53
+ * @return Innobyte_EmagMarketplace_Block_Adminhtml_Vat_Grid
54
+ */
55
+ protected function _prepareColumns()
56
+ {
57
+ $this->addColumn(
58
+ 'emag_id',
59
+ array(
60
+ 'header' => $this->__('eMAG ID'),
61
+ 'align' => 'left',
62
+ 'type' => 'number',
63
+ 'index' => 'emag_id',
64
+ 'width' => '50px',
65
+ )
66
+ );
67
+ $this->addColumn(
68
+ 'rate',
69
+ array(
70
+ 'header' => $this->__('Rate'),
71
+ 'align' => 'right',
72
+ 'type' => 'text',
73
+ 'index' => 'rate',
74
+ )
75
+ );
76
+ if (!Mage::app()->isSingleStoreMode()) {
77
+ $this->addColumn(
78
+ 'store_id',
79
+ array(
80
+ 'header' => Mage::helper('sales')->__('Store'),
81
+ 'index' => 'store_id',
82
+ 'type' => 'store',
83
+ 'store_view' => true,
84
+ )
85
+ );
86
+ }
87
+ $this->addColumn(
88
+ 'updated_at',
89
+ array(
90
+ 'header' => $this->__('Updated at'),
91
+ 'align' => 'center',
92
+ 'type' => 'datetime',
93
+ 'index' => 'updated_at',
94
+ 'width' => '150px',
95
+ )
96
+ );
97
+ $this->addColumn(
98
+ 'created_at',
99
+ array(
100
+ 'header' => $this->__('Created at'),
101
+ 'align' => 'center',
102
+ 'type' => 'datetime',
103
+ 'index' => 'created_at',
104
+ 'width' => '150px',
105
+ )
106
+ );
107
+
108
+ return parent::_prepareColumns();
109
+ }
110
+
111
+
112
+
113
+ /**
114
+ * Disable edit mode.
115
+ *
116
+ * @Override
117
+ * @param object $row
118
+ * @return boolean
119
+ */
120
+ public function getRowUrl($row)
121
+ {
122
+ return false;
123
+ }
124
+
125
+
126
+
127
+ /**
128
+ * Get grid 's url.
129
+ *
130
+ * @Override
131
+ * @return string
132
+ */
133
+ public function getGridUrl()
134
+ {
135
+ return Mage::helper('adminhtml')->getUrl(
136
+ '*/*/index',
137
+ array('_current' => 1)
138
+ );
139
+ }
140
+ }
app/code/local/Innobyte/EmagMarketplace/Exception.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Custom exception class.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Exception extends Mage_Exception
11
+ {
12
+ }
app/code/local/Innobyte/EmagMarketplace/Helper/Data.php ADDED
@@ -0,0 +1,416 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Helper_Data
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
11
+ */
12
+ class Innobyte_EmagMarketplace_Helper_Data extends Mage_Core_Helper_Data
13
+ {
14
+ /**
15
+ * Config paths
16
+ */
17
+ const CONFIG_PATH = 'Innobyte_EmagMarketplace/';
18
+ const CONFIG_PATH_GENERAL_SETTINGS = 'general_settings/';
19
+ const CONFIG_PATH_API_SETTINGS = 'api_settings/';
20
+ const CONFIG_PATH_SHIP_ORIGIN_EMAG_LOCALITY_ID = 'shipping/origin/emag_locality_id';
21
+ const CONFIG_PATH_COURIER_ACCOUNT_ID = 'Innobyte_EmagMarketplace/shipping_settings/courier_account_id';
22
+ const CONFIG_PATH_AWB_PDF_URL = 'Innobyte_EmagMarketplace/shipping_settings/awb_pdf_url';
23
+ const MODULE_NAME = 'innobyte_emag_marketplace';
24
+
25
+ /**
26
+ * Get module config
27
+ *
28
+ * @param string $path
29
+ * @param int|Mage_Core_Model_Store $storeId
30
+ * @return string
31
+ */
32
+ public function getConfig($path, $storeId = null)
33
+ {
34
+ return Mage::getStoreConfig(self::CONFIG_PATH . $path, $storeId);
35
+ }
36
+
37
+ /**
38
+ * Check if extension is enabled
39
+ *
40
+ * @param int|Mage_Core_Model_Store $storeId
41
+ * @return bool
42
+ */
43
+ public function isExtensionEnabled($storeId = null)
44
+ {
45
+ return (bool)$this->getConfig(self::CONFIG_PATH_GENERAL_SETTINGS . 'active', $storeId);
46
+ }
47
+
48
+ /**
49
+ * Check if debug mode
50
+ *
51
+ * @param int|Mage_Core_Model_Store $storeId
52
+ * @return bool
53
+ */
54
+ public function isDebug($storeId = null)
55
+ {
56
+ return (bool)$this->getConfig(self::CONFIG_PATH_GENERAL_SETTINGS . 'debug', $storeId);
57
+ }
58
+
59
+ /**
60
+ * Get eMAG domain
61
+ *
62
+ * @param int|Mage_Core_Model_Store $storeId
63
+ * @return string
64
+ */
65
+ public function getEmagDomain($storeId = null)
66
+ {
67
+ return (string)$this->getConfig(self::CONFIG_PATH_GENERAL_SETTINGS . 'domain', $storeId);
68
+ }
69
+
70
+ /**
71
+ * Get email
72
+ *
73
+ * @param int|Mage_Core_Model_Store $storeId
74
+ * @return string
75
+ */
76
+ public function getEmail($storeId = null)
77
+ {
78
+ return (string)$this->getConfig(self::CONFIG_PATH_GENERAL_SETTINGS . 'email', $storeId);
79
+ }
80
+
81
+ /**
82
+ * Get email template
83
+ *
84
+ * @param int|Mage_Core_Model_Store $storeId
85
+ * @return string
86
+ */
87
+ public function getTemplate($storeId = null)
88
+ {
89
+ return (string)$this->getConfig(self::CONFIG_PATH_GENERAL_SETTINGS . 'template', $storeId);
90
+ }
91
+
92
+ /**
93
+ * Get allowed ip addresses to access invoice folders
94
+ *
95
+ * @param null $storeId
96
+ * @return array
97
+ */
98
+ public function getAllowedIpAddresses($storeId = null)
99
+ {
100
+ $ipAddresses = explode(',', $this->getConfig(self::CONFIG_PATH_GENERAL_SETTINGS . 'allowed_ip_addresses', $storeId));
101
+
102
+ return $ipAddresses;
103
+ }
104
+
105
+ /**
106
+ * Get api url
107
+ *
108
+ * @param int|Mage_Core_Model_Store $storeId
109
+ * @return string
110
+ */
111
+ public function getApiUrl($storeId = null)
112
+ {
113
+ return rtrim(strval($this->getConfig(self::CONFIG_PATH_API_SETTINGS . 'url', $storeId)), '/');
114
+ }
115
+
116
+ /**
117
+ * Get api username
118
+ *
119
+ * @param int|Mage_Core_Model_Store $storeId
120
+ * @return string
121
+ */
122
+ public function getApiUsername($storeId = null)
123
+ {
124
+ return (string)$this->getConfig(self::CONFIG_PATH_API_SETTINGS . 'username', $storeId);
125
+ }
126
+
127
+ /**
128
+ * Get api password
129
+ *
130
+ * @param int|Mage_Core_Model_Store $storeId
131
+ * @return string
132
+ */
133
+ public function getApiPassword($storeId = null)
134
+ {
135
+ return (string) $this->getConfig(self::CONFIG_PATH_API_SETTINGS . 'password', $storeId);
136
+ }
137
+
138
+ /**
139
+ * Get api order url
140
+ *
141
+ * @param int|Mage_Core_Model_Store $storeId
142
+ * @return string
143
+ */
144
+ public function getClientCode($storeId = null)
145
+ {
146
+ return (string)$this->getConfig(self::CONFIG_PATH_API_SETTINGS . 'code', $storeId);
147
+ }
148
+
149
+ /**
150
+ * Get formatted voucher label
151
+ *
152
+ * @param $label
153
+ * @param $voucherCode
154
+ * @return string
155
+ */
156
+ public function getFormattedVoucherLabel($label, $voucherCode = null)
157
+ {
158
+ $label = $this->__($label);
159
+ if ($voucherCode) {
160
+ $label .= ' (' . $voucherCode . ')';
161
+ }
162
+
163
+ return $label;
164
+ }
165
+
166
+ /**
167
+ * Retrieve adapter for http requests.
168
+ *
169
+ * @return string One of the Zend_Http_Client adapters.
170
+ */
171
+ public function getMakeHttpCallAdapter()
172
+ {
173
+ $returnValue = 'Zend_Http_Client_Adapter_Curl'; // default value
174
+ $configValue = trim(strval(Mage::getConfig()->getNode('stores/default/innobyte_emag_marketplace_http_call_adapter')));
175
+ if (strlen($configValue)
176
+ && class_exists($configValue)
177
+ && $configValue instanceof Zend_Http_Client_Adapter_Interface
178
+ ) {
179
+ $returnValue = $configValue;
180
+ }
181
+ return $returnValue;
182
+ }
183
+
184
+ /**
185
+ * Get resource log file
186
+ *
187
+ * @param $resourceName
188
+ * @return string
189
+ */
190
+ public function getResourceLogFile($resourceName)
191
+ {
192
+ return self::MODULE_NAME . '_' . $resourceName . '.log';
193
+ }
194
+
195
+ /**
196
+ * Retrieve timeout for http requests.
197
+ *
198
+ * @return int Timeout expressed in seconds.
199
+ */
200
+ public function getMakeHttpCallTimeout()
201
+ {
202
+ $returnValue = 40; // default value
203
+ $configValue = trim(strval(Mage::getConfig()->getNode('stores/default/innobyte_emag_marketplace_http_call_timeout')));
204
+ if (is_numeric($configValue) && $configValue >= 0) {
205
+ $returnValue = intval($configValue);
206
+ }
207
+ return $returnValue;
208
+ }
209
+
210
+
211
+
212
+ /**
213
+ * Retrieve current store scope.
214
+ *
215
+ * @return int
216
+ */
217
+ public function getCurrStoreId()
218
+ {
219
+ $returnValue = Mage::app()->getStore()->getId();
220
+ $store = Mage::app()->getRequest()->getParam('store');
221
+ if ($store && Mage::app()->getStore($store)->getStoreId()) {
222
+ $returnValue = Mage::app()->getStore($store)->getStoreId();
223
+ }
224
+ return $returnValue;
225
+ }
226
+
227
+
228
+
229
+ /**
230
+ * Perform different checks to see if product action is eligible to continue.
231
+ *
232
+ * @param Mage_Catalog_Model_Product $product
233
+ * @return bool
234
+ */
235
+ public function isProductActionValid($product)
236
+ {
237
+ $storeId = $this->getCurrStoreId();
238
+ return ($storeId != Mage_Core_Model_App::ADMIN_STORE_ID
239
+ && $this->isExtensionEnabled($storeId)
240
+ && !is_null($product)
241
+ && ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE
242
+ || $product->isConfigurable()));
243
+ }
244
+
245
+
246
+
247
+ /**
248
+ * Checks api settings to be configured and extension to be enabled.
249
+ *
250
+ * @param int|Mage_Core_Model_Store $storeId
251
+ * @return bool
252
+ */
253
+ public function canMakeApiCall($storeId = null)
254
+ {
255
+ return ($this->isExtensionEnabled($storeId)
256
+ && strlen($this->getApiUrl($storeId))
257
+ && strlen($this->getApiUsername($storeId))
258
+ && strlen($this->getApiPassword($storeId))
259
+ && strlen($this->getClientCode($storeId)));
260
+ }
261
+
262
+
263
+
264
+ /**
265
+ * Check if limited stock flag is enabled to be taken into consideration.
266
+ *
267
+ * @param int|Mage_Core_Model_Store $storeId
268
+ * @return bool
269
+ */
270
+ public function isLimitedStockEnabled($storeId = null)
271
+ {
272
+ return (bool)$this->getConfig(self::CONFIG_PATH_GENERAL_SETTINGS . 'enable_limited_stock', $storeId);
273
+ }
274
+
275
+
276
+
277
+ /**
278
+ * Retrieve qty limit under which product, if "in stock", should be considered as "limited stock".
279
+ *
280
+ * @param int|Mage_Core_Model_Store $storeId
281
+ * @return int
282
+ */
283
+ public function getLimitedStockLimit($storeId = null)
284
+ {
285
+ return (int)$this->getConfig(self::CONFIG_PATH_GENERAL_SETTINGS . 'limited_stock', $storeId);
286
+ }
287
+
288
+
289
+ /**
290
+ * Retrieve shipping origin emag locality id.
291
+ *
292
+ * @param int|Mage_Core_Model_Store $storeId
293
+ * @return int
294
+ */
295
+ public function getShipOriginEmagLocalityId($storeId = null)
296
+ {
297
+ return (int) Mage::getStoreConfig(self::CONFIG_PATH_SHIP_ORIGIN_EMAG_LOCALITY_ID, $storeId);
298
+ }
299
+
300
+
301
+ /**
302
+ * Check if real stock qty shoud be sent to eMAG.
303
+ *
304
+ * @param int|Mage_Core_Model_Store $storeId
305
+ * @return bool TRUE if stock qty should be sent to eMAG, FALSE otherwise.
306
+ */
307
+ public function sendStockQty($storeId = null)
308
+ {
309
+ return (bool)$this->getConfig(self::CONFIG_PATH_GENERAL_SETTINGS . 'send_stock_qty', $storeId);
310
+ }
311
+
312
+
313
+
314
+ /**
315
+ * Try to retrieve Magento region id based on eMAG region name.
316
+ * "Try" means that exact match is searched, otherwise the region with a
317
+ * single letter difference, if only one is found.
318
+ *
319
+ * @param string $regionName
320
+ * @param string $countryCode
321
+ * @return Mage_Directory_Model_Region|null can be null if no matching was found.
322
+ */
323
+ public function getMagentoRegion($regionName, $countryCode)
324
+ {
325
+ // search for it directly
326
+ $region = Mage::getModel('directory/region')
327
+ ->loadByName($regionName, $countryCode);
328
+ if ($region->getId() > 0) {
329
+ return $region;
330
+ }
331
+ // otherwise search in all reagions for that country for a closest match.
332
+ $collection = Mage::getResourceModel('directory/region_collection')
333
+ ->addCountryFilter($countryCode)
334
+ ->load();
335
+ if (!$collection->getSize()) {
336
+ return null;
337
+ }
338
+ $shortest = -1; // shortest levenshtein dist found.
339
+ $shortestCnt = 1; // how many had the shortest distance.
340
+ $closest = null; // the region model that has the shortest distance
341
+
342
+ foreach ($collection as $region) {
343
+ $regName = $this->getAsciiTranslitVal($region->getName());
344
+ if ($regionName == $regName) {
345
+ $closest = $region;
346
+ $shortest = 0;
347
+ break;
348
+ } else { // calculate levenshtein distance
349
+ $lev = levenshtein($regionName, $regName);
350
+ if ($lev <= $shortest || $shortest < 0) {
351
+ if ($lev == $shortest) {
352
+ $shortestCnt++;
353
+ } else {
354
+ $shortestCnt = 1;
355
+ }
356
+ // set the closest match, and shortest distance
357
+ $closest = $region;
358
+ $shortest = $lev;
359
+ }
360
+ }
361
+ }
362
+ if (0 == $shortest && $closest->getId() > 0) { // found exact match
363
+ return $closest;
364
+ } elseif (1 == $shortest && 1 == $shortestCnt && $closest->getId() > 0) {
365
+ // return single closest match, "closest" meaning that a single letter
366
+ // should be distinct, otherwise is too risky to afirm that
367
+ // the eMAG region is THAT Magento region
368
+ return $closest;
369
+ }
370
+ return null;
371
+ }
372
+
373
+
374
+
375
+ /**
376
+ * Retrieve ASCII/TRANSLIT value of a string.
377
+ * @param string $string
378
+ * @return string
379
+ */
380
+ public function getAsciiTranslitVal($string)
381
+ {
382
+ $currentLocale = setlocale(LC_CTYPE, "0"); // iconv pb when locale set to C or POSIX on UX systems
383
+ if ('C' == $currentLocale || 'POSIX' == $currentLocale) {
384
+ setlocale(LC_CTYPE, 'en_US.utf8');
385
+ }
386
+ $returnValue = iconv('ISO-8859-1', 'ASCII//TRANSLIT', $string);
387
+ if ('C' == $currentLocale || 'POSIX' == $currentLocale) { // set back current locale
388
+ setlocale(LC_CTYPE, $currentLocale);
389
+ }
390
+ return $returnValue;
391
+ }
392
+
393
+
394
+
395
+ /**
396
+ * Retrieve courier account id.
397
+ *
398
+ * @param int|Mage_Core_Model_Store $storeId
399
+ * @return string
400
+ */
401
+ public function getCourierAccountId($storeId = null)
402
+ {
403
+ return trim(Mage::getStoreConfig(self::CONFIG_PATH_COURIER_ACCOUNT_ID, $storeId));
404
+ }
405
+
406
+ /**
407
+ * Retrieve url where to read AWB PDF from.
408
+ *
409
+ * @param int|Mage_Core_Model_Store $storeId
410
+ * @return string
411
+ */
412
+ public function getAwbPdfUrl($storeId = null)
413
+ {
414
+ return trim(Mage::getStoreConfig(self::CONFIG_PATH_AWB_PDF_URL, $storeId));
415
+ }
416
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Api/Abstract.php ADDED
@@ -0,0 +1,553 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Api_Abstract
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
11
+ */
12
+ abstract class Innobyte_EmagMarketplace_Model_Api_Abstract
13
+ {
14
+
15
+ /**
16
+ * Available resource actions
17
+ */
18
+ const ACTION_READ = 'read';
19
+ const ACTION_SAVE = 'save';
20
+ const ACTION_COUNT = 'count';
21
+ const ACTION_ACKNOWLEDGE = 'acknowledge';
22
+
23
+ /**
24
+ * Default no of items per page.
25
+ */
26
+ const DEFAULT_PAGE_SIZE = 100;
27
+
28
+ /**
29
+ * Api call action name
30
+ *
31
+ * @var null|string
32
+ */
33
+ protected $_actionName = null;
34
+
35
+ /**
36
+ * eMAG order id
37
+ *
38
+ * @var null
39
+ */
40
+ protected $_emagOrderId = null;
41
+
42
+ /**
43
+ * Store id
44
+ *
45
+ * @var null|int
46
+ */
47
+ protected $_storeId = null;
48
+
49
+ /**
50
+ * Data
51
+ *
52
+ * @var array
53
+ */
54
+ protected $_data = array();
55
+
56
+ /**
57
+ * File
58
+ *
59
+ * @var array
60
+ */
61
+ protected $_file = null;
62
+
63
+ /**
64
+ * Fields that should be replaced in debug with '***'
65
+ *
66
+ * @var array
67
+ */
68
+ protected $_debugReplacePrivateDataKeys = array(
69
+ //TODO: populate this if needed
70
+ );
71
+
72
+ /**
73
+ * No of items
74
+ *
75
+ * @var int
76
+ */
77
+ protected $_noOfItems = 0;
78
+
79
+ /**
80
+ * Pages no.
81
+ * @var int
82
+ */
83
+ protected $_noOfPages = 0;
84
+
85
+ /**
86
+ * Items per page.
87
+ * @var type
88
+ */
89
+ protected $_itemsPerPage = self::DEFAULT_PAGE_SIZE;
90
+
91
+ /**
92
+ * If set, pagination data will be added when calling #read()
93
+ * @var int
94
+ */
95
+ protected $_currentPage = 0;
96
+
97
+ /**
98
+ * Read
99
+ *
100
+ * @return mixed
101
+ */
102
+ public function read()
103
+ {
104
+ $this->setActionName(self::ACTION_READ);
105
+ if ($this->_currentPage > 0 && $this->getItemsPerPage() > 0) {
106
+ $pagination = array(
107
+ 'currentPage' => $this->_currentPage,
108
+ 'itemsPerPage' => $this->getItemsPerPage(),
109
+ );
110
+ $this->setData(array_merge($this->getData(), $pagination));
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Save
116
+ *
117
+ * @return mixed
118
+ */
119
+ public function save()
120
+ {
121
+ $this->setActionName(self::ACTION_SAVE);
122
+ }
123
+
124
+ /**
125
+ * Count
126
+ *
127
+ * @return mixed
128
+ */
129
+ public function count()
130
+ {
131
+ $this->setActionName(self::ACTION_COUNT);
132
+ }
133
+
134
+ /**
135
+ * Acknowledge
136
+ *
137
+ * @return mixed
138
+ */
139
+ public function acknowledge()
140
+ {
141
+ $this->setActionName(self::ACTION_ACKNOWLEDGE);
142
+ }
143
+
144
+ /**
145
+ * Get resource name
146
+ *
147
+ * @return string
148
+ */
149
+ abstract public function getResourceName();
150
+
151
+ /**
152
+ * Set api call action name
153
+ *
154
+ * @param $action
155
+ * @return Innobyte_EmagMarketplace_Model_Api_Abstract
156
+ */
157
+ public function setActionName($action)
158
+ {
159
+ $this->_actionName = $action;
160
+
161
+ return $this;
162
+ }
163
+
164
+ /**
165
+ * Get api call action name
166
+ *
167
+ * @return string
168
+ */
169
+ public function getActionName()
170
+ {
171
+ return $this->_actionName;
172
+ }
173
+
174
+ /**
175
+ * Set eMAG order id required for acknowledge
176
+ *
177
+ * @param $orderId
178
+ * @return Innobyte_EmagMarketplace_Model_Api_Abstract
179
+ */
180
+ public function setEmagOrderId($orderId)
181
+ {
182
+ $this->_emagOrderId = $orderId;
183
+
184
+ return $this;
185
+ }
186
+
187
+ /**
188
+ * Get eMAG order id required for acknowledge
189
+ *
190
+ * @return int
191
+ */
192
+ public function getEmagOrderId()
193
+ {
194
+ return $this->_emagOrderId;
195
+ }
196
+
197
+ /**
198
+ * Setter method for store id property
199
+ *
200
+ * @param int $storeId
201
+ * @return Innobyte_EmagMarketplace_Model_Api_Abstract
202
+ */
203
+ public function setStoreId($storeId)
204
+ {
205
+ if (is_numeric($storeId)) {
206
+ $this->_storeId = (int)$storeId;
207
+ }
208
+ return $this;
209
+ }
210
+
211
+ /**
212
+ * Getter method for store id property.
213
+ *
214
+ * @return int|null Store 's id.
215
+ */
216
+ public function getStoreId()
217
+ {
218
+ return $this->_storeId;
219
+ }
220
+
221
+ /**
222
+ * Set data
223
+ *
224
+ * @param $data
225
+ * @return Innobyte_EmagMarketplace_Model_Api_Abstract
226
+ */
227
+ public function setData($data)
228
+ {
229
+ $this->_data = $data;
230
+
231
+ return $this;
232
+ }
233
+
234
+ /**
235
+ * Get data
236
+ *
237
+ * @return array
238
+ */
239
+ public function getData()
240
+ {
241
+ return $this->_data;
242
+ }
243
+
244
+ /**
245
+ * File
246
+ *
247
+ * @param $file
248
+ * @return Innobyte_EmagMarketplace_Model_Api_Abstract
249
+ */
250
+ public function setFile($file)
251
+ {
252
+ $this->_file = $file;
253
+
254
+ return $this;
255
+ }
256
+
257
+ /**
258
+ * Get file
259
+ *
260
+ * @return array
261
+ */
262
+ public function getFile()
263
+ {
264
+ return $this->_file;
265
+ }
266
+
267
+ /**
268
+ * Get eMAG marketplace data helper
269
+ *
270
+ * @return Innobyte_EmagMarketplace_Helper_Data
271
+ */
272
+ public function getHelper()
273
+ {
274
+ return Mage::helper('innobyte_emag_marketplace');
275
+ }
276
+
277
+ /**
278
+ * Get api url for resource and action
279
+ *
280
+ * @return string
281
+ */
282
+ protected function getResourceActionApiUrl()
283
+ {
284
+ $url = $this->getHelper()->getApiUrl($this->getStoreId())
285
+ . DS . $this->getResourceName() . DS . $this->getActionName();
286
+
287
+ $orderId = $this->getEmagOrderId();
288
+ if ($orderId) {
289
+ $url .= DS . $orderId;
290
+ }
291
+
292
+ return $url;
293
+ }
294
+
295
+ /**
296
+ * Make an API call.
297
+ *
298
+ * @internal array $postData Only the 'data' key of the final post
299
+ * (no vendor code, pwd, username, hash)
300
+ * @internal array $file An array with key the formname for that file
301
+ * field, and value the path to file to upload.(optional)
302
+ * @return Innobyte_EmagMarketplace_Model_Api_Response Api response object.
303
+ * @throws Innobyte_EmagMarketplace_Exception if some error occurred.
304
+ */
305
+ protected function _makeApiCall()
306
+ {
307
+ $returnValue = null;
308
+
309
+ $file = $this->getFile();
310
+ $postData = $this->getData();
311
+ $url = $this->getResourceActionApiUrl();
312
+
313
+ $requestData = array(
314
+ 'code' => $this->getHelper()->getClientCode($this->getStoreId()),
315
+ 'username' => $this->getHelper()->getApiUsername($this->getStoreId()),
316
+ 'data' => $postData,
317
+ 'hash' => sha1(
318
+ http_build_query($postData) .
319
+ sha1($this->getHelper()->getApiPassword($this->getStoreId()))
320
+ ),
321
+ 'debug_info' => array(
322
+ 'site' => Mage::app()->getStore($this->getStoreId())
323
+ ->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB),
324
+ 'platform' => 'Magento',
325
+ 'version' => Mage::getVersion(),
326
+ 'extension_version' => (string) Mage::getConfig()
327
+ ->getModuleConfig('Innobyte_EmagMarketplace')->version,
328
+ ),
329
+ );
330
+
331
+ $requestDebugData = $postData;
332
+ if (is_array($file)) { // TODO check if we need this
333
+ $requestDebugData = array_merge(
334
+ $requestData,
335
+ array(key($file) => file_get_contents(current($file)))
336
+ );
337
+ } else {
338
+ $requestDebugData = $requestData;
339
+ }
340
+ $debugData = array('url' => $url, 'request' => $requestDebugData);
341
+
342
+ try {
343
+ $response = $this->_makeHttpCall(
344
+ $url,
345
+ $requestData,
346
+ Zend_Http_Client::POST,
347
+ $file
348
+ );
349
+ $apiResponse = Zend_Json::decode(
350
+ $response->getBody(),
351
+ Zend_Json::TYPE_ARRAY
352
+ );
353
+ $returnValue = Mage::getModel(
354
+ 'innobyte_emag_marketplace/api_response',
355
+ $apiResponse
356
+ );
357
+
358
+ $debugData['response'] = $apiResponse;
359
+ $this->debugData($debugData, $this->getResourceName()); // debug
360
+ } catch (Zend_Json_Exception $zjEx) {
361
+ $debugData['response [ERR]'] = 'Code: ' . $zjEx->getCode()
362
+ . ' Msg: ' . $zjEx->getMessage();
363
+ $this->debugData($debugData, $this->getResourceName()); // debug
364
+ throw new Innobyte_EmagMarketplace_Exception(
365
+ 'Json decode error: ' . $zjEx->getMessage(), $zjEx->getCode()
366
+ );
367
+ } catch (Innobyte_EmagMarketplace_Exception $iemEx) {
368
+ $debugData['response [ERR]'] = 'Code: ' . $iemEx->getCode()
369
+ . ' Msg: ' . $iemEx->getMessage();
370
+ $this->debugData($debugData, $this->getResourceName()); // debug
371
+ throw $iemEx;
372
+ } catch (Exception $e) {
373
+ $debugData['response [ERR]'] = 'Code: ' . $e->getCode()
374
+ . ' Msg: ' . $e->getMessage();
375
+ $this->debugData($debugData, $this->getResourceName()); // debug
376
+ throw new Innobyte_EmagMarketplace_Exception(
377
+ 'An error occurred. Please try again later.'
378
+ );
379
+ }
380
+
381
+ return $returnValue;
382
+ }
383
+
384
+
385
+
386
+ /**
387
+ * Make a HTTP call.
388
+ *
389
+ * @param string $url Url to make request to.
390
+ * @param array $data Data to send / parameters
391
+ * @param array $method Http method (GET | POST | ...)
392
+ * (optional, default is POST)
393
+ * @param array $file An array with key the file field name,
394
+ * and value the path to file to upload.(optional)
395
+ * @return Zend_Http_Response The http response object.
396
+ * @throws Innobyte_EmagMarketplace_Exception if an error occurred.
397
+ */
398
+ protected function _makeHttpCall(
399
+ $url,
400
+ array $data = array(),
401
+ $method = Zend_Http_Client::POST,
402
+ $file = null
403
+ )
404
+ {
405
+ $config = array(
406
+ 'adapter' => $this->getHelper()->getMakeHttpCallAdapter(),
407
+ 'timeout' => $this->getHelper()->getMakeHttpCallTimeout(),
408
+ );
409
+
410
+ $webClient = new Zend_Http_Client();
411
+ $webClient->setUri($url)
412
+ ->setConfig($config)
413
+ ->setMethod($method);
414
+
415
+ if (Zend_Http_Client::GET == $method) {
416
+ foreach ($data as $key => $value) {
417
+ $webClient->setParameterGet($key, $value);
418
+ }
419
+ } else {
420
+ foreach ($data as $key => $value) {
421
+ $webClient->setParameterPost($key, $value);
422
+ }
423
+ }
424
+ if (is_array($file)) { // TODO: check if we need file / files or not.
425
+ $webClient->setFileUpload(current($file), key($file));
426
+ }
427
+
428
+ $returnValue = $webClient->request();
429
+ if ($returnValue->isError()) {
430
+ throw new Innobyte_EmagMarketplace_Exception(
431
+ 'Http error response: ' . $returnValue->getMessage(),
432
+ $returnValue->getStatus()
433
+ );
434
+ }
435
+
436
+ return $returnValue;
437
+ }
438
+
439
+ /**
440
+ * Log debug data to file.
441
+ *
442
+ * @param mixed $debugData
443
+ * @param string $resource One of the Api classes resource name constatnts
444
+ * Ex: Innobyte_EmagMarketplace_Model_Api_Awb::AWB_RESOURCE_NAME
445
+ * @param $resource
446
+ */
447
+ public function debugData($debugData, $resource)
448
+ {
449
+ if ($this->getHelper()->isDebug($this->getStoreId())) {
450
+ Mage::getModel(
451
+ 'core/log_adapter',
452
+ $this->getHelper()->getResourceLogFile($resource)
453
+ )->setFilterDataKeys($this->_debugReplacePrivateDataKeys)
454
+ ->log($debugData);
455
+ }
456
+ }
457
+
458
+ /**
459
+ * Getter method for no of items property.
460
+ *
461
+ * @return int
462
+ */
463
+ public function getNoOfItems()
464
+ {
465
+ return $this->_noOfItems;
466
+ }
467
+
468
+ /**
469
+ * Getter method for no of pages property.
470
+ *
471
+ * @return int
472
+ */
473
+ public function getNoOfPages()
474
+ {
475
+ return $this->_noOfPages;
476
+ }
477
+
478
+
479
+ /**
480
+ * Getter method for items per page property.
481
+ *
482
+ * @return int
483
+ */
484
+ public function getItemsPerPage()
485
+ {
486
+ return $this->_itemsPerPage;
487
+ }
488
+
489
+
490
+ /**
491
+ * Setter method for current page property.
492
+ *
493
+ * @param int $currentPage Current page to be read.
494
+ * @return Innobyte_EmagMarketplace_Model_Api_Abstract
495
+ */
496
+ public function setCurrentPage($currentPage)
497
+ {
498
+ $this->_currentPage = intval($currentPage);
499
+
500
+ return $this;
501
+ }
502
+
503
+ /**
504
+ * Setter method for items per page property.
505
+ *
506
+ * @param int $pageSize
507
+ * @return Innobyte_EmagMarketplace_Model_Api_Abstract
508
+ */
509
+ public function setPageSize($pageSize)
510
+ {
511
+ $this->_itemsPerPage = intval($pageSize);
512
+
513
+ return $this;
514
+ }
515
+
516
+
517
+ /**
518
+ * Imports pagination info from #count() response.
519
+ *
520
+ * @param Innobyte_EmagMarketplace_Model_Api_Response $countResponse
521
+ * Api call response from #count()
522
+ * @return Innobyte_EmagMarketplace_Model_Api_Abstract
523
+ */
524
+ protected function _setPaginationInfo(
525
+ Innobyte_EmagMarketplace_Model_Api_Response $countResponse
526
+ )
527
+ {
528
+ if (is_null($countResponse) || $countResponse->isError()) {
529
+ return $this;
530
+ }
531
+ $noOfPages = 0;
532
+ $itemsPerPage = self::DEFAULT_PAGE_SIZE;
533
+ $countResult = $countResponse->getResults();
534
+ if (array_key_exists('noOfPages', $countResult)
535
+ && array_key_exists('itemsPerPage', $countResult)
536
+ && $countResult['noOfPages'] > 0
537
+ && $countResult['itemsPerPage'] > 0
538
+ ) {
539
+ $noOfPages = intval($countResult['noOfPages']);
540
+ $itemsPerPage = intval($countResult['itemsPerPage']);
541
+ } elseif (array_key_exists('noOfItems', $countResult)
542
+ && $countResult['noOfItems'] > 0
543
+ ) {
544
+ $noOfPages = ceil($countResult['noOfItems'] / $itemsPerPage);
545
+ }
546
+
547
+ $this->_noOfItems = isset($countResult['noOfItems'])
548
+ ? intval($countResult['noOfItems']) : 0;
549
+ $this->_noOfPages = $noOfPages;
550
+ $this->_itemsPerPage = $itemsPerPage;
551
+ return $this;
552
+ }
553
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Api/Awb.php ADDED
@@ -0,0 +1,441 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Handles AWB api related operations.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Api_Awb
11
+ extends Innobyte_EmagMarketplace_Model_Api_Abstract
12
+ {
13
+ /**
14
+ * Awb resource name
15
+ */
16
+ const AWB_RESOURCE_NAME = 'awb';
17
+
18
+ /**
19
+ * Request to shipment model.
20
+ *
21
+ * @var Mage_Shipping_Model_Shipment_Request
22
+ */
23
+ protected $_shipmentRequest;
24
+
25
+
26
+
27
+ /**
28
+ * Read AWB resource
29
+ *
30
+ * @throws Innobyte_EmagMarketplace_Exception
31
+ */
32
+ public function read()
33
+ {
34
+ throw new Innobyte_EmagMarketplace_Exception('Not implemented');
35
+ }
36
+
37
+
38
+
39
+ /**
40
+ * Read AWB 's pdf.
41
+ *
42
+ * @param int $emagAwbId eMAG AWB id.
43
+ * @throws Innobyte_EmagMarketplace_Exception
44
+ */
45
+ public function readPdf($emagAwbId)
46
+ {
47
+ $url = Mage::helper('innobyte_emag_marketplace')
48
+ ->getAwbPdfUrl($this->getStoreId());
49
+ if (!strlen($url)) {
50
+ throw new Innobyte_EmagMarketplace_Exception(
51
+ 'Read AWB PDF URL was not set in system config.'
52
+ );
53
+ }
54
+ $code = $this->getHelper()->getClientCode($this->getStoreId());
55
+ $username = $this->getHelper()->getApiUsername($this->getStoreId());
56
+ $pwd = $this->getHelper()->getApiPassword($this->getStoreId());
57
+ $data = array(
58
+ 'code' => $code,
59
+ 'username' => $username,
60
+ 'emag_id' => $emagAwbId,
61
+ 'hash' => sha1($pwd),
62
+ );
63
+
64
+ return $this->_makeHttpCall($url, $data, Zend_Http_Client::GET);
65
+ }
66
+
67
+
68
+
69
+ /**
70
+ * Save AWB resource
71
+ *
72
+ * @return Innobyte_EmagMarketplace_Model_Api_Response
73
+ * @throws Innobyte_EmagMarketplace_Exception
74
+ */
75
+ public function save()
76
+ {
77
+ parent::save();
78
+ return $this->setData($this->_computeApiSaveData())
79
+ ->setStoreId($this->getShipmentRequest()->getStoreId())
80
+ ->_makeApiCall();
81
+ }
82
+
83
+
84
+
85
+ /**
86
+ * Count AWB resource
87
+ *
88
+ * @throws Innobyte_EmagMarketplace_Exception
89
+ */
90
+ public function count()
91
+ {
92
+ throw new Innobyte_EmagMarketplace_Exception('Not implemented');
93
+ }
94
+
95
+
96
+
97
+ /**
98
+ * Acknowledge AWB resource
99
+ *
100
+ * @throws Innobyte_EmagMarketplace_Exception
101
+ */
102
+ public function acknowledge()
103
+ {
104
+ throw new Innobyte_EmagMarketplace_Exception('Not implemented');
105
+ }
106
+
107
+
108
+
109
+ /**
110
+ * Get resource name
111
+ *
112
+ * @return string
113
+ */
114
+ public function getResourceName()
115
+ {
116
+ return self::AWB_RESOURCE_NAME;
117
+ }
118
+
119
+
120
+
121
+ /**
122
+ * Setter method for shipment request.
123
+ *
124
+ * @param Mage_Shipping_Model_Shipment_Request $request
125
+ * @return Innobyte_EmagMarketplace_Model_Api_Awb
126
+ * @throws Innobyte_EmagMarketplace_Exception If null param is provided.
127
+ */
128
+ public function setShipmentRequest(Mage_Shipping_Model_Shipment_Request $request)
129
+ {
130
+ if (is_null($request)) {
131
+ throw new Innobyte_EmagMarketplace_Exception(
132
+ 'Invalid shipment request object.'
133
+ );
134
+ }
135
+ $this->_shipmentRequest = $request;
136
+ return $this;
137
+ }
138
+
139
+
140
+
141
+ /**
142
+ * Getter method for shipment request.
143
+ *
144
+ * @return Mage_Shipping_Model_Shipment_Request
145
+ */
146
+ public function getShipmentRequest()
147
+ {
148
+ if (is_null($this->_shipmentRequest)) {
149
+ $this->setShipmentRequest(
150
+ Mage::getModel('shipping/shipment_request')
151
+ );
152
+ }
153
+ return $this->_shipmentRequest;
154
+ }
155
+
156
+
157
+
158
+ /**
159
+ * Prepare data for #save() method.
160
+ *
161
+ * @return array Array with data to be sent on save awb.
162
+ * @throws Innobyte_EmagMarketplace_Exception If invalid info is found.
163
+ */
164
+ protected function _computeApiSaveData()
165
+ {
166
+ if (!$this->getShipmentRequest()->getOrderShipment()
167
+ || !$this->getShipmentRequest()->getOrderShipment()->getOrder()) {
168
+ throw new Innobyte_EmagMarketplace_Exception(
169
+ 'Invalid shipment request.'
170
+ );
171
+ }
172
+ $returnValueObj = new Varien_Object(
173
+ array_merge(
174
+ $this->_prepareRequestToShipmentBasicData(),
175
+ array('receiver' => $this->_prepareRequestToShipmentReceiverData()),
176
+ array('sender' => $this->_prepareRequestToShipmentSenderData())
177
+ )
178
+ );
179
+
180
+ // dispatch event in case customizations needs to be done by clients
181
+ Mage::dispatchEvent(
182
+ 'innobyte_emag_marketplace_compute_api_awb_data',
183
+ array(
184
+ 'awb_data' => $returnValueObj,
185
+ 'request' => $this->getShipmentRequest()
186
+ )
187
+ );
188
+
189
+ return $returnValueObj->toArray();
190
+ }
191
+
192
+
193
+
194
+ /**
195
+ * Prepare data other than receiver/sender keys.
196
+ *
197
+ * @return array
198
+ * @throws Innobyte_EmagMarketplace_Exception If invalid info is found.
199
+ */
200
+ protected function _prepareRequestToShipmentBasicData()
201
+ {
202
+ $request = $this->getShipmentRequest();
203
+ // perform some checks
204
+ $packages = $request->getPackages();
205
+ if (!is_array($packages) || !$packages) {
206
+ throw new Innobyte_EmagMarketplace_Exception(
207
+ 'No packages for request.'
208
+ );
209
+ }
210
+ $emagShippingExtra = $request->getEmagShippingExtra();
211
+ if (!is_array($emagShippingExtra)) {
212
+ throw new Innobyte_EmagMarketplace_Exception(
213
+ 'No eMAG shipping extra fields.'
214
+ );
215
+ }
216
+ if (!array_key_exists('cod', $emagShippingExtra)
217
+ || !is_numeric($emagShippingExtra['cod'])
218
+ || $emagShippingExtra['cod'] < 0
219
+ || $emagShippingExtra['cod'] > 999999999) {
220
+ throw new Innobyte_EmagMarketplace_Exception(
221
+ 'Invalid cash on delivery value.'
222
+ );
223
+ }
224
+ if (!$request->getOrderShipment()->getOrder()->getEmagOrderId()) {
225
+ throw new Innobyte_EmagMarketplace_Exception(
226
+ 'Invalid eMAG order id.'
227
+ );
228
+ }
229
+
230
+ // find out how many envelopes & parcels are
231
+ $envelopesNo = $parcelsNo = 0;
232
+ foreach ($request->getPackages() as $packageId => $package) {
233
+ if (Innobyte_EmagMarketplace_Model_Shipping_Carrier_Emag::CONTAINER_ENVELOPE == $package['params']['container']) {
234
+ $envelopesNo++;
235
+ } else {
236
+ $parcelsNo++;
237
+ }
238
+ }
239
+ // compute api required data
240
+ $data = array(
241
+ 'order_id' => intval(
242
+ $request->getOrderShipment()->getOrder()->getEmagOrderId()
243
+ ),
244
+ 'envelope_number' => $envelopesNo,
245
+ 'parcel_number' => $parcelsNo,
246
+ 'cod' => floatval($emagShippingExtra['cod']),
247
+ );
248
+ // compute api optional data
249
+ if (is_numeric($request->getPackageWeight())
250
+ && $request->getPackageWeight() >= 0
251
+ && $request->getPackageWeight() <= 99999) {
252
+ $data['weight'] = floatval($request->getPackageWeight());
253
+ }
254
+ if (array_key_exists('insured_value', $emagShippingExtra)
255
+ && is_numeric($emagShippingExtra['insured_value'])
256
+ && $emagShippingExtra['insured_value'] >= 0
257
+ && $emagShippingExtra['insured_value'] <= 999999999) {
258
+ $data['insured_value'] = floatval($emagShippingExtra['insured_value']);
259
+ }
260
+ if (array_key_exists('observation', $emagShippingExtra)
261
+ && strlen(trim($emagShippingExtra['observation']))) {
262
+ $data['observation'] = trim($emagShippingExtra['observation']);
263
+ }
264
+ $yesNoValues = array(0, 1);
265
+ if (array_key_exists('pickup_and_return', $emagShippingExtra)
266
+ && is_numeric($emagShippingExtra['pickup_and_return'])
267
+ && in_array($emagShippingExtra['pickup_and_return'], $yesNoValues)) {
268
+ $data['pickup_and_return'] = intval($emagShippingExtra['pickup_and_return']);
269
+ }
270
+ if (array_key_exists('saturday_delivery', $emagShippingExtra)
271
+ && is_numeric($emagShippingExtra['saturday_delivery'])
272
+ && in_array($emagShippingExtra['saturday_delivery'], $yesNoValues)) {
273
+ $data['saturday_delivery'] = intval($emagShippingExtra['saturday_delivery']);
274
+ }
275
+ if (array_key_exists('sameday_delivery', $emagShippingExtra)
276
+ && is_numeric($emagShippingExtra['sameday_delivery'])
277
+ && in_array($emagShippingExtra['sameday_delivery'], $yesNoValues)) {
278
+ $data['sameday_delivery'] = intval($emagShippingExtra['sameday_delivery']);
279
+ }
280
+ if (array_key_exists('open_on_receipt', $emagShippingExtra)
281
+ && is_numeric($emagShippingExtra['open_on_receipt'])
282
+ && in_array($emagShippingExtra['open_on_receipt'], $yesNoValues)) {
283
+ $data['open_on_receipt'] = intval($emagShippingExtra['open_on_receipt']);
284
+ }
285
+ $courierAccountId = Mage::helper('innobyte_emag_marketplace')
286
+ ->getCourierAccountId($request->getStoreId());
287
+ if (strlen($courierAccountId)) {
288
+ $data['courier_account_id'] = $courierAccountId;
289
+ }
290
+ return $data;
291
+ }
292
+
293
+
294
+
295
+ /**
296
+ * Prepare data for receiver key.
297
+ *
298
+ * @return array
299
+ * @throws Innobyte_EmagMarketplace_Exception If invalid info is found.
300
+ */
301
+ protected function _prepareRequestToShipmentReceiverData()
302
+ {
303
+ $request = $this->getShipmentRequest();
304
+ // perform some checks
305
+ $name = strlen($request->getRecipientContactCompanyName()) < 3 ?
306
+ $request->getRecipientContactPersonName() :
307
+ $request->getRecipientContactCompanyName();
308
+ if (strlen($name)< 3) {
309
+ throw new Innobyte_EmagMarketplace_Exception(
310
+ 'Receiver \'s name must have at least 3 letters.'
311
+ );
312
+ }
313
+ if (!strlen($request->getRecipientContactPersonName())) {
314
+ throw new Innobyte_EmagMarketplace_Exception(
315
+ 'Receiver \'s contact person name is empty.'
316
+ );
317
+ }
318
+ if (!preg_match('/^\+?[0-9]{8,11}$/', $request->getRecipientContactPhoneNumber())) {
319
+ throw new Innobyte_EmagMarketplace_Exception(
320
+ 'Receiver \'s contact phone must have between 8 and 11 digits and may contain a + sign at the beginning.'
321
+ );
322
+ }
323
+ $shippingAddr = $request->getOrderShipment()->getOrder()
324
+ ->getShippingAddress();
325
+ if ($shippingAddr->getEmagLocalityId() < 1) {
326
+ throw new Innobyte_EmagMarketplace_Exception(
327
+ 'Receiver \'s city id is empty.'
328
+ );
329
+ }
330
+ $street = str_replace("\n", '', $request->getRecipientAddressStreet());
331
+ if (strlen($street) < 3) {
332
+ throw new Innobyte_EmagMarketplace_Exception(
333
+ 'Receiver \'s street must have at least 3 letters.'
334
+ );
335
+ }
336
+ $legalEntityId = $request->getOrderShipment()->getOrder()
337
+ ->getEmagLegalEntity();
338
+ $data = array(
339
+ 'name' => $name,
340
+ 'contact' => $request->getRecipientContactPersonName(),
341
+ 'phone1' => $request->getRecipientContactPhoneNumber(),
342
+ 'legal_entity' => intval((bool)($legalEntityId)),
343
+ 'locality_id' => intval($shippingAddr->getEmagLocalityId()),
344
+ 'street' => $street,
345
+ );
346
+ if (preg_match('/^\+?[0-9]{8,11}$/', $shippingAddr->getEmagTelephone2())) {
347
+ $data['phone2'] = $shippingAddr->getEmagTelephone2();
348
+ }
349
+ if (strlen($request->getRecipientAddressPostalCode())) {
350
+ $data['zipcode'] = $request->getRecipientAddressPostalCode();
351
+ }
352
+
353
+ return $data;
354
+ }
355
+
356
+
357
+
358
+ /**
359
+ * Prepare data for receiver key.
360
+ *
361
+ * @return array
362
+ * @throws Innobyte_EmagMarketplace_Exception If invalid info is found.
363
+ */
364
+ protected function _prepareRequestToShipmentSenderData()
365
+ {
366
+ $request = $this->getShipmentRequest();
367
+ // perform some checks
368
+ $name = strlen($request->getShipperContactCompanyName()) < 3 ?
369
+ $request->getShipperContactPersonName() :
370
+ $request->getShipperContactCompanyName();
371
+ if (strlen($name)< 3) {
372
+ throw new Innobyte_EmagMarketplace_Exception(
373
+ 'Sender \'s name must have at least 3 letters.'
374
+ );
375
+ }
376
+ if (!strlen($request->getShipperContactPersonName())) {
377
+ throw new Innobyte_EmagMarketplace_Exception(
378
+ 'Sender \'s contact person name is empty.'
379
+ );
380
+ }
381
+ $helper = Mage::helper('innobyte_emag_marketplace');
382
+ if (!preg_match('/^\+?[0-9]{8,11}$/', $request->getShipperContactPhoneNumber())) {
383
+ $errMsg = 'Sender \'s contact phone must have between 8 and 11 digits and may contain a + sign at the beginning.';
384
+ if (Mage::getSingleton('admin/session')->isAllowed('system/config')) {
385
+ $errMsg .= ' <a href="%s" target="_blank">Edit</a> store phone info.';
386
+ $errMsg = $helper->__(
387
+ $errMsg,
388
+ Mage::helper('adminhtml')->getUrl(
389
+ 'adminhtml/system_config/edit',
390
+ array('section' => 'general')
391
+ )
392
+ );
393
+ }
394
+ throw new Innobyte_EmagMarketplace_Exception($errMsg);
395
+ }
396
+ $localityId = $helper->getShipOriginEmagLocalityId(
397
+ $request->getStoreId()
398
+ );
399
+ if ($localityId < 1) {
400
+ $errMsg = 'Sender \'s city id is empty.';
401
+ if (Mage::getSingleton('admin/session')->isAllowed('system/config')) {
402
+ $errMsg .= ' Please <a href="%s" target="_blank">choose</a> an eMAG city for origin shipping settings.';
403
+ $errMsg = $helper->__(
404
+ $errMsg,
405
+ Mage::helper('adminhtml')->getUrl(
406
+ 'adminhtml/system_config/edit',
407
+ array('section' => 'shipping')
408
+ )
409
+ );
410
+ }
411
+ throw new Innobyte_EmagMarketplace_Exception($errMsg);
412
+ }
413
+ $street = str_replace("\n", '', $request->getShipperAddressStreet());
414
+ if (strlen($street) < 3) {
415
+ $errMsg = 'Sender \'s street must have at least 3 letters.';
416
+ if (Mage::getSingleton('admin/session')->isAllowed('system/config')) {
417
+ $errMsg .= ' <a href="%s" target="_blank">Edit</a> street origin shipping settings.';
418
+ $errMsg = $helper->__(
419
+ $errMsg,
420
+ Mage::helper('adminhtml')->getUrl(
421
+ 'adminhtml/system_config/edit',
422
+ array('section' => 'shipping')
423
+ )
424
+ );
425
+ }
426
+ throw new Innobyte_EmagMarketplace_Exception($errMsg);
427
+ }
428
+ $data = array(
429
+ 'name' => $name,
430
+ 'contact' => $request->getShipperContactPersonName(),
431
+ 'phone1' => $request->getShipperContactPhoneNumber(),
432
+ 'locality_id' => $localityId,
433
+ 'street' => $street,
434
+ );
435
+ if (strlen($request->getShipperAddressPostalCode())) {
436
+ $data['zipcode'] = $request->getShipperAddressPostalCode();
437
+ }
438
+
439
+ return $data;
440
+ }
441
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Api/Category.php ADDED
@@ -0,0 +1,276 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Handles category api related operations.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Api_Category
11
+ extends Innobyte_EmagMarketplace_Model_Api_Abstract
12
+ {
13
+ /**
14
+ * Category resource name
15
+ */
16
+ const CATEGORY_RESOURCE_NAME = 'category';
17
+
18
+ /**
19
+ * @var Innobyte_EmagMarketplace_Model_Resource_Category_Collection
20
+ */
21
+ protected $_categoryCollection;
22
+
23
+ /**
24
+ * @var Innobyte_EmagMarketplace_Model_Resource_Category_Characteristic_Collection
25
+ */
26
+ protected $_categoryCharCollection;
27
+
28
+ /**
29
+ * @var Innobyte_EmagMarketplace_Model_Resource_Category_Familytype_Collection
30
+ */
31
+ protected $_categoryFtCollection;
32
+
33
+
34
+
35
+ /**
36
+ * Read CATEGORY resource
37
+ *
38
+ * @return Innobyte_EmagMarketplace_Model_Api_Response
39
+ * @throws Innobyte_EmagMarketplace_Exception
40
+ */
41
+ public function read()
42
+ {
43
+ parent::read();
44
+ return $this->_makeApiCall();
45
+ }
46
+
47
+
48
+
49
+ /**
50
+ * Save CATEGORY resource
51
+ *
52
+ * @throws Innobyte_EmagMarketplace_Exception
53
+ */
54
+ public function save()
55
+ {
56
+ throw new Innobyte_EmagMarketplace_Exception('Not implemented');
57
+ }
58
+
59
+
60
+
61
+ /**
62
+ * Count CATEGORY resource
63
+ *
64
+ * @return Innobyte_EmagMarketplace_Model_Api_Response
65
+ * @throws Innobyte_EmagMarketplace_Exception
66
+ */
67
+ public function count()
68
+ {
69
+ parent::count();
70
+ $apiResponse = $this->_makeApiCall();
71
+ $this->_setPaginationInfo($apiResponse);
72
+ return $apiResponse;
73
+ }
74
+
75
+
76
+
77
+ /**
78
+ * Acknowledge CATEGORY resource
79
+ *
80
+ * @throws Innobyte_EmagMarketplace_Exception
81
+ */
82
+ public function acknowledge()
83
+ {
84
+ throw new Innobyte_EmagMarketplace_Exception('Not implemented');
85
+ }
86
+
87
+
88
+
89
+ /**
90
+ * Get resource name
91
+ *
92
+ * @return string
93
+ */
94
+ public function getResourceName()
95
+ {
96
+ return self::CATEGORY_RESOURCE_NAME;
97
+ }
98
+
99
+
100
+
101
+ /**
102
+ * Map eMAG category from api to magento model.
103
+ *
104
+ * @param array $category Category from api.
105
+ * @return Innobyte_EmagMarketplace_Model_Category
106
+ */
107
+ public function importCategory(array $category)
108
+ {
109
+ $this->_getCategoryCollection()->clear()
110
+ ->getSelect()->reset(Zend_Db_Select::WHERE)
111
+ ->limit(1);
112
+ $emagCategoryId = isset($category['id']) ? intval($category['id']) : 0;
113
+ $returnValue = $this->_getCategoryCollection()
114
+ ->addStoreFilter($this->getStoreId())
115
+ ->addFieldToFilter('emag_id', $emagCategoryId)
116
+ ->getFirstItem();
117
+
118
+ $returnValue->setStoreId($this->getStoreId())
119
+ ->setEmagId($emagCategoryId);
120
+ if (isset($category['name']) && strlen($category['name'])) {
121
+ $returnValue->setName(strval($category['name']));
122
+ }
123
+ if (isset($category['characteristics'])
124
+ && is_array($category['characteristics'])) {
125
+ $returnValue->setImportedCharacteristics(
126
+ $this->_importCharacteristics(
127
+ $category['characteristics'],
128
+ $returnValue->getId()
129
+ )
130
+ );
131
+ }
132
+ if (isset($category['family_types'])
133
+ && is_array($category['family_types'])) {
134
+ $returnValue->setImportedFamilyTypes(
135
+ $this->_importFamilyTypes(
136
+ $category['family_types'],
137
+ $returnValue->getId()
138
+ )
139
+ );
140
+ }
141
+ return $returnValue;
142
+ }
143
+
144
+
145
+
146
+ /**
147
+ * Import characteristics data for a category.
148
+ *
149
+ * @param array $characteristics
150
+ * @param int $catId Magento eMAG category id.
151
+ * @return array With Innobyte_EmagMarketplace_Model_Category_Characteristic
152
+ * models; can be empty.
153
+ */
154
+ protected function _importCharacteristics(array $characteristics, $catId)
155
+ {
156
+ $returnValue = array();
157
+ if (!count($characteristics)) {
158
+ return $returnValue;
159
+ }
160
+ foreach ($characteristics as $char) {
161
+ $this->_getCategoryCharCollection()->clear()
162
+ ->getSelect()->reset(Zend_Db_Select::WHERE)
163
+ ->limit(1);
164
+ $emagId = isset($char['id']) ? intval($char['id']) : 0;
165
+ $model = $this->_getCategoryCharCollection()
166
+ ->addFieldToFilter('category_id', intval($catId))
167
+ ->addFieldToFilter('emag_id', $emagId)
168
+ ->getFirstItem();
169
+
170
+ $model->setEmagId($emagId);
171
+ if (isset($char['name'])
172
+ && strlen($char['name'])) {
173
+ $model->setName(strval($char['name']));
174
+ }
175
+ if (isset($char['display_order'])
176
+ && is_numeric($char['display_order'])) {
177
+ $model->setDisplayOrder(intval($char['display_order']));
178
+ }
179
+ $returnValue[] = $model;
180
+ }
181
+ return $returnValue;
182
+ }
183
+
184
+
185
+
186
+ /**
187
+ * Import familytypes data for a category.
188
+ *
189
+ * @param $category Innobyte_EmagMarketplace_Model_Category
190
+ * @param array $familyTypes
191
+ * @param int $catId Magento eMAG category id.
192
+ * @return array Contains Innobyte_EmagMarketplace_Model_Category_Familytype
193
+ * models; can be empty.
194
+ */
195
+ protected function _importFamilyTypes(array $familyTypes, $catId)
196
+ {
197
+ $returnValue = array();
198
+ if (!count($familyTypes)) {
199
+ return $returnValue;
200
+ }
201
+ foreach ($familyTypes as $familyType) {
202
+ $this->_getCategoryFtCollection()->clear()
203
+ ->getSelect()->reset(Zend_Db_Select::WHERE)
204
+ ->limit(1);
205
+ $emagId = isset($familyType['id']) ? intval($familyType['id']) : 0;
206
+ $model = $this->_getCategoryFtCollection()
207
+ ->addFieldToFilter('category_id', intval($catId))
208
+ ->addFieldToFilter('emag_id', $emagId)
209
+ ->getFirstItem();
210
+
211
+ $model->setEmagId($emagId);
212
+ if (isset($familyType['name']) && strlen($familyType['name'])) {
213
+ $model->setName(strval($familyType['name']));
214
+ }
215
+ if (isset($familyType['characteristics'])
216
+ && is_array($familyType['characteristics'])) {
217
+ $model->setImportedCharacteristics(
218
+ $familyType['characteristics']
219
+ );
220
+ }
221
+ $returnValue[] = $model;
222
+ }
223
+ return $returnValue;
224
+ }
225
+
226
+
227
+
228
+ /**
229
+ * Getter method for category collection property.
230
+ *
231
+ * @return Innobyte_EmagMarketplace_Model_Resource_Category_Collection
232
+ */
233
+ protected function _getCategoryCollection()
234
+ {
235
+ if (is_null($this->_categoryCollection)) {
236
+ $this->_categoryCollection = Mage::getResourceModel(
237
+ 'innobyte_emag_marketplace/category_collection'
238
+ );
239
+ }
240
+ return $this->_categoryCollection;
241
+ }
242
+
243
+
244
+
245
+ /**
246
+ * Getter method for category characteristics collection property.
247
+ *
248
+ * @return Innobyte_EmagMarketplace_Model_Resource_Category_Characteristic_Collection
249
+ */
250
+ protected function _getCategoryCharCollection()
251
+ {
252
+ if (is_null($this->_categoryCharCollection)) {
253
+ $this->_categoryCharCollection = Mage::getResourceModel(
254
+ 'innobyte_emag_marketplace/category_characteristic_collection'
255
+ );
256
+ }
257
+ return $this->_categoryCharCollection;
258
+ }
259
+
260
+
261
+
262
+ /**
263
+ * Getter method for category familytype collection property.
264
+ *
265
+ * @return Innobyte_EmagMarketplace_Model_Resource_Category_Familytype_Collection
266
+ */
267
+ protected function _getCategoryFtCollection()
268
+ {
269
+ if (is_null($this->_categoryFtCollection)) {
270
+ $this->_categoryFtCollection = Mage::getResourceModel(
271
+ 'innobyte_emag_marketplace/category_familytype_collection'
272
+ );
273
+ }
274
+ return $this->_categoryFtCollection;
275
+ }
276
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Api/Locality.php ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Handles locality api related operations.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Api_Locality
11
+ extends Innobyte_EmagMarketplace_Model_Api_Abstract
12
+ {
13
+ /**
14
+ * Locality resource name
15
+ */
16
+ const LOCALITY_RESOURCE_NAME = 'locality';
17
+
18
+
19
+ /**
20
+ * @var Innobyte_EmagMarketplace_Model_Resource_Locality_Collection
21
+ */
22
+ protected $_localityCollection;
23
+
24
+
25
+
26
+ /**
27
+ * Read LOCALITY resource
28
+ *
29
+ * @return Innobyte_EmagMarketplace_Model_Api_Response
30
+ * @throws Innobyte_EmagMarketplace_Exception
31
+ */
32
+ public function read()
33
+ {
34
+ parent::read();
35
+ return $this->_makeApiCall();
36
+ }
37
+
38
+
39
+
40
+ /**
41
+ * Save LOCALITY resource
42
+ *
43
+ * @throws Innobyte_EmagMarketplace_Exception
44
+ */
45
+ public function save()
46
+ {
47
+ throw new Innobyte_EmagMarketplace_Exception('Not implemented');
48
+ }
49
+
50
+
51
+
52
+ /**
53
+ * Count LOCALITY resource
54
+ *
55
+ * @return Innobyte_EmagMarketplace_Model_Api_Response
56
+ * @throws Innobyte_EmagMarketplace_Exception
57
+ */
58
+ public function count()
59
+ {
60
+ parent::count();
61
+ $apiResponse = $this->_makeApiCall();
62
+ $this->_setPaginationInfo($apiResponse);
63
+ return $apiResponse;
64
+ }
65
+
66
+
67
+
68
+ /**
69
+ * Acknowledge LOCALITY resource
70
+ *
71
+ * @throws Innobyte_EmagMarketplace_Exception
72
+ */
73
+ public function acknowledge()
74
+ {
75
+ throw new Innobyte_EmagMarketplace_Exception('Not implemented');
76
+ }
77
+
78
+
79
+
80
+ /**
81
+ * Get resource name
82
+ *
83
+ * @return string
84
+ */
85
+ public function getResourceName()
86
+ {
87
+ return self::LOCALITY_RESOURCE_NAME;
88
+ }
89
+
90
+
91
+
92
+ /**
93
+ * Map eMAG locality from api to magento model.
94
+ *
95
+ * @param array $locality Locality from api.
96
+ * @return Innobyte_EmagMarketplace_Model_Locality
97
+ */
98
+ public function importLocality(array $locality)
99
+ {
100
+ $this->_getLocalityCollection()->clear()
101
+ ->getSelect()->reset(Zend_Db_Select::WHERE)
102
+ ->limit(1);
103
+ $emagId = isset($locality['emag_id']) ? intval($locality['emag_id']) : 0;
104
+ $returnValue = $this->_getLocalityCollection()
105
+ ->addStoreFilter($this->getStoreId())
106
+ ->addFieldToFilter('emag_id', $emagId)
107
+ ->getFirstItem();
108
+
109
+ $returnValue->setStoreId($this->getStoreId())
110
+ ->setEmagId($emagId);
111
+ if (isset($locality['name']) && strlen($locality['name'])) {
112
+ $returnValue->setName(strval($locality['name']));
113
+ }
114
+ if (isset($locality['name_latin']) && strlen($locality['name_latin'])) {
115
+ $returnValue->setNameLatin(strval($locality['name_latin']));
116
+ }
117
+ if (isset($locality['region1']) && strlen($locality['region1'])) {
118
+ $returnValue->setRegion1(strval($locality['region1']));
119
+ }
120
+ if (isset($locality['region2']) && strlen($locality['region2'])) {
121
+ $returnValue->setRegion2(strval($locality['region2']));
122
+ }
123
+ if (isset($locality['region3']) && strlen($locality['region3'])) {
124
+ $returnValue->setRegion3(strval($locality['region3']));
125
+ }
126
+ if (isset($locality['region4']) && strlen($locality['region4'])) {
127
+ $returnValue->setRegion4(strval($locality['region4']));
128
+ }
129
+ if (isset($locality['region1_latin'])
130
+ && strlen($locality['region1_latin'])) {
131
+ $returnValue->setRegion1Latin(strval($locality['region1_latin']));
132
+ }
133
+ if (isset($locality['region2_latin'])
134
+ && strlen($locality['region2_latin'])) {
135
+ $returnValue->setRegion2Latin(strval($locality['region2_latin']));
136
+ }
137
+ if (isset($locality['region3_latin'])
138
+ && strlen($locality['region3_latin'])) {
139
+ $returnValue->setRegion3Latin(strval($locality['region3_latin']));
140
+ }
141
+ if (isset($locality['region4_latin'])
142
+ && strlen($locality['region4_latin'])) {
143
+ $returnValue->setRegion4Latin(strval($locality['region4_latin']));
144
+ }
145
+ if (isset($locality['geoid'])
146
+ && is_numeric($locality['geoid'])) {
147
+ $returnValue->setGeoid(intval($locality['geoid']));
148
+ }
149
+ if (isset($locality['modified'])
150
+ && strlen($locality['modified'])) {
151
+ $returnValue->setEmagModified(strval($locality['modified']));
152
+ }
153
+ return $returnValue;
154
+ }
155
+
156
+
157
+
158
+ /**
159
+ * Getter method for locality collection property.
160
+ *
161
+ * @return Innobyte_EmagMarketplace_Model_Resource_Locality_Collection
162
+ */
163
+ protected function _getLocalityCollection()
164
+ {
165
+ if (is_null($this->_localityCollection)) {
166
+ $this->_localityCollection = Mage::getResourceModel(
167
+ 'innobyte_emag_marketplace/locality_collection'
168
+ );
169
+ }
170
+ return $this->_localityCollection;
171
+ }
172
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Api/Order.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Api_Product
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Api_Order extends Innobyte_EmagMarketplace_Model_Api_Abstract
12
+ {
13
+
14
+ /**
15
+ * Order resource name
16
+ */
17
+ const ORDER_RESOURCE_NAME = 'order';
18
+
19
+ /**
20
+ * Read ORDER resource
21
+ *
22
+ * @return bool|mixed
23
+ */
24
+ public function read()
25
+ {
26
+ parent::read();
27
+
28
+ return $this->_makeApiCall();
29
+ }
30
+
31
+ /**
32
+ * Save ORDER resource
33
+ *
34
+ * @return bool|mixed
35
+ */
36
+ public function save()
37
+ {
38
+ parent::save();
39
+
40
+ return $this->_makeApiCall();
41
+ }
42
+
43
+ /**
44
+ * Count ORDER resource
45
+ *
46
+ * @return bool|mixed
47
+ */
48
+ public function count()
49
+ {
50
+ parent::count();
51
+
52
+ $response = $this->_makeApiCall();
53
+ $this->_setPaginationInfo($response);
54
+
55
+ return $response;
56
+ }
57
+
58
+ /**
59
+ * Acknowledge ORDER resource
60
+ *
61
+ * @return bool|mixed
62
+ */
63
+ public function acknowledge()
64
+ {
65
+ parent::acknowledge();
66
+
67
+ return $this->_makeApiCall();
68
+ }
69
+
70
+ /**
71
+ * Get resource name
72
+ *
73
+ * @return string
74
+ */
75
+ public function getResourceName()
76
+ {
77
+ return self::ORDER_RESOURCE_NAME;
78
+ }
79
+
80
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Api/Product.php ADDED
@@ -0,0 +1,596 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Handles product api related operations.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Api_Product
11
+ extends Innobyte_EmagMarketplace_Model_Api_Abstract
12
+ {
13
+ /**
14
+ * Product resource name
15
+ */
16
+ const PRODUCT_RESOURCE_NAME = 'product_offer';
17
+
18
+ /**
19
+ * Default wharehouse id.
20
+ */
21
+ const DEFAULT_WHAREHOUSE_ID = 1;
22
+
23
+ /**
24
+ * eMAG product model.
25
+ *
26
+ * @var Innobyte_EmagMarketplace_Model_Product
27
+ */
28
+ protected $_emagProduct;
29
+
30
+ /**
31
+ * Flag that indicates that whole product data should be sent.
32
+ *
33
+ * @var Innobyte_EmagMarketplace_Model_Product
34
+ */
35
+ protected $_sendProduct = true;
36
+
37
+
38
+
39
+ /**
40
+ * Read PRODUCT resource
41
+ *
42
+ * @throws Innobyte_EmagMarketplace_Exception
43
+ */
44
+ public function read()
45
+ {
46
+ throw new Innobyte_EmagMarketplace_Exception('Not implemented');
47
+ }
48
+
49
+
50
+
51
+ /**
52
+ * Save PRODUCT resource
53
+ * Set eMAG product previous to call this method with #setEmagProduct()
54
+ * Saves either whole product data or just offer data,
55
+ * by default saves whole product data.
56
+ * You can use #saveProduct() or #saveOffer() instead.
57
+ *
58
+ * @return Innobyte_EmagMarketplace_Model_Api_Response
59
+ * @throws Innobyte_EmagMarketplace_Exception
60
+ */
61
+ public function save()
62
+ {
63
+ parent::save();
64
+ if ($this->_sendProduct) {
65
+ $this->setData($this->_getProductSavingData());
66
+ } else {
67
+ $this->setData($this->_getOfferSavingData());
68
+ }
69
+ return $this->_makeApiCall();
70
+ }
71
+
72
+
73
+
74
+ /**
75
+ * Count PRODUCT resource
76
+ *
77
+ * @throws Innobyte_EmagMarketplace_Exception
78
+ */
79
+ public function count()
80
+ {
81
+ throw new Innobyte_EmagMarketplace_Exception('Not implemented');
82
+ }
83
+
84
+
85
+
86
+ /**
87
+ * Acknowledge PRODUCT resource
88
+ *
89
+ * @throws Innobyte_EmagMarketplace_Exception
90
+ */
91
+ public function acknowledge()
92
+ {
93
+ throw new Innobyte_EmagMarketplace_Exception('Not implemented');
94
+ }
95
+
96
+
97
+
98
+ /**
99
+ * Get resource name
100
+ *
101
+ * @return string
102
+ */
103
+ public function getResourceName()
104
+ {
105
+ return self::PRODUCT_RESOURCE_NAME;
106
+ }
107
+
108
+
109
+
110
+ /**
111
+ * Save whole product.
112
+ *
113
+ * @return Innobyte_EmagMarketplace_Model_Api_Response
114
+ * @throws Innobyte_EmagMarketplace_Exception
115
+ */
116
+ public function saveProduct()
117
+ {
118
+ $this->_sendProduct = true;
119
+ return $this->save();
120
+ }
121
+
122
+
123
+
124
+ /**
125
+ * Save product offer.
126
+ *
127
+ * @return Innobyte_EmagMarketplace_Model_Api_Response
128
+ * @throws Innobyte_EmagMarketplace_Exception
129
+ */
130
+ public function saveOffer()
131
+ {
132
+ $this->_sendProduct = false;
133
+ return $this->save();
134
+ }
135
+
136
+
137
+
138
+ /**
139
+ * Handle product saving.
140
+ *
141
+ * @return array
142
+ * @throws Innobyte_EmagMarketplace_Exception
143
+ */
144
+ public function _getProductSavingData()
145
+ {
146
+ $returnValue = array();
147
+
148
+ // for configurable send all child products
149
+ $mageProduct = $this->getEmagProduct()->getMagentoProduct();
150
+ if (!is_null($mageProduct) && $mageProduct->isConfigurable()) {
151
+ $childIds = $mageProduct->getTypeInstance()->getUsedProductIds();
152
+ if (empty($childIds)) {
153
+ throw new Innobyte_EmagMarketplace_Exception(
154
+ 'No associated product(s) found.'
155
+ );
156
+ }
157
+ foreach ($childIds as $childId) {
158
+ $childEmagProduct = Mage::getModel(
159
+ 'innobyte_emag_marketplace/product'
160
+ )->loadByProdIdAndStore(
161
+ $childId,
162
+ $this->getEmagProduct()->getStoreId()
163
+ );
164
+ try {
165
+ if ($childEmagProduct->getId()
166
+ && $childEmagProduct->getCategoryId() != $this->getEmagProduct()->getCategoryId()) {
167
+ throw new Innobyte_EmagMarketplace_Exception(
168
+ 'Associated product \'s category does not match parent configurable product \'s category'
169
+ );
170
+ }
171
+ $returnValue[] = $this->_computeApiProductData(
172
+ $childEmagProduct,
173
+ $this->getEmagProduct()
174
+ );
175
+ } catch (Innobyte_EmagMarketplace_Exception $iemEx) {
176
+ throw new Innobyte_EmagMarketplace_Exception(
177
+ Mage::helper('innobyte_emag_marketplace')->__(
178
+ 'Associated product #%d error: ',
179
+ $childId
180
+ )
181
+ . Mage::helper('innobyte_emag_marketplace')->__(
182
+ $iemEx->getMessage()
183
+ )
184
+ );
185
+ }
186
+ }
187
+ } else {
188
+ $returnValue[] = $this->_computeApiProductData(
189
+ $this->getEmagProduct()
190
+ );
191
+ }
192
+ return $returnValue;
193
+ }
194
+
195
+
196
+ /**
197
+ * Handle offer saving.
198
+ *
199
+ * @return array
200
+ * @throws Innobyte_EmagMarketplace_Exception
201
+ */
202
+ public function _getOfferSavingData()
203
+ {
204
+ $returnValue = array();
205
+
206
+ // for configurable send all child products
207
+ $mageProduct = $this->getEmagProduct()->getMagentoProduct();
208
+ if (!is_null($mageProduct) && $mageProduct->isConfigurable()) {
209
+ $childIds = $mageProduct->getTypeInstance()->getUsedProductIds();
210
+ if (empty($childIds)) {
211
+ throw new Innobyte_EmagMarketplace_Exception(
212
+ 'No associated product(s) found.'
213
+ );
214
+ }
215
+ foreach ($childIds as $childId) {
216
+ $childEmagProduct = Mage::getModel(
217
+ 'innobyte_emag_marketplace/product'
218
+ )->loadByProdIdAndStore(
219
+ $childId,
220
+ $this->getEmagProduct()->getStoreId()
221
+ );
222
+ try {
223
+ if ($childEmagProduct->getId()
224
+ && $childEmagProduct->getCategoryId() != $this->getEmagProduct()->getCategoryId()) {
225
+ throw new Innobyte_EmagMarketplace_Exception(
226
+ 'Associated product \'s category does not match parent configurable product \'s category'
227
+ );
228
+ }
229
+
230
+ $returnValue[] = $this->_computeApiOfferData(
231
+ $childEmagProduct
232
+ );
233
+ } catch (Innobyte_EmagMarketplace_Exception $iemEx) {
234
+ throw new Innobyte_EmagMarketplace_Exception(
235
+ Mage::helper('innobyte_emag_marketplace')->__(
236
+ 'Associated product #%d error: ',
237
+ $childId
238
+ )
239
+ . Mage::helper('innobyte_emag_marketplace')->__(
240
+ $iemEx->getMessage()
241
+ )
242
+ );
243
+ }
244
+ }
245
+ } else {
246
+ $returnValue[] = $this->_computeApiOfferData(
247
+ $this->getEmagProduct()
248
+ );
249
+ }
250
+ return $returnValue;
251
+ }
252
+
253
+
254
+
255
+ /**
256
+ * Compute api data to be sent to api (product description & offer).
257
+ *
258
+ * @param Innobyte_EmagMarketplace_Model_Product $emagProduct
259
+ * @param Innobyte_EmagMarketplace_Model_Product $parentProduct
260
+ * @return array Array to be sent to eMAG with product desc & offer data.
261
+ * @throws Innobyte_EmagMarketplace_Exception If invalid values are found.
262
+ */
263
+ protected function _computeApiProductData(
264
+ Innobyte_EmagMarketplace_Model_Product $emagProduct,
265
+ Innobyte_EmagMarketplace_Model_Product $parentProduct = null
266
+ )
267
+ {
268
+ if (!$emagProduct->getId()) {
269
+ if ($emagProduct->getProductId() && $emagProduct->getStoreId()) {
270
+ $emagProduct->loadByProdIdAndStore(
271
+ $emagProduct->getProductId(),
272
+ $emagProduct->getStoreId()
273
+ );
274
+ }
275
+ if (!$emagProduct->getId()) {
276
+ throw new Innobyte_EmagMarketplace_Exception(
277
+ 'No product eMAG data set.'
278
+ );
279
+ }
280
+ }
281
+
282
+ $mageProduct = $emagProduct->getMagentoProduct();
283
+ $returnValue = array(
284
+ 'id' => (int) $mageProduct->getId(),
285
+ );
286
+ if ($emagProduct->getPartNumberKey()) {
287
+ $returnValue['part_number_key'] = $emagProduct->getPartNumberKey();
288
+ } else {
289
+ if (!$emagProduct->getName()) {
290
+ throw new Innobyte_EmagMarketplace_Exception(
291
+ 'No eMAG product name.'
292
+ );
293
+ }
294
+ $returnValue['name'] = $emagProduct->getName();
295
+ if (!$emagProduct->getBrand()) {
296
+ throw new Innobyte_EmagMarketplace_Exception(
297
+ 'No eMAG product brand.'
298
+ );
299
+ }
300
+ $returnValue['brand'] = $emagProduct->getBrand();
301
+ if (!$emagProduct->getCategoryId()
302
+ || !$emagProduct->getCategory()) {
303
+ throw new Innobyte_EmagMarketplace_Exception(
304
+ 'No eMAG category id.'
305
+ );
306
+ }
307
+ $returnValue['category_id'] = $emagProduct->getCategory()->getEmagId();
308
+ if (!$mageProduct->getSku()) {
309
+ throw new Innobyte_EmagMarketplace_Exception(
310
+ 'No product sku.'
311
+ );
312
+ }
313
+ $characteristics = array();
314
+ foreach ($emagProduct->getCategory()->getCharacteristics() as $char) {
315
+ $key = 'category_characteristic' . $char->getId();
316
+ if (!array_key_exists($key, $emagProduct->getData())
317
+ || !strlen($emagProduct->getData($key))) {
318
+ throw new Innobyte_EmagMarketplace_Exception(
319
+ Mage::helper('innobyte_emag_marketplace')->__(
320
+ 'No category characteristic "%s" value found.',
321
+ $char->getName()
322
+ )
323
+ );
324
+ }
325
+ $characteristics[] = array(
326
+ 'id' => $char->getEmagId(),
327
+ 'value' => strval($emagProduct->getData($key)),
328
+ );
329
+ }
330
+ $returnValue['characteristics'] = $characteristics;
331
+
332
+ if (!is_null($parentProduct)) {
333
+ if ($parentProduct->getFamilyTypeId() < 1
334
+ || $parentProduct->getFamilyType()->getEmagId() < 1) {
335
+ throw new Innobyte_EmagMarketplace_Exception(
336
+ 'No family type found.'
337
+ );
338
+ }
339
+ $returnValue['family'] = array(
340
+ 'id' => (int) $parentProduct->getId(),
341
+ 'name' => $parentProduct->getName(),
342
+ 'family_type_id' => (int) $parentProduct->getFamilyType()
343
+ ->getEmagId()
344
+ );
345
+ }
346
+
347
+ $returnValue['part_number'] = $mageProduct->getSku();
348
+ }
349
+ if (!$mageProduct->getProductUrl()) {
350
+ throw new Innobyte_EmagMarketplace_Exception(
351
+ 'No product url.'
352
+ );
353
+ }
354
+ $returnValue['url'] = $mageProduct->getProductUrl();
355
+ if ($mageProduct->getWeight()) {
356
+ $returnValue['weight'] = (float) $mageProduct->getWeight();
357
+ }
358
+ if ($emagProduct->getDescription()) {
359
+ $returnValue['description'] = $emagProduct->getDescription();
360
+ }
361
+ if (is_array($emagProduct->getBarcodes())
362
+ && count($emagProduct->getBarcodes())) {
363
+ $returnValue['barcode'] = $emagProduct->getBarcodes();
364
+ }
365
+ // TODO uncomment bellow lines and remove hardcoded product when development is done.
366
+ // $images = array();
367
+ // $imageHelper = Mage::helper('catalog/image');
368
+ // if ($mageProduct->getImage()
369
+ // && $mageProduct->getImage() != 'no_selection')
370
+ // {
371
+ // $images[] = array(
372
+ // 'display_type' => Innobyte_EmagMarketplace_Model_Product::IMAGE_DISPLAY_TYPE_MAIN,
373
+ // 'url' => (string) $imageHelper->init($mageProduct, 'image'),
374
+ // );
375
+ // }
376
+ // if (count($mageProduct->getMediaGalleryImages())) {
377
+ // foreach ($mageProduct->getMediaGalleryImages() as $image) {
378
+ // $images[] = array(
379
+ // 'display_type' => Innobyte_EmagMarketplace_Model_Product::IMAGE_DISPLAY_TYPE_SECONDARY,
380
+ // 'url' => (string) $imageHelper->init(
381
+ // $mageProduct,
382
+ // 'image',
383
+ // $image->getFile()
384
+ // ),
385
+ // );
386
+ // }
387
+ // }
388
+ $images = array(
389
+ array(
390
+ 'display_type' => Innobyte_EmagMarketplace_Model_Product::IMAGE_DISPLAY_TYPE_MAIN,
391
+ 'url' => 'http://s1emagst.akamaized.net/layout/ro/images/logo//19/28252.png',
392
+ )
393
+ );
394
+ if (count($images)) {
395
+ $returnValue['images'] = $images;
396
+ }
397
+
398
+ $returnValue = array_merge(
399
+ $returnValue,
400
+ $this->_computeApiOfferData($emagProduct)
401
+ );
402
+
403
+ // dispatch event in case customizations needs to be done by clients
404
+ $returnValueObj = new Varien_Object($returnValue);
405
+ Mage::dispatchEvent(
406
+ 'innobyte_emag_marketplace_compute_api_product_data',
407
+ array(
408
+ 'emag_product' => $emagProduct,
409
+ 'parent_product' => $parentProduct,
410
+ 'offer_data' => $returnValueObj,
411
+ )
412
+ );
413
+
414
+ return $returnValueObj->toArray();
415
+ }
416
+
417
+
418
+
419
+ /**
420
+ * Compute offer api data to be sent to api.
421
+ *
422
+ * @param Innobyte_EmagMarketplace_Model_Product $emagProduct
423
+ * @return array Array to be sent to eMAG with product offer data.
424
+ * @throws Innobyte_EmagMarketplace_Exception If invalid values are found.
425
+ */
426
+ protected function _computeApiOfferData(
427
+ Innobyte_EmagMarketplace_Model_Product $emagProduct
428
+ )
429
+ {
430
+ if (!$emagProduct->getId()) {
431
+ if ($emagProduct->getProductId() && $emagProduct->getStoreId()) {
432
+ $emagProduct->loadByProdIdAndStore(
433
+ $emagProduct->getProductId(),
434
+ $emagProduct->getStoreId()
435
+ );
436
+ }
437
+ if (!$emagProduct->getId()) {
438
+ throw new Innobyte_EmagMarketplace_Exception(
439
+ 'No product eMAG data set.'
440
+ );
441
+ }
442
+ }
443
+ $mageProduct = $emagProduct->getMagentoProduct();
444
+ $commissionType = Innobyte_EmagMarketplace_Model_Source_CommissionTypes::getEmagCommissionType(
445
+ $emagProduct->getCommissionType()
446
+ );
447
+ if (!$commissionType) {
448
+ throw new Innobyte_EmagMarketplace_Exception(
449
+ 'No eMAG product commission type.'
450
+ );
451
+ }
452
+ if (!$mageProduct->getStockItem()) {
453
+ throw new Innobyte_EmagMarketplace_Exception(
454
+ 'No product stock data.'
455
+ );
456
+ }
457
+ $returnValue = array(
458
+ 'id' => intval($mageProduct->getId()),
459
+ 'status' => intval($emagProduct->getStatus()),
460
+ 'vat_id' => intval($emagProduct->getVat()->getEmagId()),
461
+ 'handling_time' => array(
462
+ array(
463
+ 'warehouse_id' => self::DEFAULT_WHAREHOUSE_ID,
464
+ 'value' => intval($emagProduct->getHandlingTime()),
465
+ ),
466
+ ),
467
+ 'commission' => array(
468
+ array(
469
+ 'type' => $commissionType,
470
+ 'value' => $emagProduct->getCommissionValue(),
471
+ ),
472
+ ),
473
+ 'warranty' => intval($emagProduct->getWarranty()),
474
+ );
475
+
476
+ $helper = Mage::helper('innobyte_emag_marketplace');
477
+
478
+ // attach availability info
479
+ $returnValue['availability'] = array(
480
+ array('warehouse_id' => self::DEFAULT_WHAREHOUSE_ID)
481
+ );
482
+ $stockQty = $mageProduct->getStockItem()->getQty() * 1;
483
+ if ($mageProduct->isAvailable()) {
484
+ $returnValue['availability'][0]['id'] = Innobyte_EmagMarketplace_Model_Product::AVAILABILITY_IN_STOCK;
485
+ if ($helper->isLimitedStockEnabled($emagProduct->getStoreId())
486
+ && $stockQty <= $helper->getLimitedStockLimit($emagProduct->getStoreId())) {
487
+ $returnValue['availability'][0]['id'] = Innobyte_EmagMarketplace_Model_Product::AVAILABILITY_LIMITED_STOCK;
488
+ }
489
+ } else {
490
+ $returnValue['availability'][0]['id'] = Innobyte_EmagMarketplace_Model_Product::AVAILABILITY_OUT_OF_STOCK;
491
+ }
492
+
493
+ // attach stock info
494
+ if ($helper->sendStockQty($emagProduct->getStoreId())
495
+ && $stockQty >= 0 && $stockQty < 65535) {
496
+ $returnValue['stock'] = array(
497
+ array(
498
+ 'warehouse_id' => self::DEFAULT_WHAREHOUSE_ID,
499
+ 'value' => $stockQty,
500
+ ),
501
+ );
502
+ }
503
+
504
+ // attach offer start date
505
+ if ($emagProduct->getStartDate()) {
506
+ try {
507
+ $zendDate = new Zend_Date(
508
+ $emagProduct->getStartDate(),
509
+ Varien_Date::DATE_INTERNAL_FORMAT
510
+ );
511
+ } catch (Zend_Date_Exception $zdex) {
512
+ throw new Innobyte_EmagMarketplace_Exception(
513
+ 'Invalid eMAG offer start date.'
514
+ );
515
+ }
516
+ $now = new Zend_Date(null, Varien_Date::DATE_INTERNAL_FORMAT);
517
+ if (!$zendDate->isLater($now)
518
+ || !$zendDate->isEarlier($now->addDay(61))) {
519
+ throw new Innobyte_EmagMarketplace_Exception(
520
+ 'Offer start date can be as far as 60 days in the future and cannot be earlier than tomorrow.'
521
+ );
522
+ }
523
+ $returnValue['start_date'] = $zendDate->toString(Varien_Date::DATE_INTERNAL_FORMAT);
524
+ }
525
+
526
+ // attach prices
527
+ $taxHelper = Mage::helper('tax');
528
+ $price = $taxHelper->getPrice(
529
+ $mageProduct,
530
+ $mageProduct->getPrice(),
531
+ false
532
+ );
533
+ $finalPrice = $taxHelper->getPrice(
534
+ $mageProduct,
535
+ $mageProduct->getFinalPrice(),
536
+ false
537
+ );
538
+ $store = $mageProduct->getStore();
539
+ $price = $store->roundPrice($store->convertPrice($price, 0, 0));
540
+ $finalPrice = $store->roundPrice($store->convertPrice($finalPrice, 0, 0));
541
+ if ($finalPrice < $price) {
542
+ $returnValue['sale_price'] = $finalPrice;
543
+ $returnValue['recommended_price'] = $price;
544
+ } else {
545
+ $returnValue['sale_price'] = $finalPrice;
546
+ }
547
+
548
+ // dispatch event in case customizations needs to be done by clients
549
+ $returnValueObj = new Varien_Object($returnValue);
550
+ Mage::dispatchEvent(
551
+ 'innobyte_emag_marketplace_compute_api_offer_data',
552
+ array(
553
+ 'emag_product' => $emagProduct,
554
+ 'offer_data' => $returnValueObj,
555
+ )
556
+ );
557
+
558
+ return $returnValueObj->toArray();
559
+ }
560
+
561
+
562
+
563
+ /**
564
+ * Setter method for emag product.
565
+ *
566
+ * @param Innobyte_EmagMarketplace_Model_Product $product
567
+ * @return Innobyte_EmagMarketplace_Model_Api_Product
568
+ * @throws Innobyte_EmagMarketplace_Exception If null param is provided.
569
+ */
570
+ public function setEmagProduct(Innobyte_EmagMarketplace_Model_Product $product)
571
+ {
572
+ if (is_null($product)) {
573
+ throw new Innobyte_EmagMarketplace_Exception(
574
+ 'Invalid product model.'
575
+ );
576
+ }
577
+ $this->_emagProduct = $product;
578
+ return $this;
579
+ }
580
+
581
+
582
+
583
+ /**
584
+ * Getter method for emag product.
585
+ *
586
+ * @return Innobyte_EmagMarketplace_Model_Product
587
+ */
588
+ public function getEmagProduct()
589
+ {
590
+ if (is_null($this->_emagProduct)) {
591
+ $model = Mage::getModel('innobyte_emag_marketplace/product');
592
+ $this->setEmagProduct($model);
593
+ }
594
+ return $this->_emagProduct;
595
+ }
596
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Api/Response.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG api respose.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Api_Response
11
+ {
12
+ /**
13
+ * Flag that indicates if response was erratic or not.
14
+ *
15
+ * @var bool
16
+ */
17
+ protected $_isError;
18
+
19
+ /**
20
+ * API Response Messages.
21
+ *
22
+ * @var array
23
+ */
24
+ protected $_messages;
25
+
26
+ /**
27
+ * API Response Results.
28
+ *
29
+ * @var array|int
30
+ */
31
+ protected $_results;
32
+
33
+
34
+
35
+ /**
36
+ * Constructor. initializes sttuffs.
37
+ *
38
+ * @param array $apiResponse Api response.
39
+ *
40
+ * @throws Innobyte_EmagMarketplace_Exception
41
+ * If invalid api response format is provided.
42
+ */
43
+ public function __construct(array $apiResponse)
44
+ {
45
+ if (!array_key_exists('isError', $apiResponse)) {
46
+ throw new Innobyte_EmagMarketplace_Exception(
47
+ 'Invalid api response format. "isError" is missing.'
48
+ );
49
+ }
50
+ if (!array_key_exists('messages', $apiResponse)) {
51
+ throw new Innobyte_EmagMarketplace_Exception(
52
+ 'Invalid api response format. "messages" is missing.'
53
+ );
54
+ }
55
+ if (!is_array($apiResponse['messages'])) {
56
+ throw new Innobyte_EmagMarketplace_Exception(
57
+ 'Invalid api response format. "messages" has invalid format.'
58
+ );
59
+ }
60
+ if (!array_key_exists('results', $apiResponse)) {
61
+ throw new Innobyte_EmagMarketplace_Exception(
62
+ 'Invalid api response format. "results" is missing.'
63
+ );
64
+ }
65
+ if (!is_array($apiResponse['results'])
66
+ && !is_numeric($apiResponse['results'])) {
67
+ throw new Innobyte_EmagMarketplace_Exception(
68
+ 'Invalid api response format. "results" has invalid format.'
69
+ );
70
+ }
71
+ $this->_isError = (bool)$apiResponse['isError'];
72
+ $this->_messages = $apiResponse['messages'];
73
+ $this->_results = $apiResponse['results'];
74
+ }
75
+
76
+
77
+ /**
78
+ * Getter method for messages property.
79
+ *
80
+ * @return array
81
+ */
82
+ public function getMessages()
83
+ {
84
+ return $this->_messages;
85
+ }
86
+
87
+
88
+ /**
89
+ * Getter method for results property.
90
+ * On 'order' related requests this maybe numeric, otherwise array.
91
+ *
92
+ * @return array|int
93
+ */
94
+ public function getResults()
95
+ {
96
+ return $this->_results;
97
+ }
98
+
99
+
100
+ /**
101
+ * Getter method for isError flag.
102
+ *
103
+ * @return boolean
104
+ */
105
+ public function isError()
106
+ {
107
+ return $this->_isError;
108
+ }
109
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Api/Vat.php ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Handles vat api related operations.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Api_Vat
11
+ extends Innobyte_EmagMarketplace_Model_Api_Abstract
12
+ {
13
+ /**
14
+ * VAT resource name
15
+ */
16
+ const VAT_RESOURCE_NAME = 'vat';
17
+
18
+ /**
19
+ * @var Innobyte_EmagMarketplace_Model_Resource_Vat_Collection
20
+ */
21
+ protected $_vatCollection;
22
+
23
+
24
+
25
+ /**
26
+ * Read VAT resource
27
+ *
28
+ * @return Innobyte_EmagMarketplace_Model_Api_Response
29
+ * @throws Innobyte_EmagMarketplace_Exception
30
+ */
31
+ public function read()
32
+ {
33
+ parent::read();
34
+ return $this->_makeApiCall();
35
+ }
36
+
37
+
38
+
39
+ /**
40
+ * Save VAT resource
41
+ *
42
+ * @throws Innobyte_EmagMarketplace_Exception
43
+ */
44
+ public function save()
45
+ {
46
+ throw new Innobyte_EmagMarketplace_Exception('Not implemented');
47
+ }
48
+
49
+
50
+
51
+ /**
52
+ * Count VAT resource
53
+ *
54
+ * @throws Innobyte_EmagMarketplace_Exception
55
+ */
56
+ public function count()
57
+ {
58
+ throw new Innobyte_EmagMarketplace_Exception('Not implemented');
59
+ }
60
+
61
+
62
+
63
+ /**
64
+ * Acknowledge VAT resource
65
+ *
66
+ * @throws Innobyte_EmagMarketplace_Exception
67
+ */
68
+ public function acknowledge()
69
+ {
70
+ throw new Innobyte_EmagMarketplace_Exception('Not implemented');
71
+ }
72
+
73
+
74
+
75
+ /**
76
+ * Get resource name
77
+ *
78
+ * @return string
79
+ */
80
+ public function getResourceName()
81
+ {
82
+ return self::VAT_RESOURCE_NAME;
83
+ }
84
+
85
+
86
+ /**
87
+ * Map eMAG vat from api to magento model.
88
+ *
89
+ * @param array $vat VAT from api.
90
+ * @return Innobyte_EmagMarketplace_Model_Vat
91
+ */
92
+ public function importEmagData(array $vat)
93
+ {
94
+ if (array_key_exists('vat_id', $vat)
95
+ && is_numeric($vat['vat_id'])) {
96
+ $this->setEmagId(intval($vat['vat_id']));
97
+ }
98
+ if (array_key_exists('vat_rate', $vat)
99
+ && is_numeric($vat['vat_rate'])) {
100
+ $this->setRate(floatval($vat['vat_rate']));
101
+ }
102
+ return $this;
103
+ }
104
+
105
+
106
+
107
+ /**
108
+ * Map eMAG VAT from api to magento model.
109
+ *
110
+ * @param array $vat VAT from api.
111
+ * @return Innobyte_EmagMarketplace_Model_Vat
112
+ */
113
+ public function importVat(array $vat)
114
+ {
115
+ $this->_getVatCollection()->clear()
116
+ ->getSelect()->reset(Zend_Db_Select::WHERE)
117
+ ->limit(1);
118
+ $emagVatId = isset($vat['vat_id']) ? intval($vat['vat_id']) : 0;
119
+ $returnValue = $this->_getVatCollection()
120
+ ->addStoreFilter($this->getStoreId())
121
+ ->addFieldToFilter('emag_id', $emagVatId)
122
+ ->getFirstItem();
123
+
124
+ $returnValue->setStoreId($this->getStoreId())
125
+ ->setEmagId($emagVatId);
126
+ if (isset($vat['vat_rate']) && is_numeric($vat['vat_rate'])) {
127
+ $returnValue->setRate(floatval($vat['vat_rate']));
128
+ }
129
+ return $returnValue;
130
+ }
131
+
132
+
133
+
134
+ /**
135
+ * Getter method for vat collection property.
136
+ *
137
+ * @return Innobyte_EmagMarketplace_Model_Resource_Vat_Collection
138
+ */
139
+ protected function _getVatCollection()
140
+ {
141
+ if (is_null($this->_vatCollection)) {
142
+ $this->_vatCollection = Mage::getResourceModel(
143
+ 'innobyte_emag_marketplace/vat_collection'
144
+ );
145
+ }
146
+ return $this->_vatCollection;
147
+ }
148
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Catalog/Product/Observer.php ADDED
@@ -0,0 +1,448 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Observer that handles product related events.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Catalog_Product_Observer
11
+ {
12
+ /**
13
+ * Helper object.
14
+ *
15
+ * @var Innobyte_EmagMarketplace_Helper_Data
16
+ */
17
+ protected $_helper;
18
+
19
+
20
+
21
+ /**
22
+ * Constructor; initializes stuffs.
23
+ */
24
+ public function __construct()
25
+ {
26
+ $this->_helper = Mage::helper('innobyte_emag_marketplace');
27
+ }
28
+
29
+
30
+
31
+ /**
32
+ * Getter method for helper property.
33
+ *
34
+ * @return Innobyte_EmagMarketplace_Helper_Data
35
+ */
36
+ protected function _getHelper()
37
+ {
38
+ return $this->_helper;
39
+ }
40
+
41
+
42
+
43
+ /**
44
+ * Saves product emag data.
45
+ * Triggered on catalog_product_save_after event.
46
+ *
47
+ * @param Varien_Event_Observer $observer
48
+ * @return Innobyte_EmagMarketplace_Model_Catalog_Product_Observer
49
+ * @throws Mage_Core_Exception
50
+ */
51
+ public function saveProductEmagData(Varien_Event_Observer $observer)
52
+ {
53
+ $storeId = $this->_getHelper()->getCurrStoreId();
54
+ $product = Mage::getModel('catalog/product')->setStoreId($storeId)
55
+ ->load($observer->getEvent()->getProduct()->getId());
56
+ if (!$this->_getHelper()->isProductActionValid($product)
57
+ || !Mage::app()->getRequest()->isPost()) {
58
+ return $this;
59
+ }
60
+
61
+ $data = Mage::app()->getRequest()->getPost('product', array());
62
+ if (!array_key_exists('inno_emag_mktp', $data)
63
+ || !is_array($data['inno_emag_mktp'])) {
64
+ return $this;
65
+ }
66
+
67
+ $emagData = $data['inno_emag_mktp'];
68
+ $emagProduct = Mage::getModel('innobyte_emag_marketplace/product')
69
+ ->loadByProdIdAndStore($product->getId(), $storeId);
70
+ try {
71
+ $this->_checkFilterEmagProductData($emagData, $product);
72
+ $emagProduct->addData($emagData)
73
+ ->setProductId($product->getId())
74
+ ->setStoreId($storeId);
75
+ // save data also on non-filled associated products if config prod
76
+ if ($product->isConfigurable()) {
77
+ $childIds = $product->getTypeInstance()->getUsedProductIds();
78
+ foreach ($childIds as $childId) {
79
+ $childEmagProduct = Mage::getModel(
80
+ 'innobyte_emag_marketplace/product'
81
+ )->loadByProdIdAndStore(
82
+ $childId,
83
+ $storeId
84
+ );
85
+ if (!$childEmagProduct->getId()) {
86
+ $childEmagProduct->addData($emagData)
87
+ ->unsFamilyTypeId()
88
+ ->setProductId($childId)
89
+ ->setStoreId($storeId);
90
+ $emagProduct->addRelatedObject($childEmagProduct);
91
+ }
92
+ }
93
+ }
94
+ $emagProduct->save();
95
+ } catch (Mage_Core_Exception $ex) {
96
+ // set data in session to repopulate form if error occurred
97
+ Mage::getSingleton('adminhtml/session')->setData(
98
+ 'inno_emag_mktp_data',
99
+ $emagData
100
+ );
101
+ throw $ex;
102
+ }
103
+
104
+ return $this;
105
+ }
106
+
107
+
108
+
109
+ /**
110
+ * Check / filter emag product form data.
111
+ *
112
+ * @param array $emagData Product post data.
113
+ * @param Mage_Catalog_Model_Product $product Magento product.
114
+ * @throws Mage_Core_Exception
115
+ */
116
+ protected function _checkFilterEmagProductData(
117
+ &$emagData,
118
+ Mage_Catalog_Model_Product $product
119
+ )
120
+ {
121
+ $storeId = $this->_getHelper()->getCurrStoreId();
122
+
123
+ if (is_null($product) || !$product->getId()) {
124
+ Mage::throwException($this->_getHelper()->__('Invalid product id.'));
125
+ }
126
+
127
+ if (array_key_exists('part_number_key', $emagData)) {
128
+ $emagData['part_number_key'] = trim($emagData['part_number_key']);
129
+ if (empty($emagData['part_number_key'])) {
130
+ $emagData['part_number_key'] = null;
131
+ }
132
+ } else {
133
+ $emagData['part_number_key'] = null;
134
+ }
135
+
136
+ if (array_key_exists('name', $emagData)) {
137
+ $emagData['name'] = trim($emagData['name']);
138
+ if (empty($emagData['name'])) {
139
+ $emagData['name'] = null;
140
+ }
141
+ } else {
142
+ $emagData['name'] = null;
143
+ }
144
+ if (empty($emagData['name']) && !$emagData['part_number_key']) {
145
+ Mage::throwException(
146
+ $this->_getHelper()->__('Please fill eMAG product name.')
147
+ );
148
+ }
149
+
150
+ if (array_key_exists('brand', $emagData)) {
151
+ $emagData['brand'] = trim($emagData['brand']);
152
+ if (empty($emagData['brand'])) {
153
+ $emagData['brand'] = null;
154
+ }
155
+ } else {
156
+ $emagData['brand'] = null;
157
+ }
158
+ if (empty($emagData['brand']) && !$emagData['part_number_key']) {
159
+ Mage::throwException(
160
+ $this->_getHelper()->__('Please fill eMAG product brand.')
161
+ );
162
+ }
163
+
164
+ if (array_key_exists('description', $emagData)) {
165
+ $emagData['description'] = trim($emagData['description']);
166
+ if (empty($emagData['description'])) {
167
+ $emagData['description'] = null;
168
+ }
169
+ } else {
170
+ $emagData['description'] = null;
171
+ }
172
+
173
+ if (array_key_exists('barcodes', $emagData)) {
174
+ if (is_array($emagData['barcodes'])) {
175
+ $emagData['barcodes'] = array_filter(
176
+ array_unique(
177
+ array_map('trim', $emagData['barcodes'])
178
+ )
179
+ );
180
+ } else {
181
+ $emagData['barcodes'] = array();
182
+ }
183
+ } else {
184
+ $emagData['barcodes'] = array();
185
+ }
186
+
187
+ $categoryId = null;
188
+ $emagCategory = Mage::getModel('innobyte_emag_marketplace/category');
189
+ if (array_key_exists('category_id', $emagData)) {
190
+ $emagCategory->load($emagData['category_id']);
191
+ if ($emagCategory->getStoreId() == $storeId) {
192
+ $categoryId = $emagCategory->getId();
193
+ }
194
+ }
195
+ $emagData['category_id'] = $categoryId;
196
+ if (empty($emagData['category_id'])) {
197
+ if (!$emagData['part_number_key']) {
198
+ Mage::throwException(
199
+ $this->_getHelper()->__('Please choose eMAG category.')
200
+ );
201
+ }
202
+ } elseif (is_array($emagCategory->getCharacteristics())) {
203
+ $skipChars = array();
204
+ if ($product->isConfigurable()) {
205
+ if (empty($emagData['family_type_id'])) {
206
+ Mage::throwException(
207
+ $this->_getHelper()->__('Please choose eMAG family type.')
208
+ );
209
+ }
210
+ $familyType = null;
211
+ foreach ($emagCategory->getFamilyTypes() as $ftModel) {
212
+ if ($ftModel->getId() == $emagData['family_type_id']) {
213
+ $familyType = $ftModel;
214
+ break;
215
+ }
216
+ }
217
+ if (is_null($familyType)) {
218
+ Mage::throwException(
219
+ $this->_getHelper()->__('Invalid family type provided.')
220
+ );
221
+ }
222
+ foreach ($familyType->getCharacteristics() as $ftChar) {
223
+ $skipChars[] = $ftChar->getMageIdEmagChar();
224
+ }
225
+ }
226
+
227
+ foreach ($emagCategory->getCharacteristics() as $characteristic) {
228
+ $charKey = 'category_characteristic' . $characteristic->getId();
229
+ if ((!array_key_exists($charKey, $emagData)
230
+ || !strlen(trim($emagData[$charKey])))
231
+ && !in_array($characteristic->getId(), $skipChars)) {
232
+ Mage::throwException(
233
+ $this->_getHelper()->__(
234
+ 'No category characteristic "%s" value found.',
235
+ $this->_getHelper()->__($characteristic->getName())
236
+ )
237
+ );
238
+ } elseif (!in_array($characteristic->getId(), $skipChars)) {
239
+ $emagData[$charKey] = trim($emagData[$charKey]);
240
+ } else {
241
+ unset($emagData[$charKey]);
242
+ }
243
+ }
244
+ }
245
+
246
+ $validOfferStatuses = Mage::getSingleton('innobyte_emag_marketplace/source_offerStatus')
247
+ ->toArray();
248
+ if (!array_key_exists('status', $emagData)
249
+ || !in_array($emagData['status'], $validOfferStatuses)) {
250
+ Mage::throwException(
251
+ $this->_getHelper()->__('Please choose eMAG offer status.')
252
+ );
253
+ }
254
+
255
+ if (array_key_exists('warranty', $emagData)) {
256
+ $emagData['warranty'] = (int) $emagData['warranty'];
257
+ if ($emagData['warranty'] < 0 || $emagData['warranty'] > 255) {
258
+ Mage::throwException(
259
+ $this->_getHelper()->__(
260
+ 'Invalid eMAG warranty. Should be a real number equal to or greater than 0 and smaller than 255.'
261
+ )
262
+ );
263
+ }
264
+ if (!$emagData['warranty']) {
265
+ $emagData['warranty'] = null;
266
+ }
267
+ }
268
+
269
+ if (!array_key_exists('commission_type', $emagData)
270
+ || empty($emagData['commission_type'])) {
271
+ Mage::throwException(
272
+ $this->_getHelper()->__('Please choose eMAG commission type.')
273
+ );
274
+ }
275
+ try {
276
+ $commissionType = Innobyte_EmagMarketplace_Model_Source_CommissionTypes::getEmagCommissionType($emagData['commission_type']);
277
+ } catch (Innobyte_EmagMarketplace_Exception $ex) {
278
+ Mage::throwException($this->_getHelper()->__($ex->getMessage()));
279
+ }
280
+
281
+ if (!array_key_exists('commission_value', $emagData)) {
282
+ Mage::throwException(
283
+ $this->_getHelper()->__('Please fill eMAG commission value.')
284
+ );
285
+ }
286
+ if (Innobyte_EmagMarketplace_Model_Source_CommissionTypes::TYPE_PERCENTAGE == $commissionType) {
287
+ $emagData['commission_value'] = (int) $emagData['commission_value'];
288
+ if ($emagData['commission_value'] < 0
289
+ || $emagData['commission_value'] > 100) {
290
+ Mage::throwException(
291
+ $this->_getHelper()->__(
292
+ 'Invalid eMAG commission value. Should be a percentage between 0 and 100.'
293
+ )
294
+ );
295
+ }
296
+ } else {
297
+ $emagData['commission_value'] = (float) $emagData['commission_value'];
298
+ if ($emagData['commission_value'] < 0) {
299
+ Mage::throwException(
300
+ $this->_getHelper()->__(
301
+ 'Invalid eMAG commission value. Should be a real number equal to or greater than 0.'
302
+ )
303
+ );
304
+ }
305
+ }
306
+
307
+ if (array_key_exists('handling_time', $emagData)) {
308
+ $emagData['handling_time'] = (int) $emagData['handling_time'];
309
+ if ($emagData['handling_time'] < 0
310
+ || $emagData['handling_time'] > 255) {
311
+ Mage::throwException(
312
+ $this->_getHelper()->__(
313
+ 'Invalid eMAG handling time. Should be a real number equal to or greater than 0 and smaller than 255.'
314
+ )
315
+ );
316
+ }
317
+ if (!$emagData['handling_time']) {
318
+ $emagData['handling_time'] = null;
319
+ }
320
+ }
321
+
322
+ $date = null;
323
+ if (array_key_exists('start_date', $emagData)) {
324
+ $filterInput = new Zend_Filter_LocalizedToNormalized(
325
+ array(
326
+ 'date_format' => Mage::app()->getLocale()
327
+ ->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)
328
+ )
329
+ );
330
+ $filterInternal = new Zend_Filter_NormalizedToLocalized(
331
+ array('date_format' => Varien_Date::DATE_INTERNAL_FORMAT)
332
+ );
333
+ $date = $filterInput->filter($emagData['start_date']);
334
+ $date = $filterInternal->filter($date);
335
+
336
+ if ($date) {
337
+ try {
338
+ $zendDate = new Zend_Date($date, Varien_Date::DATE_INTERNAL_FORMAT);
339
+ } catch (Zend_Date_Exception $zdex) {
340
+ Mage::throwException(
341
+ $this->_getHelper()->__('Invalid eMAG offer start date.')
342
+ );
343
+ }
344
+ $now = new Zend_Date(null, Varien_Date::DATE_INTERNAL_FORMAT);
345
+ if (!$zendDate->isLater($now)
346
+ || !$zendDate->isEarlier($now->addDay(61))) {
347
+ Mage::throwException(
348
+ $this->_getHelper()->__(
349
+ 'Offer start date can be as far as 60 days in the future and cannot be earlier than tomorrow.'
350
+ )
351
+ );
352
+ }
353
+ }
354
+ }
355
+ if ($date) {
356
+ $emagData['start_date'] = $date;
357
+ } else {
358
+ $emagData['start_date'] = null;
359
+ }
360
+
361
+ $vatId = null;
362
+ if (array_key_exists('vat_id', $emagData)) {
363
+ $vatId = (int) $emagData['vat_id'];
364
+ $vats = Mage::getSingleton('innobyte_emag_marketplace/source_vat')
365
+ ->getIdsArray($storeId);
366
+ if (!in_array($vatId, $vats)) {
367
+ $vatId = null;
368
+ }
369
+ }
370
+ if (null === $vatId) { // calculate vat percent
371
+ $taxClassId = $product->getTaxClassId();
372
+ $request = Mage::getSingleton('tax/calculation')
373
+ ->getRateRequest(false, false, false, Mage::app()->getStore($storeId));
374
+ $percent = Mage::getSingleton('tax/calculation')
375
+ ->getRate($request->setProductClassId($taxClassId));
376
+ $percent = $percent / 100;
377
+ $vats = Mage::getSingleton('innobyte_emag_marketplace/source_vat')
378
+ ->toOptionArray($storeId, false);
379
+ foreach ($vats as $vatRate) {
380
+ if ($vatRate['label'] == $percent && $vatRate['value'] > 0) {
381
+ $vatId = $vatRate['value'];
382
+ break;
383
+ }
384
+ }
385
+ }
386
+ $emagData['vat_id'] = $vatId;
387
+ if (empty($emagData['vat_id'])) {
388
+ Mage::throwException(
389
+ $this->_getHelper()->__('Please choose eMAG VAT.')
390
+ );
391
+ }
392
+ }
393
+
394
+
395
+
396
+ /**
397
+ * Add eMAG related mass actions to products grid.
398
+ * Triggered on adminhtml_catalog_product_grid_prepare_massaction event.
399
+ *
400
+ * @param Varien_Event_Observer $observer
401
+ * @return Innobyte_EmagMarketplace_Model_Catalog_Product_Observer
402
+ * @throws Mage_Core_Exception
403
+ */
404
+ public function addEmagProductMassActions(Varien_Event_Observer $observer)
405
+ {
406
+ $gridBlock = $observer->getEvent()->getBlock();
407
+
408
+ $storeId = $this->_getHelper()->getCurrStoreId();
409
+ if (!($gridBlock instanceof Mage_Adminhtml_Block_Catalog_Product_Grid)
410
+ || $storeId == Mage_Core_Model_App::ADMIN_STORE_ID
411
+ || !$this->_getHelper()->isExtensionEnabled($storeId)) {
412
+ return $this;
413
+ }
414
+
415
+ $gridBlock->getMassactionBlock()->addItem(
416
+ 'emag_send_product_mass',
417
+ array(
418
+ 'label'=> $this->_getHelper()->__('Send eMAG product'),
419
+ 'url' => $gridBlock->getUrl(
420
+ 'adminhtml/emag_product/massSendProduct',
421
+ array('_current' => 1)
422
+ ),
423
+ )
424
+ );
425
+ $gridBlock->getMassactionBlock()->addItem(
426
+ 'emag_send_offer_mass',
427
+ array(
428
+ 'label'=> $this->_getHelper()->__('Send eMAG offer'),
429
+ 'url' => $gridBlock->getUrl(
430
+ 'adminhtml/emag_product/massSendOffer',
431
+ array('_current' => 1)
432
+ ),
433
+ )
434
+ );
435
+ $gridBlock->getMassactionBlock()->addItem(
436
+ 'emag_deactivate_offer_mass',
437
+ array(
438
+ 'label'=> $this->_getHelper()->__('Deactivate eMAG offer'),
439
+ 'url' => $gridBlock->getUrl(
440
+ 'adminhtml/emag_product/massDeactivateOffer',
441
+ array('_current' => 1)
442
+ ),
443
+ )
444
+ );
445
+
446
+ return $this;
447
+ }
448
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Category.php ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG category model.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Category extends Mage_Core_Model_Abstract
11
+ {
12
+ /**
13
+ * @Override
14
+ * @var string Event prefix.
15
+ */
16
+ protected $_eventPrefix = 'innobyte_emag_marketplace_category';
17
+
18
+ /**
19
+ * @Override
20
+ * @var string Event object key.
21
+ */
22
+ protected $_eventObject = 'emag_category';
23
+
24
+ /**
25
+ * Imported characteristics from api response.
26
+ *
27
+ * @var array|null
28
+ */
29
+ protected $_importedCharacteristics;
30
+
31
+ /**
32
+ * Imported family types from api response.
33
+ *
34
+ * @var array|null
35
+ */
36
+ protected $_importedFamilyTypes;
37
+
38
+
39
+
40
+ /**
41
+ * @Override
42
+ */
43
+ public function _construct()
44
+ {
45
+ parent::_construct();
46
+ $this->_init('innobyte_emag_marketplace/category');
47
+ }
48
+
49
+
50
+
51
+ /**
52
+ * Getter method for imported characteristics property.
53
+ *
54
+ * @return array|null null if property is never set.
55
+ */
56
+ public function getImportedCharacteristics()
57
+ {
58
+ return $this->_importedCharacteristics;
59
+ }
60
+
61
+
62
+
63
+ /**
64
+ * Getter method for imported family types property.
65
+ *
66
+ * @return array|null null if property is never set.
67
+ */
68
+ public function getImportedFamilyTypes()
69
+ {
70
+ return $this->_importedFamilyTypes;
71
+ }
72
+
73
+
74
+
75
+ /**
76
+ * Setter method for imported characteristics property.
77
+ *
78
+ * @param array With Innobyte_EmagMarketplace_Model_Category_Characteristic
79
+ * models
80
+ * @return Innobyte_EmagMarketplace_Model_Category
81
+ */
82
+ public function setImportedCharacteristics(array $importedCharacteristics)
83
+ {
84
+ $this->_importedCharacteristics = $importedCharacteristics;
85
+ return $this;
86
+ }
87
+
88
+
89
+
90
+ /**
91
+ * Setter method for imported family types property.
92
+ *
93
+ * @param @param array With
94
+ * Innobyte_EmagMarketplace_Model_Category_Familytype
95
+ * models
96
+ * @return Innobyte_EmagMarketplace_Model_Category
97
+ */
98
+ public function setImportedFamilyTypes(array $importedFamilyTypes)
99
+ {
100
+ $this->_importedFamilyTypes = $importedFamilyTypes;
101
+ return $this;
102
+ }
103
+
104
+
105
+
106
+ /**
107
+ * Retrieve category 's characteristics.
108
+ *
109
+ * @return array|null null if module not loaded
110
+ */
111
+ public function getCharacteristics()
112
+ {
113
+ if (!$this->hasCharacteristics() && $this->getId() > 0) {
114
+ $collection = Mage::getResourceModel(
115
+ 'innobyte_emag_marketplace/category_characteristic_collection'
116
+ )->addFieldToFilter('category_id', array('eq' => $this->getId()))
117
+ ->setOrder('display_order', Varien_Data_Collection::SORT_ORDER_ASC);
118
+ $characteristics = array();
119
+ foreach ($collection as $characteristic) {
120
+ $characteristics[$characteristic->getId()] = $characteristic;
121
+ }
122
+ $this->setCharacteristics($characteristics);
123
+ }
124
+ return $this->getData('characteristics');
125
+ }
126
+
127
+
128
+
129
+ /**
130
+ * Retrieve category 's family types.
131
+ *
132
+ * @return array|null null if module not loaded
133
+ */
134
+ public function getFamilyTypes()
135
+ {
136
+ if (!$this->hasFamilyTypes() && $this->getId() > 0) {
137
+ $collection = Mage::getResourceModel(
138
+ 'innobyte_emag_marketplace/category_familytype_collection'
139
+ )->addFieldToFilter('category_id', array('eq' => $this->getId()));
140
+ $familyTypes = array();
141
+ foreach ($collection as $familyType) {
142
+ $familyTypes[$familyType->getId()] = $familyType;
143
+ }
144
+ $this->setFamilyTypes($familyTypes);
145
+ }
146
+ return $this->getData('family_types');
147
+ }
148
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Category/Characteristic.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG category characteristic model.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Category_Characteristic
11
+ extends Mage_Core_Model_Abstract
12
+ {
13
+ /**
14
+ * @Override
15
+ * @var string Event prefix.
16
+ */
17
+ protected $_eventPrefix = 'innobyte_emag_marketplace_category_characteristic';
18
+
19
+ /**
20
+ * @Override
21
+ * @var string Event object key.
22
+ */
23
+ protected $_eventObject = 'emag_category_characteristic';
24
+
25
+
26
+
27
+ /**
28
+ * @Override
29
+ */
30
+ public function _construct()
31
+ {
32
+ parent::_construct();
33
+ $this->_init('innobyte_emag_marketplace/category_characteristic');
34
+ }
35
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Category/Familytype.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG category family-type model.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Category_Familytype
11
+ extends Mage_Core_Model_Abstract
12
+ {
13
+ /**
14
+ * @Override
15
+ * @var string Event prefix.
16
+ */
17
+ protected $_eventPrefix = 'innobyte_emag_marketplace_category_familytype';
18
+
19
+ /**
20
+ * @Override
21
+ * @var string Event object key.
22
+ */
23
+ protected $_eventObject = 'emag_category_familytype';
24
+
25
+ /**
26
+ * Imported family type characteristics from api response.
27
+ *
28
+ * @var array|null
29
+ */
30
+ protected $_importedCharacteristics;
31
+
32
+
33
+
34
+ /**
35
+ * @Override
36
+ */
37
+ public function _construct()
38
+ {
39
+ parent::_construct();
40
+ $this->_init('innobyte_emag_marketplace/category_familytype');
41
+ }
42
+
43
+
44
+
45
+ /**
46
+ * Getter method for imported ft characteristics property.
47
+ *
48
+ * @return array|null null if property is never set.
49
+ */
50
+ public function getImportedCharacteristics()
51
+ {
52
+ return $this->_importedCharacteristics;
53
+ }
54
+
55
+
56
+
57
+ /**
58
+ * Setter method for imported ft characteristics property.
59
+ *
60
+ * @param array Array with api response characteristics for a family type.
61
+ * @return Innobyte_EmagMarketplace_Model_Category_Familytype
62
+ */
63
+ public function setImportedCharacteristics(array $importedCharacteristics)
64
+ {
65
+ $this->_importedCharacteristics = $importedCharacteristics;
66
+ return $this;
67
+ }
68
+
69
+
70
+
71
+ /**
72
+ * Retrieve family type 's characteristics.
73
+ *
74
+ * @return array Array of varien objects.
75
+ */
76
+ public function getCharacteristics()
77
+ {
78
+ if (!$this->hasCharacteristics() && $this->getId() > 0) {
79
+ $this->setCharacteristics(
80
+ $this->_getResource()->getCharacteristics($this)
81
+ );
82
+ }
83
+ return $this->getData('characteristics');
84
+ }
85
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Cron.php ADDED
@@ -0,0 +1,422 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Cron
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Cron extends Mage_Core_Model_Abstract
12
+ {
13
+
14
+ /**
15
+ * Sync errors
16
+ *
17
+ * @var array
18
+ */
19
+ protected $_errors = array();
20
+
21
+ /**
22
+ * Email send flag
23
+ *
24
+ * @var bool
25
+ */
26
+ protected $_canSendEmail = false;
27
+
28
+ /**
29
+ * Add sync error
30
+ *
31
+ * @param string $message
32
+ * @param bool $notice
33
+ * @return Innobyte_EmagMarketplace_Model_Cron
34
+ */
35
+ public function addError($message, $notice = false)
36
+ {
37
+ if (!$notice) {
38
+ $this->_canSendEmail = true;
39
+ }
40
+ $this->_errors[] = $message;
41
+
42
+ return $this;
43
+ }
44
+
45
+ /**
46
+ * Reset errors array
47
+ *
48
+ * @return Innobyte_EmagMarketplace_Model_Cron
49
+ */
50
+ public function resetErrors()
51
+ {
52
+ $this->_errors = array();
53
+
54
+ return $this;
55
+ }
56
+
57
+ /**
58
+ * Get sync errors
59
+ *
60
+ * @return array
61
+ */
62
+ public function getErrors()
63
+ {
64
+ return $this->_errors;
65
+ }
66
+
67
+ /**
68
+ * Get email send flag
69
+ *
70
+ * @return bool
71
+ */
72
+ public function canSendEmail()
73
+ {
74
+ return $this->_canSendEmail;
75
+ }
76
+
77
+ /**
78
+ * Reset email send flag
79
+ *
80
+ * @return bool
81
+ */
82
+ public function resetEmailFlag()
83
+ {
84
+ $this->_canSendEmail = false;
85
+
86
+ return false;
87
+ }
88
+
89
+ /**
90
+ * Get eMAG marketplace data helper
91
+ *
92
+ * @return Innobyte_EmagMarketplace_Helper_Data
93
+ */
94
+ public function getHelper()
95
+ {
96
+ return Mage::helper('innobyte_emag_marketplace');
97
+ }
98
+
99
+ /**
100
+ * @return Innobyte_EmagMarketplace_Model_Api_Order
101
+ */
102
+ public function getOrderApiModel()
103
+ {
104
+ return Mage::getModel('innobyte_emag_marketplace/api_order');
105
+ }
106
+
107
+ /**
108
+ * Read eMAG orders
109
+ *
110
+ * @return bool
111
+ */
112
+ public function readOrders()
113
+ {
114
+ foreach (Mage::app()->getWebsites() as $website) {
115
+ foreach ($website->getGroups() as $group) {
116
+ $stores = $group->getStores();
117
+ /** @var $store Mage_Core_Model_Store */
118
+ foreach ($stores as $store) {
119
+ if (!$this->getHelper()->canMakeApiCall($store->getId())) {
120
+ continue;
121
+ }
122
+
123
+ // reset erros and email flag
124
+ $this->resetErrors();
125
+ $this->resetEmailFlag();
126
+
127
+ $this->addError(
128
+ $this->getHelper()->__(
129
+ 'Sync process started for store: %s', $store->getFrontendName()
130
+ ),
131
+ true
132
+ );
133
+
134
+ $api = $this->getOrderApiModel()->setStoreId($store->getId());
135
+
136
+ /** @var $response Innobyte_EmagMarketplace_Model_Api_Response */
137
+ $response = $api->count();
138
+
139
+ // continue to next store if api order count returns error
140
+ if ($response->isError()) {
141
+ foreach ($response->getMessages() as $message) {
142
+ $this->addError($message);
143
+ }
144
+ continue;
145
+ }
146
+
147
+ // continue to next store if no orders found
148
+ if ($api->getNoOfItems() == 0) {
149
+ continue;
150
+ }
151
+
152
+ // loop through all pages and get orders
153
+ for ($currentPage = 1; $currentPage <= $api->getNoOfPages(); $currentPage++) {
154
+ $response = $this->getOrderApiModel()
155
+ ->setStoreId($store->getId())
156
+ ->setCurrentPage($currentPage)
157
+ ->read();
158
+
159
+ if (!$this->_processEmagOrders($store, $response)) {
160
+ continue;
161
+ }
162
+ }
163
+
164
+ $this->addError(
165
+ $this->getHelper()->__(
166
+ 'Sync process finished for store: %s', $store->getFrontendName()
167
+ ),
168
+ true
169
+ );
170
+
171
+ if ($this->canSendEmail()) {
172
+ $this->_sendEmail($store);
173
+ }
174
+ }
175
+ }
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Process eMAG orders
181
+ *
182
+ * @param $store
183
+ * @param Innobyte_EmagMarketplace_Model_Api_Response $response
184
+ * @return bool
185
+ */
186
+ protected function _processEmagOrders($store, $response)
187
+ {
188
+ // continue to next store if api order read returns error
189
+ if ($response->isError()) {
190
+ foreach ($response->getMessages() as $message) {
191
+ $this->addError($message);
192
+ }
193
+ return false;
194
+ }
195
+
196
+ $emagOrders = $response->getResults();
197
+ foreach ($emagOrders as $emagOrder) {
198
+ Mage::log(
199
+ $this->getHelper()->__('Sync process started for order: #%s', $emagOrder['id']),
200
+ Zend_Log::NOTICE,
201
+ $this->getHelper()->getResourceLogFile('order'),
202
+ true
203
+ );
204
+ $this->addError($this->getHelper()->__('Sync process started for order: #%s', $emagOrder['id']), true);
205
+
206
+ try {
207
+ /** @var $order Innobyte_EmagMarketplace_Model_Order_Convert_Emag */
208
+ $order = Mage::getModel('innobyte_emag_marketplace/order_convert_emag');
209
+ $order->setStore($store);
210
+ $order->setEmagOrder($emagOrder);
211
+ $order->convert();
212
+ } catch (Innobyte_EmagMarketplace_Exception $e) {
213
+ Mage::log(
214
+ $this->getHelper()->__(
215
+ 'eMAG order: #%s could not be processed. ERROR: %s',
216
+ $emagOrder['id'],
217
+ $e->getMessage()
218
+ ),
219
+ Zend_Log::ERR,
220
+ $this->getHelper()->getResourceLogFile('order'),
221
+ true
222
+ );
223
+ $this->addError($e->getMessage());
224
+ } catch (Exception $e) {
225
+ Mage::log(
226
+ $e->getMessage(),
227
+ Zend_Log::ERR,
228
+ $this->getHelper()->getResourceLogFile('order'),
229
+ true
230
+ );
231
+ $this->addError($e->getMessage());
232
+ }
233
+
234
+ Mage::log(
235
+ $this->getHelper()->__('Sync process finished for order: #%s', $emagOrder['id']),
236
+ Zend_Log::NOTICE,
237
+ $this->getHelper()->getResourceLogFile('order'),
238
+ true
239
+ );
240
+ $this->addError($this->getHelper()->__('Sync process finished for order: #%s', $emagOrder['id']), true);
241
+ }
242
+
243
+ return true;
244
+ }
245
+
246
+ /**
247
+ * Send email on sync error
248
+ *
249
+ * @param Mage_Core_Model_Store $store
250
+ * @return bool
251
+ */
252
+ protected function _sendEmail($store)
253
+ {
254
+ $recipientName = '';
255
+ $recipientEmail = $this->getHelper()->getEmail($store->getId());
256
+ if (!$recipientEmail) {
257
+ return false;
258
+ }
259
+
260
+ try {
261
+ $templateId = $this->getHelper()->getTemplate($store->getId());
262
+ if (!$templateId) {
263
+ return false;
264
+ }
265
+
266
+ // set sender information
267
+ $sender = array(
268
+ 'name' => $this->getHelper()->__('Innobyte eMAG Marketplace'),
269
+ 'email' => Mage::getStoreConfig('trans_email/ident_general/email', $store->getId())
270
+ );
271
+
272
+ // set variables that can be used in email template
273
+ $vars = array(
274
+ 'store' => $store,
275
+ 'errors' => $this->_processErrors($this->getErrors()),
276
+ );
277
+
278
+ /** @var $translate Mage_Core_Model_Translate */
279
+ $translate = Mage::getSingleton('core/translate');
280
+
281
+ /** @var $mailer Mage_Core_Model_Email_Template */
282
+ $mailer = Mage::getModel('core/email_template');
283
+ $mailer->sendTransactional(
284
+ $templateId,
285
+ $sender,
286
+ $recipientEmail,
287
+ $recipientName,
288
+ $vars,
289
+ $store->getId()
290
+ );
291
+
292
+ $translate->setTranslateInline(true);
293
+ } catch (Exception $e) {
294
+ Mage::log($e->getMessage());
295
+ return false;
296
+ }
297
+
298
+ return true;
299
+ }
300
+
301
+ /**
302
+ * Process sync errors
303
+ *
304
+ * @param $messages
305
+ * @return string
306
+ */
307
+ protected function _processErrors($messages)
308
+ {
309
+ $errors = '';
310
+ foreach ($messages as $message) {
311
+ $errors .= '<p>' . $message . '</p>';
312
+ }
313
+
314
+ return $errors;
315
+ }
316
+
317
+ public function testOrder()
318
+ {
319
+ $data = array(
320
+ 'status' => 1,
321
+ 'date' => '2015-02-02 17:50:18',
322
+ 'observation' => '',
323
+ 'id' => '12493975',
324
+ 'payment_mode' => 'RAMBURS',
325
+ 'payment_mode_id' => '1',
326
+ 'payment_status' => '0',
327
+ 'vendor_name' => 'Ishtar',
328
+ 'cancellation_request' => '',
329
+ 'has_editable_products' => '1',
330
+ 'parent_id' => '',
331
+ 'customer' => array(
332
+ 'id' => '2853241',
333
+ 'name' => 'eMAG User',
334
+ 'company' => 'eMAG Company',
335
+ 'gender' => 'M',
336
+ 'code' => 'code',
337
+ 'email' => '',
338
+ 'created' => '2015-02-02 17:50:33',
339
+ 'modified' => '2015-02-04 13:58:37',
340
+ 'bank' => 'eMAG Bank',
341
+ 'iban' => 'IBAN',
342
+ 'fax' => '021000000000',
343
+ 'mkt_id' => '2853241',
344
+ 'phone_1' => '0720000001',
345
+ 'phone_2' => '0720000002',
346
+ 'phone_3' => '0720000003',
347
+ 'registration_number' => '',
348
+ 'billing_country' => 'RO',
349
+ 'billing_suburb' => 'Timis',
350
+ 'billing_city' => 'Timisoara',
351
+ 'billing_locality_id' => '13763',
352
+ 'billing_street' => 'Calea Buziasului, nr 59B',
353
+ 'billing_postal_code' => '112233',
354
+ 'shipping_country' => 'RO',
355
+ 'shipping_suburb' => 'Timis',
356
+ 'shipping_city' => 'Timisoara',
357
+ 'shipping_locality_id' => '13763',
358
+ 'shipping_street' => 'Calea Buziasului, nr 59B',
359
+ 'shipping_postal_code' => '112233',
360
+ 'is_vat_payer' => '1',
361
+ 'legal_entity' => '0',
362
+ ),
363
+ 'details' => array(),
364
+ 'attachments' => array(),
365
+ 'products' => array(
366
+ 0 =>
367
+ array(
368
+ 'id' => '1576182',
369
+ 'product_id' => '153',
370
+ 'part_number' => 'intelcore2extreme',
371
+ 'quantity' => '1',
372
+ 'sale_price' => '9122.4555',
373
+ 'currency' => 'RON',
374
+ 'created' => '2015-02-02 17:50:33',
375
+ 'modified' => '2015-02-04 13:58:37',
376
+ 'status' => '1',
377
+ 'attachments' => array(),
378
+ 'details' => array(),
379
+ 'vat' => '0.2400',
380
+ ),
381
+ ),
382
+ 'shipping_tax' => '0.0000',
383
+ 'vouchers' => array(
384
+ 0 =>
385
+ array(
386
+ 'id' => '280934',
387
+ 'modified' => '2015-02-04 13:58:40',
388
+ 'created' => '2015-02-04 13:58:40',
389
+ 'status' => '1',
390
+ 'voucher_id' => '3628521',
391
+ 'sale_price_vat' => '-1.2',
392
+ 'sale_price' => '-5',
393
+ 'voucher_name' => 'eMAG Gift Card 1',
394
+ 'vat' => '0.24',
395
+ ),
396
+ 1 =>
397
+ array(
398
+ 'id' => '280935',
399
+ 'modified' => '2015-02-04 13:58:40',
400
+ 'created' => '2015-02-04 13:58:40',
401
+ 'status' => '1',
402
+ 'voucher_id' => '3628529',
403
+ 'sale_price_vat' => '0.72',
404
+ 'sale_price' => '-3',
405
+ 'voucher_name' => 'eMAG Gift Card 2',
406
+ 'vat' => '0.24',
407
+ )
408
+ ),
409
+ 'proforms' => array()
410
+
411
+ );
412
+
413
+ $store = Mage::getModel('core/store')->load(3);
414
+
415
+ /** @var $order Innobyte_EmagMarketplace_Model_Order_Convert_Emag */
416
+ $order = Mage::getModel('innobyte_emag_marketplace/order_convert_emag');
417
+ $order->setStore($store);
418
+ $order->setEmagOrder($data);
419
+ $order->convert();
420
+ }
421
+
422
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Customer/Attributes.php ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Customer_Attributes
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Customer_Attributes extends Mage_Core_Model_Abstract
12
+ {
13
+
14
+ /**
15
+ * Prefix of model events names
16
+ *
17
+ * @var string
18
+ */
19
+ protected $_eventPrefix = 'innobyte_emag_marketplace_customer_attributes';
20
+
21
+ /**
22
+ * Parameter name in event
23
+ *
24
+ * In observe method you can use $observer->getEvent()->getCustomerAttributes() in this case
25
+ *
26
+ * @var string
27
+ */
28
+ protected $_eventObject = 'customer_attributes';
29
+
30
+ /**
31
+ * Entity type
32
+ *
33
+ * @var null
34
+ */
35
+ protected $_entityType = null;
36
+
37
+ /**
38
+ * Customer attributes
39
+ *
40
+ * @var array
41
+ */
42
+ protected $_customerAttributes = array();
43
+
44
+ /**
45
+ * Customer address attributes
46
+ *
47
+ * @var array
48
+ */
49
+ protected $_customerAddressAttributes = array();
50
+
51
+ /**
52
+ * Set entity type
53
+ *
54
+ * @param $entityType
55
+ */
56
+ public function setEntityType($entityType)
57
+ {
58
+ $this->_entityType = $entityType;
59
+ }
60
+
61
+ /**
62
+ * Get entity type
63
+ *
64
+ * @return null
65
+ */
66
+ public function getEntityType()
67
+ {
68
+ return $this->_entityType;
69
+ }
70
+
71
+ /**
72
+ * Get customer attributes
73
+ *
74
+ * @return array
75
+ */
76
+ public function getCustomerAttributes()
77
+ {
78
+ if (empty($this->_customerAttributes)) {
79
+ $this->_customerAttributes = $this->_getAttributes();
80
+ }
81
+
82
+ return $this->_customerAttributes;
83
+ }
84
+
85
+ /**
86
+ * Get customer address attributes
87
+ *
88
+ * @return array
89
+ */
90
+ public function getCustomerAddressAttributes()
91
+ {
92
+ if (empty($this->_customerAddressAttributes)) {
93
+ $this->_customerAddressAttributes = $this->_getAttributes();
94
+ }
95
+
96
+ return $this->_customerAddressAttributes;
97
+ }
98
+
99
+ /**
100
+ * Get attributes
101
+ *
102
+ * @return array
103
+ */
104
+ protected function _getAttributes()
105
+ {
106
+ $attributes = array();
107
+ /* @var $config Mage_Eav_Model_Config */
108
+ $config = Mage::getSingleton('eav/config');
109
+ foreach ($config->getEntityAttributeCodes($this->_entityType) as $attributeCode) {
110
+ $attribute = $config->getAttribute($this->_entityType, $attributeCode);
111
+ if ($attribute && $attribute->getIsUserDefined()) {
112
+ $attributes[] = $attributeCode;
113
+ }
114
+ }
115
+ return $attributes;
116
+ }
117
+
118
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Customer/Form.php ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Customer_Form
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Customer_Form extends Mage_Customer_Model_Form
12
+ {
13
+
14
+ /**
15
+ * Check if eMAG attributes can be used
16
+ * - check if order_address edit mode and emag_order_id is available
17
+ * - check if quote and emag_order_id is available
18
+ * - make sure attributes are removed from Customer->Edit page
19
+ *
20
+ * @return bool
21
+ */
22
+ protected function _canUseEmagAttributes()
23
+ {
24
+ if (
25
+ (
26
+ ($this->_getOrderAddress() && $this->_getOrderAddress()->getOrder()->getEmagOrderId())
27
+ || $this->_getQuoteSession()->getQuote()->getEmagOrderId()
28
+ )
29
+ && !$this->_getCurrentCustomer()
30
+ ) {
31
+ return true;
32
+ }
33
+
34
+ return false;
35
+ }
36
+
37
+ /**
38
+ * Get quote session
39
+ *
40
+ * @return Mage_Adminhtml_Model_Session_Quote
41
+ */
42
+ private function _getQuoteSession()
43
+ {
44
+ return Mage::getSingleton('adminhtml/session_quote');
45
+ }
46
+
47
+ /**
48
+ * Get current order address
49
+ *
50
+ * @return Mage_Sales_Model_Order_Address
51
+ */
52
+ private function _getOrderAddress()
53
+ {
54
+ return Mage::registry('order_address');
55
+ }
56
+
57
+ /**
58
+ * Get current customer
59
+ *
60
+ * @return Mage_Customer_Model_Customer
61
+ */
62
+ private function _getCurrentCustomer()
63
+ {
64
+ return Mage::registry('current_customer');
65
+ }
66
+
67
+ /**
68
+ * Return array of form attributes
69
+ * - skip eMAG attributes if emag_order_id is not available
70
+ * - for customer account edit these attributes should be removed all the time
71
+ *
72
+ * @return array
73
+ */
74
+ public function getAttributes()
75
+ {
76
+ if($this->_canUseEmagAttributes()) {
77
+ return parent::getAttributes();
78
+ }
79
+
80
+ if (is_null($this->_attributes)) {
81
+ /* @var $collection Mage_Eav_Model_Resource_Form_Attribute_Collection */
82
+ $collection = $this->_getFormAttributeCollection();
83
+
84
+ $collection->setStore($this->getStore())
85
+ ->setEntityType($this->getEntityType())
86
+ ->addFormCodeFilter($this->getFormCode())
87
+ ->setSortOrder();
88
+
89
+ $this->_attributes = array();
90
+ $this->_userAttributes = array();
91
+
92
+ /** @var $attribute Mage_Customer_Model_Attribute */
93
+ foreach ($collection as $attribute) {
94
+ if (strpos($attribute->getAttributeCode(), 'emag') !== false) {
95
+ continue;
96
+ }
97
+
98
+ /* @var $attribute Mage_Eav_Model_Entity_Attribute */
99
+ $this->_attributes[$attribute->getAttributeCode()] = $attribute;
100
+ if ($attribute->getIsUserDefined()) {
101
+ $this->_userAttributes[$attribute->getAttributeCode()] = $attribute;
102
+ } else {
103
+ $this->_systemAttributes[$attribute->getAttributeCode()] = $attribute;
104
+ }
105
+ }
106
+ }
107
+ return $this->_attributes;
108
+ }
109
+
110
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Invoice/Pdf/Total/Voucher.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Invoice_Pdf_Total_Voucher
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Invoice_Pdf_Total_Voucher extends Mage_Sales_Model_Order_Pdf_Total_Default
12
+ {
13
+
14
+ /**
15
+ * Get eMAG marketplace data helper
16
+ *
17
+ * @return Innobyte_EmagMarketplace_Helper_Data
18
+ */
19
+ protected function _getHelper()
20
+ {
21
+ return Mage::helper('innobyte_emag_marketplace');
22
+ }
23
+
24
+ /**
25
+ * Add eMAG voucher to pdf totals
26
+ *
27
+ * @return array
28
+ */
29
+ public function getTotalsForDisplay()
30
+ {
31
+ $vouchers = $this->getVouchers();
32
+ if (empty($vouchers)) {
33
+ return array();
34
+ }
35
+
36
+ $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
37
+
38
+ $total = array();
39
+ foreach ($vouchers as $voucher) {
40
+ $total[] = array(
41
+ 'label' => $voucher['emag_voucher_name'] . ':',
42
+ 'amount' => $this->getOrder()->formatPriceTxt($voucher['emag_sale_price']),
43
+ 'font_size' => $fontSize,
44
+ );
45
+ }
46
+
47
+ return $total;
48
+ }
49
+
50
+ /**
51
+ * @return array
52
+ */
53
+ public function getVouchers()
54
+ {
55
+ return $this->getSource()->getDataUsingMethod($this->getSourceField());
56
+ }
57
+
58
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Locality.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG locality model.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Locality extends Mage_Core_Model_Abstract
11
+ {
12
+ /**
13
+ * @Override
14
+ * @var string Event prefix.
15
+ */
16
+ protected $_eventPrefix = 'innobyte_emag_marketplace_locality';
17
+
18
+ /**
19
+ * @Override
20
+ * @var string Event object key.
21
+ */
22
+ protected $_eventObject = 'emag_locality';
23
+
24
+
25
+
26
+ /**
27
+ * @Override
28
+ */
29
+ public function _construct()
30
+ {
31
+ parent::_construct();
32
+ $this->_init('innobyte_emag_marketplace/locality');
33
+ }
34
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Locality/Flag.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Locality flag where last syncronization date is stored.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Locality_Flag extends Mage_Core_Model_Flag
11
+ {
12
+ /**
13
+ * Flag code
14
+ *
15
+ * @Override
16
+ * @var string
17
+ */
18
+ protected $_flagCode = 'innobyte_emag_marketplace_locality_sync';
19
+
20
+
21
+
22
+ /**
23
+ * Retrieve flag data array
24
+ *
25
+ * @Override
26
+ * @return array
27
+ */
28
+ public function getFlagData()
29
+ {
30
+ $flagData = parent::getFlagData();
31
+ if (!is_array($flagData)) {
32
+ $flagData = array();
33
+ $this->setFlagData($flagData);
34
+ }
35
+ return $flagData;
36
+ }
37
+
38
+
39
+
40
+ /**
41
+ * Retrieve last syncronization date of localities for a store.
42
+ *
43
+ * @param int $storeId
44
+ * @return string Date in the format 'Y-m-d H:i:s', or empty string
45
+ * if no syncronization has been done before.
46
+ */
47
+ public function getLastSyncronization($storeId)
48
+ {
49
+ $flagData = $this->getFlagData();
50
+ if (!array_key_exists($storeId, $flagData)) {
51
+ $flagData[$storeId] = '';
52
+ $this->setFlagData($flagData);
53
+ }
54
+ return $flagData[$storeId];
55
+ }
56
+
57
+
58
+
59
+ /**
60
+ * Set last syncronization date of localities for a store.
61
+ *
62
+ * @param int $storeId
63
+ * @param string $date Should be in the format 'Y-m-d H:i:s'
64
+ * @return Innobyte_EmagMarketplace_Model_Locality_Flag
65
+ */
66
+ public function setLastSyncronization($storeId, $date)
67
+ {
68
+ $flagData = $this->getFlagData();
69
+ $flagData[$storeId] = $date;
70
+ $this->setFlagData($flagData);
71
+ return $this;
72
+ }
73
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Order/Convert/Abstract.php ADDED
@@ -0,0 +1,419 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Order_Convert_Abstract
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ abstract class Innobyte_EmagMarketplace_Model_Order_Convert_Abstract extends Varien_Object
12
+ {
13
+
14
+ /**
15
+ * eMAG order statuses
16
+ */
17
+ const EMAG_STATUS_CANCELED = 0;
18
+ const EMAG_STATUS_NEW = 1;
19
+ const EMAG_STATUS_IN_PROGRESS = 2;
20
+ const EMAG_STATUS_PREPARED = 3;
21
+ const EMAG_STATUS_FINALIZED = 4;
22
+ const EMAG_STATUS_RETURNED = 5;
23
+
24
+ /**
25
+ * Order statuses
26
+ */
27
+ const STATUS_CANCELED = 'emag_canceled';
28
+ const STATUS_NEW = 'emag_new';
29
+ const STATUS_IN_PROGRESS = 'emag_in_progress';
30
+ const STATUS_PREPARED = 'emag_prepared';
31
+ const STATUS_FINALIZED = 'emag_finalized';
32
+ const STATUS_RETURNED = 'emag_returned';
33
+
34
+ /**
35
+ * eMAG payment modes
36
+ */
37
+ const EMAG_PAYMENT_UNKNOWN = '';
38
+ const EMAG_PAYMENT_CASHONDELIVERY = 1;
39
+ const EMAG_PAYMENT_BANKTRANSFER = 2;
40
+ const EMAG_PAYMENT_CREDITCARD = 3;
41
+
42
+ /**
43
+ * eMAG payment statuses
44
+ */
45
+ const EMAG_PAYMENT_STATUS_NOT_PAID = 0;
46
+ const EMAG_PAYMENT_STATUS_PAID = 1;
47
+
48
+ /**
49
+ * Product status in order
50
+ */
51
+ const EMAG_PRODUCT_CANCELED = 0;
52
+ const EMAG_PRODUCT_ACTIVE = 1;
53
+
54
+ /**
55
+ * Order statuses
56
+ *
57
+ * @var array
58
+ */
59
+ protected $_orderStatuses = array(
60
+ self::EMAG_STATUS_CANCELED => self::STATUS_CANCELED,
61
+ self::EMAG_STATUS_NEW => self::STATUS_NEW,
62
+ self::EMAG_STATUS_IN_PROGRESS => self::STATUS_IN_PROGRESS,
63
+ self::EMAG_STATUS_PREPARED => self::STATUS_PREPARED,
64
+ self::EMAG_STATUS_FINALIZED => self::STATUS_FINALIZED,
65
+ self::EMAG_STATUS_RETURNED => self::STATUS_RETURNED
66
+ );
67
+
68
+ protected $_statusState = array(
69
+ self::STATUS_NEW => Mage_Sales_Model_Order::STATE_NEW,
70
+ self::STATUS_IN_PROGRESS => Mage_Sales_Model_Order::STATE_PROCESSING,
71
+ self::STATUS_PREPARED => Mage_Sales_Model_Order::STATE_PROCESSING,
72
+ self::STATUS_FINALIZED => Mage_Sales_Model_Order::STATE_PROCESSING,
73
+ self::STATUS_CANCELED => Mage_Sales_Model_Order::STATE_PROCESSING,
74
+ self::STATUS_RETURNED => Mage_Sales_Model_Order::STATE_CLOSED
75
+ );
76
+
77
+ /**
78
+ * Payment modes
79
+ *
80
+ * @var array
81
+ */
82
+ protected $_paymentMethods = array(
83
+ self::EMAG_PAYMENT_UNKNOWN => Innobyte_EmagMarketplace_Model_Payment_Method_Unknown::EMAG_UNKNOWN,
84
+ self::EMAG_PAYMENT_CASHONDELIVERY => Innobyte_EmagMarketplace_Model_Payment_Method_Cashondelivery::EMAG_CASHONDELIVERY,
85
+ self::EMAG_PAYMENT_BANKTRANSFER => Innobyte_EmagMarketplace_Model_Payment_Method_Banktransfer::EMAG_BANKTRANSFER,
86
+ self::EMAG_PAYMENT_CREDITCARD => Innobyte_EmagMarketplace_Model_Payment_Method_Cc::EMAG_CREDITCARD
87
+ );
88
+
89
+ /**
90
+ * Store
91
+ *
92
+ * @var null|Mage_Core_Model_Store
93
+ */
94
+ protected $_store = null;
95
+
96
+ /**
97
+ * Store id
98
+ *
99
+ * @var null|int
100
+ */
101
+ protected $_storeId = null;
102
+
103
+ /**
104
+ * Order id
105
+ *
106
+ * @var null
107
+ */
108
+ protected $_orderId = null;
109
+
110
+ /**
111
+ * Order
112
+ *
113
+ * @var null|Mage_Sales_Model_Order
114
+ */
115
+ protected $_order = null;
116
+
117
+ /**
118
+ * @var null|Mage_Sales_Model_Order_Payment
119
+ */
120
+ protected $_payment = null;
121
+
122
+ /**
123
+ * eMAG order
124
+ *
125
+ * @var array
126
+ */
127
+ protected $_emagOrder = array();
128
+
129
+ /**
130
+ * Debug mode
131
+ *
132
+ * @var null|bool
133
+ */
134
+ protected $_debug = null;
135
+
136
+ /**
137
+ * Set order id
138
+ *
139
+ * @param $orderId
140
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Magento
141
+ */
142
+ public function setOrderId($orderId)
143
+ {
144
+ $this->_orderId = $orderId;
145
+
146
+ return $this;
147
+ }
148
+
149
+ /**
150
+ * Set order
151
+ *
152
+ * @param Mage_Sales_Model_Order $order
153
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Magento
154
+ */
155
+ public function setOrder($order)
156
+ {
157
+ $this->_order = $order;
158
+ $this->_orderId = $order->getId();
159
+
160
+ return $this;
161
+ }
162
+
163
+ /**
164
+ * Get order status
165
+ */
166
+ abstract public function getOrderStatus();
167
+
168
+ public function getStatusState($status)
169
+ {
170
+ if (!isset($this->_statusState[$status])) {
171
+ return false;
172
+ }
173
+
174
+ return $this->_statusState[$status];
175
+ }
176
+
177
+ /**
178
+ * Get eMAG order statuses
179
+ *
180
+ * @return array
181
+ */
182
+ public function getEmagOrderStatuses()
183
+ {
184
+ return $this->_orderStatuses;
185
+ }
186
+
187
+ /**
188
+ * Get payment method
189
+ *
190
+ * @param $method
191
+ */
192
+ abstract public function getPaymentMethod($method);
193
+
194
+ /**
195
+ * Set eMAG order
196
+ *
197
+ * @param $emagOrder
198
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Abstract
199
+ */
200
+ public function setEmagOrder($emagOrder)
201
+ {
202
+ $this->_emagOrder = $emagOrder;
203
+
204
+ return $this;
205
+ }
206
+
207
+ /**
208
+ * Debug mode
209
+ *
210
+ * @return bool|null
211
+ */
212
+ protected function _isDebug()
213
+ {
214
+ if (!$this->_debug) {
215
+ $this->_debug = $this->getHelper()->isDebug();
216
+ }
217
+
218
+ return $this->_debug;
219
+ }
220
+
221
+ /**
222
+ * Get eMAG marketplace data helper
223
+ *
224
+ * @return Innobyte_EmagMarketplace_Helper_Data
225
+ */
226
+ public function getHelper()
227
+ {
228
+ return Mage::helper('innobyte_emag_marketplace');
229
+ }
230
+
231
+ /**
232
+ * @return Innobyte_EmagMarketplace_Model_Api_Order
233
+ */
234
+ public function getOrderApiModel()
235
+ {
236
+ return Mage::getModel('innobyte_emag_marketplace/api_order');
237
+ }
238
+
239
+ /**
240
+ * Set store
241
+ *
242
+ * @param $store Mage_Core_Model_Store
243
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Abstract
244
+ */
245
+ public function setStore($store)
246
+ {
247
+ $this->_store = $store;
248
+ $this->_storeId = $store->getId();
249
+
250
+ return $this;
251
+ }
252
+
253
+ /**
254
+ * Get store
255
+ *
256
+ * @return Mage_Core_Model_Store
257
+ */
258
+ public function getStore()
259
+ {
260
+ return $this->_store;
261
+ }
262
+
263
+ /**
264
+ * Set store id
265
+ *
266
+ * @param $storeId
267
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Abstract
268
+ */
269
+ public function setStoreId($storeId)
270
+ {
271
+ $this->_storeId = $storeId;
272
+
273
+ return $this;
274
+ }
275
+
276
+ /**
277
+ * Get store id
278
+ *
279
+ * @return int
280
+ */
281
+ public function getStoreId()
282
+ {
283
+ return $this->_storeId;
284
+ }
285
+
286
+ /**
287
+ * Get order
288
+ *
289
+ * @return Mage_Sales_Model_Order
290
+ */
291
+ abstract public function getOrder();
292
+
293
+ /**
294
+ * Get payment
295
+ *
296
+ * @return Mage_Sales_Model_Order_Payment
297
+ */
298
+ abstract public function getPayment();
299
+
300
+ /**
301
+ * Convert eMAG order to magento order
302
+ */
303
+ abstract public function convert();
304
+
305
+ /**
306
+ * Prepare order data
307
+ *
308
+ * @return Mage_Sales_Model_Order
309
+ */
310
+ abstract protected function _prepareOrder();
311
+
312
+ /**
313
+ * Prepare products
314
+ *
315
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Abstract
316
+ */
317
+ abstract protected function _prepareProducts();
318
+
319
+ /**
320
+ * Prepare vouchers
321
+ *
322
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Abstract
323
+ */
324
+ abstract protected function _prepareVouchers();
325
+
326
+ /**
327
+ * Prepare customer
328
+ *
329
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Abstract
330
+ */
331
+ abstract protected function _prepareCustomer();
332
+
333
+ /**
334
+ * Prepare billing address
335
+ *
336
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Abstract
337
+ */
338
+ abstract protected function _prepareBillingAddress();
339
+
340
+ /**
341
+ * Prepare shipping address
342
+ *
343
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Abstract
344
+ */
345
+ abstract protected function _prepareShippingAddress();
346
+
347
+ /**
348
+ * Prepare shipping
349
+ *
350
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Abstract
351
+ */
352
+ abstract protected function _prepareShipping();
353
+
354
+ /**
355
+ * Prepare payment
356
+ *
357
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Abstract
358
+ */
359
+ abstract protected function _preparePayment();
360
+
361
+ /**
362
+ * Prepare customer comment
363
+ *
364
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Abstract
365
+ */
366
+ abstract protected function _prepareCustomerComment();
367
+
368
+ /**
369
+ * Re-read eMAG order
370
+ *
371
+ * @param Mage_Sales_Model_Order $sales
372
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Abstract
373
+ * @throws Innobyte_EmagMarketplace_Exception
374
+ */
375
+ public function reReadEmagOrder(Mage_Sales_Model_Order $sales)
376
+ {
377
+ Mage::register('is_emag_order_updated', true);
378
+
379
+ /** @var $store Mage_Core_Model_Store */
380
+ $store = $sales->getStore();
381
+
382
+ $data = array(
383
+ 'id' => $sales->getEmagOrderId()
384
+ );
385
+
386
+ try {
387
+ /** @var $response Innobyte_EmagMarketplace_Model_Api_Response */
388
+ $response = $this->getOrderApiModel()
389
+ ->setStoreId($sales->getStoreId())
390
+ ->setData($data)
391
+ ->read();
392
+
393
+ if ($response->isError()) {
394
+ throw new Innobyte_EmagMarketplace_Exception(
395
+ $this->getHelper()->__(
396
+ 'eMAG Api Response => %s', implode(',', $response->getMessages())
397
+ )
398
+ );
399
+ }
400
+
401
+ $emagOrders = $response->getResults();
402
+ foreach ($emagOrders as $emagOrder) {
403
+ /** @var $order Innobyte_EmagMarketplace_Model_Order_Convert_Emag_Update */
404
+ $order = Mage::getModel('innobyte_emag_marketplace/order_convert_emag_update');
405
+ $order->setOrder($sales);
406
+ $order->setStore($store);
407
+ $order->setEmagOrder($emagOrder);
408
+ $order->convert();
409
+ }
410
+ } catch (Innobyte_EmagMarketplace_Exception $e) {
411
+ throw new Innobyte_EmagMarketplace_Exception($e->getMessage());
412
+ } catch (Exception $e) {
413
+ Mage::throwException($e->getMessage());
414
+ }
415
+
416
+ return $this;
417
+ }
418
+
419
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Order/Convert/Emag.php ADDED
@@ -0,0 +1,768 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Order_Convert_Emag
5
+ * - convert eMAG order to Magento order
6
+ *
7
+ * @category Innobyte
8
+ * @package Innobyte_EmagMarketplace
9
+ *
10
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
11
+ */
12
+ class Innobyte_EmagMarketplace_Model_Order_Convert_Emag
13
+ extends Innobyte_EmagMarketplace_Model_Order_Convert_Abstract
14
+ {
15
+
16
+ /**
17
+ * Global currency code
18
+ *
19
+ * @var null
20
+ */
21
+ protected $_globalCurrencyCode = null;
22
+
23
+ /**
24
+ * Base currency
25
+ *
26
+ * @var null
27
+ */
28
+ protected $_baseCurrency = null;
29
+
30
+ /**
31
+ * Current currency
32
+ *
33
+ * @var null
34
+ */
35
+ protected $_currentCurrency = null;
36
+
37
+ /**
38
+ * Get order status
39
+ *
40
+ * @return bool|string
41
+ */
42
+ public function getOrderStatus()
43
+ {
44
+ $status = $this->getEmagOrder('status');
45
+ if (!array_key_exists($status, $this->_orderStatuses)) {
46
+ return false;
47
+ }
48
+
49
+ return $this->_orderStatuses[$status];
50
+ }
51
+
52
+ /**
53
+ * Get billing address
54
+ *
55
+ * @return Mage_Sales_Model_Order_Address
56
+ */
57
+ public function getBillingAddress()
58
+ {
59
+ return Mage::getModel('sales/order_address')
60
+ ->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_BILLING);
61
+ }
62
+
63
+ /**
64
+ * Get shipping address
65
+ *
66
+ * @return Mage_Sales_Model_Order_Address
67
+ */
68
+ public function getShippingAddress()
69
+ {
70
+ return Mage::getModel('sales/order_address')
71
+ ->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING);
72
+ }
73
+
74
+ /**
75
+ * Get payment method
76
+ *
77
+ * @param $method
78
+ * @return bool|string
79
+ */
80
+ public function getPaymentMethod($method)
81
+ {
82
+ if (!array_key_exists($method, $this->_paymentMethods)) {
83
+ return false;
84
+ }
85
+
86
+ return $this->_paymentMethods[$method];
87
+ }
88
+
89
+ /**
90
+ * Get eMAG order
91
+ *
92
+ * @param null|string $key
93
+ * @throws Innobyte_EmagMarketplace_Exception
94
+ * @return array|string
95
+ */
96
+ public function getEmagOrder($key = null)
97
+ {
98
+ if ($key) {
99
+ if (!isset($this->_emagOrder[$key])) {
100
+ throw new Innobyte_EmagMarketplace_Exception(
101
+ $this->getHelper()->__(
102
+ 'Order property "%s" not found!', $key
103
+ )
104
+ );
105
+ }
106
+ return $this->_emagOrder[$key];
107
+ }
108
+
109
+ return $this->_emagOrder;
110
+ }
111
+
112
+ /**
113
+ * Get order
114
+ *
115
+ * @return Mage_Sales_Model_Order
116
+ */
117
+ public function getOrder()
118
+ {
119
+ if (!$this->_order) {
120
+ $this->_order = Mage::getModel('sales/order');
121
+ }
122
+
123
+ return $this->_order;
124
+ }
125
+
126
+ /**
127
+ * Get global currency code
128
+ *
129
+ * @return null|string
130
+ */
131
+ public function getGlobalCurrencyCode()
132
+ {
133
+ if (!$this->_globalCurrencyCode) {
134
+ $this->_globalCurrencyCode = Mage::app()->getBaseCurrencyCode();
135
+ }
136
+
137
+ return $this->_globalCurrencyCode;
138
+ }
139
+
140
+ /**
141
+ * Get base currency
142
+ *
143
+ * @return Mage_Directory_Model_Currency
144
+ */
145
+ public function getBaseCurrency()
146
+ {
147
+ if (!$this->_baseCurrency) {
148
+ $this->_baseCurrency = $this->getStore()->getBaseCurrency();
149
+ }
150
+
151
+ return $this->_baseCurrency;
152
+ }
153
+
154
+ /**
155
+ * Get current currency
156
+ *
157
+ * @return Mage_Directory_Model_Currency
158
+ */
159
+ public function getCurrentCurrency()
160
+ {
161
+ if (!$this->_currentCurrency) {
162
+ $this->_currentCurrency = $this->getStore()->getCurrentCurrency();
163
+ }
164
+
165
+ return $this->_currentCurrency;
166
+ }
167
+
168
+ /**
169
+ * Get payment
170
+ *
171
+ * @return Mage_Sales_Model_Order_Payment
172
+ */
173
+ public function getPayment()
174
+ {
175
+ if (!$this->_payment) {
176
+ $this->_payment = Mage::getModel('sales/order_payment');
177
+ }
178
+
179
+ return $this->_payment;
180
+ }
181
+
182
+ /**
183
+ * Get eav config
184
+ *
185
+ * @return Mage_Eav_Model_Config
186
+ */
187
+ public function getEavConfig()
188
+ {
189
+ return Mage::getSingleton('eav/config');
190
+ }
191
+
192
+ /**
193
+ * Convert eMAG order to magento order
194
+ */
195
+ public function convert()
196
+ {
197
+ try {
198
+ /** @var $transaction Mage_Core_Model_Resource_Transaction */
199
+ $transaction = Mage::getModel('core/resource_transaction');
200
+
201
+ $this->_prepareOrder();
202
+ $this->_prepareCurrency();
203
+ $this->_prepareCurrencyRates();
204
+ $this->_prepareProducts();
205
+ $this->_prepareVouchers();
206
+ $this->_prepareCustomer();
207
+ $this->_prepareBillingAddress();
208
+ $this->_prepareShippingAddress();
209
+ $this->_prepareShipping();
210
+ $this->_preparePayment();
211
+ $this->_prepareCustomerComment();
212
+
213
+ $order = $this->getOrder();
214
+
215
+ $transaction->addObject($order);
216
+
217
+ $transaction->addCommitCallback(array($order, 'place'));
218
+ $transaction->addCommitCallback(array($order, 'save'));
219
+ $transaction->save();
220
+
221
+ //TODO: uncomment below line in final version; used to acknowledge order
222
+ $this->acknowledgeEmagOrder($this->getOrder());
223
+
224
+ } catch (Innobyte_EmagMarketplace_Exception $e) {
225
+ throw new Innobyte_EmagMarketplace_Exception($e->getMessage());
226
+ } catch (Exception $e) {
227
+ throw new Innobyte_EmagMarketplace_Exception($e->getMessage());
228
+ }
229
+ }
230
+
231
+ /**
232
+ * Prepare order data
233
+ *
234
+ * @throws Innobyte_EmagMarketplace_Exception
235
+ * @return Mage_Sales_Model_Order
236
+ */
237
+ protected function _prepareOrder()
238
+ {
239
+ $reservedOrderId = $this->getEavConfig()
240
+ ->getEntityType('order')
241
+ ->fetchNewIncrementId($this->getStoreId());
242
+
243
+ $status = $this->getOrderStatus();
244
+ if (!$status) {
245
+ throw new Innobyte_EmagMarketplace_Exception(
246
+ $this->getHelper()->__(
247
+ 'Invalid eMAG order status: %s', $status
248
+ )
249
+ );
250
+ }
251
+
252
+ $emagOrderId = $this->getEmagOrder('id');
253
+ $emagOrderDate = $this->getEmagOrder('date');
254
+
255
+ $this->getOrder()
256
+ ->setIncrementId($reservedOrderId)
257
+ ->setStoreId($this->getStoreId())
258
+ ->setQuoteId(0)
259
+ ->setCustomerGroupId(0)
260
+ ->setState(Mage_Sales_Model_Order::STATE_NEW)
261
+ ->setStatus($status)
262
+ ->setEmagOrderId($emagOrderId)
263
+ ->setEmagOrderDate($emagOrderDate);
264
+
265
+ return $this;
266
+ }
267
+
268
+ /**
269
+ * Prepare order currency
270
+ *
271
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Emag
272
+ */
273
+ protected function _prepareCurrency()
274
+ {
275
+ $this->getOrder()
276
+ ->setGlobalCurrencyCode($this->getGlobalCurrencyCode())
277
+ ->setBaseCurrencyCode($this->getBaseCurrency()->getCode())
278
+ ->setStoreCurrencyCode($this->getBaseCurrency()->getCode())
279
+ ->setOrderCurrencyCode($this->getCurrentCurrency()->getCode());
280
+
281
+ return $this;
282
+ }
283
+
284
+ /**
285
+ * Prepare currency rates
286
+ *
287
+ * @throws Innobyte_EmagMarketplace_Exception
288
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Emag
289
+ */
290
+ protected function _prepareCurrencyRates()
291
+ {
292
+ try {
293
+ $this->getOrder()
294
+ ->setBaseToGlobalRate($this->getBaseCurrency()->getRate($this->getGlobalCurrencyCode()))
295
+ ->setBaseToOrderRate($this->getBaseCurrency()->getRate($this->getCurrentCurrency()->getCode()));
296
+ } catch (Exception $e) {
297
+ throw new Innobyte_EmagMarketplace_Exception(
298
+ $this->getHelper()->__(
299
+ 'There was an error while processing currency rates: %s', $e->getMessage()
300
+ )
301
+ );
302
+ }
303
+
304
+ return $this;
305
+ }
306
+
307
+ /**
308
+ * Prepare products
309
+ *
310
+ * @throws Innobyte_EmagMarketplace_Exception
311
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Emag
312
+ */
313
+ protected function _prepareProducts()
314
+ {
315
+ try {
316
+ $emagProducts = $this->getEmagOrder('products');
317
+ if (!count($emagProducts)) {
318
+ throw new Innobyte_EmagMarketplace_Exception(
319
+ 'No products found in eMAG order!'
320
+ );
321
+ }
322
+
323
+ $subTotal = 0;
324
+ $baseSubTotal = 0;
325
+ $subtotalInclTax = 0;
326
+ $baseSubtotalInclTax = 0;
327
+ $totalQtyOrdered = 0;
328
+ $totalTaxAmount = 0;
329
+ $totalBaseTaxAmount = 0;
330
+
331
+ foreach ($emagProducts as $emagProduct) {
332
+ $currency = $emagProduct['currency'];
333
+ if ($currency != $this->getCurrentCurrency()->getCode()) {
334
+ throw new Innobyte_EmagMarketplace_Exception(
335
+ 'Store currency and eMAG currency codes do not match!'
336
+ );
337
+ }
338
+
339
+ $status = (int)$emagProduct['status'];
340
+ // continue to next product if product status is: canceled
341
+ if ($status == self::EMAG_PRODUCT_CANCELED) {
342
+ continue;
343
+ }
344
+
345
+ $sku = $emagProduct['part_number'];
346
+ $productId = (int)$emagProduct['product_id'];
347
+ /** @var $_product Mage_Catalog_Model_Product */
348
+ $_product = Mage::getModel('catalog/product')->load($productId);
349
+
350
+ if (!$_product->getId()) {
351
+ throw new Innobyte_EmagMarketplace_Exception(
352
+ $this->getHelper()->__(
353
+ 'Product with ID %s not found. eMAG - SKU: %s', $productId, $sku
354
+ )
355
+ );
356
+ }
357
+
358
+ $quantity = (float)$emagProduct['quantity'];
359
+ $vat = (float)$emagProduct['vat'];
360
+
361
+ $price = (float)$emagProduct['sale_price'];
362
+ $basePrice = (float)$this->_convertPriceToBaseCurrency($price);
363
+ $originalPrice = (float)$price;
364
+ $baseOriginalPrice = (float)$this->_convertPriceToBaseCurrency($originalPrice);
365
+ $taxAmount = (float)(($price * $vat) * $quantity);
366
+ $taxAmount = (float)$this->getStore()->roundPrice($taxAmount);
367
+ $baseTaxAmount = (float)$this->_convertPriceToBaseCurrency($taxAmount);
368
+ $rowTotal = (float)($price * $quantity);
369
+ $rowTotal = (float)$this->getStore()->roundPrice($rowTotal);
370
+ $baseRowTotal = (float)$this->_convertPriceToBaseCurrency($rowTotal);
371
+ $priceInclTax = (float)$price + $taxAmount;
372
+ $priceInclTax = (float)$this->getStore()->roundPrice($priceInclTax);
373
+ $basePriceInclTax = (float)$this->_convertPriceToBaseCurrency($priceInclTax);
374
+ $rowTotalInclTax = (float)$rowTotal + $taxAmount;
375
+ $rowTotalInclTax = (float)$this->getStore()->roundPrice($rowTotalInclTax);
376
+ $baseRowTotalInclTax = (float)$this->_convertPriceToBaseCurrency($rowTotalInclTax);
377
+
378
+ /** @var $orderItem Mage_Sales_Model_Order_Item */
379
+ $orderItem = Mage::getModel('sales/order_item');
380
+ $orderItem
381
+ ->setQuoteItemId(0)
382
+ ->setQuoteParentItemId(null)
383
+ ->setProductId($productId)
384
+ ->setProductType($_product->getTypeId())
385
+ ->setQtyBackordered(null)
386
+ ->setTotalQtyOrdered($quantity)
387
+ ->setQtyOrdered($quantity)
388
+ ->setName($_product->getName())
389
+ ->setSku($_product->getSku())
390
+ ->setPrice($price)
391
+ ->setBasePrice($basePrice)
392
+ ->setOriginalPrice($originalPrice)
393
+ ->setBaseOriginalPrice($baseOriginalPrice)
394
+ ->setTaxPercent($vat * 100)
395
+ ->setTaxAmount($taxAmount)
396
+ ->setBaseTaxAmount($baseTaxAmount)
397
+ ->setRowTotal($rowTotal)
398
+ ->setBaseRowTotal($baseRowTotal)
399
+ ->setPriceInclTax($priceInclTax)
400
+ ->setBasePriceInclTax($basePriceInclTax)
401
+ ->setRowTotalInclTax($rowTotalInclTax)
402
+ ->setBaseTotalInclTax($baseRowTotalInclTax)
403
+ ->setEmagDetails(json_encode($emagProduct['details']))
404
+ ->setEmagCreated($emagProduct['created'])
405
+ ->setEmagModified($emagProduct['modified']);
406
+
407
+ $this->getOrder()
408
+ ->addItem($orderItem);
409
+
410
+ $subTotal += $rowTotal;
411
+ $baseSubTotal += $baseRowTotal;
412
+ $subtotalInclTax += $rowTotalInclTax;
413
+ $baseSubtotalInclTax += $baseRowTotalInclTax;
414
+ $totalQtyOrdered += $quantity;
415
+ $totalTaxAmount += $taxAmount;
416
+ $totalBaseTaxAmount += $baseTaxAmount;
417
+ }
418
+
419
+ $grandTotal = $subTotal + $totalTaxAmount;
420
+ $baseGrandTotal = $this->_convertPriceToBaseCurrency($grandTotal);
421
+
422
+ $this->getOrder()
423
+ ->setSubtotal($subTotal)
424
+ ->setBaseSubtotal($baseSubTotal)
425
+ ->setSubtotalInclTax($subtotalInclTax)
426
+ ->setBaseSubtotalInclTax($baseSubtotalInclTax)
427
+ ->setTotalQtyOrdered($totalQtyOrdered)
428
+ ->setTaxAmount($totalTaxAmount)
429
+ ->setBaseTaxAmount($totalBaseTaxAmount)
430
+ ->setGrandTotal($grandTotal)
431
+ ->setBaseGrandTotal($baseGrandTotal);
432
+
433
+ } catch (Innobyte_EmagMarketplace_Exception $e) {
434
+ throw new Innobyte_EmagMarketplace_Exception($e->getMessage());
435
+ } catch (Exception $e) {
436
+ throw new Innobyte_EmagMarketplace_Exception(
437
+ $this->getHelper()->__(
438
+ 'There was an error while processing products: %s', $e->getMessage()
439
+ )
440
+ );
441
+ }
442
+
443
+ return $this;
444
+ }
445
+
446
+ /**
447
+ * Prepare vouchers
448
+ *
449
+ * @throws Innobyte_EmagMarketplace_Exception
450
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Emag
451
+ */
452
+ protected function _prepareVouchers()
453
+ {
454
+ try {
455
+ $emagVouchers = $this->getEmagOrder('vouchers');
456
+
457
+ $vouchers = array();
458
+ $voucherDiscount = 0;
459
+ $priceColumns = array('sale_price', 'sale_price_vat');
460
+ $columnPrefix = Innobyte_EmagMarketplace_Model_Sales_Voucher_Abstract::COLUMN_PREFIX;
461
+ foreach ($emagVouchers as $emagVoucher) {
462
+ $voucher = array();
463
+ foreach ($emagVoucher as $column => $value) {
464
+ $voucher[$columnPrefix . '_' . $column] = $value;
465
+ // add values for base currency
466
+ if (in_array($column, $priceColumns)) {
467
+ $voucher['base_' . $columnPrefix . '_' . $column] = $this->_convertPriceToBaseCurrency($value, false);
468
+ }
469
+ }
470
+ $vouchers[] = $voucher;
471
+
472
+ $salePrice = $emagVoucher['sale_price'];
473
+ $voucherDiscount += $salePrice;
474
+ }
475
+
476
+ $grandTotal = $this->getOrder()->getGrandTotal() + $voucherDiscount;
477
+ $grandTotal = (float)$this->getStore()->roundPrice($grandTotal);
478
+ $baseGrandTotal = $this->_convertPriceToBaseCurrency($grandTotal);
479
+
480
+ $this->getOrder()
481
+ ->setEmagVouchers($vouchers)
482
+ ->setGrandTotal($grandTotal)
483
+ ->setBaseGrandTotal($baseGrandTotal);
484
+ } catch (Exception $e) {
485
+ throw new Innobyte_EmagMarketplace_Exception(
486
+ $this->getHelper()->__(
487
+ 'There was an error while processing vouchers: %s', $e->getMessage()
488
+ )
489
+ );
490
+ }
491
+
492
+ return $this;
493
+ }
494
+
495
+ /**
496
+ * Prepare customer
497
+ *
498
+ * @throws Innobyte_EmagMarketplace_Exception
499
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Emag
500
+ */
501
+ protected function _prepareCustomer()
502
+ {
503
+ $emagCustomer = $this->getEmagOrder('customer');
504
+ if (empty($emagCustomer)) {
505
+ throw new Innobyte_EmagMarketplace_Exception(
506
+ 'Customer not found in eMAG order!'
507
+ );
508
+ }
509
+
510
+ $this->getOrder()
511
+ ->setEmagCustomerId($emagCustomer['id'])
512
+ ->setCustomerEmail($this->_prepareCustomerEmail())
513
+ ->setCustomerFirstname($emagCustomer['name'])
514
+ ->setEmagCustomerGender($emagCustomer['gender'])
515
+ ->setCustomerIsGuest(1);
516
+
517
+ return $this;
518
+ }
519
+
520
+ /**
521
+ * Prepare billing address
522
+ *
523
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Emag
524
+ */
525
+ protected function _prepareBillingAddress()
526
+ {
527
+ $emagCustomer = $this->getEmagOrder('customer');
528
+
529
+ $billingAddress = $this->getBillingAddress()
530
+ ->setFirstname($emagCustomer['name'])
531
+ ->setEmagBank($emagCustomer['bank'])
532
+ ->setEmagIban($emagCustomer['iban'])
533
+ ->setFax($emagCustomer['fax'])
534
+ ->setTelephone($emagCustomer['phone_1'])
535
+ ->setEmagTelephone2($emagCustomer['phone_2'])
536
+ ->setEmagTelephone3($emagCustomer['phone_3'])
537
+ ->setEmagCompanyCode($emagCustomer['code'])
538
+ ->setEmagCompanyRegNo($emagCustomer['registration_number'])
539
+ ->setCompany($emagCustomer['company'])
540
+ ->setCountryId($emagCustomer['billing_country'])
541
+ ->setRegion($emagCustomer['billing_suburb'])
542
+ ->setEmagLocalityId($emagCustomer['billing_locality_id'])
543
+ ->setCity($emagCustomer['billing_city'])
544
+ ->setStreet($emagCustomer['billing_street'])
545
+ ->setPostcode($emagCustomer['billing_postal_code'])
546
+ ->setEmagIsVatPayer($emagCustomer['is_vat_payer'])
547
+ ->setEmagLegalEntity($emagCustomer['legal_entity']);
548
+ $matchedRegion = $this->getHelper()->getMagentoRegion(
549
+ $emagCustomer['billing_suburb'],
550
+ $emagCustomer['billing_country']
551
+ );
552
+ if (!is_null($matchedRegion) && $matchedRegion->getId()) {
553
+ $billingAddress->setRegionId($matchedRegion->getId());
554
+ $billingAddress->setRegion($matchedRegion->getName());
555
+ }
556
+
557
+ $this->getOrder()
558
+ ->setBillingAddress($billingAddress);
559
+
560
+ return $this;
561
+ }
562
+
563
+ /**
564
+ * Prepare shipping address
565
+ *
566
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Emag
567
+ */
568
+ protected function _prepareShippingAddress()
569
+ {
570
+ $emagCustomer = $this->getEmagOrder('customer');
571
+
572
+ $shippingAddress = $this->getShippingAddress()
573
+ ->setFirstname($emagCustomer['name'])
574
+ ->setEmagBank($emagCustomer['bank'])
575
+ ->setEmagIban($emagCustomer['iban'])
576
+ ->setFax($emagCustomer['fax'])
577
+ ->setTelephone($emagCustomer['phone_1'])
578
+ ->setEmagTelephone2($emagCustomer['phone_2'])
579
+ ->setEmagTelephone3($emagCustomer['phone_3'])
580
+ ->setEmagCompanyCode($emagCustomer['code'])
581
+ ->setEmagCompanyRegNo($emagCustomer['registration_number'])
582
+ ->setCompany($emagCustomer['company'])
583
+ ->setCountryId($emagCustomer['shipping_country'])
584
+ ->setRegion($emagCustomer['shipping_suburb'])
585
+ ->setEmagLocalityId($emagCustomer['shipping_locality_id'])
586
+ ->setCity($emagCustomer['shipping_city'])
587
+ ->setStreet($emagCustomer['shipping_street'])
588
+ ->setPostcode($emagCustomer['shipping_postal_code'])
589
+ ->setEmagIsVatPayer($emagCustomer['is_vat_payer'])
590
+ ->setEmagLegalEntity($emagCustomer['legal_entity']);
591
+ $matchedRegion = $this->getHelper()->getMagentoRegion(
592
+ $emagCustomer['shipping_suburb'],
593
+ $emagCustomer['shipping_country']
594
+ );
595
+ if (!is_null($matchedRegion) && $matchedRegion->getId()) {
596
+ $shippingAddress->setRegionId($matchedRegion->getId());
597
+ $shippingAddress->setRegion($matchedRegion->getName());
598
+ }
599
+
600
+ $this->getOrder()
601
+ ->setShippingAddress($shippingAddress);
602
+
603
+ return $this;
604
+ }
605
+
606
+ /**
607
+ * Prepare shipping
608
+ *
609
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Emag
610
+ */
611
+ protected function _prepareShipping()
612
+ {
613
+ $shippingAmount = $this->getEmagOrder('shipping_tax');
614
+ $baseShippingAmount = $this->_convertPriceToBaseCurrency($shippingAmount);
615
+
616
+ $grandTotal = $this->getOrder()->getGrandTotal() + $shippingAmount;
617
+ $baseGrandTotal = $this->getOrder()->getBaseGrandTotal() + $baseShippingAmount;
618
+
619
+ $rate = Mage::getModel('innobyte_emag_marketplace/shipping_carrier')
620
+ ->collectRates(null);
621
+ $this->getOrder()
622
+ ->setShippingMethod($rate->getCarrier() . '_' . $rate->getMethod())
623
+ ->setShippingAmount($shippingAmount)
624
+ ->setShippingDescription(trim($rate->getCarrierTitle() . ' - ' . $rate->getMethodTitle(), '-'))
625
+ ->setBaseShippingAmount($baseShippingAmount)
626
+ ->setGrandTotal($grandTotal)
627
+ ->setBaseGrandTotal($baseGrandTotal);
628
+
629
+ return $this;
630
+ }
631
+
632
+ /**
633
+ * Prepare payment
634
+ *
635
+ * @throws Innobyte_EmagMarketplace_Exception
636
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Emag
637
+ */
638
+ protected function _preparePayment()
639
+ {
640
+ try {
641
+ $paymentStatus = $this->getEmagOrder('payment_status');
642
+ $paymentMethod = $this->getEmagOrder('payment_mode_id');
643
+
644
+ $method = $this->getPaymentMethod($paymentMethod);
645
+ if (!$method) {
646
+ throw new Innobyte_EmagMarketplace_Exception(
647
+ $this->getHelper()->__(
648
+ 'Invalid eMag payment method: %s', $method
649
+ )
650
+ );
651
+ }
652
+
653
+ $payment = $this->getPayment();
654
+ $payment->setStoreId($this->getStoreId())
655
+ ->setCustomerPaymentId(0)
656
+ ->setMethod($method);
657
+
658
+ $this->getOrder()
659
+ ->setEmagPaymentStatus($paymentStatus)
660
+ ->setPayment($payment);
661
+ } catch (Innobyte_EmagMarketplace_Exception $e) {
662
+ throw new Innobyte_EmagMarketplace_Exception($e->getMessage());
663
+ } catch (Exception $e) {
664
+ throw new Innobyte_EmagMarketplace_Exception(
665
+ $this->getHelper()->__(
666
+ 'There was an error while processing payment: %s', $e->getMessage()
667
+ )
668
+ );
669
+ }
670
+
671
+ return $this;
672
+ }
673
+
674
+ /**
675
+ * Prepare customer comment
676
+ *
677
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Emag
678
+ */
679
+ protected function _prepareCustomerComment()
680
+ {
681
+ $comment = $this->getEmagOrder('observation');
682
+
683
+ $this->getOrder()
684
+ ->setEmagCustomerComment($comment);
685
+
686
+ return $this;
687
+ }
688
+
689
+ /**
690
+ * Convert price to base currency
691
+ *
692
+ * @param float $price
693
+ * @param bool $round
694
+ * @return float
695
+ */
696
+ protected function _convertPriceToBaseCurrency($price, $round = true)
697
+ {
698
+ $baseCurrency = $this->getBaseCurrency()->getCode();
699
+ $currentCurrency = $this->getCurrentCurrency()->getCode();
700
+
701
+ $rates = $this->_getCurrencyRates($baseCurrency);
702
+ $price = $price / $rates[$currentCurrency];
703
+
704
+ if ($round) {
705
+ return $this->getStore()->roundPrice($price);
706
+ }
707
+
708
+ return $price;
709
+ }
710
+
711
+ /**
712
+ * Get currency rates
713
+ *
714
+ * @param $currency
715
+ * @return array
716
+ */
717
+ protected function _getCurrencyRates($currency)
718
+ {
719
+ /** @var $model Mage_Directory_Model_Currency */
720
+ $model = Mage::getModel('directory/currency');
721
+ $allowedCurrencies = $model->getConfigAllowCurrencies();
722
+ $rates = $model->getCurrencyRates($currency, $allowedCurrencies);
723
+
724
+ return $rates;
725
+ }
726
+
727
+ /**
728
+ * Prepare customer email
729
+ *
730
+ * @return string
731
+ */
732
+ private function _prepareCustomerEmail()
733
+ {
734
+ return 'customer.eMAG.'
735
+ . $this->getOrder()->getEmagOrderId()
736
+ . '@' . $this->getHelper()->getEmagDomain($this->getStore()->getId());
737
+ }
738
+
739
+ /**
740
+ * Acknowledge eMAG order
741
+ *
742
+ * @param Mage_Sales_Model_Order $order
743
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
744
+ * @throws Innobyte_EmagMarketplace_Exception
745
+ */
746
+ public function acknowledgeEmagOrder(Mage_Sales_Model_Order $order)
747
+ {
748
+ /** @var $response Innobyte_EmagMarketplace_Model_Api_Response */
749
+ $response = $this->getOrderApiModel()
750
+ ->setStoreId($order->getStoreId())
751
+ ->setEmagOrderId($order->getEmagOrderId())
752
+ ->acknowledge();
753
+
754
+ if ($response->isError()) {
755
+ throw new Innobyte_EmagMarketplace_Exception(
756
+ $this->getHelper()->__(
757
+ 'There was an error while trying to acknowledge eMAG order: %s',
758
+ implode(',', $response->getMessages())
759
+ )
760
+ );
761
+ }
762
+
763
+ $this->reReadEmagOrder($order);
764
+
765
+ return $this;
766
+ }
767
+
768
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Order/Convert/Emag/Update.php ADDED
@@ -0,0 +1,296 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Order_Convert_Emag_Update
5
+ * - convert eMAG order to Magento order
6
+ *
7
+ * @category Innobyte
8
+ * @package Innobyte_EmagMarketplace
9
+ *
10
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
11
+ */
12
+ class Innobyte_EmagMarketplace_Model_Order_Convert_Emag_Update
13
+ extends Innobyte_EmagMarketplace_Model_Order_Convert_Emag
14
+ {
15
+
16
+ /**
17
+ * Get order
18
+ *
19
+ * @return Mage_Sales_Model_Order
20
+ * @throws Innobyte_EmagMarketplace_Exception
21
+ */
22
+ public function getOrder()
23
+ {
24
+ return $this->_order;
25
+ }
26
+
27
+ /**
28
+ * Get billing address
29
+ *
30
+ * @return Mage_Sales_Model_Order_Address
31
+ */
32
+ public function getBillingAddress()
33
+ {
34
+ return $this->getOrder()->getBillingAddress();
35
+ }
36
+
37
+ /**
38
+ * Get shipping address
39
+ *
40
+ * @return Mage_Sales_Model_Order_Address
41
+ */
42
+ public function getShippingAddress()
43
+ {
44
+ return $this->getOrder()->getShippingAddress();
45
+ }
46
+
47
+ /**
48
+ * Get payment
49
+ *
50
+ * @return Mage_Sales_Model_Order_Payment
51
+ */
52
+ public function getPayment()
53
+ {
54
+ if (!$this->_payment) {
55
+ $this->_payment = $this->getOrder()->getPayment();
56
+ }
57
+
58
+ return $this->_payment;
59
+ }
60
+
61
+ /**
62
+ * Convert eMAG order to magento order
63
+ */
64
+ public function convert()
65
+ {
66
+ try {
67
+ /** @var $transaction Mage_Core_Model_Resource_Transaction */
68
+ $transaction = Mage::getModel('core/resource_transaction');
69
+
70
+ $this->_prepareOrder();
71
+ $this->_prepareCurrencyRates();
72
+ $this->_prepareProducts();
73
+ $this->_prepareVouchers();
74
+ $this->_prepareCustomer();
75
+ $this->_prepareBillingAddress();
76
+ $this->_prepareShippingAddress();
77
+ $this->_prepareShipping();
78
+ $this->_preparePayment();
79
+ $this->_prepareCustomerComment();
80
+
81
+ $order = $this->getOrder();
82
+
83
+ $transaction->addObject($order);
84
+
85
+ $transaction->addCommitCallback(array($order, 'save'));
86
+ $transaction->save();
87
+ } catch (Innobyte_EmagMarketplace_Exception $e) {
88
+ throw new Innobyte_EmagMarketplace_Exception($e->getMessage());
89
+ } catch (Exception $e) {
90
+ throw new Innobyte_EmagMarketplace_Exception($e->getMessage());
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Prepare order
96
+ *
97
+ * @throws Innobyte_EmagMarketplace_Exception
98
+ * @return Mage_Sales_Model_Order
99
+ */
100
+ protected function _prepareOrder()
101
+ {
102
+ // exit if order is invalid
103
+ if (!$this->getOrder()->getId()) {
104
+ throw new Innobyte_EmagMarketplace_Exception(
105
+ 'eMAG order update failed. Invalid Magento Order!'
106
+ );
107
+ }
108
+
109
+ $status = $this->getOrderStatus();
110
+ if (!$status) {
111
+ throw new Innobyte_EmagMarketplace_Exception(
112
+ $this->getHelper()->__(
113
+ 'Invalid eMAG order status: %s', $status
114
+ )
115
+ );
116
+ }
117
+ $state = $this->getStatusState($status);
118
+
119
+ $this->getOrder()->setState($state);
120
+ $this->getOrder()->setStatus($status);
121
+
122
+ return $this;
123
+ }
124
+
125
+ /**
126
+ * Prepare products
127
+ *
128
+ * @throws Innobyte_EmagMarketplace_Exception
129
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Emag
130
+ */
131
+ protected function _prepareProducts()
132
+ {
133
+ try {
134
+ $emagProducts = $this->getEmagOrder('products');
135
+ if (!count($emagProducts)) {
136
+ throw new Innobyte_EmagMarketplace_Exception(
137
+ 'No products found in eMAG order!'
138
+ );
139
+ }
140
+
141
+ $subTotal = 0;
142
+ $baseSubTotal = 0;
143
+ $subtotalInclTax = 0;
144
+ $baseSubtotalInclTax = 0;
145
+ $totalQtyOrdered = 0;
146
+ $totalTaxAmount = 0;
147
+ $totalBaseTaxAmount = 0;
148
+
149
+ foreach ($emagProducts as $emagProduct) {
150
+ $currency = $emagProduct['currency'];
151
+ if ($currency != $this->getCurrentCurrency()->getCode()) {
152
+ throw new Innobyte_EmagMarketplace_Exception(
153
+ 'Store currency and eMAG currency codes do not match!'
154
+ );
155
+ }
156
+
157
+ $sku = $emagProduct['part_number'];
158
+ $productId = (int)$emagProduct['product_id'];
159
+
160
+ /** @var $orderItem Mage_Sales_Model_Order_Item */
161
+ $orderItem = Mage::getModel('sales/order_item');
162
+ $items = $this->getOrder()->getAllItems();
163
+ foreach ($items as $item) {
164
+ if ($item->getProductId() == $productId) {
165
+ $orderItem = $item;
166
+ break;
167
+ }
168
+ }
169
+
170
+ $status = (int)$emagProduct['status'];
171
+ // continue to next product if product status is: canceled
172
+ if ($status == self::EMAG_PRODUCT_CANCELED) {
173
+ $orderItem->isDeleted(true);
174
+ continue;
175
+ }
176
+
177
+ /** @var $_product Mage_Catalog_Model_Product */
178
+ $_product = Mage::getModel('catalog/product')->load($productId);
179
+
180
+ if (!$_product->getId()) {
181
+ throw new Innobyte_EmagMarketplace_Exception(
182
+ $this->getHelper()->__(
183
+ 'Product with ID %s not found. eMAG - SKU: %s', $productId, $sku
184
+ )
185
+ );
186
+ }
187
+
188
+ $quantity = (float)$emagProduct['quantity'];
189
+ $vat = (float)$emagProduct['vat'];
190
+
191
+ $price = (float)$emagProduct['sale_price'];
192
+ $basePrice = (float)$this->_convertPriceToBaseCurrency($price);
193
+ $originalPrice = (float)$price;
194
+ $baseOriginalPrice = (float)$this->_convertPriceToBaseCurrency($originalPrice);
195
+ $taxAmount = (float)(($price * $vat) * $quantity);
196
+ $taxAmount = (float)$this->getStore()->roundPrice($taxAmount);
197
+ $baseTaxAmount = (float)$this->_convertPriceToBaseCurrency($taxAmount);
198
+ $rowTotal = (float)($price * $quantity);
199
+ $rowTotal = (float)$this->getStore()->roundPrice($rowTotal);
200
+ $baseRowTotal = (float)$this->_convertPriceToBaseCurrency($rowTotal);
201
+ $priceInclTax = (float)$price + $taxAmount;
202
+ $priceInclTax = (float)$this->getStore()->roundPrice($priceInclTax);
203
+ $basePriceInclTax = (float)$this->_convertPriceToBaseCurrency($priceInclTax);
204
+ $rowTotalInclTax = (float)$rowTotal + $taxAmount;
205
+ $rowTotalInclTax = (float)$this->getStore()->roundPrice($rowTotalInclTax);
206
+ $baseRowTotalInclTax = (float)$this->_convertPriceToBaseCurrency($rowTotalInclTax);
207
+
208
+ $orderItem
209
+ ->setQuoteItemId(0)
210
+ ->setQuoteParentItemId(null)
211
+ ->setProductId($productId)
212
+ ->setProductType($_product->getTypeId())
213
+ ->setQtyBackordered(null)
214
+ ->setTotalQtyOrdered($quantity)
215
+ ->setQtyOrdered($quantity)
216
+ ->setName($_product->getName())
217
+ ->setSku($_product->getSku())
218
+ ->setPrice($price)
219
+ ->setBasePrice($basePrice)
220
+ ->setOriginalPrice($originalPrice)
221
+ ->setBaseOriginalPrice($baseOriginalPrice)
222
+ ->setTaxPercent($vat * 100)
223
+ ->setTaxAmount($taxAmount)
224
+ ->setBaseTaxAmount($baseTaxAmount)
225
+ ->setRowTotal($rowTotal)
226
+ ->setBaseRowTotal($baseRowTotal)
227
+ ->setPriceInclTax($priceInclTax)
228
+ ->setBasePriceInclTax($basePriceInclTax)
229
+ ->setRowTotalInclTax($rowTotalInclTax)
230
+ ->setBaseTotalInclTax($baseRowTotalInclTax)
231
+ ->setEmagDetails(json_encode($emagProduct['details']))
232
+ ->setEmagCreated($emagProduct['created'])
233
+ ->setEmagModified($emagProduct['modified']);
234
+
235
+ // add item to order only if it's not already added
236
+ if (!$orderItem->getId()) {
237
+ $this->getOrder()
238
+ ->addItem($orderItem);
239
+ }
240
+
241
+ $subTotal += $rowTotal;
242
+ $baseSubTotal += $baseRowTotal;
243
+ $subtotalInclTax += $rowTotalInclTax;
244
+ $baseSubtotalInclTax += $baseRowTotalInclTax;
245
+ $totalQtyOrdered += $quantity;
246
+ $totalTaxAmount += $taxAmount;
247
+ $totalBaseTaxAmount += $baseTaxAmount;
248
+ }
249
+
250
+ $grandTotal = $subTotal + $totalTaxAmount;
251
+ $baseGrandTotal = $this->_convertPriceToBaseCurrency($grandTotal);
252
+
253
+ $this->getOrder()
254
+ ->setSubtotal($subTotal)
255
+ ->setBaseSubtotal($baseSubTotal)
256
+ ->setSubtotalInclTax($subtotalInclTax)
257
+ ->setBaseSubtotalInclTax($baseSubtotalInclTax)
258
+ ->setTotalQtyOrdered($totalQtyOrdered)
259
+ ->setTaxAmount($totalTaxAmount)
260
+ ->setBaseTaxAmount($totalBaseTaxAmount)
261
+ ->setGrandTotal($grandTotal)
262
+ ->setBaseGrandTotal($baseGrandTotal);
263
+
264
+ } catch (Innobyte_EmagMarketplace_Exception $e) {
265
+ throw new Innobyte_EmagMarketplace_Exception($e->getMessage());
266
+ } catch (Exception $e) {
267
+ throw new Innobyte_EmagMarketplace_Exception(
268
+ $this->getHelper()->__(
269
+ 'There was an error while processing products: %s', $e->getMessage()
270
+ )
271
+ );
272
+ }
273
+
274
+ return $this;
275
+ }
276
+
277
+ /**
278
+ * Prepare vouchers
279
+ * - mark old vouchers as deleted
280
+ *
281
+ * @throws Innobyte_EmagMarketplace_Exception
282
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Emag
283
+ */
284
+ protected function _prepareVouchers()
285
+ {
286
+ $vouchers = $this->getOrder()->getEmagVouchers();
287
+ if (is_array($vouchers)) {
288
+ foreach ($vouchers as $voucher) {
289
+ $voucher['isDeleted'] = true;
290
+ }
291
+ }
292
+
293
+ return parent::_prepareVouchers();
294
+ }
295
+
296
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Order/Convert/Magento.php ADDED
@@ -0,0 +1,1066 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Order_Convert_Magento
5
+ * - convert Magento order to eMAG order
6
+ *
7
+ * @category Innobyte
8
+ * @package Innobyte_EmagMarketplace
9
+ *
10
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
11
+ */
12
+ class Innobyte_EmagMarketplace_Model_Order_Convert_Magento
13
+ extends Innobyte_EmagMarketplace_Model_Order_Convert_Abstract
14
+ {
15
+
16
+ /**
17
+ * Order status
18
+ *
19
+ * @var null
20
+ */
21
+ protected $_status = null;
22
+
23
+ /**
24
+ * Customer
25
+ *
26
+ * @var array
27
+ */
28
+ protected $_customer = array();
29
+
30
+ /**
31
+ * Products
32
+ *
33
+ * @var array
34
+ */
35
+ protected $_products = array();
36
+
37
+ /**
38
+ * Invoices/creditmemos
39
+ *
40
+ * @var array
41
+ */
42
+ protected $_invoices = array();
43
+
44
+ /**
45
+ * Currency
46
+ *
47
+ * @var null
48
+ */
49
+ protected $_currency = null;
50
+
51
+ /**
52
+ * Current order products
53
+ *
54
+ * @var array
55
+ */
56
+ protected $_currentOrderProducts = array();
57
+
58
+ /**
59
+ * Get store id from order
60
+ *
61
+ * @return int
62
+ */
63
+ public function getStoreId()
64
+ {
65
+ if (!$this->_storeId) {
66
+ $this->_storeId = $this->getOrder()->getStoreId();
67
+ }
68
+
69
+ return $this->_storeId;
70
+ }
71
+
72
+ /**
73
+ * Set order status
74
+ *
75
+ * @param $status
76
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Magento
77
+ */
78
+ public function setStatus($status)
79
+ {
80
+ $this->_status = $status;
81
+
82
+ return $this;
83
+ }
84
+
85
+ /**
86
+ * Set customer
87
+ *
88
+ * @param $customer
89
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Magento
90
+ */
91
+ public function setCustomer($customer)
92
+ {
93
+ $this->_customer = $customer;
94
+
95
+ return $this;
96
+ }
97
+
98
+ /**
99
+ * Set products for eMAG order
100
+ *
101
+ * @param $products
102
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Magento
103
+ */
104
+ public function setProducts($products)
105
+ {
106
+ $this->_products = $products;
107
+
108
+ return $this;
109
+ }
110
+
111
+ /**
112
+ * Set currency
113
+ *
114
+ * @param $currency
115
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Magento
116
+ */
117
+ public function setCurrency($currency)
118
+ {
119
+ $this->_currency = $currency;
120
+
121
+ return $this;
122
+ }
123
+
124
+ /**
125
+ * Get order id
126
+ *
127
+ * @return int
128
+ */
129
+ public function getOrderId()
130
+ {
131
+ return $this->_orderId;
132
+ }
133
+
134
+ /**
135
+ * Get order status
136
+ *
137
+ * @return string
138
+ */
139
+ public function getStatus()
140
+ {
141
+ return $this->_status;
142
+ }
143
+
144
+ /**
145
+ * Get customer
146
+ *
147
+ * @return array
148
+ */
149
+ public function getCustomer()
150
+ {
151
+ return $this->_customer;
152
+ }
153
+
154
+ /**
155
+ * Get products
156
+ *
157
+ * @return array
158
+ */
159
+ public function getProducts()
160
+ {
161
+ return $this->_products;
162
+ }
163
+
164
+ /**
165
+ * Add product
166
+ *
167
+ * @param $product
168
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Magento
169
+ */
170
+ protected function _addProduct($product)
171
+ {
172
+ $this->_products[] = $product;
173
+
174
+ return $this;
175
+ }
176
+
177
+ /**
178
+ * Get invoices/creditmemos
179
+ *
180
+ * @return array
181
+ */
182
+ public function getInvoices()
183
+ {
184
+ return $this->_invoices;
185
+ }
186
+
187
+ /**
188
+ * Add invoice/creditmemo
189
+ *
190
+ * @param $invoice
191
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Magento
192
+ */
193
+ protected function _addInvoice($invoice)
194
+ {
195
+ $this->_invoices[] = $invoice;
196
+
197
+ return $this;
198
+ }
199
+
200
+ /**
201
+ * Get order currency
202
+ *
203
+ * @return Mage_Directory_Model_Currency
204
+ */
205
+ public function getCurrency()
206
+ {
207
+ if (!$this->_currency) {
208
+ $this->_currency = $this->getOrder()->getOrderCurrency();
209
+ }
210
+
211
+ return $this->_currency;
212
+ }
213
+
214
+ /**
215
+ * Get order status
216
+ *
217
+ * @return bool|int
218
+ */
219
+ public function getOrderStatus()
220
+ {
221
+ $status = $this->getStatus();
222
+ if (is_null($status)) {
223
+ $status = $this->getOrder()->getStatus();
224
+ }
225
+
226
+ $statuses = array_flip($this->_orderStatuses);
227
+
228
+ if (!array_key_exists($status, $statuses)) {
229
+ return false;
230
+ }
231
+
232
+ return $statuses[$status];
233
+ }
234
+
235
+ /**
236
+ * Get payment method
237
+ *
238
+ * @param $method
239
+ * @return bool|int
240
+ */
241
+ public function getPaymentMethod($method)
242
+ {
243
+ $paymentMethods = array_flip($this->_paymentMethods);
244
+ if (!array_key_exists($method, $paymentMethods)) {
245
+ return false;
246
+ }
247
+
248
+ return $paymentMethods[$method];
249
+ }
250
+
251
+ /**
252
+ * Get eMAG order
253
+ *
254
+ * @return Varien_Object
255
+ */
256
+ public function getEmagOrder()
257
+ {
258
+ if (!$this->_emagOrder) {
259
+ $this->_emagOrder = new Varien_Object();
260
+ }
261
+
262
+ return $this->_emagOrder;
263
+ }
264
+
265
+ /**
266
+ * Get order
267
+ *
268
+ * @return Mage_Sales_Model_Order
269
+ */
270
+ public function getOrder()
271
+ {
272
+ if (!$this->_order) {
273
+ $this->_order = Mage::getModel('sales/order')->load($this->getOrderId());
274
+ }
275
+
276
+ return $this->_order;
277
+ }
278
+
279
+ /**
280
+ * Get payment
281
+ *
282
+ * @return Mage_Sales_Model_Order_Payment
283
+ */
284
+ public function getPayment()
285
+ {
286
+ if (!$this->_payment) {
287
+ $this->_payment = $this->getOrder()->getPayment();
288
+ }
289
+
290
+ return $this->_payment;
291
+ }
292
+
293
+ /**
294
+ * Get entity model
295
+ *
296
+ * @return Mage_Eav_Model_Entity_Store
297
+ */
298
+ public function getEntityModel()
299
+ {
300
+ return Mage::getModel('eav/entity_store');
301
+ }
302
+
303
+ /**
304
+ * Get entity type model
305
+ *
306
+ * @param $entityType
307
+ * @return Mage_Eav_Model_Entity_Type
308
+ */
309
+ public function getEntityTypeModel($entityType)
310
+ {
311
+ return Mage::getModel('eav/config')->getEntityType($entityType);
312
+ }
313
+
314
+ /**
315
+ * Invoice/creditmemo prefix
316
+ *
317
+ * @param $entityType
318
+ * @return string
319
+ */
320
+ public function getEntityPrefix($entityType)
321
+ {
322
+ $entityModel = $this->getEntityModel()
323
+ ->loadByEntityStore(
324
+ $this->getEntityTypeModel($entityType)->getEntityTypeId(),
325
+ $this->getStoreId()
326
+ );
327
+
328
+ return $entityModel->getIncrementPrefix();
329
+ }
330
+
331
+ /**
332
+ * Convert magento order to eMAG order
333
+ *
334
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Magento
335
+ * @throws Innobyte_EmagMarketplace_Exception
336
+ */
337
+ public function convert()
338
+ {
339
+ try {
340
+ $this->_prepareOrder();
341
+ $this->_prepareCustomer();
342
+ $this->_prepareBillingAddress();
343
+ $this->_prepareShippingAddress();
344
+ $this->_prepareShipping();
345
+ $this->_prepareProducts();
346
+ //TODO: uncomment if magento native invoices need to be sent to eMAG
347
+ //$this->_prepareInvoices();
348
+ $this->_prepareVouchers();
349
+ $this->_preparePayment();
350
+ $this->_prepareCustomerComment();
351
+ $this->_prepareAttachments();
352
+
353
+ $data['order'] = $this->getEmagOrder()->toArray();
354
+
355
+ $api = $this->getOrderApiModel();
356
+ $response = $api->setStoreId($this->getStoreId())
357
+ ->setData($data)
358
+ ->save();
359
+
360
+ if ($response->isError()) {
361
+ throw new Innobyte_EmagMarketplace_Exception(
362
+ $this->getHelper()->__(
363
+ 'eMAG Api Response => %s', implode(',', $response->getMessages())
364
+ )
365
+ );
366
+ }
367
+
368
+ $this->reReadEmagOrder($this->getOrder());
369
+ } catch (Innobyte_EmagMarketplace_Exception $e) {
370
+ throw new Innobyte_EmagMarketplace_Exception($e->getMessage());
371
+ } catch (Exception $e) {
372
+ Mage::log($e->getMessage(), Zend_Log::ERR, $this->getHelper()->getResourceLogFile('order'), $this->_isDebug());
373
+ throw new Innobyte_EmagMarketplace_Exception(
374
+ $this->getHelper()->__(
375
+ 'There was an error while processing order: #%s', $this->getOrder()->getIncrementId()
376
+ )
377
+ );
378
+ }
379
+
380
+ return $this;
381
+ }
382
+
383
+ /**
384
+ * Prepare order data
385
+ *
386
+ * @throws Innobyte_EmagMarketplace_Exception
387
+ * @return Mage_Sales_Model_Order
388
+ */
389
+ protected function _prepareOrder()
390
+ {
391
+ try {
392
+ $orderId = $this->getOrder()->getEmagOrderId();
393
+ $orderDate = $this->getOrder()->getEmagOrderDate();
394
+ $orderStatus = $this->getOrderStatus();
395
+
396
+ if (!$orderStatus) {
397
+ throw new Innobyte_EmagMarketplace_Exception(
398
+ $this->getHelper()->__(
399
+ 'Invalid Magento order status: %s', $this->getOrder()->getStatus()
400
+ )
401
+ );
402
+ }
403
+
404
+ $vendorName = $this->getHelper()->getClientCode($this->getStoreId());
405
+
406
+ $this->getEmagOrder()
407
+ ->setId($orderId)
408
+ ->setDate($orderDate)
409
+ ->setStatus($orderStatus)
410
+ ->setVendorName($vendorName);
411
+ } catch (Exception $e) {
412
+ throw new Innobyte_EmagMarketplace_Exception($e->getMessage());
413
+ }
414
+
415
+ return $this;
416
+ }
417
+
418
+ /**
419
+ * Prepare products
420
+ * - add current products to eMAG order
421
+ * - on edit check if any products from parent order are not present in current order
422
+ *
423
+ * @throws Innobyte_EmagMarketplace_Exception
424
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Magento
425
+ */
426
+ protected function _prepareProducts()
427
+ {
428
+ try {
429
+ $items = $this->getOrder()->getAllItems();
430
+ foreach ($items as $item) {
431
+ $product = $this->_processOrderItem($item);
432
+ $this->_addProduct($product);
433
+ $this->_currentOrderProducts[] = $item->getProductId();
434
+ }
435
+
436
+ if ($this->_isEdited()) {
437
+ $this->_processCanceledProducts();
438
+ }
439
+
440
+ $this->getEmagOrder()
441
+ ->setProducts($this->getProducts());
442
+ } catch (Exception $e) {
443
+ Mage::log($e->getMessage(), Zend_Log::ERR, $this->getHelper()->getResourceLogFile('order'), $this->_isDebug());
444
+ throw new Innobyte_EmagMarketplace_Exception(
445
+ 'There was an error while processing order products!'
446
+ );
447
+ }
448
+
449
+ return $this;
450
+ }
451
+
452
+ /**
453
+ * Check if order was edited
454
+ *
455
+ * @return bool
456
+ */
457
+ private function _isEdited()
458
+ {
459
+ if ($this->getOrder()->getRelationParentId()) {
460
+ return true;
461
+ }
462
+
463
+ return false;
464
+ }
465
+
466
+ /**
467
+ * Check if any products where canceled
468
+ *
469
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Magento
470
+ */
471
+ protected function _processCanceledProducts()
472
+ {
473
+ /** @var $parentOrder Mage_Sales_Model_Order */
474
+ $parentOrder = Mage::getModel('sales/order')
475
+ ->load($this->getOrder()->getRelationParentId());
476
+
477
+ /** @var $item Mage_Sales_Model_Order_Item */
478
+ foreach ($parentOrder->getAllVisibleItems() as $item) {
479
+ if (!in_array($item->getProductId(), $this->_currentOrderProducts)) {
480
+ $product = $this->_processOrderItem($item, true);
481
+ $this->_addProduct($product);
482
+ }
483
+ }
484
+
485
+ return $this;
486
+ }
487
+
488
+ /**
489
+ * Convert order item to eMAG product
490
+ *
491
+ * @param Mage_Sales_Model_Order_Item $item
492
+ * @param bool $canceled
493
+ * @return array
494
+ */
495
+ private function _processOrderItem(Mage_Sales_Model_Order_Item $item, $canceled = false)
496
+ {
497
+ $status = Innobyte_EmagMarketplace_Model_Product::PRODUCT_STATUS_AVAILABLE;
498
+ if ($canceled) {
499
+ $status = Innobyte_EmagMarketplace_Model_Product::PRODUCT_STATUS_CANCELED;
500
+ }
501
+
502
+ $product = array(
503
+ 'product_id' => $item->getProductId(),
504
+ 'part_number' => $item->getSku(),
505
+ 'quantity' => $item->getQtyOrdered(),
506
+ 'sale_price' => $item->getPrice,
507
+ 'currency' => $this->getCurrency()->getCode(),
508
+ 'created' => $item->getEmagCreated(),
509
+ 'modified' => $item->getEmagModified(),
510
+ 'status' => $status,
511
+ 'attachments' => array(), // attachment field will be empty at product level; all attachments are attached to order
512
+ 'details' => json_decode($item->getEmagDetails()),
513
+ 'vat' => number_format($item->getTaxPercent() / 100, 4),
514
+ );
515
+
516
+ return $product;
517
+ }
518
+
519
+ /**
520
+ * Prepare vouchers
521
+ *
522
+ * @throws Innobyte_EmagMarketplace_Exception
523
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Magento
524
+ */
525
+ protected function _prepareVouchers()
526
+ {
527
+ $vouchers = array();
528
+ $emagVouchers = $this->getOrder()->getEmagVouchers();
529
+
530
+ if (!is_array($emagVouchers)) {
531
+ return $this;
532
+ }
533
+
534
+ try {
535
+ foreach ($emagVouchers as $emagVoucher) {
536
+ $voucher = array();
537
+ foreach ($emagVoucher as $key => $value) {
538
+
539
+ if (strpos($key, 'base_') !== false) {
540
+ unset($emagVoucher[$key]);
541
+ continue;
542
+ }
543
+
544
+ $column = $this->_removeColumnPrefix($key);
545
+ $voucher[$column] = $emagVoucher[$key];
546
+ }
547
+ $vouchers[] = $voucher;
548
+ }
549
+
550
+ $this->getEmagOrder()
551
+ ->setVouchers($vouchers);
552
+
553
+ } catch (Exception $e) {
554
+ Mage::log($e->getMessage(), Zend_Log::ERR, $this->getHelper()->getResourceLogFile('order'), $this->_isDebug());
555
+ throw new Innobyte_EmagMarketplace_Exception(
556
+ 'There was an error while processing vouchers!'
557
+ );
558
+ }
559
+
560
+ return $this;
561
+ }
562
+
563
+ /**
564
+ * Remove column prefix
565
+ *
566
+ * @param $column
567
+ * @return mixed
568
+ */
569
+ protected function _removeColumnPrefix($column)
570
+ {
571
+ $columnPrefix = Innobyte_EmagMarketplace_Model_Sales_Voucher_Abstract::COLUMN_PREFIX;
572
+
573
+ return str_replace($columnPrefix . '_', '', $column);
574
+ }
575
+
576
+ /**
577
+ * Prepare customer
578
+ *
579
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Magento
580
+ */
581
+ protected function _prepareCustomer()
582
+ {
583
+ $customer = array(
584
+ 'id' => $this->getOrder()->getEmagCustomerId(),
585
+ 'name' => $this->getOrder()->getCustomerName(),
586
+ 'gender' => $this->getOrder()->getEmagCustomerGender(),
587
+ );
588
+
589
+ $this->getEmagOrder()
590
+ ->setCustomer($customer);
591
+
592
+ return $this;
593
+ }
594
+
595
+ /**
596
+ * Prepare billing address
597
+ *
598
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Magento
599
+ */
600
+ protected function _prepareBillingAddress()
601
+ {
602
+ $customer = $this->getEmagOrder()->getCustomer();
603
+ $billingAddress = $this->getOrder()->getBillingAddress();
604
+ $billing = array(
605
+ 'company' => $billingAddress->getCompany(),
606
+ 'code' => $billingAddress->getEmagCompanyCode(),
607
+ 'email' => '',
608
+ 'bank' => $billingAddress->getEmagBank(),
609
+ 'iban' => $billingAddress->getEmagIban(),
610
+ 'fax' => $billingAddress->getFax(),
611
+ 'phone_1' => $billingAddress->getTelephone(),
612
+ 'phone_2' => $billingAddress->getEmagTelephone2(),
613
+ 'phone_3' => $billingAddress->getEmagTelephone3(),
614
+ 'registration_number' => $billingAddress->getEmagCompanyRegNo(),
615
+ 'is_vat_payer' => $billingAddress->getEmagIsVatPayer(),
616
+ 'legal_entity' => $billingAddress->getEmagLegalEntity(),
617
+ 'billing_country' => $billingAddress->getCountryId(),
618
+ 'billing_suburb' => $billingAddress->getRegion(),
619
+ 'billing_city' => $billingAddress->getCity(),
620
+ 'billing_locality_id' => $billingAddress->getEmagLocalityId(),
621
+ 'billing_street' => $billingAddress->getStreet1(),
622
+ 'billing_postal_code' => $billingAddress->getPostcode()
623
+ );
624
+
625
+ $customer = array_merge($customer, $billing);
626
+ $this->getEmagOrder()
627
+ ->setCustomer($customer);
628
+
629
+ return $this;
630
+ }
631
+
632
+ /**
633
+ * Prepare shipping address
634
+ *
635
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Magento
636
+ */
637
+ protected function _prepareShippingAddress()
638
+ {
639
+ $customer = $this->getEmagOrder()->getCustomer();
640
+ $shippingAddress = $this->getOrder()->getShippingAddress();
641
+ $shipping = array(
642
+ 'shipping_country' => $shippingAddress->getCountryId(),
643
+ 'shipping_suburb' => $shippingAddress->getRegion(),
644
+ 'shipping_city' => $shippingAddress->getCity(),
645
+ 'shipping_locality_id' => $shippingAddress->getEmagLocalityId(),
646
+ 'shipping_street' => $shippingAddress->getStreet1(),
647
+ 'shipping_postal_code' => $shippingAddress->getPostcode()
648
+ );
649
+
650
+ $customer = array_merge($customer, $shipping);
651
+ $this->getEmagOrder()
652
+ ->setCustomer($customer);
653
+
654
+ return $this;
655
+ }
656
+
657
+ /**
658
+ * Prepare shipping
659
+ *
660
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Magento
661
+ */
662
+ protected function _prepareShipping()
663
+ {
664
+ $shippingAmount = $this->getOrder()->getShippingAmount();
665
+ $this->getEmagOrder()
666
+ ->setShippingTax($shippingAmount);
667
+
668
+ return $this;
669
+ }
670
+
671
+ /**
672
+ * Prepare payment
673
+ *
674
+ * @throws Innobyte_EmagMarketplace_Exception
675
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Magento
676
+ */
677
+ protected function _preparePayment()
678
+ {
679
+ try {
680
+ $payment = $this->getPayment();
681
+ $status = $this->getOrder()->getEmagPaymentStatus();
682
+ $method = $this->getPaymentMethod($payment->getMethodInstance()->getCode());
683
+ if (!$method) {
684
+ throw new Innobyte_EmagMarketplace_Exception(
685
+ $this->getHelper()->__(
686
+ 'Invalid Magento payment method: %s', $method
687
+ )
688
+ );
689
+ }
690
+
691
+ $this->getEmagOrder()->setPaymentStatus($status);
692
+ $this->getEmagOrder()->setPaymentModeId($method);
693
+ } catch (Exception $e) {
694
+ throw new Innobyte_EmagMarketplace_Exception($e->getMessage());
695
+ }
696
+
697
+ return $this;
698
+ }
699
+
700
+ /**
701
+ * Prepare invoices and creditmemos
702
+ *
703
+ * @throws Innobyte_EmagMarketplace_Exception
704
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Magento
705
+ */
706
+ protected function _prepareInvoices()
707
+ {
708
+ try {
709
+ $invoices = $this->getOrder()->getInvoiceCollection();
710
+ foreach ($invoices as $invoice) {
711
+ $item = $this->_processInvoice($invoice);
712
+ $this->_addInvoice($item);
713
+ }
714
+
715
+ $creditmemos = $this->getOrder()->getCreditmemosCollection();
716
+ foreach ($creditmemos as $creditmemo) {
717
+ $item = $this->_processInvoice($creditmemo, true);
718
+ $this->_addInvoice($item);
719
+ }
720
+
721
+ $this->getEmagOrder()
722
+ ->setInvoices($this->getInvoices());
723
+ } catch (Exception $e) {
724
+ Mage::log($e->getMessage(), Zend_Log::ERR, $this->getHelper()->getResourceLogFile('order'), $this->_isDebug());
725
+ throw new Innobyte_EmagMarketplace_Exception(
726
+ 'There was an error while processing order invoices!'
727
+ );
728
+ }
729
+
730
+ return $this;
731
+ }
732
+
733
+ /**
734
+ * Process invoice/creditmemo
735
+ *
736
+ * @param Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo $entity
737
+ * @param bool $storno
738
+ * @return array
739
+ */
740
+ private function _processInvoice($entity, $storno = false)
741
+ {
742
+ $type = Innobyte_EmagMarketplace_Model_Sales_Invoice::EMAG_INVOICE_NORMAL;
743
+ $entityType = Mage_Sales_Model_Order::ACTION_FLAG_INVOICE;
744
+ if ($storno) {
745
+ $type = Innobyte_EmagMarketplace_Model_Sales_Invoice::EMAG_INVOICE_STORNO;
746
+ $entityType = Mage_Sales_Model_Order::ACTION_FLAG_CREDITMEMO;
747
+ }
748
+
749
+ // get entity prefix(series)
750
+ $series = $this->getEntityPrefix($entityType);
751
+ // remove entity prefix from increment number(firs occurrence only)
752
+ $number = substr_replace($entity->getIncrementId(), '', 0, strlen($series));
753
+ // prepare products
754
+ $products = $this->_prepareInvoiceProducts($entity);
755
+
756
+ $item = array(
757
+ 'id' => $entity->getId(),
758
+ 'series' => $series,
759
+ 'number' => $number,
760
+ 'date' => $entity->getCreatedAt(),
761
+ 'due_date' => '0000-00-00 00:00:00', //TODO: send correct value only if requested by eMAG; currently is not needed
762
+ 'net_value' => $entity->getSubtotal(),
763
+ 'gross_value' => $entity->getGrandTotal(),
764
+ 'products' => $products,
765
+ 'details' => '',
766
+ 'type' => $type
767
+ );
768
+
769
+ return $item;
770
+ }
771
+
772
+ /**
773
+ * Prepare invoice/creditmemo products
774
+ *
775
+ * @param Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo $entity
776
+ * @return array
777
+ */
778
+ private function _prepareInvoiceProducts($entity)
779
+ {
780
+ $products = array();
781
+
782
+ /** @var $item Mage_Sales_Model_Order_Invoice_Item|Mage_Sales_Model_Order_Creditmemo_Item */
783
+ foreach ($entity->getAllItems() as $item) {
784
+ /** @var $orderItem Mage_Sales_Model_Order_Item */
785
+ $orderItem = $this->getOrder()->getItemById($item->getOrderItemId());
786
+ $products[] = array(
787
+ 'id' => $item->getProductId(),
788
+ 'quantity' => $item->getQty(),
789
+ 'sale_price' => $item->getPrice(),
790
+ 'vat' => number_format($orderItem->getTaxPercent() / 100, 4),
791
+ 'details' => ''
792
+ );
793
+ }
794
+
795
+ return $products;
796
+ }
797
+
798
+
799
+ /**
800
+ * Prepare customer comment
801
+ *
802
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Magento
803
+ */
804
+ protected function _prepareCustomerComment()
805
+ {
806
+ $comment = $this->getOrder()->getEmagCustomerComment();
807
+ $this->getEmagOrder()
808
+ ->setObservation($comment);
809
+
810
+ return $this;
811
+ }
812
+
813
+ /**
814
+ * Prepare attachments
815
+ *
816
+ * @throws Innobyte_EmagMarketplace_Exception
817
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Magento
818
+ */
819
+ protected function _prepareAttachments()
820
+ {
821
+ $attachments = array();
822
+ try {
823
+ $thirdPartyInvoices = $this->_getThirdPartyInvoices();
824
+ foreach ($thirdPartyInvoices as $invoice) {
825
+ $attachments[] = array(
826
+ 'name' => $invoice->getEmagInvoiceName(),
827
+ 'url' => $this->_getFileUrl($invoice->getId(), Innobyte_EmagMarketplace_Model_Sales_Invoice::THIRD_PARTY_INVOICE),
828
+ 'type' => 1
829
+ );
830
+ }
831
+
832
+ //TODO: uncomment if magento native invoices need to be sent to eMAG
833
+ // $magentoInvoices = $this->_getMagentoInvoices();
834
+ // foreach ($magentoInvoices as $invoice) {
835
+ // $this->_generateInvoice($invoice);
836
+ //
837
+ // $attachments[] = array(
838
+ // 'name' => $this->getInvoiceFileName($invoice, Mage_Sales_Model_Order::ACTION_FLAG_INVOICE),
839
+ // 'url' => $this->_getFileUrl($invoice->getId(), Mage_Sales_Model_Order::ACTION_FLAG_INVOICE),
840
+ // 'type' => 1
841
+ // );
842
+ // }
843
+ //
844
+ // $magentoCreditmemos = $this->_getMagentoCreditmemos();
845
+ // foreach ($magentoCreditmemos as $creditmemo) {
846
+ // $this->_generateCreditmemo($creditmemo);
847
+ //
848
+ // $attachments[] = array(
849
+ // 'name' => $this->getInvoiceFileName($creditmemo, Mage_Sales_Model_Order::ACTION_FLAG_CREDITMEMO),
850
+ // 'url' => $this->_getFileUrl($creditmemo->getId(), Mage_Sales_Model_Order::ACTION_FLAG_CREDITMEMO),
851
+ // 'type' => 1
852
+ // );
853
+ // }
854
+
855
+ $this->getEmagOrder()
856
+ ->setAttachments($attachments);
857
+ } catch (Exception $e) {
858
+ Mage::log($e->getMessage(), Zend_Log::ERR, $this->getHelper()->getResourceLogFile('order'), $this->_isDebug());
859
+ throw new Innobyte_EmagMarketplace_Exception(
860
+ 'There was an error while processing order attachments!'
861
+ );
862
+ }
863
+
864
+ return $this;
865
+ }
866
+
867
+ /**
868
+ * Get third party invoices
869
+ *
870
+ * @return array
871
+ */
872
+ private function _getThirdPartyInvoices()
873
+ {
874
+ /** @var $model Innobyte_EmagMarketplace_Model_Sales_Invoice */
875
+ $model = Mage::getModel('innobyte_emag_marketplace/sales_invoice');
876
+ $invoices = $model->getEmagThirdPartyInvoicesCollection($this->getOrder()->getId());
877
+
878
+ return $invoices;
879
+ }
880
+
881
+ /**
882
+ * Get magento invoices
883
+ *
884
+ * @return array
885
+ */
886
+ private function _getMagentoInvoices()
887
+ {
888
+ $invoices = $this->getOrder()->getInvoiceCollection();
889
+
890
+ return $invoices;
891
+ }
892
+
893
+ /**
894
+ * Get magento creditmemos
895
+ *
896
+ * @return array
897
+ */
898
+ private function _getMagentoCreditmemos()
899
+ {
900
+ $creditmemos = $this->getOrder()->getCreditmemosCollection();
901
+
902
+ return $creditmemos;
903
+ }
904
+
905
+ /**
906
+ * Generate invoice pdf and save it to disk
907
+ *
908
+ * @param $invoice
909
+ * @throws Innobyte_EmagMarketplace_Exception
910
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Magento
911
+ */
912
+ private function _generateInvoice($invoice)
913
+ {
914
+ try {
915
+ /** @var $model Mage_Sales_Model_Order_Pdf_Invoice */
916
+ $model = Mage::getModel('sales/order_pdf_invoice');
917
+ $pdf = $model->getPdf(array($invoice))->render();
918
+
919
+ $invoiceBaseDirectory = $this->getInvoiceBaseDirectory();
920
+ $invoiceBasePath = $invoiceBaseDirectory . $this->getInvoiceFileName($invoice, Mage_Sales_Model_Order::ACTION_FLAG_INVOICE);
921
+
922
+ if (is_dir_writeable(Mage::getBaseDir('media'))) {
923
+ if (!is_dir($invoiceBaseDirectory)) {
924
+ mkdir($invoiceBaseDirectory, 0755, true);
925
+ }
926
+ } else {
927
+ throw new Innobyte_EmagMarketplace_Exception(
928
+ $this->getHelper()->__(
929
+ 'Unable to write to media folder: %s', $invoiceBaseDirectory
930
+ )
931
+ );
932
+ }
933
+
934
+ try {
935
+ if (file_put_contents($invoiceBasePath, $pdf) === false) {
936
+ throw new Innobyte_EmagMarketplace_Exception(
937
+ 'Unable to save Magento invoice to disk'
938
+ );
939
+ }
940
+ } catch (Exception $e) {
941
+ Mage::log($e->getMessage(), Zend_Log::ERR, $this->getHelper()->getResourceLogFile('order'), $this->_isDebug());
942
+ throw new Innobyte_EmagMarketplace_Exception(
943
+ $this->getHelper()->__(
944
+ 'Magento Invoice Pdf could not be saved. Invoice increment id: #%s',
945
+ $invoice->getIncrementId()
946
+ )
947
+ );
948
+ }
949
+ } catch (Exception $e) {
950
+ throw new Innobyte_EmagMarketplace_Exception($e->getMessage());
951
+ }
952
+
953
+ return $this;
954
+ }
955
+
956
+ /**
957
+ * Generate creditmemo pdf and save it to disk
958
+ *
959
+ * @param $creditmemo
960
+ * @throws Innobyte_EmagMarketplace_Exception
961
+ * @return Innobyte_EmagMarketplace_Model_Order_Convert_Magento
962
+ */
963
+ private function _generateCreditmemo($creditmemo)
964
+ {
965
+ try {
966
+ /** @var $model Mage_Sales_Model_Order_Pdf_Creditmemo */
967
+ $model = Mage::getModel('sales/order_pdf_creditmemo');
968
+ $pdf = $model->getPdf(array($creditmemo))->render();
969
+
970
+ $creditmemoBaseDirectory = $this->getCreditmemoBaseDirectory();
971
+ $creditmemoBasePath = $creditmemoBaseDirectory . $this->getInvoiceFileName(
972
+ $creditmemo,
973
+ Mage_Sales_Model_Order::ACTION_FLAG_CREDITMEMO
974
+ );
975
+
976
+ if (is_dir_writeable(Mage::getBaseDir('media'))) {
977
+ if (!is_dir($creditmemoBaseDirectory)) {
978
+ mkdir($creditmemoBaseDirectory, 0755, true);
979
+ }
980
+ } else {
981
+ throw new Innobyte_EmagMarketplace_Exception(
982
+ $this->getHelper()->__(
983
+ 'Unable to write to media folder: %s', $creditmemoBaseDirectory
984
+ )
985
+ );
986
+ }
987
+
988
+ try {
989
+ if (file_put_contents($creditmemoBasePath, $pdf) === false) {
990
+ throw new Innobyte_EmagMarketplace_Exception(
991
+ 'Unable to save Magento creditmemo to disk'
992
+ );
993
+ }
994
+
995
+ } catch (Exception $e) {
996
+ Mage::log($e->getMessage(), Zend_Log::ERR, $this->getHelper()->getResourceLogFile('order'), $this->_isDebug());
997
+ throw new Innobyte_EmagMarketplace_Exception(
998
+ $this->getHelper()->__(
999
+ 'Magento Creditmemo Pdf could not be saved. Creditmemo increment id: #%s',
1000
+ $creditmemo->getIncrementId()
1001
+ )
1002
+ );
1003
+ }
1004
+ } catch (Exception $e) {
1005
+ throw new Innobyte_EmagMarketplace_Exception($e->getMessage());
1006
+ }
1007
+
1008
+ return $this;
1009
+ }
1010
+
1011
+ /**
1012
+ * Get invoice|creditmemo file name
1013
+ *
1014
+ * @param Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo $invoice
1015
+ * @param string $type
1016
+ * @return string
1017
+ */
1018
+ public function getInvoiceFileName($invoice, $type)
1019
+ {
1020
+ $fileName = $type . '_' . $invoice->getIncrementId() . '.pdf';
1021
+
1022
+ return $fileName;
1023
+ }
1024
+
1025
+ /**
1026
+ * Get invoice base directory
1027
+ *
1028
+ * @return string
1029
+ */
1030
+ public function getInvoiceBaseDirectory()
1031
+ {
1032
+ return Mage::getBaseDir('media') . DS . Innobyte_EmagMarketplace_Model_Sales_Invoice::MAGENTO_INVOICE_DIRECTORY;
1033
+ }
1034
+
1035
+ /**
1036
+ * Get creditmemo base directory
1037
+ *
1038
+ * @return string
1039
+ */
1040
+ public function getCreditmemoBaseDirectory()
1041
+ {
1042
+ return Mage::getBaseDir('media') . DS . Innobyte_EmagMarketplace_Model_Sales_Invoice::MAGENTO_CREDITMEMO_DIRECTORY;
1043
+ }
1044
+
1045
+ /**
1046
+ * Get file url
1047
+ *
1048
+ * @param $invoiceId
1049
+ * @param $type
1050
+ * @return string
1051
+ */
1052
+ private function _getFileUrl($invoiceId, $type)
1053
+ {
1054
+ $url = Mage::getUrl(
1055
+ 'marketplace/invoice/download',
1056
+ array(
1057
+ 'invoice' => Mage::helper('core')->encrypt($invoiceId),
1058
+ 'type' => Mage::helper('core')->encrypt($type),
1059
+ 'store' => $this->getOrder()->getStoreId()
1060
+ )
1061
+ );
1062
+
1063
+ return $url;
1064
+ }
1065
+
1066
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Payment/Method/Banktransfer.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Payment_Method_Banktransfer
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Payment_Method_Banktransfer extends Mage_Payment_Model_Method_Abstract
12
+ {
13
+
14
+ /**
15
+ * Code
16
+ */
17
+ const EMAG_BANKTRANSFER = 'emag_banktransfer';
18
+
19
+ /**
20
+ * Payment method code
21
+ *
22
+ * @var string
23
+ */
24
+ protected $_code = self::EMAG_BANKTRANSFER;
25
+
26
+ /**
27
+ * Hide payment in frontend
28
+ *
29
+ * @var bool
30
+ */
31
+ protected $_canUseCheckout = false;
32
+ protected $_canUseForMultishipping = false;
33
+
34
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Payment/Method/Cashondelivery.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Payment_Method_Cashondelivery
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Payment_Method_Cashondelivery extends Mage_Payment_Model_Method_Abstract
12
+ {
13
+
14
+ /**
15
+ * Code
16
+ */
17
+ const EMAG_CASHONDELIVERY = 'emag_cashondelivery';
18
+
19
+ /**
20
+ * Payment method code
21
+ *
22
+ * @var string
23
+ */
24
+ protected $_code = self::EMAG_CASHONDELIVERY;
25
+
26
+ /**
27
+ * Hide payment in frontend
28
+ *
29
+ * @var bool
30
+ */
31
+ protected $_canUseCheckout = false;
32
+ protected $_canUseForMultishipping = false;
33
+
34
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Payment/Method/Cc.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Payment_Method_Cc
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Payment_Method_Cc extends Mage_Payment_Model_Method_Abstract
12
+ {
13
+
14
+ /**
15
+ * Code
16
+ */
17
+ const EMAG_CREDITCARD = 'emag_cc';
18
+
19
+ /**
20
+ * Payment method code
21
+ *
22
+ * @var string
23
+ */
24
+ protected $_code = self::EMAG_CREDITCARD;
25
+
26
+ /**
27
+ * Hide payment in frontend
28
+ *
29
+ * @var bool
30
+ */
31
+ protected $_canUseCheckout = false;
32
+ protected $_canUseForMultishipping = false;
33
+
34
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Payment/Method/Unknown.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Payment_Method_Unknown
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Payment_Method_Unknown extends Mage_Payment_Model_Method_Abstract
12
+ {
13
+
14
+ /**
15
+ * Code
16
+ */
17
+ const EMAG_UNKNOWN = 'emag_unknown';
18
+
19
+ /**
20
+ * Payment method code
21
+ *
22
+ * @var string
23
+ */
24
+ protected $_code = self::EMAG_UNKNOWN;
25
+
26
+ /**
27
+ * Hide payment in frontend
28
+ *
29
+ * @var bool
30
+ */
31
+ protected $_canUseCheckout = false;
32
+ protected $_canUseForMultishipping = false;
33
+
34
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Product.php ADDED
@@ -0,0 +1,395 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * eMAG product model.
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
9
+ */
10
+ class Innobyte_EmagMarketplace_Model_Product extends Mage_Core_Model_Abstract
11
+ {
12
+ /**
13
+ * @Override
14
+ * @var string Event prefix.
15
+ */
16
+ protected $_eventPrefix = 'innobyte_emag_marketplace_product';
17
+
18
+ /**
19
+ * @Override
20
+ * @var string Event object key.
21
+ */
22
+ protected $_eventObject = 'emag_product';
23
+
24
+ /**
25
+ * Different eMAG image displaying types.
26
+ */
27
+ const IMAGE_DISPLAY_TYPE_MAIN = 1;
28
+ const IMAGE_DISPLAY_TYPE_SECONDARY = 2;
29
+ const IMAGE_DISPLAY_TYPE_OTHER = 0;
30
+
31
+ /**
32
+ * Different eMAG stock availabilities.
33
+ */
34
+ const AVAILABILITY_LIMITED_STOCK = 2;
35
+ const AVAILABILITY_IN_STOCK = 3;
36
+ const AVAILABILITY_OUT_OF_STOCK = 5;
37
+
38
+ /**
39
+ * Flags that indicates wheter product has been synced (sent to eMAG).
40
+ */
41
+ const IS_SYNCED = 1;
42
+ const IS_NOT_SYNCED = 0;
43
+
44
+ /**
45
+ * Product status in order
46
+ */
47
+ const PRODUCT_STATUS_CANCELED = 0;
48
+ const PRODUCT_STATUS_AVAILABLE = 1;
49
+
50
+ /**
51
+ * Related objects to save
52
+ * @var array
53
+ */
54
+ protected $_relatedObjects;
55
+
56
+
57
+
58
+ /**
59
+ * @Override
60
+ */
61
+ public function _construct()
62
+ {
63
+ parent::_construct();
64
+ $this->_init('innobyte_emag_marketplace/product');
65
+ $this->_relatedObjects = array();
66
+ }
67
+
68
+
69
+
70
+ /**
71
+ * Load by product id and store id.
72
+ *
73
+ * @param int $intProductId Mage catalog product id.
74
+ * @param int $intStoreId Store scope id.
75
+ * @return Innobyte_EmagMarketplace_Model_Product
76
+ */
77
+ public function loadByProdIdAndStore($intProductId, $intStoreId)
78
+ {
79
+ $this->_beforeLoad(
80
+ array('product_id' => $intProductId, 'store_id' => $intStoreId),
81
+ array('product_id', 'store_id')
82
+ );
83
+ $this->_getResource()->loadByProdIdAndStore(
84
+ $this,
85
+ $intProductId,
86
+ $intStoreId
87
+ );
88
+ $this->_afterLoad();
89
+ $this->setOrigData();
90
+ $this->_hasDataChanges = false;
91
+ return $this;
92
+ }
93
+
94
+
95
+
96
+ /**
97
+ * Retrieve commission value.
98
+ *
99
+ * @return mixed
100
+ */
101
+ public function getCommissionValue()
102
+ {
103
+ try {
104
+ $commissionType = Innobyte_EmagMarketplace_Model_Source_CommissionTypes::getEmagCommissionType(
105
+ $this->getCommissionType()
106
+ );
107
+ switch ($commissionType) {
108
+ case Innobyte_EmagMarketplace_Model_Source_CommissionTypes::TYPE_PERCENTAGE:
109
+ return intval($this->getData('commission_value'));
110
+ case Innobyte_EmagMarketplace_Model_Source_CommissionTypes::TYPE_ABSOLUTE:
111
+ return floatval($this->getData('commission_value'));
112
+ default:
113
+ }
114
+ } catch (Innobyte_EmagMarketplace_Exception $ex) {
115
+ }
116
+ return $this->getData('commission_value');
117
+ }
118
+
119
+
120
+
121
+ /**
122
+ * Setter method for category id.
123
+ *
124
+ * @param int $categoryId
125
+ * @return Innobyte_EmagMarketplace_Model_Product
126
+ */
127
+ public function setCategoryId($categoryId)
128
+ {
129
+ if ($this->getCategoryId() != $categoryId) {
130
+ // reset magento category object too, make sure to set category id
131
+ // through this method not using #setData()
132
+ $this->unsetData('category');
133
+ }
134
+ $this->setData('category_id', intval($categoryId));
135
+ return $this;
136
+ }
137
+
138
+
139
+
140
+ /**
141
+ * Retrieve emag category model based on product 's category id.
142
+ *
143
+ * @return Innobyte_EmagMarketplace_Model_Category|null
144
+ */
145
+ public function getCategory()
146
+ {
147
+ if (!$this->hasCategory() && $this->getCategoryId() > 0) {
148
+ $this->setCategory(
149
+ Mage::getModel('innobyte_emag_marketplace/category')
150
+ ->load($this->getCategoryId())
151
+ );
152
+ }
153
+ return $this->getData('category');
154
+ }
155
+
156
+
157
+
158
+ /**
159
+ * Setter method for product id.
160
+ *
161
+ * @param int $mageProductId Magento product id.
162
+ * @return Innobyte_EmagMarketplace_Model_Product
163
+ */
164
+ public function setProductId($mageProductId)
165
+ {
166
+ if ($this->getProductId() != $mageProductId) {
167
+ // reset magento product object too, make sure to set product id
168
+ // through this method not using #setData()
169
+ $this->unsetData('magento_product');
170
+ }
171
+ $this->setData('product_id', intval($mageProductId));
172
+ return $this;
173
+ }
174
+
175
+
176
+
177
+ /**
178
+ * Retrieve magento product model.
179
+ *
180
+ * @return Mage_Catalog_Model_Product|null
181
+ */
182
+ public function getMagentoProduct()
183
+ {
184
+ if (!$this->hasMagentoProduct() && $this->getProductId() > 0) {
185
+ $this->setMagentoProduct(
186
+ Mage::getModel('catalog/product')
187
+ ->setStoreId($this->getStoreId())
188
+ ->load($this->getProductId())
189
+ );
190
+ }
191
+ return $this->getData('magento_product');
192
+ }
193
+
194
+
195
+
196
+ /**
197
+ * Setter method for vat id.
198
+ *
199
+ * @param int $vatId
200
+ * @return Innobyte_EmagMarketplace_Model_Product
201
+ */
202
+ public function setVatId($vatId)
203
+ {
204
+ if ($this->getVatId() != $vatId) {
205
+ // reset emat vat object too, make sure to set vat id
206
+ // through this method not using #setData()
207
+ $this->unsetData('vat');
208
+ }
209
+ $this->setData('vat_id', intval($vatId));
210
+ return $this;
211
+ }
212
+
213
+
214
+
215
+ /**
216
+ * Retrieve emag vat model.
217
+ *
218
+ * @return Innobyte_EmagMarketplace_Model_Category|null
219
+ */
220
+ public function getVat()
221
+ {
222
+ if (!$this->hasVat() && $this->getVatId() > 0) {
223
+ $this->setVat(
224
+ Mage::getModel('innobyte_emag_marketplace/vat')
225
+ ->load($this->getVatId())
226
+ );
227
+ }
228
+ return $this->getData('vat');
229
+ }
230
+
231
+
232
+ /**
233
+ * Setter method for family type id.
234
+ *
235
+ * @param int $familyTypeId Magento id for family type.
236
+ * @return Innobyte_EmagMarketplace_Model_Product
237
+ */
238
+ public function setFamilyTypeId($familyTypeId)
239
+ {
240
+ if ($this->getFamilyTypeId() != $familyTypeId) {
241
+ // reset magento family type object too, make sure to set
242
+ // family id through this method not using #setData()
243
+ $this->unsetData('category');
244
+ }
245
+ $this->setData('family_type_id', intval($familyTypeId));
246
+ return $this;
247
+ }
248
+
249
+
250
+
251
+ /**
252
+ * Retrieve emag family type model based on product 's family type id.
253
+ *
254
+ * @return Innobyte_EmagMarketplace_Model_Category_Familytype|null
255
+ */
256
+ public function getFamilyType()
257
+ {
258
+ if (!$this->hasFamilyType() && $this->getFamilyTypeId() > 0) {
259
+ $this->setFamilyType(
260
+ Mage::getModel('innobyte_emag_marketplace/category_familytype')
261
+ ->load($this->getFamilyTypeId())
262
+ );
263
+ }
264
+ return $this->getData('family_type');
265
+ }
266
+
267
+
268
+
269
+ /**
270
+ * Check if product has been synced
271
+ * (sent whole documentation at least once).
272
+ *
273
+ * @return bool
274
+ */
275
+ public function isSynced()
276
+ {
277
+ return (bool) $this->getIsSynced();
278
+ }
279
+
280
+
281
+
282
+ /**
283
+ * Setter method for synced.
284
+ *
285
+ * @param int One of the constants
286
+ * Innobyte_EmagMarketplace_Model_Product::IS_SYNCED,
287
+ * Innobyte_EmagMarketplace_Model_Product::IS_NOT_SYNCED
288
+ * @return Innobyte_EmagMarketplace_Model_Product
289
+ */
290
+ public function setIsSynced($synced)
291
+ {
292
+ // set synced flag for configurable child products also
293
+ if (!is_null($this->getMagentoProduct())
294
+ && $this->getMagentoProduct()->isConfigurable()) {
295
+ $chidIds = $this->getMagentoProduct()->getTypeInstance()
296
+ ->getUsedProductIds();
297
+ foreach ($chidIds as $childId) {
298
+ $childEmagProduct = Mage::getModel('innobyte_emag_marketplace/product')
299
+ ->loadByProdIdAndStore($childId, $this->getStoreId());
300
+ if ($childEmagProduct->getId()) {
301
+ $childEmagProduct->setIsSynced($synced);
302
+ $this->addRelatedObject($childEmagProduct);
303
+ }
304
+ }
305
+ }
306
+
307
+ switch ($synced) {
308
+ case Innobyte_EmagMarketplace_Model_Product::IS_SYNCED: // intentionally ommitted break
309
+ case Innobyte_EmagMarketplace_Model_Product::IS_NOT_SYNCED;
310
+ $this->setData('is_synced', $synced);
311
+ break;
312
+ default:
313
+ }
314
+
315
+ return $this;
316
+ }
317
+
318
+
319
+
320
+ /**
321
+ * Setter method for status.
322
+ *
323
+ * @param int $status One of the constants
324
+ * Innobyte_EmagMarketplace_Model_Source_OfferStatus::STATUS_*
325
+ * @return Innobyte_EmagMarketplace_Model_Product
326
+ */
327
+ public function setStatus($status)
328
+ {
329
+ // set status for configurable child products also
330
+ if (!is_null($this->getMagentoProduct())
331
+ && $this->getMagentoProduct()->isConfigurable()) {
332
+ $chidIds = $this->getMagentoProduct()->getTypeInstance()
333
+ ->getUsedProductIds();
334
+ foreach ($chidIds as $childId) {
335
+ $childEmagProduct = Mage::getModel('innobyte_emag_marketplace/product')
336
+ ->loadByProdIdAndStore($childId, $this->getStoreId());
337
+ if ($childEmagProduct->getId()) {
338
+ $childEmagProduct->setStatus($status);
339
+ $this->addRelatedObject($childEmagProduct);
340
+ }
341
+ }
342
+ }
343
+
344
+ switch ($status) {
345
+ case Innobyte_EmagMarketplace_Model_Source_OfferStatus::STATUS_ACTIVE: // intentionally ommitted break
346
+ case Innobyte_EmagMarketplace_Model_Source_OfferStatus::STATUS_INACTIVE;
347
+ $this->setData('status', $status);
348
+ break;
349
+ default:
350
+ }
351
+
352
+ return $this;
353
+ }
354
+
355
+
356
+
357
+ /**
358
+ * Retrieve array of related objects used for also saving them.
359
+ *
360
+ * @return array
361
+ */
362
+ public function getRelatedObjects()
363
+ {
364
+ return $this->_relatedObjects;
365
+ }
366
+
367
+
368
+
369
+ /**
370
+ * Add new object to related array
371
+ *
372
+ * @param Mage_Core_Model_Abstract $object
373
+ * @return Innobyte_EmagMarketplace_Model_Product
374
+ */
375
+ public function addRelatedObject(Mage_Core_Model_Abstract $object)
376
+ {
377
+ if (!is_null($object)) {
378
+ $this->_relatedObjects[] = $object;
379
+ }
380
+ return $this;
381
+ }
382
+
383
+
384
+
385
+ /**
386
+ * @Override
387
+ */
388
+ protected function _afterSave()
389
+ {
390
+ foreach ($this->getRelatedObjects() as $object) {
391
+ $object->save();
392
+ }
393
+ return parent::_afterSave();
394
+ }
395
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Category.php ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG category resource model.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Resource_Category
11
+ extends Mage_Core_Model_Resource_Db_Abstract
12
+ {
13
+ /**
14
+ * @Override
15
+ */
16
+ public function _construct()
17
+ {
18
+ $this->_init('innobyte_emag_marketplace/category', 'id');
19
+ }
20
+
21
+
22
+
23
+ /**
24
+ * @Override
25
+ */
26
+ protected function _prepareDataForSave(Mage_Core_Model_Abstract $object)
27
+ {
28
+ $currentTime = Varien_Date::now();
29
+ if ((!$object->getId() || $object->isObjectNew())
30
+ && !$object->getCreatedAt()) {
31
+ $object->setCreatedAt($currentTime);
32
+ }
33
+ $object->setUpdatedAt($currentTime);
34
+ return parent::_prepareDataForSave($object);
35
+ }
36
+
37
+
38
+
39
+ /**
40
+ * @Override
41
+ */
42
+ protected function _afterSave(Mage_Core_Model_Abstract $object)
43
+ {
44
+ $write = $this->_getWriteAdapter();
45
+ $read = $this->_getReadAdapter();
46
+
47
+ if (is_array($object->getImportedCharacteristics())) {
48
+ $tableNameC = $this->getTable(
49
+ 'innobyte_emag_marketplace/category_characteristic'
50
+ );
51
+
52
+ $select = $read->select()
53
+ ->from($tableNameC, array('emag_id'))
54
+ ->where('category_id = ?', $object->getId());
55
+
56
+ $oldCharacteristicsEmagIds = $read->fetchCol($select);
57
+ $newCharacteristicsEmagIds = array();
58
+ foreach ($object->getImportedCharacteristics() as $cModel) {
59
+ $newCharacteristicsEmagIds[] = $cModel->getEmagId();
60
+ }
61
+
62
+ $toBeDeleted = array_diff(
63
+ $oldCharacteristicsEmagIds,
64
+ $newCharacteristicsEmagIds
65
+ );
66
+ if (!empty($toBeDeleted)) {
67
+ $where[] = $write->quoteInto('category_id = ?', $object->getId());
68
+ $where[] = $write->quoteInto('emag_id IN (?)', $toBeDeleted);
69
+ $write->delete($tableNameC, $where);
70
+ }
71
+
72
+ foreach ($object->getImportedCharacteristics() as $cModel) {
73
+ $cModel->setCategoryId($object->getId())
74
+ ->save();
75
+ }
76
+ }
77
+
78
+ if (is_array($object->getImportedFamilyTypes())) {
79
+ $tableNameFt = $this->getTable(
80
+ 'innobyte_emag_marketplace/category_familytype'
81
+ );
82
+
83
+ $select = $read->select()
84
+ ->from($tableNameFt, array('emag_id'))
85
+ ->where('category_id = ?', $object->getId());
86
+
87
+ $oldFamilyTypeEmagIds = $read->fetchCol($select);
88
+ $newFamilyTypeEmagIds = array();
89
+ foreach ($object->getImportedFamilyTypes() as $ftModel) {
90
+ $newFamilyTypeEmagIds[] = $ftModel->getEmagId();
91
+ }
92
+
93
+ $toBeDeleted = array_diff(
94
+ $oldFamilyTypeEmagIds,
95
+ $newFamilyTypeEmagIds
96
+ );
97
+ if (!empty($toBeDeleted)) {
98
+ $where[] = $write->quoteInto('category_id = ?', $object->getId());
99
+ $where[] = $write->quoteInto('emag_id IN (?)', $toBeDeleted);
100
+ $write->delete($tableNameFt, $where);
101
+ }
102
+
103
+ foreach ($object->getImportedFamilyTypes() as $ftModel) {
104
+ $ftModel->setCategoryId($object->getId())
105
+ ->save();
106
+ }
107
+ }
108
+
109
+ return parent::_afterSave($object);
110
+ }
111
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Category/Characteristic.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG category characteristic resource model.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Resource_Category_Characteristic
11
+ extends Mage_Core_Model_Resource_Db_Abstract
12
+ {
13
+ /**
14
+ * @Override
15
+ */
16
+ public function _construct()
17
+ {
18
+ $this->_init('innobyte_emag_marketplace/category_characteristic', 'id');
19
+ }
20
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Category/Characteristic/Collection.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG category characteristic resource collection model.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Resource_Category_Characteristic_Collection
11
+ extends Mage_Core_Model_Resource_Db_Collection_Abstract
12
+ {
13
+ /**
14
+ * Name prefix of events that are dispatched by model
15
+ *
16
+ * @Override
17
+ * @var string
18
+ */
19
+ protected $_eventPrefix = 'innobyte_emag_marketplace_category_characteristic_collection';
20
+
21
+ /**
22
+ * Name of event parameter
23
+ *
24
+ * @Override
25
+ * @var string
26
+ */
27
+ protected $_eventObject = 'emag_category_characteristic_collection';
28
+
29
+
30
+
31
+ /**
32
+ * @Override
33
+ */
34
+ public function _construct()
35
+ {
36
+ parent::_construct();
37
+ $this->_init('innobyte_emag_marketplace/category_characteristic');
38
+ }
39
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Category/Collection.php ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG category resource collection model.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Resource_Category_Collection
11
+ extends Mage_Core_Model_Resource_Db_Collection_Abstract
12
+ {
13
+ /**
14
+ * Name prefix of events that are dispatched by model
15
+ *
16
+ * @Override
17
+ * @var string
18
+ */
19
+ protected $_eventPrefix = 'innobyte_emag_marketplace_category_collection';
20
+
21
+ /**
22
+ * Name of event parameter
23
+ *
24
+ * @Override
25
+ * @var string
26
+ */
27
+ protected $_eventObject = 'emag_category_collection';
28
+
29
+
30
+
31
+ /**
32
+ * @Override
33
+ */
34
+ public function _construct()
35
+ {
36
+ parent::_construct();
37
+ $this->_init('innobyte_emag_marketplace/category');
38
+ $this->setFlag('load_only_with_family_types', 0);
39
+ $this->setFlag('load_only_with_family_types_has_been_applied', 0);
40
+ }
41
+
42
+
43
+
44
+ /**
45
+ * Add filter by store
46
+ *
47
+ * @param int|Mage_Core_Model_Store $mxdStore
48
+ *
49
+ * @return Innobyte_EmagMarketplace_Model_Resource_Category_Collection
50
+ */
51
+ public function addStoreFilter($mxdStore)
52
+ {
53
+ $stores = array();
54
+ $storesCnt = 0;
55
+ if ($mxdStore instanceof Mage_Core_Model_Store) {
56
+ $stores[] = $mxdStore->getId();
57
+ $storesCnt++;
58
+ } elseif (is_numeric($mxdStore)) {
59
+ $stores[] = (int) $mxdStore;
60
+ $storesCnt++;
61
+ }
62
+
63
+ if (Mage_Core_Model_App::ADMIN_STORE_ID == $stores[0]) {
64
+ foreach (Mage::app()->getWebsites() as $website) {
65
+ foreach ($website->getGroups() as $group) {
66
+ $s = $group->getStores();
67
+ foreach ($s as $storeModel) {
68
+ $stores[] = $storeModel->getId();
69
+ $storesCnt++;
70
+ }
71
+ }
72
+ }
73
+ }
74
+
75
+ if (1 == $storesCnt) {
76
+ $this->addFieldToFilter('store_id', array('eq' => $stores[0]));
77
+ } elseif ($storesCnt > 1) {
78
+ $this->addFieldToFilter('store_id', array('in' => $stores));
79
+ }
80
+
81
+ return $this;
82
+ }
83
+
84
+
85
+
86
+ /**
87
+ * @Override
88
+ */
89
+ public function getSelectCountSql()
90
+ {
91
+ $this->_renderFilters();
92
+
93
+ $countSelect = clone $this->getSelect();
94
+ $countSelect->reset(Zend_Db_Select::ORDER);
95
+ $countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
96
+ $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
97
+ if ($this->getSelect()->getPart(Zend_Db_Select::HAVING)) {
98
+ //No good way to chop this up, so just subquery it
99
+ $subQuery = new Zend_Db_Expr('(' . $countSelect->__toString() . ')');
100
+ $countSelect->reset()
101
+ ->from(array('temp' => $subQuery))
102
+ ->reset(Zend_Db_Select::COLUMNS)
103
+ ->columns('COUNT(*)');
104
+ } else {
105
+ $countSelect->reset(Zend_Db_Select::COLUMNS);
106
+ // Count doesn't work with group by columns keep the group by
107
+ if (count($this->getSelect()->getPart(Zend_Db_Select::GROUP)) > 0) {
108
+ $countSelect->reset(Zend_Db_Select::GROUP);
109
+ $countSelect->distinct(true);
110
+ $group = $this->getSelect()->getPart(Zend_Db_Select::GROUP);
111
+ $countSelect->columns('COUNT(DISTINCT ' . implode(', ', $group) . ')');
112
+ } else {
113
+ $countSelect->columns('COUNT(*)');
114
+ }
115
+ }
116
+ return $countSelect;
117
+ }
118
+
119
+
120
+
121
+ /**
122
+ * Load collection data
123
+ *
124
+ * @Override
125
+ * @param boolean $printQuery
126
+ * @param boolean $logQuery
127
+ * @return Varien_Data_Collection_Db
128
+ */
129
+ public function load($printQuery = false, $logQuery = false)
130
+ {
131
+ if ($this->getOnlyWithFamilyTypes()
132
+ && !$this->isLoaded()
133
+ && !$this->getFlag('load_only_with_family_types_has_been_applied')) {
134
+ $this->getSelect()->where(
135
+ new Zend_Db_Expr(
136
+ ' EXISTS (SELECT 1 FROM '
137
+ . $this->getTable('innobyte_emag_marketplace/category_familytype')
138
+ . ' WHERE category_id = main_table.id)'
139
+ )
140
+ );
141
+ $this->setFlag('load_only_with_family_types_has_been_applied', 1);
142
+ }
143
+
144
+ return parent::load($printQuery, $logQuery);
145
+ }
146
+
147
+
148
+
149
+ /**
150
+ * Setter method for loading only categories that have family type(s).
151
+ *
152
+ * @param boolean $flag
153
+ * @return Innobyte_EmagMarketplace_Model_Resource_Category_Collection
154
+ */
155
+ public function setOnlyWithFamilyTypes($flag)
156
+ {
157
+ $this->setFlag('load_only_with_family_types', (bool) $flag);
158
+ return $this;
159
+ }
160
+
161
+
162
+
163
+ /**
164
+ * Getter method for loading only categories that have family type(s).
165
+ *
166
+ * @return boolean
167
+ */
168
+ public function getOnlyWithFamilyTypes()
169
+ {
170
+ return $this->getFlag('load_only_with_family_types');
171
+ }
172
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Category/Familytype.php ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG category family-type resource model.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Resource_Category_Familytype
11
+ extends Mage_Core_Model_Resource_Db_Abstract
12
+ {
13
+ /**
14
+ * @Override
15
+ */
16
+ public function _construct()
17
+ {
18
+ $this->_init('innobyte_emag_marketplace/category_familytype', 'id');
19
+ }
20
+
21
+
22
+
23
+ /**
24
+ * @Override
25
+ */
26
+ protected function _afterSave(Mage_Core_Model_Abstract $object)
27
+ {
28
+ if (is_array($object->getImportedCharacteristics())) {
29
+ $write = $this->_getWriteAdapter();
30
+ $read = $this->_getReadAdapter();
31
+
32
+ $tableName = $this->getTable(
33
+ 'innobyte_emag_marketplace/category_familytype_characteristic'
34
+ );
35
+ $select = $read->select()
36
+ ->from(array('main_table' => $tableName), array('characteristic_id'))
37
+ ->where('family_type_id = ?', intval($object->getId()));
38
+ $oldCharEmagIds = $read->fetchCol($select);
39
+ $newCharEmagIds = array();
40
+ foreach ($object->getImportedCharacteristics() as $char) {
41
+ $newCharEmagIds[] = intval($char['characteristic_id']);
42
+ }
43
+
44
+ $charToDelete = array_diff($oldCharEmagIds, $newCharEmagIds);
45
+ if (!empty($charToDelete)) {
46
+ $where[] = $write->quoteInto(
47
+ 'family_type_id = ?',
48
+ intval($object->getId())
49
+ );
50
+ $where[] = $write->quoteInto(
51
+ 'characteristic_id IN (?)',
52
+ $charToDelete
53
+ );
54
+ $write->delete($tableName, $where);
55
+ }
56
+
57
+ foreach ($object->getImportedCharacteristics() as $char) {
58
+ $char['family_type_id'] = intval($object->getId());
59
+ $write->insertOnDuplicate(
60
+ $tableName,
61
+ $char,
62
+ array(
63
+ 'characteristic_id',
64
+ 'family_type_id',
65
+ 'display_order',
66
+ 'is_foldable',
67
+ 'characteristic_family_type_id',
68
+ )
69
+ );
70
+ }
71
+ }
72
+
73
+ return parent::_afterSave($object);
74
+ }
75
+
76
+
77
+
78
+ /**
79
+ * Retrieve a family type 's characteristics.
80
+ *
81
+ * @return array Array for varien objects.
82
+ */
83
+ public function getCharacteristics(Mage_Core_Model_Abstract $object)
84
+ {
85
+ $read = $this->_getReadAdapter();
86
+ $tableFtCharacteristics = $this->getTable(
87
+ 'innobyte_emag_marketplace/category_familytype_characteristic'
88
+ );
89
+ $tableCharacteristics = $this->getTable(
90
+ 'innobyte_emag_marketplace/category_characteristic'
91
+ );
92
+ $select = $read->select()
93
+ ->from(array('ft_characteristics' => $tableFtCharacteristics), '*')
94
+ ->join(
95
+ array('characteristics' => $tableCharacteristics),
96
+ 'ft_characteristics.characteristic_id = characteristics.emag_id'
97
+ . ' AND characteristics.category_id = '
98
+ . intval($object->getCategoryId()),
99
+ array('characteristics.id AS mage_id_emag_char')
100
+ )
101
+ ->where(
102
+ 'ft_characteristics.family_type_id = ?',
103
+ intval($object->getId())
104
+ );
105
+ $characteristics = $read->fetchAll($select);
106
+ $returnValue = array();
107
+ foreach ($characteristics as $char) {
108
+ $returnValue[] = new Varien_Object($char);
109
+ }
110
+ return $returnValue;
111
+ }
112
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Category/Familytype/Collection.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG category family-type resource collection model.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Resource_Category_Familytype_Collection
11
+ extends Mage_Core_Model_Resource_Db_Collection_Abstract
12
+ {
13
+ /**
14
+ * Name prefix of events that are dispatched by model
15
+ *
16
+ * @Override
17
+ * @var string
18
+ */
19
+ protected $_eventPrefix = 'innobyte_emag_marketplace_category_familytype_collection';
20
+
21
+ /**
22
+ * Name of event parameter
23
+ *
24
+ * @Override
25
+ * @var string
26
+ */
27
+ protected $_eventObject = 'emag_category_familytype_collection';
28
+
29
+
30
+
31
+ /**
32
+ * @Override
33
+ */
34
+ public function _construct()
35
+ {
36
+ parent::_construct();
37
+ $this->_init('innobyte_emag_marketplace/category_familytype');
38
+ }
39
+
40
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Locality.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG locality resource model.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Resource_Locality
11
+ extends Mage_Core_Model_Resource_Db_Abstract
12
+ {
13
+ /**
14
+ * @Override
15
+ */
16
+ public function _construct()
17
+ {
18
+ $this->_init('innobyte_emag_marketplace/locality', 'id');
19
+ }
20
+
21
+
22
+
23
+ /**
24
+ * @Override
25
+ */
26
+ protected function _prepareDataForSave(Mage_Core_Model_Abstract $object)
27
+ {
28
+ $currentTime = Varien_Date::now();
29
+ if ((!$object->getId() || $object->isObjectNew())
30
+ && !$object->getCreatedAt()) {
31
+ $object->setCreatedAt($currentTime);
32
+ }
33
+ $object->setUpdatedAt($currentTime);
34
+ return parent::_prepareDataForSave($object);
35
+ }
36
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Locality/Collection.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG locality resource collection model.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Resource_Locality_Collection
11
+ extends Mage_Core_Model_Resource_Db_Collection_Abstract
12
+ {
13
+ /**
14
+ * Name prefix of events that are dispatched by model
15
+ *
16
+ * @Override
17
+ * @var string
18
+ */
19
+ protected $_eventPrefix = 'innobyte_emag_marketplace_locality_collection';
20
+
21
+ /**
22
+ * Name of event parameter
23
+ *
24
+ * @Override
25
+ * @var string
26
+ */
27
+ protected $_eventObject = 'emag_locality_collection';
28
+
29
+
30
+
31
+ /**
32
+ * @Override
33
+ */
34
+ public function _construct()
35
+ {
36
+ parent::_construct();
37
+ $this->_init('innobyte_emag_marketplace/locality');
38
+ }
39
+
40
+
41
+
42
+ /**
43
+ * Add filter by store
44
+ *
45
+ * @param int|Mage_Core_Model_Store $mxdStore
46
+ *
47
+ * @return Innobyte_EmagMarketplace_Model_Resource_Locality_Collection
48
+ */
49
+ public function addStoreFilter($mxdStore)
50
+ {
51
+ $stores = array();
52
+ $storesCnt = 0;
53
+ if ($mxdStore instanceof Mage_Core_Model_Store) {
54
+ $stores[] = $mxdStore->getId();
55
+ $storesCnt++;
56
+ } elseif (is_numeric($mxdStore)) {
57
+ $stores[] = (int) $mxdStore;
58
+ $storesCnt++;
59
+ }
60
+
61
+ if (Mage_Core_Model_App::ADMIN_STORE_ID == $stores[0]) {
62
+ foreach (Mage::app()->getWebsites() as $website) {
63
+ foreach ($website->getGroups() as $group) {
64
+ $s = $group->getStores();
65
+ foreach ($s as $storeModel) {
66
+ $stores[] = $storeModel->getId();
67
+ $storesCnt++;
68
+ }
69
+ }
70
+ }
71
+ }
72
+
73
+ if (1 == $storesCnt) {
74
+ $this->addFieldToFilter('store_id', array('eq' => $stores[0]));
75
+ } elseif ($storesCnt > 1) {
76
+ $this->addFieldToFilter('store_id', array('in' => $stores));
77
+ }
78
+
79
+ return $this;
80
+ }
81
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Product.php ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG product resource model.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Resource_Product
11
+ extends Mage_Core_Model_Resource_Db_Abstract
12
+ {
13
+ /**
14
+ * @Override
15
+ */
16
+ public function _construct()
17
+ {
18
+ $this->_init('innobyte_emag_marketplace/product', 'id');
19
+ }
20
+
21
+
22
+
23
+ /**
24
+ * @Override
25
+ */
26
+ protected function _prepareDataForSave(Mage_Core_Model_Abstract $object)
27
+ {
28
+ $currentTime = Varien_Date::now();
29
+ if ((!$object->getId() || $object->isObjectNew())
30
+ && !$object->getCreatedAt()) {
31
+ $object->setCreatedAt($currentTime);
32
+ }
33
+ $object->setUpdatedAt($currentTime);
34
+ return parent::_prepareDataForSave($object);
35
+ }
36
+
37
+
38
+
39
+ /**
40
+ * @Override
41
+ */
42
+ protected function _afterSave(Mage_Core_Model_Abstract $object)
43
+ {
44
+ $write = $this->_getWriteAdapter();
45
+ $read = $this->_getReadAdapter();
46
+
47
+ // save barcodes
48
+ if (!is_array($object->getBarcodes())) {
49
+ $object->setBarcodes(array());
50
+ }
51
+ $tableNameBarcodes = $this->getTable(
52
+ 'innobyte_emag_marketplace/product_barcode'
53
+ );
54
+ $select = $read->select()
55
+ ->from($tableNameBarcodes, array('value'))
56
+ ->where('product_id = ?', intval($object->getId()));
57
+ $currentBarcodes = $read->fetchCol($select);
58
+ $newBarcodes = array_diff($object->getBarcodes(), $currentBarcodes);
59
+ $deleteBarcodes = array_diff($currentBarcodes, $object->getBarcodes());
60
+ if (!empty($deleteBarcodes)) {
61
+ $where = array();
62
+ $where[] = $write->quoteInto('product_id = ?', intval($object->getId()));
63
+ $where[] = $write->quoteInto('value IN (?)', $deleteBarcodes);
64
+ $write->delete($tableNameBarcodes, $where);
65
+ }
66
+ if (!empty($newBarcodes)) {
67
+ $dataToInsert = array();
68
+ foreach ($newBarcodes as $newBarcode) {
69
+ $dataToInsert[] = array(
70
+ 'product_id' => intval($object->getId()),
71
+ 'value' => $newBarcode,
72
+ );
73
+ }
74
+ $write->insertMultiple($tableNameBarcodes, $dataToInsert);
75
+ }
76
+
77
+ // save category 's characteristics
78
+ $tableNameCharacteristics = $this->getTable(
79
+ 'innobyte_emag_marketplace/product_cat_characteristic'
80
+ );
81
+ $select = $read->select()
82
+ ->from($tableNameCharacteristics, array('characteristic_id', 'value'))
83
+ ->where('product_id = ?', intval($object->getId()));
84
+ $currentCharacteristics = $read->fetchPairs($select);
85
+
86
+ $removeChar = array();
87
+ $categoryCharacteristics = array();
88
+ if (!is_null($object->getCategory())
89
+ && is_array($object->getCategory()->getCharacteristics())) {
90
+ $categoryCharacteristics = $object->getCategory()->getCharacteristics();
91
+ }
92
+ foreach ($currentCharacteristics as $charId => $charValue) {
93
+ if (!array_key_exists($charId, $categoryCharacteristics)) {
94
+ $removeChar[] = $charId;
95
+ }
96
+ }
97
+ $updateChar = array();
98
+ $insertChar = array();
99
+ foreach ($categoryCharacteristics as $characteristic) {
100
+ $key = 'category_characteristic' . $characteristic->getId();
101
+ if ($object->hasData($key)
102
+ && array_key_exists($characteristic->getId(), $currentCharacteristics)
103
+ && $currentCharacteristics[$characteristic->getId()] != $object->getData($key)) {
104
+ $updateChar[$characteristic->getId()] = $object->getData($key);
105
+ } elseif ($object->hasData($key)
106
+ && !array_key_exists($characteristic->getId(), $currentCharacteristics)) {
107
+ $insertChar[$characteristic->getId()] = $object->getData($key);
108
+ }
109
+ }
110
+ if (!empty($removeChar)) {
111
+ $where = array();
112
+ $where[] = $write->quoteInto('product_id = ?', intval($object->getId()));
113
+ $where[] = $write->quoteInto('characteristic_id IN (?)', $removeChar);
114
+ $write->delete($tableNameCharacteristics, $where);
115
+ }
116
+ if (!empty($insertChar)) {
117
+ $dataToInsert = array();
118
+ foreach ($insertChar as $charId => $charValue) {
119
+ $dataToInsert[] = array(
120
+ 'product_id' => intval($object->getId()),
121
+ 'characteristic_id' => $charId,
122
+ 'value' => $charValue,
123
+ );
124
+ }
125
+ $write->insertMultiple($tableNameCharacteristics, $dataToInsert);
126
+ }
127
+ if (!empty($updateChar)) {
128
+ foreach ($updateChar as $charId => $charValue) {
129
+ $where = array();
130
+ $where[] = $write->quoteInto('product_id = ?', intval($object->getId()));
131
+ $where[] = $write->quoteInto('characteristic_id = ?', $charId);
132
+ $write->update($tableNameCharacteristics, array('value' => $charValue), $where);
133
+ }
134
+ }
135
+
136
+ return parent::_afterSave($object);
137
+ }
138
+
139
+
140
+
141
+ /**
142
+ * @Override
143
+ */
144
+ protected function _afterLoad(Mage_Core_Model_Abstract $object)
145
+ {
146
+ $read = $this->_getReadAdapter();
147
+
148
+ // attach barcodes
149
+ $tableNameBarcodes = $this->getTable(
150
+ 'innobyte_emag_marketplace/product_barcode'
151
+ );
152
+ $select = $read->select()
153
+ ->from($tableNameBarcodes, array('value'))
154
+ ->where('product_id = ?', intval($object->getId()));
155
+ $object->setBarcodes($read->fetchCol($select));
156
+
157
+ // attach characteristics
158
+ $tableNameCharacteristics = $this->getTable(
159
+ 'innobyte_emag_marketplace/product_cat_characteristic'
160
+ );
161
+ $select = $read->select()
162
+ ->from($tableNameCharacteristics, array('characteristic_id', 'value'))
163
+ ->where('product_id = ?', intval($object->getId()));
164
+ $currentCharacteristics = $read->fetchPairs($select);
165
+ foreach ($currentCharacteristics as $charId => $charValue) {
166
+ $object->setData('category_characteristic' . $charId, $charValue);
167
+ }
168
+
169
+ return parent::_afterLoad($object);
170
+ }
171
+
172
+
173
+
174
+ /**
175
+ * Custom load method.
176
+ *
177
+ * @param Mage_Core_Model_Abstract $object
178
+ * @param int $intProductId
179
+ * @param int $intStoreId
180
+ * @return Innobyte_EmagMarketplace_Model_Resource_Product
181
+ */
182
+ public function loadByProdIdAndStore(
183
+ Mage_Core_Model_Abstract $object,
184
+ $intProductId,
185
+ $intStoreId
186
+ )
187
+ {
188
+ $read = $this->_getReadAdapter();
189
+ if ($read) {
190
+ $fieldProd = $read->quoteIdentifier(
191
+ sprintf('%s.%s', $this->getMainTable(), 'product_id')
192
+ );
193
+ $fieldStore = $read->quoteIdentifier(
194
+ sprintf('%s.%s', $this->getMainTable(), 'store_id')
195
+ );
196
+ $select = $read->select()
197
+ ->from($this->getMainTable())
198
+ ->where($fieldProd . '=?', intval($intProductId))
199
+ ->where($fieldStore . '=?', intval($intStoreId));
200
+ $data = $read->fetchRow($select);
201
+
202
+ if ($data) {
203
+ $object->setData($data);
204
+ }
205
+ }
206
+
207
+ $this->unserializeFields($object);
208
+ $this->_afterLoad($object);
209
+
210
+ return $this;
211
+ }
212
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Product/Collection.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG product resource collection model.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Resource_Product_Collection
11
+ extends Mage_Core_Model_Resource_Db_Collection_Abstract
12
+ {
13
+ /**
14
+ * Name prefix of events that are dispatched by model
15
+ *
16
+ * @Override
17
+ * @var string
18
+ */
19
+ protected $_eventPrefix = 'innobyte_emag_marketplace_product_collection';
20
+
21
+ /**
22
+ * Name of event parameter
23
+ *
24
+ * @Override
25
+ * @var string
26
+ */
27
+ protected $_eventObject = 'emag_product_collection';
28
+
29
+
30
+
31
+ /**
32
+ * @Override
33
+ */
34
+ public function _construct()
35
+ {
36
+ parent::_construct();
37
+ $this->_init('innobyte_emag_marketplace/product');
38
+ }
39
+
40
+
41
+
42
+ /**
43
+ * @Override
44
+ */
45
+ protected function _afterLoad()
46
+ {
47
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
48
+ $tableNameBarcodes = $this->getTable(
49
+ 'innobyte_emag_marketplace/product_barcode'
50
+ );
51
+ $selectBar = $read->select()->from($tableNameBarcodes, array('value'));
52
+ $tableNameCharacteristics = $this->getTable(
53
+ 'innobyte_emag_marketplace/product_cat_characteristic'
54
+ );
55
+ $selectChar = $read->select()->from(
56
+ $tableNameCharacteristics,
57
+ array('characteristic_id', 'value')
58
+ );
59
+
60
+ foreach ($this->getItems() as $item) {
61
+ $selectBar->reset(Zend_Db_Select::WHERE);
62
+ $selectBar->where('product_id = ?', intval($item->getId()));
63
+ $item->setBarcodes($read->fetchCol($selectBar));
64
+
65
+ $selectChar->reset(Zend_Db_Select::WHERE);
66
+ $selectChar->where('product_id = ?', intval($item->getId()));
67
+ $currentCharacteristics = $read->fetchPairs($selectChar);
68
+ foreach ($currentCharacteristics as $charId => $charValue) {
69
+ $item->setData('category_characteristic' . $charId, $charValue);
70
+ }
71
+ }
72
+
73
+ return parent::_afterLoad();
74
+ }
75
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Abstract.php ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Resource_Sales_Abstract
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ abstract class Innobyte_EmagMarketplace_Model_Resource_Sales_Abstract extends Mage_Core_Model_Resource_Db_Abstract
12
+ {
13
+
14
+ /**
15
+ * Column prefix
16
+ *
17
+ * @var null|string
18
+ */
19
+ protected $_columnPrefix = null;
20
+
21
+ /**
22
+ * Primary key auto increment flag
23
+ *
24
+ * @var bool
25
+ */
26
+ protected $_isPkAutoIncrement = false;
27
+
28
+ /**
29
+ * Main entity resource model
30
+ *
31
+ * @var string
32
+ */
33
+ protected $_parentResourceModel = '';
34
+
35
+ /**
36
+ * Get main entity resource model
37
+ *
38
+ * @return Mage_Sales_Model_Resource_Order|Mage_Sales_Model_Resource_Quote
39
+ */
40
+ protected function _getParentResourceModel()
41
+ {
42
+ if (!$this->_parentResourceModel) {
43
+ return null;
44
+ }
45
+
46
+ return Mage::getResourceSingleton($this->_parentResourceModel);
47
+ }
48
+
49
+ /**
50
+ * Get attribute column name
51
+ *
52
+ * @param Mage_Customer_Model_Attribute $attribute
53
+ * @return string
54
+ */
55
+ protected function _getColumnName(Mage_Customer_Model_Attribute $attribute)
56
+ {
57
+ $columnName = $attribute->getAttributeCode();
58
+ if ($this->_columnPrefix) {
59
+ $columnName = sprintf('%s_%s', $this->_columnPrefix, $columnName);
60
+ }
61
+
62
+ return $columnName;
63
+ }
64
+
65
+ /**
66
+ * Saves attribute
67
+ *
68
+ * @param Mage_Customer_Model_Attribute $attribute
69
+ * @return Innobyte_EmagMarketplace_Model_Resource_Sales_Abstract
70
+ */
71
+ public function saveAttribute(Mage_Customer_Model_Attribute $attribute)
72
+ {
73
+ $backendType = $attribute->getBackendType();
74
+ if ($backendType == Mage_Customer_Model_Attribute::TYPE_STATIC) {
75
+ return $this;
76
+ }
77
+
78
+ switch ($backendType) {
79
+ case 'datetime':
80
+ $definition = array(
81
+ 'type' => Varien_Db_Ddl_Table::TYPE_DATE,
82
+ );
83
+ break;
84
+ case 'decimal':
85
+ $definition = array(
86
+ 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
87
+ 'length' => 12, 4,
88
+ );
89
+ break;
90
+ case 'int':
91
+ $definition = array(
92
+ 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
93
+ );
94
+ break;
95
+ case 'text':
96
+ $definition = array(
97
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
98
+ );
99
+ break;
100
+ case 'varchar':
101
+ $definition = array(
102
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
103
+ 'length' => 255,
104
+ );
105
+ break;
106
+ default:
107
+ return $this;
108
+ }
109
+
110
+ $columnName = $this->_getColumnName($attribute);
111
+ $definition['comment'] = ucwords(str_replace('_', ' ', $columnName));
112
+
113
+ $this->_getWriteAdapter()->addColumn($this->getMainTable(), $columnName, $definition);
114
+
115
+ return $this;
116
+ }
117
+
118
+ /**
119
+ * Deletes an attribute
120
+ *
121
+ * @param Mage_Customer_Model_Attribute $attribute
122
+ * @return Innobyte_EmagMarketplace_Model_Resource_Sales_Abstract
123
+ */
124
+ public function deleteAttribute(Mage_Customer_Model_Attribute $attribute)
125
+ {
126
+ $this->_getWriteAdapter()->dropColumn(
127
+ $this->getMainTable(),
128
+ $this->_getColumnName($attribute)
129
+ );
130
+
131
+ return $this;
132
+ }
133
+
134
+ /**
135
+ * Check if main entity exists in main table
136
+ *
137
+ * @param Innobyte_EmagMarketplace_Model_Sales_Abstract $sales
138
+ * @return bool
139
+ */
140
+ public function isEntityExists(Innobyte_EmagMarketplace_Model_Sales_Abstract $sales)
141
+ {
142
+ if (!$sales->getId()) {
143
+ return false;
144
+ }
145
+
146
+ $resource = $this->_getParentResourceModel();
147
+ if (!$resource) {
148
+ // skip if resource model is not available
149
+ return true;
150
+ }
151
+
152
+ $parentTable = $resource->getMainTable();
153
+ $parentIdField = $resource->getIdFieldName();
154
+ $select = $this->_getWriteAdapter()->select()
155
+ ->from($parentTable, $parentIdField)
156
+ ->forUpdate(true)
157
+ ->where("{$parentIdField} = ?", $sales->getId());
158
+
159
+ if ($this->_getWriteAdapter()->fetchOne($select)) {
160
+ return true;
161
+ }
162
+
163
+ return false;
164
+ }
165
+
166
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Address/Abstract.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Resource_Sales_Address_Abstract
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ abstract class Innobyte_EmagMarketplace_Model_Resource_Sales_Address_Abstract
12
+ extends Innobyte_EmagMarketplace_Model_Resource_Sales_Abstract
13
+ {
14
+
15
+ /**
16
+ * Column prefix
17
+ *
18
+ * @var null|string
19
+ */
20
+ protected $_columnPrefix = null;
21
+
22
+ /**
23
+ * Attachs data to collection
24
+ *
25
+ * @param Varien_Data_Collection_Db $collection
26
+ * @return Innobyte_EmagMarketplace_Model_Resource_Sales_Address_Abstract
27
+ */
28
+ public function attachDataToCollection(Varien_Data_Collection_Db $collection)
29
+ {
30
+ $items = array();
31
+ $itemIds = array();
32
+ foreach ($collection->getItems() as $item) {
33
+ $itemIds[] = $item->getId();
34
+ $items[$item->getId()] = $item;
35
+ }
36
+
37
+ if ($itemIds) {
38
+ $select = $this->_getReadAdapter()->select()
39
+ ->from($this->getMainTable())
40
+ ->where("{$this->getIdFieldName()} IN (?)", $itemIds);
41
+ $rowSet = $this->_getReadAdapter()->fetchAll($select);
42
+ foreach ($rowSet as $row) {
43
+ $items[$row[$this->getIdFieldName()]]->addData($row);
44
+ }
45
+ }
46
+
47
+ return $this;
48
+ }
49
+
50
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Invoice.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Resource_Sales_Invoice
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Resource_Sales_Invoice
12
+ extends Mage_Core_Model_Resource_Db_Abstract
13
+ {
14
+
15
+ /**
16
+ * Initialize resource
17
+ */
18
+ protected function _construct()
19
+ {
20
+ $this->_init('innobyte_emag_marketplace/sales_invoice', 'id');
21
+ }
22
+
23
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Invoice/Collection.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Resource_Sales_Invoice_Collection
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Resource_Sales_Invoice_Collection
12
+ extends Mage_Core_Model_Resource_Db_Collection_Abstract
13
+ {
14
+
15
+ /**
16
+ * Prefix of model events names
17
+ *
18
+ * @var string
19
+ */
20
+ protected $_eventPrefix = 'innobyte_emag_marketplace_sales_invoice_collection';
21
+
22
+ /**
23
+ * Parameter name in event
24
+ *
25
+ * In observe method you can use $observer->getEvent()->getInvoiceCollection() in this case
26
+ *
27
+ * @var string
28
+ */
29
+ protected $_eventObject = 'invoice_collection';
30
+
31
+ /**
32
+ * Initialize resource
33
+ */
34
+ public function _construct()
35
+ {
36
+ $this->_init('innobyte_emag_marketplace/sales_invoice');
37
+ }
38
+
39
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Item/Abstract.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Resource_Sales_Address_Abstract
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ abstract class Innobyte_EmagMarketplace_Model_Resource_Sales_Item_Abstract
12
+ extends Innobyte_EmagMarketplace_Model_Resource_Sales_Abstract
13
+ {
14
+
15
+ /**
16
+ * Column prefix
17
+ *
18
+ * @var null|string
19
+ */
20
+ protected $_columnPrefix = null;
21
+
22
+ /**
23
+ * Attachs data to collection
24
+ *
25
+ * @param Varien_Data_Collection_Db $collection
26
+ * @return Innobyte_EmagMarketplace_Model_Resource_Sales_Address_Abstract
27
+ */
28
+ public function attachDataToCollection(Varien_Data_Collection_Db $collection)
29
+ {
30
+ $items = array();
31
+ $itemIds = array();
32
+ foreach ($collection->getItems() as $item) {
33
+ $itemIds[] = $item->getId();
34
+ $items[$item->getId()] = $item;
35
+ }
36
+
37
+ if ($itemIds) {
38
+ $select = $this->_getReadAdapter()->select()
39
+ ->from($this->getMainTable())
40
+ ->where("{$this->getIdFieldName()} IN (?)", $itemIds);
41
+ $rowSet = $this->_getReadAdapter()->fetchAll($select);
42
+ foreach ($rowSet as $row) {
43
+ $items[$row[$this->getIdFieldName()]]->addData($row);
44
+ }
45
+ }
46
+
47
+ return $this;
48
+ }
49
+
50
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Order.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Resource_Sales_Order
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Resource_Sales_Order
12
+ extends Innobyte_EmagMarketplace_Model_Resource_Sales_Abstract
13
+ {
14
+
15
+ /**
16
+ * Main entity resource model name
17
+ *
18
+ * @var string
19
+ */
20
+ protected $_parentResourceModel = 'sales/order';
21
+
22
+ /**
23
+ * Initialize resource
24
+ */
25
+ protected function _construct()
26
+ {
27
+ $this->_init('innobyte_emag_marketplace/sales_order', 'entity_id');
28
+ }
29
+
30
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Order/Address.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Resource_Sales_Order_Address
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Resource_Sales_Order_Address
12
+ extends Innobyte_EmagMarketplace_Model_Resource_Sales_Address_Abstract
13
+ {
14
+
15
+ /**
16
+ * Main entity resource model name
17
+ *
18
+ * @var string
19
+ */
20
+ protected $_parentResourceModel = 'sales/order_address';
21
+
22
+ /**
23
+ * Initializes resource
24
+ */
25
+ protected function _construct()
26
+ {
27
+ $this->_init('innobyte_emag_marketplace/sales_order_address', 'entity_id');
28
+ }
29
+
30
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Order/Item.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Resource_Sales_Order_Item
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Resource_Sales_Order_Item
12
+ extends Innobyte_EmagMarketplace_Model_Resource_Sales_Item_Abstract
13
+ {
14
+
15
+ /**
16
+ * Main entity resource model name
17
+ *
18
+ * @var string
19
+ */
20
+ protected $_parentResourceModel = 'sales/order_item';
21
+
22
+ /**
23
+ * Initialize resource
24
+ */
25
+ protected function _construct()
26
+ {
27
+ $this->_init('innobyte_emag_marketplace/sales_order_item', 'item_id');
28
+ }
29
+
30
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Order/Item/Collection.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Resource_Sales_Quote_Item_Collection
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Resource_Sales_Order_Item_Collection
12
+ extends Mage_Sales_Model_Resource_Order_Item_Collection
13
+ {
14
+
15
+ /**
16
+ * Prefix of model events names
17
+ *
18
+ * @var string
19
+ */
20
+ protected $_eventPrefix = 'sales_order_item_collection';
21
+
22
+ /**
23
+ * Parameter name in event
24
+ *
25
+ * In observer method you can use $observer->getEvent()->getOrderItemCollection()
26
+ *
27
+ * @var string
28
+ */
29
+ protected $_eventObject = 'order_item_collection';
30
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Order/Voucher.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Resource_Sales_Order_Voucher
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Resource_Sales_Order_Voucher
12
+ extends Innobyte_EmagMarketplace_Model_Resource_Sales_Voucher_Abstract
13
+ {
14
+
15
+ /**
16
+ * Initialize resource
17
+ */
18
+ protected function _construct()
19
+ {
20
+ $this->_init('innobyte_emag_marketplace/sales_order_voucher', 'id');
21
+ }
22
+
23
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Order/Voucher/Collection.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Resource_Sales_Order_Voucher_Collection
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Resource_Sales_Order_Voucher_Collection
12
+ extends Mage_Core_Model_Resource_Db_Collection_Abstract
13
+ {
14
+
15
+ /**
16
+ * Prefix of model events names
17
+ *
18
+ * @var string
19
+ */
20
+ protected $_eventPrefix = 'innobyte_emag_marketplace_sales_order_voucher_collection';
21
+
22
+ /**
23
+ * Parameter name in event
24
+ *
25
+ * In observe method you can use $observer->getEvent()->getOrderVoucherCollection() in this case
26
+ *
27
+ * @var string
28
+ */
29
+ protected $_eventObject = 'order_voucher_collection';
30
+
31
+ /**
32
+ * Initialize resource
33
+ */
34
+ public function _construct()
35
+ {
36
+ $this->_init('innobyte_emag_marketplace/sales_order_voucher');
37
+ }
38
+
39
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Quote.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Resource_Sales_Quote
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Resource_Sales_Quote
12
+ extends Innobyte_EmagMarketplace_Model_Resource_Sales_Abstract
13
+ {
14
+
15
+ /**
16
+ * Main entity resource model name
17
+ *
18
+ * @var string
19
+ */
20
+ protected $_parentResourceModel = 'sales/quote';
21
+
22
+ /**
23
+ * Initialize resource
24
+ */
25
+ protected function _construct()
26
+ {
27
+ $this->_init('innobyte_emag_marketplace/sales_quote', 'entity_id');
28
+ }
29
+
30
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Quote/Address.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Resource_Sales_Quote_Address
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Resource_Sales_Quote_Address
12
+ extends Innobyte_EmagMarketplace_Model_Resource_Sales_Address_Abstract
13
+ {
14
+
15
+ /**
16
+ * Main entity resource model name
17
+ *
18
+ * @var string
19
+ */
20
+ protected $_parentResourceModel = 'sales/quote_address';
21
+
22
+ /**
23
+ * Initialize resource
24
+ */
25
+ protected function _construct()
26
+ {
27
+ $this->_init('innobyte_emag_marketplace/sales_quote_address', 'entity_id');
28
+ }
29
+
30
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Quote/Voucher.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Resource_Sales_Quote_Voucher
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Resource_Sales_Quote_Voucher
12
+ extends Innobyte_EmagMarketplace_Model_Resource_Sales_Voucher_Abstract
13
+ {
14
+
15
+ /**
16
+ * Initialize resource
17
+ */
18
+ protected function _construct()
19
+ {
20
+ $this->_init('innobyte_emag_marketplace/sales_quote_voucher', 'id');
21
+ }
22
+
23
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Quote/Voucher/Collection.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Resource_Sales_Quote_Voucher_Collection
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Resource_Sales_Quote_Voucher_Collection
12
+ extends Mage_Core_Model_Resource_Db_Collection_Abstract
13
+ {
14
+
15
+ /**
16
+ * Prefix of model events names
17
+ *
18
+ * @var string
19
+ */
20
+ protected $_eventPrefix = 'innobyte_emag_marketplace_sales_quote_voucher_collection';
21
+
22
+ /**
23
+ * Parameter name in event
24
+ *
25
+ * In observe method you can use $observer->getEvent()->getQuoteVoucherCollection() in this case
26
+ *
27
+ * @var string
28
+ */
29
+ protected $_eventObject = 'quote_voucher_collection';
30
+
31
+ /**
32
+ * Initialize resource
33
+ */
34
+ public function _construct()
35
+ {
36
+ $this->_init('innobyte_emag_marketplace/sales_quote_voucher');
37
+ }
38
+
39
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Sales/Voucher/Abstract.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Resource_Sales_Voucher_Abstract
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ abstract class Innobyte_EmagMarketplace_Model_Resource_Sales_Voucher_Abstract
12
+ extends Mage_Core_Model_Resource_Db_Abstract
13
+ {
14
+
15
+ /**
16
+ * Check if voucher exists
17
+ *
18
+ * @param $voucher Innobyte_EmagMarketplace_Model_Sales_Voucher_Abstract
19
+ * @return bool
20
+ */
21
+ public function isVoucherExists(Innobyte_EmagMarketplace_Model_Sales_Voucher_Abstract $voucher)
22
+ {
23
+ $select = $this->_getWriteAdapter()->select()
24
+ ->from($this->getMainTable(), 'entity_id')
25
+ ->where("entity_id = ?", $voucher->getEntityId())
26
+ ->where("emag_voucher_id = ?", $voucher->getEmagVoucherId());
27
+
28
+ if ($this->_getWriteAdapter()->fetchOne($select)) {
29
+ return true;
30
+ }
31
+
32
+ return false;
33
+ }
34
+
35
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Vat.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG VAT resource model.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Resource_Vat
11
+ extends Mage_Core_Model_Resource_Db_Abstract
12
+ {
13
+
14
+ /**
15
+ * @Override
16
+ */
17
+ public function _construct()
18
+ {
19
+ $this->_init('innobyte_emag_marketplace/vat', 'id');
20
+ }
21
+
22
+
23
+
24
+ /**
25
+ * @Override
26
+ */
27
+ protected function _prepareDataForSave(Mage_Core_Model_Abstract $object)
28
+ {
29
+ $currentTime = Varien_Date::now();
30
+ if ((!$object->getId() || $object->isObjectNew())
31
+ && !$object->getCreatedAt()) {
32
+ $object->setCreatedAt($currentTime);
33
+ }
34
+ $object->setUpdatedAt($currentTime);
35
+ return parent::_prepareDataForSave($object);
36
+ }
37
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Resource/Vat/Collection.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG vat resource collection model.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Resource_Vat_Collection
11
+ extends Mage_Core_Model_Resource_Db_Collection_Abstract
12
+ {
13
+ /**
14
+ * Name prefix of events that are dispatched by model
15
+ *
16
+ * @Override
17
+ * @var string
18
+ */
19
+ protected $_eventPrefix = 'innobyte_emag_marketplace_vat_collection';
20
+
21
+ /**
22
+ * Name of event parameter
23
+ *
24
+ * @Override
25
+ * @var string
26
+ */
27
+ protected $_eventObject = 'emag_vat_collection';
28
+
29
+
30
+
31
+ /**
32
+ * @Override
33
+ */
34
+ public function _construct()
35
+ {
36
+ parent::_construct();
37
+ $this->_init('innobyte_emag_marketplace/vat');
38
+ }
39
+
40
+
41
+
42
+ /**
43
+ * Add filter by store
44
+ *
45
+ * @param int|Mage_Core_Model_Store $mxdStore
46
+ *
47
+ * @return Innobyte_EmagMarketplace_Model_Resource_Vat_Collection
48
+ */
49
+ public function addStoreFilter($mxdStore)
50
+ {
51
+ $stores = array();
52
+ $storesCnt = 0;
53
+ if ($mxdStore instanceof Mage_Core_Model_Store) {
54
+ $stores[] = $mxdStore->getId();
55
+ $storesCnt++;
56
+ } elseif (is_numeric($mxdStore)) {
57
+ $stores[] = (int) $mxdStore;
58
+ $storesCnt++;
59
+ }
60
+
61
+ if (Mage_Core_Model_App::ADMIN_STORE_ID == $stores[0]) {
62
+ foreach (Mage::app()->getWebsites() as $website) {
63
+ foreach ($website->getGroups() as $group) {
64
+ $s = $group->getStores();
65
+ foreach ($s as $storeModel) {
66
+ $stores[] = $storeModel->getId();
67
+ $storesCnt++;
68
+ }
69
+ }
70
+ }
71
+ }
72
+
73
+ if (1 == $storesCnt) {
74
+ $this->addFieldToFilter('store_id', array('eq' => $stores[0]));
75
+ } elseif ($storesCnt > 1) {
76
+ $this->addFieldToFilter('store_id', array('in' => $stores));
77
+ }
78
+
79
+ return $this;
80
+ }
81
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Sales/Abstract.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Sales_Abstract
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ abstract class Innobyte_EmagMarketplace_Model_Sales_Abstract extends Mage_Core_Model_Abstract
12
+ {
13
+
14
+ /**
15
+ * Save attribute
16
+ *
17
+ * @param Mage_Customer_Model_Attribute $attribute
18
+ * @return Innobyte_EmagMarketplace_Model_Sales_Abstract
19
+ */
20
+ public function saveAttribute(Mage_Customer_Model_Attribute $attribute)
21
+ {
22
+ $this->_getResource()->saveAttribute($attribute);
23
+
24
+ return $this;
25
+ }
26
+
27
+ /**
28
+ * Delete attribute
29
+ *
30
+ * @param Mage_Customer_Model_Attribute $attribute
31
+ * @return Innobyte_EmagMarketplace_Model_Sales_Abstract
32
+ */
33
+ public function deleteAttribute(Mage_Customer_Model_Attribute $attribute)
34
+ {
35
+ $this->_getResource()->deleteAttribute($attribute);
36
+
37
+ return $this;
38
+ }
39
+
40
+ /**
41
+ * Attach attribute data to sales object
42
+ *
43
+ * @param Mage_Core_Model_Abstract $sales
44
+ * @return Innobyte_EmagMarketplace_Model_Sales_Abstract
45
+ */
46
+ public function attachAttributeData(Mage_Core_Model_Abstract $sales)
47
+ {
48
+ $sales->addData($this->getData());
49
+
50
+ return $this;
51
+ }
52
+
53
+ /**
54
+ * Save attributes data
55
+ *
56
+ * @param Mage_Core_Model_Abstract $sales
57
+ * @return Innobyte_EmagMarketplace_Model_Sales_Abstract
58
+ */
59
+ public function saveAttributeData(Mage_Core_Model_Abstract $sales)
60
+ {
61
+ $this->addData($sales->getData())
62
+ ->setId($sales->getId())
63
+ ->save();
64
+
65
+ return $this;
66
+ }
67
+
68
+ /**
69
+ * Check if main entity is already deleted from the database:
70
+ * - delete attributes should not be saved in database
71
+ *
72
+ * @return Innobyte_EmagMarketplace_Model_Sales_Abstract
73
+ */
74
+ protected function _beforeSave()
75
+ {
76
+ if ($this->_dataSaveAllowed && !$this->_getResource()->isEntityExists($this)) {
77
+ $this->_dataSaveAllowed = false;
78
+ }
79
+
80
+ return parent::_beforeSave();
81
+ }
82
+
83
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Sales/Address/Abstract.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Sales_Address_Abstract
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ abstract class Innobyte_EmagMarketplace_Model_Sales_Address_Abstract
12
+ extends Innobyte_EmagMarketplace_Model_Sales_Abstract
13
+ {
14
+
15
+ /**
16
+ * Attach data to collection
17
+ *
18
+ * @param Varien_Data_Collection_Db $collection
19
+ * @return Innobyte_EmagMarketplace_Model_Sales_Address_Abstract
20
+ */
21
+ public function attachDataToCollection(Varien_Data_Collection_Db $collection)
22
+ {
23
+ $this->_getResource()->attachDataToCollection($collection);
24
+
25
+ return $this;
26
+ }
27
+
28
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Sales/Invoice.php ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Sales_Invoice
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Sales_Invoice extends Mage_Core_Model_Abstract
12
+ {
13
+
14
+ /**
15
+ * Prefix of model events names
16
+ *
17
+ * @var string
18
+ */
19
+ protected $_eventPrefix = 'innobyte_emag_marketplace_sales_invoice';
20
+
21
+ /**
22
+ * Parameter name in event
23
+ *
24
+ * In observe method you can use $observer->getEvent()->getInvoice() in this case
25
+ *
26
+ * @var string
27
+ */
28
+ protected $_eventObject = 'invoice';
29
+
30
+ /**
31
+ * Emag normal invoice type
32
+ */
33
+ const EMAG_INVOICE_NORMAL = 0;
34
+
35
+ /**
36
+ * Emag storno invoice type
37
+ */
38
+ const EMAG_INVOICE_STORNO = 1;
39
+
40
+ /**
41
+ * Code
42
+ */
43
+ const THIRD_PARTY_INVOICE = 'third_party_invoice';
44
+
45
+ /**
46
+ * Magento invoice directory
47
+ */
48
+ const MAGENTO_INVOICE_DIRECTORY = 'innobyte/emag_marketplace/magento_invoice/';
49
+
50
+ /**
51
+ * Magento creditmemo directory
52
+ */
53
+ const MAGENTO_CREDITMEMO_DIRECTORY = 'innobyte/emag_marketplace/magento_creditmemo/';
54
+
55
+ /**
56
+ * Third party invoice directory
57
+ */
58
+ const THIRD_PARTY_INVOICE_DIRECTORY = 'innobyte/emag_marketplace/third_party_invoice/';
59
+
60
+ /**
61
+ * Initialize resource model
62
+ */
63
+ protected function _construct()
64
+ {
65
+ $this->_init('innobyte_emag_marketplace/sales_invoice');
66
+ }
67
+
68
+ /**
69
+ * Attach third party invoices to order
70
+ *
71
+ * @param $sales Mage_Sales_Model_Order
72
+ * @return Innobyte_EmagMarketplace_Model_Sales_Invoice
73
+ */
74
+ public function attachInvoiceData($sales)
75
+ {
76
+ $invoices = $this->getEmagThirdPartyInvoices($sales->getId());
77
+ if (!empty($invoices)) {
78
+ $sales->addData(array('emag_third_party_invoice' => $invoices));
79
+ }
80
+
81
+ return $this;
82
+ }
83
+
84
+ /**
85
+ * Get third party invoices collection
86
+ *
87
+ * @param $orderId
88
+ * @return mixed
89
+ */
90
+ public function getEmagThirdPartyInvoicesCollection($orderId)
91
+ {
92
+ $collection = $this->getCollection()
93
+ ->addFieldToFilter('order_id', $orderId);
94
+
95
+ return $collection;
96
+ }
97
+
98
+ /**
99
+ * Get third party invoices
100
+ *
101
+ * @param $orderId
102
+ * @return array
103
+ */
104
+ public function getEmagThirdPartyInvoices($orderId)
105
+ {
106
+ $invoices = array();
107
+
108
+ $collection = $this->getEmagThirdPartyInvoicesCollection($orderId);
109
+ if (!$collection->getSize()) {
110
+ return $invoices;
111
+ }
112
+
113
+ foreach ($collection as $invoice) {
114
+ $invoices[$invoice->getId()] = $invoice->getEmagInvoiceName();
115
+ }
116
+
117
+ return $invoices;
118
+ }
119
+
120
+ /**
121
+ * Media invoice directory name
122
+ *
123
+ * @return string
124
+ */
125
+ public function getInvoiceDirectory()
126
+ {
127
+ return self::THIRD_PARTY_INVOICE_DIRECTORY;
128
+ }
129
+
130
+ /**
131
+ * Base disk directory where invoices are stored
132
+ *
133
+ * @return string
134
+ */
135
+ public function getInvoiceBaseDirectory()
136
+ {
137
+ return Mage::getBaseDir('media') . DS . $this->getInvoiceDirectory();
138
+ }
139
+
140
+ /**
141
+ * Get invoice url
142
+ *
143
+ * @return string
144
+ */
145
+ public function getInvoiceUrl()
146
+ {
147
+ return Mage::getBaseUrl('media') . $this->getInvoiceDirectory() . $this->getEmagInvoiceName();
148
+ }
149
+
150
+ /**
151
+ * Get invoice path
152
+ *
153
+ * @return string
154
+ */
155
+ public function getInvoicePath()
156
+ {
157
+ return $this->getInvoiceDirectory() . $this->getEmagInvoiceName();
158
+ }
159
+
160
+ /**
161
+ * Get invoice base path
162
+ *
163
+ * @return string
164
+ */
165
+ public function getInvoiceBasePath()
166
+ {
167
+ return $this->getInvoiceBaseDirectory() . $this->getEmagInvoiceName();
168
+ }
169
+
170
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Sales/Item/Abstract.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Sales_Address_Abstract
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ abstract class Innobyte_EmagMarketplace_Model_Sales_Item_Abstract
12
+ extends Innobyte_EmagMarketplace_Model_Sales_Abstract
13
+ {
14
+
15
+ /**
16
+ * Attach data to collection
17
+ *
18
+ * @param Varien_Data_Collection_Db $collection
19
+ * @return Innobyte_EmagMarketplace_Model_Sales_Address_Abstract
20
+ */
21
+ public function attachDataToCollection(Varien_Data_Collection_Db $collection)
22
+ {
23
+ $this->_getResource()->attachDataToCollection($collection);
24
+
25
+ return $this;
26
+ }
27
+
28
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Sales/Observer.php ADDED
@@ -0,0 +1,934 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Sales_Observer
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Sales_Observer
12
+ {
13
+
14
+ /**
15
+ * Conversion types
16
+ */
17
+ const CUSTOMER = 'customer';
18
+ const CUSTOMER_ADDRESS = 'customer_address';
19
+
20
+ /**
21
+ * Get voucher attribute name
22
+ *
23
+ * @return string
24
+ */
25
+ protected function _getVouchersAttributeName()
26
+ {
27
+ return Innobyte_EmagMarketplace_Model_Sales_Voucher_Abstract::EMAG_VOUCHERS;
28
+ }
29
+
30
+ /**
31
+ * @return Innobyte_EmagMarketplace_Model_Api_Order
32
+ */
33
+ public function getOrderApiModel()
34
+ {
35
+ return Mage::getModel('innobyte_emag_marketplace/api_order');
36
+ }
37
+
38
+ /**
39
+ * Get eMAG marketplace data helper
40
+ *
41
+ * @return Innobyte_EmagMarketplace_Helper_Data
42
+ */
43
+ protected function _getHelper()
44
+ {
45
+ return Mage::helper('innobyte_emag_marketplace');
46
+ }
47
+
48
+ /**
49
+ * Change shipping method rate price
50
+ *
51
+ * Apply eMAG shipping price on:
52
+ * - adminhtml_sales_order_create_process_data_before
53
+ *
54
+ * @param Varien_Event_Observer $observer
55
+ * @return $this
56
+ */
57
+ public function applyEmagShippingMethod(Varien_Event_Observer $observer)
58
+ {
59
+ /** @var $quote Mage_Sales_Model_Quote */
60
+ $quote = $observer->getEvent()->getSession()->getQuote();
61
+ $data = Mage::app()->getRequest()->getPost('order');
62
+
63
+ if (
64
+ isset($data['carrier'])
65
+ && $data['carrier'] == Innobyte_EmagMarketplace_Model_Shipping_Carrier_Emag::EMAG_SHIPPING
66
+ ) {
67
+ $shippingMethod = $data['shipping_method'];
68
+ $quote->getShippingAddress()->setShippingMethod($shippingMethod);
69
+
70
+ $shippingAmount = $this->_parseShippingAmount($data['shipping_amount']);
71
+ $rates = $quote->getShippingAddress()->collectShippingRates()
72
+ ->getGroupedAllShippingRates();
73
+
74
+ foreach ($rates as $carrier) {
75
+ /** @var $rate Mage_Sales_Model_Quote_Address_Rate */
76
+ foreach ($carrier as $rate) {
77
+ // set new price for eMAG shipping
78
+ if ($rate->getCode() == $shippingMethod) {
79
+ $rate->setPrice($shippingAmount);
80
+ $rate->save();
81
+ break;
82
+ }
83
+ }
84
+ }
85
+ }
86
+
87
+ return $this;
88
+ }
89
+
90
+ /**
91
+ * Parse shipping amount
92
+ *
93
+ * @param $price
94
+ * @return float|int|null
95
+ */
96
+ protected function _parseShippingAmount($price)
97
+ {
98
+ $price = Mage::app()->getLocale()->getNumber($price);
99
+ if ($price > 0) {
100
+ return $price;
101
+ }
102
+
103
+ return 0;
104
+ }
105
+
106
+ /**
107
+ * Convert shipping amount to base currency
108
+ *
109
+ * @param Mage_Sales_Model_Quote $quote
110
+ * @param $shippingAmount
111
+ * @param bool $round
112
+ * @return float
113
+ */
114
+ protected function _getBaseShippingAmount(Mage_Sales_Model_Quote $quote, $shippingAmount, $round = false)
115
+ {
116
+ $baseCurrency = $quote->getBaseCurrencyCode();
117
+ $currentCurrency = $quote->getQuoteCurrencyCode();
118
+
119
+ /** @var $model Mage_Directory_Model_Currency */
120
+ $model = Mage::getModel('directory/currency');
121
+ $allowedCurrencies = $model->getConfigAllowCurrencies();
122
+ $rates = $model->getCurrencyRates($baseCurrency, $allowedCurrencies);
123
+
124
+ $baseShippingAmount = $shippingAmount / $rates[$currentCurrency];
125
+
126
+ if ($round) {
127
+ return $quote->getStore()->roundPrice($baseShippingAmount);
128
+ }
129
+
130
+ return $baseShippingAmount;
131
+ }
132
+
133
+ /**
134
+ * Save attribute data for quote on:
135
+ * - sales_quote_save_after
136
+ *
137
+ * @param Varien_Event_Observer $observer
138
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
139
+ */
140
+ public function quoteAfterSave(Varien_Event_Observer $observer)
141
+ {
142
+ /** @var $quote Mage_Sales_Model_Quote */
143
+ $quote = $observer->getEvent()->getQuote();
144
+
145
+ // skip if not eMAG order
146
+ if (!$quote->getEmagOrderId()) {
147
+ return $this;
148
+ }
149
+
150
+ if ($quote instanceof Mage_Core_Model_Abstract) {
151
+ Mage::getModel('innobyte_emag_marketplace/sales_quote')
152
+ ->saveAttributeData($quote);
153
+
154
+ Mage::getModel('innobyte_emag_marketplace/sales_quote_voucher')
155
+ ->saveVoucherData($quote);
156
+ }
157
+
158
+ return $this;
159
+ }
160
+
161
+ /**
162
+ * Change order status to "emag_in_progress" on:
163
+ * - sales_order_invoice_register
164
+ *
165
+ * @param Varien_Event_Observer $observer
166
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
167
+ */
168
+ public function invoiceRegister(Varien_Event_Observer $observer)
169
+ {
170
+ /** @var $order Mage_Sales_Model_Order */
171
+ $order = $observer->getEvent()->getOrder();
172
+ if (!$order->getEmagOrderId()) {
173
+ return $this;
174
+ }
175
+ $order->setState(
176
+ Mage_Sales_Model_Order::STATE_PROCESSING,
177
+ Innobyte_EmagMarketplace_Model_Order_Convert_Abstract::STATUS_IN_PROGRESS
178
+ );
179
+
180
+ return $this;
181
+ }
182
+
183
+ /**
184
+ * Generate invoice for eMAG orders paid with credit card and payment status "paid" on:
185
+ * - sales_order_place_after
186
+ *
187
+ * Notes:
188
+ * - order must be in state processing to generate invoice
189
+ * - order must have acknowledge() request sent to eMAG before generating invoice
190
+ * - order payment must be credit card with status "paid"
191
+ *
192
+ * @param Varien_Event_Observer $observer
193
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
194
+ * @throws Exception
195
+ * @throws Innobyte_EmagMarketplace_Exception
196
+ */
197
+ public function orderAfterPlace(Varien_Event_Observer $observer)
198
+ {
199
+ /** @var $order Mage_Sales_Model_Order */
200
+ $order = $observer->getEvent()->getOrder();
201
+ if (!$order->getEmagOrderId()) {
202
+ return $this;
203
+ }
204
+
205
+ if ($order->getState() != Mage_Sales_Model_Order::STATE_PROCESSING) {
206
+ return $this;
207
+ }
208
+
209
+ if ($order->getEmagPaymentStatus() != Innobyte_EmagMarketplace_Model_Order_Convert_Abstract::EMAG_PAYMENT_STATUS_PAID) {
210
+ return $this;
211
+ }
212
+
213
+ try {
214
+ $invoice = $this->_prepareInvoice($order);
215
+ $order->addStatusHistoryComment(
216
+ $this->_getHelper()->__(
217
+ 'Amount of %s captured by eMAG Marketplace.', $order->formatPriceTxt($order->getGrandTotal())
218
+ ),
219
+ false
220
+ );
221
+
222
+ $transaction = Mage::getModel('core/resource_transaction');
223
+ $transaction->addObject($invoice);
224
+ $transaction->addObject($invoice->getOrder());
225
+ $transaction->save();
226
+ } catch (Exception $e) {
227
+ throw new Exception($e->getMessage());
228
+ }
229
+
230
+ return $this;
231
+ }
232
+
233
+ /**
234
+ * Prepare correct statuses for eMAG order on:
235
+ * - sales_order_save_before
236
+ *
237
+ * Notes:
238
+ * - eMAG orders allowed states are only: new, processing,
239
+ *
240
+ * @param Varien_Event_Observer $observer
241
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
242
+ */
243
+ public function orderBeforeSave(Varien_Event_Observer $observer)
244
+ {
245
+ /** @var $order Mage_Sales_Model_Order */
246
+ $order = $observer->getEvent()->getOrder();
247
+
248
+ if (!$order->getEmagOrderId()) {
249
+ return $this;
250
+ }
251
+
252
+ // exit if order state is canceled, complete or closed
253
+ if (
254
+ $order->isStateProtected($order->getState())
255
+ || $order->getState() == Mage_Sales_Model_Order::STATE_CANCELED
256
+ ) {
257
+ return $this;
258
+ }
259
+
260
+ // for edit mode order state and status is not available; apply it
261
+ if (!$order->getState()) {
262
+ $order->setState(
263
+ Mage_Sales_Model_Order::STATE_PROCESSING,
264
+ Innobyte_EmagMarketplace_Model_Order_Convert_Abstract::STATUS_IN_PROGRESS
265
+ );
266
+ }
267
+
268
+ /** @var $model Innobyte_EmagMarketplace_Model_Sales_Order */
269
+ $model = Mage::getModel('innobyte_emag_marketplace/sales_order');
270
+ $allowedOrderStates = $model->getAllowedOrderStates();
271
+ if (!in_array($order->getState(), $allowedOrderStates)) {
272
+ Mage::throwException(
273
+ $this->_getHelper()->__(
274
+ 'Order state "%s" is not valid for eMAG orders!', $order->getState()
275
+ )
276
+ );
277
+ }
278
+
279
+ //TODO: check if status is set correctly after performing a magento default action; if not set is manually
280
+ //if (!in_array($order->getStatus(), $model->getEmagOrderStatuses())) {
281
+ // $order->setStatus($order->getOrigData('status'));
282
+ //}
283
+
284
+ if (
285
+ !$order->isCanceled()
286
+ && !$order->canUnhold()
287
+ && !$order->canInvoice()
288
+ && !$order->canShip()
289
+ ) {
290
+ if (
291
+ 0 == $order->getBaseGrandTotal()
292
+ || $order->canCreditmemo()
293
+ ) {
294
+ $emagOrderStatus = $this->getConfig()
295
+ ->getStateDefaultStatus(Mage_Sales_Model_Order::STATE_COMPLETE);
296
+ } /**
297
+ * Order can be closed just in case when we have refunded amount.
298
+ * In case of "0" grand total order checking ForcedCanCreditmemo flag
299
+ */
300
+ elseif (
301
+ floatval($order->getTotalRefunded())
302
+ || (!$order->getTotalRefunded()
303
+ && $order->hasForcedCanCreditmemo())
304
+ ) {
305
+ $emagOrderStatus = Innobyte_EmagMarketplace_Model_Order_Convert_Abstract::STATUS_RETURNED;
306
+ }
307
+
308
+ Mage::register('emag_order_status', $emagOrderStatus);
309
+ }
310
+
311
+ return $this;
312
+ }
313
+
314
+ /**
315
+ * Set eMAG order status as "emag_returned" for full refund on:
316
+ * - sales_order_status_load_after
317
+ *
318
+ * @see method _checkState() from Mage_Sales_Model_Order for more info
319
+ *
320
+ * @param Varien_Event_Observer $observer
321
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
322
+ */
323
+ public function updateOrderStatus(Varien_Event_Observer $observer)
324
+ {
325
+ /** @var $status Mage_Sales_Model_Order_Status */
326
+ $status = $observer->getEvent()->getOrderStatus();
327
+
328
+ //set order status to "emag_returned" if credit memo is total refund
329
+ $orderStatus = Mage::registry('emag_order_status');
330
+ if ($orderStatus) {
331
+ $status->setStatus($orderStatus);
332
+ }
333
+
334
+ return $this;
335
+ }
336
+
337
+ /**
338
+ * Save attribute data for order on:
339
+ * - sales_order_save_after
340
+ *
341
+ * @param Varien_Event_Observer $observer
342
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
343
+ */
344
+ public function orderAfterSave(Varien_Event_Observer $observer)
345
+ {
346
+ /** @var $order Mage_Sales_Model_Order */
347
+ $order = $observer->getEvent()->getOrder();
348
+
349
+ // skip if not eMAG order
350
+ if (!$order->getEmagOrderId()) {
351
+ return $this;
352
+ }
353
+
354
+ if ($order instanceof Mage_Core_Model_Abstract) {
355
+ Mage::getModel('innobyte_emag_marketplace/sales_order')
356
+ ->saveAttributeData($order);
357
+
358
+ Mage::getModel('innobyte_emag_marketplace/sales_order_voucher')
359
+ ->saveVoucherData($order);
360
+ }
361
+
362
+ // update eMAG order only if state is processing
363
+ if ($order->getState() == Mage_Sales_Model_Order::STATE_PROCESSING) {
364
+ if (!Mage::registry('is_emag_order_updated')) {
365
+ $this->_updateEmagOrder($order);
366
+ }
367
+ }
368
+
369
+ return $this;
370
+ }
371
+
372
+ /**
373
+ * Save item custom data for order item on:
374
+ * - sales_order_item_save_after
375
+ *
376
+ * @param Varien_Event_Observer $observer
377
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
378
+ */
379
+ public function orderItemAfterSave(Varien_Event_Observer $observer)
380
+ {
381
+ /** @var $item Mage_Sales_Model_Order_Item */
382
+ $item = $observer->getEvent()->getItem();
383
+
384
+ // skip if not eMAG order
385
+ if (!$item->getOrder()->getEmagOrderId()) {
386
+ return $this;
387
+ }
388
+
389
+ if ($item instanceof Mage_Core_Model_Abstract) {
390
+ Mage::getModel('innobyte_emag_marketplace/sales_order_item')
391
+ ->saveAttributeData($item);
392
+ }
393
+
394
+ return $this;
395
+ }
396
+
397
+ /**
398
+ * Attach attribute data to quote on:
399
+ * - sales_quote_load_after
400
+ *
401
+ * @param Varien_Event_Observer $observer
402
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
403
+ */
404
+ public function quoteAfterLoad(Varien_Event_Observer $observer)
405
+ {
406
+ /** @var $quote Mage_Sales_Model_Quote */
407
+ $quote = $observer->getEvent()->getQuote();
408
+ if ($quote instanceof Mage_Core_Model_Abstract) {
409
+ Mage::getModel('innobyte_emag_marketplace/sales_quote')
410
+ ->load($quote->getId())
411
+ ->attachAttributeData($quote);
412
+
413
+ // skip if not eMAG order
414
+ if (!$quote->getEmagOrderId()) {
415
+ return $this;
416
+ }
417
+
418
+ // attach eMAG vouchers
419
+ Mage::getModel('innobyte_emag_marketplace/sales_quote_voucher')
420
+ ->attachVoucherData($quote);
421
+ }
422
+
423
+ return $this;
424
+ }
425
+
426
+ /**
427
+ * Attach item custom data to quote item on:
428
+ * - sales_quote_item_collection_products_after_load
429
+ *
430
+ * @param Varien_Event_Observer $observer
431
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
432
+ */
433
+ public function orderItemCollectionAfterLoad(Varien_Event_Observer $observer)
434
+ {
435
+ $collection = $observer->getEvent()->getOrderItemCollection();
436
+ if ($collection instanceof Varien_Data_Collection_Db) {
437
+ Mage::getModel('innobyte_emag_marketplace/sales_order_item')
438
+ ->attachDataToCollection($collection);
439
+ }
440
+
441
+ return $this;
442
+ }
443
+
444
+ /**
445
+ * Attach attribute invoice and voucher data to order on:
446
+ * - sales_order_load_after
447
+ *
448
+ * @param Varien_Event_Observer $observer
449
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
450
+ */
451
+ public function orderAfterLoad(Varien_Event_Observer $observer)
452
+ {
453
+ /** @var $quote Mage_Sales_Model_Order */
454
+ $order = $observer->getEvent()->getOrder();
455
+ if ($order instanceof Mage_Core_Model_Abstract) {
456
+ // attach attribute data
457
+ Mage::getModel('innobyte_emag_marketplace/sales_order')
458
+ ->load($order->getId())
459
+ ->attachAttributeData($order);
460
+
461
+ // skip if not eMAG order
462
+ if (!$order->getEmagOrderId()) {
463
+ return $this;
464
+ }
465
+
466
+ // attach third party invoice data
467
+ Mage::getModel('innobyte_emag_marketplace/sales_invoice')
468
+ ->attachInvoiceData($order);
469
+
470
+ // attach eMAG vouchers
471
+ Mage::getModel('innobyte_emag_marketplace/sales_order_voucher')
472
+ ->attachVoucherData($order);
473
+ }
474
+
475
+ return $this;
476
+ }
477
+
478
+ /**
479
+ * Attach attribute and voucher data to invoice on:
480
+ * - sales_order_invoice_load_after
481
+ *
482
+ * @param Varien_Event_Observer $observer
483
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
484
+ */
485
+ public function invoiceAfterLoad(Varien_Event_Observer $observer)
486
+ {
487
+ /** @var $invoice Mage_Sales_Model_Order_Invoice */
488
+ $invoice = $observer->getEvent()->getInvoice();
489
+ if ($invoice instanceof Mage_Core_Model_Abstract) {
490
+ // attach attribute data
491
+ Mage::getModel('innobyte_emag_marketplace/sales_order')
492
+ ->load($invoice->getId())
493
+ ->attachAttributeData($invoice);
494
+
495
+ // attach eMAG vouchers
496
+ $invoice->addData(array($this->_getVouchersAttributeName() => $invoice->getOrder()->getEmagVouchers()));
497
+ }
498
+
499
+ return $this;
500
+ }
501
+
502
+ /**
503
+ * Attach attribute and voucher data to creditmemo on:
504
+ * - sales_order_creditmemo_load_after
505
+ *
506
+ * @param Varien_Event_Observer $observer
507
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
508
+ */
509
+ public function creditmemoAfterLoad(Varien_Event_Observer $observer)
510
+ {
511
+ /** @var $creditmemo Mage_Sales_Model_Order_Invoice */
512
+ $creditmemo = $observer->getEvent()->getCreditmemo();
513
+ if ($creditmemo instanceof Mage_Core_Model_Abstract) {
514
+ // attach attribute data
515
+ Mage::getModel('innobyte_emag_marketplace/sales_order')
516
+ ->load($creditmemo->getId())
517
+ ->attachAttributeData($creditmemo);
518
+
519
+ // attach eMAG vouchers
520
+ $creditmemo->addData(array($this->_getVouchersAttributeName() => $creditmemo->getOrder()->getEmagVouchers()));
521
+ }
522
+
523
+ return $this;
524
+ }
525
+
526
+ /**
527
+ * Save attribute data for quote address on:
528
+ * - sales_quote_address_save_after
529
+ *
530
+ * @param Varien_Event_Observer $observer
531
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
532
+ */
533
+ public function quoteAddressAfterSave(Varien_Event_Observer $observer)
534
+ {
535
+ /** @var $quoteAddress Mage_Sales_Model_Quote_Address */
536
+ $quoteAddress = $observer->getEvent()->getQuoteAddress();
537
+
538
+ // skip if not eMAG order
539
+ if (!$quoteAddress->getQuote()->getEmagOrderId()) {
540
+ return $this;
541
+ }
542
+
543
+ if ($quoteAddress instanceof Mage_Core_Model_Abstract) {
544
+ Mage::getModel('innobyte_emag_marketplace/sales_quote_address')
545
+ ->saveAttributeData($quoteAddress);
546
+ }
547
+
548
+ return $this;
549
+ }
550
+
551
+ /**
552
+ * Save attribute data for order address on:
553
+ * - sales_order_address_save_after
554
+ *
555
+ * @param Varien_Event_Observer $observer
556
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
557
+ */
558
+ public function orderAddressAfterSave(Varien_Event_Observer $observer)
559
+ {
560
+ /** @var $orderAddress Mage_Sales_Model_Order_Address */
561
+ $orderAddress = $observer->getEvent()->getAddress();
562
+
563
+ // skip if not eMAG order
564
+ if (!$orderAddress->getOrder()->getEmagOrderId()) {
565
+ return $this;
566
+ }
567
+
568
+ if ($orderAddress instanceof Mage_Core_Model_Abstract) {
569
+ Mage::getModel('innobyte_emag_marketplace/sales_order_address')
570
+ ->saveAttributeData($orderAddress);
571
+ }
572
+
573
+ return $this;
574
+ }
575
+
576
+ /**
577
+ * Attach attribute data to quote collection on:
578
+ * - sales_quote_address_collection_load_after
579
+ *
580
+ * @param Varien_Event_Observer $observer
581
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
582
+ */
583
+ public function quoteAddressCollectionAfterLoad(Varien_Event_Observer $observer)
584
+ {
585
+ $collection = $observer->getEvent()->getQuoteAddressCollection();
586
+ if ($collection instanceof Varien_Data_Collection_Db) {
587
+ Mage::getModel('innobyte_emag_marketplace/sales_quote_address')
588
+ ->attachDataToCollection($collection);
589
+ }
590
+
591
+ return $this;
592
+ }
593
+
594
+ /**
595
+ * Attach attribute data to order collection on:
596
+ * - sales_order_address_collection_load_after
597
+ *
598
+ * @param Varien_Event_Observer $observer
599
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
600
+ */
601
+ public function orderAddressCollectionAfterLoad(Varien_Event_Observer $observer)
602
+ {
603
+ $collection = $observer->getEvent()->getOrderAddressCollection();
604
+ if ($collection instanceof Varien_Data_Collection_Db) {
605
+ Mage::getModel('innobyte_emag_marketplace/sales_order_address')
606
+ ->attachDataToCollection($collection);
607
+ }
608
+
609
+ return $this;
610
+ }
611
+
612
+ /**
613
+ * Convert customer to quote on:
614
+ * - core_copy_fieldset_customer_account_to_quote
615
+ *
616
+ * @param Varien_Event_Observer $observer
617
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
618
+ */
619
+ public function convertCustomerAccountToQuote(Varien_Event_Observer $observer)
620
+ {
621
+ $this->_copyFieldset($observer, self::CUSTOMER);
622
+
623
+ return $this;
624
+ }
625
+
626
+ /**
627
+ * Convert quote to order on:
628
+ * - core_copy_fieldset_sales_convert_quote_to_order
629
+ *
630
+ * @param Varien_Event_Observer $observer
631
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
632
+ */
633
+ public function convertSalesConvertQuoteToOrder(Varien_Event_Observer $observer)
634
+ {
635
+ $this->_copyFieldset($observer, self::CUSTOMER);
636
+
637
+ return $this;
638
+ }
639
+
640
+ /**
641
+ * Convert quote to customer on:
642
+ * - core_copy_fieldset_checkout_onepage_quote_to_customer
643
+ *
644
+ * @param Varien_Event_Observer $observer
645
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
646
+ */
647
+ public function convertCheckoutOnepageQuoteToCustomer(Varien_Event_Observer $observer)
648
+ {
649
+ $this->_copyFieldset($observer, self::CUSTOMER);
650
+
651
+ return $this;
652
+ }
653
+
654
+ /**
655
+ * Convert order to quote on:
656
+ * - core_copy_fieldset_sales_copy_order_to_edit
657
+ *
658
+ * @param Varien_Event_Observer $observer
659
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
660
+ */
661
+ public function convertSalesCopyOrderToEdit(Varien_Event_Observer $observer)
662
+ {
663
+ $this->_copyFieldset($observer, self::CUSTOMER);
664
+
665
+ return $this;
666
+ }
667
+
668
+ /**
669
+ * Attach voucher data from order to quote on (order edit):
670
+ * - core_copy_fieldset_sales_copy_order_to_edit
671
+ *
672
+ * @param Varien_Event_Observer $observer
673
+ * @return $this
674
+ */
675
+ public function convertSalesCopyOrderVoucherToEdit(Varien_Event_Observer $observer)
676
+ {
677
+ /** @var $source Mage_Sales_Model_Order */
678
+ $source = $observer->getEvent()->getSource();
679
+
680
+ // skip if not eMAG order
681
+ if (!$source->getEmagOrderId()) {
682
+ return $this;
683
+ }
684
+
685
+ /** @var $target Mage_Sales_Model_Quote */
686
+ $target = $observer->getEvent()->getTarget();
687
+ $attribute = $this->_getVouchersAttributeName();
688
+
689
+ $target->setData($attribute, $source->getData($attribute));
690
+
691
+ return $this;
692
+ }
693
+
694
+ /**
695
+ * Convert customer address to quote address on:
696
+ * - core_copy_fieldset_customer_address_to_quote_address
697
+ *
698
+ * @param Varien_Event_Observer $observer
699
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
700
+ */
701
+ public function convertCustomerAddressToQuoteAddress(Varien_Event_Observer $observer)
702
+ {
703
+ $this->_copyFieldset($observer, self::CUSTOMER_ADDRESS);
704
+
705
+ return $this;
706
+ }
707
+
708
+ /**
709
+ * Convert quote address to order address on:
710
+ * - core_copy_fieldset_sales_convert_quote_address_to_order_address
711
+ *
712
+ * @param Varien_Event_Observer $observer
713
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
714
+ */
715
+ public function convertSalesConvertQuoteAddressToOrderAddress(Varien_Event_Observer $observer)
716
+ {
717
+ $this->_copyFieldset($observer, self::CUSTOMER_ADDRESS);
718
+
719
+ return $this;
720
+ }
721
+
722
+ /**
723
+ * Convert quote address to customer address on:
724
+ * - core_copy_fieldset_sales_convert_quote_address_to_customer_address
725
+ *
726
+ * @param Varien_Event_Observer $observer
727
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
728
+ */
729
+ public function convertQuoteAddressToCustomerAddress(Varien_Event_Observer $observer)
730
+ {
731
+ $this->_copyFieldset($observer, self::CUSTOMER_ADDRESS);
732
+
733
+ return $this;
734
+ }
735
+
736
+ /**
737
+ * Convert order billing address to quote billing address on:
738
+ * - core_copy_fieldset_sales_copy_order_billing_address_to_order
739
+ *
740
+ * @param Varien_Event_Observer $observer
741
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
742
+ */
743
+ public function convertSalesCopyOrderBillingAddressToOrder(Varien_Event_Observer $observer)
744
+ {
745
+ $this->_copyFieldset($observer, self::CUSTOMER_ADDRESS);
746
+
747
+ return $this;
748
+ }
749
+
750
+ /**
751
+ * Convert order shipping address to quote shipping address on:
752
+ * - core_copy_fieldset_sales_copy_order_shipping_address_to_order
753
+ *
754
+ * @param Varien_Event_Observer $observer
755
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
756
+ */
757
+ public function convertSalesCopyOrderShippingAddressToOrder(Varien_Event_Observer $observer)
758
+ {
759
+ $this->_copyFieldset($observer, self::CUSTOMER_ADDRESS);
760
+
761
+ return $this;
762
+ }
763
+
764
+ /**
765
+ * Copy fieldset
766
+ *
767
+ * @param Varien_Event_Observer $observer
768
+ * @param string $type
769
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
770
+ */
771
+ protected function _copyFieldset(Varien_Event_Observer $observer, $type)
772
+ {
773
+ $source = $observer->getEvent()->getSource();
774
+ $target = $observer->getEvent()->getTarget();
775
+
776
+ if ($source instanceof Mage_Core_Model_Abstract && $target instanceof Mage_Core_Model_Abstract) {
777
+ if ($type == self::CUSTOMER) {
778
+ /** @var $model Innobyte_EmagMarketplace_Model_Customer_Attributes */
779
+ $model = Mage::getModel('innobyte_emag_marketplace/customer_attributes');
780
+ $model->setEntityType(self::CUSTOMER);
781
+ $attributes = $model->getCustomerAttributes();
782
+ } else if ($type == self::CUSTOMER_ADDRESS) {
783
+ /** @var $model Innobyte_EmagMarketplace_Model_Customer_Attributes */
784
+ $model = Mage::getModel('innobyte_emag_marketplace/customer_attributes');
785
+ $model->setEntityType(self::CUSTOMER_ADDRESS);
786
+ $attributes = $model->getCustomerAddressAttributes();
787
+ } else {
788
+ return $this;
789
+ }
790
+
791
+ foreach ($attributes as $attribute) {
792
+ $target->setData($attribute, $source->getData($attribute));
793
+ }
794
+ }
795
+
796
+ return $this;
797
+ }
798
+
799
+ /**
800
+ * Prepare order invoice
801
+ *
802
+ * @param Mage_Sales_Model_Order $order
803
+ * @return Mage_Sales_Model_Order_Invoice
804
+ * @throws Innobyte_EmagMarketplace_Exception
805
+ */
806
+ private function _prepareInvoice($order)
807
+ {
808
+ try {
809
+ if (!$order->canInvoice()) {
810
+ throw new Innobyte_EmagMarketplace_Exception(
811
+ $this->_getHelper()->__(
812
+ 'Cannot create invoice for eMAG order #%s', $order->getEmagOrderId()
813
+ )
814
+ );
815
+ }
816
+
817
+ /** @var $model Mage_Sales_Model_Service_Order */
818
+ $model = Mage::getModel('sales/service_order', $order);
819
+
820
+ /** @var $invoice Mage_Sales_Model_Order_Invoice */
821
+ $invoice = $model->prepareInvoice();
822
+
823
+ if (!$invoice->getTotalQty()) {
824
+ throw new Innobyte_EmagMarketplace_Exception(
825
+ 'Cannot create an invoice without products!'
826
+ );
827
+ }
828
+
829
+ $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
830
+ $invoice->register();
831
+ } catch (Innobyte_EmagMarketplace_Exception $e) {
832
+ throw new Innobyte_EmagMarketplace_Exception($e->getMessage());
833
+ } catch (Exception $e) {
834
+ Mage::log($e->getMessage(), Zend_Log::ERR, $this->_getHelper()->getResourceLogFile('order'), true);
835
+ throw new Innobyte_EmagMarketplace_Exception(
836
+ $this->_getHelper()->__(
837
+ 'There was an error while creating order invoice: %s', $e->getMessage()
838
+ )
839
+ );
840
+ }
841
+
842
+ return $invoice;
843
+ }
844
+
845
+ /**
846
+ * Make API call to update eMAG order
847
+ *
848
+ * @param Mage_Sales_Model_Order $sales
849
+ * @return $this
850
+ * @throws Innobyte_EmagMarketplace_Exception
851
+ * @throws Mage_Core_Exception
852
+ */
853
+ protected function _updateEmagOrder(Mage_Sales_Model_Order $sales)
854
+ {
855
+ /** @var $order Innobyte_EmagMarketplace_Model_Order_Convert_Magento */
856
+ $order = Mage::getModel('innobyte_emag_marketplace/order_convert_magento');
857
+ $order->setOrder($sales);
858
+ $order->convert();
859
+
860
+ return $this;
861
+ }
862
+
863
+ /**
864
+ * Add eMAG buttons to order view page on:
865
+ * - adminhtml_widget_container_html_before
866
+ *
867
+ * @param Varien_Event_Observer $observer
868
+ * @return Innobyte_EmagMarketplace_Model_Sales_Observer
869
+ */
870
+ public function addEmagButtonsToOrderView(Varien_Event_Observer $observer)
871
+ {
872
+ $block = $observer->getBlock();
873
+ if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View) {
874
+ /** @var $order Mage_Sales_Model_Order */
875
+ $order = Mage::registry('current_order');
876
+ if (!$order->getEmagOrderId()) {
877
+ return $this;
878
+ }
879
+
880
+ $block->addButton(
881
+ 'emag_upload_invoice',
882
+ array(
883
+ 'label' => $this->_getHelper()->__('eMAG Upload Invoice'),
884
+ 'onclick' => "inno.emag_marketplace.showPopup()",
885
+ 'class' => 'go'
886
+ )
887
+ );
888
+
889
+ /** @var $model Innobyte_EmagMarketplace_Model_Sales_Order */
890
+ $model = Mage::getModel('innobyte_emag_marketplace/sales_order');
891
+
892
+ $message = $this->_getHelper()->__('You are about to mark this order as acknowledged. Are you sure?');
893
+ if ($model->canAcknowledge($order)) {
894
+ $url = $block->getUrl('*/*/emagacknowledge');
895
+ $block->addButton(
896
+ 'emag_acknowledge',
897
+ array(
898
+ 'label' => $this->_getHelper()->__('eMAG Acknowledge'),
899
+ 'onclick' => "confirmSetLocation('" . $message . "', '" . $url . "')",
900
+ 'class' => 'go'
901
+ )
902
+ );
903
+ }
904
+
905
+ $message = $this->_getHelper()->__('This action will update order in eMAG Marketplace. Are you sure?');
906
+ if ($model->canPrepare($order)) {
907
+ $url = $block->getUrl('*/*/emagprepare');
908
+ $block->addButton(
909
+ 'emag_prepared',
910
+ array(
911
+ 'label' => $this->_getHelper()->__('eMAG Prepared'),
912
+ 'onclick' => "confirmSetLocation('" . $message . "', '" . $url . "')",
913
+ 'class' => 'go'
914
+ )
915
+ );
916
+ }
917
+
918
+ if ($model->canCancel($order)) {
919
+ $url = $block->getUrl('*/*/emagcancel');
920
+ $block->addButton(
921
+ 'emag_canceled',
922
+ array(
923
+ 'label' => $this->_getHelper()->__('eMAG Cancel'),
924
+ 'onclick' => "confirmSetLocation('" . $message . "', '" . $url . "')",
925
+ 'class' => 'go'
926
+ )
927
+ );
928
+ }
929
+ }
930
+
931
+ return $this;
932
+ }
933
+
934
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Sales/Order.php ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Sales_Order
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Sales_Order extends Innobyte_EmagMarketplace_Model_Sales_Abstract
12
+ {
13
+
14
+ /**
15
+ * Prefix of model events names
16
+ *
17
+ * @var string
18
+ */
19
+ protected $_eventPrefix = 'innobyte_emag_marketplace_sales_order';
20
+
21
+ /**
22
+ * Parameter name in event
23
+ *
24
+ * In observe method you can use $observer->getEvent()->getOrder() in this case
25
+ *
26
+ * @var string
27
+ */
28
+ protected $_eventObject = 'order';
29
+
30
+ /**
31
+ * eMAG order statuses
32
+ *
33
+ * @var array
34
+ */
35
+ protected $_orderStatuses = null;
36
+
37
+ /**
38
+ * Allowed magento states for eMAG orders
39
+ *
40
+ * @var array
41
+ */
42
+ protected $_allowedOrderStates = array(
43
+ Mage_Sales_Model_Order::STATE_NEW,
44
+ Mage_Sales_Model_Order::STATE_PROCESSING
45
+ );
46
+
47
+ /**
48
+ * Initialize resource model
49
+ */
50
+ protected function _construct()
51
+ {
52
+ $this->_init('innobyte_emag_marketplace/sales_order');
53
+ }
54
+
55
+ /**
56
+ * Get allowed magento order states
57
+ *
58
+ * @return array
59
+ */
60
+ public function getAllowedOrderStates()
61
+ {
62
+ return $this->_allowedOrderStates;
63
+ }
64
+
65
+ /**
66
+ * Get eMAG order statuses
67
+ *
68
+ * @return array
69
+ */
70
+ public function getEmagOrderStatuses()
71
+ {
72
+ if(!$this->_orderStatuses) {
73
+ /** @var $model Innobyte_EmagMarketplace_Model_Order_Convert_Emag */
74
+ $model = Mage::getModel('innobyte_emag_marketplace/order_convert_emag');
75
+ $this->_orderStatuses = $model->getEmagOrderStatuses();
76
+ }
77
+
78
+ return $this->_orderStatuses;
79
+ }
80
+
81
+ /**
82
+ * Check if order can be acknowledged
83
+ *
84
+ * @param Mage_Sales_Model_Order $order
85
+ * @return bool
86
+ */
87
+ public function canAcknowledge(Mage_Sales_Model_Order $order)
88
+ {
89
+ return $order->getStatus() == Innobyte_EmagMarketplace_Model_Order_Convert_Abstract::STATUS_NEW;
90
+ }
91
+
92
+ /**
93
+ * Can prepare order
94
+ *
95
+ * @param Mage_Sales_Model_Order $order
96
+ * @return bool
97
+ */
98
+ public function canPrepare(Mage_Sales_Model_Order $order)
99
+ {
100
+ if (
101
+ $order->getStatus() == Innobyte_EmagMarketplace_Model_Order_Convert_Abstract::STATUS_IN_PROGRESS
102
+ || $order->getStatus() == Innobyte_EmagMarketplace_Model_Order_Convert_Abstract::STATUS_FINALIZED
103
+ || $order->getStatus() == Innobyte_EmagMarketplace_Model_Order_Convert_Abstract::STATUS_CANCELED
104
+ ) {
105
+ return true;
106
+ }
107
+
108
+ return false;
109
+ }
110
+
111
+ /**
112
+ * Can finalize order
113
+ *
114
+ * @param Mage_Sales_Model_Order $order
115
+ * @return bool
116
+ */
117
+ public function canFinalize(Mage_Sales_Model_Order $order)
118
+ {
119
+ if (
120
+ $order->getStatus() == Innobyte_EmagMarketplace_Model_Order_Convert_Abstract::STATUS_IN_PROGRESS
121
+ || $order->getStatus() == Innobyte_EmagMarketplace_Model_Order_Convert_Abstract::STATUS_PREPARED
122
+ ) {
123
+ return true;
124
+ }
125
+
126
+ return false;
127
+ }
128
+
129
+ /**
130
+ * Can cancel order
131
+ *
132
+ * @param Mage_Sales_Model_Order $order
133
+ * @return bool
134
+ */
135
+ public function canCancel(Mage_Sales_Model_Order $order)
136
+ {
137
+ if (
138
+ $order->getStatus() == Innobyte_EmagMarketplace_Model_Order_Convert_Abstract::STATUS_IN_PROGRESS
139
+ || $order->getStatus() == Innobyte_EmagMarketplace_Model_Order_Convert_Abstract::STATUS_PREPARED
140
+ ) {
141
+ return true;
142
+ }
143
+
144
+ return false;
145
+ }
146
+
147
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Sales/Order/Address.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Sales_Order_Address
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Sales_Order_Address
12
+ extends Innobyte_EmagMarketplace_Model_Sales_Address_Abstract
13
+ {
14
+
15
+ /**
16
+ * Prefix of model events names
17
+ *
18
+ * @var string
19
+ */
20
+ protected $_eventPrefix = 'innobyte_emag_marketplace_sales_order_address';
21
+
22
+ /**
23
+ * Parameter name in event
24
+ *
25
+ * In observe method you can use $observer->getEvent()->getOrderAddress() in this case
26
+ *
27
+ * @var string
28
+ */
29
+ protected $_eventObject = 'order_address';
30
+
31
+ /**
32
+ * Initialize resource model
33
+ */
34
+ protected function _construct()
35
+ {
36
+ $this->_init('innobyte_emag_marketplace/sales_order_address');
37
+ }
38
+
39
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Sales/Order/Creditmemo/Total.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Sales_Order_Creditmemo_Total
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Sales_Order_Creditmemo_Total
12
+ extends Mage_Sales_Model_Order_Creditmemo_Total_Abstract
13
+ {
14
+
15
+ /**
16
+ * Collect totals for credit memo
17
+ *
18
+ * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
19
+ * @return Innobyte_EmagMarketplace_Model_Sales_Order_Creditmemo_Total
20
+ */
21
+ public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
22
+ {
23
+ // skip if not eMAG order
24
+ if(!$creditmemo->getEmagOrderId()) {
25
+ return $this;
26
+ }
27
+
28
+ $emagVouchersValue = 0;
29
+ $baseEmagVouchersValue = 0;
30
+
31
+ // skip empty
32
+ $vouchers = $creditmemo->getEmagVouchers();
33
+ if (empty($vouchers) || !is_array($vouchers)) {
34
+ return $this;
35
+ }
36
+
37
+ foreach ($vouchers as $voucher) {
38
+ $emagVouchersValue += $voucher['emag_sale_price'];
39
+ $baseEmagVouchersValue += $voucher['base_emag_sale_price'];
40
+ }
41
+
42
+ $grandTotal = $creditmemo->getGrandTotal() + $emagVouchersValue;
43
+ $baseGrandTotal = $creditmemo->getBaseGrandTotal() + $baseEmagVouchersValue;
44
+
45
+ $creditmemo->setGrandTotal($grandTotal);
46
+ $creditmemo->setBaseGrandTotal($baseGrandTotal);
47
+
48
+ return $this;
49
+ }
50
+
51
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Sales/Order/Invoice/Total.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Sales_Order_Invoice_Total
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Sales_Order_Invoice_Total
12
+ extends Mage_Sales_Model_Order_Invoice_Total_Abstract
13
+ {
14
+
15
+ /**
16
+ * Collect totals for invoice
17
+ *
18
+ * @param Mage_Sales_Model_Order_Invoice $invoice
19
+ * @return Innobyte_EmagMarketplace_Model_Sales_Order_Invoice_Total
20
+ */
21
+ public function collect(Mage_Sales_Model_Order_Invoice $invoice)
22
+ {
23
+ // skip if not eMAG order
24
+ if(!$invoice->getEmagOrderId()) {
25
+ return $this;
26
+ }
27
+
28
+ $emagVouchersValue = 0;
29
+ $baseEmagVouchersValue = 0;
30
+
31
+ // skip empty
32
+ $vouchers = $invoice->getEmagVouchers();
33
+ if (empty($vouchers) || !is_array($vouchers)) {
34
+ return $this;
35
+ }
36
+
37
+ foreach ($vouchers as $voucher) {
38
+ $emagVouchersValue += $voucher['emag_sale_price'];
39
+ $baseEmagVouchersValue += $voucher['base_emag_sale_price'];
40
+ }
41
+
42
+ $grandTotal = $invoice->getGrandTotal() + $emagVouchersValue;
43
+ $baseGrandTotal = $invoice->getBaseGrandTotal() + $baseEmagVouchersValue;
44
+
45
+ $invoice->setGrandTotal($grandTotal);
46
+ $invoice->setBaseGrandTotal($baseGrandTotal);
47
+
48
+ return $this;
49
+ }
50
+
51
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Sales/Order/Item.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Sales_Order_Item
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Sales_Order_Item
12
+ extends Innobyte_EmagMarketplace_Model_Sales_Item_Abstract
13
+ {
14
+
15
+ /**
16
+ * Prefix of model events names
17
+ *
18
+ * @var string
19
+ */
20
+ protected $_eventPrefix = 'innobyte_emag_marketplace_sales_order_item';
21
+
22
+ /**
23
+ * Parameter name in event
24
+ *
25
+ * In observe method you can use $observer->getEvent()->getOrderItem() in this case
26
+ *
27
+ * @var string
28
+ */
29
+ protected $_eventObject = 'order_item';
30
+
31
+ /**
32
+ * Initialize resource model
33
+ */
34
+ protected function _construct()
35
+ {
36
+ $this->_init('innobyte_emag_marketplace/sales_order_item');
37
+ }
38
+
39
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Sales/Order/Status.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Sales_Order_Status
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @rewrite: add event prefix and event object to use them in observers
10
+ *
11
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
12
+ */
13
+ class Innobyte_EmagMarketplace_Model_Sales_Order_Status extends Mage_Sales_Model_Order_Status
14
+ {
15
+
16
+ /**
17
+ * Prefix of model events names
18
+ *
19
+ * @var string
20
+ */
21
+ protected $_eventPrefix = 'sales_order_status';
22
+
23
+ /**
24
+ * Parameter name in event
25
+ *
26
+ * In observer method you can use $observer->getEvent()->getStatus()
27
+ *
28
+ * @var string
29
+ */
30
+ protected $_eventObject = 'order_status';
31
+
32
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Sales/Order/Voucher.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Sales_Order_Voucher
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Sales_Order_Voucher
12
+ extends Innobyte_EmagMarketplace_Model_Sales_Voucher_Abstract
13
+ {
14
+
15
+ /**
16
+ * Prefix of model events names
17
+ *
18
+ * @var string
19
+ */
20
+ protected $_eventPrefix = 'innobyte_emag_marketplace_sales_order_voucher';
21
+
22
+ /**
23
+ * Parameter name in event
24
+ *
25
+ * In observe method you can use $observer->getEvent()->getOrderVoucher() in this case
26
+ *
27
+ * @var string
28
+ */
29
+ protected $_eventObject = 'order_voucher';
30
+
31
+ /**
32
+ * Initialize resource model
33
+ */
34
+ protected function _construct()
35
+ {
36
+ $this->_init('innobyte_emag_marketplace/sales_order_voucher');
37
+ }
38
+
39
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Sales/Quote.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Sales_Quote
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Sales_Quote extends Innobyte_EmagMarketplace_Model_Sales_Abstract
12
+ {
13
+
14
+ /**
15
+ * Prefix of model events names
16
+ *
17
+ * @var string
18
+ */
19
+ protected $_eventPrefix = 'innobyte_emag_marketplace_sales_quote';
20
+
21
+ /**
22
+ * Parameter name in event
23
+ *
24
+ * In observe method you can use $observer->getEvent()->getQuote() in this case
25
+ *
26
+ * @var string
27
+ */
28
+ protected $_eventObject = 'quote';
29
+
30
+ /**
31
+ * Initialize resource model
32
+ */
33
+ protected function _construct()
34
+ {
35
+ $this->_init('innobyte_emag_marketplace/sales_quote');
36
+ }
37
+
38
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Sales/Quote/Address.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Sales_Quote_Address
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Sales_Quote_Address
12
+ extends Innobyte_EmagMarketplace_Model_Sales_Address_Abstract
13
+ {
14
+
15
+ /**
16
+ * Prefix of model events names
17
+ *
18
+ * @var string
19
+ */
20
+ protected $_eventPrefix = 'innobyte_emag_marketplace_sales_quote_address';
21
+
22
+ /**
23
+ * Parameter name in event
24
+ *
25
+ * In observe method you can use $observer->getEvent()->getQuoteAddress() in this case
26
+ *
27
+ * @var string
28
+ */
29
+ protected $_eventObject = 'quote_address';
30
+
31
+ /**
32
+ * Initialize resource model
33
+ */
34
+ protected function _construct()
35
+ {
36
+ $this->_init('innobyte_emag_marketplace/sales_quote_address');
37
+ }
38
+
39
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Sales/Quote/Address/Total/Voucher.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Sales_Quote_Address_Total_Voucher
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Sales_Quote_Address_Total_Voucher
12
+ extends Mage_Sales_Model_Quote_Address_Total_Abstract
13
+ {
14
+
15
+ /**
16
+ * Collect eMAG vouchers address amount
17
+ *
18
+ * @param Mage_Sales_Model_Quote_Address $address
19
+ * @return Innobyte_EmagMarketplace_Model_Sales_Quote_Address_Total_Voucher
20
+ */
21
+ public function collect(Mage_Sales_Model_Quote_Address $address)
22
+ {
23
+ // skip if not eMAG order
24
+ if (!$address->getQuote()->getEmagOrderId()) {
25
+ return $this;
26
+ }
27
+
28
+ //skip billing address
29
+ $items = $this->_getAddressItems($address);
30
+ if (!count($items)) {
31
+ return $this;
32
+ }
33
+
34
+ $emagVouchersValue = 0;
35
+ $baseEmagVouchersValue = 0;
36
+
37
+ // skip empty
38
+ $vouchers = $address->getQuote()->getEmagVouchers();
39
+ if (empty($vouchers) || !is_array($vouchers)) {
40
+ return $this;
41
+ }
42
+
43
+ foreach ($vouchers as $voucher) {
44
+ $emagVouchersValue += $voucher['emag_sale_price'];
45
+ $baseEmagVouchersValue += $voucher['base_emag_sale_price'];
46
+ }
47
+
48
+ $grandTotal = $address->getGrandTotal() + $emagVouchersValue;
49
+ $baseGrandTotal = $address->getGrandTotal() + $baseEmagVouchersValue;
50
+
51
+ $address->setGrandTotal($grandTotal);
52
+ $address->setBaseGrandTotal($baseGrandTotal);
53
+
54
+ return $this;
55
+ }
56
+
57
+ /**
58
+ * Add eMAG vouchers information to address
59
+ * - this method only added emag_voucher code in subtotals
60
+ * - voucher value and title are handled in:
61
+ * app/design/adminhtml/default/default/template/innobyte/emag_marketplace/sales/order/create/totals/voucher.phtml
62
+ *
63
+ * @param Mage_Sales_Model_Quote_Address $address
64
+ * @return Innobyte_EmagMarketplace_Model_Sales_Quote_Address_Total_Voucher
65
+ */
66
+ public function fetch(Mage_Sales_Model_Quote_Address $address)
67
+ {
68
+ // skip if not eMAG order
69
+ if (!$address->getQuote()->getEmagOrderId()) {
70
+ return $this;
71
+ }
72
+
73
+ $vouchers = $address->getQuote()->getEmagVouchers();
74
+ if (empty($vouchers) || !is_array($vouchers)) {
75
+ return $this;
76
+ }
77
+
78
+ $address->addTotal(array(
79
+ 'code' => 'emag_vouchers',
80
+ 'title' => '',
81
+ 'value' => ''
82
+ ));
83
+
84
+ return $this;
85
+ }
86
+
87
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Sales/Quote/Voucher.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Sales_Quote_Voucher
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Sales_Quote_Voucher
12
+ extends Innobyte_EmagMarketplace_Model_Sales_Voucher_Abstract
13
+ {
14
+
15
+ /**
16
+ * Prefix of model events names
17
+ *
18
+ * @var string
19
+ */
20
+ protected $_eventPrefix = 'innobyte_emag_marketplace_sales_quote_vouchers';
21
+
22
+ /**
23
+ * Parameter name in event
24
+ *
25
+ * In observe method you can use $observer->getEvent()->getQuoteVouchers() in this case
26
+ *
27
+ * @var string
28
+ */
29
+ protected $_eventObject = 'quote_vouchers';
30
+
31
+ /**
32
+ * Initialize resource model
33
+ */
34
+ protected function _construct()
35
+ {
36
+ $this->_init('innobyte_emag_marketplace/sales_quote_voucher');
37
+ }
38
+
39
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Sales/Voucher/Abstract.php ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Sales_Voucher_Abstract
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ abstract class Innobyte_EmagMarketplace_Model_Sales_Voucher_Abstract extends Mage_Core_Model_Abstract
12
+ {
13
+
14
+ /**
15
+ * Column prefix
16
+ */
17
+ const COLUMN_PREFIX = 'emag';
18
+
19
+ /**
20
+ * Emag vouchers field name on sales objects
21
+ */
22
+ const EMAG_VOUCHERS = 'emag_vouchers';
23
+
24
+ /**
25
+ * Check if voucher is already added for current order|quote
26
+ * - vouchers already added should not be saved again
27
+ *
28
+ * @return Mage_Core_Model_Abstract
29
+ */
30
+ protected function _beforeSave()
31
+ {
32
+ if ($this->_getResource()->isVoucherExists($this)) {
33
+ $this->_dataSaveAllowed = false;
34
+ }
35
+
36
+ return parent::_beforeSave();
37
+ }
38
+
39
+ /**
40
+ * Attach eMAG vouchers to order/quote
41
+ *
42
+ * @param $sales Mage_Sales_Model_Quote|Mage_Sales_Model_Order
43
+ * @return Innobyte_EmagMarketplace_Model_Sales_Voucher_Abstract
44
+ */
45
+ public function attachVoucherData($sales)
46
+ {
47
+ $vouchers = $this->getEmagVouchers($sales->getId());
48
+ if (!empty($vouchers)) {
49
+ $sales->addData(array(self::EMAG_VOUCHERS => $vouchers));
50
+ }
51
+
52
+ return $this;
53
+ }
54
+
55
+ /**
56
+ * Save eMAG vouchers
57
+ *
58
+ * @param Mage_Core_Model_Abstract $sales
59
+ * @return Innobyte_EmagMarketplace_Model_Sales_Abstract
60
+ */
61
+ public function saveVoucherData(Mage_Core_Model_Abstract $sales)
62
+ {
63
+ if (!$sales->getEmagVouchers()) {
64
+ return $this;
65
+ }
66
+
67
+ foreach ($sales->getEmagVouchers() as $voucher) {
68
+ $this->addData($voucher);
69
+ $this->setEntityId($sales->getId());
70
+
71
+ if (!empty($voucher['isDeleted'])) {
72
+ $this->isDeleted(true);
73
+ }
74
+
75
+ $this->save();
76
+ $this->unsetData();
77
+ }
78
+
79
+ return $this;
80
+ }
81
+
82
+ /**
83
+ * Get eMAG vouchers
84
+ *
85
+ * @param $orderId
86
+ * @return array
87
+ */
88
+ public function getEmagVouchers($orderId)
89
+ {
90
+ $collection = $this->getCollection()
91
+ ->addFieldToSelect('emag_id')
92
+ ->addFieldToSelect('emag_voucher_id')
93
+ ->addFieldToSelect('emag_voucher_name')
94
+ ->addFieldToSelect('emag_sale_price')
95
+ ->addFieldToSelect('base_emag_sale_price')
96
+ ->addFieldToSelect('emag_sale_price_vat')
97
+ ->addFieldToSelect('base_emag_sale_price_vat')
98
+ ->addFieldToSelect('emag_status')
99
+ ->addFieldToSelect('emag_vat')
100
+ ->addFieldToSelect('emag_created')
101
+ ->addFieldToSelect('emag_modified')
102
+ ->addFieldToFilter('entity_id', $orderId);
103
+
104
+ $vouchers = array();
105
+ if (!$collection->getSize()) {
106
+ return $vouchers;
107
+ }
108
+
109
+ foreach ($collection as $voucher) {
110
+ $vouchers[] = $voucher->getData();
111
+ }
112
+
113
+ return $vouchers;
114
+ }
115
+
116
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Shipping/Carrier/Emag.php ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Custom shipping carrier that represents the "eMAG" shipping.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ *
8
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
9
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
10
+ */
11
+
12
+ class Innobyte_EmagMarketplace_Model_Shipping_Carrier_Emag
13
+ extends Mage_Shipping_Model_Carrier_Abstract
14
+ implements Mage_Shipping_Model_Carrier_Interface
15
+ {
16
+ /**
17
+ * @var const int Container types.
18
+ */
19
+ const CONTAINER_ENVELOPE = 1;
20
+ const CONTAINER_PARCEL = 2;
21
+
22
+
23
+ /**
24
+ * eMAG shipping code
25
+ */
26
+ const EMAG_SHIPPING = 'emagshipping';
27
+
28
+ /**
29
+ * Shipping method code
30
+ *
31
+ * @var string
32
+ */
33
+ protected $_code = self::EMAG_SHIPPING;
34
+
35
+ /**
36
+ * Whether this carrier has fixed rates calculation
37
+ *
38
+ * @var bool
39
+ */
40
+ protected $_isFixed = true;
41
+
42
+ /**
43
+ * Allowed methods
44
+ *
45
+ * @return array
46
+ */
47
+ public function getAllowedMethods()
48
+ {
49
+ return array(
50
+ 'standard' => $this->getConfigData('name'),
51
+ );
52
+ }
53
+
54
+ /**
55
+ * Collect rates
56
+ *
57
+ * @param Mage_Shipping_Model_Rate_Request $request
58
+ * @return bool|Mage_Shipping_Model_Rate_Result|null
59
+ */
60
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request)
61
+ {
62
+ if (!Mage::app()->getStore()->isAdmin()) {
63
+ return false;
64
+ }
65
+
66
+ /** @var Mage_Shipping_Model_Rate_Result $result */
67
+ $result = Mage::getModel('shipping/rate_result');
68
+ $result->append($this->_getStandardShippingRate());
69
+
70
+ return $result;
71
+ }
72
+
73
+ /**
74
+ * Get standard shipping rate
75
+ *
76
+ * @return Mage_Shipping_Model_Rate_Result_Method
77
+ */
78
+ protected function _getStandardShippingRate()
79
+ {
80
+ /** @var Mage_Shipping_Model_Rate_Result_Method $rate */
81
+ $rate = Mage::getModel('shipping/rate_result_method');
82
+ $rate->setCarrier($this->getCarrierCode());
83
+ $rate->setCarrierTitle($this->getConfigData('title'));
84
+ $rate->setMethod('standard');
85
+ $rate->setMethodTitle($this->getConfigData('name'));
86
+ $rate->setPrice(0);
87
+ $rate->setCost(0);
88
+
89
+ return $rate;
90
+ }
91
+
92
+
93
+
94
+ /**
95
+ * Check if carrier has shipping label option available.
96
+ * @Override
97
+ * @return boolean
98
+ */
99
+ public function isShippingLabelsAvailable()
100
+ {
101
+ return true;
102
+ }
103
+
104
+
105
+
106
+ /**
107
+ * Retrieve container types of carrier.
108
+ *
109
+ * @Override
110
+ * @param Varien_Object|null $params
111
+ * @return array
112
+ */
113
+ public function getContainerTypes(Varien_Object $params = null)
114
+ {
115
+ $helper = Mage::helper('innobyte_emag_marketplace');
116
+ return array(
117
+ self::CONTAINER_ENVELOPE => $helper->__('Envelope'),
118
+ self::CONTAINER_PARCEL => $helper->__('Parcel'),
119
+ );
120
+ }
121
+
122
+
123
+
124
+ /**
125
+ * Do request to shipment.
126
+ *
127
+ * @Override
128
+ * @param Mage_Shipping_Model_Shipment_Request $req
129
+ * @return Varien_Object
130
+ */
131
+ public function requestToShipment(Mage_Shipping_Model_Shipment_Request $req)
132
+ {
133
+ $returnValue = new Varien_Object();
134
+ $helper = Mage::helper('innobyte_emag_marketplace');
135
+ try {
136
+ $req->setData(
137
+ 'emag_shipping_extra',
138
+ Mage::app()->getRequest()->getParam('emag-marketplace-shipping')
139
+ );
140
+ $apiAwb = Mage::getModel('innobyte_emag_marketplace/api_awb');
141
+ $apiResponse = $apiAwb->setShipmentRequest($req)->save();
142
+ if ($apiResponse->isError()) {
143
+ throw new Innobyte_EmagMarketplace_Exception(
144
+ implode(', ', $apiResponse->getMessages())
145
+ );
146
+ }
147
+ $results = $apiResponse->getResults();
148
+ if (!array_key_exists('awb', $results)
149
+ || !is_array($results['awb'])) {
150
+ throw new Innobyte_EmagMarketplace_Exception(
151
+ 'Invalid API awb response'
152
+ );
153
+ }
154
+
155
+ /* get shipping label */
156
+ $info = array();
157
+ foreach ($results['awb'] as $awbInfo) {
158
+ $labelContent = '';
159
+ try {
160
+ $pdfResponse = $apiAwb->readPdf($awbInfo['emag_id']);
161
+ $validContents = array(
162
+ 'application/pdf',
163
+ 'application/x-pdf',
164
+ );
165
+ $content = $pdfResponse->getHeader('Content-Type');
166
+ if (in_array($content, $validContents)) {
167
+ $labelContent = $pdfResponse->getBody();
168
+ } else {
169
+ throw new Innobyte_EmagMarketplace_Exception(
170
+ 'eMAG AWB #' . $awbInfo['emag_id']
171
+ . ' PDF could not be retrieved.'
172
+ . ' Response content type: ' . $content
173
+ . ' Response body: ' . $pdfResponse->getBody()
174
+ );
175
+ }
176
+ } catch (Exception $e) {
177
+ $apiAwb->debugData(
178
+ $e->getMessage(),
179
+ Innobyte_EmagMarketplace_Model_Api_Awb::AWB_RESOURCE_NAME
180
+ );
181
+ }
182
+ $info[] = array(
183
+ 'tracking_number' => $awbInfo['awb_number'],
184
+ 'label_content' => $labelContent,
185
+ );
186
+ }
187
+ $returnValue->setInfo($info);
188
+ } catch (Innobyte_EmagMarketplace_Exception $iemEx) {
189
+ $returnValue->setErrors($helper->__($iemEx->getMessage()));
190
+ }
191
+ return $returnValue;
192
+ }
193
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Source/Category.php ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG category source model.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Source_Category
11
+ {
12
+ /**
13
+ * Array with options.
14
+ *
15
+ * @var array
16
+ */
17
+ protected $_options = array();
18
+
19
+
20
+
21
+ /**
22
+ * Retreive options array.
23
+ *
24
+ * @param int $storeId Store to retrieve categories for.
25
+ * @param boolean $includeEmpty Whether to return also an empty value.
26
+ * @param boolean $onlyWithFamilyTypes Whether to return only categories
27
+ * that have family type(s).
28
+ * @return array
29
+ */
30
+ public function toOptionArray(
31
+ $storeId,
32
+ $includeEmpty = true,
33
+ $onlyWithFamilyTypes = false
34
+ )
35
+ {
36
+ $key = $this->_getKey($storeId, $includeEmpty, $onlyWithFamilyTypes);
37
+ if (!array_key_exists($key, $this->_options)
38
+ || empty($this->_options[$key])) {
39
+ $this->_options[$key] = array();
40
+ $categoriesColl = Mage::getResourceModel(
41
+ 'innobyte_emag_marketplace/category_collection'
42
+ )->addFieldToSelect(array('id', 'name'))
43
+ ->addStoreFilter(intval($storeId))
44
+ ->setOnlyWithFamilyTypes($onlyWithFamilyTypes);
45
+ $helper = Mage::helper('innobyte_emag_marketplace');
46
+
47
+ // process products in chunk so DB
48
+ // does not get busy if too many categories
49
+ $catCnt = $categoriesColl->getSize();
50
+ $chunkSize = 100;
51
+ $pages = ceil($catCnt / $chunkSize);
52
+ $i = 0;
53
+ $categoriesColl->setOrder('name', Varien_Data_Collection::SORT_ORDER_ASC);
54
+ while ($i < $pages) {
55
+ $categoriesColl->clear();
56
+ $categoriesColl->getSelect()
57
+ ->reset(Zend_Db_Select::LIMIT_COUNT)
58
+ ->reset(Zend_Db_Select::LIMIT_OFFSET)
59
+ ->limit($chunkSize, $i * $chunkSize);
60
+ foreach ($categoriesColl as $category) {
61
+ $this->_options[$key][] = array(
62
+ 'value' => $category->getId(),
63
+ 'label' => $helper->__($category->getName()),
64
+ );
65
+ }
66
+ $i++;
67
+ }
68
+
69
+ // store also the other value in order not to make db select again.
70
+ $otherKey = $this->_getKey($storeId, !$includeEmpty, $onlyWithFamilyTypes);
71
+ $this->_options[$otherKey] = $this->_options[$key];
72
+ if ($includeEmpty) {
73
+ array_unshift(
74
+ $this->_options[$key],
75
+ array('value' => '', 'label' => '')
76
+ );
77
+ } else {
78
+ array_unshift(
79
+ $this->_options[$otherKey],
80
+ array('value' => '', 'label' => '')
81
+ );
82
+ }
83
+ }
84
+
85
+ return $this->_options[$key];
86
+ }
87
+
88
+
89
+
90
+ /**
91
+ * Calculates key to store options.
92
+ *
93
+ * @param int $storeId
94
+ * @param boolean $includeEmpty
95
+ * @param boolean $onlyWithFamilyTypes
96
+ * @return string
97
+ */
98
+ private function _getKey($storeId, $includeEmpty, $onlyWithFamilyTypes)
99
+ {
100
+ return intval($storeId) . '_' . intval($includeEmpty)
101
+ . '_' . intval($onlyWithFamilyTypes);
102
+ }
103
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Source/CommissionTypes.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG commission types source model.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Source_CommissionTypes
11
+ {
12
+ /**
13
+ * eMAG commission types
14
+ */
15
+ const TYPE_PERCENTAGE = 'percentage';
16
+ const TYPE_ABSOLUTE = 'absolute';
17
+
18
+ /**
19
+ * Mapping between eMAG commission types and locally magento values
20
+ *
21
+ * @var array
22
+ */
23
+ protected static $_typesMatch = array(
24
+ 1 => self::TYPE_PERCENTAGE,
25
+ 2 => self::TYPE_ABSOLUTE,
26
+ );
27
+
28
+ /**
29
+ * Array with options.
30
+ *
31
+ * @var array
32
+ */
33
+ protected $_options = array();
34
+
35
+
36
+
37
+ /**
38
+ * Retreive options array.
39
+ *
40
+ * @return array
41
+ */
42
+ public function toOptionArray()
43
+ {
44
+ if (empty($this->_options)) {
45
+ $innoHelper = Mage::helper('innobyte_emag_marketplace');
46
+ foreach (self::$_typesMatch as $magentoValue => $emagValue) {
47
+ $this->_options[] = array(
48
+ 'value' => $magentoValue,
49
+ 'label' => $innoHelper->__($emagValue),
50
+ );
51
+ }
52
+ }
53
+
54
+ return $this->_options;
55
+ }
56
+
57
+
58
+
59
+ /**
60
+ * Retrieve eMAG string commission type based on
61
+ * integer magento defined commission type.
62
+ *
63
+ * @param int $magentoCommissionType
64
+ * @return string eMAG commission type.
65
+ * @throws Innobyte_EmagMarketplace_Exception
66
+ * If invalid magento commission type provided.
67
+ */
68
+ public static function getEmagCommissionType($magentoCommissionType)
69
+ {
70
+ if (array_key_exists($magentoCommissionType, self::$_typesMatch)) {
71
+ return self::$_typesMatch[$magentoCommissionType];
72
+ }
73
+ throw new Innobyte_EmagMarketplace_Exception(
74
+ 'Invalid commission type provided'
75
+ );
76
+ }
77
+
78
+
79
+
80
+ /**
81
+ * Retreive array with values.
82
+ *
83
+ * @return array
84
+ */
85
+ public function toArray()
86
+ {
87
+ return array(
88
+ self::STATUS_INACTIVE,
89
+ self::STATUS_ACTIVE,
90
+ );
91
+ }
92
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Source/Customer/Address/Attributes/Legalentity.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_Source_Customer_Address_Attributes_Legalentity
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_Source_Customer_Address_Attributes_Legalentity
12
+ extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
13
+ {
14
+
15
+ /**
16
+ * Get all options
17
+ *
18
+ * @return array
19
+ */
20
+ public function getAllOptions()
21
+ {
22
+ $options = array(
23
+ array(
24
+ 'label' => Mage::helper('innobyte_emag_marketplace')->__('Private Entity'),
25
+ 'value' => 0
26
+ ),
27
+ array(
28
+ 'label' => Mage::helper('innobyte_emag_marketplace')->__('Legal Entity'),
29
+ 'value' => 1
30
+ )
31
+ );
32
+
33
+ return $options;
34
+ }
35
+
36
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Source/FamilyType.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG family type source model.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Source_FamilyType
11
+ {
12
+ /**
13
+ * Array with options.
14
+ *
15
+ * @var array
16
+ */
17
+ protected $_options = array();
18
+
19
+
20
+
21
+ /**
22
+ * Retreive options array.
23
+ *
24
+ * @param int $categoryId Category to retrieve families for.
25
+ * @param boolean $includeEmpty Whether to return also an empty value.
26
+ * @return array
27
+ */
28
+ public function toOptionArray($categoryId, $includeEmpty = true)
29
+ {
30
+ $key = $this->_getKey($categoryId, $includeEmpty);
31
+ if (!array_key_exists($key, $this->_options)
32
+ || empty($this->_options[$key])) {
33
+ $this->_options[$key] = array();
34
+ $familyTypesColl = Mage::getResourceModel(
35
+ 'innobyte_emag_marketplace/category_familytype_collection'
36
+ )->addFieldToFilter('category_id', intval($categoryId));
37
+ $helper = Mage::helper('innobyte_emag_marketplace');
38
+
39
+ foreach ($familyTypesColl as $familyType) {
40
+ $this->_options[$key][] = array(
41
+ 'value' => $familyType->getId(),
42
+ 'label' => $helper->__($familyType->getName()),
43
+ );
44
+ }
45
+
46
+ // store also the other value in order not to make db select again.
47
+ $otherKey = $this->_getKey($categoryId, !$includeEmpty);
48
+ $this->_options[$otherKey] = $this->_options[$key];
49
+ if ($includeEmpty) {
50
+ array_unshift(
51
+ $this->_options[$key],
52
+ array('value' => '', 'label' => '')
53
+ );
54
+ } else {
55
+ array_unshift(
56
+ $this->_options[$otherKey],
57
+ array('value' => '', 'label' => '')
58
+ );
59
+ }
60
+ }
61
+
62
+ return $this->_options[$key];
63
+ }
64
+
65
+
66
+
67
+ /**
68
+ * Calculates key to store options.
69
+ *
70
+ * @param int $categoryId
71
+ * @param boolean $includeEmpty
72
+ * @return string
73
+ */
74
+ private function _getKey($categoryId, $includeEmpty)
75
+ {
76
+ return intval($categoryId) . '_' . intval($includeEmpty);
77
+ }
78
+
79
+
80
+
81
+ /**
82
+ * Retrieve categories ids.
83
+ *
84
+ * @param int $storeId
85
+ * @return array Array with category ids.
86
+ */
87
+ public function getIdsArray($storeId)
88
+ {
89
+ $returnValue = array();
90
+ $options = $this->toOptionArray($storeId, false);
91
+ foreach ($options as $option) {
92
+ $returnValue[] = $option['value'];
93
+ }
94
+ return $returnValue;
95
+ }
96
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Source/OfferStatus.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG offer statuses source model.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Source_OfferStatus
11
+ {
12
+ /**
13
+ * eMAG offer status
14
+ */
15
+ const STATUS_ACTIVE = 1;
16
+ const STATUS_INACTIVE = 0;
17
+
18
+
19
+ /**
20
+ * Array with options.
21
+ *
22
+ * @var array
23
+ */
24
+ protected $_options = array();
25
+
26
+
27
+
28
+ /**
29
+ * Retreive options array.
30
+ *
31
+ * @return array
32
+ */
33
+ public function toOptionArray()
34
+ {
35
+ if (empty($this->_options)) {
36
+ $innoHelper = Mage::helper('innobyte_emag_marketplace');
37
+ $this->_options[] = array(
38
+ 'value' => self::STATUS_INACTIVE,
39
+ 'label' => $innoHelper->__('Inactive'),
40
+ );
41
+ $this->_options[] = array(
42
+ 'value' => self::STATUS_ACTIVE,
43
+ 'label' => $innoHelper->__('Active'),
44
+ );
45
+ }
46
+
47
+ return $this->_options;
48
+ }
49
+
50
+
51
+
52
+ /**
53
+ * Retreive array with values.
54
+ *
55
+ * @return array
56
+ */
57
+ public function toArray()
58
+ {
59
+ return array(
60
+ self::STATUS_INACTIVE,
61
+ self::STATUS_ACTIVE,
62
+ );
63
+ }
64
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Source/Vat.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG vat source model.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Source_Vat
11
+ {
12
+ /**
13
+ * Array with options.
14
+ *
15
+ * @var array
16
+ */
17
+ protected $_options = array();
18
+
19
+
20
+
21
+ /**
22
+ * Retreive options array.
23
+ *
24
+ * @param int $storeId Store to retrieve categories for.
25
+ * @param boolean $includeEmpty Whether to return also an empty value.
26
+ * @return array
27
+ */
28
+ public function toOptionArray($storeId, $includeEmpty = true)
29
+ {
30
+ $key = $this->_getKey($storeId, $includeEmpty);
31
+ if (!array_key_exists($key, $this->_options)
32
+ || empty($this->_options[$key])) {
33
+ $this->_options[$key] = array();
34
+ $vats = Mage::getResourceModel(
35
+ 'innobyte_emag_marketplace/vat_collection'
36
+ )->addFieldToSelect(array('id', 'rate'))
37
+ ->addStoreFilter(intval($storeId));
38
+ foreach ($vats as $vat) {
39
+ $this->_options[$key][] = array(
40
+ 'value' => $vat->getId(),
41
+ 'label' => $vat->getRate()
42
+ );
43
+ }
44
+
45
+ // store also the other value in order not to make db select again.
46
+ $otherKey = $this->_getKey($storeId, !$includeEmpty);
47
+ $this->_options[$otherKey] = $this->_options[$key];
48
+ if ($includeEmpty) {
49
+ array_unshift(
50
+ $this->_options[$key],
51
+ array('value' => '', 'label' => '')
52
+ );
53
+ } else {
54
+ array_unshift(
55
+ $this->_options[$otherKey],
56
+ array('value' => '', 'label' => '')
57
+ );
58
+ }
59
+ }
60
+
61
+ return $this->_options[$key];
62
+ }
63
+
64
+
65
+
66
+ /**
67
+ * Calculates key to store options.
68
+ *
69
+ * @param int $storeId
70
+ * @param boolean $includeEmpty
71
+ * @return string
72
+ */
73
+ private function _getKey($storeId, $includeEmpty)
74
+ {
75
+ return intval($storeId) . '_' . intval($includeEmpty);
76
+ }
77
+
78
+
79
+
80
+ /**
81
+ * Retrieve vat ids.
82
+ *
83
+ * @param int $storeId
84
+ * @return array Array with vat ids.
85
+ */
86
+ public function getIdsArray($storeId)
87
+ {
88
+ $returnValue = array();
89
+ $options = $this->toOptionArray($storeId, false);
90
+ foreach ($options as $option) {
91
+ $returnValue[] = $option['value'];
92
+ }
93
+ return $returnValue;
94
+ }
95
+ }
app/code/local/Innobyte/EmagMarketplace/Model/System/Config/Backend/Prefix/Abstract.php ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_System_Config_Backend_Prefix_Abstract
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_System_Config_Backend_Prefix_Abstract extends Mage_Core_Model_Config_Data
12
+ {
13
+
14
+ /**
15
+ * Prefix
16
+ *
17
+ * @var null
18
+ */
19
+ protected $_prefix = null;
20
+
21
+ /**
22
+ * Entity type
23
+ *
24
+ * @var array
25
+ */
26
+ protected $_entityType = null;
27
+
28
+ /**
29
+ * Get prefix
30
+ */
31
+ public function getPrefix()
32
+ {
33
+ return $this->_prefix;
34
+ }
35
+
36
+ /**
37
+ * Get entity type
38
+ *
39
+ * @return array
40
+ */
41
+ public function getEntityType()
42
+ {
43
+ return $this->_entityType;
44
+ }
45
+
46
+ /**
47
+ * Get entity model
48
+ *
49
+ * @return Mage_Eav_Model_Entity_Store
50
+ */
51
+ public function getEntityModel()
52
+ {
53
+ return Mage::getModel('eav/entity_store');
54
+ }
55
+
56
+ /**
57
+ * Get entity type model
58
+ *
59
+ * @param $entityType
60
+ * @return Mage_Eav_Model_Entity_Type
61
+ */
62
+ public function getEntityTypeModel($entityType)
63
+ {
64
+ return Mage::getModel('eav/config')->getEntityType($entityType);
65
+ }
66
+
67
+ /**
68
+ * Update eav_entity_store table
69
+ * - set increment_prefix for invoice/creditmemo in current store
70
+ * - insert new record if not found
71
+ *
72
+ * @return Innobyte_EmagMarketplace_Model_System_Config_Backend_Prefix_Abstract
73
+ */
74
+ protected function _afterSave()
75
+ {
76
+ parent::_afterSave();
77
+
78
+ $prefix = $this->getPrefix();
79
+ $storeCode = Mage::app()->getRequest()->getParam('store');
80
+
81
+ // exit if invoice prefix is not defined
82
+ if (!$prefix) {
83
+ return $this;
84
+ }
85
+
86
+ // throw exception if store code is not present; invoice increment_prefix can only be edited at store level
87
+ if ($prefix && !$storeCode) {
88
+ Mage::throwException('Invoice/Creditmemo prefix can only be edited at store level!');
89
+ }
90
+
91
+ // exit if store code is missing
92
+ if (!$storeCode) {
93
+ return $this;
94
+ }
95
+
96
+ $store = Mage::getModel('core/store')->load($storeCode, 'code');
97
+ if (!$store->getId()) {
98
+ return $this;
99
+ }
100
+
101
+ try {
102
+ $entityType = $this->getEntityType();
103
+ $entityTypeModel = $this->getEntityTypeModel($entityType);
104
+ $entityModel = $this->getEntityModel()
105
+ ->loadByEntityStore($this->getEntityTypeModel($entityType)->getEntityTypeId(), $store->getId());
106
+
107
+ if (!$entityModel->getEntityStoreId()) {
108
+ $this->_getResource()->beginTransaction();
109
+
110
+ // insert entity model with magento default prefix
111
+ $entityModel
112
+ ->setEntityTypeId($entityTypeModel->getId())
113
+ ->setStoreId($store->getId())
114
+ ->setIncrementPrefix($store->getId())
115
+ ->save();
116
+
117
+ $incrementInstance = Mage::getModel($entityTypeModel->getIncrementModel())
118
+ ->setPrefix($entityModel->getIncrementPrefix())
119
+ ->setPadLength($entityTypeModel->getIncrementPadLength())
120
+ ->setPadChar($entityTypeModel->getIncrementPadChar())
121
+ ->setLastId($entityModel->getIncrementLastId())
122
+ ->setEntityTypeId($entityModel->getEntityTypeId())
123
+ ->setStoreId($entityModel->getStoreId());
124
+
125
+ /**
126
+ * do read lock on eav/entity_store to solve potential timing issues
127
+ * (most probably already done by beginTransaction of entity save)
128
+ */
129
+ $incrementId = (string)$incrementInstance->getNextId();
130
+ $incrementId = substr_replace($incrementId, '0', -1);
131
+
132
+ $entityModel->setIncrementLastId($incrementId);
133
+ $entityModel->save();
134
+
135
+ $this->_getResource()->commit();
136
+
137
+ // update entity model with custom prefix
138
+ $entityModel = $this->getEntityModel()
139
+ ->loadByEntityStore($this->getEntityTypeModel($entityType)->getEntityTypeId(), $store->getId());
140
+ $entityModel
141
+ ->setIncrementPrefix($prefix)
142
+ ->save();
143
+
144
+ } else {
145
+ $entityModel->setIncrementPrefix($prefix);
146
+ $entityModel->save();
147
+ }
148
+ } catch (Exception $e) {
149
+ $this->_getResource()->rollBack();
150
+ Mage::throwException($e->getMessage());
151
+ }
152
+
153
+ return $this;
154
+ }
155
+
156
+ }
app/code/local/Innobyte/EmagMarketplace/Model/System/Config/Backend/Prefix/Creditmemo.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_System_Config_Backend_Prefix_Creditmemo
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_System_Config_Backend_Prefix_Creditmemo
12
+ extends Innobyte_EmagMarketplace_Model_System_Config_Backend_Prefix_Abstract
13
+ {
14
+
15
+ /**
16
+ * Entity types
17
+ *
18
+ * @var array
19
+ */
20
+ protected $_entityType = 'creditmemo';
21
+
22
+ /**
23
+ * Set prefix value
24
+ */
25
+ protected function _afterSave()
26
+ {
27
+ $this->_prefix = $this->getFieldsetDataValue('creditmemo_prefix');
28
+
29
+ return parent::_afterSave();
30
+ }
31
+
32
+ }
app/code/local/Innobyte/EmagMarketplace/Model/System/Config/Backend/Prefix/Invoice.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Model_System_Config_Backend_Prefix_Invoice
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Model_System_Config_Backend_Prefix_Invoice
12
+ extends Innobyte_EmagMarketplace_Model_System_Config_Backend_Prefix_Abstract
13
+ {
14
+
15
+ /**
16
+ * Entity types
17
+ *
18
+ * @var array
19
+ */
20
+ protected $_entityType = 'invoice';
21
+
22
+ /**
23
+ * Set prefix value
24
+ */
25
+ protected function _afterSave()
26
+ {
27
+ $this->_prefix = $this->getFieldsetDataValue('invoice_prefix');
28
+
29
+ return parent::_afterSave();
30
+ }
31
+
32
+ }
app/code/local/Innobyte/EmagMarketplace/Model/Vat.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG VAT model.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Model_Vat extends Mage_Core_Model_Abstract
11
+ {
12
+ /**
13
+ * @Override
14
+ * @var string Event prefix.
15
+ */
16
+ protected $_eventPrefix = 'innobyte_emag_marketplace_vat';
17
+
18
+ /**
19
+ * @Override
20
+ * @var string Event object key.
21
+ */
22
+ protected $_eventObject = 'emag_vat';
23
+
24
+
25
+
26
+ /**
27
+ * @Override
28
+ */
29
+ public function _construct()
30
+ {
31
+ parent::_construct();
32
+ $this->_init('innobyte_emag_marketplace/vat');
33
+ }
34
+ }
app/code/local/Innobyte/EmagMarketplace/controllers/Adminhtml/Emag/CategoryController.php ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG categories controller.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Adminhtml_Emag_CategoryController
11
+ extends Mage_Adminhtml_Controller_Action
12
+ {
13
+ /**
14
+ * Check ACL.
15
+ *
16
+ * @Override
17
+ * @return boolean
18
+ */
19
+ protected function _isAllowed()
20
+ {
21
+ return Mage::getSingleton('admin/session')
22
+ ->isAllowed('innobyte_emag_marketplace/category');
23
+ }
24
+
25
+
26
+
27
+ /**
28
+ * Init different stuffs.
29
+ *
30
+ * @return Innobyte_EmagMarketplace_Adminhtml_Emag_CategoryController
31
+ */
32
+ protected function _init()
33
+ {
34
+ $this->loadLayout()
35
+ ->_title($this->__('eMAG'))
36
+ ->_title($this->__('Categories'))
37
+ ->_setActiveMenu('innobyte_emag_marketplace/category');
38
+
39
+ return $this;
40
+ }
41
+
42
+
43
+
44
+ /**
45
+ * Display categories.
46
+ */
47
+ public function indexAction()
48
+ {
49
+ if ($this->getRequest()->isXmlHttpRequest()) {
50
+ $this->getResponse()->setBody(
51
+ $this->getLayout()
52
+ ->createBlock(
53
+ 'innobyte_emag_marketplace/adminhtml_category_grid'
54
+ )
55
+ ->toHtml()
56
+ );
57
+ } else {
58
+ $this->_init()
59
+ ->renderLayout();
60
+ }
61
+ }
62
+
63
+
64
+
65
+ /**
66
+ * Read eMAG categories.
67
+ */
68
+ public function syncCategoriesAction()
69
+ {
70
+ $response = array(
71
+ 'status' => 'error',
72
+ 'message' => '',
73
+ );
74
+ $helper = Mage::helper('innobyte_emag_marketplace');
75
+ $storeId = $helper->getCurrStoreId();
76
+ try {
77
+ if (!$helper->canMakeApiCall($storeId)) {
78
+ throw new Innobyte_EmagMarketplace_Exception(
79
+ 'Please configure extension from System -> Configuration -> eMAG Marketplace'
80
+ );
81
+ }
82
+ $api = Mage::getSingleton('innobyte_emag_marketplace/api_category')
83
+ ->setStoreId($storeId);
84
+
85
+ // get pagination
86
+ $apiResponse = $api->count();
87
+ if ($apiResponse->isError()) {
88
+ throw new Innobyte_EmagMarketplace_Exception(
89
+ implode(', ', $apiResponse->getMessages())
90
+ );
91
+ }
92
+
93
+ // get categories
94
+ for ($i = 1; $i <= $api->getNoOfPages(); $i++) {
95
+ $apiResponse = $api->setCurrentPage($i)->read();
96
+ if ($apiResponse->isError()) {
97
+ throw new Innobyte_EmagMarketplace_Exception(
98
+ implode(', ', $apiResponse->getMessages())
99
+ );
100
+ }
101
+ foreach ($apiResponse->getResults() as $category) {
102
+ $api->importCategory($category)->save();
103
+ }
104
+ }
105
+ $response['status'] = 'success';
106
+ $response['message'] = $helper->__(
107
+ 'Successfully synced categories.'
108
+ );
109
+ } catch (Innobyte_EmagMarketplace_Exception $iemEx) {
110
+ $response['message'] = $helper->__($iemEx->getMessage());
111
+ } catch (Exception $ex) {
112
+ Mage::logException($ex);
113
+ $response['message'] = $helper->__(
114
+ 'An error occurred. Please try again later.'
115
+ );
116
+ }
117
+
118
+ $this->getResponse()
119
+ ->setHeader(
120
+ 'Content-Type',
121
+ 'application/json; charset=utf-8'
122
+ )
123
+ ->setBody(Mage::helper('core')->jsonEncode($response));
124
+ }
125
+ }
app/code/local/Innobyte/EmagMarketplace/controllers/Adminhtml/Emag/LocalityController.php ADDED
@@ -0,0 +1,283 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG locality controller.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Adminhtml_Emag_LocalityController
11
+ extends Mage_Adminhtml_Controller_Action
12
+ {
13
+ /**
14
+ * Check ACL.
15
+ *
16
+ * @Override
17
+ * @return boolean
18
+ */
19
+ protected function _isAllowed()
20
+ {
21
+ $returnValue = false;
22
+ $session = Mage::getSingleton('admin/session');
23
+ switch ($this->getRequest()->getActionName()) {
24
+ case 'index': // intentionally ommitted break;
25
+ case 'syncLocalities':
26
+ $returnValue = $session->isAllowed(
27
+ 'innobyte_emag_marketplace/locality'
28
+ );
29
+ break;
30
+ case 'getCities':
31
+ $returnValue = $session->isAllowed(
32
+ 'sales/order/actions/edit'
33
+ ) || $session->isAllowed('system/config');
34
+ break;
35
+ default:
36
+ }
37
+ return $returnValue;
38
+ }
39
+
40
+
41
+
42
+ /**
43
+ * Init different stuffs.
44
+ *
45
+ * @return Innobyte_EmagMarketplace_Adminhtml_Emag_LocalityController
46
+ */
47
+ protected function _init()
48
+ {
49
+ $this->loadLayout()
50
+ ->_title($this->__('eMAG'))
51
+ ->_title($this->__('Localities'))
52
+ ->_setActiveMenu('innobyte_emag_marketplace/locality');
53
+
54
+ return $this;
55
+ }
56
+
57
+
58
+
59
+ /**
60
+ * Display localities.
61
+ */
62
+ public function indexAction()
63
+ {
64
+ if ($this->getRequest()->isXmlHttpRequest()) {
65
+ $this->getResponse()->setBody(
66
+ $this->getLayout()
67
+ ->createBlock(
68
+ 'innobyte_emag_marketplace/adminhtml_locality_grid'
69
+ )
70
+ ->toHtml()
71
+ );
72
+ } else {
73
+ $this->_init()
74
+ ->renderLayout();
75
+ }
76
+ }
77
+
78
+
79
+
80
+ /**
81
+ * Read eMAG localities.
82
+ */
83
+ public function syncLocalitiesAction()
84
+ {
85
+ $response = array(
86
+ 'status' => 'error',
87
+ 'message' => '',
88
+ );
89
+ $helper = Mage::helper('innobyte_emag_marketplace');
90
+ $storeId = $helper->getCurrStoreId();
91
+ try {
92
+ if (!$helper->canMakeApiCall($storeId)) {
93
+ throw new Innobyte_EmagMarketplace_Exception(
94
+ 'Please configure extension from System -> Configuration -> eMAG Marketplace'
95
+ );
96
+ }
97
+ $api = Mage::getSingleton('innobyte_emag_marketplace/api_locality')
98
+ ->setStoreId($storeId);
99
+ $flag = Mage::getModel('innobyte_emag_marketplace/locality_flag')
100
+ ->loadSelf();
101
+
102
+ // get pagination
103
+ $data = array();
104
+ if ($flag->getLastSyncronization($storeId)) {
105
+ $data['modified'] = $flag->getLastSyncronization($storeId);
106
+ }
107
+ $apiResponse = $api->setData($data)->count();
108
+ if ($apiResponse->isError()) {
109
+ throw new Innobyte_EmagMarketplace_Exception(
110
+ implode(', ', $apiResponse->getMessages())
111
+ );
112
+ }
113
+
114
+ // get localities
115
+ for ($i = 1; $i <= $api->getNoOfPages(); $i++) {
116
+ $apiResponse = $api->setCurrentPage($i)->read();
117
+ if ($apiResponse->isError()) {
118
+ throw new Innobyte_EmagMarketplace_Exception(
119
+ implode(', ', $apiResponse->getMessages())
120
+ );
121
+ }
122
+ foreach ($apiResponse->getResults() as $locality) {
123
+ $api->importLocality($locality)->save();
124
+ }
125
+ }
126
+ $date = Mage::getModel('core/date')->date('Y-m-d') . ' 00:00:00';
127
+ $flag->setLastSyncronization($storeId, $date)->save();
128
+ $response['status'] = 'success';
129
+ $response['message'] = $helper->__(
130
+ 'Successfully synced localities.'
131
+ );
132
+ } catch (Innobyte_EmagMarketplace_Exception $iemEx) {
133
+ $response['message'] = $helper->__($iemEx->getMessage());
134
+ } catch (Exception $ex) {
135
+ Mage::logException($ex);
136
+ $response['message'] = $helper->__(
137
+ 'An error occurred. Please try again later.'
138
+ );
139
+ }
140
+
141
+ $this->getResponse()
142
+ ->setHeader(
143
+ 'Content-Type',
144
+ 'application/json; charset=utf-8'
145
+ )
146
+ ->setBody(Mage::helper('core')->jsonEncode($response));
147
+ }
148
+
149
+
150
+
151
+ /**
152
+ * Retrieve cities for autocomplete.
153
+ */
154
+ public function getCitiesAction()
155
+ {
156
+ $items = array();
157
+ $helper = Mage::helper('innobyte_emag_marketplace');
158
+ try {
159
+ $addressType = trim($this->getRequest()->getParam('address_type'));
160
+ $allowedAddresses = array('billing', 'shipping', 'shipping_origin');
161
+ if (!in_array($addressType, $allowedAddresses)) {
162
+ throw new Innobyte_EmagMarketplace_Exception(
163
+ 'Address Type (billing|shipping|shipping origin) not set.'
164
+ );
165
+ }
166
+
167
+ $city = trim($this->getRequest()->getParam('city'));
168
+ if (empty($city)) {
169
+ throw new Innobyte_EmagMarketplace_Exception(
170
+ 'Please provide some part of the city name'
171
+ );
172
+ }
173
+ $cityTranslited = $helper->getAsciiTranslitVal($city);
174
+
175
+ $storeId = intval($this->getRequest()->getParam('store_id', 0));
176
+ $country = trim($this->getRequest()->getParam('country', ''));
177
+
178
+ $citiesColl = Mage::getResourceModel(
179
+ 'innobyte_emag_marketplace/locality_collection'
180
+ )->addStoreFilter($storeId)
181
+ ->addFieldToFilter(
182
+ array('name_latin', 'name'),
183
+ array(
184
+ array('like' => '%' . $cityTranslited . '%'),
185
+ array('like' => '%' . $city . '%'),
186
+ )
187
+ );
188
+
189
+ // process products in chunks
190
+ // so DB does not get busy if too many localities
191
+ $citiesCnt = $citiesColl->getSize();
192
+ $chunkSize = 100;
193
+ $pages = ceil($citiesCnt / $chunkSize);
194
+ $i = 0;
195
+ $results = array();
196
+ while ($i < $pages) {
197
+ $citiesColl->clear();
198
+ $citiesColl->getSelect()
199
+ ->reset(Zend_Db_Select::LIMIT_COUNT)
200
+ ->reset(Zend_Db_Select::LIMIT_OFFSET)
201
+ ->limit($chunkSize, $i * $chunkSize);
202
+ foreach ($citiesColl as $locality) {
203
+ $itemData = array(
204
+ 'id' => $locality->getEmagId(),
205
+ 'name' => $locality->getName(),
206
+ 'county' => $locality->getRegion2(),
207
+ 'description' => $this->_getCityDescription($locality),
208
+ );
209
+ if ($country) {
210
+ // add auxiliay region id data, based on country sent,
211
+ // unfortunately eMAG cities do not have country info
212
+ // so the filter to be made more accurrate.
213
+ $region = $helper->getMagentoRegion(
214
+ $locality->getRegion2Latin(),
215
+ $country
216
+ );
217
+ if (!is_null($region) && $region->getId()) {
218
+ $itemData['county_id'] = $region->getId();
219
+ }
220
+ }
221
+ $results[] = $itemData;
222
+ }
223
+ $i++;
224
+ }
225
+ $items = $results;
226
+ } catch (Innobyte_EmagMarketplace_Exception $iemEx) {
227
+ $items[] = array(
228
+ 'id' => 'error',
229
+ 'name' => '',
230
+ 'county' => '',
231
+ 'description' => $helper->__($iemEx->getMessage()),
232
+ );
233
+ } catch (Exception $ex) {
234
+ Mage::logException($ex);
235
+ $items[] = array(
236
+ 'id' => 'error',
237
+ 'name' => '',
238
+ 'county' => '',
239
+ 'description' => $helper->__(
240
+ 'An error occurred. Please try again later.'
241
+ ),
242
+ );
243
+ }
244
+
245
+ $block = $this->getLayout()->createBlock('adminhtml/template')
246
+ ->setTemplate('innobyte/emag_marketplace/sales/order/emag_edit/city-autocomplete.phtml')
247
+ ->assign('items', $items)
248
+ ->assign('addressType', $addressType);
249
+ $this->getResponse()->setBody($block->toHtml());
250
+ }
251
+
252
+
253
+
254
+ /**
255
+ * Retrieve region 3 and region 2.
256
+ *
257
+ * @param Innobyte_EmagMarketplace_Model_Locality $locality
258
+ * @return string
259
+ */
260
+ protected function _getCityDescription(
261
+ Innobyte_EmagMarketplace_Model_Locality $locality
262
+ )
263
+ {
264
+ $returnValue = '';
265
+ if (is_null($locality)) {
266
+ return $returnValue;
267
+ }
268
+ if ($locality->getRegion3()) {
269
+ $returnValue .= '[' . $locality->getRegion3();
270
+ }
271
+ if ($locality->getRegion2()) {
272
+ if ($locality->getRegion3()) {
273
+ $returnValue .= ', ' . $locality->getRegion2();
274
+ } else {
275
+ $returnValue .= '[' . $locality->getRegion2();
276
+ }
277
+ }
278
+ if ($locality->getRegion3() || $locality->getRegion2()) {
279
+ $returnValue .= ']';
280
+ }
281
+ return $returnValue;
282
+ }
283
+ }
app/code/local/Innobyte/EmagMarketplace/controllers/Adminhtml/Emag/ProductController.php ADDED
@@ -0,0 +1,517 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG product controller.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Adminhtml_Emag_ProductController
11
+ extends Mage_Adminhtml_Controller_Action
12
+ {
13
+ /**
14
+ * Check ACL.
15
+ *
16
+ * @Override
17
+ * @return boolean
18
+ */
19
+ protected function _isAllowed()
20
+ {
21
+ return Mage::getSingleton('admin/session')
22
+ ->isAllowed('catalog/products');
23
+ }
24
+
25
+
26
+
27
+ /**
28
+ * Display tab 's content.
29
+ */
30
+ public function indexAction()
31
+ {
32
+ $storeId = $this->getRequest()->getParam('store');
33
+ $prodId = $this->getRequest()->getParam('id');
34
+ $mageProduct = Mage::getModel('catalog/product')
35
+ ->setStoreId($storeId)
36
+ ->load($prodId);
37
+
38
+ $emagProduct = Mage::getModel('innobyte_emag_marketplace/product')
39
+ ->loadByProdIdAndStore($prodId, $storeId);
40
+ $session = Mage::getSingleton('adminhtml/session');
41
+ if (is_array($session->getData('inno_emag_mktp_data'))) {
42
+ $emagProduct->addData($session->getData('inno_emag_mktp_data'));
43
+ $session->unsetData('inno_emag_mktp_data');
44
+ }
45
+ Mage::register('current_emag_product', $emagProduct);
46
+
47
+ if (!Mage::registry('current_product')) {
48
+ Mage::register('current_product', $mageProduct);
49
+ }
50
+
51
+ if ($this->getRequest()->isXmlHttpRequest()) {
52
+ $this->getResponse()->setBody(
53
+ $this->getLayout()
54
+ ->createBlock(
55
+ 'innobyte_emag_marketplace/adminhtml_catalog_product_edit_tab_emagMarketplace'
56
+ )
57
+ ->toHtml()
58
+ );
59
+ }
60
+ }
61
+
62
+
63
+
64
+ /**
65
+ * Display tab 's content.
66
+ */
67
+ public function getCategoryDataAction()
68
+ {
69
+ $response = array(
70
+ 'status' => 'error',
71
+ 'message' => '',
72
+ 'results' => array(),
73
+ );
74
+
75
+ $helper = Mage::helper('innobyte_emag_marketplace');
76
+ try {
77
+ $categoryId = (int) $this->getRequest()->getParam('category_id');
78
+ $getFamilyTypes = (bool) $this->getRequest()->getParam('get_family_types', 0);
79
+ if (!$categoryId) {
80
+ throw new Innobyte_EmagMarketplace_Exception(
81
+ 'No category provided.'
82
+ );
83
+ }
84
+ $category = Mage::getModel('innobyte_emag_marketplace/category')
85
+ ->load($categoryId);
86
+ if ($category->getStoreId() != $helper->getCurrStoreId()) {
87
+ throw new Innobyte_EmagMarketplace_Exception(
88
+ 'Invalid category provided.'
89
+ );
90
+ }
91
+ $characteristics = is_array($category->getCharacteristics()) ?
92
+ $category->getCharacteristics() :
93
+ array();
94
+ $response['results']['characteristics'] = array();
95
+ foreach ($characteristics as $characteristic) {
96
+ $response['results']['characteristics'][$characteristic->getId()] = $helper->escapeHtml(
97
+ $helper->__($characteristic->getName())
98
+ );
99
+ }
100
+ if ($getFamilyTypes && is_array($category->getFamilyTypes())) {
101
+ $familyTypes = array();
102
+ $familyTypesCharacteristics = array();
103
+ foreach ($category->getFamilyTypes() as $fType) {
104
+ $familyTypes[$fType->getId()] = $helper->escapeHtml(
105
+ $helper->__($fType->getName())
106
+ );
107
+ $ftCharacteristics = array();
108
+ foreach ($fType->getCharacteristics() as $ftChar) {
109
+ $ftCharacteristics[] = $ftChar->getMageIdEmagChar();
110
+ }
111
+ $familyTypesCharacteristics[$fType->getId()] = $ftCharacteristics;
112
+ }
113
+ $response['results']['family_types'] = array(
114
+ 'items' => $familyTypes,
115
+ 'characteristics' => $familyTypesCharacteristics,
116
+ );
117
+ }
118
+ $response['status'] = 'success';
119
+ } catch (Innobyte_EmagMarketplace_Exception $iemEx) {
120
+ $response['message'] = $helper->__($iemEx->getMessage());
121
+ } catch (Exception $ex) {
122
+ Mage::logException($ex);
123
+ $response['message'] = $helper->__(
124
+ 'An error occurred. Please try again later.'
125
+ );
126
+ }
127
+
128
+ $this->getResponse()
129
+ ->setHeader(
130
+ 'Content-Type',
131
+ 'application/json; charset=utf-8'
132
+ )
133
+ ->setBody(Mage::helper('core')->jsonEncode($response));
134
+ }
135
+
136
+
137
+
138
+ /**
139
+ * Send whole/offer product.
140
+ */
141
+ public function sendAction()
142
+ {
143
+ $productId = (int) $this->getRequest()->getParam('id', 0);
144
+ $sendType = $this->getRequest()->getParam('send', 'product');
145
+ $helper = Mage::helper('innobyte_emag_marketplace');
146
+ $emagProduct = Mage::getModel('innobyte_emag_marketplace/product')
147
+ ->loadByProdIdAndStore($productId, $helper->getCurrStoreId());
148
+
149
+ if (!$emagProduct->getId()
150
+ || !$helper->isProductActionValid($emagProduct->getMagentoProduct())
151
+ || !$helper->canMakeApiCall($emagProduct->getStoreId())) {
152
+ return $this->_redirect(
153
+ 'adminhtml/catalog_product/edit',
154
+ array('_current' => 1)
155
+ );
156
+ }
157
+ try {
158
+ $apiProd = Mage::getModel('innobyte_emag_marketplace/api_product')
159
+ ->setStoreId($emagProduct->getStoreId())
160
+ ->setEmagProduct($emagProduct);
161
+ if ('product' === $sendType) {
162
+ $apiResp = $apiProd->saveProduct();
163
+ } else {
164
+ $apiResp = $apiProd->saveOffer();
165
+ }
166
+ if ($apiResp->isError()) {
167
+ throw new Innobyte_EmagMarketplace_Exception(
168
+ implode('<br />', $apiResp->getMessages())
169
+ );
170
+ }
171
+ if ('product' === $sendType && !$emagProduct->isSynced()) {
172
+ $emagProduct
173
+ ->setIsSynced(Innobyte_EmagMarketplace_Model_Product::IS_SYNCED)
174
+ ->save();
175
+ }
176
+ if (!count($apiResp->getMessages())) { // check for warnings
177
+ if ('product' === $sendType) {
178
+ $this->_getSession()->addSuccess(
179
+ $helper->__('Successfully sent product to eMAG.')
180
+ );
181
+ } else {
182
+ $this->_getSession()->addSuccess(
183
+ $helper->__('Successfully sent offer to eMAG.')
184
+ );
185
+ }
186
+ } else {
187
+ $this->_getSession()->addNotice(
188
+ implode('<br />', $apiResp->getMessages())
189
+ );
190
+ }
191
+ } catch (Innobyte_EmagMarketplace_Exception $iemex) {
192
+ $this->_getSession()->addError($helper->__($iemex->getMessage()));
193
+ } catch (Exception $ex) {
194
+ Mage::logException($ex);
195
+ $this->_getSession()->addError(
196
+ $helper->__('An error occurred. Please try again later.')
197
+ );
198
+ }
199
+ return $this->_redirect(
200
+ 'adminhtml/catalog_product/edit',
201
+ array('_current' => 1)
202
+ );
203
+ }
204
+
205
+
206
+
207
+ /**
208
+ * Deactivate offer.
209
+ */
210
+ public function deactivateOfferAction()
211
+ {
212
+ $productId = (int) $this->getRequest()->getParam('id', 0);
213
+ $helper = Mage::helper('innobyte_emag_marketplace');
214
+ $emagProduct = Mage::getModel('innobyte_emag_marketplace/product')
215
+ ->loadByProdIdAndStore($productId, $helper->getCurrStoreId());
216
+
217
+ if (!$emagProduct->getId()
218
+ || !$helper->isProductActionValid($emagProduct->getMagentoProduct())
219
+ || !$helper->canMakeApiCall($emagProduct->getStoreId())) {
220
+ return $this->_redirect(
221
+ 'adminhtml/catalog_product/edit',
222
+ array('_current' => 1)
223
+ );
224
+ }
225
+ try {
226
+ $emagProduct
227
+ ->setStatus(Innobyte_EmagMarketplace_Model_Source_OfferStatus::STATUS_INACTIVE);
228
+ $apiResp = Mage::getModel('innobyte_emag_marketplace/api_product')
229
+ ->setStoreId($emagProduct->getStoreId())
230
+ ->setEmagProduct($emagProduct)
231
+ ->saveOffer();
232
+ if ($apiResp->isError()) {
233
+ throw new Innobyte_EmagMarketplace_Exception(
234
+ implode('<br />', $apiResp->getMessages())
235
+ );
236
+ }
237
+ $emagProduct->save();
238
+ if (!count($apiResp->getMessages())) { // check for warnings
239
+ $this->_getSession()->addSuccess(
240
+ $helper->__('Successfully deactivated offer.')
241
+ );
242
+ } else {
243
+ $this->_getSession()->addNotice(
244
+ implode('<br />', $apiResp->getMessages())
245
+ );
246
+ }
247
+ } catch (Innobyte_EmagMarketplace_Exception $iemex) {
248
+ $this->_getSession()->addError($helper->__($iemex->getMessage()));
249
+ } catch (Exception $ex) {
250
+ Mage::logException($ex);
251
+ $this->_getSession()->addError(
252
+ $helper->__('An error occurred. Please try again later.')
253
+ );
254
+ }
255
+ return $this->_redirect(
256
+ 'adminhtml/catalog_product/edit',
257
+ array('_current' => 1)
258
+ );
259
+ }
260
+
261
+
262
+
263
+ /**
264
+ * Send whole product (mass).
265
+ */
266
+ public function massSendProductAction()
267
+ {
268
+ $prodIds = $this->getRequest()->getParam('product', array());
269
+ $prodIds = array_filter(array_unique(array_map('intval', $prodIds)));
270
+ $helper = Mage::helper('innobyte_emag_marketplace');
271
+ $storeId = $helper->getCurrStoreId();
272
+ $invalidIds = array();
273
+ $successfullySentIds = array();
274
+ try {
275
+ if (empty($prodIds)) {
276
+ throw new Innobyte_EmagMarketplace_Exception(
277
+ 'Please select some products.'
278
+ );
279
+ }
280
+ if (!$helper->canMakeApiCall($storeId)) {
281
+ throw new Innobyte_EmagMarketplace_Exception(
282
+ 'Please configure extension from System -> '
283
+ . 'Configuration -> eMAG Marketplace'
284
+ );
285
+ }
286
+ foreach ($prodIds as $prodId) {
287
+ $emagProd = Mage::getModel('innobyte_emag_marketplace/product')
288
+ ->loadByProdIdAndStore($prodId, $storeId);
289
+ $isProdValid = $helper->isProductActionValid(
290
+ $emagProd->getMagentoProduct()
291
+ );
292
+ if (!$emagProd->getId() || !$isProdValid) {
293
+ $invalidIds[] = $prodId;
294
+ continue;
295
+ }
296
+ $apiResp = Mage::getModel('innobyte_emag_marketplace/api_product')
297
+ ->setStoreId($emagProd->getStoreId())
298
+ ->setEmagProduct($emagProd)
299
+ ->saveProduct();
300
+ if ($apiResp->isError()) {
301
+ $this->_getSession()->addError(
302
+ implode('<br />', $apiResp->getMessages())
303
+ );
304
+ continue;
305
+ } elseif (count($apiResp->getMessages())) {
306
+ $this->_getSession()->addNotice(
307
+ implode('<br />', $apiResp->getMessages())
308
+ );
309
+ }
310
+ if (!$emagProd->isSynced()) {
311
+ $emagProd
312
+ ->setIsSynced(Innobyte_EmagMarketplace_Model_Product::IS_SYNCED)
313
+ ->save();
314
+ }
315
+ $successfullySentIds[] = $prodId;
316
+ }
317
+ } catch (Innobyte_EmagMarketplace_Exception $iemex) {
318
+ $this->_getSession()->addError($helper->__($iemex->getMessage()));
319
+ } catch (Exception $ex) {
320
+ Mage::logException($ex);
321
+ $this->_getSession()->addError(
322
+ $helper->__('An error occurred. Please try again later.')
323
+ );
324
+ }
325
+
326
+ if (!empty($invalidIds)) {
327
+ $this->_getSession()->addNotice(
328
+ $helper->__(
329
+ 'Action cannot be applied for product(s): %s',
330
+ implode(', ', $invalidIds)
331
+ )
332
+ );
333
+ }
334
+ if (!empty($successfullySentIds)) {
335
+ $this->_getSession()->addSuccess(
336
+ $helper->__(
337
+ 'Successfully sent to eMAG the product(s): %s',
338
+ implode(', ', $successfullySentIds)
339
+ )
340
+ );
341
+ }
342
+
343
+ return $this->_redirect(
344
+ 'adminhtml/catalog_product/',
345
+ array('store' => $storeId)
346
+ );
347
+ }
348
+
349
+
350
+
351
+ /**
352
+ * Send products offers (mass).
353
+ */
354
+ public function massSendOfferAction()
355
+ {
356
+ $prodIds = $this->getRequest()->getParam('product', array());
357
+ $prodIds = array_filter(array_unique(array_map('intval', $prodIds)));
358
+ $helper = Mage::helper('innobyte_emag_marketplace');
359
+ $storeId = $helper->getCurrStoreId();
360
+ $invalidIds = array();
361
+ $successfullySentIds = array();
362
+ try {
363
+ if (empty($prodIds)) {
364
+ throw new Innobyte_EmagMarketplace_Exception(
365
+ 'Please select some products.'
366
+ );
367
+ }
368
+ if (!$helper->canMakeApiCall($storeId)) {
369
+ throw new Innobyte_EmagMarketplace_Exception(
370
+ 'Please configure extension from System -> '
371
+ . 'Configuration -> eMAG Marketplace'
372
+ );
373
+ }
374
+ foreach ($prodIds as $prodId) {
375
+ $emagProd = Mage::getModel('innobyte_emag_marketplace/product')
376
+ ->loadByProdIdAndStore($prodId, $storeId);
377
+ $isProdValid = $helper->isProductActionValid(
378
+ $emagProd->getMagentoProduct()
379
+ );
380
+ if (!$emagProd->getId() || !$isProdValid) {
381
+ $invalidIds[] = $prodId;
382
+ continue;
383
+ }
384
+ $apiResp = Mage::getModel('innobyte_emag_marketplace/api_product')
385
+ ->setStoreId($emagProd->getStoreId())
386
+ ->setEmagProduct($emagProd)
387
+ ->saveOffer();
388
+ if ($apiResp->isError()) {
389
+ $this->_getSession()->addError(
390
+ implode('<br />', $apiResp->getMessages())
391
+ );
392
+ continue;
393
+ } elseif (count($apiResp->getMessages())) {
394
+ $this->_getSession()->addNotice(
395
+ implode('<br />', $apiResp->getMessages())
396
+ );
397
+ }
398
+ $successfullySentIds[] = $prodId;
399
+ }
400
+ } catch (Innobyte_EmagMarketplace_Exception $iemex) {
401
+ $this->_getSession()->addError($helper->__($iemex->getMessage()));
402
+ } catch (Exception $ex) {
403
+ Mage::logException($ex);
404
+ $this->_getSession()->addError(
405
+ $helper->__('An error occurred. Please try again later.')
406
+ );
407
+ }
408
+
409
+ if (!empty($invalidIds)) {
410
+ $this->_getSession()->addNotice(
411
+ $helper->__(
412
+ 'Action cannot be applied for product(s): %s',
413
+ implode(', ', $invalidIds)
414
+ )
415
+ );
416
+ }
417
+ if (!empty($successfullySentIds)) {
418
+ $this->_getSession()->addSuccess(
419
+ $helper->__(
420
+ 'Successfully sent to eMAG the offer for product(s): %s',
421
+ implode(', ', $successfullySentIds)
422
+ )
423
+ );
424
+ }
425
+
426
+ return $this->_redirect(
427
+ 'adminhtml/catalog_product/',
428
+ array('store' => $storeId)
429
+ );
430
+ }
431
+
432
+
433
+
434
+ /**
435
+ * Deactivate products offers (mass).
436
+ */
437
+ public function massDeactivateOfferAction()
438
+ {
439
+ $prodIds = $this->getRequest()->getParam('product', array());
440
+ $prodIds = array_filter(array_unique(array_map('intval', $prodIds)));
441
+ $helper = Mage::helper('innobyte_emag_marketplace');
442
+ $storeId = $helper->getCurrStoreId();
443
+ $invalidIds = array();
444
+ $successfullySentIds = array();
445
+ try {
446
+ if (empty($prodIds)) {
447
+ throw new Innobyte_EmagMarketplace_Exception(
448
+ 'Please select some products.'
449
+ );
450
+ }
451
+ if (!$helper->canMakeApiCall($storeId)) {
452
+ throw new Innobyte_EmagMarketplace_Exception(
453
+ 'Please configure extension from System -> '
454
+ . 'Configuration -> eMAG Marketplace'
455
+ );
456
+ }
457
+ foreach ($prodIds as $prodId) {
458
+ Mage::log(__METHOD__ . ' ' . $prodId);
459
+ $emagProd = Mage::getModel('innobyte_emag_marketplace/product')
460
+ ->loadByProdIdAndStore($prodId, $storeId);
461
+ $isProdValid = $helper->isProductActionValid(
462
+ $emagProd->getMagentoProduct()
463
+ );
464
+ if (!$emagProd->getId() || !$isProdValid) {
465
+ $invalidIds[] = $prodId;
466
+ continue;
467
+ }
468
+ $emagProd->setStatus(Innobyte_EmagMarketplace_Model_Source_OfferStatus::STATUS_INACTIVE);
469
+ $apiResp = Mage::getModel('innobyte_emag_marketplace/api_product')
470
+ ->setStoreId($emagProd->getStoreId())
471
+ ->setEmagProduct($emagProd)
472
+ ->saveOffer();
473
+ if ($apiResp->isError()) {
474
+ $this->_getSession()->addError(
475
+ implode('<br />', $apiResp->getMessages())
476
+ );
477
+ continue;
478
+ } elseif (count($apiResp->getMessages())) {
479
+ $this->_getSession()->addNotice(
480
+ implode('<br />', $apiResp->getMessages())
481
+ );
482
+ }
483
+ $emagProd->save();
484
+ $successfullySentIds[] = $prodId;
485
+ }
486
+ } catch (Innobyte_EmagMarketplace_Exception $iemex) {
487
+ $this->_getSession()->addError($helper->__($iemex->getMessage()));
488
+ } catch (Exception $ex) {
489
+ Mage::logException($ex);
490
+ $this->_getSession()->addError(
491
+ $helper->__('An error occurred. Please try again later.')
492
+ );
493
+ }
494
+
495
+ if (!empty($invalidIds)) {
496
+ $this->_getSession()->addNotice(
497
+ $helper->__(
498
+ 'Action cannot be applied for product(s): %s',
499
+ implode(', ', $invalidIds)
500
+ )
501
+ );
502
+ }
503
+ if (!empty($successfullySentIds)) {
504
+ $this->_getSession()->addSuccess(
505
+ $helper->__(
506
+ 'Successfully deactivated offer for product(s): %s',
507
+ implode(', ', $successfullySentIds)
508
+ )
509
+ );
510
+ }
511
+
512
+ return $this->_redirect(
513
+ 'adminhtml/catalog_product/',
514
+ array('store' => $storeId)
515
+ );
516
+ }
517
+ }
app/code/local/Innobyte/EmagMarketplace/controllers/Adminhtml/Emag/VatController.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG VAT controller.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+
10
+ class Innobyte_EmagMarketplace_Adminhtml_Emag_VatController
11
+ extends Mage_Adminhtml_Controller_Action
12
+ {
13
+ /**
14
+ * Check ACL.
15
+ *
16
+ * @Override
17
+ * @return boolean
18
+ */
19
+ protected function _isAllowed()
20
+ {
21
+ return Mage::getSingleton('admin/session')
22
+ ->isAllowed('innobyte_emag_marketplace/vat');
23
+ }
24
+
25
+
26
+
27
+ /**
28
+ * Init different stuffs.
29
+ *
30
+ * @return Innobyte_EmagMarketplace_Adminhtml_Emag_VatController
31
+ */
32
+ protected function _init()
33
+ {
34
+ $this->loadLayout()
35
+ ->_title($this->__('eMAG'))
36
+ ->_title($this->__('VATs'))
37
+ ->_setActiveMenu('innobyte_emag_marketplace/vat');
38
+
39
+ return $this;
40
+ }
41
+
42
+
43
+
44
+ /**
45
+ * Display VATs.
46
+ */
47
+ public function indexAction()
48
+ {
49
+ if ($this->getRequest()->isXmlHttpRequest()) {
50
+ $this->getResponse()->setBody(
51
+ $this->getLayout()
52
+ ->createBlock(
53
+ 'innobyte_emag_marketplace/adminhtml_vat_grid'
54
+ )->toHtml()
55
+ );
56
+ } else {
57
+ $this->_init()
58
+ ->renderLayout();
59
+ }
60
+ }
61
+
62
+
63
+
64
+ /**
65
+ * Read eMAG VATs.
66
+ */
67
+ public function syncVatsAction()
68
+ {
69
+ $response = array(
70
+ 'status' => 'error',
71
+ 'message' => '',
72
+ );
73
+ $helper = Mage::helper('innobyte_emag_marketplace');
74
+ $storeId = $helper->getCurrStoreId();
75
+ try {
76
+ if (!$helper->canMakeApiCall($storeId)) {
77
+ throw new Innobyte_EmagMarketplace_Exception(
78
+ 'Please configure extension from System -> Configuration -> eMAG Marketplace'
79
+ );
80
+ }
81
+ $api = Mage::getSingleton('innobyte_emag_marketplace/api_vat')
82
+ ->setStoreId($storeId);
83
+ $apiResponse = $api->read();
84
+ if ($apiResponse->isError()) {
85
+ throw new Innobyte_EmagMarketplace_Exception(
86
+ implode(', ', $apiResponse->getMessages())
87
+ );
88
+ }
89
+
90
+ $hasVat = false;
91
+ foreach ($apiResponse->getResults() as $vat) {
92
+ $hasVat = true;
93
+ $api->importVat($vat)->save();
94
+ }
95
+
96
+ if ($hasVat) {
97
+ $response = array(
98
+ 'status' => 'success',
99
+ 'message' => $helper->__('Successfully synced VATs.'),
100
+ );
101
+ } else {
102
+ $response = array(
103
+ 'status' => 'success',
104
+ 'message' => $helper->__('No VATs found.'),
105
+ );
106
+ }
107
+ } catch (Innobyte_EmagMarketplace_Exception $iemEx) {
108
+ $response['message'] = $helper->__($iemEx->getMessage());
109
+ } catch (Exception $ex) {
110
+ Mage::logException($ex);
111
+ $response['message'] = $helper->__(
112
+ 'An error occurred. Please try again later.'
113
+ );
114
+ }
115
+
116
+ $this->getResponse()
117
+ ->setHeader(
118
+ 'Content-Type',
119
+ 'application/json; charset=utf-8'
120
+ )
121
+ ->setBody(Mage::helper('core')->jsonEncode($response));
122
+ }
123
+ }
app/code/local/Innobyte/EmagMarketplace/controllers/Adminhtml/Emag/VoucherController.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Adminhtml_Emag_VoucherController
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_Adminhtml_Emag_VoucherController extends Mage_Adminhtml_Controller_Action
12
+ {
13
+
14
+ /**
15
+ * Get eMAG marketplace data helper
16
+ *
17
+ * @return Innobyte_EmagMarketplace_Helper_Data
18
+ */
19
+ protected function _getHelper()
20
+ {
21
+ return Mage::helper('innobyte_emag_marketplace');
22
+ }
23
+
24
+ /**
25
+ * Remove voucher from sales entity
26
+ */
27
+ public function removeAction()
28
+ {
29
+ if (!$this->getRequest()->isXmlHttpRequest()) {
30
+ $this->getResponse()->setBody($this->_getHelper()->__('Invalid request!'));
31
+ }
32
+
33
+ try {
34
+ /** @var $voucher Innobyte_EmagMarketplace_Model_Resource_Sales_Quote_Voucher_Collection */
35
+ $collection = Mage::getResourceModel('innobyte_emag_marketplace/sales_quote_voucher_collection');
36
+ $collection
37
+ ->addFieldToFilter('entity_id', $this->getRequest()->getParam('quote_id'))
38
+ ->addFieldToFilter('emag_voucher_id', $this->getRequest()->getParam('voucher_id'));
39
+
40
+ /** @var $voucher Innobyte_EmagMarketplace_Model_Sales_Quote_Voucher */
41
+ $voucher = $collection->getFirstItem();
42
+
43
+ if ($collection->getSize()) {
44
+ $voucher->delete();
45
+ $this->getResponse()->setBody(
46
+ $this->_getHelper()->__(
47
+ 'eMAG Voucher successfully deleted!'
48
+ )
49
+ );
50
+ }
51
+ } catch (Exception $e) {
52
+ $this->getResponse()->setBody(
53
+ $this->_getHelper()->__(
54
+ 'There was an error while removing voucher. Please try again!'
55
+ )
56
+ );
57
+ Mage::log($e->getMessage());
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Acl check for admin
63
+ *
64
+ * @return bool
65
+ */
66
+ protected function _isAllowed()
67
+ {
68
+ return Mage::getSingleton('admin/session')->isAllowed('innobyte_emag_marketplace/vouchers');
69
+ }
70
+
71
+ }
app/code/local/Innobyte/EmagMarketplace/controllers/Adminhtml/Sales/Invoice/UploadController.php ADDED
@@ -0,0 +1,211 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Adminhtml_Sales_Invoice_UploadController
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ *
11
+ */
12
+ class Innobyte_EmagMarketplace_Adminhtml_Sales_Invoice_UploadController extends Mage_Adminhtml_Controller_Action
13
+ {
14
+
15
+ /**
16
+ * Get eMAG marketplace data helper
17
+ *
18
+ * @return Innobyte_EmagMarketplace_Helper_Data
19
+ */
20
+ protected function _getHelper()
21
+ {
22
+ return Mage::helper('innobyte_emag_marketplace');
23
+ }
24
+
25
+ /**
26
+ * Get third party invoice model
27
+ *
28
+ * @return Innobyte_EmagMarketplace_Model_Sales_Invoice
29
+ */
30
+ protected function _getInvoiceModel()
31
+ {
32
+ return Mage::getModel('innobyte_emag_marketplace/sales_invoice');
33
+ }
34
+
35
+ /**
36
+ * Invoice popup
37
+ */
38
+ public function popupAction()
39
+ {
40
+ $this->loadLayout('popup');
41
+ $this->renderLayout();
42
+ }
43
+
44
+ /**
45
+ * Save invoice
46
+ */
47
+ public function saveAction()
48
+ {
49
+ if (!is_uploaded_file($_FILES['invoice']['tmp_name'])) {
50
+ $this->_getSession()->addError(
51
+ $this->_getHelper()->__(
52
+ 'There was an error while uploading file. Please try again!'
53
+ )
54
+ );
55
+ $this->_redirect('*/sales_invoice_upload/popup', array('_current' => true));
56
+ return;
57
+ }
58
+
59
+ try {
60
+ $emagInvoice = $this->_getInvoiceModel();
61
+
62
+ $uploader = new Varien_File_Uploader($_FILES['invoice']);
63
+ $uploader->setAllowedExtensions(array('pdf', 'doc', 'docx'));
64
+ $uploader->addValidateCallback('validate_image', Mage::helper('catalog/image'), 'validateUploadFile');
65
+ $uploader->setAllowRenameFiles(true);
66
+ $uploader->setFilesDispersion(false);
67
+ $uploader->removeValidateCallback('validate_image');
68
+ $result = $uploader->save($emagInvoice->getInvoiceBaseDirectory());
69
+
70
+ // set invoice type
71
+ $type = Innobyte_EmagMarketplace_Model_Sales_Invoice::EMAG_INVOICE_NORMAL;
72
+ if ($this->getRequest()->getParam('is_storno')) {
73
+ $type = Innobyte_EmagMarketplace_Model_Sales_Invoice::EMAG_INVOICE_STORNO;
74
+ }
75
+
76
+ // save third party invoice
77
+ $emagInvoice->setOrderId($this->getRequest()->getParam('order_id'));
78
+ $emagInvoice->setEmagInvoiceName($result['file']);
79
+ $emagInvoice->setEmagInvoiceType($type);
80
+ $emagInvoice->save();
81
+ } catch (Exception $e) {
82
+ $this->_getSession()->addError(
83
+ $this->_getHelper()->__(
84
+ $e->getMessage()
85
+ )
86
+ );
87
+ }
88
+
89
+ $this->_redirect('*/sales_invoice_upload/popup', array('_current' => true));
90
+ }
91
+
92
+ /**
93
+ * Preview/Download invoice
94
+ */
95
+ public function downloadAction()
96
+ {
97
+ $file = null;
98
+ $plain = false;
99
+ if ($this->getRequest()->getParam('file')) {
100
+ // download file
101
+ $file = Mage::helper('core')->urlDecode($this->getRequest()->getParam('file'));
102
+ } else if ($this->getRequest()->getParam('image')) {
103
+ // show plain image
104
+ $file = Mage::helper('core')->urlDecode($this->getRequest()->getParam('image'));
105
+ $plain = true;
106
+ } else {
107
+ return $this->norouteAction();
108
+ }
109
+
110
+ $path = $this->_getInvoiceModel()->getInvoiceBaseDirectory();
111
+
112
+ $ioFile = new Varien_Io_File();
113
+ $ioFile->open(array('path' => $path));
114
+ $fileName = $ioFile->getCleanPath($path . $file);
115
+ $path = $ioFile->getCleanPath($path);
116
+
117
+ if ((!$ioFile->fileExists($fileName) || strpos($fileName, $path) !== 0)
118
+ && !Mage::helper('core/file_storage')->processStorageFile(str_replace('/', DS, $fileName))
119
+ ) {
120
+ return $this->norouteAction();
121
+ }
122
+
123
+ if ($plain) {
124
+ $extension = pathinfo($fileName, PATHINFO_EXTENSION);
125
+ switch (strtolower($extension)) {
126
+ case 'gif':
127
+ $contentType = 'image/gif';
128
+ break;
129
+ case 'jpg':
130
+ $contentType = 'image/jpeg';
131
+ break;
132
+ case 'png':
133
+ $contentType = 'image/png';
134
+ break;
135
+ default:
136
+ $contentType = 'application/octet-stream';
137
+ break;
138
+ }
139
+
140
+ $ioFile->streamOpen($fileName, 'r');
141
+ $contentLength = $ioFile->streamStat('size');
142
+ $contentModify = $ioFile->streamStat('mtime');
143
+
144
+ $this->getResponse()
145
+ ->setHttpResponseCode(200)
146
+ ->setHeader('Pragma', 'public', true)
147
+ ->setHeader('Content-type', $contentType, true)
148
+ ->setHeader('Content-Length', $contentLength)
149
+ ->setHeader('Last-Modified', date('r', $contentModify))
150
+ ->clearBody();
151
+ $this->getResponse()->sendHeaders();
152
+
153
+ while (false !== ($buffer = $ioFile->streamRead())) {
154
+ echo $buffer;
155
+ }
156
+ } else {
157
+ $name = pathinfo($fileName, PATHINFO_BASENAME);
158
+ $this->_prepareDownloadResponse($name, array(
159
+ 'type' => 'filename',
160
+ 'value' => $fileName
161
+ ));
162
+ }
163
+
164
+ return $this;
165
+ }
166
+
167
+ /**
168
+ * Delete invoice
169
+ */
170
+ public function deleteAction()
171
+ {
172
+ $invoiceId = $this->getRequest()->getParam('invoice_id');
173
+ if (!$invoiceId) {
174
+ $this->_getSession()->addError(
175
+ $this->_getHelper()->__(
176
+ 'Invoice not found!'
177
+ )
178
+ );
179
+ $this->_redirect('*/sales_invoice_upload/popup', array('_current' => true));
180
+ return;
181
+ }
182
+
183
+ /** @var $invoice Innobyte_EmagMarketplace_Model_Sales_Invoice */
184
+ $invoice = $this->_getInvoiceModel()
185
+ ->load($invoiceId);
186
+ $filePath = $invoice->getInvoiceBasePath();
187
+
188
+ $invoice->delete();
189
+
190
+ unlink($filePath);
191
+
192
+ $this->_getSession()->addSuccess(
193
+ $this->_getHelper()->__(
194
+ 'Invoice successfully deleted.'
195
+ )
196
+ );
197
+
198
+ $this->_redirect('*/sales_invoice_upload/popup', array('_current' => true));
199
+ }
200
+
201
+ /**
202
+ * Acl check for admin
203
+ *
204
+ * @return bool
205
+ */
206
+ protected function _isAllowed()
207
+ {
208
+ return Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/emag_upload_invoice');
209
+ }
210
+
211
+ }
app/code/local/Innobyte/EmagMarketplace/controllers/Adminhtml/Sales/OrderController.php ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_Adminhtml_Sales_OrderController
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ *
11
+ */
12
+ class Innobyte_EmagMarketplace_Adminhtml_Sales_OrderController extends Mage_Adminhtml_Controller_Action
13
+ {
14
+
15
+ /**
16
+ * Get eMAG marketplace data helper
17
+ *
18
+ * @return Innobyte_EmagMarketplace_Helper_Data
19
+ */
20
+ protected function _getHelper()
21
+ {
22
+ return Mage::helper('innobyte_emag_marketplace');
23
+ }
24
+
25
+ /**
26
+ * @return Innobyte_EmagMarketplace_Model_Api_Order
27
+ */
28
+ public function getOrderApiModel()
29
+ {
30
+ return Mage::getModel('innobyte_emag_marketplace/api_order');
31
+ }
32
+
33
+ /**
34
+ * Acknowledge eMAG order action
35
+ */
36
+ public function emagacknowledgeAction()
37
+ {
38
+ $orderId = $this->getRequest()->getParam('order_id');
39
+ /** @var $order Mage_Sales_Model_Order */
40
+ $order = Mage::getModel('sales/order')->load($orderId);
41
+
42
+ if ($order->getStatus() != Innobyte_EmagMarketplace_Model_Order_Convert_Abstract::STATUS_NEW) {
43
+ $this->_getSession()->addError('Invalid order status!');
44
+ $this->_redirect('*/*/view', array('_current' => true));
45
+ return;
46
+ }
47
+
48
+ if (!$order->getEmagOrderId()) {
49
+ $this->_getSession()->addError('Only eMAG orders can be acknowledged!');
50
+ $this->_redirect('*/*/view', array('_current' => true));
51
+ return;
52
+ }
53
+
54
+ try {
55
+ /** @var $response Innobyte_EmagMarketplace_Model_Api_Response */
56
+ $orderApiModel = $this->getOrderApiModel();
57
+ $response = $orderApiModel
58
+ ->setStoreId($order->getStoreId())
59
+ ->setEmagOrderId($order->getEmagOrderId())
60
+ ->acknowledge();
61
+
62
+ if ($response->isError()) {
63
+ $this->_getSession()->addError(
64
+ $this->getHelper()->__(
65
+ 'eMAG Api Response => %s', implode(',', $response->getMessages())
66
+ )
67
+ );
68
+
69
+ $this->_redirect('*/*/view', array('_current' => true));
70
+ return;
71
+ }
72
+
73
+ /** @var $model Innobyte_EmagMarketplace_Model_Order_Convert_Magento */
74
+ $model = Mage::getModel('innobyte_emag_marketplace/order_convert_magento');
75
+ $model->reReadEmagOrder($order);
76
+
77
+ $this->_getSession()->addSuccess(
78
+ $this->_getHelper()->__('Order successfully acknowledged.')
79
+ );
80
+ } catch (Innobyte_EmagMarketplace_Exception $e) {
81
+ $this->_getSession()->addError(
82
+ $this->_getHelper()->__($e->getMessage())
83
+ );
84
+ } catch (Exception $e) {
85
+ Mage::log($e->getMessage());
86
+ $this->_getSession()->addError(
87
+ $this->_getHelper()->__('There was an error while trying to acknowledge eMAG order!')
88
+ );
89
+ }
90
+
91
+ $this->_redirect('*/*/view', array('_current' => true));
92
+ }
93
+
94
+ /**
95
+ * Change order status to:
96
+ * - emag_prepared
97
+ */
98
+ public function emagprepareAction()
99
+ {
100
+ $status = Innobyte_EmagMarketplace_Model_Order_Convert_Abstract::STATUS_PREPARED;
101
+ $this->_updateStatus($status);
102
+ }
103
+
104
+ /**
105
+ * Change order status to:
106
+ * - emag_canceled
107
+ */
108
+ public function emagcancelAction()
109
+ {
110
+ $status = Innobyte_EmagMarketplace_Model_Order_Convert_Abstract::STATUS_CANCELED;
111
+ $this->_updateStatus($status);
112
+ }
113
+
114
+ /**
115
+ * Update eMAG order status
116
+ *
117
+ * @param $status
118
+ */
119
+ public function _updateStatus($status)
120
+ {
121
+ $orderId = $this->getRequest()->getParam('order_id');
122
+ /** @var $order Mage_Sales_Model_Order */
123
+ $order = Mage::getModel('sales/order')->load($orderId);
124
+ if (!$order->getEmagOrderId()) {
125
+ $this->_getSession()->addError('Not an eMAG order!');
126
+ $this->_redirect('*/*/view', array('_current' => true));
127
+ return;
128
+ }
129
+
130
+ try {
131
+ /** @var $order Innobyte_EmagMarketplace_Model_Order_Convert_Magento */
132
+ $order = Mage::getModel('innobyte_emag_marketplace/order_convert_magento');
133
+ $order->setOrderId($orderId);
134
+ $order->setStatus($status);
135
+ $order->convert();
136
+
137
+ $this->_getSession()->addSuccess(
138
+ $this->_getHelper()->__('Order successfully synced with eMAG.')
139
+ );
140
+ } catch (Exception $e) {
141
+ $this->_getSession()->addError(
142
+ $this->_getHelper()->__($e->getMessage())
143
+ );
144
+ }
145
+
146
+ $this->_redirect('*/*/view', array('_current' => true));
147
+ }
148
+
149
+ /**
150
+ * Acl check for admin
151
+ *
152
+ * @return bool
153
+ */
154
+ protected function _isAllowed()
155
+ {
156
+ $action = strtolower($this->getRequest()->getActionName());
157
+ switch ($action) {
158
+ case 'emagacknowledge':
159
+ $aclResource = 'sales/order/actions/emag_acknowledge';
160
+ break;
161
+ case 'emagprepare':
162
+ $aclResource = 'sales/order/actions/emag_prepare';
163
+ break;
164
+ case 'emagcancel':
165
+ $aclResource = 'sales/order/actions/emag_cancel';
166
+ break;
167
+ default:
168
+ $aclResource = 'sales/order';
169
+ break;
170
+ }
171
+
172
+ return Mage::getSingleton('admin/session')->isAllowed($aclResource);
173
+ }
174
+
175
+ }
app/code/local/Innobyte/EmagMarketplace/controllers/InvoiceController.php ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Innobyte_EmagMarketplace_InvoiceController
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ */
11
+ class Innobyte_EmagMarketplace_InvoiceController extends Mage_Core_Controller_Front_Action
12
+ {
13
+
14
+ /**
15
+ * Download invoice
16
+ */
17
+ public function downloadAction()
18
+ {
19
+ $storeId = $this->getRequest()->getParam('store');
20
+ if (!$this->_isAllowed($storeId)) {
21
+ die('Access Denied');
22
+ }
23
+
24
+ $invoiceId = Mage::helper('core')->decrypt($this->getRequest()->getParam('invoice'));
25
+ $type = Mage::helper('core')->decrypt($this->getRequest()->getParam('type'));
26
+
27
+ $data = array();
28
+ if ($type == Innobyte_EmagMarketplace_Model_Sales_Invoice::THIRD_PARTY_INVOICE) {
29
+ $data = $this->_getThirdPartyInvoiceData($invoiceId);
30
+ } elseif ($type == Mage_Sales_Model_Order::ACTION_FLAG_INVOICE) {
31
+ $data = $this->_getMagentoInvoiceData($invoiceId);
32
+ } elseif ($type == Mage_Sales_Model_Order::ACTION_FLAG_CREDITMEMO) {
33
+ $data = $this->_getMagentoCreditmemoData($invoiceId);
34
+ }
35
+
36
+ if (empty($data)) {
37
+ die('Could not read invoice');
38
+ }
39
+
40
+ header('Content-Transfer-Encoding: binary');
41
+ header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($data['path'])) . ' GMT');
42
+ header('Accept-Ranges: bytes');
43
+ header('Content-Length: ' . filesize($data['path']));
44
+ header('Content-Encoding: none');
45
+ header('Content-Type: application/pdf');
46
+ header('Content-Disposition: attachment; filename=' . $data['filename']);
47
+ readfile($data['path']);
48
+ }
49
+
50
+ /**
51
+ * Check if url is allowed from current IP Address
52
+ *
53
+ * @param int $storeId
54
+ * @return bool
55
+ */
56
+ protected function _isAllowed($storeId)
57
+ {
58
+ $ipAddress = Mage::helper('core/http')->getRemoteAddr();
59
+ $allowedIpAddresses = Mage::helper('innobyte_emag_marketplace')->getAllowedIpAddresses($storeId);
60
+ if (in_array($ipAddress, $allowedIpAddresses)) {
61
+ return true;
62
+ }
63
+
64
+ return false;
65
+ }
66
+
67
+ /**
68
+ * Get third party invoice data
69
+ *
70
+ * @param $invoiceId
71
+ * @return array
72
+ */
73
+ protected function _getThirdPartyInvoiceData($invoiceId)
74
+ {
75
+ /** @var $invoice Innobyte_EmagMarketplace_Model_Sales_Invoice */
76
+ $invoice = Mage::getModel('innobyte_emag_marketplace/sales_invoice')->load($invoiceId);
77
+
78
+ $data = array();
79
+ if ($invoice->getId()) {
80
+ $data = array(
81
+ 'path' => $invoice->getInvoiceBasePath(),
82
+ 'filename' => $invoice->getEmagInvoiceName()
83
+ );
84
+ }
85
+
86
+ return $data;
87
+ }
88
+
89
+ /**
90
+ * Get magento invoice data
91
+ *
92
+ * @param $invoiceId
93
+ * @return array
94
+ */
95
+ protected function _getMagentoInvoiceData($invoiceId)
96
+ {
97
+ /** @var $invoice Mage_Sales_Model_Order_Invoice */
98
+ $invoice = Mage::getModel('sales/order_invoice')->load($invoiceId);
99
+ /** @var $model Innobyte_EmagMarketplace_Model_Order_Convert_Magento */
100
+ $model = Mage::getModel('innobyte_emag_marketplace/order_convert_magento');
101
+
102
+ $data = array();
103
+ if ($invoice->getId()) {
104
+ $data = array(
105
+ 'path' => $model->getInvoiceBaseDirectory(),
106
+ 'filename' => $model->getInvoiceFileName($invoice, Mage_Sales_Model_Order::ACTION_FLAG_CREDITMEMO)
107
+ );
108
+ }
109
+
110
+ return $data;
111
+ }
112
+
113
+ /**
114
+ * Get credit memo invoice data
115
+ *
116
+ * @param $creditmemoId
117
+ * @return array
118
+ */
119
+ protected function _getMagentoCreditmemoData($creditmemoId)
120
+ {
121
+ /** @var $creditmemo Mage_Sales_Model_Order_Creditmemo */
122
+ $creditmemo = Mage::getModel('sales/order_creditmemo')->load($creditmemoId);
123
+ /** @var $model Innobyte_EmagMarketplace_Model_Order_Convert_Magento */
124
+ $model = Mage::getModel('innobyte_emag_marketplace/order_convert_magento');
125
+
126
+ $data = array();
127
+ if ($creditmemo->getId()) {
128
+ $data = array(
129
+ 'path' => $model->getCreditmemoBaseDirectory(),
130
+ 'filename' => $model->getInvoiceFileName($creditmemo, Mage_Sales_Model_Order::ACTION_FLAG_CREDITMEMO)
131
+ );
132
+ }
133
+ return $data;
134
+ }
135
+
136
+ }
app/code/local/Innobyte/EmagMarketplace/data/innobyte_emag_marketplace_setup/data-install-1.0.0.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ //eMAG statuses
4
+ $statuses = array(
5
+ 'emag_canceled' => 'eMAG - Canceled ',
6
+ 'emag_new' => 'eMAG - New',
7
+ 'emag_in_progress' => 'eMAG - In progress',
8
+ 'emag_prepared' => 'eMAG - Prepared',
9
+ 'emag_finalized' => 'eMAG - Finalized',
10
+ 'emag_returned' => 'eMAG - Returned'
11
+ );
12
+
13
+ // state assignment
14
+ $assignedState = array(
15
+ 'emag_new' => 'new',
16
+ 'emag_in_progress' => 'processing',
17
+ 'emag_prepared' => 'processing',
18
+ 'emag_finalized' => 'processing',
19
+ 'emag_canceled' => 'processing',
20
+ 'emag_returned' => 'closed'
21
+ );
22
+
23
+ foreach ($statuses as $code => $label) {
24
+ /** @var $status Mage_Sales_Model_Order_Status */
25
+ $status = Mage::getModel('sales/order_status')->load($code, 'status');
26
+ if ($status->getStatus()) {
27
+ continue;
28
+ }
29
+ // save first then assign state (state table has foreign key on status)
30
+ $status->setStatus($code);
31
+ $status->setLabel($label);
32
+ $status->save();
33
+
34
+ $status = Mage::getModel('sales/order_status')->load($code, 'status');
35
+ $status->assignState($assignedState[$code]);
36
+ $status->setIsDefault(0);
37
+ $status->save();
38
+ }
app/code/local/Innobyte/EmagMarketplace/docs/eMAG Markeplace API documentation v3.6.docx ADDED
Binary file
app/code/local/Innobyte/EmagMarketplace/etc/adminhtml.xml ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ /**
4
+ * Adminhtml config file.
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ *
9
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
10
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
11
+ */
12
+ -->
13
+
14
+ <config>
15
+ <menu>
16
+ <innobyte_emag_marketplace module="innobyte_emag_marketplace" translate="title">
17
+ <title>eMAG Marketplace</title>
18
+ <sort_order>200</sort_order>
19
+ <children>
20
+ <category translate="title">
21
+ <title>Categories</title>
22
+ <sort_order>10</sort_order>
23
+ <action>adminhtml/emag_category/index</action>
24
+ </category>
25
+ <vat translate="title">
26
+ <title>VATs</title>
27
+ <sort_order>15</sort_order>
28
+ <action>adminhtml/emag_vat/index</action>
29
+ </vat>
30
+ <localities translate="title">
31
+ <title>Localities</title>
32
+ <sort_order>20</sort_order>
33
+ <action>adminhtml/emag_locality/index</action>
34
+ </localities>
35
+ <settings translate="title">
36
+ <title>Settings</title>
37
+ <sort_order>25</sort_order>
38
+ <action>adminhtml/system_config/edit/section/Innobyte_EmagMarketplace</action>
39
+ </settings>
40
+ </children>
41
+ </innobyte_emag_marketplace>
42
+ </menu>
43
+
44
+ <acl>
45
+ <all>
46
+ <title>Allow Everything</title>
47
+ </all>
48
+ <resources>
49
+ <admin>
50
+ <children>
51
+ <sales translate="title" module="sales">
52
+ <children>
53
+ <order translate="title">
54
+ <children>
55
+ <actions translate="title">
56
+ <children>
57
+ <emag_upload_invoice translate="title"><title>eMAG Upload Invoice</title></emag_upload_invoice>
58
+ <emag_acknowledge translate="title"><title>eMAG Acknowledge</title></emag_acknowledge>
59
+ <emag_prepare translate="title"><title>eMAG Prepared</title></emag_prepare>
60
+ <emag_cancel translate="title"><title>eMAG Cancel</title></emag_cancel>
61
+ </children>
62
+ </actions>
63
+ </children>
64
+ </order>
65
+ </children>
66
+ </sales>
67
+
68
+ <innobyte_emag_marketplace module="innobyte_emag_marketplace" translate="title">
69
+ <title>eMAG Marketplace</title>
70
+ <children>
71
+ <category translate="title" module="innobyte_emag_marketplace">
72
+ <title>Categories</title>
73
+ <sort_order>10</sort_order>
74
+ </category>
75
+ <locality translate="title" module="innobyte_emag_marketplace">
76
+ <title>Localities</title>
77
+ <sort_order>20</sort_order>
78
+ </locality>
79
+ <vat translate="title" module="innobyte_emag_marketplace">
80
+ <title>VATs</title>
81
+ <sort_order>30</sort_order>
82
+ </vat>
83
+ <vouchers translate="title" module="innobyte_emag_marketplace">
84
+ <title>Vouchers</title>
85
+ <sort_order>40</sort_order>
86
+ </vouchers>
87
+ </children>
88
+ </innobyte_emag_marketplace>
89
+ <system>
90
+ <children>
91
+ <config>
92
+ <children>
93
+ <Innobyte_EmagMarketplace translate="title" module="innobyte_emag_marketplace">
94
+ <title>eMAG Marketplace</title>
95
+ <sort_order>10</sort_order>
96
+ </Innobyte_EmagMarketplace>
97
+ </children>
98
+ </config>
99
+ </children>
100
+ </system>
101
+ </children>
102
+ </admin>
103
+ </resources>
104
+ </acl>
105
+ </config>
app/code/local/Innobyte/EmagMarketplace/etc/config.xml ADDED
@@ -0,0 +1,564 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <modules>
3
+ <Innobyte_EmagMarketplace>
4
+ <version>1.0.0</version>
5
+ </Innobyte_EmagMarketplace>
6
+ </modules>
7
+ <global>
8
+ <blocks>
9
+ <innobyte_emag_marketplace>
10
+ <class>Innobyte_EmagMarketplace_Block</class>
11
+ </innobyte_emag_marketplace>
12
+ <adminhtml>
13
+ <rewrite>
14
+ <catalog_product_edit>Innobyte_EmagMarketplace_Block_Adminhtml_Catalog_Product_Edit</catalog_product_edit>
15
+ </rewrite>
16
+ </adminhtml>
17
+ </blocks>
18
+ <helpers>
19
+ <innobyte_emag_marketplace>
20
+ <class>Innobyte_EmagMarketplace_Helper</class>
21
+ </innobyte_emag_marketplace>
22
+ </helpers>
23
+ <models>
24
+ <innobyte_emag_marketplace>
25
+ <class>Innobyte_EmagMarketplace_Model</class>
26
+ <resourceModel>innobyte_emag_marketplace_resource</resourceModel>
27
+ </innobyte_emag_marketplace>
28
+ <customer>
29
+ <rewrite>
30
+ <form>Innobyte_EmagMarketplace_Model_Customer_Form</form>
31
+ </rewrite>
32
+ </customer>
33
+ <sales>
34
+ <rewrite>
35
+ <order_status>Innobyte_EmagMarketplace_Model_Sales_Order_Status</order_status>
36
+ </rewrite>
37
+ </sales>
38
+ <sales_resource>
39
+ <order_item_collection>Innobyte_EmagMarketplace_Model_Resource_Sales_Order_Item_Collection</order_item_collection>
40
+ </sales_resource>
41
+
42
+ <innobyte_emag_marketplace_resource>
43
+ <class>Innobyte_EmagMarketplace_Model_Resource</class>
44
+ <entities>
45
+ <sales_quote>
46
+ <table>innobyte_emag_marketplace_sales_flat_quote</table>
47
+ </sales_quote>
48
+ <sales_order>
49
+ <table>innobyte_emag_marketplace_sales_flat_order</table>
50
+ </sales_order>
51
+ <sales_quote_voucher>
52
+ <table>innobyte_emag_marketplace_sales_flat_quote_voucher</table>
53
+ </sales_quote_voucher>
54
+ <sales_order_voucher>
55
+ <table>innobyte_emag_marketplace_sales_flat_order_voucher</table>
56
+ </sales_order_voucher>
57
+ <sales_invoice>
58
+ <table>innobyte_emag_marketplace_sales_flat_invoice</table>
59
+ </sales_invoice>
60
+ <sales_quote_address>
61
+ <table>innobyte_emag_marketplace_sales_flat_quote_address</table>
62
+ </sales_quote_address>
63
+ <sales_order_address>
64
+ <table>innobyte_emag_marketplace_sales_flat_order_address</table>
65
+ </sales_order_address>
66
+ <sales_order_item>
67
+ <table>innobyte_emag_marketplace_sales_flat_order_item</table>
68
+ </sales_order_item>
69
+ <category>
70
+ <table>innobyte_emag_marketplace_category</table>
71
+ </category>
72
+ <category_characteristic>
73
+ <table>innobyte_emag_marketplace_category_characteristic</table>
74
+ </category_characteristic>
75
+ <category_familytype>
76
+ <table>innobyte_emag_marketplace_category_familytype</table>
77
+ </category_familytype>
78
+ <category_familytype_characteristic>
79
+ <table>innobyte_emag_marketplace_category_familytype_characteristic</table>
80
+ </category_familytype_characteristic>
81
+ <product>
82
+ <table>innobyte_emag_marketplace_product</table>
83
+ </product>
84
+ <product_barcode>
85
+ <table>innobyte_emag_marketplace_product_barcode</table>
86
+ </product_barcode>
87
+ <product_cat_characteristic>
88
+ <table>innobyte_emag_marketplace_product_cat_characteristic</table>
89
+ </product_cat_characteristic>
90
+ <vat>
91
+ <table>innobyte_emag_marketplace_vat</table>
92
+ </vat>
93
+ <locality>
94
+ <table>innobyte_emag_marketplace_locality</table>
95
+ </locality>
96
+ </entities>
97
+ </innobyte_emag_marketplace_resource>
98
+ </models>
99
+ <resources>
100
+ <innobyte_emag_marketplace_setup>
101
+ <setup>
102
+ <module>Innobyte_EmagMarketplace</module>
103
+ <class>Mage_Sales_Model_Resource_Setup</class>
104
+ </setup>
105
+ <connection>
106
+ <use>core_setup</use>
107
+ </connection>
108
+ </innobyte_emag_marketplace_setup>
109
+ <innobyte_emag_marketplace_write>
110
+ <connection>
111
+ <use>core_write</use>
112
+ </connection>
113
+ </innobyte_emag_marketplace_write>
114
+ <innobyte_emag_marketplace_read>
115
+ <connection>
116
+ <use>core_read</use>
117
+ </connection>
118
+ </innobyte_emag_marketplace_read>
119
+ </resources>
120
+ <sales>
121
+ <quote>
122
+ <totals>
123
+ <emag_vouchers>
124
+ <class>innobyte_emag_marketplace/sales_quote_address_total_voucher</class>
125
+ <after>subtotal</after>
126
+ <admin_renderer>innobyte_emag_marketplace/adminhtml_sales_order_create_totals_voucher</admin_renderer>
127
+ </emag_vouchers>
128
+ </totals>
129
+ </quote>
130
+ <order_invoice>
131
+ <totals>
132
+ <emag_vouchers>
133
+ <class>innobyte_emag_marketplace/sales_order_invoice_total</class>
134
+ <after>grand_total</after>
135
+ </emag_vouchers>
136
+ </totals>
137
+ </order_invoice>
138
+ <order_creditmemo>
139
+ <totals>
140
+ <emag_vouchers>
141
+ <class>innobyte_emag_marketplace/sales_order_creditmemo_total</class>
142
+ <after>weee,discount,tax,grand_total</after>
143
+ </emag_vouchers>
144
+ </totals>
145
+ </order_creditmemo>
146
+ </sales>
147
+ <pdf>
148
+ <totals>
149
+ <emag_voucher translate="title">
150
+ <title>eMAG Voucher</title>
151
+ <source_field>emag_vouchers</source_field>
152
+ <model>Innobyte_EmagMarketplace_Model_Invoice_Pdf_Total_Voucher</model>
153
+ <font_size>7</font_size>
154
+ <display_zero>0</display_zero>
155
+ <sort_order>200</sort_order>
156
+ </emag_voucher>
157
+ </totals>
158
+ </pdf>
159
+ <events>
160
+ <sales_order_invoice_register>
161
+ <observers>
162
+ <innobyte_emag_marketplace>
163
+ <class>innobyte_emag_marketplace/sales_observer</class>
164
+ <method>invoiceRegister</method>
165
+ </innobyte_emag_marketplace>
166
+ </observers>
167
+ </sales_order_invoice_register>
168
+ <sales_order_place_after>
169
+ <observers>
170
+ <innobyte_emag_marketplace>
171
+ <class>innobyte_emag_marketplace/sales_observer</class>
172
+ <method>orderAfterPlace</method>
173
+ </innobyte_emag_marketplace>
174
+ </observers>
175
+ </sales_order_place_after>
176
+ <sales_order_save_before>
177
+ <observers>
178
+ <innobyte_emag_marketplace>
179
+ <class>innobyte_emag_marketplace/sales_observer</class>
180
+ <method>orderBeforeSave</method>
181
+ </innobyte_emag_marketplace>
182
+ </observers>
183
+ </sales_order_save_before>
184
+ <sales_order_status_load_after>
185
+ <observers>
186
+ <innobyte_emag_marketplace>
187
+ <class>innobyte_emag_marketplace/sales_observer</class>
188
+ <method>updateOrderStatus</method>
189
+ </innobyte_emag_marketplace>
190
+ </observers>
191
+ </sales_order_status_load_after>
192
+
193
+ <!--ENTITY AFTER SAVE-->
194
+ <sales_quote_save_after>
195
+ <observers>
196
+ <innobyte_emag_marketplace>
197
+ <class>innobyte_emag_marketplace/sales_observer</class>
198
+ <method>quoteAfterSave</method>
199
+ </innobyte_emag_marketplace>
200
+ </observers>
201
+ </sales_quote_save_after>
202
+ <sales_order_save_after>
203
+ <observers>
204
+ <innobyte_emag_marketplace>
205
+ <class>innobyte_emag_marketplace/sales_observer</class>
206
+ <method>orderAfterSave</method>
207
+ </innobyte_emag_marketplace>
208
+ </observers>
209
+ </sales_order_save_after>
210
+ <sales_order_item_save_after>
211
+ <observers>
212
+ <innobyte_emag_marketplace>
213
+ <class>innobyte_emag_marketplace/sales_observer</class>
214
+ <method>orderItemAfterSave</method>
215
+ </innobyte_emag_marketplace>
216
+ </observers>
217
+ </sales_order_item_save_after>
218
+
219
+ <!--ENTITY AFTER LOAD-->
220
+ <sales_quote_load_after>
221
+ <observers>
222
+ <innobyte_emag_marketplace>
223
+ <class>innobyte_emag_marketplace/sales_observer</class>
224
+ <method>quoteAfterLoad</method>
225
+ </innobyte_emag_marketplace>
226
+ </observers>
227
+ </sales_quote_load_after>
228
+ <sales_order_load_after>
229
+ <observers>
230
+ <innobyte_emag_marketplace>
231
+ <class>innobyte_emag_marketplace/sales_observer</class>
232
+ <method>orderAfterLoad</method>
233
+ </innobyte_emag_marketplace>
234
+ </observers>
235
+ </sales_order_load_after>
236
+ <sales_order_invoice_load_after>
237
+ <observers>
238
+ <innobyte_emag_marketplace>
239
+ <class>innobyte_emag_marketplace/sales_observer</class>
240
+ <method>invoiceAfterLoad</method>
241
+ </innobyte_emag_marketplace>
242
+ </observers>
243
+ </sales_order_invoice_load_after>
244
+ <sales_order_creditmemo_load_after>
245
+ <observers>
246
+ <innobyte_emag_marketplace>
247
+ <class>innobyte_emag_marketplace/sales_observer</class>
248
+ <method>creditmemoAfterLoad</method>
249
+ </innobyte_emag_marketplace>
250
+ </observers>
251
+ </sales_order_creditmemo_load_after>
252
+
253
+ <!--ENTITY ADDRESS AFTER SAVE-->
254
+ <sales_quote_address_save_after>
255
+ <observers>
256
+ <innobyte_emag_marketplace>
257
+ <class>innobyte_emag_marketplace/sales_observer</class>
258
+ <method>quoteAddressAfterSave</method>
259
+ </innobyte_emag_marketplace>
260
+ </observers>
261
+ </sales_quote_address_save_after>
262
+ <sales_order_address_save_after>
263
+ <observers>
264
+ <innobyte_emag_marketplace>
265
+ <class>innobyte_emag_marketplace/sales_observer</class>
266
+ <method>orderAddressAfterSave</method>
267
+ </innobyte_emag_marketplace>
268
+ </observers>
269
+ </sales_order_address_save_after>
270
+
271
+ <!--ENTITY ITEM COLLECTION AFTER LOAD-->
272
+ <sales_order_item_collection_load_after>
273
+ <observers>
274
+ <innobyte_emag_marketplace>
275
+ <class>innobyte_emag_marketplace/sales_observer</class>
276
+ <method>orderItemCollectionAfterLoad</method>
277
+ </innobyte_emag_marketplace>
278
+ </observers>
279
+ </sales_order_item_collection_load_after>
280
+
281
+ <!--ENTITY ADDRESS ATTRIBUTE COLLECTION AFTER LOAD-->
282
+ <sales_quote_address_collection_load_after>
283
+ <observers>
284
+ <innobyte_emag_marketplace>
285
+ <class>innobyte_emag_marketplace/sales_observer</class>
286
+ <method>quoteAddressCollectionAfterLoad</method>
287
+ </innobyte_emag_marketplace>
288
+ </observers>
289
+ </sales_quote_address_collection_load_after>
290
+ <sales_order_address_collection_load_after>
291
+ <observers>
292
+ <innobyte_emag_marketplace>
293
+ <class>innobyte_emag_marketplace/sales_observer</class>
294
+ <method>orderAddressCollectionAfterLoad</method>
295
+ </innobyte_emag_marketplace>
296
+ </observers>
297
+ </sales_order_address_collection_load_after>
298
+
299
+ <!--CONVERT CUSTOMER-->
300
+ <core_copy_fieldset_customer_account_to_quote>
301
+ <observers>
302
+ <innobyte_emag_marketplace>
303
+ <class>innobyte_emag_marketplace/sales_observer</class>
304
+ <method>convertCustomerAccountToQuote</method>
305
+ </innobyte_emag_marketplace>
306
+ </observers>
307
+ </core_copy_fieldset_customer_account_to_quote>
308
+ <core_copy_fieldset_customer_address_to_quote_address>
309
+ <observers>
310
+ <innobyte_emag_marketplace>
311
+ <class>innobyte_emag_marketplace/sales_observer</class>
312
+ <method>convertCustomerAddressToQuoteAddress</method>
313
+ </innobyte_emag_marketplace>
314
+ </observers>
315
+ </core_copy_fieldset_customer_address_to_quote_address>
316
+
317
+ <!--CONVERT QUOTE-->
318
+ <core_copy_fieldset_sales_convert_quote_to_order>
319
+ <observers>
320
+ <innobyte_emag_marketplace>
321
+ <class>innobyte_emag_marketplace/sales_observer</class>
322
+ <method>convertSalesConvertQuoteToOrder</method>
323
+ </innobyte_emag_marketplace>
324
+ </observers>
325
+ </core_copy_fieldset_sales_convert_quote_to_order>
326
+ <core_copy_fieldset_sales_convert_quote_address_to_order_address>
327
+ <observers>
328
+ <innobyte_emag_marketplace>
329
+ <class>innobyte_emag_marketplace/sales_observer</class>
330
+ <method>convertSalesConvertQuoteAddressToOrderAddress</method>
331
+ </innobyte_emag_marketplace>
332
+ </observers>
333
+ </core_copy_fieldset_sales_convert_quote_address_to_order_address>
334
+ <core_copy_fieldset_sales_convert_quote_address_to_customer_address>
335
+ <observers>
336
+ <innobyte_emag_marketplace>
337
+ <class>innobyte_emag_marketplace/sales_observer</class>
338
+ <method>convertQuoteAddressToCustomerAddress</method>
339
+ </innobyte_emag_marketplace>
340
+ </observers>
341
+ </core_copy_fieldset_sales_convert_quote_address_to_customer_address>
342
+ <core_copy_fieldset_checkout_onepage_quote_to_customer>
343
+ <observers>
344
+ <innobyte_emag_marketplace>
345
+ <class>innobyte_emag_marketplace/sales_observer</class>
346
+ <method>convertCheckoutOnepageQuoteToCustomer</method>
347
+ </innobyte_emag_marketplace>
348
+ </observers>
349
+ </core_copy_fieldset_checkout_onepage_quote_to_customer>
350
+
351
+ <!--CONVERT ORDER-->
352
+ <core_copy_fieldset_sales_copy_order_to_edit>
353
+ <observers>
354
+ <innobyte_emag_marketplace>
355
+ <class>innobyte_emag_marketplace/sales_observer</class>
356
+ <method>convertSalesCopyOrderToEdit</method>
357
+ </innobyte_emag_marketplace>
358
+ <innobyte_emag_marketplace_vouchers>
359
+ <class>innobyte_emag_marketplace/sales_observer</class>
360
+ <method>convertSalesCopyOrderVoucherToEdit</method>
361
+ </innobyte_emag_marketplace_vouchers>
362
+ </observers>
363
+ </core_copy_fieldset_sales_copy_order_to_edit>
364
+ <core_copy_fieldset_sales_convert_order_to_invoice>
365
+ <observers>
366
+ <innobyte_emag_marketplace>
367
+ <class>innobyte_emag_marketplace/sales_observer</class>
368
+ <method>convertSalesCopyOrderToEdit</method>
369
+ </innobyte_emag_marketplace>
370
+ <innobyte_emag_marketplace_vouchers>
371
+ <class>innobyte_emag_marketplace/sales_observer</class>
372
+ <method>convertSalesCopyOrderVoucherToEdit</method>
373
+ </innobyte_emag_marketplace_vouchers>
374
+ </observers>
375
+ </core_copy_fieldset_sales_convert_order_to_invoice>
376
+ <core_copy_fieldset_sales_convert_order_to_cm>
377
+ <observers>
378
+ <innobyte_emag_marketplace>
379
+ <class>innobyte_emag_marketplace/sales_observer</class>
380
+ <method>convertSalesCopyOrderToEdit</method>
381
+ </innobyte_emag_marketplace>
382
+ <innobyte_emag_marketplace_vouchers>
383
+ <class>innobyte_emag_marketplace/sales_observer</class>
384
+ <method>convertSalesCopyOrderVoucherToEdit</method>
385
+ </innobyte_emag_marketplace_vouchers>
386
+ </observers>
387
+ </core_copy_fieldset_sales_convert_order_to_cm>
388
+
389
+ <core_copy_fieldset_sales_copy_order_billing_address_to_order>
390
+ <observers>
391
+ <innobyte_emag_marketplace>
392
+ <class>innobyte_emag_marketplace/sales_observer</class>
393
+ <method>convertSalesCopyOrderBillingAddressToOrder</method>
394
+ </innobyte_emag_marketplace>
395
+ </observers>
396
+ </core_copy_fieldset_sales_copy_order_billing_address_to_order>
397
+ <core_copy_fieldset_sales_copy_order_shipping_address_to_order>
398
+ <observers>
399
+ <innobyte_emag_marketplace>
400
+ <class>innobyte_emag_marketplace/sales_observer</class>
401
+ <method>convertSalesCopyOrderShippingAddressToOrder</method>
402
+ </innobyte_emag_marketplace>
403
+ </observers>
404
+ </core_copy_fieldset_sales_copy_order_shipping_address_to_order>
405
+ </events>
406
+
407
+ <template>
408
+ <email>
409
+ <Innobyte_EmagMarketplace_general_settings_template translate="label" module="innobyte_emag_marketplace">
410
+ <label>Innobyte EmagMarketplace Order Sync Errors</label>
411
+ <file>innobyte/emag_marketplace/errors.html</file>
412
+ <type>html</type>
413
+ </Innobyte_EmagMarketplace_general_settings_template>
414
+ </email>
415
+ </template>
416
+ </global>
417
+ <admin>
418
+ <routers>
419
+ <adminhtml>
420
+ <args>
421
+ <modules>
422
+ <innobyte_emag_marketplace after="Mage_Adminhtml">Innobyte_EmagMarketplace_Adminhtml</innobyte_emag_marketplace>
423
+ </modules>
424
+ </args>
425
+ </adminhtml>
426
+ </routers>
427
+ </admin>
428
+ <adminhtml>
429
+ <events>
430
+ <adminhtml_widget_container_html_before>
431
+ <observers>
432
+ <innobyte_emag_marketplace>
433
+ <class>innobyte_emag_marketplace/sales_observer</class>
434
+ <type>singleton</type>
435
+ <method>addEmagButtonsToOrderView</method>
436
+ </innobyte_emag_marketplace>
437
+ </observers>
438
+ </adminhtml_widget_container_html_before>
439
+ <adminhtml_catalog_product_grid_prepare_massaction>
440
+ <observers>
441
+ <innobyte_emag_marketplace>
442
+ <class>innobyte_emag_marketplace/catalog_product_observer</class>
443
+ <type>singleton</type>
444
+ <method>addEmagProductMassActions</method>
445
+ </innobyte_emag_marketplace>
446
+ </observers>
447
+ </adminhtml_catalog_product_grid_prepare_massaction>
448
+ <catalog_product_save_after>
449
+ <observers>
450
+ <innobyte_emag_marketplace>
451
+ <class>innobyte_emag_marketplace/catalog_product_observer</class>
452
+ <type>singleton</type>
453
+ <method>saveProductEmagData</method>
454
+ </innobyte_emag_marketplace>
455
+ </observers>
456
+ </catalog_product_save_after>
457
+ <adminhtml_sales_order_create_process_data_before>
458
+ <observers>
459
+ <innobyte_emag_marketplace>
460
+ <class>innobyte_emag_marketplace/sales_observer</class>
461
+ <type>singleton</type>
462
+ <method>applyEmagShippingMethod</method>
463
+ </innobyte_emag_marketplace>
464
+ </observers>
465
+ </adminhtml_sales_order_create_process_data_before>
466
+ </events>
467
+ <layout>
468
+ <updates>
469
+ <innobyte_emag_marketplace>
470
+ <file>innobyte/emag_marketplace.xml</file>
471
+ </innobyte_emag_marketplace>
472
+ </updates>
473
+ </layout>
474
+ <translate>
475
+ <modules>
476
+ <Innobyte_EmagMarketplace>
477
+ <files>
478
+ <default>Innobyte_EmagMarketplace.csv</default>
479
+ </files>
480
+ </Innobyte_EmagMarketplace>
481
+ </modules>
482
+ </translate>
483
+ </adminhtml>
484
+ <frontend>
485
+ <routers>
486
+ <innobyte_emag_marketplace>
487
+ <use>standard</use>
488
+ <args>
489
+ <module>Innobyte_EmagMarketplace</module>
490
+ <frontName>marketplace</frontName>
491
+ </args>
492
+ </innobyte_emag_marketplace>
493
+ </routers>
494
+ </frontend>
495
+ <crontab>
496
+ <jobs>
497
+ <innobyte_emag_marketplace_cron>
498
+ <schedule>
499
+ <cron_expr>*/5 * * * *</cron_expr>
500
+ </schedule>
501
+ <run>
502
+ <model>innobyte_emag_marketplace/cron::someMethod</model>
503
+ </run>
504
+ </innobyte_emag_marketplace_cron>
505
+ </jobs>
506
+ </crontab>
507
+
508
+ <default>
509
+ <carriers>
510
+ <emagshipping>
511
+ <active>1</active>
512
+ <model>innobyte_emag_marketplace/shipping_carrier_emag</model>
513
+ <title>eMAG Shipping</title>
514
+ <name>eMAG Standard Delivery</name>
515
+ <sort_order>1</sort_order>
516
+ <sallowspecific>0</sallowspecific>
517
+ </emagshipping>
518
+ </carriers>
519
+
520
+ <payment>
521
+ <emag_banktransfer>
522
+ <active>1</active>
523
+ <title>eMAG Bank Transfer</title>
524
+ <model>innobyte_emag_marketplace/payment_method_banktransfer</model>
525
+ <order_status>emag_new</order_status>
526
+ <sort_order>1</sort_order>
527
+ </emag_banktransfer>
528
+ <emag_cashondelivery>
529
+ <active>1</active>
530
+ <title>eMAG Cash on Delivery</title>
531
+ <model>innobyte_emag_marketplace/payment_method_cashondelivery</model>
532
+ <order_status>emag_new</order_status>
533
+ <sort_order>2</sort_order>
534
+ </emag_cashondelivery>
535
+ <emag_cc>
536
+ <active>1</active>
537
+ <title>eMAG Credit Card</title>
538
+ <model>innobyte_emag_marketplace/payment_method_cc</model>
539
+ <order_status>emag_new</order_status>
540
+ <sort_order>3</sort_order>
541
+ </emag_cc>
542
+ <emag_unknown>
543
+ <active>1</active>
544
+ <title>eMAG Unknown</title>
545
+ <model>innobyte_emag_marketplace/payment_method_unknown</model>
546
+ <order_status>emag_new</order_status>
547
+ <sort_order>4</sort_order>
548
+ </emag_unknown>
549
+ </payment>
550
+
551
+ <Innobyte_EmagMarketplace>
552
+ <general_settings>
553
+ <template>Innobyte_EmagMarketplace_general_settings_template</template>
554
+ </general_settings>
555
+ <api_settings>
556
+ <password backend_model="adminhtml/system_config_backend_encrypted"/>
557
+ </api_settings>
558
+ </Innobyte_EmagMarketplace>
559
+
560
+ <!-- api call settings, can be overridden easely in modules that <depends> on this one -->
561
+ <innobyte_emag_marketplace_http_call_adapter>Zend_Http_Client_Adapter_Curl</innobyte_emag_marketplace_http_call_adapter>
562
+ <innobyte_emag_marketplace_http_call_timeout>40</innobyte_emag_marketplace_http_call_timeout>
563
+ </default>
564
+ </config>
app/code/local/Innobyte/EmagMarketplace/etc/jstranslator.xml ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ /**
4
+ * Javascript translated texts.
5
+ *
6
+ * @category Innobyte
7
+ * @package Innobyte_EmagMarketplace
8
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
9
+ */
10
+ -->
11
+ <jstranslator>
12
+ <inno-emag-mktp-error-occurred translate="message" module="innobyte_emag_marketplace">
13
+ <message>An error occurred. Please try again later.</message>
14
+ </inno-emag-mktp-error-occurred>
15
+ <inno-emag-mktp-remove-item translate="message" module="innobyte_emag_marketplace">
16
+ <message>Remove</message>
17
+ </inno-emag-mktp-remove-item>
18
+ <inno-emag-mktp-confirm-prod-send translate="message" module="innobyte_emag_marketplace">
19
+ <message>Please confirm product sending. All data that hasn't been saved will be lost.</message>
20
+ </inno-emag-mktp-confirm-prod-send>
21
+ <inno-emag-mktp-confirm-offer-send translate="message" module="innobyte_emag_marketplace">
22
+ <message>Please confirm offer sending. All data that hasn't been saved will be lost.</message>
23
+ </inno-emag-mktp-confirm-offer-send>
24
+ <inno-emag-mktp-confirm-offer-deactivation translate="message" module="innobyte_emag_marketplace">
25
+ <message>Please confirm offer deactivation. All data that hasn't been saved will be lost.</message>
26
+ </inno-emag-mktp-confirm-offer-deactivation>
27
+ <inno-emag-mktp-order-city-load translate="message" module="innobyte_emag_marketplace">
28
+ <message>Loading...</message>
29
+ </inno-emag-mktp-order-city-load>
30
+ <inno-emag-mktp-family-type translate="message" module="innobyte_emag_marketplace">
31
+ <message>Family Type</message>
32
+ </inno-emag-mktp-family-type>
33
+ <inno-emag-mktp-family-type-characteristic-note translate="message" module="innobyte_emag_marketplace">
34
+ <message>This attribute will have to be set on associated products individually</message>
35
+ </inno-emag-mktp-family-type-characteristic-note>
36
+ </jstranslator>
app/code/local/Innobyte/EmagMarketplace/etc/system.xml ADDED
@@ -0,0 +1,468 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <Innobyte_EmagMarketplace translate="label" module="innobyte_emag_marketplace">
5
+ <label>eMAG Marketplace</label>
6
+ <tab>innobyte_core</tab>
7
+ <frontend_type>text</frontend_type>
8
+ <sort_order>20</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>1</show_in_store>
12
+ <groups>
13
+ <license translate="label" module="innobyte_core">
14
+ <label>License</label>
15
+ <frontend_type>text</frontend_type>
16
+ <frontend_model>innobyte_core/system_config_form_fieldset_extensions</frontend_model>
17
+ <sort_order>1</sort_order>
18
+ <show_in_default>1</show_in_default>
19
+ <show_in_website>1</show_in_website>
20
+ <show_in_store>0</show_in_store>
21
+ <fields>
22
+ <ar translate="label">
23
+ <label>ar</label>
24
+ <frontend_type>text</frontend_type>
25
+ <sort_order>20</sort_order>
26
+ <show_in_default>0</show_in_default>
27
+ <show_in_website>0</show_in_website>
28
+ <show_in_store>0</show_in_store>
29
+ </ar>
30
+ <websites translate="label">
31
+ <label>websites</label>
32
+ <frontend_type>text</frontend_type>
33
+ <sort_order>20</sort_order>
34
+ <show_in_default>0</show_in_default>
35
+ <show_in_website>0</show_in_website>
36
+ <show_in_store>0</show_in_store>
37
+ </websites>
38
+ <time translate="label">
39
+ <label>Time</label>
40
+ <frontend_type>text</frontend_type>
41
+ <sort_order>20</sort_order>
42
+ <show_in_default>0</show_in_default>
43
+ <show_in_website>0</show_in_website>
44
+ <show_in_store>0</show_in_store>
45
+ </time>
46
+ <installed translate="label">
47
+ <label>Installed</label>
48
+ <frontend_type>text</frontend_type>
49
+ <sort_order>20</sort_order>
50
+ <show_in_default>0</show_in_default>
51
+ <show_in_website>0</show_in_website>
52
+ <show_in_store>0</show_in_store>
53
+ </installed>
54
+ <count translate="label">
55
+ <label>Installed</label>
56
+ <frontend_type>text</frontend_type>
57
+ <sort_order>20</sort_order>
58
+ <show_in_default>0</show_in_default>
59
+ <show_in_website>0</show_in_website>
60
+ <show_in_store>0</show_in_store>
61
+ </count>
62
+ <key translate="label">
63
+ <label>License key</label>
64
+ <frontend_type>text</frontend_type>
65
+ <sort_order>20</sort_order>
66
+ <show_in_default>1</show_in_default>
67
+ <show_in_website>1</show_in_website>
68
+ <show_in_store>0</show_in_store>
69
+ </key>
70
+ <enabled translate="label">
71
+ <label>Enable Extension</label>
72
+ <frontend_type>select</frontend_type>
73
+ <frontend_model>innobyte_core/system_config_form_renderer_field</frontend_model>
74
+ <source_model>innobyte_core/source_config_enabledisable</source_model>
75
+ <sort_order>10</sort_order>
76
+ <show_in_default>1</show_in_default>
77
+ <show_in_website>1</show_in_website>
78
+ <show_in_store>0</show_in_store>
79
+ <hint>Innobyte_EmagMarketplace</hint>
80
+ </enabled>
81
+ </fields>
82
+ </license>
83
+ <general_settings translate="label" module="innobyte_emag_marketplace">
84
+ <label>General Settings</label>
85
+ <frontend_type>text</frontend_type>
86
+ <sort_order>10</sort_order>
87
+ <show_in_default>1</show_in_default>
88
+ <show_in_website>0</show_in_website>
89
+ <show_in_store>1</show_in_store>
90
+ <fields>
91
+ <active translate="label comment">
92
+ <label>Enable</label>
93
+ <frontend_type>select</frontend_type>
94
+ <source_model>adminhtml/system_config_source_yesno</source_model>
95
+ <sort_order>5</sort_order>
96
+ <show_in_default>1</show_in_default>
97
+ <show_in_website>0</show_in_website>
98
+ <show_in_store>1</show_in_store>
99
+ <comment><![CDATA[Enable/Disable extension.]]></comment>
100
+ </active>
101
+ <debug translate="label comment">
102
+ <label>Debug</label>
103
+ <frontend_type>select</frontend_type>
104
+ <source_model>adminhtml/system_config_source_yesno</source_model>
105
+ <sort_order>10</sort_order>
106
+ <show_in_default>1</show_in_default>
107
+ <show_in_website>0</show_in_website>
108
+ <show_in_store>1</show_in_store>
109
+ <comment><![CDATA[Enable debug mode.]]></comment>
110
+ </debug>
111
+ <domain translate="label comment">
112
+ <label>eMAG Domain</label>
113
+ <frontend_type>text</frontend_type>
114
+ <sort_order>15</sort_order>
115
+ <show_in_default>0</show_in_default>
116
+ <show_in_website>0</show_in_website>
117
+ <show_in_store>1</show_in_store>
118
+ <comment><![CDATA[eMAG Marketplace domain in your country. (Ex: emag.ro)]]></comment>
119
+ </domain>
120
+ <allowed_ip_addresses>
121
+ <label>Allowed IP Addresses</label>
122
+ <frontend_type>text</frontend_type>
123
+ <sort_order>18</sort_order>
124
+ <show_in_default>0</show_in_default>
125
+ <show_in_website>0</show_in_website>
126
+ <show_in_store>1</show_in_store>
127
+ <comment><![CDATA[List of allowed IP Addresses that can access invoice directories. Separated by comma.]]></comment>
128
+ </allowed_ip_addresses>
129
+ <email>
130
+ <label>Error Reporting Email</label>
131
+ <frontend_type>text</frontend_type>
132
+ <sort_order>20</sort_order>
133
+ <show_in_default>0</show_in_default>
134
+ <show_in_website>0</show_in_website>
135
+ <show_in_store>1</show_in_store>
136
+ <validate>validate-email</validate>
137
+ <comment><![CDATA[Email address that will receive eMAG order sync errors.]]></comment>
138
+ </email>
139
+ <template translate="label comment">
140
+ <label>Error Reporting Email Template</label>
141
+ <frontend_type>select</frontend_type>
142
+ <source_model>adminhtml/system_config_source_email_template</source_model>
143
+ <sort_order>25</sort_order>
144
+ <show_in_default>0</show_in_default>
145
+ <show_in_website>0</show_in_website>
146
+ <show_in_store>1</show_in_store>
147
+ <comment><![CDATA[Set error reporting email template.]]></comment>
148
+ </template>
149
+ <enable_limited_stock translate="label comment">
150
+ <label>Product offer availability "limited stock"</label>
151
+ <validate>validate-number</validate>
152
+ <frontend_type>select</frontend_type>
153
+ <source_model>adminhtml/system_config_source_yesno</source_model>
154
+ <sort_order>30</sort_order>
155
+ <show_in_default>0</show_in_default>
156
+ <show_in_website>0</show_in_website>
157
+ <show_in_store>1</show_in_store>
158
+ <comment><![CDATA[Enable/Disable availability status "limited stock" for a product.]]></comment>
159
+ </enable_limited_stock>
160
+ <limited_stock translate="label comment">
161
+ <label>Availability Limited Stock</label>
162
+ <validate>validate-number required-entry</validate>
163
+ <frontend_type>text</frontend_type>
164
+ <sort_order>35</sort_order>
165
+ <show_in_default>0</show_in_default>
166
+ <show_in_website>0</show_in_website>
167
+ <show_in_store>1</show_in_store>
168
+ <depends><enable_limited_stock>1</enable_limited_stock></depends>
169
+ <comment><![CDATA[Qty limit under which the product, if "in stock", should be considered as "limited stock"]]></comment>
170
+ </limited_stock>
171
+ <send_stock_qty translate="label comment">
172
+ <label>Send Product Offer Stock Qty</label>
173
+ <validate>validate-number</validate>
174
+ <frontend_type>select</frontend_type>
175
+ <source_model>adminhtml/system_config_source_yesno</source_model>
176
+ <sort_order>40</sort_order>
177
+ <show_in_default>0</show_in_default>
178
+ <show_in_website>0</show_in_website>
179
+ <show_in_store>1</show_in_store>
180
+ <comment><![CDATA[Send also magento real stock qty, not only availability flags as "limited stock", "in stock", "out of stock"]]></comment>
181
+ </send_stock_qty>
182
+ </fields>
183
+ </general_settings>
184
+ <api_settings translate="label" module="innobyte_emag_marketplace">
185
+ <label>Api Settings</label>
186
+ <frontend_type>text</frontend_type>
187
+ <sort_order>20</sort_order>
188
+ <show_in_default>1</show_in_default>
189
+ <show_in_website>0</show_in_website>
190
+ <show_in_store>1</show_in_store>
191
+ <fields>
192
+ <url translate="label comment">
193
+ <label>Api URL</label>
194
+ <frontend_type>text</frontend_type>
195
+ <sort_order>10</sort_order>
196
+ <show_in_default>0</show_in_default>
197
+ <show_in_website>0</show_in_website>
198
+ <show_in_store>1</show_in_store>
199
+ <comment><![CDATA[Api URL provided by eMAG.]]></comment>
200
+ <validate>validate-url</validate>
201
+ </url>
202
+ <username translate="label comment">
203
+ <label>Api Username</label>
204
+ <frontend_type>text</frontend_type>
205
+ <sort_order>20</sort_order>
206
+ <show_in_default>0</show_in_default>
207
+ <show_in_website>0</show_in_website>
208
+ <show_in_store>1</show_in_store>
209
+ <comment><![CDATA[Api username provided by eMAG.]]></comment>
210
+ </username>
211
+ <password translate="label comment">
212
+ <label>Api Password</label>
213
+ <frontend_type>password</frontend_type>
214
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
215
+ <sort_order>30</sort_order>
216
+ <show_in_default>0</show_in_default>
217
+ <show_in_website>0</show_in_website>
218
+ <show_in_store>1</show_in_store>
219
+ <comment><![CDATA[Api password provided by eMAG.]]></comment>
220
+ </password>
221
+ <code translate="label comment">
222
+ <label>Client Code</label>
223
+ <frontend_type>text</frontend_type>
224
+ <sort_order>40</sort_order>
225
+ <show_in_default>0</show_in_default>
226
+ <show_in_website>0</show_in_website>
227
+ <show_in_store>1</show_in_store>
228
+ <comment><![CDATA[Client code provided by eMAG.]]></comment>
229
+ </code>
230
+ </fields>
231
+ </api_settings>
232
+ <invoice_creditmemo_settings translate="label" module="innobyte_emag_marketplace">
233
+ <label>Invoice / Creditmemo Settings</label>
234
+ <frontend_type>text</frontend_type>
235
+ <sort_order>30</sort_order>
236
+ <show_in_default>0</show_in_default>
237
+ <show_in_website>0</show_in_website>
238
+ <show_in_store>1</show_in_store>
239
+ <fields>
240
+ <invoice_prefix translate="label comment">
241
+ <label>Invoice Prefix</label>
242
+ <frontend_type>text</frontend_type>
243
+ <backend_model>innobyte_emag_marketplace/system_config_backend_prefix_invoice
244
+ </backend_model>
245
+ <sort_order>10</sort_order>
246
+ <show_in_default>0</show_in_default>
247
+ <show_in_website>0</show_in_website>
248
+ <show_in_store>1</show_in_store>
249
+ <comment>
250
+ <![CDATA[Define invoice prefix. Leave blank to use Magento default invoice prefix. (Ex: PREFIX10000122) <br><strong>Note:</strong> <span style="color:orange">Maximum length 10 characters.</span>]]>
251
+ </comment>
252
+ <validate>validate-length maximum-length-10</validate>
253
+ </invoice_prefix>
254
+ <creditmemo_prefix translate="label comment">
255
+ <label>Creditmemo Prefix</label>
256
+ <frontend_type>text</frontend_type>
257
+ <backend_model>innobyte_emag_marketplace/system_config_backend_prefix_creditmemo
258
+ </backend_model>
259
+ <sort_order>20</sort_order>
260
+ <show_in_default>0</show_in_default>
261
+ <show_in_website>0</show_in_website>
262
+ <show_in_store>1</show_in_store>
263
+ <comment>
264
+ <![CDATA[Define creditmemo prefix. Leave blank to use Magento default creditmemo prefix. (Ex: PREFIX10000122) <br><strong>Note:</strong> <span style="color:orange">Maximum length 10 characters.</span>]]>
265
+ </comment>
266
+ <validate>validate-length maximum-length-10</validate>
267
+ </creditmemo_prefix>
268
+ </fields>
269
+ </invoice_creditmemo_settings>
270
+ <shipping_settings translate="label" module="innobyte_emag_marketplace">
271
+ <label>Shipping Settings</label>
272
+ <frontend_type>text</frontend_type>
273
+ <sort_order>40</sort_order>
274
+ <show_in_default>0</show_in_default>
275
+ <show_in_website>0</show_in_website>
276
+ <show_in_store>1</show_in_store>
277
+ <fields>
278
+ <awb_pdf_url translate="label comment">
279
+ <label>AWB PDF URL</label>
280
+ <frontend_type>text</frontend_type>
281
+ <validate>validate-url</validate>
282
+ <sort_order>5</sort_order>
283
+ <show_in_default>0</show_in_default>
284
+ <show_in_website>0</show_in_website>
285
+ <show_in_store>1</show_in_store>
286
+ <comment><![CDATA[URL where to read AWB 's PDF from.<br/>Ex: https://mktp-stage.emag.ro/awb/read_pdf]]></comment>
287
+ </awb_pdf_url>
288
+ <courier_account_id translate="label comment">
289
+ <label>Courier Account Id</label>
290
+ <frontend_type>text</frontend_type>
291
+ <sort_order>10</sort_order>
292
+ <show_in_default>0</show_in_default>
293
+ <show_in_website>0</show_in_website>
294
+ <show_in_store>1</show_in_store>
295
+ <comment><![CDATA[Unique identifier for vendor 's courier account. If not provided, a default account will be used when creating AWBs.]]></comment>
296
+ </courier_account_id>
297
+ </fields>
298
+ </shipping_settings>
299
+ </groups>
300
+ </Innobyte_EmagMarketplace>
301
+
302
+ <payment>
303
+ <groups>
304
+ <emag_banktransfer translate="label" module="innobyte_emag_marketplace">
305
+ <label>eMAG Bank Transfer</label>
306
+ <sort_order>1000</sort_order>
307
+ <show_in_default>1</show_in_default>
308
+ <show_in_website>1</show_in_website>
309
+ <show_in_store>1</show_in_store>
310
+ <fields>
311
+ <title translate="label">
312
+ <label>Payment Title</label>
313
+ <frontend_type>text</frontend_type>
314
+ <sort_order>20</sort_order>
315
+ <show_in_default>0</show_in_default>
316
+ <show_in_website>0</show_in_website>
317
+ <show_in_store>1</show_in_store>
318
+ </title>
319
+ <sort_order>
320
+ <label>Sort Order</label>
321
+ <frontend_type>text</frontend_type>
322
+ <sort_order>40</sort_order>
323
+ <show_in_default>0</show_in_default>
324
+ <show_in_website>0</show_in_website>
325
+ <show_in_store>1</show_in_store>
326
+ <validate>validate-number</validate>
327
+ </sort_order>
328
+ </fields>
329
+ </emag_banktransfer>
330
+ <emag_cashondelivery translate="label" module="innobyte_emag_marketplace">
331
+ <label>eMAG Cash on Delivery</label>
332
+ <sort_order>1010</sort_order>
333
+ <show_in_default>0</show_in_default>
334
+ <show_in_website>0</show_in_website>
335
+ <show_in_store>1</show_in_store>
336
+ <fields>
337
+ <title translate="label">
338
+ <label>Payment Title</label>
339
+ <frontend_type>text</frontend_type>
340
+ <sort_order>20</sort_order>
341
+ <show_in_default>0</show_in_default>
342
+ <show_in_website>0</show_in_website>
343
+ <show_in_store>1</show_in_store>
344
+ </title>
345
+ <sort_order>
346
+ <label>Sort Order</label>
347
+ <frontend_type>text</frontend_type>
348
+ <sort_order>40</sort_order>
349
+ <show_in_default>0</show_in_default>
350
+ <show_in_website>0</show_in_website>
351
+ <show_in_store>1</show_in_store>
352
+ <validate>validate-number</validate>
353
+ </sort_order>
354
+ </fields>
355
+ </emag_cashondelivery>
356
+ <emag_cc translate="label" module="innobyte_emag_marketplace">
357
+ <label>eMAG Credit Card</label>
358
+ <sort_order>1030</sort_order>
359
+ <show_in_default>1</show_in_default>
360
+ <show_in_website>1</show_in_website>
361
+ <show_in_store>1</show_in_store>
362
+ <fields>
363
+ <title translate="label">
364
+ <label>Payment Title</label>
365
+ <frontend_type>text</frontend_type>
366
+ <sort_order>20</sort_order>
367
+ <show_in_default>0</show_in_default>
368
+ <show_in_website>0</show_in_website>
369
+ <show_in_store>1</show_in_store>
370
+ </title>
371
+ <sort_order>
372
+ <label>Sort Order</label>
373
+ <frontend_type>text</frontend_type>
374
+ <sort_order>40</sort_order>
375
+ <show_in_default>0</show_in_default>
376
+ <show_in_website>0</show_in_website>
377
+ <show_in_store>1</show_in_store>
378
+ <validate>validate-number</validate>
379
+ </sort_order>
380
+ </fields>
381
+ </emag_cc>
382
+ <emag_unknown translate="label" module="innobyte_emag_marketplace">
383
+ <label>eMAG Unknown</label>
384
+ <sort_order>1040</sort_order>
385
+ <show_in_default>0</show_in_default>
386
+ <show_in_website>0</show_in_website>
387
+ <show_in_store>0</show_in_store>
388
+ <fields>
389
+ <title translate="label">
390
+ <label>Payment Title</label>
391
+ <frontend_type>text</frontend_type>
392
+ <sort_order>20</sort_order>
393
+ <show_in_default>0</show_in_default>
394
+ <show_in_website>0</show_in_website>
395
+ <show_in_store>0</show_in_store>
396
+ </title>
397
+ <sort_order>
398
+ <label>Sort Order</label>
399
+ <frontend_type>text</frontend_type>
400
+ <sort_order>40</sort_order>
401
+ <show_in_default>0</show_in_default>
402
+ <show_in_website>0</show_in_website>
403
+ <show_in_store>0</show_in_store>
404
+ <validate>validate-number</validate>
405
+ </sort_order>
406
+ </fields>
407
+ </emag_unknown>
408
+ </groups>
409
+ </payment>
410
+
411
+ <carriers>
412
+ <groups>
413
+ <emagshipping translate="label" module="innobyte_emag_marketplace">
414
+ <label>eMAG Shipping</label>
415
+ <frontend_type>text</frontend_type>
416
+ <sort_order>1000</sort_order>
417
+ <show_in_default>1</show_in_default>
418
+ <show_in_website>1</show_in_website>
419
+ <show_in_store>1</show_in_store>
420
+ <fields>
421
+ <title translate="label">
422
+ <label>Title</label>
423
+ <frontend_type>text</frontend_type>
424
+ <show_in_default>0</show_in_default>
425
+ <show_in_website>0</show_in_website>
426
+ <show_in_store>1</show_in_store>
427
+ <sort_order>20</sort_order>
428
+ </title>
429
+ <name translate="label">
430
+ <label>Method Name</label>
431
+ <frontend_type>text</frontend_type>
432
+ <sort_order>25</sort_order>
433
+ <show_in_default>0</show_in_default>
434
+ <show_in_website>0</show_in_website>
435
+ <show_in_store>1</show_in_store>
436
+ </name>
437
+ <sort_order translate="label">
438
+ <label>Sort Order</label>
439
+ <frontend_type>text</frontend_type>
440
+ <show_in_default>0</show_in_default>
441
+ <show_in_website>0</show_in_website>
442
+ <show_in_store>1</show_in_store>
443
+ <sort_order>50</sort_order>
444
+ </sort_order>
445
+ </fields>
446
+ </emagshipping>
447
+ </groups>
448
+ </carriers>
449
+
450
+ <shipping>
451
+ <groups>
452
+ <origin>
453
+ <fields>
454
+ <emag_locality_id translate="label" module="innobyte_emag_marketplace">
455
+ <label>Locality Id</label>
456
+ <frontend_type>hidden</frontend_type>
457
+ <frontend_model>innobyte_emag_marketplace/adminhtml_form_field_localityId</frontend_model>
458
+ <show_in_default>1</show_in_default>
459
+ <show_in_website>1</show_in_website>
460
+ <show_in_store>0</show_in_store>
461
+ <sort_order>100</sort_order>
462
+ </emag_locality_id>
463
+ </fields>
464
+ </origin>
465
+ </groups>
466
+ </shipping>
467
+ </sections>
468
+ </config>
app/code/local/Innobyte/EmagMarketplace/sql/innobyte_emag_marketplace_setup/install-1.0.0.php ADDED
@@ -0,0 +1,1744 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Installer script.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ *
8
+ * @author Valentin Sandu <valentin.sandu@innobyte.com>
9
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
10
+ */
11
+ ?>
12
+ <?php
13
+ /** @var $installer Mage_Sales_Model_Resource_Setup */
14
+ $installer = $this;
15
+
16
+ $installer->startSetup();
17
+
18
+ $emagSalesQuoteTable = $installer->getTable('innobyte_emag_marketplace/sales_quote');
19
+ $emagSalesOrderTable = $installer->getTable('innobyte_emag_marketplace/sales_order');
20
+ $emagSalesQuoteAddressTable = $installer->getTable('innobyte_emag_marketplace/sales_quote_address');
21
+ $emagSalesOrderAddressTable = $installer->getTable('innobyte_emag_marketplace/sales_order_address');
22
+
23
+ // Table 'innobyte_emag_marketplace/sales_quote'
24
+ if (!$installer->getConnection()->isTableExists($emagSalesQuoteTable)) {
25
+ $table = $installer->getConnection()
26
+ ->newTable($emagSalesQuoteTable)
27
+ ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
28
+ 'unsigned' => true,
29
+ 'nullable' => false,
30
+ 'primary' => true,
31
+ 'default' => '0',
32
+ ), 'Entity Id')
33
+ ->addForeignKey(
34
+ $installer->getFkName(
35
+ 'innobyte_emag_marketplace/sales_quote',
36
+ 'entity_id',
37
+ 'sales/order',
38
+ 'entity_id'
39
+ ),
40
+ 'entity_id',
41
+ $installer->getTable('sales/quote'),
42
+ 'entity_id',
43
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
44
+ Varien_Db_Ddl_Table::ACTION_CASCADE)
45
+ ->setComment('eMAG Sales Flat Quote');
46
+ $installer->getConnection()->createTable($table);
47
+ }
48
+
49
+ // Table 'innobyte_emag_marketplace/sales_quote_address'
50
+ if (!$installer->getConnection()->isTableExists($emagSalesQuoteAddressTable)) {
51
+ $table = $installer->getConnection()
52
+ ->newTable($emagSalesQuoteAddressTable)
53
+ ->addColumn(
54
+ 'entity_id',
55
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
56
+ null,
57
+ array(
58
+ 'unsigned' => true,
59
+ 'nullable' => false,
60
+ 'primary' => true,
61
+ 'default' => '0',
62
+ )
63
+ , 'Entity Id'
64
+ )
65
+ ->addForeignKey($installer->getFkName(
66
+ 'innobyte_emag_marketplace/sales_quote_address',
67
+ 'entity_id',
68
+ 'sales/quote_address',
69
+ 'address_id'
70
+ ),
71
+ 'entity_id',
72
+ $installer->getTable('sales/quote_address'),
73
+ 'address_id',
74
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
75
+ Varien_Db_Ddl_Table::ACTION_CASCADE
76
+ )
77
+ ->setComment('eMAG Sales Flat Quote Address');
78
+
79
+ // Create Table
80
+ $installer->getConnection()->createTable($table);
81
+ }
82
+
83
+ // Table 'innobyte_emag_marketplace/sales_order'
84
+ if (!$installer->getConnection()->isTableExists($emagSalesOrderTable)) {
85
+ $table = $installer->getConnection()
86
+ ->newTable($emagSalesOrderTable)
87
+ ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
88
+ 'unsigned' => true,
89
+ 'nullable' => false,
90
+ 'primary' => true,
91
+ 'default' => '0',
92
+ ), 'Entity Id')
93
+ ->addForeignKey(
94
+ $installer->getFkName(
95
+ 'innobyte_emag_marketplace/sales_order',
96
+ 'entity_id',
97
+ 'sales/order',
98
+ 'entity_id'
99
+ ),
100
+ 'entity_id',
101
+ $installer->getTable('sales/order'),
102
+ 'entity_id',
103
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
104
+ Varien_Db_Ddl_Table::ACTION_CASCADE)
105
+ ->setComment('eMAG Sales Flat Order');
106
+ $installer->getConnection()->createTable($table);
107
+ }
108
+
109
+ // Table 'innobyte_emag_marketplace/sales_order_address'
110
+ if (!$installer->getConnection()->isTableExists($emagSalesOrderAddressTable)) {
111
+ $table = $installer->getConnection()
112
+ ->newTable($emagSalesOrderAddressTable)
113
+ ->addColumn(
114
+ 'entity_id',
115
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
116
+ null,
117
+ array(
118
+ 'unsigned' => true,
119
+ 'nullable' => false,
120
+ 'primary' => true,
121
+ 'default' => '0',
122
+ )
123
+ , 'Entity Id'
124
+ )
125
+ ->addForeignKey($installer->getFkName(
126
+ 'innobyte_emag_marketplace/sales_order_address',
127
+ 'entity_id',
128
+ 'sales/order_address',
129
+ 'entity_id'
130
+ ),
131
+ 'entity_id',
132
+ $installer->getTable('sales/order_address'),
133
+ 'entity_id',
134
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
135
+ Varien_Db_Ddl_Table::ACTION_CASCADE)
136
+ ->setComment('eMAG Sales Flat Order Address');
137
+
138
+ // Create Table
139
+ $installer->getConnection()->createTable($table);
140
+ }
141
+
142
+
143
+ //====================== ADD CUSTOMER ADDRESS ATTRIBUTES =====================//
144
+
145
+ /** @var $eavConfig Mage_Eav_Model_Config */
146
+ $eavConfig = Mage::getSingleton('eav/config');
147
+
148
+ $attributes = array(
149
+ 'emag_order_id' => array(
150
+ 'frontend_label' => 'eMAG - Order ID',
151
+ 'frontend_input' => 'hidden',
152
+ 'is_user_defined' => 1,
153
+ 'is_system' => 1,
154
+ 'is_visible' => 0,
155
+ 'is_required' => 0,
156
+ 'backend_type' => 'int',
157
+ 'sort_order' => 1,
158
+ 'note' => 'eMAG - Order ID.'
159
+ ),
160
+ 'emag_customer_id' => array(
161
+ 'frontend_label' => 'eMAG - Customer ID',
162
+ 'frontend_input' => 'hidden',
163
+ 'is_user_defined' => 1,
164
+ 'is_system' => 1,
165
+ 'is_visible' => 0,
166
+ 'is_required' => 0,
167
+ 'backend_type' => 'int',
168
+ 'sort_order' => 1,
169
+ 'note' => 'eMAG - Customer ID.'
170
+ ),
171
+ 'emag_customer_comment' => array(
172
+ 'frontend_label' => 'eMAG - Customer Comment',
173
+ 'frontend_input' => 'text',
174
+ 'is_user_defined' => 1,
175
+ 'is_system' => 1,
176
+ 'is_visible' => 0,
177
+ 'is_required' => 0,
178
+ 'backend_type' => 'text',
179
+ 'sort_order' => 1,
180
+ 'note' => 'eMAG - Customer Comment.'
181
+ ),
182
+ 'emag_customer_gender' => array(
183
+ 'frontend_label' => 'eMAG - Customer Gender',
184
+ 'frontend_input' => 'hidden',
185
+ 'is_user_defined' => 1,
186
+ 'is_system' => 1,
187
+ 'is_visible' => 0,
188
+ 'is_required' => 0,
189
+ 'backend_type' => 'varchar',
190
+ 'sort_order' => 1,
191
+ 'note' => 'eMAG - Customer Gender.'
192
+ ),
193
+ 'emag_payment_status' => array(
194
+ 'frontend_label' => 'eMAG - Payment Status',
195
+ 'frontend_input' => 'hidden',
196
+ 'is_user_defined' => 1,
197
+ 'is_system' => 1,
198
+ 'is_visible' => 0,
199
+ 'is_required' => 0,
200
+ 'backend_type' => 'varchar',
201
+ 'sort_order' => 1,
202
+ 'note' => 'eMAG - Payment Status.'
203
+ ),
204
+ 'emag_order_date' => array(
205
+ 'frontend_label' => 'eMAG - Order Date',
206
+ 'frontend_input' => 'hidden',
207
+ 'is_user_defined' => 1,
208
+ 'is_system' => 1,
209
+ 'is_visible' => 0,
210
+ 'is_required' => 0,
211
+ 'backend_type' => 'varchar',
212
+ 'sort_order' => 1,
213
+ 'note' => 'eMAG - Order Date.'
214
+ )
215
+ );
216
+
217
+ // eMAG attributes
218
+ $addressAttributes = array(
219
+ 'emag_company_code' => array(
220
+ 'frontend_label' => 'eMAG - Company Registration Code',
221
+ 'frontend_input' => 'text',
222
+ 'is_user_defined' => 1,
223
+ 'is_system' => 1,
224
+ 'is_visible' => 1,
225
+ 'is_required' => 0,
226
+ 'backend_type' => 'varchar',
227
+ 'validate_rules' => array(
228
+ 'max_text_length' => 255,
229
+ 'min_text_length' => 1
230
+ ),
231
+ 'sort_order' => 61,
232
+ 'note' => 'eMAG - Company registration code.'
233
+ ),
234
+ 'emag_company_reg_no' => array(
235
+ 'frontend_label' => 'eMAG - Company Registration Number',
236
+ 'frontend_input' => 'text',
237
+ 'is_user_defined' => 1,
238
+ 'is_system' => 1,
239
+ 'is_visible' => 1,
240
+ 'is_required' => 0,
241
+ 'backend_type' => 'varchar',
242
+ 'validate_rules' => array(
243
+ 'max_text_length' => 255,
244
+ 'min_text_length' => 1
245
+ ),
246
+ 'sort_order' => 62,
247
+ 'note' => 'eMAG - Company registration number.'
248
+ ),
249
+ 'emag_bank' => array(
250
+ 'frontend_label' => 'eMAG - Bank',
251
+ 'frontend_input' => 'text',
252
+ 'is_user_defined' => 1,
253
+ 'is_system' => 1,
254
+ 'is_visible' => 1,
255
+ 'is_required' => 0,
256
+ 'backend_type' => 'varchar',
257
+ 'validate_rules' => array(
258
+ 'max_text_length' => 255,
259
+ 'min_text_length' => 1
260
+ ),
261
+ 'sort_order' => 63,
262
+ 'note' => 'eMAG - Bank.'
263
+ ),
264
+ 'emag_iban' => array(
265
+ 'frontend_label' => 'eMAG - IBAN',
266
+ 'frontend_input' => 'text',
267
+ 'is_user_defined' => 1,
268
+ 'is_system' => 1,
269
+ 'is_visible' => 1,
270
+ 'is_required' => 0,
271
+ 'backend_type' => 'varchar',
272
+ 'validate_rules' => array(
273
+ 'max_text_length' => 255,
274
+ 'min_text_length' => 1
275
+ ),
276
+ 'sort_order' => 64,
277
+ 'note' => 'eMAG - IBAN.'
278
+ ),
279
+ 'emag_legal_entity' => array(
280
+ 'frontend_label' => 'eMAG - Legal Entity',
281
+ 'frontend_input' => 'select',
282
+ 'is_user_defined' => 1,
283
+ 'is_system' => 1,
284
+ 'is_visible' => 1,
285
+ 'is_required' => 0,
286
+ 'source_model' => 'innobyte_emag_marketplace/source_customer_address_attributes_legalentity',
287
+ 'backend_type' => 'int',
288
+ 'sort_order' => 58,
289
+ 'note' => 'eMAG - Legal Entity.'
290
+ ),
291
+ 'emag_is_vat_payer' => array(
292
+ 'frontend_label' => 'eMAG - Is VAT Payer',
293
+ 'frontend_input' => 'boolean',
294
+ 'is_user_defined' => 1,
295
+ 'is_system' => 1,
296
+ 'is_visible' => 1,
297
+ 'is_required' => 0,
298
+ 'source_model' => 'customer/attribute_backend_data_boolean',
299
+ 'backend_type' => 'static',
300
+ 'sort_order' => 59,
301
+ 'note' => 'eMAG - Is VAT Payer.'
302
+ ),
303
+ 'emag_telephone_2' => array(
304
+ 'frontend_label' => 'eMAG - Telephone 2',
305
+ 'frontend_input' => 'text',
306
+ 'is_user_defined' => 1,
307
+ 'is_system' => 1,
308
+ 'is_visible' => 1,
309
+ 'is_required' => 0,
310
+ 'backend_type' => 'varchar',
311
+ 'validate_rules' => array(
312
+ 'max_text_length' => 255,
313
+ 'min_text_length' => 1
314
+ ),
315
+ 'sort_order' => 121,
316
+ 'note' => 'eMAG - Second Telephone Number.'
317
+ ),
318
+ 'emag_telephone_3' => array(
319
+ 'frontend_label' => 'eMAG - Telephone 3',
320
+ 'frontend_input' => 'text',
321
+ 'is_user_defined' => 1,
322
+ 'is_system' => 1,
323
+ 'is_visible' => 1,
324
+ 'is_required' => 0,
325
+ 'backend_type' => 'varchar',
326
+ 'validate_rules' => array(
327
+ 'max_text_length' => 255,
328
+ 'min_text_length' => 1
329
+ ),
330
+ 'sort_order' => 122,
331
+ 'note' => 'eMAG - Third Telephone Number.'
332
+ ),
333
+ 'emag_locality_id' => array(
334
+ 'frontend_label' => 'eMAG - Locality',
335
+ 'frontend_input' => 'hidden',
336
+ 'is_user_defined' => 1,
337
+ 'is_system' => 1,
338
+ 'is_visible' => 0,
339
+ 'is_required' => 0,
340
+ 'backend_type' => 'int',
341
+ 'sort_order' => 100,
342
+ 'note' => 'eMAG - Locality ID.'
343
+ ),
344
+ );
345
+
346
+ // set forms to be used in; see table "customer_form_attribute" for form codes
347
+ $attributesForms = array(
348
+ 'adminhtml_customer'
349
+ );
350
+
351
+ $addressAttributesForms = array(
352
+ 'adminhtml_customer_address',
353
+ );
354
+
355
+ // add attributes
356
+ foreach ($attributes as $attributeCode => $data) {
357
+ /** @var $attribute Mage_Customer_Model_Attribute */
358
+ $attribute = $eavConfig->getAttribute('customer', $attributeCode);
359
+ if (!$attribute) {
360
+ continue;
361
+ }
362
+
363
+ $attribute->addData($data);
364
+ $attribute->setData('used_in_forms', $attributesForms);
365
+ $attribute->save();
366
+
367
+ // add attribute to quote
368
+ /** @var $quote Innobyte_EmagMarketplace_Model_Sales_Quote */
369
+ $quote = Mage::getModel('innobyte_emag_marketplace/sales_quote');
370
+ $quote->saveAttribute($attribute);
371
+
372
+ // add attribute to order
373
+ /** @var $order Innobyte_EmagMarketplace_Model_Sales_Order */
374
+ $order = Mage::getModel('innobyte_emag_marketplace/sales_order');
375
+ $order->saveAttribute($attribute);
376
+ }
377
+
378
+ // add address attributes
379
+ foreach ($addressAttributes as $attributeCode => $data) {
380
+ /** @var $attribute Mage_Customer_Model_Attribute */
381
+ $attribute = $eavConfig->getAttribute('customer_address', $attributeCode);
382
+ if (!$attribute) {
383
+ continue;
384
+ }
385
+
386
+ $attribute->addData($data);
387
+ $attribute->setData('used_in_forms', $addressAttributesForms);
388
+ $attribute->save();
389
+
390
+ // add attribute to quote address
391
+ /** @var $quoteAddress Innobyte_EmagMarketplace_Model_Sales_Quote_Address */
392
+ $quoteAddress = Mage::getModel('innobyte_emag_marketplace/sales_quote_address');
393
+ $quoteAddress->saveAttribute($attribute);
394
+
395
+ // add attribute to order address
396
+ /** @var $orderAddress Innobyte_EmagMarketplace_Model_Sales_Order_Address */
397
+ $orderAddress = Mage::getModel('innobyte_emag_marketplace/sales_order_address');
398
+ $orderAddress->saveAttribute($attribute);
399
+ }
400
+
401
+ $emagSalesInvoiceTable = $installer->getTable('innobyte_emag_marketplace/sales_invoice');
402
+ // Table 'innobyte_emag_marketplace/sales_invoice'
403
+ if (!$installer->getConnection()->isTableExists($emagSalesInvoiceTable)) {
404
+ $table = $installer->getConnection()
405
+ ->newTable($emagSalesInvoiceTable)
406
+ ->addColumn(
407
+ 'id',
408
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
409
+ null,
410
+ array(
411
+ 'unsigned' => true,
412
+ 'nullable' => false,
413
+ 'primary' => true,
414
+ 'identity' => true,
415
+ ),
416
+ 'ID'
417
+ )
418
+ ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
419
+ 'unsigned' => true,
420
+ 'nullable' => false,
421
+ 'primary' => true,
422
+ 'default' => '0',
423
+ ), 'Order Id')
424
+ ->addColumn(
425
+ 'emag_invoice_name',
426
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
427
+ 255,
428
+ array(
429
+ 'nullable' => false,
430
+ ),
431
+ 'eMAG Invoice Name'
432
+ )
433
+ ->addColumn('emag_invoice_type', Varien_Db_Ddl_Table::TYPE_INTEGER, 5, array(
434
+ 'unsigned' => true,
435
+ 'nullable' => false,
436
+ 'default' => '0',
437
+ ), 'eMAG Invoice Type 0-normal, 1-storno')
438
+ ->addForeignKey(
439
+ $installer->getFkName(
440
+ 'innobyte_emag_marketplace/sales_invoice',
441
+ 'order_id',
442
+ 'sales/order',
443
+ 'entity_id'
444
+ ),
445
+ 'order_id',
446
+ $installer->getTable('sales/order'),
447
+ 'entity_id',
448
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
449
+ Varien_Db_Ddl_Table::ACTION_CASCADE)
450
+ ->setComment('eMAG Third Party Invoice');
451
+ $installer->getConnection()->createTable($table);
452
+ }
453
+
454
+ $emagSalesQuoteVoucherTable = $installer->getTable('innobyte_emag_marketplace/sales_quote_voucher');
455
+ $emagSalesOrderVoucherTable = $installer->getTable('innobyte_emag_marketplace/sales_order_voucher');
456
+
457
+ // Table 'innobyte_emag_marketplace/sales_quote_voucher'
458
+ if (!$installer->getConnection()->isTableExists($emagSalesQuoteVoucherTable)) {
459
+ $table = $installer->getConnection()
460
+ ->newTable($emagSalesQuoteVoucherTable)
461
+ ->addColumn(
462
+ 'id',
463
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
464
+ null,
465
+ array(
466
+ 'unsigned' => true,
467
+ 'nullable' => false,
468
+ 'primary' => true,
469
+ 'identity' => true,
470
+ ),
471
+ 'ID'
472
+ )
473
+ ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
474
+ 'unsigned' => true,
475
+ 'nullable' => false
476
+ ), 'Entity Id')
477
+ ->addColumn('emag_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 11, array(
478
+ 'unsigned' => true,
479
+ 'nullable' => false,
480
+ 'default' => '0',
481
+ ), 'eMAG ID')
482
+ ->addColumn('emag_voucher_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 11, array(
483
+ 'unsigned' => true,
484
+ 'nullable' => false,
485
+ 'default' => '0',
486
+ ), 'eMAG Voucher ID')
487
+ ->addColumn(
488
+ 'emag_voucher_name',
489
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
490
+ 255,
491
+ array(
492
+ 'nullable' => false,
493
+ ),
494
+ 'eMAG Voucher Name'
495
+ )
496
+ ->addColumn(
497
+ 'emag_sale_price',
498
+ Varien_Db_Ddl_Table::TYPE_DECIMAL,
499
+ '12,4',
500
+ array(
501
+ 'nullable' => false,
502
+ 'default' => 0
503
+ ),
504
+ 'eMAG Sale Price'
505
+ )
506
+ ->addColumn(
507
+ 'base_emag_sale_price',
508
+ Varien_Db_Ddl_Table::TYPE_DECIMAL,
509
+ '12,4',
510
+ array(
511
+ 'nullable' => false,
512
+ 'default' => 0
513
+ ),
514
+ 'Base eMAG Sale Price'
515
+ )
516
+ ->addColumn(
517
+ 'emag_sale_price_vat',
518
+ Varien_Db_Ddl_Table::TYPE_DECIMAL,
519
+ '12,4',
520
+ array(
521
+ 'nullable' => false,
522
+ 'default' => 0
523
+ ),
524
+ 'eMAG Sale Price VAT'
525
+ )
526
+ ->addColumn(
527
+ 'base_emag_sale_price_vat',
528
+ Varien_Db_Ddl_Table::TYPE_DECIMAL,
529
+ '12,4',
530
+ array(
531
+ 'nullable' => false,
532
+ 'default' => 0
533
+ ),
534
+ 'Base eMAG Sale Price VAT'
535
+ )
536
+ ->addColumn('emag_status', Varien_Db_Ddl_Table::TYPE_INTEGER, 5, array(
537
+ 'unsigned' => true,
538
+ 'nullable' => false,
539
+ 'default' => '0',
540
+ ), 'eMAG Status')
541
+ ->addColumn(
542
+ 'emag_vat',
543
+ Varien_Db_Ddl_Table::TYPE_DECIMAL,
544
+ '4,2',
545
+ array(
546
+ 'nullable' => false,
547
+ 'default' => 0
548
+ ),
549
+ 'eMAG VAT'
550
+ )
551
+ ->addColumn('emag_created', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
552
+ ), 'eMAG Creation Time')
553
+ ->addColumn('emag_modified', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
554
+ ), 'eMAG Modification Time')
555
+ ->addIndex(
556
+ $installer->getIdxName(
557
+ 'innobyte_emag_marketplace/sales_quote_voucher',
558
+ array('entity_id', 'emag_voucher_id'),
559
+ Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
560
+ ),
561
+ array('entity_id', 'emag_voucher_id'),
562
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)
563
+ )
564
+ ->addForeignKey(
565
+ $installer->getFkName(
566
+ 'innobyte_emag_marketplace/sales_quote_voucher',
567
+ 'entity_id',
568
+ 'sales/quote',
569
+ 'entity_id'
570
+ ),
571
+ 'entity_id',
572
+ $installer->getTable('sales/quote'),
573
+ 'entity_id',
574
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
575
+ Varien_Db_Ddl_Table::ACTION_CASCADE)
576
+ ->setComment('eMAG Quote Vouchers');
577
+ $installer->getConnection()->createTable($table);
578
+ }
579
+
580
+ // Table 'innobyte_emag_marketplace/sales_order_voucher'
581
+ if (!$installer->getConnection()->isTableExists($emagSalesOrderVoucherTable)) {
582
+ $table = $installer->getConnection()
583
+ ->newTable($emagSalesOrderVoucherTable)
584
+ ->addColumn(
585
+ 'id',
586
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
587
+ null,
588
+ array(
589
+ 'unsigned' => true,
590
+ 'nullable' => false,
591
+ 'primary' => true,
592
+ 'identity' => true,
593
+ ),
594
+ 'ID'
595
+ )
596
+ ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
597
+ 'unsigned' => true,
598
+ 'nullable' => false
599
+ ), 'Entity Id')
600
+ ->addColumn('emag_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 11, array(
601
+ 'unsigned' => true,
602
+ 'nullable' => false,
603
+ 'default' => '0',
604
+ ), 'eMAG ID')
605
+ ->addColumn('emag_voucher_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 11, array(
606
+ 'unsigned' => true,
607
+ 'nullable' => false,
608
+ 'default' => '0',
609
+ ), 'eMAG Voucher ID')
610
+ ->addColumn(
611
+ 'emag_voucher_name',
612
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
613
+ 255,
614
+ array(
615
+ 'nullable' => false,
616
+ ),
617
+ 'eMAG Voucher Name'
618
+ )
619
+ ->addColumn(
620
+ 'emag_sale_price',
621
+ Varien_Db_Ddl_Table::TYPE_DECIMAL,
622
+ '12,4',
623
+ array(
624
+ 'nullable' => false,
625
+ 'default' => 0
626
+ ),
627
+ 'eMAG Sale Price'
628
+ )
629
+ ->addColumn(
630
+ 'base_emag_sale_price',
631
+ Varien_Db_Ddl_Table::TYPE_DECIMAL,
632
+ '12,4',
633
+ array(
634
+ 'nullable' => false,
635
+ 'default' => 0
636
+ ),
637
+ 'Base eMAG Sale Price'
638
+ )
639
+ ->addColumn(
640
+ 'emag_sale_price_vat',
641
+ Varien_Db_Ddl_Table::TYPE_DECIMAL,
642
+ '12,4',
643
+ array(
644
+ 'nullable' => false,
645
+ 'default' => 0
646
+ ),
647
+ 'eMAG Sale Price VAT'
648
+ )
649
+ ->addColumn(
650
+ 'base_emag_sale_price_vat',
651
+ Varien_Db_Ddl_Table::TYPE_DECIMAL,
652
+ '12,4',
653
+ array(
654
+ 'nullable' => false,
655
+ 'default' => 0
656
+ ),
657
+ 'Base eMAG Sale Price VAT'
658
+ )
659
+ ->addColumn('emag_status', Varien_Db_Ddl_Table::TYPE_INTEGER, 5, array(
660
+ 'unsigned' => true,
661
+ 'nullable' => false,
662
+ 'default' => '0',
663
+ ), 'eMAG Status')
664
+ ->addColumn(
665
+ 'emag_vat',
666
+ Varien_Db_Ddl_Table::TYPE_DECIMAL,
667
+ '4,2',
668
+ array(
669
+ 'nullable' => false,
670
+ 'default' => 0
671
+ ),
672
+ 'eMAG VAT'
673
+ )
674
+ ->addColumn('emag_created', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
675
+ ), 'eMAG Creation Time')
676
+ ->addColumn('emag_modified', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
677
+ ), 'eMAG Modification Time')
678
+ ->addIndex(
679
+ $installer->getIdxName(
680
+ 'innobyte_emag_marketplace/sales_order_voucher',
681
+ array('entity_id', 'emag_voucher_id'),
682
+ Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
683
+ ),
684
+ array('entity_id', 'emag_voucher_id'),
685
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)
686
+ )
687
+ ->addForeignKey(
688
+ $installer->getFkName(
689
+ 'innobyte_emag_marketplace/sales_order_voucher',
690
+ 'entity_id',
691
+ 'sales/order',
692
+ 'entity_id'
693
+ ),
694
+ 'entity_id',
695
+ $installer->getTable('sales/order'),
696
+ 'entity_id',
697
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
698
+ Varien_Db_Ddl_Table::ACTION_CASCADE)
699
+ ->setComment('eMAG Order Vouchers');
700
+ $installer->getConnection()->createTable($table);
701
+ }
702
+
703
+ $emagSalesOrderItemTable = $installer->getTable('innobyte_emag_marketplace/sales_order_item');
704
+
705
+ // Table 'innobyte_emag_marketplace/sales_order_item'
706
+ if (!$installer->getConnection()->isTableExists($emagSalesOrderItemTable)) {
707
+ $table = $installer->getConnection()
708
+ ->newTable($emagSalesOrderItemTable)
709
+ ->addColumn(
710
+ 'item_id',
711
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
712
+ null,
713
+ array(
714
+ 'unsigned' => true,
715
+ 'nullable' => false,
716
+ 'primary' => true,
717
+ 'default' => '0',
718
+ )
719
+ , 'Item Id'
720
+ )
721
+ ->addColumn('emag_details', Varien_Db_Ddl_Table::TYPE_TEXT, '64K', array(), 'eMAG Details')
722
+ ->addColumn('emag_created', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(), 'eMAG Creation Time')
723
+ ->addColumn('emag_modified', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(), 'eMAG Modification Time')
724
+ ->addForeignKey($installer->getFkName(
725
+ 'innobyte_emag_marketplace/sales_order_item',
726
+ 'item_id',
727
+ 'sales/order_item',
728
+ 'item_id'
729
+ ),
730
+ 'item_id',
731
+ $installer->getTable('sales/order_item'),
732
+ 'item_id',
733
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
734
+ Varien_Db_Ddl_Table::ACTION_CASCADE)
735
+ ->setComment('eMAG Sales Flat Order Item');
736
+
737
+ // Create Table
738
+ $installer->getConnection()->createTable($table);
739
+ }
740
+
741
+ ###############################################################################
742
+
743
+ // table 'innobyte_emag_marketplace_locality'
744
+ $tableNameLocality = $installer->getTable('innobyte_emag_marketplace/locality');
745
+ $installer->getConnection()->dropTable($tableNameLocality);
746
+ $tableLocality = $installer->getConnection()
747
+ ->newTable($tableNameLocality)
748
+ ->addColumn(
749
+ 'id',
750
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
751
+ null,
752
+ array(
753
+ 'unsigned' => true,
754
+ 'nullable' => false,
755
+ 'primary' => true,
756
+ 'identity' => true,
757
+ ),
758
+ 'The table \'s PK'
759
+ )
760
+ ->addColumn(
761
+ 'name',
762
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
763
+ 60,
764
+ array(
765
+ 'nullable' => true,
766
+ ),
767
+ 'eMAG locality name'
768
+ )
769
+ ->addColumn(
770
+ 'name_latin',
771
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
772
+ 60,
773
+ array(
774
+ 'nullable' => true,
775
+ ),
776
+ 'eMAG locality name latin'
777
+ )
778
+ ->addColumn(
779
+ 'region1',
780
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
781
+ 60,
782
+ array(
783
+ 'nullable' => true,
784
+ ),
785
+ 'eMAG locality region 1'
786
+ )
787
+ ->addColumn(
788
+ 'region2',
789
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
790
+ 60,
791
+ array(
792
+ 'nullable' => true,
793
+ ),
794
+ 'eMAG locality region 2'
795
+ )
796
+ ->addColumn(
797
+ 'region3',
798
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
799
+ 60,
800
+ array(
801
+ 'nullable' => true,
802
+ ),
803
+ 'eMAG locality region 3'
804
+ )
805
+ ->addColumn(
806
+ 'region4',
807
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
808
+ 60,
809
+ array(
810
+ 'nullable' => true,
811
+ ),
812
+ 'eMAG locality region 4'
813
+ )
814
+ ->addColumn(
815
+ 'region1_latin',
816
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
817
+ 60,
818
+ array(
819
+ 'nullable' => true,
820
+ ),
821
+ 'eMAG locality region 1 latin'
822
+ )
823
+ ->addColumn(
824
+ 'region2_latin',
825
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
826
+ 60,
827
+ array(
828
+ 'nullable' => true,
829
+ ),
830
+ 'eMAG locality region 2 latin'
831
+ )
832
+ ->addColumn(
833
+ 'region3_latin',
834
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
835
+ 60,
836
+ array(
837
+ 'nullable' => true,
838
+ ),
839
+ 'eMAG locality region 3 latin'
840
+ )
841
+ ->addColumn(
842
+ 'region4_latin',
843
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
844
+ 60,
845
+ array(
846
+ 'nullable' => true,
847
+ ),
848
+ 'eMAG locality region 4 latin'
849
+ )
850
+ ->addColumn(
851
+ 'emag_id',
852
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
853
+ null,
854
+ array(
855
+ 'nullable' => false,
856
+ ),
857
+ 'eMAG vat ID'
858
+ )
859
+ ->addColumn(
860
+ 'geoid',
861
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
862
+ null,
863
+ array(
864
+ 'nullable' => true,
865
+ ),
866
+ 'eMAG locality geoid'
867
+ )
868
+ ->addColumn(
869
+ 'emag_modified',
870
+ Varien_Db_Ddl_Table::TYPE_DATETIME,
871
+ null,
872
+ array(
873
+ 'nullable' => true,
874
+ ),
875
+ 'eMAG locality modification'
876
+ )
877
+ ->addColumn(
878
+ 'store_id',
879
+ Varien_Db_Ddl_Table::TYPE_SMALLINT,
880
+ null,
881
+ array(
882
+ 'unsigned' => true,
883
+ 'nullable' => false,
884
+ ),
885
+ 'Store ID'
886
+ )
887
+ ->addColumn(
888
+ 'updated_at',
889
+ Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
890
+ null,
891
+ array(
892
+ 'nullable' => false,
893
+ 'default' => Varien_Db_Ddl_Table::TIMESTAMP_INIT,
894
+ ),
895
+ 'Row update time'
896
+ )
897
+ ->addColumn(
898
+ 'created_at',
899
+ Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
900
+ null,
901
+ array(
902
+ 'nullable' => false,
903
+ ),
904
+ 'Row creation time'
905
+ )
906
+ ->addIndex(
907
+ $installer->getIdxName(
908
+ 'innobyte_emag_marketplace/locality',
909
+ array('emag_id', 'store_id'),
910
+ Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
911
+ ),
912
+ array('emag_id', 'store_id'),
913
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)
914
+ )
915
+ ->addForeignKey(
916
+ $installer->getFkName(
917
+ 'innobyte_emag_marketplace/locality',
918
+ 'store_id',
919
+ 'core/store',
920
+ 'store_id'
921
+ ),
922
+ 'store_id',
923
+ $installer->getTable('core/store'),
924
+ 'store_id',
925
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
926
+ Varien_Db_Ddl_Table::ACTION_CASCADE
927
+ )
928
+ ->setComment('eMAG localities');
929
+ $installer->getConnection()->createTable($tableLocality);
930
+
931
+
932
+ // table 'innobyte_emag_marketplace_vat'
933
+ $tableNameVats = $installer->getTable('innobyte_emag_marketplace/vat');
934
+ $installer->getConnection()->dropTable($tableNameVats);
935
+ $tableVats = $installer->getConnection()
936
+ ->newTable($tableNameVats)
937
+ ->addColumn(
938
+ 'id',
939
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
940
+ null,
941
+ array(
942
+ 'unsigned' => true,
943
+ 'nullable' => false,
944
+ 'primary' => true,
945
+ 'identity' => true,
946
+ ),
947
+ 'The table \'s PK'
948
+ )
949
+ ->addColumn(
950
+ 'rate',
951
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
952
+ 255,
953
+ array(
954
+ 'nullable' => false,
955
+ ),
956
+ 'eMAG vat value'
957
+ )
958
+ ->addColumn(
959
+ 'emag_id',
960
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
961
+ null,
962
+ array(
963
+ 'nullable' => false,
964
+ ),
965
+ 'eMAG vat ID'
966
+ )
967
+ ->addColumn(
968
+ 'store_id',
969
+ Varien_Db_Ddl_Table::TYPE_SMALLINT,
970
+ null,
971
+ array(
972
+ 'unsigned' => true,
973
+ 'nullable' => false,
974
+ ),
975
+ 'Store ID'
976
+ )
977
+ ->addColumn(
978
+ 'updated_at',
979
+ Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
980
+ null,
981
+ array(
982
+ 'nullable' => false,
983
+ 'default' => Varien_Db_Ddl_Table::TIMESTAMP_INIT,
984
+ ),
985
+ 'Row update time'
986
+ )
987
+ ->addColumn(
988
+ 'created_at',
989
+ Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
990
+ null,
991
+ array(
992
+ 'nullable' => false,
993
+ ),
994
+ 'Row creation time'
995
+ )
996
+ ->addIndex(
997
+ $installer->getIdxName(
998
+ 'innobyte_emag_marketplace/vat',
999
+ array('emag_id', 'store_id'),
1000
+ Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
1001
+ ),
1002
+ array('emag_id', 'store_id'),
1003
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)
1004
+ )
1005
+ ->addForeignKey(
1006
+ $installer->getFkName(
1007
+ 'innobyte_emag_marketplace/vat',
1008
+ 'store_id',
1009
+ 'core/store',
1010
+ 'store_id'
1011
+ ),
1012
+ 'store_id',
1013
+ $installer->getTable('core/store'),
1014
+ 'store_id',
1015
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
1016
+ Varien_Db_Ddl_Table::ACTION_CASCADE
1017
+ )
1018
+ ->setComment('eMAG vat');
1019
+ $installer->getConnection()->createTable($tableVats);
1020
+
1021
+ // table 'innobyte_emag_marketplace_category'
1022
+ $tableNameCategories = $installer->getTable('innobyte_emag_marketplace/category');
1023
+ $installer->getConnection()->dropTable($tableNameCategories);
1024
+ $tableCategories = $installer->getConnection()
1025
+ ->newTable($tableNameCategories)
1026
+ ->addColumn(
1027
+ 'id',
1028
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
1029
+ null,
1030
+ array(
1031
+ 'unsigned' => true,
1032
+ 'nullable' => false,
1033
+ 'primary' => true,
1034
+ 'identity' => true,
1035
+ ),
1036
+ 'The table \'s PK'
1037
+ )
1038
+ ->addColumn(
1039
+ 'name',
1040
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
1041
+ 255,
1042
+ array(
1043
+ 'nullable' => false,
1044
+ ),
1045
+ 'eMAG category name'
1046
+ )
1047
+ ->addColumn(
1048
+ 'emag_id',
1049
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
1050
+ null,
1051
+ array(
1052
+ 'nullable' => false,
1053
+ ),
1054
+ 'eMAG category ID'
1055
+ )
1056
+ ->addColumn(
1057
+ 'store_id',
1058
+ Varien_Db_Ddl_Table::TYPE_SMALLINT,
1059
+ null,
1060
+ array(
1061
+ 'unsigned' => true,
1062
+ 'nullable' => false,
1063
+ ),
1064
+ 'Store ID'
1065
+ )
1066
+ ->addColumn(
1067
+ 'updated_at',
1068
+ Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
1069
+ null,
1070
+ array(
1071
+ 'nullable' => false,
1072
+ 'default' => Varien_Db_Ddl_Table::TIMESTAMP_INIT,
1073
+ ),
1074
+ 'Row update time'
1075
+ )
1076
+ ->addColumn(
1077
+ 'created_at',
1078
+ Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
1079
+ null,
1080
+ array(
1081
+ 'nullable' => false,
1082
+ ),
1083
+ 'Row creation time'
1084
+ )
1085
+ ->addIndex(
1086
+ $installer->getIdxName(
1087
+ 'innobyte_emag_marketplace/category',
1088
+ array('emag_id', 'store_id'),
1089
+ Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
1090
+ ),
1091
+ array('emag_id', 'store_id'),
1092
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)
1093
+ )
1094
+ ->addForeignKey(
1095
+ $installer->getFkName(
1096
+ 'innobyte_emag_marketplace/category',
1097
+ 'store_id',
1098
+ 'core/store',
1099
+ 'store_id'
1100
+ ),
1101
+ 'store_id',
1102
+ $installer->getTable('core/store'),
1103
+ 'store_id',
1104
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
1105
+ Varien_Db_Ddl_Table::ACTION_CASCADE
1106
+ )
1107
+ ->setComment('eMAG categories');
1108
+ $installer->getConnection()->createTable($tableCategories);
1109
+
1110
+ // table 'innobyte_emag_marketplace_category_characteristic'
1111
+ $tableNameCategoryCharacteristic = $installer->getTable(
1112
+ 'innobyte_emag_marketplace/category_characteristic'
1113
+ );
1114
+ $installer->getConnection()->dropTable($tableNameCategoryCharacteristic);
1115
+ $tableCategoryCharacteristic = $installer->getConnection()
1116
+ ->newTable($tableNameCategoryCharacteristic)
1117
+ ->addColumn(
1118
+ 'id',
1119
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
1120
+ null,
1121
+ array(
1122
+ 'unsigned' => true,
1123
+ 'nullable' => false,
1124
+ 'primary' => true,
1125
+ 'identity' => true,
1126
+ ),
1127
+ 'The table \'s PK'
1128
+ )
1129
+ ->addColumn(
1130
+ 'emag_id',
1131
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
1132
+ null,
1133
+ array(
1134
+ 'nullable' => false,
1135
+ ),
1136
+ 'eMAG characteristic ID'
1137
+ )
1138
+ ->addColumn(
1139
+ 'category_id',
1140
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
1141
+ null,
1142
+ array(
1143
+ 'unsigned' => true,
1144
+ 'nullable' => false,
1145
+ ),
1146
+ 'Magento eMAG category id'
1147
+ )
1148
+ ->addColumn(
1149
+ 'name',
1150
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
1151
+ 255,
1152
+ array(
1153
+ 'nullable' => false,
1154
+ ),
1155
+ 'eMAG characteristic name'
1156
+ )
1157
+ ->addColumn(
1158
+ 'display_order',
1159
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
1160
+ null,
1161
+ array(
1162
+ 'nullable' => true,
1163
+ ),
1164
+ 'eMAG characteristic display order'
1165
+ )
1166
+ ->addIndex(
1167
+ $installer->getIdxName(
1168
+ 'innobyte_emag_marketplace/category_characteristic',
1169
+ array('emag_id', 'category_id'),
1170
+ Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
1171
+ ),
1172
+ array('emag_id', 'category_id'),
1173
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)
1174
+ )
1175
+ ->addForeignKey(
1176
+ $installer->getFkName(
1177
+ 'innobyte_emag_marketplace/category_characteristic',
1178
+ 'category_id',
1179
+ 'innobyte_emag_marketplace/category',
1180
+ 'id'
1181
+ ),
1182
+ 'category_id',
1183
+ $installer->getTable('innobyte_emag_marketplace/category'),
1184
+ 'id',
1185
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
1186
+ Varien_Db_Ddl_Table::ACTION_CASCADE
1187
+ )
1188
+ ->setComment('eMAG category characteristics');
1189
+ $installer->getConnection()->createTable($tableCategoryCharacteristic);
1190
+
1191
+ // table 'innobyte_emag_marketplace_category_familytype'
1192
+ $tableNameCategoryFamilytype = $installer->getTable(
1193
+ 'innobyte_emag_marketplace/category_familytype'
1194
+ );
1195
+ $installer->getConnection()->dropTable($tableNameCategoryFamilytype);
1196
+ $tableCategoryFamilytype = $installer->getConnection()
1197
+ ->newTable($tableNameCategoryFamilytype)
1198
+ ->addColumn(
1199
+ 'id',
1200
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
1201
+ null,
1202
+ array(
1203
+ 'unsigned' => true,
1204
+ 'nullable' => false,
1205
+ 'primary' => true,
1206
+ 'identity' => true,
1207
+ ),
1208
+ 'The table \'s PK'
1209
+ )
1210
+ ->addColumn(
1211
+ 'emag_id',
1212
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
1213
+ null,
1214
+ array(
1215
+ 'nullable' => false,
1216
+ ),
1217
+ 'eMAG characteristic ID'
1218
+ )
1219
+ ->addColumn(
1220
+ 'category_id',
1221
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
1222
+ null,
1223
+ array(
1224
+ 'unsigned' => true,
1225
+ 'nullable' => false,
1226
+ ),
1227
+ 'Magento eMAG category id'
1228
+ )
1229
+ ->addColumn(
1230
+ 'name',
1231
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
1232
+ 255,
1233
+ array(
1234
+ 'nullable' => false,
1235
+ ),
1236
+ 'eMAG family type name'
1237
+ )
1238
+ ->addIndex(
1239
+ $installer->getIdxName(
1240
+ 'innobyte_emag_marketplace/category_familytype',
1241
+ array('emag_id', 'category_id'),
1242
+ Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
1243
+ ),
1244
+ array('emag_id', 'category_id'),
1245
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)
1246
+ )
1247
+ ->addForeignKey(
1248
+ $installer->getFkName(
1249
+ 'innobyte_emag_marketplace/category_familytype',
1250
+ 'category_id',
1251
+ 'innobyte_emag_marketplace/category',
1252
+ 'id'
1253
+ ),
1254
+ 'category_id',
1255
+ $installer->getTable('innobyte_emag_marketplace/category'),
1256
+ 'id',
1257
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
1258
+ Varien_Db_Ddl_Table::ACTION_CASCADE
1259
+ )
1260
+ ->setComment('eMAG category family types');
1261
+ $installer->getConnection()->createTable($tableCategoryFamilytype);
1262
+
1263
+ // create table 'innobyte_emag_marketplace/category_familytype_characteristic'
1264
+ $tableNameCatFamilyCharacteristic = $installer->getTable(
1265
+ 'innobyte_emag_marketplace/category_familytype_characteristic'
1266
+ );
1267
+ $installer->getConnection()->dropTable($tableNameCatFamilyCharacteristic);
1268
+ $tableCatFamilyCharacteristic = $installer->getConnection()
1269
+ ->newTable($tableNameCatFamilyCharacteristic)
1270
+ ->addColumn(
1271
+ 'characteristic_id',
1272
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
1273
+ null,
1274
+ array(
1275
+ 'unsigned' => true,
1276
+ 'nullable' => false,
1277
+ 'primary' => true,
1278
+ ),
1279
+ 'eMAG characteristic id'
1280
+ )
1281
+ ->addColumn(
1282
+ 'family_type_id',
1283
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
1284
+ null,
1285
+ array(
1286
+ 'unsigned' => true,
1287
+ 'nullable' => false,
1288
+ 'primary' => true,
1289
+ ),
1290
+ 'Magento eMAG family type id'
1291
+ )
1292
+ ->addColumn(
1293
+ 'characteristic_family_type_id',
1294
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
1295
+ null,
1296
+ array(
1297
+ 'nullable' => true,
1298
+ ),
1299
+ 'Display type'
1300
+ )
1301
+ ->addColumn(
1302
+ 'is_foldable',
1303
+ Varien_Db_Ddl_Table::TYPE_TINYINT,
1304
+ null,
1305
+ array(
1306
+ 'nullable' => true,
1307
+ ),
1308
+ 'A foldable characteristic wraps all family members as one item'
1309
+ )
1310
+ ->addColumn(
1311
+ 'display_order',
1312
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
1313
+ null,
1314
+ array(
1315
+ 'nullable' => true,
1316
+ ),
1317
+ 'Display order'
1318
+ )
1319
+ ->addForeignKey(
1320
+ $installer->getFkName(
1321
+ 'innobyte_emag_marketplace/category_familytype_characteristic',
1322
+ 'family_type_id',
1323
+ 'innobyte_emag_marketplace/category_familytype',
1324
+ 'id'
1325
+ ),
1326
+ 'family_type_id',
1327
+ $installer->getTable('innobyte_emag_marketplace/category_familytype'),
1328
+ 'id',
1329
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
1330
+ Varien_Db_Ddl_Table::ACTION_CASCADE
1331
+ )
1332
+ ->setComment('Family types characteristics');
1333
+ $installer->getConnection()->createTable($tableCatFamilyCharacteristic);
1334
+
1335
+ // table 'innobyte_emag_marketplace_product'
1336
+ $tableNameProducts = $installer->getTable('innobyte_emag_marketplace/product');
1337
+ $installer->getConnection()->dropTable($tableNameProducts);
1338
+ $tableProducts = $installer->getConnection()
1339
+ ->newTable($tableNameProducts)
1340
+ ->addColumn(
1341
+ 'id',
1342
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
1343
+ null,
1344
+ array(
1345
+ 'unsigned' => true,
1346
+ 'nullable' => false,
1347
+ 'primary' => true,
1348
+ 'identity' => true,
1349
+ ),
1350
+ 'The table \'s PK'
1351
+ )
1352
+ ->addColumn(
1353
+ 'product_id',
1354
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
1355
+ null,
1356
+ array(
1357
+ 'unsigned' => true,
1358
+ 'nullable' => false,
1359
+ ),
1360
+ 'Magento product id'
1361
+ )
1362
+ ->addColumn(
1363
+ 'part_number_key',
1364
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
1365
+ 255,
1366
+ array(
1367
+ 'nullable' => true,
1368
+ ),
1369
+ 'eMAG part number key'
1370
+ )
1371
+ ->addColumn(
1372
+ 'name',
1373
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
1374
+ 255,
1375
+ array(
1376
+ 'nullable' => true,
1377
+ ),
1378
+ 'eMAG product name'
1379
+ )
1380
+ ->addColumn(
1381
+ 'brand',
1382
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
1383
+ 255,
1384
+ array(
1385
+ 'nullable' => true,
1386
+ ),
1387
+ 'eMAG product brand'
1388
+ )
1389
+ // this is altered afterwards to mediumtext
1390
+ ->addColumn(
1391
+ 'description',
1392
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
1393
+ 255,
1394
+ array(
1395
+ 'nullable' => true,
1396
+ ),
1397
+ 'eMAG product desc'
1398
+ )
1399
+ ->addColumn(
1400
+ 'warranty',
1401
+ Varien_Db_Ddl_Table::TYPE_SMALLINT,
1402
+ null,
1403
+ array(
1404
+ 'nullable' => true,
1405
+ 'unsigned' => true,
1406
+ ),
1407
+ 'eMAG product warranty'
1408
+ )
1409
+ ->addColumn(
1410
+ 'commission_type',
1411
+ Varien_Db_Ddl_Table::TYPE_TINYINT,
1412
+ null,
1413
+ array(
1414
+ 'nullable' => false,
1415
+ 'default' => '1',
1416
+ ),
1417
+ 'eMAG commission type'
1418
+ )
1419
+ ->addColumn(
1420
+ 'commission_value',
1421
+ Varien_Db_Ddl_Table::TYPE_DECIMAL,
1422
+ '12,4',
1423
+ array(
1424
+ 'nullable' => false,
1425
+ 'unsigned' => true,
1426
+ ),
1427
+ 'eMAG commission value'
1428
+ )
1429
+ ->addColumn(
1430
+ 'category_id',
1431
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
1432
+ null,
1433
+ array(
1434
+ 'nullable' => true,
1435
+ 'unsigned' => true,
1436
+ ),
1437
+ 'Magento eMAG category id'
1438
+ )
1439
+ ->addColumn(
1440
+ 'family_type_id',
1441
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
1442
+ null,
1443
+ array(
1444
+ 'nullable' => true,
1445
+ 'unsigned' => true,
1446
+ ),
1447
+ 'Magento id of eMAG family type'
1448
+ )
1449
+ ->addColumn(
1450
+ 'handling_time',
1451
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
1452
+ null,
1453
+ array(
1454
+ 'nullable' => true,
1455
+ 'unsigned' => true,
1456
+ ),
1457
+ 'Handling time'
1458
+ )
1459
+ ->addColumn(
1460
+ 'status',
1461
+ Varien_Db_Ddl_Table::TYPE_TINYINT,
1462
+ null,
1463
+ array(
1464
+ 'nullable' => false,
1465
+ 'default' => 0,
1466
+ ),
1467
+ 'Vendor offer status'
1468
+ )
1469
+ ->addColumn(
1470
+ 'start_date',
1471
+ Varien_Db_Ddl_Table::TYPE_DATE,
1472
+ null,
1473
+ array(
1474
+ 'nullable' => true,
1475
+ ),
1476
+ 'eMAG offer start date'
1477
+ )
1478
+ ->addColumn(
1479
+ 'store_id',
1480
+ Varien_Db_Ddl_Table::TYPE_SMALLINT,
1481
+ null,
1482
+ array(
1483
+ 'unsigned' => true,
1484
+ 'nullable' => false,
1485
+ ),
1486
+ 'Store ID'
1487
+ )
1488
+ ->addColumn(
1489
+ 'vat_id',
1490
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
1491
+ null,
1492
+ array(
1493
+ 'unsigned' => true,
1494
+ 'nullable' => true,
1495
+ ),
1496
+ 'Store ID'
1497
+ )
1498
+ ->addColumn(
1499
+ 'is_synced',
1500
+ Varien_Db_Ddl_Table::TYPE_TINYINT,
1501
+ 1,
1502
+ array(
1503
+ 'unsigned' => true,
1504
+ 'default' => 0,
1505
+ ),
1506
+ 'Whether product has been sent to eMAG'
1507
+ )
1508
+ ->addColumn(
1509
+ 'updated_at',
1510
+ Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
1511
+ null,
1512
+ array(
1513
+ 'nullable' => false,
1514
+ 'default' => Varien_Db_Ddl_Table::TIMESTAMP_INIT,
1515
+ ),
1516
+ 'Row update time'
1517
+ )
1518
+ ->addColumn(
1519
+ 'created_at',
1520
+ Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
1521
+ null,
1522
+ array(
1523
+ 'nullable' => false,
1524
+ ),
1525
+ 'Row creation time'
1526
+ )
1527
+ ->addIndex(
1528
+ $installer->getIdxName(
1529
+ 'innobyte_emag_marketplace/category',
1530
+ array('product_id', 'store_id'),
1531
+ Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
1532
+ ),
1533
+ array('product_id', 'store_id'),
1534
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)
1535
+ )
1536
+ ->addForeignKey(
1537
+ $installer->getFkName(
1538
+ 'innobyte_emag_marketplace/product',
1539
+ 'store_id',
1540
+ 'core/store',
1541
+ 'store_id'
1542
+ ),
1543
+ 'store_id',
1544
+ $installer->getTable('core/store'),
1545
+ 'store_id',
1546
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
1547
+ Varien_Db_Ddl_Table::ACTION_CASCADE
1548
+ )
1549
+ ->addForeignKey(
1550
+ $installer->getFkName(
1551
+ 'innobyte_emag_marketplace/product',
1552
+ 'product_id',
1553
+ 'catalog/product',
1554
+ 'entity_id'
1555
+ ),
1556
+ 'product_id',
1557
+ $installer->getTable('catalog/product'),
1558
+ 'entity_id',
1559
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
1560
+ Varien_Db_Ddl_Table::ACTION_CASCADE
1561
+ )
1562
+ ->addForeignKey(
1563
+ $installer->getFkName(
1564
+ 'innobyte_emag_marketplace/product',
1565
+ 'vat_id',
1566
+ 'innobyte_emag_marketplace/vat',
1567
+ 'id'
1568
+ ),
1569
+ 'vat_id',
1570
+ $installer->getTable('innobyte_emag_marketplace/vat'),
1571
+ 'id',
1572
+ Varien_Db_Ddl_Table::ACTION_SET_NULL,
1573
+ Varien_Db_Ddl_Table::ACTION_CASCADE
1574
+ )
1575
+ ->addForeignKey(
1576
+ $installer->getFkName(
1577
+ 'innobyte_emag_marketplace/product',
1578
+ 'category_id',
1579
+ 'innobyte_emag_marketplace/category',
1580
+ 'id'
1581
+ ),
1582
+ 'category_id',
1583
+ $installer->getTable('innobyte_emag_marketplace/category'),
1584
+ 'id',
1585
+ Varien_Db_Ddl_Table::ACTION_SET_NULL,
1586
+ Varien_Db_Ddl_Table::ACTION_CASCADE
1587
+ )
1588
+ ->addForeignKey(
1589
+ $installer->getFkName(
1590
+ 'innobyte_emag_marketplace/product',
1591
+ 'family_type_id',
1592
+ 'innobyte_emag_marketplace/category_familytype',
1593
+ 'id'
1594
+ ),
1595
+ 'family_type_id',
1596
+ $installer->getTable('innobyte_emag_marketplace/category_familytype'),
1597
+ 'id',
1598
+ Varien_Db_Ddl_Table::ACTION_SET_NULL,
1599
+ Varien_Db_Ddl_Table::ACTION_CASCADE
1600
+ )
1601
+ ->setComment('eMAG product data');
1602
+ $installer->getConnection()->createTable($tableProducts);
1603
+ // hack since magento does not have mediumtext column type
1604
+ // in order to create it direcly as mediumtext
1605
+ $installer->getConnection()
1606
+ ->changeColumn(
1607
+ $tableNameProducts,
1608
+ 'description',
1609
+ 'description',
1610
+ 'MEDIUMTEXT NULL'
1611
+ );
1612
+
1613
+ // table 'innobyte_emag_marketplace_product_barcode'
1614
+ $tableNameProdBarcodes = $installer->getTable(
1615
+ 'innobyte_emag_marketplace/product_barcode'
1616
+ );
1617
+ $installer->getConnection()->dropTable($tableNameProdBarcodes);
1618
+ $tableProdBarcodes = $installer->getConnection()
1619
+ ->newTable($tableNameProdBarcodes)
1620
+ ->addColumn(
1621
+ 'id',
1622
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
1623
+ null,
1624
+ array(
1625
+ 'unsigned' => true,
1626
+ 'nullable' => false,
1627
+ 'primary' => true,
1628
+ 'identity' => true,
1629
+ ),
1630
+ 'The table \'s PK'
1631
+ )
1632
+ ->addColumn(
1633
+ 'product_id',
1634
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
1635
+ null,
1636
+ array(
1637
+ 'unsigned' => true,
1638
+ 'nullable' => false,
1639
+ ),
1640
+ 'FK innobyte_emag_marketplace_product table'
1641
+ )
1642
+ ->addColumn(
1643
+ 'value',
1644
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
1645
+ 20,
1646
+ array(
1647
+ 'nullable' => false,
1648
+ ),
1649
+ 'product barcode'
1650
+ )
1651
+ ->addForeignKey(
1652
+ $installer->getFkName(
1653
+ 'innobyte_emag_marketplace/product_barcode',
1654
+ 'product_id',
1655
+ 'innobyte_emag_marketplace/product',
1656
+ 'id'
1657
+ ),
1658
+ 'product_id',
1659
+ $installer->getTable('innobyte_emag_marketplace/product'),
1660
+ 'id',
1661
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
1662
+ Varien_Db_Ddl_Table::ACTION_CASCADE
1663
+ )
1664
+ ->setComment('Product barcodes');
1665
+ $installer->getConnection()->createTable($tableProdBarcodes);
1666
+
1667
+ // innobyte_emag_marketplace_product_cat_characteristic
1668
+ $tableNameProdCatChar = $installer->getTable(
1669
+ 'innobyte_emag_marketplace/product_cat_characteristic'
1670
+ );
1671
+ $installer->getConnection()->dropTable($tableNameProdCatChar);
1672
+ $tableProdCatChar = $installer->getConnection()
1673
+ ->newTable($tableNameProdCatChar)
1674
+ ->addColumn(
1675
+ 'id',
1676
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
1677
+ null,
1678
+ array(
1679
+ 'unsigned' => true,
1680
+ 'nullable' => false,
1681
+ 'primary' => true,
1682
+ 'identity' => true,
1683
+ ),
1684
+ 'The table \'s PK'
1685
+ )
1686
+ ->addColumn(
1687
+ 'product_id',
1688
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
1689
+ null,
1690
+ array(
1691
+ 'unsigned' => true,
1692
+ 'nullable' => false,
1693
+ ),
1694
+ 'FK innobyte_emag_marketplace_product table'
1695
+ )
1696
+ ->addColumn(
1697
+ 'characteristic_id',
1698
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
1699
+ null,
1700
+ array(
1701
+ 'nullable' => false,
1702
+ 'unsigned' => true,
1703
+ ),
1704
+ 'FK innobyte_emag_marketplace_category_characteristic table'
1705
+ )
1706
+ ->addColumn(
1707
+ 'value',
1708
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
1709
+ 255,
1710
+ array(
1711
+ 'nullable' => false,
1712
+ ),
1713
+ 'Characteristic value'
1714
+ )
1715
+ ->addForeignKey(
1716
+ $installer->getFkName(
1717
+ 'innobyte_emag_marketplace/product_cat_characteristic',
1718
+ 'product_id',
1719
+ 'innobyte_emag_marketplace/product',
1720
+ 'id'
1721
+ ),
1722
+ 'product_id',
1723
+ $installer->getTable('innobyte_emag_marketplace/product'),
1724
+ 'id',
1725
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
1726
+ Varien_Db_Ddl_Table::ACTION_CASCADE
1727
+ )
1728
+ ->addForeignKey(
1729
+ $installer->getFkName(
1730
+ 'innobyte_emag_marketplace/product_cat_characteristic',
1731
+ 'characteristic_id',
1732
+ 'innobyte_emag_marketplace/category_characteristic',
1733
+ 'id'
1734
+ ),
1735
+ 'product_id',
1736
+ $installer->getTable('innobyte_emag_marketplace/category_characteristic'),
1737
+ 'id',
1738
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
1739
+ Varien_Db_Ddl_Table::ACTION_CASCADE
1740
+ )
1741
+ ->setComment('Product \'s category characteristics values');
1742
+ $installer->getConnection()->createTable($tableProdCatChar);
1743
+
1744
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/innobyte/core.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <adminhtml_system_config_edit>
4
+ <reference name="content">
5
+ <block type="innobyte_core/shop" name="innobyte_core_shop" template="innobyte/core/shop.phtml"></block>
6
+ </reference>
7
+ </adminhtml_system_config_edit>
8
+ </layout>
app/design/adminhtml/default/default/layout/innobyte/emag_marketplace.xml ADDED
@@ -0,0 +1,337 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <layout>
3
+ <adminhtml_sales_order_view>
4
+ <reference name="head">
5
+ <action method="addItem">
6
+ <type>js_css</type>
7
+ <name>prototype/windows/themes/default.css</name>
8
+ </action>
9
+ <action method="addCss">
10
+ <name>lib/prototype/windows/themes/magento.css</name>
11
+ </action>
12
+ </reference>
13
+ <reference name="content">
14
+ <block type="innobyte_emag_marketplace/adminhtml_sales_order_view_invoice_popup"
15
+ name='emag_invoice_popup'
16
+ template="innobyte/emag_marketplace/sales/order/view/invoice/popup.phtml">
17
+ </block>
18
+ </reference>
19
+ <reference name="order_totals">
20
+ <block type="adminhtml/sales_order_totals_item"
21
+ name="emag_voucher"
22
+ template="innobyte/emag_marketplace/sales/order/totals.phtml">
23
+ <action method="setBeforeCondition">
24
+ <condition>discount</condition>
25
+ </action>
26
+ </block>
27
+ </reference>
28
+ <reference name="order_tab_info">
29
+ <action method="setTemplate">
30
+ <template>innobyte/emag_marketplace/sales/order/view/tab/info.phtml</template>
31
+ </action>
32
+ <block type="innobyte_emag_marketplace/adminhtml_sales_order_view_comment" name="emag_customer_comment"
33
+ template="innobyte/emag_marketplace/sales/order/view/comment.phtml"/>
34
+ </reference>
35
+ </adminhtml_sales_order_view>
36
+
37
+ <adminhtml_sales_invoice_upload_popup>
38
+ <update handle="editor"/>
39
+ <reference name="content">
40
+ <block type="innobyte_emag_marketplace/adminhtml_sales_order_view_invoice_upload"
41
+ name="emag_invoice_upload">
42
+ <block type="innobyte_emag_marketplace/adminhtml_sales_order_view_invoice_upload_form"
43
+ name="form"/>
44
+ </block>
45
+ </reference>
46
+ <remove name="footer"/>
47
+ </adminhtml_sales_invoice_upload_popup>
48
+
49
+ <adminhtml_sales_order_invoice_new>
50
+ <reference name="invoice_totals">
51
+ <block type="adminhtml/sales_order_totals_item"
52
+ name="emag_voucher"
53
+ template="innobyte/emag_marketplace/sales/order/totals.phtml">
54
+ <action method="setBeforeCondition">
55
+ <condition>discount</condition>
56
+ </action>
57
+ </block>
58
+ </reference>
59
+ </adminhtml_sales_order_invoice_new>
60
+
61
+ <adminhtml_sales_order_invoice_updateqty>
62
+ <reference name="invoice_totals">
63
+ <block type="adminhtml/sales_order_totals_item"
64
+ name="emag_voucher"
65
+ template="innobyte/emag_marketplace/sales/order/totals.phtml">
66
+ <action method="setBeforeCondition">
67
+ <condition>discount</condition>
68
+ </action>
69
+ </block>
70
+ </reference>
71
+ </adminhtml_sales_order_invoice_updateqty>
72
+
73
+ <adminhtml_sales_order_invoice_view>
74
+ <reference name="invoice_totals">
75
+ <block type="adminhtml/sales_order_totals_item"
76
+ name="emag_voucher"
77
+ template="innobyte/emag_marketplace/sales/order/totals.phtml">
78
+ <action method="setBeforeCondition">
79
+ <condition>discount</condition>
80
+ </action>
81
+ </block>
82
+ </reference>
83
+ </adminhtml_sales_order_invoice_view>
84
+
85
+ <adminhtml_sales_order_creditmemo_new>
86
+ <reference name="creditmemo_totals">
87
+ <block type="adminhtml/sales_order_totals_item"
88
+ name="emag_voucher"
89
+ template="innobyte/emag_marketplace/sales/order/totals.phtml">
90
+ <action method="setBeforeCondition">
91
+ <condition>discount</condition>
92
+ </action>
93
+ </block>
94
+ </reference>
95
+ </adminhtml_sales_order_creditmemo_new>
96
+
97
+ <adminhtml_sales_order_creditmemo_updateqty>
98
+ <reference name="creditmemo_totals">
99
+ <block type="adminhtml/sales_order_totals_item"
100
+ name="emag_voucher"
101
+ template="innobyte/emag_marketplace/sales/order/totals.phtml">
102
+ <action method="setBeforeCondition">
103
+ <condition>discount</condition>
104
+ </action>
105
+ </block>
106
+ </reference>
107
+ </adminhtml_sales_order_creditmemo_updateqty>
108
+
109
+ <adminhtml_sales_order_create_index>
110
+ <reference name="shipping_method">
111
+ <block type="innobyte_emag_marketplace/adminhtml_sales_order_create_shipping_method_form"
112
+ template="innobyte/emag_marketplace/sales/order/create/shipping/method/form.phtml" name="form"/>
113
+ </reference>
114
+ <reference name="billing_method">
115
+ <block type="innobyte_emag_marketplace/adminhtml_sales_order_create_billing_method_form"
116
+ template="sales/order/create/billing/method/form.phtml" name="form"/>
117
+ </reference>
118
+ </adminhtml_sales_order_create_index>
119
+
120
+ <adminhtml_sales_order_edit_index>
121
+ <reference name="head">
122
+ <action method="addItem">
123
+ <type>skin_js</type>
124
+ <script>js/innobyte/emag_marketplace/protolicius/event.simulate.js</script>
125
+ </action>
126
+ <action method="addItem">
127
+ <type>skin_js</type>
128
+ <script>js/innobyte/emag_marketplace/locality.js</script>
129
+ </action>
130
+ <action method="addItem">
131
+ <type>skin_css</type>
132
+ <name>css/innobyte/emag_marketplace/style.css</name>
133
+ </action>
134
+ </reference>
135
+ <reference name="shipping_address">
136
+ <action method="setTemplate">
137
+ <new_template>innobyte/emag_marketplace/sales/order/create/form/address.phtml</new_template>
138
+ </action>
139
+ </reference>
140
+ <reference name="billing_address">
141
+ <action method="setTemplate">
142
+ <new_template>innobyte/emag_marketplace/sales/order/create/form/address.phtml</new_template>
143
+ </action>
144
+ </reference>
145
+ <reference name="items">
146
+ <block type="innobyte_emag_marketplace/adminhtml_sales_order_create_items_grid"
147
+ template="innobyte/emag_marketplace/sales/order/create/items/grid.phtml"
148
+ name="items_grid">
149
+ <block type="adminhtml/sales_order_create_coupons" template="sales/order/create/coupons/form.phtml"
150
+ name="coupons">
151
+ <block type="adminhtml/sales_order_create_coupons_form"
152
+ template="sales/order/create/coupons/form.phtml" name="form"/>
153
+ </block>
154
+ </block>
155
+ </reference>
156
+ </adminhtml_sales_order_edit_index>
157
+
158
+ <adminhtml_sales_order_create_load_block_data>
159
+ <reference name="items">
160
+ <block type="innobyte_emag_marketplace/adminhtml_sales_order_create_items_grid"
161
+ template="innobyte/emag_marketplace/sales/order/create/items/grid.phtml"
162
+ name="items_grid">
163
+ <block type="adminhtml/sales_order_create_coupons" template="sales/order/create/coupons/form.phtml"
164
+ name="coupons">
165
+ <block type="innobyte_emag_marketplace/adminhtml_sales_order_create_coupons_form"
166
+ template="sales/order/create/coupons/form.phtml" name="form"/>
167
+ </block>
168
+ </block>
169
+ </reference>
170
+ <reference name="shipping_method">
171
+ <block type="innobyte_emag_marketplace/adminhtml_sales_order_create_shipping_method_form"
172
+ template="innobyte/emag_marketplace/sales/order/create/shipping/method/form.phtml" name="form"/>
173
+ </reference>
174
+ <reference name="billing_method">
175
+ <block type="innobyte_emag_marketplace/adminhtml_sales_order_create_billing_method_form"
176
+ template="sales/order/create/billing/method/form.phtml" name="form"/>
177
+ </reference>
178
+ <reference name="shipping_address">
179
+ <action method="setTemplate">
180
+ <new_template>innobyte/emag_marketplace/sales/order/create/form/address.phtml</new_template>
181
+ </action>
182
+ </reference>
183
+ <reference name="billing_address">
184
+ <action method="setTemplate">
185
+ <new_template>innobyte/emag_marketplace/sales/order/create/form/address.phtml</new_template>
186
+ </action>
187
+ </reference>
188
+ </adminhtml_sales_order_create_load_block_data>
189
+
190
+ <adminhtml_sales_order_create_load_block_items>
191
+ <reference name="items">
192
+ <block type="innobyte_emag_marketplace/adminhtml_sales_order_create_items_grid"
193
+ template="innobyte/emag_marketplace/sales/order/create/items/grid.phtml"
194
+ name="items_grid">
195
+ <block type="adminhtml/sales_order_create_coupons" template="sales/order/create/coupons/form.phtml"
196
+ name="coupons">
197
+ <block type="adminhtml/sales_order_create_coupons_form"
198
+ template="sales/order/create/coupons/form.phtml" name="form"/>
199
+ </block>
200
+ </block>
201
+ </reference>
202
+ </adminhtml_sales_order_create_load_block_items>
203
+
204
+ <adminhtml_sales_order_create_load_block_shipping_method>
205
+ <reference name="shipping_method">
206
+ <block type="innobyte_emag_marketplace/adminhtml_sales_order_create_shipping_method_form"
207
+ template="innobyte/emag_marketplace/sales/order/create/shipping/method/form.phtml" name="form"/>
208
+ </reference>
209
+ </adminhtml_sales_order_create_load_block_shipping_method>
210
+
211
+ <adminhtml_sales_order_create_load_block_billing_method>
212
+ <reference name="billing_method">
213
+ <block type="innobyte_emag_marketplace/adminhtml_sales_order_create_billing_method_form"
214
+ template="sales/order/create/billing/method/form.phtml" name="form"/>
215
+ </reference>
216
+ </adminhtml_sales_order_create_load_block_billing_method>
217
+
218
+ <adminhtml_sales_order_create_load_block_shipping_address>
219
+ <reference name="shipping_address">
220
+ <action method="setTemplate">
221
+ <new_template>innobyte/emag_marketplace/sales/order/create/form/address.phtml</new_template>
222
+ </action>
223
+ </reference>
224
+ </adminhtml_sales_order_create_load_block_shipping_address>
225
+
226
+ <adminhtml_sales_order_create_load_block_billing_address>
227
+ <reference name="billing_address">
228
+ <action method="setTemplate">
229
+ <new_template>innobyte/emag_marketplace/sales/order/create/form/address.phtml</new_template>
230
+ </action>
231
+ </reference>
232
+ </adminhtml_sales_order_create_load_block_billing_address>
233
+
234
+ <adminhtml_sales_order_shipment_new>
235
+ <reference name="head">
236
+ <action method="addItem">
237
+ <type>skin_js</type>
238
+ <script>js/innobyte/emag_marketplace/packaging.js</script>
239
+ </action>
240
+ </reference>
241
+ <reference name="shipment_packaging">
242
+ <action method="setTemplate">
243
+ <template>innobyte/emag_marketplace/sales/order/shipment/packaging/popup.phtml</template>
244
+ </action>
245
+ </reference>
246
+ </adminhtml_sales_order_shipment_new>
247
+
248
+ <adminhtml_sales_order_shipment_view>
249
+ <reference name="head">
250
+ <action method="addItem">
251
+ <type>skin_js</type>
252
+ <script>js/innobyte/emag_marketplace/packaging.js</script>
253
+ </action>
254
+ </reference>
255
+ <reference name="shipment_packaging">
256
+ <action method="setTemplate">
257
+ <template>innobyte/emag_marketplace/sales/order/shipment/packaging/popup.phtml</template>
258
+ </action>
259
+ </reference>
260
+ </adminhtml_sales_order_shipment_view>
261
+
262
+ <adminhtml_emag_category_index>
263
+ <reference name="head">
264
+ <action method="addItem">
265
+ <type>skin_js</type>
266
+ <script>js/innobyte/emag_marketplace/category.js</script>
267
+ </action>
268
+ </reference>
269
+ <reference name="content">
270
+ <block type="adminhtml/store_switcher" name="store_switcher" as="store_switcher">
271
+ <action method="setUseConfirm">
272
+ <params>0</params>
273
+ </action>
274
+ </block>
275
+ <block type="innobyte_emag_marketplace/adminhtml_category"
276
+ name="inno.emag.category.grid.container"/>
277
+ </reference>
278
+ </adminhtml_emag_category_index>
279
+
280
+ <adminhtml_emag_vat_index>
281
+ <reference name="head">
282
+ <action method="addItem">
283
+ <type>skin_js</type>
284
+ <script>js/innobyte/emag_marketplace/vat.js</script>
285
+ </action>
286
+ </reference>
287
+ <reference name="content">
288
+ <block type="adminhtml/store_switcher" name="store_switcher" as="store_switcher">
289
+ <action method="setUseConfirm">
290
+ <params>0</params>
291
+ </action>
292
+ </block>
293
+ <block type="innobyte_emag_marketplace/adminhtml_vat"
294
+ name="inno.emag.vat.grid.container"/>
295
+ </reference>
296
+ </adminhtml_emag_vat_index>
297
+
298
+ <adminhtml_emag_locality_index>
299
+ <reference name="head">
300
+ <action method="addItem">
301
+ <type>skin_js</type>
302
+ <script>js/innobyte/emag_marketplace/locality.js</script>
303
+ </action>
304
+ </reference>
305
+ <reference name="content">
306
+ <block type="adminhtml/store_switcher" name="store_switcher" as="store_switcher">
307
+ <action method="setUseConfirm">
308
+ <params>0</params>
309
+ </action>
310
+ </block>
311
+ <block type="innobyte_emag_marketplace/adminhtml_locality"
312
+ name="inno.emag.locality.grid.container"/>
313
+ </reference>
314
+ </adminhtml_emag_locality_index>
315
+
316
+ <adminhtml_catalog_product_edit>
317
+ <reference name="head">
318
+ <action method="addItem">
319
+ <type>skin_js</type>
320
+ <script>js/innobyte/emag_marketplace/product.js</script>
321
+ </action>
322
+ <action method="addItem">
323
+ <type>skin_css</type>
324
+ <name>css/innobyte/emag_marketplace/style.css</name>
325
+ </action>
326
+ </reference>
327
+ <reference name="product_tabs">
328
+ <action method="addTab">
329
+ <name>innobyte_emag_marketplace_tab</name>
330
+ <block>innobyte_emag_marketplace/adminhtml_catalog_product_edit_tab_emagMarketplace</block>
331
+ </action>
332
+ </reference>
333
+ <reference name="product_edit">
334
+ <action method="setTemplate"><path>innobyte/emag_marketplace/catalog/product/edit.phtml</path></action>
335
+ </reference>
336
+ </adminhtml_catalog_product_edit>
337
+ </layout>
app/design/adminhtml/default/default/template/innobyte/core/button.phtml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <?php echo $this->getButtonHtml();?>
3
+
4
+ <script type="text/javascript">
5
+ //<![CDATA[
6
+ // init inno namespace if case
7
+ var inno = inno || {};
8
+ // init core namespace if case
9
+ inno.core = inno.core || {} ;
10
+ inno.core.sendReport = function () {
11
+ new Ajax.Request('<?php echo $this->getAjaxSendReportUrl() ?>', {
12
+ method: 'POST',
13
+ parameters: {'message':$('innobyte_core_debugger_explanation_message').value},
14
+ onSuccess: function (transport) {
15
+ var response = transport.responseText.evalJSON();
16
+ if (response.code) {
17
+ alert(response.message);
18
+ }
19
+ }
20
+ });
21
+ }
22
+ //]]>
23
+ </script>
app/design/adminhtml/default/default/template/innobyte/core/debugger_email/cron.phtml ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <?php $_magento = $this->getMagento(); ?>
3
+ <?php if (isset($_magento['crontab'])) : ?>
4
+ <?php foreach ($_magento['crontab'] as $_code=>$_info): ?>
5
+ <li style="list-style:none inside; padding:0 0 0 10px; margin-top: 15px;">
6
+ <div style="display:block; overflow: hidden;">
7
+ <?php echo $_info; ?><br/>
8
+ </div>
9
+ </li>
10
+ <?php endforeach; ?>
11
+ <?php endif; ?>
12
+
13
+ <hr/>
14
+
15
+
16
+
17
+ <?php if (isset($_magento['crons'])) : ?>
18
+ <ul style="font-size:12px; line-height:16px; margin:0 0 16px 0; padding:0;">
19
+ <?php foreach ($_magento['crons'] as $_code=>$_info): ?>
20
+ <li style="list-style:none inside; padding:0 0 0 10px; margin-top: 15px;">
21
+ <div style="display:block; overflow: hidden;">
22
+ <div style="width:38%;float:left;">
23
+ <strong><?php echo $_code; ?></strong><br/>
24
+ &nbsp; <?php echo $_info['info']['cron_expr']; ?></br>
25
+ <?php echo $_info['info']['model']; ?>
26
+ </div>
27
+ <div style="width:12%;float:left;">
28
+ <?php if (isset($_info['schedule'])) : ?>
29
+ <?php echo $_info['schedule']['status']; ?>
30
+ <?php endif; ?>
31
+
32
+ </div>
33
+ <div style="width:50%;float:left;font-family:monospace;">
34
+ <?php if (isset($_info['schedule'])) : ?>
35
+ messages&nbsp;&nbsp;&nbsp;&nbsp;: <?php echo $_info['schedule']['messages']; ?><br/>
36
+ created_at&nbsp;&nbsp;: <?php echo $_info['schedule']['created_at']; ?><br/>
37
+ scheduled_at: <?php echo $_info['schedule']['scheduled_at']; ?><br/>
38
+ executed_at&nbsp;: <?php echo $_info['schedule']['executed_at']; ?><br/>
39
+ finished_at&nbsp;: <?php echo $_info['schedule']['finished_at']; ?><br/>
40
+ <?php endif; ?>
41
+ </div>
42
+
43
+ </div>
44
+ </li>
45
+ <?php endforeach; ?>
46
+ </ul>
47
+ <?php else: ?>
48
+ --- No cron jobs found
49
+ <?php endif; ?>
app/design/adminhtml/default/default/template/innobyte/core/debugger_email/disabled_extensions.phtml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $_magento = $this->getMagento(); ?>
2
+
3
+ <?php if (isset($_magento['disabled_modules'])) : ?>
4
+ <ul style="font-size:12px; line-height:16px; margin:0 0 16px 0; padding:0;">
5
+ <?php foreach ($_magento['disabled_modules'] as $_key=>$_extension): ?>
6
+ <li style="list-style:none inside; padding:0 0 0 10px;">
7
+ &ndash; <?php echo $_extension; ?>
8
+ </li>
9
+ <?php endforeach; ?>
10
+ </ul>
11
+ <?php else: ?>
12
+ --- no extension found
13
+ <?php endif; ?>
app/design/adminhtml/default/default/template/innobyte/core/debugger_email/general.phtml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $_magento = $this->getMagento(); ?>
2
+
3
+ <strong>Magento edition</strong>: <?php echo $_magento['edition'] ?><br/>
4
+ <strong>Magento version</strong>: <?php echo $_magento['version'] ?><br/>
5
+ <strong>Compilation</strong>: <?php echo $_magento['compilation'] ?><br/>
6
+ <strong>Magento Domains</strong>:
7
+
8
+
9
+ <?php foreach ($_magento['domains'] as $_key=>$_domain): ?>
10
+ <?php echo $_domain; ?><br/>
11
+ <?php endforeach; ?>
app/design/adminhtml/default/default/template/innobyte/core/debugger_email/inno_config_data.phtml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $_magento = $this->getMagento(); ?>
2
+
3
+ <?php if (isset($_magento['inno_extensions_info'])) : ?>
4
+ <ul style="font-size:12px; line-height:16px; margin:0 0 16px 0; padding:0;">
5
+ <?php foreach ($_magento['inno_extensions_info'] as $_key=>$_item): ?>
6
+ <li style="list-style:none inside; padding:0 0 0 10px;">
7
+ <div style="width: 300px;float:left;font-family:monospace;">
8
+ <?php echo $_item['path']; ?>
9
+ </div>
10
+ <div style="width: 200px;float:left;margin-bottom: 15px;">
11
+ <?php echo $_item['value']; ?>
12
+ </div>
13
+ <div style="clear: both"></div>
14
+ </li>
15
+ <?php endforeach; ?>
16
+ </ul>
17
+ <?php else: ?>
18
+ --- no innobyte extension config data found
19
+ <?php endif; ?>
20
+ <div style="clear: both"></div>
app/design/adminhtml/default/default/template/innobyte/core/debugger_email/inno_extensions.phtml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $_magento = $this->getMagento(); ?>
2
+
3
+ <?php if (isset($_magento['inno_extensions'])) : ?>
4
+ <ul style="font-size:12px; line-height:16px; margin:0 0 16px 0; padding:0;">
5
+ <?php foreach ($_magento['inno_extensions'] as $_key=>$_extension): ?>
6
+ <li style="list-style:none inside; padding:0 0 0 10px;">
7
+ &ndash; <?php echo $_extension['name']; ?> - v<?php echo $_extension['version']; ?>
8
+ </li>
9
+ <?php endforeach; ?>
10
+ </ul>
11
+ <?php else: ?>
12
+ --- no extension found
13
+ <?php endif; ?>
app/design/adminhtml/default/default/template/innobyte/core/debugger_email/rewrites.phtml ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <?php $_magento = $this->getMagento(); ?>
3
+
4
+ <?php if (isset($_magento['rewrites']) && !empty($_magento['rewrites']) ) : ?>
5
+ <ul style="font-size:12px; line-height:16px; margin:0 0 16px 0; padding:0;">
6
+ <?php foreach ($_magento['rewrites'] as $_type=>$_rewrite): ?>
7
+ <li style="list-style:none inside; padding:0 0 0 10px; margin-top: 15px;">
8
+ <div style="display:block; overflow: hidden;">
9
+ <div style="border-bottom: 1px solid #CCCCCC;font-weight: bold;">
10
+ &ndash; <?php echo $_type; ?><br/>
11
+ </div>
12
+
13
+ <div style="margin-left:25px">
14
+ <?php foreach ($_rewrite as $_class=>$_rewrites): ?>
15
+ <div style="width: 30%;float:left;font-family:monospace;">
16
+ <?php echo $_class; ?>
17
+ </div>
18
+ <div style="width: 70%;float:left;margin-bottom: 15px;">
19
+ <?php foreach ($_rewrites as $_key=>$_rewriteClass): ?>
20
+ <?php echo $_rewriteClass; ?><br/>
21
+ <?php endforeach; ?>
22
+ </div>
23
+ <?php endforeach; ?>
24
+ </div>
25
+ </div>
26
+ </li>
27
+ <?php endforeach; ?>
28
+ </ul>
29
+ <?php else: ?>
30
+ --- no rewrites
31
+ <?php endif; ?>
app/design/adminhtml/default/default/template/innobyte/core/shop.phtml ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if ($this->configPage == 'innobyte_core'): ?>
2
+ <div id="innobyte_core_extensions_hidden" style="display:none;">
3
+ <table class="form-list">
4
+ <tbody>
5
+ <?php foreach ($this->getExtensions() as $extension): ?>
6
+ <tr>
7
+ <td>
8
+ <img src="<?php echo $this->getIcon($extension)->getSource()?>"
9
+ alt="<?php echo $this->getIcon($extension)->getTitle()?>"/>
10
+ </td>
11
+ <td>
12
+ <a href="<?php echo $extension->getFeedInfo()->getUrl()?>"
13
+ onclick="this.target = '_blank'"><?php echo $extension->getFeedInfo()->getDisplayName()?></a>
14
+ </td>
15
+ <td><?php echo $extension->getVersion()?></td>
16
+ <?php /*
17
+ <td>
18
+ <a href="http://shop.innobyte.com/extensions/<?php echo $extension->getName()?>-<?php echo $extension->getVersion()?>/readme.html"
19
+ onclick="this.target = '_blank'"><img src="<?php echo $this->getSkinUrl('innobyte/core/images/readme.png')?>"/></a>
20
+ </td>
21
+ */
22
+ ?>
23
+ </tr>
24
+ <?php endforeach; ?>
25
+ </tbody>
26
+ </table>
27
+ </div>
28
+ <?php endif; ?>
29
+ <?php if ($this->configPage == 'innobyte_shop'): ?>
30
+ <div id="innobyte_shop" style="display:none;">
31
+ <?php echo $this->_getShopData()->getTextResponse()?>
32
+ </div>
33
+ <?php endif; ?>
34
+
35
+ <script type="text/javascript">
36
+ innobyte_core_admin_section = '<?php echo $this->configPage?>';
37
+ </script>
app/design/adminhtml/default/default/template/innobyte/emag_marketplace/catalog/product/edit.phtml ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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) 2012 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
+ /**
29
+ * Template for Mage_Adminhtml_Block_Catalog_Product_Edit
30
+ */
31
+ ?>
32
+
33
+
34
+
35
+ <div class="content-header">
36
+ <h3 class="icon-head head-products"><?php echo $this->getHeader() ?></h3>
37
+ <p class="content-buttons form-buttons"><?php echo $this->getBackButtonHtml() ?>
38
+ <?php echo $this->getCancelButtonHtml() ?>
39
+ <?php if($this->getProductId()): ?>
40
+ <?php echo $this->getDeleteButtonHtml() ?>
41
+ <?php if($this->getProductSetId() && $this->getIsConfigured()): ?>
42
+ <?php echo $this->getDuplicateButtonHtml() ?>
43
+ <?php endif; ?>
44
+ <?php endif; ?>
45
+ <?php if($this->getProductSetId() && $this->getIsConfigured()): ?>
46
+ <?php echo $this->getSaveButtonHtml() ?>
47
+ <?php echo $this->getSaveAndEditButtonHtml() ?>
48
+ <?php endif; ?>
49
+ <?php // begin Innobyte customization ?>
50
+ <?php if (is_object($this->getChild('emag_send_product_btn'))): ?>
51
+ <?php echo $this->getChildHtml('emag_send_product_btn'); ?>
52
+ <?php endif; ?>
53
+ <?php if (is_object($this->getChild('emag_send_offer_btn'))): ?>
54
+ <?php echo $this->getChildHtml('emag_send_offer_btn'); ?>
55
+ <?php endif; ?>
56
+ <?php if (is_object($this->getChild('emag_deactivate_offer_btn'))): ?>
57
+ <?php echo $this->getChildHtml('emag_deactivate_offer_btn'); ?>
58
+ <?php endif; ?>
59
+ <?php // end Innobyte customization ?>
60
+ </p>
61
+ </div>
62
+ <form action="<?php echo $this->getSaveUrl() ?>" method="post" id="product_edit_form" enctype="multipart/form-data">
63
+ <?php echo $this->getBlockHtml('formkey')?>
64
+ <div style="display:none"></div>
65
+ </form>
66
+ <script type="text/javascript">
67
+ //<![CDATA[
68
+ var productTemplateSyntax = /(^|.|\r|\n)({{(\w+)}})/;
69
+ var productForm = new varienForm('product_edit_form', '<?php echo $this->getValidationUrl() ?>');
70
+ productForm._processValidationResult = function(transport) {
71
+ var response = transport.responseText.evalJSON();
72
+ if (response.error){
73
+ if (response.attribute && $(response.attribute)) {
74
+ $(response.attribute).setHasError(true, productForm);
75
+ Validation.ajaxError($(response.attribute), response.message);
76
+ if (!Prototype.Browser.IE){
77
+ $(response.attribute).focus();
78
+ }
79
+ }
80
+ else if ($('messages')) {
81
+ $('messages').innerHTML = '<ul class="messages"><li class="error-msg"><ul><li>' + response.message + '</li></ul></li></ul>';
82
+ }
83
+ }
84
+ else{
85
+ productForm._submit();
86
+ }
87
+ };
88
+ function saveAndContinueEdit(urlTemplate) {
89
+ var template = new Template(urlTemplate, productTemplateSyntax);
90
+ var url = template.evaluate({tab_id:product_info_tabsJsTabs.activeTab.id});
91
+ productForm.submit(url);
92
+ }
93
+ function setSettings(urlTemplate, setElement, typeElement) {
94
+ var template = new Template(urlTemplate, productTemplateSyntax);
95
+ setLocation(template.evaluate({attribute_set:$F(setElement),type:$F(typeElement)}));
96
+ }
97
+
98
+ function setSuperSettings(urlTemplate, attributesClass, validateField) {
99
+ var attributesFields = $$('.' + attributesClass);
100
+ var attributes = Form.serializeElements(attributesFields, true).attribute;
101
+ if(typeof attributes == 'string') {
102
+ attributes = [attributes];
103
+ }
104
+
105
+ if(!attributes) {
106
+ $(validateField).value = 'no-attributes';
107
+ } else {
108
+ $(validateField).value = 'has-attributes';
109
+ }
110
+
111
+ if (productForm.validator.validate()) {
112
+ var template = new Template(urlTemplate, productTemplateSyntax);
113
+ var url = template.evaluate({
114
+ attributes: encode_base64(attributes.join(',')).replace(new RegExp('/','g'),'%2F').replace(new RegExp('=','g'),'%3D')
115
+ });
116
+ setLocation(url);
117
+ }
118
+ }
119
+
120
+ function checkMaxLength(Object, MaxLen)
121
+ {
122
+ if (Object.value.length > MaxLen-1) {
123
+ Object.value = Object.value.substr(0, MaxLen);
124
+ }
125
+ return 1;
126
+ }
127
+
128
+ Event.observe(window, 'load', function() {
129
+ var objName = '<?php echo $this->getSelectedTabId() ?>';
130
+ if (objName) {
131
+ obj = $(objName);
132
+ //IE fix (bubbling event model)
133
+ product_info_tabsJsTabs.setSkipDisplayFirstTab();
134
+ product_info_tabsJsTabs.showTabContent(obj);
135
+ }
136
+ Product.AttributesBridge.setTabsObject(product_info_tabsJsTabs);
137
+ });
138
+
139
+ Validation.addAllThese([
140
+ ['validate-super-product-attributes', '<?php echo Mage::helper('catalog')->__('Please select one or more attributes.') ?>', function(v) {
141
+ return (v != "no-attributes");
142
+ }]]);
143
+ //]]>
144
+ </script>
app/design/adminhtml/default/default/template/innobyte/emag_marketplace/catalog/product/edit/tab/emag_marketplace_form_after.phtml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * eMAG tab form after html.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+ /** @var $this Mage_Adminhtml_Block_Template */
10
+ ?>
11
+ <script type="text/javascript">
12
+ //<![CDATA[
13
+ varienWindowOnload(true); // re-bind form elements onchange
14
+ //]]>
15
+ </script>
app/design/adminhtml/default/default/template/innobyte/emag_marketplace/sales/order/create/form/address.phtml ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ if($this->getIsShipping()):
27
+ $_fieldsContainerId = 'order-shipping_address_fields';
28
+ $_addressChoiceContainerId = 'order-shipping_address_choice';
29
+ ?>
30
+ <script type="text/javascript">
31
+ order.shippingAddressContainer = '<?php echo $_fieldsContainerId ?>';
32
+ order.setAddresses(<?php echo $this->getAddressCollectionJson() ?>);
33
+ </script>
34
+ <?php
35
+ else:
36
+ $_fieldsContainerId = 'order-billing_address_fields';
37
+ $_addressChoiceContainerId = 'order-billing_address_choice';
38
+ ?>
39
+ <script type="text/javascript">
40
+ order.billingAddressContainer = '<?php echo $_fieldsContainerId ?>';
41
+ </script>
42
+ <?php
43
+ endif; ?>
44
+ <div class="entry-edit">
45
+
46
+ <div class="entry-edit-head">
47
+ <h4 class="icon-head fieldset-legend <?php echo $this->getHeaderCssClass() ?>"><?php echo $this->getHeaderText() ?></h4>
48
+ </div>
49
+
50
+ <fieldset class="np">
51
+ <div id = "<?php echo $_addressChoiceContainerId ?>" class="order-choose-address">
52
+ <?php echo Mage::helper('sales')->__('Select from existing customer addresses:') ?><br/>
53
+ <?php $_id = $this->getForm()->getHtmlIdPrefix() . 'customer_address_id' ?>
54
+ <select id="<?php echo $_id ?>" name="<?php echo $this->getForm()->getHtmlNamePrefix()?>[customer_address_id]" style="width:97.5%;" onchange="order.selectAddress(this, '<?php echo $_fieldsContainerId ?>')">
55
+ <option value=""><?php echo Mage::helper('sales')->__('Add New Address') ?></option>
56
+ <?php foreach ($this->getAddressCollection() as $_address): ?>
57
+ <?php //if($this->getAddressAsString($_address)!=$this->getAddressAsString($this->getAddress())): ?>
58
+ <option value="<?php echo $_address->getId() ?>"<?php if ($_address->getId()==$this->getAddressId()): ?> selected="selected"<?php endif; ?>>
59
+ <?php echo $this->getAddressAsString($_address) ?>
60
+ </option>
61
+ <?php //endif; ?>
62
+ <?php endforeach; ?>
63
+
64
+ </select>
65
+ <br/>
66
+ <?php if($this->getIsShipping()): ?>
67
+ <input type="checkbox" id="order-shipping_same_as_billing" name="shipping_same_as_billing" onchange="order.setShippingAsBilling(this.checked)" <?php if($this->getIsAsBilling()): ?>checked<?php endif; ?>/>
68
+ <label for="order-shipping_same_as_billing" class="no-float"><?php echo Mage::helper('sales')->__('Same As Billing Address') ?></label>
69
+ <?php else: ?>
70
+ &nbsp;
71
+ <?php endif; ?>
72
+ </div>
73
+
74
+ <div class="order-address" id="<?php echo $_fieldsContainerId ?>">
75
+ <div class="content">
76
+ <?php echo $this->getForm()->toHtml() ?>
77
+ </div>
78
+ <div class="order-save-in-address-book">
79
+ <input name="<?php echo $this->getForm()->getHtmlNamePrefix()?>[save_in_address_book]" type="checkbox" id="<?php echo $this->getForm()->getHtmlIdPrefix()?>save_in_address_book" value="1" <?php if (!$this->getDontSaveInAddressBook() && $this->getAddress()->getSaveInAddressBook()):?> checked="checked"<?php endif;?>/>
80
+ <label for="<?php echo $this->getForm()->getHtmlIdPrefix()?>save_in_address_book"><?php echo Mage::helper('sales')->__('Save in address book') ?></label>
81
+ </div>
82
+ </div>
83
+ <?php $hideElement = 'address-' . ($this->getIsShipping() ? 'shipping' : 'billing') . '-overlay'; ?>
84
+ <div style="display:none;" id="<?php echo $hideElement ?>" class="overlay"><span><?php echo $this->__('Shipping address selection is not applicable') ?></span></div>
85
+ <script type="text/javascript">
86
+ order.bindAddressFields('<?php echo $_fieldsContainerId ?>');
87
+ order.bindAddressFields('<?php echo $_addressChoiceContainerId ?>');
88
+ <?php if($this->getIsShipping() && $this->getIsAsBilling()): ?>
89
+ order.disableShippingAddress(true);
90
+ <?php endif; ?>
91
+ </script>
92
+ <?php // begin Innobyte customization ?>
93
+ <?php if ($this->getQuote()->getEmagOrderId()): ?>
94
+ <script type="text/javascript">
95
+ //<![CDATA[
96
+ document.observe("dom:loaded", function() {
97
+ // atach city autocomplete
98
+ inno.emagMarketplace.attachAutocompleteEmagCity(
99
+ '<?php echo $this->escapeUrl($this->getUrl('adminhtml/emag_locality/getCities')); ?>',
100
+ '<?php echo $this->getIsShipping() ? 'shipping' : 'billing'; ?>',
101
+ '<?php echo $this->escapeUrl($this->getSkinUrl('images/ajax-loader.gif')); ?>'
102
+ );
103
+
104
+ // attach a new validation class to telephone because in AWB creation
105
+ // phones must have a specific format
106
+ if ($('order-billing_address_telephone')) {
107
+ $('order-billing_address_telephone').addClassName('validate-emag-phone');
108
+ $('order-shipping_address_telephone').addClassName('validate-emag-phone');
109
+ }
110
+ if ($('order-billing_address_emag_telephone_2')) {
111
+ $('order-billing_address_emag_telephone_2').addClassName('validate-emag-phone');
112
+ $('order-shipping_address_emag_telephone_2').addClassName('validate-emag-phone');
113
+ }
114
+ if ($('order-billing_address_emag_telephone_3')) {
115
+ $('order-billing_address_emag_telephone_3').addClassName('validate-emag-phone');
116
+ $('order-shipping_address_emag_telephone_3').addClassName('validate-emag-phone');
117
+ }
118
+ Validation.add(
119
+ 'validate-emag-phone',
120
+ '<?php echo $this->__('Phone must have between 8 and 11 digits and may contain a + sign at the beginning.') ?>',
121
+ function (input) {
122
+ if (input === "") {
123
+ return true;
124
+ }
125
+ return /^\+?[0-9]{8,11}$/.exec(input);
126
+ }
127
+ );
128
+ });
129
+ //]]>
130
+ </script>
131
+ <?php endif; ?>
132
+ <?php // end Innobyte customization ?>
133
+ </fieldset>
134
+ </div>
app/design/adminhtml/default/default/template/innobyte/emag_marketplace/sales/order/create/items/grid.phtml ADDED
@@ -0,0 +1,557 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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) 2012 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
+ /**
29
+ * @see Mage_Adminhtml_Block_Sales_Order_Create_Items_Grid
30
+ */
31
+ ?>
32
+ <?php /** @var $this Innobyte_EmagMarketplace_Block_Adminhtml_Sales_Order_Create_Items_Grid */ ?>
33
+ <?php $order = $this->getOrigOrder() ?>
34
+
35
+ <?php $_items = $this->getItems() ?>
36
+ <?php if (empty($_items)): ?>
37
+ <div class="grid" id="order-items_grid">
38
+ <table cellspacing="0" class="data order-tables">
39
+ <col/>
40
+ <col width="100"/>
41
+ <col width="40"/>
42
+ <col width="100"/>
43
+ <col width="80"/>
44
+ <col width="100"/>
45
+ <col width="80"/>
46
+ <thead>
47
+ <tr class="headings">
48
+ <th class="no-link"><?php echo $this->helper('sales')->__('Product') ?></th>
49
+ <th class="no-link"><?php echo $this->helper('sales')->__('Price') ?></th>
50
+ <th class="no-link"><?php echo $this->helper('sales')->__('Qty') ?></th>
51
+ <th class="no-link"><?php echo $this->helper('sales')->__('Subtotal') ?></th>
52
+ <th class="no-link"><?php echo $this->helper('sales')->__('Discount') ?></th>
53
+ <th class="no-link"><?php echo $this->helper('sales')->__('Row Subtotal') ?></th>
54
+
55
+ <th class="no-link last"><?php echo $this->helper('sales')->__('Action') ?></th>
56
+ </tr>
57
+ </thead>
58
+ <tbody>
59
+ <tr class="even">
60
+ <td class="empty-text a-center" colspan="100"><?php echo $this->helper('sales')->__('No ordered items') ?></td>
61
+ </tr>
62
+ </tbody>
63
+ </table>
64
+ </div>
65
+ <?php else: ?>
66
+ <div>
67
+ <?php if (count($_items) > 10): ?>
68
+ <p class="a-right">
69
+ <?php echo $this->getButtonHtml($this->helper('sales')->__('Update Items and Qty\'s'), 'order.itemsUpdate()'); ?>
70
+ </p>
71
+ <?php endif; ?>
72
+ <div class="grid" id="order-items_grid">
73
+ <table cellspacing="0" class="data order-tables">
74
+ <col/>
75
+ <col width="100"/>
76
+ <col width="100"/>
77
+ <col width="40"/>
78
+ <col width="100"/>
79
+ <col width="80"/>
80
+ <col width="100"/>
81
+ <col width="80"/>
82
+ <thead>
83
+ <tr class="headings">
84
+ <th class="no-link" colspan="2"><?php echo $this->helper('sales')->__('Product') ?></th>
85
+ <th class="no-link"><?php echo $this->helper('sales')->__('Price') ?></th>
86
+ <th class="no-link"><?php echo $this->helper('sales')->__('Qty') ?></th>
87
+ <th class="no-link"><?php echo $this->helper('sales')->__('Subtotal') ?></th>
88
+ <th class="no-link"><?php echo $this->helper('sales')->__('Discount') ?></th>
89
+ <th class="no-link"><?php echo $this->helper('sales')->__('Row Subtotal') ?></th>
90
+
91
+ <th class="no-link last"><?php echo $this->helper('sales')->__('Action') ?></th>
92
+ </tr>
93
+ </thead>
94
+ <tfoot>
95
+ <tr>
96
+ <td class="a-left"
97
+ colspan="2"><?php echo $this->helper('sales')->__('Total %d product(s)', count($_items)) ?></td>
98
+ <td colspan="2" class="a-right"><?php echo $this->helper('sales')->__('Subtotal:') ?></td>
99
+ <td class="price"><strong><?php echo $this->formatPrice($this->getSubtotal()) ?></strong></td>
100
+ <td class="price"><strong><?php echo $this->formatPrice($this->getDiscountAmount()) ?></strong></td>
101
+ <td class="price"><strong>
102
+ <?php
103
+ echo $this->formatPrice($this->getSubtotal() + $this->getDiscountAmount());
104
+ ?></strong></td>
105
+ <td colspan="2">&nbsp;</td>
106
+ </tr>
107
+ </tfoot>
108
+ <?php $i = 0 ?>
109
+ <?php foreach ($_items as $_item):$i++ ?>
110
+ <?php $originalItem = $this->getOriginalItem($_item) ?>
111
+ <tbody class="<?php echo ($i % 2) ? 'even' : 'odd' ?>">
112
+ <tr>
113
+ <td class="first">
114
+ <h5 class="title"><span
115
+ id="order_item_<?php echo $_item->getId() ?>_title"><?php echo $this->htmlEscape($_item->getName()) ?></span>
116
+ </h5>
117
+
118
+ <div>
119
+ <strong><?php echo $this->helper('sales')->__('SKU') ?>:</strong>
120
+ <?php echo implode('<br />', Mage::helper('catalog')->splitSku($this->escapeHtml($_item->getSku()))); ?>
121
+ </div>
122
+ <?php if ($_item->getMessage(false)): ?>
123
+ <?php foreach ($_item->getMessage(false) as $message): ?>
124
+ <div class="<?php if ($_item->getHasError()): ?>error<?php else: ?>notice<?php endif; ?>">
125
+ <div style="font-size:95%"><?php echo Mage::helper('core')->escapeHtml($message); ?></div>
126
+ </div>
127
+ <?php endforeach; ?>
128
+ <?php endif; ?>
129
+ </td>
130
+ <td class="a-center v-middle">
131
+ <?php echo $this->getConfigureButtonHtml($_item) ?>
132
+ </td>
133
+ <td class="price">
134
+ <?php if($originalItem): ?>
135
+ <div class="original-item">
136
+ <?php echo $this->formatPrice($originalItem->getPrice()) ?>
137
+ </div>
138
+ <?php endif; ?>
139
+
140
+ <?php if ($this->helper('tax')->displayCartPriceExclTax($this->getStore()) || $this->helper('tax')->displayCartBothPrices($this->getStore())): ?>
141
+ <?php if ($this->helper('tax')->displayCartBothPrices($this->getStore())): ?>
142
+ <span class="label"><?php echo $this->__('Excl. Tax'); ?>:</span>
143
+ <?php endif; ?>
144
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales')): ?>
145
+ <?php echo $this->formatPrice($_item->getCalculationPrice() + $_item->getWeeeTaxAppliedAmount() + $_item->getWeeeTaxDisposition()); ?>
146
+ <?php else: ?>
147
+ <?php echo $this->formatPrice($_item->getCalculationPrice()) ?>
148
+ <?php endif; ?>
149
+
150
+
151
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
152
+ <br/>
153
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales')): ?>
154
+ <small>
155
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
156
+ <span class="nobr"><?php echo $tax['title']; ?>
157
+ : <?php echo $this->formatPrice($tax['amount'], true, true); ?></span><br/>
158
+ <?php endforeach; ?>
159
+ </small>
160
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
161
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
162
+ <span class="nobr"><small><?php echo $tax['title']; ?>
163
+ : <?php echo $this->formatPrice($tax['amount_incl_tax'], true, true); ?></small></span>
164
+ <br/>
165
+ <?php endforeach; ?>
166
+ <?php
167
+ elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales')): ?>
168
+ <small>
169
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
170
+ <span class="nobr"><?php echo $tax['title']; ?>
171
+ : <?php echo $this->formatPrice($tax['amount_incl_tax'], true, true); ?></span><br/>
172
+ <?php endforeach; ?>
173
+ </small>
174
+ <?php endif; ?>
175
+
176
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
177
+ <br/>
178
+ <span class="nobr"><?php echo Mage::helper('weee')->__('Total'); ?>
179
+ :<br/> <?php echo $this->formatPrice($_item->getCalculationPrice() + $_item->getWeeeTaxAppliedAmount() + $_item->getWeeeTaxDisposition()); ?></span>
180
+ <?php endif; ?>
181
+ <?php endif; ?>
182
+ <?php endif; ?>
183
+
184
+
185
+ <?php if ($this->helper('tax')->displayCartPriceInclTax($this->getStore()) || $this->helper('tax')->displayCartBothPrices($this->getStore())): ?>
186
+ <?php if ($this->helper('tax')->displayCartBothPrices($this->getStore())): ?>
187
+ <br/><span class="label"><?php echo $this->__('Incl. Tax'); ?>:</span>
188
+ <?php endif; ?>
189
+ <?php $_incl = $this->helper('checkout')->getPriceInclTax($_item); ?>
190
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales')): ?>
191
+ <?php echo $this->formatPrice($_incl + $_item->getWeeeTaxAppliedAmount()); ?>
192
+ <?php else: ?>
193
+ <?php echo $this->formatPrice($_incl - $_item->getWeeeTaxDisposition()) ?>
194
+ <?php endif; ?>
195
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
196
+ <br/>
197
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales')): ?>
198
+ <small>
199
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
200
+ <span class="nobr"><?php echo $tax['title']; ?>
201
+ : <?php echo $this->formatPrice($tax['amount'], true, true); ?></span><br/>
202
+ <?php endforeach; ?>
203
+ </small>
204
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
205
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
206
+ <span class="nobr"><small><?php echo $tax['title']; ?>
207
+ : <?php echo $this->formatPrice($tax['amount_incl_tax'], true, true); ?></small></span>
208
+ <br/>
209
+ <?php endforeach; ?>
210
+ <?php
211
+ elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales')): ?>
212
+ <small>
213
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
214
+ <span class="nobr"><?php echo $tax['title']; ?>
215
+ : <?php echo $this->formatPrice($tax['amount_incl_tax'], true, true); ?></span><br/>
216
+ <?php endforeach; ?>
217
+ </small>
218
+ <?php endif; ?>
219
+
220
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
221
+ <span class="nobr"><?php echo Mage::helper('weee')->__('Total incl. tax'); ?>
222
+ :<br/> <?php echo $this->formatPrice($_incl + $_item->getWeeeTaxAppliedAmount()); ?></span>
223
+ <?php endif; ?>
224
+ <?php endif; ?>
225
+ <?php endif; ?>
226
+
227
+
228
+
229
+
230
+ <?php $_isCustomPrice = $this->usedCustomPriceForItem($_item) ?>
231
+ <?php if ($_tier = $this->getTierHtml($_item)): ?>
232
+ <div
233
+ id="item_tier_block_<?php echo $_item->getId() ?>"<?php if ($_isCustomPrice): ?> style="display:none"<?php endif; ?>>
234
+ <a href="#"
235
+ onclick="$('item_tier_<?php echo $_item->getId() ?>').toggle();return false;"><?php echo $this->helper('sales')->__('Tier Pricing') ?></a>
236
+
237
+ <div style="display:none" id="item_tier_<?php echo $_item->getId() ?>"><?php echo $_tier ?></div>
238
+ </div>
239
+ <?php endif; ?>
240
+ <?php if ($this->canApplyCustomPrice($_item)): ?>
241
+ <div class="nobr">
242
+ <input type="checkbox"
243
+ id="item_use_custom_price_<?php echo $_item->getId() ?>"<?php if ($_isCustomPrice): ?> checked="checked"<?php endif; ?>
244
+ onclick="order.toggleCustomPrice(this, 'item_custom_price_<?php echo $_item->getId() ?>', 'item_tier_block_<?php echo $_item->getId() ?>');"/>
245
+ <label class="normal"
246
+ for="item_use_custom_price_<?php echo $_item->getId() ?>"><?php echo $this->helper('sales')->__('Custom Price') ?>
247
+ *</label>
248
+ </div>
249
+ <?php endif; ?>
250
+ <input id="item_custom_price_<?php echo $_item->getId() ?>"
251
+ name="item[<?php echo $_item->getId() ?>][custom_price]"
252
+ value="<?php echo sprintf("%.2f", $this->getOriginalEditablePrice($_item)) ?>"<?php if (!$_isCustomPrice): ?> style="display:none" disabled="disabled"<?php endif; ?>
253
+ class="input-text item-price"/>
254
+ </td>
255
+ <td>
256
+ <?php if($originalItem): ?>
257
+ <div class="original-item">
258
+ <span class="quantity">
259
+ <?php echo $originalItem->getQtyOrdered() * 1 ?>
260
+ </span>
261
+ </div>
262
+ <?php endif; ?>
263
+
264
+ <input name="item[<?php echo $_item->getId() ?>][qty]" class="input-text item-qty"
265
+ value="<?php echo $_item->getQty() * 1 ?>" maxlength="12"/></td>
266
+ <td class="price">
267
+ <?php if($originalItem): ?>
268
+ <div class="original-item">
269
+ <span class="subtotal">
270
+ <?php echo $this->formatPrice($originalItem->getRowTotal()) ?>
271
+ </span>
272
+ </div>
273
+ <?php endif; ?>
274
+
275
+ <?php if ($this->helper('tax')->displayCartPriceExclTax($this->getStore()) || $this->helper('tax')->displayCartBothPrices($this->getStore())): ?>
276
+ <?php if ($this->helper('tax')->displayCartBothPrices($this->getStore())): ?>
277
+ <span class="label"><?php echo $this->__('Excl. Tax'); ?>:</span>
278
+ <?php endif; ?>
279
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales')): ?>
280
+ <?php echo $this->formatPrice($_item->getRowTotal() + $_item->getWeeeTaxAppliedRowAmount() + $_item->getWeeeTaxRowDisposition()); ?>
281
+ <?php else: ?>
282
+ <?php echo $this->formatPrice($_item->getRowTotal()) ?>
283
+ <?php endif; ?>
284
+
285
+
286
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
287
+ <br/>
288
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales')): ?>
289
+ <small>
290
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
291
+ <span class="nobr"><?php echo $tax['title']; ?>
292
+ : <?php echo $this->formatPrice($tax['row_amount'], true, true); ?></span><br/>
293
+ <?php endforeach; ?>
294
+ </small>
295
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
296
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
297
+ <span class="nobr"><small><?php echo $tax['title']; ?>
298
+ : <?php echo $this->formatPrice($tax['row_amount_incl_tax'], true, true); ?></small></span>
299
+ <br/>
300
+ <?php endforeach; ?>
301
+ <?php
302
+ elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales')): ?>
303
+ <small>
304
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
305
+ <span class="nobr"><?php echo $tax['title']; ?>
306
+ : <?php echo $this->formatPrice($tax['row_amount_incl_tax'], true, true); ?></span>
307
+ <br/>
308
+ <?php endforeach; ?>
309
+ </small>
310
+ <?php endif; ?>
311
+
312
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
313
+ <br/>
314
+ <span class="nobr"><?php echo Mage::helper('weee')->__('Total'); ?>
315
+ :<br/> <?php echo $this->formatPrice($_item->getCalculationPrice() + $_item->getWeeeTaxAppliedRowAmount() + $_item->getWeeeTaxRowDisposition()); ?></span>
316
+ <?php endif; ?>
317
+ <?php endif; ?>
318
+ <?php endif; ?>
319
+
320
+
321
+ <?php if ($this->helper('tax')->displayCartPriceInclTax($this->getStore()) || $this->helper('tax')->displayCartBothPrices($this->getStore())): ?>
322
+ <?php if ($this->helper('tax')->displayCartBothPrices($this->getStore())): ?>
323
+ <br/><span class="label"><?php echo $this->__('Incl. Tax'); ?>:</span>
324
+ <?php endif; ?>
325
+ <?php $_incl = $this->helper('checkout')->getSubtotalInclTax($_item); ?>
326
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales')): ?>
327
+ <?php echo $this->formatPrice($_incl + $_item->getWeeeTaxAppliedRowAmount()); ?>
328
+ <?php else: ?>
329
+ <?php echo $this->formatPrice($_incl - $_item->getWeeeTaxRowDisposition()) ?>
330
+ <?php endif; ?>
331
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
332
+ <br/>
333
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales')): ?>
334
+ <small>
335
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
336
+ <span class="nobr"><?php echo $tax['title']; ?>
337
+ : <?php echo $this->formatPrice($tax['row_amount'], true, true); ?></span><br/>
338
+ <?php endforeach; ?>
339
+ </small>
340
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
341
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
342
+ <span class="nobr"><small><?php echo $tax['title']; ?>
343
+ : <?php echo $this->formatPrice($tax['row_amount_incl_tax'], true, true); ?></small></span>
344
+ <br/>
345
+ <?php endforeach; ?>
346
+ <?php
347
+ elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales')): ?>
348
+ <small>
349
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
350
+ <span class="nobr"><?php echo $tax['title']; ?>
351
+ : <?php echo $this->formatPrice($tax['row_amount_incl_tax'], true, true); ?></span>
352
+ <br/>
353
+ <?php endforeach; ?>
354
+ </small>
355
+ <?php endif; ?>
356
+
357
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
358
+ <span class="nobr"><?php echo Mage::helper('weee')->__('Total incl. tax'); ?>
359
+ :<br/> <?php echo $this->formatPrice($_incl + $_item->getWeeeTaxAppliedRowAmount()); ?></span>
360
+ <?php endif; ?>
361
+ <?php endif; ?>
362
+ <?php endif; ?>
363
+
364
+
365
+ </td>
366
+ <td class="price">
367
+ <?php if($originalItem): ?>
368
+ <div class="original-item">
369
+ <span class="discount">
370
+ <?php echo $this->formatPrice(-$originalItem->getDiscountAmount()) ?>
371
+ </span>
372
+ </div>
373
+ <?php endif; ?>
374
+
375
+ <?php echo $this->formatPrice(-$_item->getDiscountAmount()) ?><br/>
376
+ <input id="item_use_discount_<?php echo $_item->getId() ?>"
377
+ name="item[<?php echo $_item->getId() ?>][use_discount]"
378
+ <?php if (!$_item->getNoDiscount()): ?>checked="checked"<?php endif; ?> value="1" type="checkbox"/>
379
+ <label for="item_use_discount_<?php echo $_item->getId() ?>"
380
+ class="normal"><?php echo $this->helper('sales')->__('Apply') ?></label>
381
+ </td>
382
+ <td class="price">
383
+ <?php if($originalItem): ?>
384
+ <div class="original-item">
385
+ <span class="row-subtotal">
386
+ <?php echo $this->formatPrice($originalItem->getRowTotal()) ?>
387
+ </span>
388
+ </div>
389
+ <?php endif; ?>
390
+
391
+
392
+ <?php if ($this->helper('tax')->displayCartPriceExclTax($this->getStore()) || $this->helper('tax')->displayCartBothPrices($this->getStore())): ?>
393
+ <?php $_rowTotalWithoutDiscount = $_item->getPriceInclTax() * $_item->getQty() - $_item->getDiscountAmount() - $_item->getTaxAmount(); ?>
394
+ <?php if ($this->helper('tax')->displayCartBothPrices($this->getStore())): ?>
395
+ <span class="label"><?php echo $this->__('Excl. Tax'); ?>:</span>
396
+ <?php endif; ?>
397
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales')): ?>
398
+ <?php echo $this->formatPrice(max(0, $_rowTotalWithoutDiscount + $_item->getWeeeTaxAppliedRowAmount() + $_item->getWeeeTaxRowDisposition())); ?>
399
+ <?php else: ?>
400
+ <?php echo $this->formatPrice(max(0, $_rowTotalWithoutDiscount)) ?>
401
+ <?php endif; ?>
402
+
403
+
404
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
405
+ <br/>
406
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales')): ?>
407
+ <small>
408
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
409
+ <span class="nobr"><?php echo $tax['title']; ?>
410
+ : <?php echo $this->formatPrice($tax['row_amount'], true, true); ?></span><br/>
411
+ <?php endforeach; ?>
412
+ </small>
413
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
414
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
415
+ <span class="nobr"><small><?php echo $tax['title']; ?>
416
+ : <?php echo $this->formatPrice($tax['row_amount_incl_tax'], true, true); ?></small></span>
417
+ <br/>
418
+ <?php endforeach; ?>
419
+ <?php
420
+ elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales')): ?>
421
+ <small>
422
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
423
+ <span class="nobr"><?php echo $tax['title']; ?>
424
+ : <?php echo $this->formatPrice($tax['row_amount_incl_tax'], true, true); ?></span>
425
+ <br/>
426
+ <?php endforeach; ?>
427
+ </small>
428
+ <?php endif; ?>
429
+
430
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
431
+ <br/>
432
+ <span class="nobr"><?php echo Mage::helper('weee')->__('Total'); ?>
433
+ :<br/> <?php echo $this->formatPrice($_item->getCalculationPrice() + $_item->getWeeeTaxAppliedRowAmount() + $_item->getWeeeTaxRowDisposition()); ?></span>
434
+ <?php endif; ?>
435
+ <?php endif; ?>
436
+ <?php endif; ?>
437
+
438
+
439
+ <?php if ($this->helper('tax')->displayCartPriceInclTax($this->getStore()) || $this->helper('tax')->displayCartBothPrices($this->getStore())): ?>
440
+ <?php if ($this->helper('tax')->displayCartBothPrices($this->getStore())): ?>
441
+ <br/><span class="label"><?php echo $this->__('Incl. Tax'); ?>:</span>
442
+ <?php endif; ?>
443
+ <?php $_incl = $_item->getPriceInclTax() * $_item->getQty() - $_item->getDiscountAmount(); ?>
444
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales')): ?>
445
+ <?php echo $this->formatPrice($_incl + $_item->getWeeeTaxAppliedRowAmount()); ?>
446
+ <?php else: ?>
447
+ <?php echo $this->formatPrice($_incl - $_item->getWeeeTaxRowDisposition()) ?>
448
+ <?php endif; ?>
449
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
450
+ <br/>
451
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales')): ?>
452
+ <small>
453
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
454
+ <span class="nobr"><?php echo $tax['title']; ?>
455
+ : <?php echo $this->formatPrice($tax['row_amount'], true, true); ?></span><br/>
456
+ <?php endforeach; ?>
457
+ </small>
458
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
459
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
460
+ <span class="nobr"><small><?php echo $tax['title']; ?>
461
+ : <?php echo $this->formatPrice($tax['row_amount_incl_tax'], true, true); ?></small></span>
462
+ <br/>
463
+ <?php endforeach; ?>
464
+ <?php
465
+ elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales')): ?>
466
+ <small>
467
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
468
+ <span class="nobr"><?php echo $tax['title']; ?>
469
+ : <?php echo $this->formatPrice($tax['row_amount_incl_tax'], true, true); ?></span>
470
+ <br/>
471
+ <?php endforeach; ?>
472
+ </small>
473
+ <?php endif; ?>
474
+
475
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
476
+ <span class="nobr"><?php echo Mage::helper('weee')->__('Total incl. tax'); ?>
477
+ :<br/> <?php echo $this->formatPrice($_incl + $_item->getWeeeTaxAppliedRowAmount()); ?></span>
478
+ <?php endif; ?>
479
+ <?php endif; ?>
480
+ <?php endif; ?>
481
+
482
+ </td>
483
+ <td class="last">
484
+ <select name="item[<?php echo $_item->getId() ?>][action]" style="width:100px;">
485
+ <option value=""></option>
486
+ <option value="remove"><?php echo $this->helper('sales')->__('Remove') ?></option>
487
+ <?php if ($this->getCustomerId() && $this->getMoveToCustomerStorage()): ?>
488
+ <option value="cart"><?php echo $this->helper('sales')->__('Move to Shopping Cart') ?></option>
489
+ <?php if ($this->isMoveToWishlistAllowed($_item)): ?>
490
+ <?php $wishlists = $this->getCustomerWishlists(); ?>
491
+ <?php if (count($wishlists) <= 1): ?>
492
+ <option
493
+ value="wishlist"><?php echo $this->helper('sales')->__('Move to Wishlist') ?></option>
494
+ <?php else: ?>
495
+ <optgroup label="<?php echo $this->helper('sales')->__('Move to Wishlist') ?>">
496
+ <?php foreach ($wishlists as $wishlist): ?>
497
+ <option
498
+ value="wishlist_<?php echo $wishlist->getId(); ?>"><?php echo $this->escapeHtml($wishlist->getName()); ?></option>
499
+ <?php endforeach; ?>
500
+ </optgroup>
501
+ <?php endif; ?>
502
+ <?php endif; ?>
503
+ <?php endif; ?>
504
+ </select>
505
+ </td>
506
+ </tr>
507
+ <?php echo $this->getItemExtraInfo($_item)->toHtml(); ?>
508
+ </tbody>
509
+ <?php endforeach; ?>
510
+ </table>
511
+ </div>
512
+ <table cellspacing="0" width="100%">
513
+ <col width="50%"/>
514
+ <col width="50%"/>
515
+ <tr>
516
+ <td class="a-left">
517
+ <small><?php echo $this->getInclExclTaxMessage(); ?></small>
518
+ </td>
519
+ <td class="a-right"><?php echo $this->getButtonHtml($this->helper('sales')->__('Update Items and Qty\'s'), 'order.itemsUpdate()'); ?></td>
520
+ </tr>
521
+ </table>
522
+ <br/>
523
+
524
+ <div id="order-coupons"><?php echo $this->getChildHtml(); ?></div>
525
+ <div class="clear"></div>
526
+ <script type="text/javascript">order.itemsOnchangeBind()</script>
527
+ </div>
528
+
529
+ <?php if ($this->isGiftMessagesAvailable()) : ?>
530
+ <script type="text/javascript">
531
+ //<![CDATA[
532
+ /**
533
+ * Retrieve gift options tooltip content
534
+ */
535
+ function getGiftOptionsTooltipContent(itemId) {
536
+ var contentLines = [];
537
+ var headerLine = null;
538
+ var contentLine = null;
539
+
540
+ $$('#gift_options_data_' + itemId + ' .gift-options-tooltip-content').each(function (element) {
541
+ if (element.down(0)) {
542
+ headerLine = element.down(0).innerHTML;
543
+ contentLine = element.down(0).next().innerHTML;
544
+ if (contentLine.length > 30) {
545
+ contentLine = contentLine.slice(0, 30) + '...';
546
+ }
547
+ contentLines.push(headerLine + ' ' + contentLine);
548
+ }
549
+ });
550
+ return contentLines.join('<br/>');
551
+ }
552
+ giftOptionsTooltip.setTooltipContentLoaderFunction(getGiftOptionsTooltipContent);
553
+
554
+ //]]>
555
+ </script>
556
+ <?php endif; ?>
557
+ <?php endif; ?>
app/design/adminhtml/default/default/template/innobyte/emag_marketplace/sales/order/create/shipping/method/form.phtml ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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) 2012 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 /** @var $this Mage_Adminhtml_Block_Sales_Order_Create_Shipping_Method_Form */ ?>
28
+ <?php $_shippingRateGroups = $this->getShippingRates(); ?>
29
+ <?php if ($_shippingRateGroups): ?>
30
+ <div id="order-shipping-method-choose" style="display:none">
31
+ <dl class="shipment-methods">
32
+ <?php foreach ($_shippingRateGroups as $code => $_rates): ?>
33
+ <dt><strong><?php echo $this->escapeHtml($this->getCarrierName($code)) ?></strong></dt>
34
+ <dd>
35
+ <ul>
36
+ <?php foreach ($_rates as $_rate): ?>
37
+ <?php $_radioProperty = 'name="order[shipping_method]" type="radio" onclick="order.setShippingMethod(this.value)"' ?>
38
+ <?php $_code=$_rate->getCode() ?>
39
+ <li>
40
+ <?php if ($_rate->getErrorMessage()): ?>
41
+ <ul class="messages">
42
+ <li class="error-msg"><?php echo $this->escapeHtml($_rate->getErrorMessage()) ?></li>
43
+ </ul>
44
+ <?php else: ?>
45
+ <?php $_checked = $this->isMethodActive($_code) ? 'checked="checked"' : '' ?>
46
+ <input <?php echo $_radioProperty ?> value="<?php echo $_code ?>" id="s_method_<?php echo $_code ?>" <?php echo $_checked ?>/>
47
+ <?php if($code == Innobyte_EmagMarketplace_Model_Shipping_Carrier_Emag::EMAG_SHIPPING): ?>
48
+ <?php echo $this->escapeHtml($_rate->getMethodTitle() ? $_rate->getMethodTitle() : $_rate->getMethodDescription()) ?>:
49
+ <label class="normal" for="s_method_<?php echo $_code ?>"></label>
50
+ <strong><?php echo $this->getQuote()->getBaseCurrencyCode() ?></strong>
51
+ <input id="emag-shipping-rate" class="input-text" type="text" value="<?php echo $_rate->getPrice() ?>" onclick="return false;" />
52
+ <button id="custom-shipping-button" type="button" class="scalable" onclick="order.setEmagShippingPrice();">
53
+ <span><?php echo $this->__('Save'); ?></span>
54
+ </button>
55
+ <script type="text/javascript">
56
+ //<![CDATA[
57
+ AdminOrder.addMethods({
58
+ setEmagShippingPrice: function () {
59
+ var data = {};
60
+ data['order[carrier]'] = '<?php echo $code ?>';
61
+ data['order[shipping_method]'] = '<?php echo $_code ?>';
62
+ data['order[shipping_amount]'] = $('emag-shipping-rate').value;
63
+ this.loadArea(['shipping_method', 'totals', 'billing_method'], true, data);
64
+ }
65
+ });
66
+ //]]>
67
+ </script>
68
+ <?php else: ?>
69
+ <label class="normal" for="s_method_<?php echo $_code ?>">
70
+ <?php echo $this->escapeHtml($_rate->getMethodTitle() ? $_rate->getMethodTitle() : $_rate->getMethodDescription()) ?> -
71
+ <strong>
72
+ <?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
73
+ <?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
74
+
75
+ <?php echo $_excl; ?>
76
+ <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
77
+ (<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
78
+ <?php endif; ?>
79
+ </strong>
80
+ </label>
81
+ <?php endif; ?>
82
+ <?php endif ?>
83
+ </li>
84
+ <?php endforeach; ?>
85
+ </ul>
86
+ </dd>
87
+ <?php endforeach; ?>
88
+ </dl>
89
+ </div>
90
+ <?php if ($_rate = $this->getActiveMethodRate()): ?>
91
+ <div id="order-shipping-method-info">
92
+ <strong><?php echo $this->escapeHtml($this->getCarrierName($_rate->getCarrier())) ?></strong><br/>
93
+ <?php echo $this->escapeHtml($_rate->getMethodTitle() ? $_rate->getMethodTitle() : $_rate->getMethodDescription()) ?> -
94
+ <strong>
95
+ <?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
96
+ <?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
97
+
98
+ <?php echo $_excl; ?>
99
+ <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
100
+ (<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
101
+ <?php endif; ?>
102
+ </strong>
103
+ <!--input type="text" class="input-text" style="width:70px"/-->
104
+ <br/>
105
+ <a href="#" onclick="$('order-shipping-method-info').hide();$('order-shipping-method-choose').show();return false">
106
+ <?php echo Mage::helper('sales')->__('Click to change shipping method') ?>
107
+ </a>
108
+ </div>
109
+ <?php else: ?>
110
+ <script type="text/javascript">$('order-shipping-method-choose').show();</script>
111
+ <?php endif; ?>
112
+ <?php elseif($this->getIsRateRequest()): ?>
113
+ <strong><?php echo Mage::helper('sales')->__('Sorry, no quotes are available for this order at this time.') ?></strong>
114
+ <?php else: ?>
115
+ <div id="order-shipping-method-summary">
116
+ <a href="#" onclick="order.loadShippingRates();return false">
117
+ <?php echo Mage::helper('sales')->__('Get shipping methods and rates') ?>
118
+ </a>
119
+ <input type="hidden" name="order[has_shipping]" value="" class="required-entry" />
120
+ </div>
121
+ <?php endif; ?>
122
+ <div style="display:none;" id="shipping-method-overlay" class="overlay"><span><?php echo $this->__('Shipping method selection is not applicable') ?></span></div>
123
+ <script type="text/javascript">
124
+ order.overlay('shipping-method-overlay', <?php if ($this->getQuote()->isVirtual()): ?>false<?php else: ?>true<?php endif; ?>);
125
+ order.overlay('address-shipping-overlay', <?php if ($this->getQuote()->isVirtual()): ?>false<?php else: ?>true<?php endif; ?>);
126
+ </script>
app/design/adminhtml/default/default/template/innobyte/emag_marketplace/sales/order/create/totals/voucher.phtml ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $emagVouchers = $this->getQuote()->getEmagVouchers(); ?>
2
+ <?php if (!empty($emagVouchers)): ?>
3
+ <?php foreach ($emagVouchers as $voucher): ?>
4
+ <?php $url = $this->getUrl('*/emag_voucher/remove', array('voucher_id' => $voucher['emag_voucher_id'], 'quote_id' => $this->getQuote()->getId())) ?>
5
+ <tr class="<?php echo $this->getTotal()->getCode(); ?>">
6
+ <td style="<?php echo $this->getTotal()->getStyle() ?>" class="a-right"
7
+ colspan="<?php echo $this->getColspan(); ?>">
8
+ <?php if ($this->getRenderingArea() == $this->getTotal()->getArea()): ?><strong><?php endif; ?>
9
+ <?php echo $this->escapeHtml($voucher['emag_voucher_name']); ?>
10
+ <?php if ($this->getRenderingArea() == $this->getTotal()->getArea()): ?></strong><?php endif; ?>
11
+ <img src="<?php echo $this->getSkinUrl('images/icon_btn_delete.gif') ?>" class="emag-voucher-remove"
12
+ onclick="inno.emag_marketplace.removeVoucher('<?php echo $url ?>')"
13
+ title="<?php echo Mage::helper('innobyte_emag_marketplace')->__('Remove') ?>"/>
14
+ </td>
15
+ <td style="<?php echo $this->getTotal()->getStyle() ?>" class="a-right">
16
+ <?php if ($this->getRenderingArea() == $this->getTotal()->getArea()): ?><strong><?php endif; ?>
17
+ <?php echo $this->formatPrice($voucher['emag_sale_price']) ?>
18
+ <?php if ($this->getRenderingArea() == $this->getTotal()->getArea()): ?></strong><?php endif; ?>
19
+ </td>
20
+ </tr>
21
+ <?php endforeach; ?>
22
+
23
+ <script type="text/javascript">
24
+ var inno = inno || {};
25
+ inno.emag_marketplace = {
26
+ removeVoucher: function (url) {
27
+ var canDelete = confirm('<?php echo Mage::helper('innobyte_emag_marketplace')->__('Voucher will be removed permanently from quote. Are you sure?')?>');
28
+ if (!canDelete) {
29
+ return;
30
+ }
31
+ new Ajax.Request(url, {
32
+ method: 'post',
33
+ onSuccess: function (transport) {
34
+ var response = transport.responseText || "no response text";
35
+
36
+ alert(response);
37
+ order.loadArea(['totals'], true);
38
+ },
39
+ onFailure: function () {
40
+ alert('<?php echo Mage::helper('innobyte_emag_marketplace')->__('There was an error while processing request.') ?>');
41
+ }
42
+ });
43
+ }
44
+ };
45
+ </script>
46
+ <?php endif; ?>
app/design/adminhtml/default/default/template/innobyte/emag_marketplace/sales/order/emag_edit/city-autocomplete.phtml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Autocomplete returned list.
4
+ *
5
+ * @category Innobyte
6
+ * @package Innobyte_EmagMarketplace
7
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
8
+ */
9
+ ?>
10
+ <ul data-address-type="<?php echo $this->escapeHtml($addressType); ?>">
11
+ <?php foreach ($items as $item): ?>
12
+ <li data-emag-id="<?php echo $this->escapeHtml($item['id']); ?>"
13
+ data-county="<?php echo $this->escapeHtml($item['county']); ?>"
14
+ <?php if (isset($item['county_id'])): ?>
15
+ data-county-id="<?php echo intval($item['county_id']); ?>"
16
+ <?php endif; ?>
17
+ >
18
+ <strong class="emag-city-name-<?php echo $this->escapeHtml($addressType); ?>"><?php echo $this->escapeHtml($item['name']); ?></strong>
19
+ <span class="informal"><?php echo $this->escapeHtml($item['description']); ?></span>
20
+ </li>
21
+ <?php endforeach; ?>
22
+ </ul>
app/design/adminhtml/default/default/template/innobyte/emag_marketplace/sales/order/shipment/packaging/popup.phtml ADDED
@@ -0,0 +1,302 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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) 2012 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
+ $shippingMethod = $this->getShipment()->getOrder()->getShippingMethod();
29
+ $sizeSource = Mage::getModel('usa/shipping_carrier_usps_source_size')->toOptionArray();
30
+ $girthEnabled = Mage::helper('usa')->displayGirthValue($shippingMethod) && $this->isGirthAllowed() ? 1 : 0;
31
+ ?>
32
+ <script type="text/javascript">
33
+ //<![CDATA[
34
+ document.observe("dom:loaded", function() {
35
+ <?php // begin Innobyte customization
36
+ $method = $this->getShipment()->getOrder()->getShippingMethod(true)->getMethod();
37
+ $shippingCarrier = $this->getShipment()->getOrder()->getShippingCarrier();
38
+ if (Innobyte_EmagMarketplace_Model_Shipping_Carrier_Emag::EMAG_SHIPPING == $shippingCarrier->getCarrierCode()): ?>
39
+ packaging = new inno.emagMarketplace.packaging(<?php echo $this->getConfigDataJson() ?>);
40
+ <?php else: ?>
41
+ <?php // end Innobyte customization ?>
42
+ packaging = new Packaging(<?php echo $this->getConfigDataJson() ?>);
43
+ <?php endif; ?>
44
+ packaging.changeContainerType($$('select[name=package_container]')[0]);
45
+ packaging.checkSizeAndGirthParameter(
46
+ $$('select[name=package_container]')[0],
47
+ <?php echo $girthEnabled; ?>
48
+ );
49
+ });
50
+ //]]>
51
+ </script>
52
+ <div id="popup-window-mask" style="display:none;"></div>
53
+ <div id="packaging_window" class="packaging-window" style="display:none;">
54
+ <div class="entry-edit">
55
+ <div class="entry-edit-head">
56
+ <button type="button" class="scalable AddPackageBtn" onclick="packaging.newPackage();">
57
+ <span><span><span><?php echo Mage::helper('sales')->__('Add Package') ?></span></span></span>
58
+ </button>
59
+ <h4 class="icon-head fieldset-legend"><?php echo Mage::helper('sales')->__('Create Packages') ?></h4>
60
+ </div>
61
+ <?php // begin Innobyte customization - add extra fields ?>
62
+ <?php if (Innobyte_EmagMarketplace_Model_Shipping_Carrier_Emag::EMAG_SHIPPING == $shippingCarrier->getCarrierCode()): ?>
63
+ <div id="emag-marketplace-shipping-extra" class="package-block" style="margin: 10px;">
64
+ <table class="data" cellspacing="5">
65
+ <tbody>
66
+ <tr>
67
+ <td><label for="emag-marketplace-shipping_cod"><?php echo $this->helper('innobyte_emag_marketplace')->__('Cash on delivery value'); ?><span class="required">*</span></label></td>
68
+ <td><input type="text" class="input-text required-entry validate-number validate-not-negative-number" name="emag-marketplace-shipping[cod]" id="emag-marketplace-shipping_cod" value="" /></td>
69
+ </tr>
70
+ <tr>
71
+ <td><label for="emag-marketplace-shipping_insured_value"><?php echo $this->helper('innobyte_emag_marketplace')->__('Insured value'); ?></label></td>
72
+ <td><input type="text" class="input-text validate-number validate-not-negative-number" name="emag-marketplace-shipping[insured_value]" id="emag-marketplace-shipping_insured_value" value="" /></td>
73
+ </tr>
74
+ <tr>
75
+ <td><label for="emag-marketplace-shipping_observation"><?php echo $this->helper('innobyte_emag_marketplace')->__('Observation'); ?></label></td>
76
+ <td><input type="text" class="input-text validate-length minimum-length-0 maximum-length-255" name="emag-marketplace-shipping[observation]" id="emag-marketplace-shipping_observation" value="" maxlength="255" /></td>
77
+ </tr>
78
+ <tr>
79
+ <td><label for="emag-marketplace-shipping_pickup_and_return"><?php echo $this->helper('innobyte_emag_marketplace')->__('Pickup and return'); ?></label></td>
80
+ <td class="form-list">
81
+ <select name="emag-marketplace-shipping[pickup_and_return]" id="emag-marketplace-shipping_pickup_and_return">
82
+ <option value="-1" selected="selected"></option>
83
+ <?php foreach (Mage::getSingleton('adminhtml/system_config_source_yesno')->toArray() as $key => $value): ?>
84
+ <option value="<?php echo intval($key); ?>"><?php echo $this->escapeHtml($value); ?></option>
85
+ <?php endforeach; ?>
86
+ </select>
87
+ <p class="note"><?php echo $this->helper('innobyte_emag_marketplace')->__('If set to "Yes", sender expects something in return to this expedition (documents, buy-back products, etc).'); ?></p>
88
+ </td>
89
+ </tr>
90
+ <tr>
91
+ <td><label for="emag-marketplace-shipping_saturday_delivery"><?php echo $this->helper('innobyte_emag_marketplace')->__('Saturday delivery'); ?></label></td>
92
+ <td class="form-list">
93
+ <select name="emag-marketplace-shipping[saturday_delivery]" id="emag-marketplace-shipping_saturday_delivery">
94
+ <option value="-1" selected="selected"></option>
95
+ <?php foreach (Mage::getSingleton('adminhtml/system_config_source_yesno')->toArray() as $key => $value): ?>
96
+ <option value="<?php echo intval($key); ?>"><?php echo $this->escapeHtml($value); ?></option>
97
+ <?php endforeach; ?>
98
+ </select>
99
+ <p class="note"><?php echo $this->helper('innobyte_emag_marketplace')->__('If set to "Yes", sender requests the package to be delivered on Saturday.'); ?></p>
100
+ </td>
101
+ </tr>
102
+ <tr>
103
+ <td><label for="emag-marketplace-shipping_sameday_delivery"><?php echo $this->helper('innobyte_emag_marketplace')->__('Same day delivery'); ?></label></td>
104
+ <td class="form-list">
105
+ <select name="emag-marketplace-shipping[sameday_delivery]" id="emag-marketplace-shipping_sameday_delivery">
106
+ <option value="-1" selected="selected"></option>
107
+ <?php foreach (Mage::getSingleton('adminhtml/system_config_source_yesno')->toArray() as $key => $value): ?>
108
+ <option value="<?php echo intval($key); ?>"><?php echo $this->escapeHtml($value); ?></option>
109
+ <?php endforeach; ?>
110
+ </select>
111
+ <p class="note"><?php echo $this->helper('innobyte_emag_marketplace')->__('If set to "Yes", sender requests the package to be delivered the same day.'); ?></p>
112
+ </td>
113
+ </tr>
114
+ <tr>
115
+ <td><label for="emag-marketplace-shipping_open_on_receipt"><?php echo $this->helper('innobyte_emag_marketplace')->__('Open On Receipt'); ?></label></td>
116
+ <td class="form-list">
117
+ <select name="emag-marketplace-shipping[open_on_receipt]" id="emag-marketplace-shipping_open_on_receipt">
118
+ <?php foreach (Mage::getSingleton('adminhtml/system_config_source_yesno')->toArray() as $key => $value): ?>
119
+ <option value="<?php echo intval($key); ?>" <?php if (1 == $key): echo 'selected="selected"'; endif; ?>><?php echo $this->escapeHtml($value); ?></option>
120
+ <?php endforeach; ?>
121
+ </select>
122
+ </td>
123
+ </tr>
124
+ </tbody>
125
+ </table>
126
+ </div>
127
+ <?php endif; ?>
128
+ <?php // end Innobyte customization - add extra fields ?>
129
+ <div class="packaging-content">
130
+ <div class="messages" style="display:none;"></div>
131
+ <div id="package_template" style="display:none;">
132
+ <div class="package-number"><?php echo Mage::helper('sales')->__('Package') ?><span></span></div>
133
+ <table class="package-options" cellspacing="0">
134
+ <thead>
135
+ <th><?php echo Mage::helper('sales')->__('Type') ?></th>
136
+ <?php if ($girthEnabled == 1): ?>
137
+ <th><?php echo Mage::helper('sales')->__('Size') ?></th>
138
+ <th><?php echo Mage::helper('sales')->__('Girth') ?></th>
139
+ <th>&nbsp;</th>
140
+ <?php endif; ?>
141
+ <th <?php echo $this->displayCustomsValue() ? '' : 'style="display: none;"' ?>>
142
+ <?php echo Mage::helper('sales')->__('Customs Value') ?>
143
+ </th>
144
+ <th><?php echo Mage::helper('sales')->__('Total Weight') ?></th>
145
+ <th><?php echo Mage::helper('sales')->__('Length') ?></th>
146
+ <th><?php echo Mage::helper('sales')->__('Width') ?></th>
147
+ <th><?php echo Mage::helper('sales')->__('Height') ?></th>
148
+ <th>&nbsp;</th>
149
+ <?php if ($this->getDeliveryConfirmationTypes()): ?>
150
+ <th><?php echo Mage::helper('sales')->__('Signature Confirmation') ?></th>
151
+ <?php endif; ?>
152
+ <th>&nbsp;</th>
153
+ <th>&nbsp;</th>
154
+ </thead>
155
+ <tbody>
156
+ <td>
157
+ <?php $containers = $this->getContainers(); ?>
158
+ <select name="package_container" onchange="packaging.changeContainerType(this);packaging.checkSizeAndGirthParameter(this, <?php echo $girthEnabled ?>);"<?php if (empty($containers)):?>
159
+ title="<?php echo Mage::helper('sales')->__('Package types are disregarded for USPS domestic shipments.') ?>"
160
+ disabled="" class="disabled"
161
+ <?php endif; ?>>
162
+ <?php foreach ($this->getContainers() as $key => $value): ?>
163
+ <option value="<?php echo $key ?>" >
164
+ <?php echo $value ?>
165
+ </option>
166
+ <?php endforeach; ?>
167
+ </select>
168
+ </td>
169
+ <?php if ($girthEnabled == 1): ?>
170
+ <td>
171
+ <select name="package_size" onchange="packaging.checkSizeAndGirthParameter(this, <?php echo $girthEnabled ?>);">
172
+ <?php foreach ($sizeSource as $key => $value): ?>
173
+ <option value="<?php echo $sizeSource[$key]['value'] ?>">
174
+ <?php echo $sizeSource[$key]['label'] ?>
175
+ </option>
176
+ <?php endforeach; ?>
177
+ </select>
178
+ </td>
179
+ <td><input type="text" class="input-text validate-greater-than-zero" name="container_girth" /></td>
180
+ <td>
181
+ <select name="container_girth_dimension_units" class="options-units-dimensions measures" onchange="packaging.changeMeasures(this);">
182
+ <?php // begin Innobyte customization - changed selected option by default ?>
183
+ <option value="<?php echo Zend_Measure_Length::INCH ?>"><?php echo Mage::helper('sales')->__('in') ?></option>
184
+ <option value="<?php echo Zend_Measure_Length::CENTIMETER ?>" selected="selected" ><?php echo Mage::helper('sales')->__('cm') ?></option>
185
+ <?php // end Innobyte customization - changed selected option by default ?>
186
+ </select>
187
+ </td>
188
+ <?php endif; ?>
189
+ <?php
190
+ if ($this->displayCustomsValue()) {
191
+ $customsValueDisplay = '';
192
+ $customsValueValidation = ' validate-zero-or-greater ';
193
+ } else {
194
+ $customsValueDisplay = ' style="display: none;" ';
195
+ $customsValueValidation = '';
196
+ }
197
+ ?>
198
+ <td <?php echo $customsValueDisplay ?>>
199
+ <input type="text" class="customs-value input-text <?php echo $customsValueValidation ?>" name="package_customs_value" />
200
+ <span class="customs-value-currency">[<?php echo $this->getCustomValueCurrencyCode(); ?>]</span>
201
+ </td>
202
+ <td>
203
+ <input type="text" class="options-weight input-text required-entry validate-greater-than-zero" name="container_weight" />
204
+ <select name="container_weight_units" class="options-units-weight measures" onchange="packaging.changeMeasures(this);">
205
+ <?php // begin Innobyte customization - changed selected option by default ?>
206
+ <option value="<?php echo Zend_Measure_Weight::POUND ?>"><?php echo Mage::helper('sales')->__('lb') ?></option>
207
+ <option value="<?php echo Zend_Measure_Weight::KILOGRAM ?>" selected="selected" ><?php echo Mage::helper('sales')->__('kg') ?></option>
208
+ <?php // end Innobyte customization - changed selected option by default ?>
209
+ </select>
210
+ </td>
211
+ <td>
212
+ <input type="text" class="input-text validate-greater-than-zero" name="container_length" />
213
+ </td>
214
+ <td>
215
+ <input type="text" class="input-text validate-greater-than-zero" name="container_width" />
216
+ </td>
217
+ <td>
218
+ <input type="text" class="input-text validate-greater-than-zero" name="container_height" />
219
+ </td>
220
+ <td>
221
+ <select name="container_dimension_units" class="options-units-dimensions measures" onchange="packaging.changeMeasures(this);">
222
+ <?php // begin Innobyte customization - changed selected option by default ?>
223
+ <option value="<?php echo Zend_Measure_Length::INCH ?>"><?php echo Mage::helper('sales')->__('in') ?></option>
224
+ <option value="<?php echo Zend_Measure_Length::CENTIMETER ?>" selected="selected" ><?php echo Mage::helper('sales')->__('cm') ?></option>
225
+ <?php // end Innobyte customization - changed selected option by default ?>
226
+ </select>
227
+ </td>
228
+ <?php if ($this->getDeliveryConfirmationTypes()): ?>
229
+ <td>
230
+ <select name="delivery_confirmation_types">
231
+ <?php foreach ($this->getDeliveryConfirmationTypes() as $key => $value): ?>
232
+ <option value="<?php echo $key ?>" >
233
+ <?php echo $value ?>
234
+ </option>
235
+ <?php endforeach; ?>
236
+ </select>
237
+ </td>
238
+ <?php endif; ?>
239
+ <td>
240
+ <button type="button" class="scalable AddItemsBtn" onclick="packaging.getItemsForPack(this);">
241
+ <span><span><span><?php echo Mage::helper('sales')->__('Add Products') ?></span></span></span>
242
+ </button>
243
+ </td>
244
+ <td>
245
+ <button type="button" class="scalable DeletePackageBtn" onclick="packaging.deletePackage(this);">
246
+ <span><span><span><?php echo Mage::helper('sales')->__('Delete Package') ?></span></span></span>
247
+ </button>
248
+ </td>
249
+ </tbody>
250
+ </table>
251
+
252
+ <?php if ($this->getContentTypes()): ?>
253
+ <table class="package-options package-options-contents" cellspacing="0">
254
+ <colgroup>
255
+ <col width="150">
256
+ <col width="*">
257
+ </colgroup>
258
+ <thead>
259
+ <th><?php echo Mage::helper('sales')->__('Contents') ?></th>
260
+ <th><?php echo Mage::helper('sales')->__('Explanation') ?></th>
261
+ </thead>
262
+ <tbody>
263
+ <td>
264
+ <select name="content_type" onchange="packaging.changeContentTypes(this);">
265
+ <?php foreach ($this->getContentTypes() as $key => $value): ?>
266
+ <option value="<?php echo $key ?>" >
267
+ <?php echo $value ?>
268
+ </option>
269
+ <?php endforeach; ?>
270
+ </select>
271
+ </td>
272
+ <td>
273
+ <input name="content_type_other" type="text" class="input-text options-content-type disabled" disabled="disabled" />
274
+ </td>
275
+ </tbody>
276
+ </table>
277
+ <?php endif; ?>
278
+
279
+ <div class="package-add-products">
280
+ <div class="package_prapare" style="display:none">
281
+ <div class="entry-edit-head">
282
+ <button type="button" class="scalable AddSelectedBtn" onclick="packaging.packItems(this);">
283
+ <span><span><span><?php echo Mage::helper('sales')->__('Add Selected Product(s) to Package') ?></span></span></span>
284
+ </button>
285
+ <h4><?php echo Mage::helper('sales')->__('Please Select Products to Add') ?></h4>
286
+ </div>
287
+ <div class="grid_prepare"></div>
288
+ </div>
289
+ </div>
290
+ </div>
291
+ <div id="packages_content"></div>
292
+ </div>
293
+ <div class="buttons-set a-right">
294
+ <button type="button" class="scalable disabled SavePackagesBtn" disabled="disabled" onclick="packaging.confirmPackaging();" title="<?php echo Mage::helper('sales')->__('Products should be added to package(s)')?>">
295
+ <span><span><span><?php echo Mage::helper('sales')->__('OK') ?></span></span></span>
296
+ </button>
297
+ <button type="button" class="scalable" onclick="packaging.cancelPackaging();">
298
+ <span><span><span><?php echo Mage::helper('sales')->__('Cancel') ?></span></span></span>
299
+ </button>
300
+ </div>
301
+ </div>
302
+ </div>
app/design/adminhtml/default/default/template/innobyte/emag_marketplace/sales/order/totals.phtml ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $this->setPriceDataObject($this->getSource()) ?>
2
+ <?php $vouchers = $this->getSource()->getEmagVouchers() ?>
3
+ <?php if ($vouchers): ?>
4
+ <?php /** @var $helper Innobyte_EmagMarketplace_Helper_Data */?>
5
+ <?php $helper = Mage::helper('innobyte_emag_marketplace'); ?>
6
+ <?php foreach($vouchers as $voucher): ?>
7
+ <tr>
8
+ <td class="label">
9
+ <?php echo $helper->getFormattedVoucherLabel($voucher['emag_voucher_name']) ?>
10
+ </td>
11
+ <td>
12
+ <?php echo $this->displayPrices($voucher['base_emag_sale_price'], $voucher['emag_sale_price']); ?>
13
+ </td>
14
+ </tr>
15
+ <?php endforeach ?>
16
+ <?php endif; ?>
app/design/adminhtml/default/default/template/innobyte/emag_marketplace/sales/order/view/comment.phtml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php /** @var $this Innobyte_EmagMarketplace_Block_Adminhtml_Sales_Order_View_Comment */ ?>
2
+ <ul class="note-list">
3
+ <li>
4
+ <?php if ($this->getCustomerComment()): ?>
5
+ <?php echo $this->escapeHtml($this->getCustomerComment(), array('b', 'br', 'strong', 'i', 'u')) ?>
6
+ <?php else: ?>
7
+ <?php echo Mage::helper('innobyte_emag_marketplace')->__('No comment supplied.') ?>
8
+ <?php endif; ?>
9
+ </li>
10
+ </ul>
app/design/adminhtml/default/default/template/innobyte/emag_marketplace/sales/order/view/invoice/popup.phtml ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php /** @var $this Innobyte_EmagMarketplace_Block_Adminhtml_Sales_Order_View_Invoice_Popup */ ?>
2
+ <?php echo $this->getFormInitScripts() ?>
3
+ <script type="text/javascript">
4
+ var inno = inno || {};
5
+
6
+ inno.emag_marketplace = {
7
+ id: 'emag_invoice_upload_window',
8
+ title: '<?php echo Mage::helper('innobyte_emag_marketplace')->__('eMAG Invoice Upload') ?>',
9
+ url: '<?php echo $this->getUrl('*/sales_invoice_upload/popup', array('_current' => true)) ?>',
10
+ popupWindow: null,
11
+ showPopup: function() {
12
+ if ($('emag_invoice_upload_window') && typeof(Windows) != 'undefined') {
13
+ Windows.focus('emag_invoice_upload_window');
14
+ return;
15
+ }
16
+ this.popupWindow = Dialog.info(null, {
17
+ closable: true,
18
+ resizable: false,
19
+ draggable: true,
20
+ className: 'magento',
21
+ windowClassName: 'popup-window',
22
+ title: this.title,
23
+ top: 50,
24
+ width: 800,
25
+ height: 225,
26
+ zIndex: 1000,
27
+ recenterAuto: false,
28
+ hideEffect: Element.hide,
29
+ showEffect: Element.show,
30
+ id: this.id,
31
+ url: this.url,
32
+ onClose: function (param, el) {
33
+ }
34
+ });
35
+ },
36
+ closePopup: function () {
37
+ Windows.close('emag_invoice_upload_window');
38
+ }
39
+ }
40
+
41
+
42
+ </script>
43
+ <div class="content-header">
44
+ <?php echo $this->getHeaderHtml() ?>
45
+ <p class="form-buttons"><?php echo $this->getButtonsHtml('header') ?></p>
46
+ </div>
47
+ <?php echo $this->getFormHtml() ?>
48
+ <?php if ($this->hasFooterButtons()): ?>
49
+ <div class="content-footer">
50
+ <p class="form-buttons"><?php echo $this->getButtonsHtml('footer') ?></p>
51
+ </div>
52
+ <?php endif; ?>
53
+ <?php echo $this->getFormScripts() ?>
app/design/adminhtml/default/default/template/innobyte/emag_marketplace/sales/order/view/tab/info.phtml ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php /** @var $this Mage_Adminhtml_Block_Sales_Order_View_Tab_Info */ ?>
2
+ <?php $_order = $this->getOrder() ?>
3
+ <div>
4
+ <div id="order-messages">
5
+ <?php echo $this->getChildHtml('order_messages') ?>
6
+ </div>
7
+ <?php echo $this->getChildHtml('order_info') ?>
8
+ <input type="hidden" name="order_id" value="<?php echo $_order->getId() ?>"/>
9
+ <?php if ($_order->getIsVirtual()): ?>
10
+ <div class="box-right">
11
+ <?php else: ?>
12
+ <div class="box-left">
13
+ <?php endif; ?>
14
+ <!--Payment Method-->
15
+ <div class="entry-edit">
16
+ <div class="entry-edit-head">
17
+ <h4 class="icon-head head-payment-method"><?php echo Mage::helper('sales')->__('Payment Information') ?></h4>
18
+ </div>
19
+ <fieldset>
20
+ <?php echo $this->getPaymentHtml() ?>
21
+ <div><?php echo Mage::helper('sales')->__('Order was placed using %s', $_order->getOrderCurrencyCode()) ?></div>
22
+ </fieldset>
23
+ </div>
24
+ </div>
25
+ <?php if (!$_order->getIsVirtual()): ?>
26
+ <div class="box-right">
27
+ <!--Shipping Method-->
28
+ <div class="entry-edit">
29
+ <div class="entry-edit-head">
30
+ <h4 class="icon-head head-shipping-method"><?php echo Mage::helper('sales')->__('Shipping &amp; Handling Information') ?></h4>
31
+ </div>
32
+ <fieldset>
33
+ <?php if ($_order->getTracksCollection()->count()) : ?>
34
+ <a href="#" id="linkId" onclick="popWin('<?php echo $this->helper('shipping')->getTrackingPopupUrlBySalesModel($_order) ?>','trackorder','width=800,height=600,resizable=yes,scrollbars=yes')" title="<?php echo $this->__('Track Order') ?>"><?php echo $this->__('Track Order') ?></a>
35
+ <br/>
36
+ <?php endif; ?>
37
+ <?php if ($_order->getShippingDescription()): ?>
38
+ <strong><?php echo $this->escapeHtml($_order->getShippingDescription()) ?></strong>
39
+
40
+ <?php if ($this->helper('tax')->displayShippingPriceIncludingTax()): ?>
41
+ <?php $_excl = $this->displayShippingPriceInclTax($_order); ?>
42
+ <?php else: ?>
43
+ <?php $_excl = $this->displayPriceAttribute('shipping_amount', false, ' '); ?>
44
+ <?php endif; ?>
45
+ <?php $_incl = $this->displayShippingPriceInclTax($_order); ?>
46
+
47
+ <?php echo $_excl; ?>
48
+ <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
49
+ (<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
50
+ <?php endif; ?>
51
+ <?php else: ?>
52
+ <?php echo $this->helper('sales')->__('No shipping information available'); ?>
53
+ <?php endif; ?>
54
+ </fieldset>
55
+ </div>
56
+ </div>
57
+ <?php endif; ?>
58
+ <div class="clear"></div>
59
+ <?php echo $this->getGiftOptionsHtml() ?>
60
+ <div class="clear"></div>
61
+ <div class="entry-edit">
62
+ <div class="entry-edit-head">
63
+ <h4 class="icon-head head-products"><?php echo Mage::helper('sales')->__('Items Ordered') ?></h4>
64
+ </div>
65
+ </div>
66
+ <?php echo $this->getItemsHtml() ?>
67
+ <div class="clear"></div>
68
+
69
+ <div class="box-left">
70
+ <div class="entry-edit">
71
+ <div class="entry-edit-head">
72
+ <h4><?php echo Mage::helper('sales')->__('Comments History') ?></h4>
73
+ </div>
74
+ <fieldset><?php echo $this->getChildHtml('order_history') ?></fieldset>
75
+ </div>
76
+ </div>
77
+ <div class="box-right entry-edit">
78
+ <div class="entry-edit-head"><h4><?php echo Mage::helper('sales')->__('Order Totals') ?></h4></div>
79
+ <div class="order-totals"><?php echo $this->getChildHtml('order_totals') ?></div>
80
+ </div>
81
+ <div class="clear"></div>
82
+
83
+ <div class="box-left">
84
+ <div class="entry-edit">
85
+ <div class="entry-edit-head">
86
+ <h4><?php echo Mage::helper('innobyte_emag_marketplace')->__('eMAG - Customer Comment') ?></h4>
87
+ </div>
88
+ <fieldset><?php echo $this->getChildHtml('emag_customer_comment') ?></fieldset>
89
+ </div>
90
+ </div>
91
+ <div class="clear"></div>
92
+ </div>
93
+
94
+ <?php echo $this->getChildHtml('popup_window');?>
95
+ <script type="text/javascript">
96
+ //<![CDATA[
97
+ /**
98
+ * Retrieve gift options tooltip content
99
+ */
100
+ function getGiftOptionsTooltipContent(itemId) {
101
+ var contentLines = [];
102
+ var headerLine = null;
103
+ var contentLine = null;
104
+
105
+ $$('#gift_options_data_' + itemId + ' .gift-options-tooltip-content').each(function (element) {
106
+ if (element.down(0)) {
107
+ headerLine = element.down(0).innerHTML;
108
+ contentLine = element.down(0).next().innerHTML;
109
+ if (contentLine.length > 30) {
110
+ contentLine = contentLine.slice(0,30) + '...';
111
+ }
112
+ contentLines.push(headerLine + ' ' + contentLine);
113
+ }
114
+ });
115
+ return contentLines.join('<br/>');
116
+ }
117
+ giftOptionsTooltip.setTooltipContentLoaderFunction(getGiftOptionsTooltipContent);
118
+ //]]>
119
+ </script>
app/etc/modules/Innobyte_Core.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Innobyte_Core>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Innobyte_Core>
8
+ </modules>
9
+ </config>
app/etc/modules/Innobyte_EmagMarketplace.xml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <modules>
3
+ <Innobyte_EmagMarketplace>
4
+ <active>true</active>
5
+ <codePool>local</codePool>
6
+ <depends>
7
+ <Mage_Adminhtml/>
8
+ <Mage_Sales/>
9
+ <Mage_Catalog/>
10
+ <Mage_Customer/>
11
+ <Innobyte_Core/>
12
+ </depends>
13
+ </Innobyte_EmagMarketplace>
14
+ </modules>
15
+ </config>
app/locale/en_US/Innobyte_EmagMarketplace.csv ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Date can be as far as 60 days in the future and cannot be earlier than tomorrow.", "Date can be as far as 60 days in the future and cannot be earlier than tomorrow."
2
+ "eMAG Marketplace","eMAG Marketplace"
3
+ "Click here to set eMAG Marketplace info for this product","Click here to set eMAG Marketplace info for this product"
4
+ "eMAG ID","eMAG ID"
5
+ "Name","Name"
6
+ "Characteristics","Characteristics"
7
+ "Family Types","Family Types"
8
+ "Updated at","Updated at"
9
+ "Created at","Created at"
10
+ "Name Latin","Name Latin"
11
+ "Region 1","Region 1"
12
+ "Region 2","Region 2"
13
+ "Region 3","Region 3"
14
+ "Region 4","Region 4"
15
+ "Region 1 Latin","Region 1 Latin"
16
+ "Region 2 Latin","Region 2 Latin"
17
+ "Region 3 Latin","Region 3 Latin"
18
+ "Region 4 Latin","Region 4 Latin"
19
+ "Geoid","Geoid"
20
+ "eMAG last modified","eMAG last modified"
21
+ "Upload File","Upload File"
22
+ "Invoice","Invoice"
23
+ "Is Storno","Is Storno"
24
+ "Upload","Upload"
25
+ "eMAG Upload Invoice","eMAG Upload Invoice"
26
+ "Rate","Rate"
27
+ "eMAG Categories","eMAG Categories"
28
+ "Synchronize categories","Synchronize categories"
29
+ "Please configure extension from System -> Configuration -> eMAG Marketplace","Please configure extension from System -> Configuration -> eMAG Marketplace"
30
+ "eMAG Localities","eMAG Localities"
31
+ "Synchronize localities","Synchronize localities"
32
+ "eMAG VATs","eMAG VATs"
33
+ "Synchronize VATs","Synchronize VATs"
34
+ "Successfully synced categories.","Successfully synced categories."
35
+ "An error occurred. Please try again later.","An error occurred. Please try again later."
36
+ "eMAG","eMAG"
37
+ "Localities","Localities"
38
+ "Successfully synced localities.","Successfully synced localities."
39
+ "Address Type (billing|shipping|shipping origin) not set.","Address Type (billing|shipping|shipping origin) not set."
40
+ "Please provide some part of the city name","Please provide some part of the city name"
41
+ "No category provided.","No category provided."
42
+ "Invalid category provided.","Invalid category provided."
43
+ "Successfully sent product to eMAG.","Successfully sent product to eMAG."
44
+ "Successfully sent offer to eMAG.","Successfully sent offer to eMAG."
45
+ "Please select some products.","Please select some products."
46
+ "Action cannot be applied for product(s): %s","Action cannot be applied for product(s): %s"
47
+ "Successfully sent to eMAG the product(s): %s","Successfully sent to eMAG the product(s): %s"
48
+ "Successfully sent to eMAG the offer for product(s): %s","Successfully sent to eMAG the offer for product(s): %s"
49
+ "Successfully deactivated offer for product(s): %s","Successfully deactivated offer for product(s): %s"
50
+ "VATs","VATs"
51
+ "Successfully synced VATs.","Successfully synced VATs."
52
+ "No VATs found.","No VATs found."
53
+ "eMAG Voucher successfully deleted!","eMAG Voucher successfully deleted!"
54
+ "There was an error while removing voucher. Please try again!","There was an error while removing voucher. Please try again!"
55
+ "There was an error while uploading file. Please try again!","There was an error while uploading file. Please try again!"
56
+ "Invoice not found!","Invoice not found!"
57
+ "Invoice successfully deleted.","Invoice successfully deleted."
58
+ "Order successfully synced with eMAG.","Order successfully synced with eMAG."
59
+ "Invalid order status!","Invalid order status!"
60
+ "Only eMAG orders can be acknowledged!","Only eMAG orders can be acknowledged!"
61
+ "Order successfully acknowledged.","Order successfully acknowledged."
62
+ "There was an error while trying to acknowledge eMAG order!","There was an error while trying to acknowledge eMAG order!"
63
+ "Categories","Categories"
64
+ "Settings","Settings"
65
+ "Innobyte EmagMarketplace Order Sync Errors","Innobyte EmagMarketplace Order Sync Errors"
66
+ "General Settings","General Settings"
67
+ "Enable","Enable"
68
+ "Enable/Disable extension.","Enable/Disable extension."
69
+ "Debug","Debug"
70
+ "Enable debug mode.","Enable debug mode."
71
+ "eMAG Domain","eMAG Domain"
72
+ "eMAG Marketplace domain in your country. (Ex: emag.ro)","eMAG Marketplace domain in your country. (Ex: emag.ro)"
73
+ "Allowed IP Addresses","Allowed IP Addresses"
74
+ "List of allowed IP Addresses that can access invoice directories. Separated by comma.","List of allowed IP Addresses that can access invoice directories. Separated by comma."
75
+ "Error Reporting Email","Error Reporting Email"
76
+ "Email address that will receive eMAG order sync errors.","Email address that will receive eMAG order sync errors."
77
+ "Error Reporting Email Template","Error Reporting Email Template"
78
+ "Set error reporting email template.","Set error reporting email template."
79
+ "Product offer availability ""limited stock""","Product offer availability ""limited stock"""
80
+ "Enable/Disable availability status ""limited stock"" for a product.","Enable/Disable availability status ""limited stock"" for a product."
81
+ "Availability Limited Stock","Availability Limited Stock"
82
+ "Qty limit under which the product, if ""in stock"", should be considered as ""limited stock""","Qty limit under which the product, if ""in stock"", should be considered as ""limited stock"""
83
+ "Send Product Offer Stock Qty","Send Product Offer Stock Qty"
84
+ "Send also magento real stock qty, not only availability flags as ""limited stock"", ""in stock"", ""out of stock""","Send also magento real stock qty, not only availability flags as ""limited stock"", ""in stock"", ""out of stock"""
85
+ "Api Settings","Api Settings"
86
+ "Api URL","Api URL"
87
+ "Api URL provided by eMAG.","Api URL provided by eMAG."
88
+ "Api Username","Api Username"
89
+ "Api username provided by eMAG.","Api username provided by eMAG."
90
+ "Api Password","Api Password"
91
+ "Api password provided by eMAG.","Api password provided by eMAG."
92
+ "Client Code","Client Code"
93
+ "Client code provided by eMAG.","Client code provided by eMAG."
94
+ "Invoice / Creditmemo Settings","Invoice / Creditmemo Settings"
95
+ "Invoice Prefix","Invoice Prefix"
96
+ "Define invoice prefix. Leave blank to use Magento default invoice prefix. (Ex: PREFIX10000122) <br><strong>Note:</strong> <span style=""color:orange"">Maximum length 10 characters.</span>","Define invoice prefix. Leave blank to use Magento default invoice prefix. (Ex: PREFIX10000122) <br><strong>Note:</strong> <span style=""color:orange"">Maximum length 10 characters.</span>"
97
+ "Creditmemo Prefix","Creditmemo Prefix"
98
+ "Define creditmemo prefix. Leave blank to use Magento default creditmemo prefix. (Ex: PREFIX10000122) <br><strong>Note:</strong> <span style=""color:orange"">Maximum length 10 characters.</span>","Define creditmemo prefix. Leave blank to use Magento default creditmemo prefix. (Ex: PREFIX10000122) <br><strong>Note:</strong> <span style=""color:orange"">Maximum length 10 characters.</span>"
99
+ "Shipping Settings","Shipping Settings"
100
+ "Courier Account Id","Courier Account Id"
101
+ "Unique identifier for vendor 's courier account. If not provided, a default account will be used when creating AWBs.","Unique identifier for vendor 's courier account. If not provided, a default account will be used when creating AWBs."
102
+ "eMAG Bank Transfer","eMAG Bank Transfer"
103
+ "Payment Title","Payment Title"
104
+ "New Order Status","New Order Status"
105
+ "Sort Order","Sort Order"
106
+ "eMAG Cash on Delivery","eMAG Cash on Delivery"
107
+ "eMAG Credit Card","eMAG Credit Card"
108
+ "eMAG Unknown","eMAG Unknown"
109
+ "eMAG Shipping","eMAG Shipping"
110
+ "Title","Title"
111
+ "Ship to Applicable Countries","Ship to Applicable Countries"
112
+ "Ship to Specific Countries","Ship to Specific Countries"
113
+ "Locality Id","Locality Id"
114
+ "Not implemented","Not implemented"
115
+ "Invalid shipment request object.","Invalid shipment request object."
116
+ "Invalid shipment request.","Invalid shipment request."
117
+ "No packages for request.","No packages for request."
118
+ "No eMAG shipping extra fields.","No eMAG shipping extra fields."
119
+ "Invalid cash on delivery value.","Invalid cash on delivery value."
120
+ "Invalid eMAG order id.","Invalid eMAG order id."
121
+ "Receiver 's name must have at least 3 letters.","Receiver 's name must have at least 3 letters."
122
+ "Receiver 's contact person name is empty.","Receiver 's contact person name is empty."
123
+ "Receiver 's contact phone must have between 8 and 11 digits and may contain a + sign at the beginning.","Receiver 's contact phone must have between 8 and 11 digits and may contain a + sign at the beginning."
124
+ "Receiver 's city id is empty.","Receiver 's city id is empty."
125
+ "Receiver 's street must have at least 3 letters.","Receiver 's street must have at least 3 letters."
126
+ "Sender 's name must have at least 3 letters.","Sender 's name must have at least 3 letters."
127
+ "Sender 's contact person name is empty.","Sender 's contact person name is empty."
128
+ "Sender 's contact phone must have between 8 and 11 digits and may contain a + sign at the beginning.","Sender 's contact phone must have between 8 and 11 digits and may contain a + sign at the beginning."
129
+ "Sender 's contact phone must have between 8 and 11 digits and may contain a + sign at the beginning. <a href=""%s"" target=""_blank"">Edit</a> store phone info.","Sender 's contact phone must have between 8 and 11 digits and may contain a + sign at the beginning. <a href=""%s"" target=""_blank"">Edit</a> store phone info."
130
+ "Sender 's city id is empty.","Sender 's city id is empty."
131
+ "Sender 's city id is empty. Please <a href=""%s"" target=""_blank"">choose</a> an eMAG city for origin shipping settings.","Sender 's city id is empty. Please <a href=""%s"" target=""_blank"">choose</a> an eMAG city for origin shipping settings."
132
+ "Sender 's street must have at least 3 letters.","Sender 's street must have at least 3 letters."
133
+ "Sender 's street must have at least 3 letters. <a href=""%s"" target=""_blank"">Edit</a> street origin shipping settings.","Sender 's street must have at least 3 letters. <a href=""%s"" target=""_blank"">Edit</a> street origin shipping settings."
134
+ "No product eMAG data set.","No product eMAG data set."
135
+ "No eMAG product name.","No eMAG product name."
136
+ "No eMAG product brand.","No eMAG product brand."
137
+ "No eMAG category id.","No eMAG category id."
138
+ "No product sku.","No product sku."
139
+ "No product url.","No product url."
140
+ "No product eMAG data set.","No product eMAG data set."
141
+ "No eMAG product commission type.","No eMAG product commission type."
142
+ "No product stock data.","No product stock data."
143
+ "Invalid eMAG offer start date.","Invalid eMAG offer start date."
144
+ "Offer start date can be as far as 60 days in the future and cannot be earlier than tomorrow.","Offer start date can be as far as 60 days in the future and cannot be earlier than tomorrow."
145
+ "Invalid product model.","Invalid product model."
146
+ "Invalid api response format. ""isError"" is missing.","Invalid api response format. ""isError"" is missing."
147
+ "Invalid api response format. ""messages"" is missing.","Invalid api response format. ""messages"" is missing."
148
+ "Invalid api response format. ""messages"" has invalid format.","Invalid api response format. ""messages"" has invalid format."
149
+ "Invalid api response format. ""results"" is missing.","Invalid api response format. ""results"" is missing."
150
+ "Invalid api response format. ""results"" has invalid format.","Invalid api response format. ""results"" has invalid format."
151
+ "Send eMAG product","Send eMAG product"
152
+ "Send eMAG offer","Send eMAG offer"
153
+ "Deactivate eMAG offer","Deactivate eMAG offer"
154
+ "Invalid product id.","Invalid product id."
155
+ "Please fill eMAG product name.","Please fill eMAG product name."
156
+ "Please fill eMAG product brand.","Please fill eMAG product brand."
157
+ "Please choose eMAG category.","Please choose eMAG category."
158
+ "Please choose eMAG offer status.","Please choose eMAG offer status."
159
+ "Invalid eMAG warranty. Should be a real number equal to or greater than 0 and smaller than 255.","Invalid eMAG warranty. Should be a real number equal to or greater than 0 and smaller than 255."
160
+ "Please choose eMAG commission type.","Please choose eMAG commission type."
161
+ "Please fill eMAG commission value.","Please fill eMAG commission value."
162
+ "Invalid eMAG commission value. Should be a percentage between 0 and 100.","Invalid eMAG commission value. Should be a percentage between 0 and 100."
163
+ "Invalid eMAG commission value. Should be a real number equal to or greater than 0.","Invalid eMAG commission value. Should be a real number equal to or greater than 0."
164
+ "Invalid eMAG handling time. Should be a real number equal to or greater than 0 and smaller than 255.","Invalid eMAG handling time. Should be a real number equal to or greater than 0 and smaller than 255."
165
+ "Offer start date can be as far as 60 days in the future and cannot be earlier than tomorrow.","Offer start date can be as far as 60 days in the future and cannot be earlier than tomorrow."
166
+ "Please choose eMAG VAT.","Please choose eMAG VAT."
167
+ "Send eMAG product","Send eMAG product"
168
+ "Send eMAG offer","Send eMAG offer"
169
+ "Deactivate eMAG offer","Deactivate eMAG offer"
170
+ "eMAG order update failed. Invalid Magento Order!","eMAG order update failed. Invalid Magento Order!"
171
+ "No products found in eMAG order!","No products found in eMAG order!"
172
+ "Store currency and eMAG currency codes do not match!","Store currency and eMAG currency codes do not match!"
173
+ "Customer not found in eMAG order!","Customer not found in eMAG order!"
174
+ "There was an error while processing order products!","There was an error while processing order products!"
175
+ "There was an error while processing vouchers!","There was an error while processing vouchers!"
176
+ "There was an error while processing order attachments","There was an error while processing order attachments"
177
+ "There was an error while processing order invoices!","There was an error while processing order invoices!"
178
+ "Cannot create an invoice without products!","Cannot create an invoice without products!"
179
+ "eMAG Standard Delivery","eMAG Standard Delivery"
180
+ "Private Entity","Private Entity"
181
+ "Legal Entity","Legal Entity"
182
+ "Invalid commission type provided","Invalid commission type provided"
183
+ "Inactive","Inactive"
184
+ "Active","Active"
185
+ "Invoice/Creditmemo prefix can only be edited at store level!","Invoice/Creditmemo prefix can only be edited at store level!"
186
+ "eMAG Upload Invoice","eMAG Upload Invoice"
187
+ "You are about to mark this order as acknowledged. Are you sure?","You are about to mark this order as acknowledged. Are you sure?"
188
+ "eMAG Acknowledge","eMAG Acknowledge"
189
+ "This action will update order in eMAG Marketplace. Are you sure?","This action will update order in eMAG Marketplace. Are you sure?"
190
+ "eMAG Prepared","eMAG Prepared"
191
+ "eMAG Cancel","eMAG Cancel"
192
+ "Brand","Brand"
193
+ "Description","Description"
194
+ "Barcode(s)","Barcode(s)"
195
+ "Product barcode identifier (EAN, UPC, ISBN, GTIN). Please use the supplier barcode, not your internal barcodes.","Product barcode identifier (EAN, UPC, ISBN, GTIN). Please use the supplier barcode, not your internal barcodes."
196
+ "Category","Category"
197
+ "Part Number Key","Part Number Key"
198
+ "Used for attaching a product offer to an existing product in eMAG platform.<br />If you want to create new product, don't set this key.","Used for attaching a product offer to an existing product in eMAG platform.<br />If you want to create new product, don't set this key."
199
+ "Ex: for product http://www.emag.ro/telefon-mobil-nokia-105-black-105-black/pd/D5DD9BBBM/ the part_number_key is D5DD9BBBM.","Ex: for product http://www.emag.ro/telefon-mobil-nokia-105-black-105-black/pd/D5DD9BBBM/ the part_number_key is D5DD9BBBM."
200
+ "Offer Status","Offer Status"
201
+ "Warranty","Warranty"
202
+ "The warranty offered in months.","The warranty offered in months."
203
+ "Commission Type","Commission Type"
204
+ "The type of commission for a finalized order containing the offer.","The type of commission for a finalized order containing the offer."
205
+ "Commission Value","Commission Value"
206
+ "If type is percentage the value should be between 0 and 100, otherwise a float with 4 decimals and without VAT.","If type is percentage the value should be between 0 and 100, otherwise a float with 4 decimals and without VAT."
207
+ "Handling Time","Handling Time"
208
+ "Handling time, in number of days counted from the day the order was received. If handling_time = 0 the order will be shipped the same day it is received.","Handling time, in number of days counted from the day the order was received. If handling_time = 0 the order will be shipped the same day it is received."
209
+ "Start Date","Start Date"
210
+ "If it's a new offer, it represents the date your offer will be available from.<br />For offer updates, it schedules value updates for the following data: sale_price, recommended_price, stock, handling_time, commission, vat_id, warranty, status, availability.<br />All other data will be updated on the fly.<br />Using Start Date, for example, you can schedule the inactivation of an offer, a price update, etc.","If it's a new offer, it represents the date your offer will be available from.<br />For offer updates, it schedules value updates for the following data: sale_price, recommended_price, stock, handling_time, commission, vat_id, warranty, status, availability.<br />All other data will be updated on the fly.<br />Using Start Date, for example, you can schedule the inactivation of an offer, a price update, etc."
211
+ "VAT","VAT"
212
+ "If not set, will be automatically calculated based on product 's class tax and store shipping origin address.","If not set, will be automatically calculated based on product 's class tax and store shipping origin address."
213
+ "Save","Save"
214
+ "Remove","Remove"
215
+ "Cash on delivery value","Cash on delivery value"
216
+ "Insured value","Insured value"
217
+ "Observation","Observation"
218
+ "Pickup and return","Pickup and return"
219
+ "If set to ""Yes"", sender expects something in return to this expedition (documents, buy-back products, etc).","If set to ""Yes"", sender expects something in return to this expedition (documents, buy-back products, etc)."
220
+ "Saturday delivery","Saturday delivery"
221
+ "If set to ""Yes"", sender requests the package to be delivered on Saturday.","If set to ""Yes"", sender requests the package to be delivered on Saturday."
222
+ "Same day delivery","Same day delivery"
223
+ "Open On Receipt","Open On Receipt"
224
+ "If set to ""Yes"", sender requests the package to be delivered the same day.","If set to ""Yes"", sender requests the package to be delivered the same day."
225
+ "eMAG Invoice Upload","eMAG Invoice Upload"
226
+ "eMAG - Customer Comment","eMAG - Customer Comment"
227
+ "No comment supplied.","No comment supplied."
228
+ "Invalid eMAG order status: %s","Invalid eMAG order status: %s"
229
+ "Product with ID %s not found. eMAG - SKU: %s","Product with ID %s not found. eMAG - SKU: %s"
230
+ "There was an error while processing products: %s","There was an error while processing products: %s"
231
+ "Order property ""%s"" not found!","Order property ""%s"" not found!"
232
+ "There was an error while processing currency rates: %s","There was an error while processing currency rates: %s"
233
+ "There was an error while processing vouchers: %s","There was an error while processing vouchers: %s"
234
+ "Invalid eMag payment method: %s","Invalid eMag payment method: %s"
235
+ "There was an error while processing payment: %s","There was an error while processing payment: %s"
236
+ "Invalid Magento order status: %s","Invalid Magento order status: %s"
237
+ "Invalid Magento payment method: %s","Invalid Magento payment method: %s"
238
+ "Unable to write to media folder: %s","Unable to write to media folder: %s"
239
+ "Magento Invoice Pdf could not be saved. Invoice increment id: #%s","Magento Invoice Pdf could not be saved. Invoice increment id: #%s"
240
+ "Magento Creditmemo Pdf could not be saved. Creditmemo increment id: #%s","Magento Creditmemo Pdf could not be saved. Creditmemo increment id: #%s"
241
+ "There was an error while trying to acknowledge eMAG order: %s","There was an error while trying to acknowledge eMAG order: %s"
242
+ "Amount of %s captured by eMAG Marketplace.","Amount of %s captured by eMAG Marketplace."
243
+ "Order state ""%s"" is not valid for eMAG orders!","Order state ""%s"" is not valid for eMAG orders!"
244
+ "There was an error while creating order invoice: %s","There was an error while creating order invoice: %s"
245
+ "Cannot create invoice for eMAG order #%s","Cannot create invoice for eMAG order #%s"
246
+ "AWB PDF URL","AWB PDF URL"
247
+ "URL where to read AWB 's PDF from.<br/>Ex: https://mktp-stage.emag.ro/awb/read_pdf","URL where to read AWB 's PDF from.<br/>Ex: https://mktp-stage.emag.ro/awb/read_pdf"
248
+ "Invalid API awb response","Invalid API awb response"
249
+ "Read AWB PDF URL was not set in system config.","Read AWB PDF URL was not set in system config."
250
+ "Please confirm product sending. All data that hasn't been saved will be lost.","Please confirm product sending. All data that hasn't been saved will be lost."
251
+ "Please confirm offer sending. All data that hasn't been saved will be lost.","Please confirm offer sending. All data that hasn't been saved will be lost."
252
+ "Please confirm offer deactivation. All data that hasn't been saved will be lost.","Please confirm offer deactivation. All data that hasn't been saved will be lost."
253
+ "Loading...","Loading..."
254
+ "eMAG Api Response => %s","eMAG Api Response => %s"
255
+ "Sync process started for store: %s","Sync process started for store: %s"
256
+ "Sync process finished for store: %s","Sync process finished for store: %s"
257
+ "Sync process started for order: #%s","Sync process started for order: #%s"
258
+ "eMAG order: #%s could not be processed. ERROR: %s","eMAG order: #%s could not be processed. ERROR: %s"
259
+ "Sync process finished for order: #%s","Sync process finished for order: #%s"
260
+ "Phone must have between 8 and 11 digits and may contain a + sign at the beginning.","Phone must have between 8 and 11 digits and may contain a + sign at the beginning."
261
+ "Successfully deactivated offer.","Successfully deactivated offer."
262
+ "No category characteristic ""%s"" value found.","No category characteristic ""%s"" value found."
263
+ "Voucher will be removed permanently from quote. Are you sure?","Voucher will be removed permanently from quote. Are you sure?"
264
+ "There was an error while processing request.","There was an error while processing request."
265
+ "Not an eMAG order!","Not an eMAG order!"
266
+ "Unable to save Magento invoice to disk","Unable to save Magento invoice to disk"
267
+ "Unable to save Magento creditmemo to disk","Unable to save Magento creditmemo to disk"
268
+ "Family Type","Family Type"
269
+ "This attribute will have to be set on associated products individually","This attribute will have to be set on associated products individually"
270
+ "Associated product #%d error: ","Associated product #%d error: "
271
+ "Please choose eMAG family type.","Please choose eMAG family type."
272
+ "Invalid family type provided.","Invalid family type provided."
273
+ "Associated product 's category does not match parent configurable product 's category","Associated product 's category does not match parent configurable product 's category"
274
+ "General Information","General Information"
275
+ "Name","Name"
276
+ "Should be consistent with eMAG Product Documentation Standard.","Should be consistent with eMAG Product Documentation Standard."
277
+ "Should be consistent with eMAG Product Documentation Standard. Can contain basic HTML tags.","Should be consistent with eMAG Product Documentation Standard. Can contain basic HTML tags."
278
+ "Product Offer","Product Offer"
279
+
app/locale/en_US/template/email/innobyte/core/debug.html ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--@subject Troubleshooter email for {{var store.getFrontendName()}}! @-->
2
+ <!--@vars
3
+ {"store url=\"\"":"Store Url",
4
+ "var logo_url":"Email Logo Image Url",
5
+ "var magento":"Magento information",
6
+ "var explanation_message":"Explanation message",
7
+ "var php_info":"PHP info"}
8
+ @-->
9
+
10
+ <!--@styles
11
+ body,td { color:#2f2f2f; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; }
12
+ @-->
13
+
14
+ <body style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
15
+ <div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
16
+ <table cellspacing="0" cellpadding="0" border="0" height="100%" width="100%">
17
+ <tr>
18
+ <td align="center" valign="top" style="padding:20px 0 20px 0">
19
+ <!-- [ header starts here] -->
20
+ <table bgcolor="FFFFFF" cellspacing="0" cellpadding="10" border="0" width="650" style="border:1px solid #E0E0E0;">
21
+ <tr>
22
+ <td valign="top">
23
+ <a href="{{store url=""}}">
24
+ <img src="{{var logo_url}}" alt="{{var logo_alt}}" style="margin-bottom:10px;" border="0"/>
25
+ </a>
26
+ </td>
27
+ </tr>
28
+ <!-- [ middle starts here] -->
29
+ <tr>
30
+ <td valign="top">
31
+ <h1 style="font-size:22px; font-weight:normal; line-height:22px; margin:0 0 11px 0;">Hello,</h1>
32
+ <p style="font-size:12px; line-height:16px; margin:0 0 16px 0;">
33
+ This email contains informations regarding <a href="{{store url=""}}">{{var store.getFrontendName()}}</a>.
34
+ </p>
35
+
36
+ <p style="font-style: italic;">{{var explanation_message}}</p>
37
+ <p></p>
38
+ <p style="border:1px solid #E0E0E0; font-size:12px; line-height:16px; margin:0; padding:13px 18px; background:#f9f9f9;">
39
+ {{block type='core/template'
40
+ area='adminhtml'
41
+ template='innobyte/core/debugger_email/general.phtml'
42
+ magento=$magento}}
43
+ </p>
44
+
45
+
46
+ <h2>Installed Innobyte Extension</h2>
47
+ {{block type='core/template'
48
+ area='adminhtml'
49
+ template='innobyte/core/debugger_email/inno_extensions.phtml'
50
+ magento=$magento}}
51
+
52
+
53
+ <h2>Disabled output</h2>
54
+ {{block type='core/template'
55
+ area='adminhtml'
56
+ template='innobyte/core/debugger_email/disabled_extensions.phtml'
57
+ magento=$magento}}
58
+
59
+
60
+ <h2>Rewrites</h2>
61
+ {{block type='core/template'
62
+ area='adminhtml'
63
+ template='innobyte/core/debugger_email/rewrites.phtml'
64
+ magento=$magento}}
65
+
66
+ <h2>Cron</h2>
67
+ {{block type='core/template'
68
+ area='adminhtml'
69
+ template='innobyte/core/debugger_email/cron.phtml'
70
+ magento=$magento}}
71
+
72
+ <hr/>
73
+
74
+ {{var php_info}}
75
+
76
+ <!-- <h2>Installed Innobyte Extensions Config Data</h2>
77
+ {{block type='core/template'
78
+ area='adminhtml'
79
+ template='innobyte/core/debugger_email/inno_config_data.phtml'
80
+ magento=$magento}}-->
81
+
82
+ </td>
83
+ </tr>
84
+ <!-- [ footer starts here] -->
85
+ <tr>
86
+ <td bgcolor="#EAEAEA" align="center" style="background:#EAEAEA; text-align:center;">
87
+ <center>
88
+ <p style="font-size:12px; margin:0;">
89
+ Thank you, <strong>{{var store.getFrontendName()}}</strong>
90
+ </p>
91
+ </center>
92
+ </td>
93
+ </tr>
94
+ </table>
95
+ </td>
96
+ </tr>
97
+ </table>
98
+ </div>
99
+ </body>
app/locale/en_US/template/email/innobyte/emag_marketplace/errors.html ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <!--@subject eMAG order sync failed @-->
3
+ <!--@vars
4
+ "var errors":"Order sync errors"}
5
+ @-->
6
+ <div>Hello!</div>
7
+ <div>There was an error while synchronizing eMAG orders. Below is your error:</div>
8
+ <div>{{var errors}}</div>
9
+ <br/>
10
+ <div>For more details please refer to magento logs.</div>
js/innobyte/core/init.js ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ function initInnoCore(){
2
+ if(innobyte_core_admin_section == 'innobyte_core'){
3
+ $('innobyte_core_extensions').update($('innobyte_core_extensions_hidden').innerHTML)
4
+ }
5
+ if(innobyte_core_admin_section == 'innobyte_shop'){
6
+ $('innobyte_shop_extensions').update($('innobyte_shop').innerHTML)
7
+ }
8
+ }
9
+ Event.observe(window, 'load', function() {
10
+ initInnoCore();
11
+ });
package.xml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Innobyte_EmagMarketplace</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>Innobyte License</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Being the fastest growing marketplace in Romania, Bulgaria and Hungary, eMAG Marketplace will bring your store&#x2019;s sales to the next level by opening a new and efficient sales channel.</summary>
10
+ <description>Being the fastest growing marketplace in Romania, Bulgaria and Hungary, eMAG Marketplace will bring your store&#x2019;s sales to the next level by opening a new and efficient sales channel.&#xD;
11
+ eMAG Marketplace integration extension by Innobyte helps Magento store owners publish their products on eMAG Marketplace and build up their reputation.</description>
12
+ <notes>-</notes>
13
+ <authors><author><name>Florin Mihai Savici</name><user>innobyte</user><email>management@innobyte.com</email></author></authors>
14
+ <date>2015-05-05</date>
15
+ <time>11:55:41</time>
16
+ <contents><target name="magelocal"><dir name="Innobyte"><dir name="EmagMarketplace"><dir><dir name="Block"><dir name="Adminhtml"><dir name="Catalog"><dir name="Product"><dir name="Edit"><dir name="Tab"><file name="EmagMarketplace.php" hash="84d28e6371a85f378038e5412158ebb3"/></dir></dir><file name="Edit.php" hash="56121505211aee840a3f896283b3cd05"/></dir></dir><dir name="Category"><file name="Grid.php" hash="17d5e61840283e320e455796b063b85b"/></dir><file name="Category.php" hash="b28cf6ff81b68b26299ea2d94f19ef1e"/><dir name="Form"><dir name="Element"><file name="Barcodes.php" hash="029b5cabf48a1475378ff9ec83242c72"/><file name="File.php" hash="2d19999b0bf01b33e07a1667e89bc5c3"/></dir><dir name="Field"><file name="LocalityId.php" hash="fda3d9e04a2aab30d3affcc377770571"/></dir></dir><dir name="Locality"><file name="Grid.php" hash="9d3c565f261f93d6b38d196be6b9fa20"/></dir><file name="Locality.php" hash="244d56f08dbfcb14924c6dc3607a12c3"/><dir name="Sales"><dir name="Order"><dir name="Create"><dir name="Billing"><dir name="Method"><file name="Form.php" hash="5c2d94f37317d23ab35292d5a9b55a85"/></dir></dir><dir name="Items"><file name="Grid.php" hash="c58d1f3342f10014fd8cf2b9fa2a7380"/></dir><dir name="Shipping"><dir name="Method"><file name="Form.php" hash="c6596c59ebfb7b7e73ab06da32c7adf5"/></dir></dir><dir name="Totals"><file name="Voucher.php" hash="547dbfe0c4107d8a041cd35d0d0358d5"/></dir></dir><dir name="View"><file name="Comment.php" hash="39a50c5d6ecf9622523f0948f7d1052a"/><dir name="Invoice"><file name="Popup.php" hash="e936b3a67ad5f4bd41cb3458978973e3"/><dir name="Upload"><file name="Form.php" hash="08661772c4b2d4dad04ac41b1bc6f2b0"/></dir><file name="Upload.php" hash="e7d9468ab75a4da81ad947ee35ea99aa"/></dir></dir></dir></dir><dir name="Vat"><file name="Grid.php" hash="6cf11cb0e2568052512dcd9af8a47416"/></dir><file name="Vat.php" hash="af6380f2b1a91540a85717d8f7cc024c"/></dir></dir><dir name="Helper"><file name="Data.php" hash="6729a41a90e4152ce08a63f1c4fe02db"/></dir><dir name="Model"><dir name="Api"><file name="Abstract.php" hash="04fa602912f05d53f76839a7057b27f1"/><file name="Awb.php" hash="7427827fe386c1fd48c47698d076cada"/><file name="Category.php" hash="abcaa037eca294794c7586a9324c7874"/><file name="Locality.php" hash="9229328cbd3387cfa41e3be79b79de87"/><file name="Order.php" hash="5dd5599ae6747cbe7912b47b78a9754a"/><file name="Product.php" hash="79679cf55339f17ff8d377c4a65e9a55"/><file name="Response.php" hash="4efb4046012f2a8eab44c0b0583fe5a0"/><file name="Vat.php" hash="1dadec377d4b25cad027b6299ece0f78"/></dir><dir name="Catalog"><dir name="Product"><file name="Observer.php" hash="e57ab404faa3111b1e379e83e3ef2a5e"/></dir></dir><dir name="Category"><file name="Characteristic.php" hash="c861ac8bb0485228056139ec2a5b2b1b"/><file name="Familytype.php" hash="c6ac762fa2f20261774c02490a157226"/></dir><file name="Category.php" hash="ebaf767fa33ad5af408286614dd20ef0"/><file name="Cron.php" hash="537fcc07585e2a502fd322c97ff6cd48"/><dir name="Customer"><file name="Attributes.php" hash="04866547213ce95f7c2caa5d426ba681"/><file name="Form.php" hash="259c8eba0ff64f7aa2559f46f9bd0bd4"/></dir><dir name="Invoice"><dir name="Pdf"><dir name="Total"><file name="Voucher.php" hash="e92be3b9b90677f0ff7ede6721eab3bc"/></dir></dir></dir><dir name="Locality"><file name="Flag.php" hash="a4e04313b24d2f32e9a7c101b7a3ebf4"/></dir><file name="Locality.php" hash="9eebf51b580234af3279d22801368c24"/><dir name="Order"><dir name="Convert"><file name="Abstract.php" hash="7d487712955771f834bd2daaaaf891d4"/><dir name="Emag"><file name="Update.php" hash="1140b2b3b114f24ec31b619e8d2d9501"/></dir><file name="Emag.php" hash="55b9823148ea7ecb173b2bcc4d77699c"/><file name="Magento.php" hash="735502541dfab539c8b306bc2f8f991e"/></dir></dir><dir name="Payment"><dir name="Method"><file name="Banktransfer.php" hash="de16ae6d2bfbe44efae91de5cb51c9c9"/><file name="Cashondelivery.php" hash="31d5608e9b4c2e47b03b70d922114ee1"/><file name="Cc.php" hash="054e75f54dbdb92dd92c79cc69e6006a"/><file name="Unknown.php" hash="c2bfa3c318a5d14867589a6d162d3014"/></dir></dir><file name="Product.php" hash="c8c910e60151bb1bb22c40ebaf12bc75"/><dir name="Resource"><dir name="Category"><dir name="Characteristic"><file name="Collection.php" hash="199a72bfe17fc978980cc466df2e6bf1"/></dir><file name="Characteristic.php" hash="a6a7f440c274a8dc70e21601461faa43"/><file name="Collection.php" hash="58380ccc531ad65837eda3d1ec326279"/><dir name="Familytype"><file name="Collection.php" hash="b51fb1747d1c563605801a52cddbc807"/></dir><file name="Familytype.php" hash="252f23169c78af34f1101c5c1ef00429"/></dir><file name="Category.php" hash="d0b00b7a79d42b1c8264215af8f6f25d"/><dir name="Locality"><file name="Collection.php" hash="919d2ec66fde1bfdfdba7a4351ec6e5b"/></dir><file name="Locality.php" hash="984483f1f254c773dc03f84e7ecfc842"/><dir name="Product"><file name="Collection.php" hash="2b269b788215822b1e836f1685eef1c6"/></dir><file name="Product.php" hash="8086bddef12d45e3b700e64f7a5154cd"/><dir name="Sales"><file name="Abstract.php" hash="4e28e8cea40a92c8551b9bb61fcc9168"/><dir name="Address"><file name="Abstract.php" hash="c95b407223fec1067ea66080fdf10677"/></dir><dir name="Invoice"><file name="Collection.php" hash="be9a2e37e986174327d4e532175a1a98"/></dir><file name="Invoice.php" hash="729574058005ed24ac39da04366d6c51"/><dir name="Item"><file name="Abstract.php" hash="a750e4cfcb85af0781047fa917e78d5c"/></dir><dir name="Order"><file name="Address.php" hash="ded5c157ac93c958d2c8149e97ab7b8a"/><dir name="Item"><file name="Collection.php" hash="cc749faeb2b194bab19c8b2f6657bf23"/></dir><file name="Item.php" hash="192143c67ae67ce77d5a69c07edc5f11"/><dir name="Voucher"><file name="Collection.php" hash="1e99b2c9e29eae6a7ae58d2f56acd01d"/></dir><file name="Voucher.php" hash="307aba5c74dbcd3a99ba37f8f0c72df2"/></dir><file name="Order.php" hash="f560e8f1bf96e2e6a41a692d5fb6c024"/><dir name="Quote"><file name="Address.php" hash="dd2ed7664775fe2d017a62e99f185b8b"/><dir name="Voucher"><file name="Collection.php" hash="d92263c78194131f1f93b965309dea04"/></dir><file name="Voucher.php" hash="75da1101f5ef453b6f796a127120b0d2"/></dir><file name="Quote.php" hash="2e451c02bd215c279a39f33156e464e4"/><dir name="Voucher"><file name="Abstract.php" hash="c4c39040b36e50120a227b6e39138fa5"/></dir></dir><dir name="Vat"><file name="Collection.php" hash="960899654592afb847d3bbf08a812d4d"/></dir><file name="Vat.php" hash="bd96a9809e1732c0192835443474a41b"/></dir><dir name="Sales"><file name="Abstract.php" hash="a631cb89d8d3f1613e332573330539e8"/><dir name="Address"><file name="Abstract.php" hash="ba8a438491d2b5de442bee67541594d0"/></dir><file name="Invoice.php" hash="70a156a393c81c2704e510af89e13631"/><dir name="Item"><file name="Abstract.php" hash="d308f8ad6b1aeaa1eade7c7457ab0ef4"/></dir><file name="Observer.php" hash="08f7c72a45db4b2ef17652b8ad6aa5ed"/><dir name="Order"><file name="Address.php" hash="60ae8af915f7ef591a99ce963ace9c70"/><dir name="Creditmemo"><file name="Total.php" hash="2ae049c6b5d3e97b2df36c532eaf1079"/></dir><dir name="Invoice"><file name="Total.php" hash="a0749ac2cdaef5242f90e377cfb22094"/></dir><file name="Item.php" hash="56fd503ed25e09569b4b220f1ed828cd"/><file name="Status.php" hash="2cc44f61150581a931c76a7224402724"/><file name="Voucher.php" hash="bde2d05e031f136aaf59478b842d68e6"/></dir><file name="Order.php" hash="e345960b8361cf62e57f4e10cbc890a1"/><dir name="Quote"><dir name="Address"><dir name="Total"><file name="Voucher.php" hash="360834496dd8e6ba2f2ebe5481cb5357"/></dir></dir><file name="Address.php" hash="9e8e4ee7aa202b4940e1d532205db098"/><file name="Voucher.php" hash="e1364b975930aa4bc13fb5d4348ceb55"/></dir><file name="Quote.php" hash="30ad86af4d35ecb361feda0892f1ad78"/><dir name="Voucher"><file name="Abstract.php" hash="5db452297c71ba7cb2452347e8950131"/></dir></dir><dir name="Shipping"><dir name="Carrier"><file name="Emag.php" hash="70808be244b81ac6829e87a4a6e3349c"/></dir></dir><dir name="Source"><file name="Category.php" hash="1c23985bd28e00317bf9b85b6ec10741"/><file name="CommissionTypes.php" hash="e7c14db1490db8b4b9c0413d4f4f40aa"/><dir name="Customer"><dir name="Address"><dir name="Attributes"><file name="Legalentity.php" hash="996caae77c6a7cf32e92343ab5a0ab4e"/></dir></dir></dir><file name="FamilyType.php" hash="170f2cdc201c2e0d41adfaefa5309840"/><file name="OfferStatus.php" hash="0d08ef9e0379014e97f732b3ebd3bb71"/><file name="Vat.php" hash="74fc94ccf2fc63fb22697e44f610a9c7"/></dir><dir name="System"><dir name="Config"><dir name="Backend"><dir name="Prefix"><file name="Abstract.php" hash="18fbf03dc6505be1cfb260cde745b953"/><file name="Creditmemo.php" hash="adc1566bb71632f033ef90fcd2c7fc81"/><file name="Invoice.php" hash="369df8e80686fc436864bba9ec1f96bd"/></dir></dir></dir></dir><file name="Vat.php" hash="6f8024e5bfc76ccd1c827d81bda48d25"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Emag"><file name="CategoryController.php" hash="e42dd195c112b1d2230ff805abed16f3"/><file name="LocalityController.php" hash="c30f8a9e5e1aed443f81fc1a232579f7"/><file name="ProductController.php" hash="4b2e8dcdcc2d41b9d7256e339defbb39"/><file name="VatController.php" hash="16f558732b4fa7a2bb08b7583816b017"/><file name="VoucherController.php" hash="19bf0a8a753c171447b8bf98069ad26f"/></dir><dir name="Sales"><dir name="Invoice"><file name="UploadController.php" hash="888399443eb8b0f28c91e698b34d9f0e"/></dir><file name="OrderController.php" hash="b502d7b8b7a2fa59c1c9ac32cbfe41fb"/></dir></dir><file name="InvoiceController.php" hash="8df75fd59d862afaaa7675d7831b9202"/></dir><dir name="data"><dir name="innobyte_emag_marketplace_setup"><file name="data-install-1.0.0.php" hash="e5d5342a60398c63955fe537b63699e3"/></dir></dir><dir name="docs"><file name="eMAG Markeplace API documentation v3.6.docx" hash="e5cf25307fc1111c12d2e10825aff517"/></dir><dir name="etc"><file name="adminhtml.xml" hash="aea476a16999dabe7c929151a86493a7"/><file name="config.xml" hash="250007f364c25bb95809e3c2eb10d432"/><file name="jstranslator.xml" hash="2bad6817b7f348bcba8048d2c44004f3"/><file name="system.xml" hash="0776627962229b463003f7d4fa9325af"/></dir><dir name="sql"><dir name="innobyte_emag_marketplace_setup"><file name="install-1.0.0.php" hash="ea105ca65a3328b3e7228a630583b7ce"/></dir></dir></dir><file name="Exception.php" hash="8dd468af95b0bc4dedb6563e962f06e4"/></dir><dir name="Core"><dir><dir name="Block"><file name="Shop.php" hash="9fb4bf22cb95f3de1c62fdcf699d06b5"/><dir name="System"><dir name="Config"><file name="Button.php" hash="cb37bfd01290995adbe71e12afaf0871"/><dir name="Form"><dir name="Fieldset"><file name="Extensions.php" hash="5d026a00ef966334874c14aa66bacc29"/><file name="Shop.php" hash="3f888c968145b6969a252e4d54605bce"/></dir><dir name="Renderer"><file name="Field.php" hash="933192bb4da4eb0ba4b69deceec3c4a8"/><file name="Website.php" hash="779612dbd02ccd216ecc295fb6f00485"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Config.php" hash="9cf989d6077f4f6d896c7969fb70e4f3"/><file name="Data.php" hash="8e46d8fddeab5556b075d9dd24902233"/><file name="Versions.php" hash="3e7125101f4c191d53f01deb2a1dfe16"/></dir><dir name="Model"><file name="Data.php" hash="f82288d94a83518737e28a1f2addb2ec"/><file name="Debug.php" hash="92223602c9d3d907bc13b57294f6d390"/><file name="Feed.php" hash="ce1f5b9c91a5e248c2baefdbfbdb89d0"/><dir name="Source"><dir name="Config"><file name="Enabledisable.php" hash="b9a4230779dd6f1f89d87c9a9dc2417f"/></dir><dir name="Feed"><file name="Type.php" hash="1fd10cc387061e08661faa540d5bb64e"/></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="IndexController.php" hash="f9647f277d74e473970fa67e6e1465f3"/></dir></dir><dir name="etc"><file name="config.xml" hash="6b6bcccfd131be35210c716ae75e747e"/><file name="system.xml" hash="2d15facb3d7ada2e74940eb90fe41afd"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Innobyte_EmagMarketplace.xml" hash="da8e2a8d64721eb5d9f512fe72fa1dde"/><file name="Innobyte_Core.xml" hash="0f11fbe094b94c3fd2233e8e96aa972d"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><dir name="innobyte"><file name="emag_marketplace.xml" hash="1233947fb7451a46a922d48c7a3f2ffd"/><file name="core.xml" hash="93f1070ea6bdbf4d84e7892a5ac0f400"/></dir></dir><dir name="template"><dir name="innobyte"><dir name="emag_marketplace"><dir><dir name="catalog"><dir name="product"><dir name="edit"><dir name="tab"><file name="emag_marketplace_form_after.phtml" hash="d5c2f3121179ff57ec656b3f118b9767"/></dir></dir><file name="edit.phtml" hash="eecad18f7709d130032067d24739c7ee"/></dir></dir><dir name="sales"><dir name="order"><dir name="create"><dir name="form"><file name="address.phtml" hash="a9b386c72699305a98393b5cd0d74943"/></dir><dir name="items"><file name="grid.phtml" hash="d38172cd6a2336ea908a811e4add9eee"/></dir><dir name="shipping"><dir name="method"><file name="form.phtml" hash="83231a4b5f764ce9ba0a025e923133a8"/></dir></dir><dir name="totals"><file name="voucher.phtml" hash="cad64614d2d39235749d609acfaa0d7e"/></dir></dir><dir name="emag_edit"><file name="city-autocomplete.phtml" hash="d65cdd8eb3da972acd5d1034d9d6fb5c"/></dir><dir name="shipment"><dir name="packaging"><file name="popup.phtml" hash="23745250ff3dd4097c2db02724da86a5"/></dir></dir><file name="totals.phtml" hash="75721998e3b54102f00e5811035c5635"/><dir name="view"><file name="comment.phtml" hash="077590b70fdca143bdacdf6417eafe59"/><dir name="invoice"><file name="popup.phtml" hash="3e66f62b99db17b25508cb2ea5d98d75"/></dir><dir name="tab"><file name="info.phtml" hash="cb3cb174b4cc53b2f027133fac258603"/></dir></dir></dir></dir></dir></dir><dir name="core"><file name="button.phtml" hash="69d0764414ca2f5479fa33cb959938ff"/><dir><dir name="debugger_email"><file name="cron.phtml" hash="579efa83212bc5c40040661bfa5f6f85"/><file name="disabled_extensions.phtml" hash="c3ad7a6601ec3e0728f7e8f0b6f954a7"/><file name="general.phtml" hash="55f57190f950090953dced36f29327bc"/><file name="inno_config_data.phtml" hash="404e799ac17b746af9b839cf5355cd2e"/><file name="inno_extensions.phtml" hash="f3f2cdc4de54d9fd0bbc16662b8b9130"/><file name="rewrites.phtml" hash="4d5ef250221d78738b517805376593be"/></dir></dir><file name="shop.phtml" hash="c01bda6de32abd29133e21314464a378"/></dir></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><file name="Innobyte_EmagMarketplace.csv" hash="b15bc3e97c579458e1f07858f6136cb1"/><dir name="template"><dir name="email"><dir name="innobyte"><dir name="emag_marketplace"><file name="errors.html" hash="3ee9c66da915736970df64fd9997b134"/></dir><dir name="core"><file name="debug.html" hash="d676f5c3000f50f8ff1253be2a550ff1"/></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="css"><dir name="innobyte"><dir name="emag_marketplace"><file name="style.css" hash="5848cd48fb6ad98ab5ce7017b2893187"/></dir></dir></dir><dir name="images"><dir name="innobyte"><dir name="emag_marketplace"><file name="pdf_icon.png" hash="28cdd201144351e73035a9a0e87873c0"/><file name="trash.png" hash="50967defe5ec53849432c8aa9088a0f4"/></dir><dir name="core"><file name="error_msg_icon.gif" hash="e4f28607f075a105e53fa3113d84bd26"/><file name="icon-enabled.png" hash="5fa7c06b312cbea3675e844686e434af"/><file name="note_msg_icon.gif" hash="e774ee481a2820789c1a77112377c4e0"/></dir></dir></dir><dir name="js"><dir name="innobyte"><dir name="emag_marketplace"><file name="category.js" hash="93e14d1fd6ead1dc89bd61cde22cb3be"/><file name="locality.js" hash="fd0d491529f49caeca258805dd6da7e0"/><file name="packaging.js" hash="bb58bc75a189f619cb85d26aa1865455"/><file name="product.js" hash="6475229cd509c55c63f676297f4579d3"/><dir><dir name="protolicius"><file name="README.rdoc" hash="94cf4a315a18d6a7e2b4a16081001549"/><file name="event.simulate.js" hash="ff2cb029b4f6579bbf7caec22d4d07ee"/></dir></dir><file name="vat.js" hash="93d3ff86c70a2e4297bcd1e7fbd62cf0"/></dir></dir></dir></dir></dir></dir></target><target name="mage"><dir name="js"><dir name="innobyte"><dir name="core"><file name="init.js" hash="48517ed746f15553e7adc8f86983f51f"/></dir></dir></dir><dir name="."><file name="README.md" hash="262f01bfe097f19bb394bae830c451d3"/></dir></target></contents>
17
+ <compatible/>
18
+ <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
19
+ </package>
skin/adminhtml/default/default/css/innobyte/emag_marketplace/style.css ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .original-item {
2
+ border-bottom: dotted 1px #CCCCCC;
3
+ text-align: center;
4
+ margin: 0 0 5px 0;
5
+ }
6
+ .original-item .price, .original-item .quantity {
7
+ color: red;
8
+ font-weight: bold;
9
+ }
10
+ .emag-voucher-remove {
11
+ cursor: pointer;
12
+ width: 11px;
13
+ }
14
+ .innoemag-addremove-item {
15
+ border: 1px solid #000;
16
+ padding: 0px 5px 0px 5px;
17
+ float: right;
18
+ cursor: pointer;
19
+ width: 6px;
20
+ }
21
+ #emag-shipping-rate {
22
+ width: 70px;
23
+ }
24
+ div.emag-city-autocomplete {
25
+ background-color: white;
26
+ border-style: solid;
27
+ border-width: 1px;
28
+ border-color: #aaa #c8c8c8 #c8c8c8 #aaa;
29
+ margin: 0;
30
+ padding: 0;
31
+ position: absolute;
32
+ width: 250px;
33
+ z-index: 10000;
34
+ }
35
+ .emag-city-autocomplete-indicator {
36
+ position: absolute;
37
+ }
skin/adminhtml/default/default/images/innobyte/core/error_msg_icon.gif ADDED
Binary file
skin/adminhtml/default/default/images/innobyte/core/icon-enabled.png ADDED
Binary file
skin/adminhtml/default/default/images/innobyte/core/note_msg_icon.gif ADDED
Binary file
skin/adminhtml/default/default/images/innobyte/emag_marketplace/pdf_icon.png ADDED
Binary file
skin/adminhtml/default/default/images/innobyte/emag_marketplace/trash.png ADDED
Binary file
skin/adminhtml/default/default/js/innobyte/emag_marketplace/category.js ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Js script for eMAG categories.
3
+ *
4
+ * @category Innobyte
5
+ * @package Innobyte_EmagMarketplace
6
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
7
+ */
8
+ "use strict";
9
+
10
+ var inno = inno || {};
11
+ inno.emagMarketplace = inno.emagMarketplace || {};
12
+
13
+ /**
14
+ * Show message on top of the page.
15
+ *
16
+ * @param {string} strMessage The message to show
17
+ * @param {string} strType The type of the message (success|error|notice...)
18
+ */
19
+ inno.emagMarketplace.showMsg = function(strMessage, strType) {
20
+ if ($('messages')) {
21
+ var strHtml = '<ul class="messages">\n\
22
+ <li class="' + strType + '-msg">\n\
23
+ <ul>\n\
24
+ <li>' + strMessage + '</li>\n\
25
+ </ul>\n\
26
+ </li>\n\
27
+ </ul>';
28
+ $('messages').update(strHtml);
29
+ }
30
+ };
31
+
32
+ /**
33
+ * Synchronize categories.
34
+ *
35
+ * @param {string} strUrl URL to syncronize categories.
36
+ */
37
+ inno.emagMarketplace.syncCategories = function(strUrl) {
38
+ new Ajax.Request(
39
+ strUrl,
40
+ {
41
+ method: 'post',
42
+ onSuccess: function (transport) {
43
+ var response;
44
+ if (transport && transport.responseText
45
+ && transport.responseText.isJSON()) {
46
+ response = transport.responseText.evalJSON();
47
+ }
48
+ if (response) {
49
+ if ('success' === response.status) {
50
+ inno.emagMarketplace.showMsg(
51
+ response.message,
52
+ response.status
53
+ );
54
+ location.reload();
55
+ } else {
56
+ inno.emagMarketplace.showMsg(
57
+ response.message,
58
+ response.status
59
+ );
60
+ }
61
+ }
62
+ },
63
+ onFailure: function() {
64
+ if ("undefined" !== typeof(Translator)) {
65
+ alert(Translator.translate('An error occurred. Please try again later.'));
66
+ } else {
67
+ alert('An error occurred. Please try again later.');
68
+ }
69
+ }
70
+ }
71
+ );
72
+ };
skin/adminhtml/default/default/js/innobyte/emag_marketplace/locality.js ADDED
@@ -0,0 +1,262 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Js script for eMAG localities.
3
+ *
4
+ * @category Innobyte
5
+ * @package Innobyte_EmagMarketplace
6
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
7
+ */
8
+ "use strict";
9
+
10
+ var inno = inno || {};
11
+ inno.emagMarketplace = inno.emagMarketplace || {};
12
+
13
+ /**
14
+ * Show message on top of the page.
15
+ *
16
+ * @param {string} strMessage The message to show
17
+ * @param {string} strType The type of the message (success|error|notice...)
18
+ */
19
+ inno.emagMarketplace.showMsg = function(strMessage, strType) {
20
+ if ($('messages')) {
21
+ var strHtml = '<ul class="messages">\n\
22
+ <li class="' + strType + '-msg">\n\
23
+ <ul>\n\
24
+ <li>' + strMessage + '</li>\n\
25
+ </ul>\n\
26
+ </li>\n\
27
+ </ul>';
28
+ $('messages').update(strHtml);
29
+ }
30
+ };
31
+
32
+ /**
33
+ * Synchronize localities.
34
+ *
35
+ * @param {string} strUrl URL to syncronize localities.
36
+ */
37
+ inno.emagMarketplace.syncLocalities = function(strUrl) {
38
+ new Ajax.Request(
39
+ strUrl,
40
+ {
41
+ method: 'post',
42
+ onSuccess: function (transport) {
43
+ var response;
44
+ if (transport && transport.responseText
45
+ && transport.responseText.isJSON()) {
46
+ response = transport.responseText.evalJSON();
47
+ }
48
+ if (response) {
49
+ if ('success' === response.status) {
50
+ inno.emagMarketplace.showMsg(
51
+ response.message,
52
+ response.status
53
+ );
54
+ location.reload();
55
+ } else {
56
+ inno.emagMarketplace.showMsg(
57
+ response.message,
58
+ response.status
59
+ );
60
+ }
61
+ }
62
+ },
63
+ onFailure: function() {
64
+ if ("undefined" !== typeof(Translator)) {
65
+ alert(Translator.translate('An error occurred. Please try again later.'));
66
+ } else {
67
+ alert('An error occurred. Please try again later.');
68
+ }
69
+ }
70
+ }
71
+ );
72
+ };
73
+
74
+ /**
75
+ * Callback for Ajax.Autocompleter
76
+ *
77
+ * @param {string} text The text of the li.
78
+ * @param {object} li The li from autocomplete response.
79
+ * @returns {Boolean} TRUE if all code was successfully executed, FALSE otherwise
80
+ */
81
+ inno.emagMarketplace.updateAddressLocality = function(text, li) {
82
+ // get emag locality id
83
+ var intCityEmagId = parseInt(li.getAttribute('data-emag-id'));
84
+ if (isNaN(intCityEmagId) || intCityEmagId < 1) {
85
+ return false;
86
+ }
87
+
88
+ var strAddressTypePrefix = '';
89
+ var strAddressTypeSuffix = '';
90
+ // compute suffixes and prefixes by determining if we are on order page
91
+ // or in system config shipping origin page
92
+ if ('undefined' !== typeof(order)) {
93
+ strAddressTypePrefix = 'order-';
94
+ strAddressTypeSuffix = '_address';
95
+ }
96
+ // get address type from <ul> tag
97
+ var objUlElem = li.up();
98
+ var strAddressType = objUlElem.getAttribute('data-address-type');
99
+ if ('billing' !== strAddressType && 'shipping' !== strAddressType
100
+ && 'shipping_origin' !== strAddressType) {
101
+ return false;
102
+ }
103
+ var strHighlightColor = '#c8c8c8';
104
+
105
+ // check and set region if exists
106
+ var strCounty = li.getAttribute('data-county');
107
+ if (strCounty.length > 0) {
108
+ var strRegionElemId = strAddressTypePrefix + strAddressType
109
+ + strAddressTypeSuffix + '_region';
110
+ var objRegionElem = $(strRegionElemId);
111
+ if (objRegionElem) {
112
+ objRegionElem.value = strCounty;
113
+ new Effect.Highlight(
114
+ objRegionElem,
115
+ { startcolor: strHighlightColor, duration: 3 }
116
+ );
117
+ if ('billing' === strAddressType && order.shippingAsBilling) {
118
+ inno.emagMarketplace.copyDataFromBillingToShipping(strRegionElemId);
119
+ }
120
+ }
121
+ }
122
+
123
+ // check and set region id select if region id info is available
124
+ var intCountyId = parseInt(li.getAttribute('data-county-id'));
125
+ if (!isNaN(intCountyId) && intCountyId > 0) {
126
+ var strRegionIdElemId = strAddressTypePrefix + strAddressType
127
+ + strAddressTypeSuffix + '_region_id';
128
+ var objRegionIdElem = $(strRegionIdElemId);
129
+ if (objRegionIdElem && objRegionIdElem.visible()) {
130
+ objRegionIdElem.value = intCountyId;
131
+ // make the option selected
132
+ $$('select#' + strRegionIdElemId + ' option').each(function(o) {
133
+ if (o.readAttribute('value') == intCountyId) {
134
+ o.selected = true;
135
+ throw $break;
136
+ }
137
+ });
138
+ new Effect.Highlight(
139
+ objRegionIdElem,
140
+ { startcolor: strHighlightColor, duration: 3 }
141
+ );
142
+ if ('billing' === strAddressType && order.shippingAsBilling) {
143
+ inno.emagMarketplace.copyDataFromBillingToShipping(strRegionIdElemId);
144
+ }
145
+ }
146
+ }
147
+
148
+ // set emag locality id
149
+ var strEmagLocalityIdElemId = strAddressTypePrefix + strAddressType
150
+ + strAddressTypeSuffix + '_emag_locality_id';
151
+ var objEmagLocalityIdElem = $(strEmagLocalityIdElemId);
152
+ if (objEmagLocalityIdElem) {
153
+ objEmagLocalityIdElem.value = intCityEmagId;
154
+ if ('billing' === strAddressType && order.shippingAsBilling) {
155
+ inno.emagMarketplace.copyDataFromBillingToShipping(strEmagLocalityIdElemId);
156
+ }
157
+ }
158
+
159
+ var objCityElem = $(strAddressTypePrefix + strAddressType + strAddressTypeSuffix + '_city');
160
+ if (objCityElem) {
161
+ // called only once "change", for city, so loadBlock call will be called
162
+ // only here, and made "if ('billing' === strAddressType &&
163
+ // order.shippingAsBilling)" checks for the other fields instead of
164
+ // calling "change" for them too.
165
+ if ('undefined' !== typeof(order)) {
166
+ objCityElem.simulate('change'); // this will trigger loadBlock call
167
+ }
168
+ new Effect.Highlight(
169
+ objCityElem,
170
+ { startcolor: strHighlightColor, duration: 3 }
171
+ );
172
+ }
173
+ return true;
174
+ };
175
+
176
+ /**
177
+ * Copy data from billing to shipping address.
178
+ * This function is present in original OrderAdmin - sales.js Magento >= 1.8,
179
+ * but not in 1.7.
180
+ *
181
+ * @param string strFieldId Billing field id to copy data from.
182
+ */
183
+ inno.emagMarketplace.copyDataFromBillingToShipping = function(strFieldId) {
184
+ var shippingId = $(strFieldId).identify().replace('-billing_', '-shipping_');
185
+ var inputField = $(shippingId);
186
+ if (inputField) {
187
+ inputField.setValue($(strFieldId).getValue());
188
+ if (inputField.changeUpdater) {
189
+ inputField.changeUpdater();
190
+ }
191
+ $(order.shippingAddressContainer).select('select').each(function(el){
192
+ el.disable();
193
+ });
194
+ }
195
+ };
196
+
197
+ /**
198
+ * Attach autocomplete city to an address.
199
+ *
200
+ * @param {string} strLoadCitiesUrl Ajax url to get cities.
201
+ * @param {string} strAddressType Address type(billing|shipping|shipping_origin)
202
+ * @param {string} strLoaderImgUrl Autocomplete loading image; optional.
203
+ * @returns {Boolean} TRUE if all code was successfully executed, FALSE otherwise
204
+ */
205
+ inno.emagMarketplace.attachAutocompleteEmagCity = function(strLoadCitiesUrl, strAddressType, strLoaderImgUrl) {
206
+ var strAddressTypePrefix = '';
207
+ var strAddressTypeSuffix = '';
208
+ // compute suffixes and prefixes by determining if we are on order page
209
+ // or in system config shipping origin page
210
+ if ('undefined' !== typeof(order)) {
211
+ strAddressTypePrefix = 'order-';
212
+ strAddressTypeSuffix = '_address';
213
+ }
214
+ // check that city elements exist
215
+ var strCityElemId = strAddressTypePrefix + strAddressType + strAddressTypeSuffix + '_city';
216
+ var objCityElem = $(strCityElemId);
217
+ var strEmagLocalityIdElemId = strAddressTypePrefix + strAddressType + strAddressTypeSuffix + '_emag_locality_id';
218
+ var objEmagCityElem = $(strEmagLocalityIdElemId);
219
+ if (!objCityElem || !objEmagCityElem) {
220
+ return false;
221
+ }
222
+
223
+ // insert autocomplete indicator and results container
224
+ if (strLoaderImgUrl) {
225
+ objCityElem.insert({
226
+ before: '<span id="emag-city-autocomplete-indicator-' + strAddressType + '" class="emag-city-autocomplete-indicator" style="display: none">'
227
+ + '<img src="' + strLoaderImgUrl +'" alt="' + Translator.translate('Loading...') + '" class="v-middle"/>'
228
+ + '</span>'
229
+ });
230
+ }
231
+ objCityElem.insert({
232
+ after: '<div id="emag-city-autocomplete-' + strAddressType + '" class="emag-city-autocomplete"></div>'
233
+ });
234
+
235
+ // configure scriptaculos autocompleter
236
+ var additionalParams = 'address_type=' + encodeURIComponent(strAddressType);
237
+ if ('undefined' !== typeof(order)) {
238
+ additionalParams += '&store_id=' + parseInt(order.storeId);
239
+ }
240
+ new Ajax.Autocompleter(
241
+ strCityElemId,
242
+ 'emag-city-autocomplete-' + strAddressType,
243
+ strLoadCitiesUrl,
244
+ {
245
+ paramName: strCityElemId,
246
+ parameters: additionalParams,
247
+ minChars: 2,
248
+ indicator: (strLoaderImgUrl ? 'emag-city-autocomplete-indicator-' + strAddressType : false),
249
+ select: 'emag-city-name-' + strAddressType,
250
+ afterUpdateElement: inno.emagMarketplace.updateAddressLocality,
251
+ callback: function(field, query) {
252
+ query += '&city=' + encodeURIComponent(field.value); // resend city param with unique name
253
+ var strCountryIdElemId = strAddressTypePrefix + strAddressType + strAddressTypeSuffix + '_country_id';
254
+ if ($(strCountryIdElemId)) {
255
+ query += '&country=' + encodeURIComponent($(strCountryIdElemId).value);
256
+ }
257
+ objEmagCityElem.value = ''; // reset locality id
258
+ return query;
259
+ }
260
+ }
261
+ );
262
+ };
skin/adminhtml/default/default/js/innobyte/emag_marketplace/packaging.js ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Extend Packaging class from Magento.
3
+ *
4
+ * @category Innobyte
5
+ * @package Innobyte_EmagMarketplace
6
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
7
+ */
8
+ "use strict";
9
+
10
+ var inno = inno || {};
11
+ inno.emagMarketplace = inno.emagMarketplace || {};
12
+
13
+ /**
14
+ * Extend "Packaging" class.
15
+ */
16
+ inno.emagMarketplace.packaging = Class.create(Packaging, {
17
+ /**
18
+ * @Override
19
+ */
20
+ sendCreateLabelRequest: function($super) {
21
+ // begin Innobyte customization - add extra inno emag params
22
+ if (!$('emag-marketplace-shipping-extra')) {
23
+ $super();
24
+ return;
25
+ }
26
+ $('emag-marketplace-shipping-extra').select('input,select').each(
27
+ function(item, idx) {
28
+ this.paramsCreateLabelRequest[item.name] = item.value;
29
+ },
30
+ this
31
+ );
32
+ // end Innobyte customization - add extra inno emag params
33
+ $super();
34
+ },
35
+
36
+ /**
37
+ * @Override
38
+ */
39
+ validate: function($super) {
40
+ var blnResult = $super();
41
+ // begin Innobyte customization - validate extra inno emag inputs
42
+ if (!$('emag-marketplace-shipping-extra')) {
43
+ return blnResult;
44
+ }
45
+ var blnInnoFieldsResult = $('emag-marketplace-shipping-extra')
46
+ .select('input,select')
47
+ .collect(
48
+ function (element) {
49
+ return this.validateElement(element);
50
+ },
51
+ this
52
+ );
53
+ blnResult = blnResult && blnInnoFieldsResult;
54
+ // end Innobyte customization - validate extra inno emag inputs
55
+ return blnResult;
56
+ }
57
+ });
skin/adminhtml/default/default/js/innobyte/emag_marketplace/product.js ADDED
@@ -0,0 +1,264 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Js script for eMAG products.
3
+ *
4
+ * @category Innobyte
5
+ * @package Innobyte_EmagMarketplace
6
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
7
+ */
8
+ "use strict";
9
+
10
+ var inno = inno || {};
11
+ inno.emagMarketplace = inno.emagMarketplace || {};
12
+
13
+ /**
14
+ * Triggered on "onchange" for commission type select.
15
+ * Adds / removes percents validation class for commission valuedepending on
16
+ * commission type.
17
+ */
18
+ inno.emagMarketplace.changeCommissionType = function() {
19
+ var intCommissionType = parseInt($('innoemag_commission_type').value);
20
+ if (1 === intCommissionType) {
21
+ $('innoemag_commission_value').addClassName('validate-percents');
22
+ } else {
23
+ $('innoemag_commission_value').removeClassName('validate-percents');
24
+ }
25
+ };
26
+
27
+ /**
28
+ * Add new barcode input.
29
+ *
30
+ * @returns {Boolean} TRUE if all code was successfully executed, FALSE otherwise
31
+ */
32
+ inno.emagMarketplace.addNewBarcode = function() {
33
+ if (!$('innoemag_barcodes') || !$('note_barcodes')) {
34
+ return false;
35
+ }
36
+ $('note_barcodes').insert({
37
+ before: '<input type="text" class="input-text validate-length minimum-length-1 maximum-length-20 f-left" name="product[inno_emag_mktp][barcodes][]" value="" maxlength="20" />'
38
+ + '<span class="innoemag-addremove-item" '
39
+ + ("undefined" !== typeof(Translator) ? ('title="' + Translator.translate('Remove') + '"') : 'Remove')
40
+ + '" onclick="inno.emagMarketplace.removeBarcode(this)"> - </span>'
41
+ + '<br style="clear: both;"/>'
42
+ });
43
+ return true;
44
+ };
45
+
46
+ /**
47
+ * Remove a barcode input.
48
+ */
49
+ inno.emagMarketplace.removeBarcode = function(obj) {
50
+ if ($(obj).previous('input')) {
51
+ $(obj).previous('input').remove();
52
+ }
53
+ if ($(obj).next('br')) {
54
+ $(obj).next('br').remove();
55
+ }
56
+ $(obj).remove();
57
+ };
58
+
59
+ /**
60
+ * Triggered on "onchange" for category select.
61
+ *
62
+ * @returns {Boolean} TRUE if all code was successfully executed, FALSE otherwise
63
+ */
64
+ inno.emagMarketplace.changeCategory = function(strUrl, blnRetrieveFamilyTypes) {
65
+ // remove old characteristics
66
+ $$('[id^="innoemag_category_characteristic"]').each(function(item) {
67
+ item.up('tr').remove();
68
+ });
69
+ // remove family type
70
+ if ($('innoemag_family_type_id')) {
71
+ $('innoemag_family_type_id').up('tr').remove();
72
+ }
73
+ // check if we have a category id
74
+ if (!$('innoemag_category_id')) {
75
+ return false;
76
+ }
77
+ var intCatId = parseInt($('innoemag_category_id').value);
78
+ if (isNaN(intCatId) || intCatId < 1) {
79
+ return false;
80
+ }
81
+ new Ajax.Request(
82
+ strUrl,
83
+ {
84
+ method: 'get',
85
+ parameters: $H({category_id: intCatId, get_family_types: blnRetrieveFamilyTypes}),
86
+ onSuccess: function (transport) {
87
+ var response;
88
+ if (transport && transport.responseText && transport.responseText.isJSON()) {
89
+ response = transport.responseText.evalJSON();
90
+ }
91
+ if (response) {
92
+ if ('success' === response.status) {
93
+ var strInputs = '';
94
+ // show the new characteristics
95
+ var characteristics = response.results.characteristics;
96
+ var strKey;
97
+ for (var i in characteristics) {
98
+ if (characteristics.hasOwnProperty(i)) {
99
+ strKey = 'category_characteristic' + parseInt(i);
100
+ strInputs += '<tr>\n'
101
+ + '<td class="label"><label for=innoemag_"' + strKey + '">' + characteristics[i] + '<span class="required">*</span></label></td>\n'
102
+ + '<td class="value">\n'
103
+ + ' <input type="text" class="input-text required-entry validate-length maximum-length-255" id="innoemag_' + strKey + '" name="product[inno_emag_mktp][' + strKey + ']" value="" maxlength="255" />\n'
104
+ + '</td>\n'
105
+ + '</tr>\n';
106
+ }
107
+ }
108
+ $('innoemag_category_id').up('tr').insert({after: strInputs});
109
+ // show family type
110
+ if (blnRetrieveFamilyTypes && response.results.family_types) {
111
+ var familyTypes = response.results.family_types.items;
112
+ var ftOptions = '';
113
+ for (var i in familyTypes) {
114
+ if (familyTypes.hasOwnProperty(i)) {
115
+ ftOptions += '<option value="' + i + '">' + familyTypes[i] + '</option>\n';
116
+ }
117
+ }
118
+ if (ftOptions.length > 0) {
119
+ strInputs = '<tr>\n'
120
+ + '<td class="label"><label for="innoemag_family_type_id">' + ("undefined" !== typeof(Translator) ? Translator.translate('Family Type') : 'Family Type') + '<span class="required">*</span></label></td>\n'
121
+ + '<td class="value">\n'
122
+ + ' <select onchange="inno.emagMarketplace.changeFamilyType()" class="required-entry" id="innoemag_family_type_id" name="product[inno_emag_mktp][family_type_id]">'
123
+ + ' <option value=""></option>\n'
124
+ + ftOptions
125
+ + ' </select>\n'
126
+ + '</td>\n'
127
+ + '</tr>\n';
128
+ $('innoemag_category_id').up('tr').insert({after: strInputs});
129
+
130
+ inno.emagMarketplace.familyTypesCharacteristics = response.results.family_types.characteristics;
131
+ }
132
+ } else if ($('innoemag_family_type_id')) {
133
+ $('innoemag_family_type_id').up('tr').remove();
134
+ }
135
+ } else {
136
+ alert(response.message);
137
+ }
138
+ }
139
+ },
140
+ onFailure: function() {
141
+ if ("undefined" !== typeof(Translator)) {
142
+ alert(Translator.translate('An error occurred. Please try again later.'));
143
+ } else {
144
+ alert('An error occurred. Please try again later.');
145
+ }
146
+ }
147
+ }
148
+ );
149
+ return true;
150
+ };
151
+
152
+ /**
153
+ * Send new product / offer / deactivation request.
154
+ *
155
+ * @param {string} strTabsContainerId Left tabs container id.
156
+ * @param {string} strUrl URL to sent request to.
157
+ * @param {string} strType One of the product|offer|deactivate-offer strings.
158
+ */
159
+ inno.emagMarketplace.send = function(strTabsContainerId, strUrl, strType) {
160
+ var blnFormHasChanges = false;
161
+ // check if form contains unsaved data
162
+ $$('#' + strTabsContainerId + ' li a.tab-item-link').each(function(tab) {
163
+ if (tab.hasClassName('changed')) {
164
+ blnFormHasChanges = true;
165
+ throw $break;
166
+ }
167
+ });
168
+ if (blnFormHasChanges) {
169
+ var strConfirmMsg;
170
+ if ('product' === strType) {
171
+ strConfirmMsg = ("undefined" !== typeof(Translator)
172
+ ? Translator.translate("Please confirm product sending. All data that hasn't been saved will be lost.")
173
+ : "Please confirm product sending. All data that hasn't been saved will be lost.");
174
+ } else if ('offer' === strType) {
175
+ strConfirmMsg = ("undefined" !== typeof(Translator)
176
+ ? Translator.translate("Please confirm offer sending. All data that hasn't been saved will be lost.")
177
+ : "Please confirm offer sending. All data that hasn't been saved will be lost.");
178
+ } else {
179
+ strConfirmMsg = ("undefined" !== typeof(Translator)
180
+ ? Translator.translate("Please confirm offer deactivation. All data that hasn't been saved will be lost.")
181
+ : "Please confirm offer deactivation. All data that hasn't been saved will be lost.");
182
+ }
183
+ if (confirm(strConfirmMsg)) {
184
+ setLocation(strUrl);
185
+ }
186
+ } else {
187
+ setLocation(strUrl);
188
+ }
189
+ };
190
+
191
+ /**
192
+ * Triggered on "onchange" for family type select.
193
+ * Enables/disables selected family type 's characteristics.
194
+ *
195
+ * @returns {Boolean} TRUE if all code was successfully executed, FALSE otherwise
196
+ */
197
+ inno.emagMarketplace.changeFamilyType = function() {
198
+ if (!$('innoemag_family_type_id')
199
+ || !inno.emagMarketplace.familyTypesCharacteristics) {
200
+ return false;
201
+ }
202
+ $$('[id^=innoemag_category_characteristic]').each(function(item) {
203
+ if (item.hasAttribute('disabled')) {
204
+ item.removeAttribute('disabled');
205
+ item.removeClassName('disabled');
206
+ }
207
+ if (item.next('p.note')) {
208
+ item.next('p.note').remove();
209
+ }
210
+ });
211
+ var intFamTypeId = parseInt($('innoemag_family_type_id').value);
212
+ if (isNaN(intFamTypeId) || intFamTypeId < 1) {
213
+ return false;
214
+ }
215
+ var arrCharacteristics = inno.emagMarketplace.familyTypesCharacteristics[intFamTypeId];
216
+ if (!arrCharacteristics) {
217
+ return false;
218
+ }
219
+ for (var i = 0; i < arrCharacteristics.length; i++) {
220
+ var objCharInput = $('innoemag_category_characteristic' + arrCharacteristics[i]);
221
+ objCharInput.setAttribute('disabled', 'disabled');
222
+ objCharInput.addClassName('disabled');
223
+ objCharInput.value = '';
224
+ var strNote = '<p class="note">' + ("undefined" !== typeof(Translator) ?
225
+ Translator.translate('This attribute will have to be set on associated products individually') :
226
+ 'This attribute will have to be set on associated products individually') + '</p>';
227
+ objCharInput.insert({after: strNote});
228
+ }
229
+ };
230
+
231
+ /**
232
+ * Triggerd on part number key input bluring.
233
+ * Makes some fields required / not required depending if we have a part number key.
234
+ *
235
+ * @returns {Boolean} TRUE if all code was successfully executed, FALSE otherwise
236
+ */
237
+ inno.emagMarketplace.changePartNumberKey = function() {
238
+ if (!$('innoemag_part_number_key')) {
239
+ return false;
240
+ }
241
+ if ($('innoemag_part_number_key').value.length > 0) {
242
+ if ($('innoemag_name').hasClassName('required-entry')) {
243
+ $$('label[for="innoemag_name"]')[0].select('span.required')[0].remove();
244
+ $('innoemag_name').removeClassName('required-entry');
245
+
246
+ $$('label[for="innoemag_brand"]')[0].select('span.required')[0].remove();
247
+ $('innoemag_brand').removeClassName('required-entry');
248
+
249
+ $$('label[for="innoemag_category_id"]')[0].select('span.required')[0].remove();
250
+ $('innoemag_category_id').removeClassName('required-entry');
251
+ }
252
+ } else {
253
+ if (!$('innoemag_name').hasClassName('required-entry')) {
254
+ $$('label[for="innoemag_name"]')[0].insert('<span class="required">*</span>');
255
+ $('innoemag_name').addClassName('required-entry');
256
+
257
+ $$('label[for="innoemag_brand"]')[0].insert('<span class="required">*</span>');
258
+ $('innoemag_brand').addClassName('required-entry');
259
+
260
+ $$('label[for="innoemag_category_id"]')[0].insert('<span class="required">*</span>');
261
+ $('innoemag_category_id').addClassName('required-entry');
262
+ }
263
+ }
264
+ };
skin/adminhtml/default/default/js/innobyte/emag_marketplace/protolicius/README.rdoc ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ = Description
2
+
3
+ Protolicious is a set of javascript snippets based on prototype.js
4
+
5
+ = Contents
6
+
7
+ == Element (Element.Methods) extensions
8
+
9
+ * <tt>Element#setProperty</tt>
10
+ * <tt>Element#swapClassName</tt>
11
+ * <tt>Element#enableClassName</tt>
12
+ * <tt>Element#contains</tt>
13
+ * <tt>Element#indexOf</tt>
14
+ * <tt>Element#isTagName</tt>
15
+ * <tt>Element#getContentWidth</tt>
16
+ * <tt>Element#getContentHeight</tt>
17
+ * <tt>Element#setWidth</tt>
18
+ * <tt>Element#setHeight</tt>
19
+ * <tt>Element#appearVisible</tt>
20
+ * <tt>Element#delegate</tt>
21
+ * <tt>Element#fillDocument</tt>
22
+ * <tt>Element#centerInViewport</tt>
23
+
24
+ == Function extensions
25
+
26
+ * <tt>Function.K</tt>
27
+ * <tt>Function#negate</tt>
28
+ * <tt>Function#runOnce</tt>
29
+ * <tt>Function#_new</tt>
30
+ * <tt>Function#toDelayed</tt>
31
+ * <tt>Function#toDeferred</tt>
32
+ * <tt>Function#addAdvice</tt>
33
+
34
+ == Array extensions
35
+
36
+ * <tt>Array#sum</tt>
37
+ * <tt>Array#namespace</tt>
38
+
39
+ == Field (Form.Element.Methods) extensions
40
+
41
+ * <tt>Field#isBlank</tt>
42
+ * <tt>Field#present</tt>
43
+
44
+ == Form (Form.Methods) extensions
45
+
46
+ * <tt>Form#unserialize</tt>
47
+
48
+ == Event extensions
49
+
50
+ * <tt>Event.simulate</tt>
51
+ * <tt>Event.register</tt>
52
+ * <tt>Event.unregister</tt>
53
+
54
+ == Cookie
55
+
56
+ * <tt>Cookie.set</tt>
57
+ * <tt>Cookie.get</tt>
58
+ * <tt>Cookie.unset</tt>
59
+
60
+ == Prototype
61
+
62
+ * <tt>Prototype.addScript</tt>
63
+ * <tt>Prototype.addStylesheet</tt>
64
+
65
+ == Object extensions
66
+
67
+ * <tt>Object.isEvent</tt>
68
+ * <tt>Object.methodize</tt>
69
+
70
+ = License
71
+
72
+ protolicious is licensed under the terms of the MIT license
skin/adminhtml/default/default/js/innobyte/emag_marketplace/protolicius/event.simulate.js ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Event.simulate(@element, eventName[, options]) -> Element
3
+ *
4
+ * - @element: element to fire event on
5
+ * - eventName: name of event to fire (only MouseEvents and HTMLEvents interfaces are supported)
6
+ * - options: optional object to fine-tune event properties - pointerX, pointerY, ctrlKey, etc.
7
+ *
8
+ * $('foo').simulate('click'); // => fires "click" event on an element with id=foo
9
+ *
10
+ **/
11
+ (function(){
12
+
13
+ var eventMatchers = {
14
+ 'HTMLEvents': /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,
15
+ 'MouseEvents': /^(?:click|mouse(?:down|up|over|move|out))$/
16
+ }
17
+ var defaultOptions = {
18
+ pointerX: 0,
19
+ pointerY: 0,
20
+ button: 0,
21
+ ctrlKey: false,
22
+ altKey: false,
23
+ shiftKey: false,
24
+ metaKey: false,
25
+ bubbles: true,
26
+ cancelable: true
27
+ }
28
+
29
+ Event.simulate = function(element, eventName) {
30
+ var options = Object.extend(defaultOptions, arguments[2] || { });
31
+ var oEvent, eventType = null;
32
+
33
+ element = $(element);
34
+
35
+ for (var name in eventMatchers) {
36
+ if (eventMatchers[name].test(eventName)) { eventType = name; break; }
37
+ }
38
+
39
+ if (!eventType)
40
+ throw new SyntaxError('Only HTMLEvents and MouseEvents interfaces are supported');
41
+
42
+ if (document.createEvent) {
43
+ oEvent = document.createEvent(eventType);
44
+ if (eventType == 'HTMLEvents') {
45
+ oEvent.initEvent(eventName, options.bubbles, options.cancelable);
46
+ }
47
+ else {
48
+ oEvent.initMouseEvent(eventName, options.bubbles, options.cancelable, document.defaultView,
49
+ options.button, options.pointerX, options.pointerY, options.pointerX, options.pointerY,
50
+ options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, options.button, element);
51
+ }
52
+ element.dispatchEvent(oEvent);
53
+ }
54
+ else {
55
+ options.clientX = options.pointerX;
56
+ options.clientY = options.pointerY;
57
+ oEvent = Object.extend(document.createEventObject(), options);
58
+ element.fireEvent('on' + eventName, oEvent);
59
+ }
60
+ return element;
61
+ }
62
+
63
+ Element.addMethods({ simulate: Event.simulate });
64
+ })()
skin/adminhtml/default/default/js/innobyte/emag_marketplace/vat.js ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Js script for eMAG vats.
3
+ *
4
+ * @category Innobyte
5
+ * @package Innobyte_EmagMarketplace
6
+ * @author Bogdan Constantinescu <bogdan.constantinescu@innobyte.com>
7
+ */
8
+ "use strict";
9
+
10
+ var inno = inno || {};
11
+ inno.emagMarketplace = inno.emagMarketplace || {};
12
+
13
+ /**
14
+ * Show message on top of the page.
15
+ *
16
+ * @param {string} strMessage The message to show
17
+ * @param {string} strType The type of the message (success|error|notice...)
18
+ */
19
+ inno.emagMarketplace.showMsg = function(strMessage, strType) {
20
+ if ($('messages')) {
21
+ var strHtml = '<ul class="messages">\n\
22
+ <li class="' + strType + '-msg">\n\
23
+ <ul>\n\
24
+ <li>' + strMessage + '</li>\n\
25
+ </ul>\n\
26
+ </li>\n\
27
+ </ul>';
28
+ $('messages').update(strHtml);
29
+ }
30
+ };
31
+
32
+ /**
33
+ * Synchronize VATs.
34
+ *
35
+ * @param {string} strUrl URL to syncronize VATs.
36
+ */
37
+ inno.emagMarketplace.syncVats = function(strUrl) {
38
+ new Ajax.Request(
39
+ strUrl,
40
+ {
41
+ method: 'post',
42
+ onSuccess: function (transport) {
43
+ var response;
44
+ if (transport && transport.responseText
45
+ && transport.responseText.isJSON()) {
46
+ response = transport.responseText.evalJSON();
47
+ }
48
+ if (response) {
49
+ if ('success' === response.status) {
50
+ inno.emagMarketplace.showMsg(
51
+ response.message,
52
+ response.status
53
+ );
54
+ location.reload();
55
+ } else {
56
+ inno.emagMarketplace.showMsg(
57
+ response.message,
58
+ response.status
59
+ );
60
+ }
61
+ }
62
+ },
63
+ onFailure: function() {
64
+ if ("undefined" !== typeof(Translator)) {
65
+ alert(Translator.translate('An error occurred. Please try again later.'));
66
+ } else {
67
+ alert('An error occurred. Please try again later.');
68
+ }
69
+ }
70
+ }
71
+ );
72
+ };