Magento_Mobile - Version 1.4.2.0.22.1

Version Notes

1.4.2.0.22.1 version of package
internal svn revision #121425

Download this release

Release Info

Developer Magento Core Team
Extension Magento_Mobile
Version 1.4.2.0.22.1
Comparing to
See all releases


Version 1.4.2.0.22.1

Files changed (204) hide show
  1. app/code/core/Mage/XmlConnect/Block/Adminhtml/History.php +48 -0
  2. app/code/core/Mage/XmlConnect/Block/Adminhtml/History/Grid.php +116 -0
  3. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile.php +53 -0
  4. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit.php +136 -0
  5. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Form.php +55 -0
  6. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Submission.php +49 -0
  7. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Cache.php +106 -0
  8. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Content.php +146 -0
  9. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design.php +98 -0
  10. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion.php +57 -0
  11. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Images.php +157 -0
  12. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Tabs.php +79 -0
  13. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Themes.php +77 -0
  14. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Preview.php +75 -0
  15. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Themes.php +199 -0
  16. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Flurryanalytics.php +161 -0
  17. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/General.php +168 -0
  18. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Notification.php +216 -0
  19. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Payment.php +288 -0
  20. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Settings.php +120 -0
  21. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Social.php +330 -0
  22. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Submission/History.php +163 -0
  23. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tabs.php +67 -0
  24. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Addrow.php +101 -0
  25. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Color.php +47 -0
  26. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Country.php +172 -0
  27. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Datetime.php +205 -0
  28. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Font.php +105 -0
  29. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Image.php +99 -0
  30. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Page.php +107 -0
  31. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Tabs.php +65 -0
  32. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Theme.php +52 -0
  33. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid.php +123 -0
  34. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid/Renderer/Bool.php +61 -0
  35. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid/Renderer/Type.php +53 -0
  36. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Preview/Content.php +55 -0
  37. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Preview/Tabitems.php +63 -0
  38. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission.php +121 -0
  39. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Form.php +54 -0
  40. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Renderer/Country/Androidmarket.php +47 -0
  41. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Renderer/Country/Istore.php +47 -0
  42. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tab/Container.php +99 -0
  43. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tab/Container/Submission.php +389 -0
  44. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tabs.php +49 -0
  45. app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Widget/Form.php +112 -0
  46. app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue.php +48 -0
  47. app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Edit.php +88 -0
  48. app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Edit/Form.php +166 -0
  49. app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid.php +184 -0
  50. app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Action.php +74 -0
  51. app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Application.php +51 -0
  52. app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Id.php +47 -0
  53. app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Msgtitle.php +51 -0
  54. app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Pushtitle.php +47 -0
  55. app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Status.php +69 -0
  56. app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Template.php +51 -0
  57. app/code/core/Mage/XmlConnect/Block/Adminhtml/Template.php +65 -0
  58. app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Edit.php +87 -0
  59. app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Edit/Form.php +160 -0
  60. app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid.php +159 -0
  61. app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid/Renderer/Application.php +51 -0
  62. app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Preview.php +69 -0
  63. app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Preview/Form.php +69 -0
  64. app/code/core/Mage/XmlConnect/Block/Cart.php +245 -0
  65. app/code/core/Mage/XmlConnect/Block/Cart/Crosssell.php +100 -0
  66. app/code/core/Mage/XmlConnect/Block/Cart/Info.php +75 -0
  67. app/code/core/Mage/XmlConnect/Block/Cart/Item/Renderer.php +261 -0
  68. app/code/core/Mage/XmlConnect/Block/Cart/Item/Renderer/Configurable.php +86 -0
  69. app/code/core/Mage/XmlConnect/Block/Cart/Item/Renderer/Grouped.php +51 -0
  70. app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mecl/Details.php +91 -0
  71. app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mecl/Review.php +128 -0
  72. app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mecl/Shippingmethods.php +118 -0
  73. app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mep/Totals.php +86 -0
  74. app/code/core/Mage/XmlConnect/Block/Cart/Totals.php +165 -0
  75. app/code/core/Mage/XmlConnect/Block/Catalog.php +75 -0
  76. app/code/core/Mage/XmlConnect/Block/Catalog/Category.php +122 -0
  77. app/code/core/Mage/XmlConnect/Block/Catalog/Category/Info.php +76 -0
  78. app/code/core/Mage/XmlConnect/Block/Catalog/Filters.php +68 -0
  79. app/code/core/Mage/XmlConnect/Block/Catalog/Product.php +165 -0
  80. app/code/core/Mage/XmlConnect/Block/Catalog/Product/Attributes.php +64 -0
  81. app/code/core/Mage/XmlConnect/Block/Catalog/Product/Gallery.php +89 -0
  82. app/code/core/Mage/XmlConnect/Block/Catalog/Product/List.php +202 -0
  83. app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options.php +227 -0
  84. app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Bundle.php +123 -0
  85. app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Configurable.php +236 -0
  86. app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Giftcard.php +316 -0
  87. app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Grouped.php +102 -0
  88. app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Simple.php +49 -0
  89. app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Virtual.php +49 -0
  90. app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price.php +98 -0
  91. app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Bundle.php +425 -0
  92. app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Default.php +828 -0
  93. app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Giftcard.php +96 -0
  94. app/code/core/Mage/XmlConnect/Block/Catalog/Product/Related.php +132 -0
  95. app/code/core/Mage/XmlConnect/Block/Catalog/Product/Review.php +90 -0
  96. app/code/core/Mage/XmlConnect/Block/Catalog/Product/Review/List.php +115 -0
  97. app/code/core/Mage/XmlConnect/Block/Catalog/Search.php +144 -0
  98. app/code/core/Mage/XmlConnect/Block/Catalog/Search/Suggest.php +69 -0
  99. app/code/core/Mage/XmlConnect/Block/Checkout/Address/Billing.php +62 -0
  100. app/code/core/Mage/XmlConnect/Block/Checkout/Address/Form.php +234 -0
  101. app/code/core/Mage/XmlConnect/Block/Checkout/Address/Shipping.php +62 -0
  102. app/code/core/Mage/XmlConnect/Block/Checkout/Agreements.php +63 -0
  103. app/code/core/Mage/XmlConnect/Block/Checkout/Order/Review.php +74 -0
  104. app/code/core/Mage/XmlConnect/Block/Checkout/Order/Review/Info.php +191 -0
  105. app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Authorizenet.php +128 -0
  106. app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Ccsave.php +142 -0
  107. app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Checkmo.php +73 -0
  108. app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Authorizenet.php +37 -0
  109. app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Ccsave.php +62 -0
  110. app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Checkmo.php +71 -0
  111. app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Free.php +50 -0
  112. app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Paypal/Abstract.php +63 -0
  113. app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Paypal/Express.php +37 -0
  114. app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Paypal/Mecl.php +37 -0
  115. app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Pbridge/Authorizenet.php +37 -0
  116. app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Pbridge/Paypal/Direct.php +37 -0
  117. app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Pbridge/Paypaluk/Direct.php +37 -0
  118. app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Pbridge/Verisign.php +63 -0
  119. app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Purchaseorder.php +59 -0
  120. app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/List.php +366 -0
  121. app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Paypal/Direct.php +62 -0
  122. app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Paypal/Payflow.php +160 -0
  123. app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Abstract.php +90 -0
  124. app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Authorizenet.php +43 -0
  125. app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Paypal.php +43 -0
  126. app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Paypaluk.php +43 -0
  127. app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Verisign.php +43 -0
  128. app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Purchaseorder.php +91 -0
  129. app/code/core/Mage/XmlConnect/Block/Checkout/Pbridge/Result.php +50 -0
  130. app/code/core/Mage/XmlConnect/Block/Checkout/Shipping/Method/Available.php +81 -0
  131. app/code/core/Mage/XmlConnect/Block/Checkout/Shipping/Method/Avaliable.php +39 -0
  132. app/code/core/Mage/XmlConnect/Block/Cms/Page.php +45 -0
  133. app/code/core/Mage/XmlConnect/Block/Configuration.php +125 -0
  134. app/code/core/Mage/XmlConnect/Block/Customer/Address/Form.php +466 -0
  135. app/code/core/Mage/XmlConnect/Block/Customer/Address/List.php +128 -0
  136. app/code/core/Mage/XmlConnect/Block/Customer/Form.php +96 -0
  137. app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Boolean.php +59 -0
  138. app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Date.php +110 -0
  139. app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/File.php +119 -0
  140. app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Image.php +88 -0
  141. app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Multiline.php +99 -0
  142. app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Multiselect.php +66 -0
  143. app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Select.php +66 -0
  144. app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Text.php +99 -0
  145. app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Textarea.php +43 -0
  146. app/code/core/Mage/XmlConnect/Block/Customer/GiftcardCheck.php +79 -0
  147. app/code/core/Mage/XmlConnect/Block/Customer/Order/Details.php +199 -0
  148. app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Bundle.php +226 -0
  149. app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Default.php +133 -0
  150. app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Downloadable.php +148 -0
  151. app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Giftcard.php +79 -0
  152. app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Grouped.php +62 -0
  153. app/code/core/Mage/XmlConnect/Block/Customer/Order/Items.php +94 -0
  154. app/code/core/Mage/XmlConnect/Block/Customer/Order/List.php +76 -0
  155. app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals.php +147 -0
  156. app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals/Customerbalance.php +66 -0
  157. app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals/Customerbalance/Refunded.php +66 -0
  158. app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals/Giftcards.php +78 -0
  159. app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals/Tax.php +93 -0
  160. app/code/core/Mage/XmlConnect/Block/Customer/Storecredit.php +121 -0
  161. app/code/core/Mage/XmlConnect/Block/Home.php +88 -0
  162. app/code/core/Mage/XmlConnect/Block/Review/Form.php +113 -0
  163. app/code/core/Mage/XmlConnect/Block/Wishlist.php +115 -0
  164. app/code/core/Mage/XmlConnect/Controller/Action.php +157 -0
  165. app/code/core/Mage/XmlConnect/Helper/Android.php +725 -0
  166. app/code/core/Mage/XmlConnect/Helper/Catalog/Category/Image.php +103 -0
  167. app/code/core/Mage/XmlConnect/Helper/Customer/Form/Renderer.php +59 -0
  168. app/code/core/Mage/XmlConnect/Helper/Customer/Order.php +304 -0
  169. app/code/core/Mage/XmlConnect/Helper/Data.php +865 -0
  170. app/code/core/Mage/XmlConnect/Helper/Image.php +788 -0
  171. app/code/core/Mage/XmlConnect/Helper/Ipad.php +750 -0
  172. app/code/core/Mage/XmlConnect/Helper/Iphone.php +797 -0
  173. app/code/core/Mage/XmlConnect/Helper/Payment.php +42 -0
  174. app/code/core/Mage/XmlConnect/Helper/Theme.php +395 -0
  175. app/code/core/Mage/XmlConnect/Model/Adminhtml/System/Config/Backend/Baseurl.php +50 -0
  176. app/code/core/Mage/XmlConnect/Model/Adminhtml/System/Config/Backend/Currency/Default.php +50 -0
  177. app/code/core/Mage/XmlConnect/Model/Application.php +1219 -0
  178. app/code/core/Mage/XmlConnect/Model/Catalog/Category/Image.php +206 -0
  179. app/code/core/Mage/XmlConnect/Model/Catalog/Category/Media/Config.php +75 -0
  180. app/code/core/Mage/XmlConnect/Model/ConfigData.php +221 -0
  181. app/code/core/Mage/XmlConnect/Model/Corefix/Checkout/Session.php +137 -0
  182. app/code/core/Mage/XmlConnect/Model/Corefix/Checkout/Type/Onepage.php +465 -0
  183. app/code/core/Mage/XmlConnect/Model/Corefix/Sales/Quote.php +427 -0
  184. app/code/core/Mage/XmlConnect/Model/History.php +73 -0
  185. app/code/core/Mage/XmlConnect/Model/Input/Filter/MaliciousCode.php +100 -0
  186. app/code/core/Mage/XmlConnect/Model/Mysql4/Application.php +128 -0
  187. app/code/core/Mage/XmlConnect/Model/Mysql4/Application/Collection.php +37 -0
  188. app/code/core/Mage/XmlConnect/Model/Mysql4/Cms/Page/Collection.php +63 -0
  189. app/code/core/Mage/XmlConnect/Model/Mysql4/ConfigData.php +107 -0
  190. app/code/core/Mage/XmlConnect/Model/Mysql4/ConfigData/Collection.php +177 -0
  191. app/code/core/Mage/XmlConnect/Model/Mysql4/Filter/Collection.php +101 -0
  192. app/code/core/Mage/XmlConnect/Model/Mysql4/History.php +84 -0
  193. app/code/core/Mage/XmlConnect/Model/Mysql4/History/Collection.php +69 -0
  194. app/code/core/Mage/XmlConnect/Model/Mysql4/Queue.php +37 -0
  195. app/code/core/Mage/XmlConnect/Model/Mysql4/Queue/Collection.php +103 -0
  196. app/code/core/Mage/XmlConnect/Model/Mysql4/Setup.php +29 -0
  197. app/code/core/Mage/XmlConnect/Model/Mysql4/Template.php +37 -0
  198. app/code/core/Mage/XmlConnect/Model/Mysql4/Template/Collection.php +72 -0
  199. app/code/core/Mage/XmlConnect/Model/Observer.php +121 -0
  200. app/code/core/Mage/XmlConnect/Model/Payment/Method/Paypal/Config.php +55 -0
  201. app/code/core/Mage/XmlConnect/Model/Payment/Method/Paypal/Mecl.php +82 -0
  202. app/code/core/Mage/XmlConnect/Model/Payment/Method/Paypal/Mep.php +114 -0
  203. app/code/core/Mage/XmlConnect/Model/Paypal/Mecl/Checkout.php +43 -0
  204. app/code/core/Mage/XmlConnect/Model/Paypal/Mep/Checkout.php +83 -0
app/code/core/Mage/XmlConnect/Block/Adminhtml/History.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect application submission history grid
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_History extends Mage_Adminhtml_Block_Widget_Grid_Container
35
+ {
36
+ /**
37
+ * Class constructor
38
+ */
39
+ public function __construct()
40
+ {
41
+ $this->_blockGroup = 'xmlconnect';
42
+ $this->_controller = 'adminhtml_history';
43
+ $this->_headerText = $this->__('App Submission History');
44
+
45
+ parent::__construct();
46
+ $this->removeButton('add');
47
+ }
48
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/History/Grid.php ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect application history grid
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_History_Grid extends Mage_Adminhtml_Block_Widget_Grid
35
+ {
36
+ /**
37
+ * Constructor
38
+ *
39
+ * Setting grid_id, sort order and sort direction
40
+ */
41
+ public function __construct()
42
+ {
43
+ parent::__construct();
44
+ $this->setId('app_history_grid');
45
+ $this->setDefaultSort('created_at');
46
+ $this->setDefaultDir('ASC');
47
+ }
48
+
49
+ /**
50
+ * Setting collection to show
51
+ *
52
+ * @return Mage_Adminhtml_Block_Widget_Grid
53
+ */
54
+ protected function _prepareCollection()
55
+ {
56
+ $collection = Mage::getModel('xmlconnect/history')->getCollection();
57
+ $this->setCollection($collection);
58
+ return parent::_prepareCollection();
59
+ }
60
+
61
+ /**
62
+ * Configuration of grid
63
+ *
64
+ * @return Mage_Adminhtml_Block_Widget_Grid
65
+ */
66
+ protected function _prepareColumns()
67
+ {
68
+ $this->addColumn('title', array(
69
+ 'header' => $this->__('App Title'),
70
+ 'align' => 'left',
71
+ 'index' => 'title',
72
+ 'type' => 'text',
73
+ 'escape' => true
74
+ ));
75
+
76
+ $this->addColumn('name', array(
77
+ 'header' => $this->__('App Name'),
78
+ 'align' => 'left',
79
+ 'index' => 'name',
80
+ 'escape' => true
81
+ ));
82
+
83
+ $this->addColumn('code', array(
84
+ 'header' => $this->__('App Code'),
85
+ 'align' => 'left',
86
+ 'index' => 'code',
87
+ 'escape' => true
88
+ ));
89
+
90
+ $this->addColumn('created_at', array(
91
+ 'header' => $this->__('Date Submitted'),
92
+ 'align' => 'left',
93
+ 'index' => 'created_at',
94
+ 'type' => 'datetime'
95
+ ));
96
+
97
+ $this->addColumn('activation_key', array(
98
+ 'header' => $this->__('Activation Key'),
99
+ 'align' => 'left',
100
+ 'index' => 'activation_key',
101
+ 'escape' => true
102
+ ));
103
+ return parent::_prepareColumns();
104
+ }
105
+
106
+ /**
107
+ * Remove row click url
108
+ *
109
+ * @param Mage_Catalog_Model_Product|Varien_Object $row
110
+ * @return string
111
+ */
112
+ public function getRowUrl($row)
113
+ {
114
+ return '';
115
+ }
116
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect application grid
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile extends Mage_Adminhtml_Block_Widget_Grid_Container
35
+ {
36
+ /**
37
+ * Class constructor
38
+ */
39
+ public function __construct()
40
+ {
41
+ $this->_controller = 'adminhtml_mobile';
42
+ $this->_blockGroup = 'xmlconnect';
43
+ $xmlconnectVersion = Mage::getConfig()->getNode(
44
+ Mage_XmlConnect_Model_Application::XML_PATH_MODULE_VERSION
45
+ );
46
+ $this->_headerText = $this->__('Manage Apps')
47
+ . ' '
48
+ . $this->__('ver. %s', $xmlconnectVersion);
49
+ $this->_addButtonLabel = $this->__('Add App');
50
+
51
+ parent::__construct();
52
+ }
53
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit.php ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Application edit block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit
35
+ extends Mage_Adminhtml_Block_Widget_Form_Container
36
+ {
37
+ /**
38
+ * Setting app action buttons for application
39
+ */
40
+ public function __construct()
41
+ {
42
+ $this->_objectId = 'application_id';
43
+ $this->_controller = 'adminhtml_mobile';
44
+ $this->_blockGroup = 'xmlconnect';
45
+ parent::__construct();
46
+ if ((bool)!Mage::getSingleton('adminhtml/session')->getNewApplication()) {
47
+ $app = Mage::helper('xmlconnect')->getApplication();
48
+ $this->_updateButton('save', 'label', $this->__('Save'));
49
+ $this->_updateButton('save', 'onclick', 'if (editForm.submit()) {disableElements(\'save\')}');
50
+
51
+ $this->_addButton('save_and_continue', array(
52
+ 'label' => $this->__('Save and Continue Edit'),
53
+ 'onclick' => 'saveAndContinueEdit()',
54
+ 'class' => 'save',
55
+ ), -5);
56
+
57
+ if ($app->getId()) {
58
+ $this->_addButton('submit_application_button', array(
59
+ 'label' => $this->__('Save and Submit App'),
60
+ 'onclick' => 'saveAndSubmitApp()',
61
+ 'class' => 'save'
62
+ ), -10);
63
+ }
64
+
65
+ $this->_formScripts[] = 'function saveAndContinueEdit() {'
66
+ .'if (editForm.submit($(\'edit_form\').action + \'back/edit/\')) {disableElements(\'save\')};}';
67
+ if ($app->getId()) {
68
+ $this->_formScripts[] = 'function saveAndSubmitApp() {'
69
+ .'if (editForm.submit($(\'edit_form\').action + \'submitapp/' . $app->getId() . '\')) {'
70
+ .'disableElements(\'save\')};}';
71
+ }
72
+ } else {
73
+ $this->removeButton('save');
74
+ $this->removeButton('delete');
75
+ }
76
+
77
+ if (isset($app) && $app->getIsSubmitted()) {
78
+ $this->removeButton('delete');
79
+ }
80
+ $this->removeButton('reset');
81
+ }
82
+
83
+ /**
84
+ * Adding JS scripts and styles to block
85
+ *
86
+ * @throws Mage_Core_Exception
87
+ * @return Mage_Adminhtml_Block_Widget_Form_Container
88
+ */
89
+ protected function _prepareLayout()
90
+ {
91
+ $this->getLayout()->getBlock('head')->addJs('jscolor/jscolor.js');
92
+ $this->getLayout()->getBlock('head')->addJs('scriptaculous/scriptaculous.js');
93
+
94
+ if ((bool)!Mage::getSingleton('adminhtml/session')->getNewApplication()) {
95
+ $deviceType = Mage::helper('xmlconnect')->getDeviceType();
96
+ switch ($deviceType) {
97
+ case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPHONE:
98
+ $this->getLayout()->getBlock('head')->addItem('skin_css', 'xmlconnect/mobile-home.css');
99
+ $this->getLayout()->getBlock('head')->addItem('skin_css', 'xmlconnect/mobile-catalog.css');
100
+ break;
101
+ case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPAD:
102
+ $this->getLayout()->getBlock('head')->addItem('skin_css', 'xmlconnect/mobile-ipad-home.css');
103
+ $this->getLayout()->getBlock('head')->addItem('skin_css', 'xmlconnect/mobile-ipad-catalog.css');
104
+ break;
105
+ case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_ANDROID:
106
+ $this->getLayout()->getBlock('head')->addItem('skin_css', 'xmlconnect/mobile-android.css');
107
+ break;
108
+ default:
109
+ Mage::throwException(
110
+ $this->__('Device doesn\'t recognized: "%s". Unable to load preview model.', $deviceType)
111
+ );
112
+ break;
113
+ }
114
+ }
115
+
116
+ return parent::_prepareLayout();
117
+ }
118
+
119
+ /**
120
+ * Get form header title
121
+ *
122
+ * @return string
123
+ */
124
+ public function getHeaderText()
125
+ {
126
+ if ((bool)!Mage::getSingleton('adminhtml/session')->getNewApplication()) {
127
+ $app = Mage::helper('xmlconnect')->getApplication();
128
+ }
129
+
130
+ if (isset($app) && $app->getId()) {
131
+ return $this->__('Edit App "%s"', $this->htmlEscape($app->getName()));
132
+ } else {
133
+ return $this->__('New App');
134
+ }
135
+ }
136
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Form.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Application Form block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
35
+ {
36
+ /**
37
+ * Prepare form before rendering HTML
38
+ * Setting Form Fieldsets and fields
39
+ *
40
+ * @return Mage_Adminhtml_Block_Widget_Form
41
+ */
42
+ protected function _prepareForm()
43
+ {
44
+ $form = new Varien_Data_Form(array('id' => 'edit_form',
45
+ 'action' => Mage::getSingleton('adminhtml/session')->getNewApplication()
46
+ ? $this->getUrl('*/mobile/edit', array('_current' => true))
47
+ : $this->getUrl('*/mobile/save'),
48
+ 'method' => 'post',
49
+ 'enctype' => 'multipart/form-data'
50
+ ));
51
+ $form->setUseContainer(true);
52
+ $this->setForm($form);
53
+ return parent::_prepareForm();
54
+ }
55
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Submission.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Application Submission block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Submission
35
+ extends Mage_Adminhtml_Block_Widget_Tabs
36
+ {
37
+ /**
38
+ * Constructor
39
+ *
40
+ * Setting grid_id, DOM destination element id
41
+ *
42
+ */
43
+ public function __construct()
44
+ {
45
+ parent::__construct();
46
+ $this->setId('mobile_app_submit');
47
+ $this->setDestElementId('content');
48
+ }
49
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Cache.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Tab for Cache Management
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Cache
35
+ extends Mage_Adminhtml_Block_Widget_Form
36
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
37
+ {
38
+ /**
39
+ * Prepare form before rendering HTML
40
+ * Setting Form Fieldsets and fields
41
+ *
42
+ * @return Mage_Adminhtml_Block_Widget_Form
43
+ */
44
+ protected function _prepareForm()
45
+ {
46
+ $form = new Varien_Data_Form();
47
+ $this->setForm($form);
48
+
49
+ $data = Mage::helper('xmlconnect')->getApplication()->getFormData();
50
+
51
+ $fieldset = $form->addFieldset('cache_management', array('legend' => $this->__('Cache Management')));
52
+ if (isset($data['conf[native][cacheLifetime]'])) {
53
+ $lifetime = $data['conf[native][cacheLifetime]'];
54
+ } else {
55
+ $lifetime = Mage::helper('xmlconnect')->getDefaultCacheLifetime();
56
+ }
57
+ $fieldset->addField('conf/native/cacheLifetime', 'text', array(
58
+ 'label' => $this->__('Cache Lifetime (seconds)'),
59
+ 'name' => 'conf[native][cacheLifetime]',
60
+ 'value' => $lifetime,
61
+ 'note' => $this->__('If you want to disable the cache on the application side, leave the field empty. Warning! When disabling cache, the application will take time to load each page.'),
62
+ ));
63
+
64
+ return parent::_prepareForm();
65
+ }
66
+
67
+ /**
68
+ * Tab label getter
69
+ *
70
+ * @return string
71
+ */
72
+ public function getTabLabel()
73
+ {
74
+ return $this->__('Cache Management');
75
+ }
76
+
77
+ /**
78
+ * Tab title getter
79
+ *
80
+ * @return string
81
+ */
82
+ public function getTabTitle()
83
+ {
84
+ return $this->__('Cache Management');
85
+ }
86
+
87
+ /**
88
+ * Check if tab can be shown
89
+ *
90
+ * @return bool
91
+ */
92
+ public function canShowTab()
93
+ {
94
+ return (bool) !Mage::getSingleton('adminhtml/session')->getNewApplication();
95
+ }
96
+
97
+ /**
98
+ * Check if tab hidden
99
+ *
100
+ * @return bool
101
+ */
102
+ public function isHidden()
103
+ {
104
+ return false;
105
+ }
106
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Content.php ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Tab for Content Management
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Content
35
+ extends Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form
36
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
37
+ {
38
+ protected $_pages;
39
+
40
+ /**
41
+ * Class constructor
42
+ * Setting view option
43
+ */
44
+ public function __construct()
45
+ {
46
+ parent::__construct();
47
+ $this->setShowGlobalIcon(true);
48
+ }
49
+
50
+ /**
51
+ * Add page input to fieldset
52
+ *
53
+ * @param Varien_Data_Form_Element_Fieldset $fieldset
54
+ * @param string $fieldPrefix
55
+ */
56
+ protected function _addPage($fieldset, $fieldPrefix)
57
+ {
58
+ $element = $fieldset->addField($fieldPrefix, 'page', array(
59
+ 'name' => $fieldPrefix,
60
+ ));
61
+ $element->initFields(array(
62
+ 'name' => $fieldPrefix,
63
+ 'values' => $this->_pages,
64
+ ));
65
+ }
66
+
67
+ /**
68
+ * Prepare form before rendering HTML
69
+ * Setting Form Fieldsets and fields
70
+ *
71
+ * @return Mage_Adminhtml_Block_Widget_Form
72
+ */
73
+ protected function _prepareForm()
74
+ {
75
+ $model = Mage::helper('xmlconnect')->getApplication();
76
+ $conf = $model->getConf();
77
+ $form = new Varien_Data_Form();
78
+ $this->setForm($form);
79
+
80
+ $pages = Mage::getResourceModel('xmlconnect/cms_page_collection')->toOptionIdArray();
81
+ $dummy = array(array( 'value' => '', 'label' => '' ));
82
+ $this->_pages = array_merge($dummy, $pages);
83
+
84
+ $fieldset = $form->addFieldset('cms_pages', array('legend' => $this->__('Pages')));
85
+ $this->_addElementTypes($fieldset);
86
+
87
+ $fieldset->addField('page_row_add', 'addrow', array(
88
+ 'onclick' => 'insertNewTableRow(this)',
89
+ 'options' => $this->_pages,
90
+ 'class' => ' scalable save ',
91
+ 'label' => $this->__('Label'),
92
+ 'before_element_html' => $this->__('Get Content from CMS Page').'</td><td class="label">',
93
+ ));
94
+
95
+ if (!empty($conf['native']['pages'])) {
96
+ foreach ($conf['native']['pages'] as $key=>$dummy) {
97
+ $this->_addPage($fieldset, 'conf[native][pages]['.$key.']');
98
+ }
99
+ }
100
+
101
+ $data = $model->getFormData();
102
+ $data['page_row_add'] = $this->__('Add Page');
103
+ $form->setValues($data);
104
+ return parent::_prepareForm();
105
+ }
106
+
107
+ /**
108
+ * Prepare label for tab
109
+ *
110
+ * @return string
111
+ */
112
+ public function getTabLabel()
113
+ {
114
+ return $this->__('Content');
115
+ }
116
+
117
+ /**
118
+ * Prepare title for tab
119
+ *
120
+ * @return string
121
+ */
122
+ public function getTabTitle()
123
+ {
124
+ return $this->__('Content');
125
+ }
126
+
127
+ /**
128
+ * Returns status flag about this tab can be shown or not
129
+ *
130
+ * @return true
131
+ */
132
+ public function canShowTab()
133
+ {
134
+ return (bool) !Mage::getSingleton('adminhtml/session')->getNewApplication();
135
+ }
136
+
137
+ /**
138
+ * Returns status flag about this tab hidden or not
139
+ *
140
+ * @return false
141
+ */
142
+ public function isHidden()
143
+ {
144
+ return false;
145
+ }
146
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design.php ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Tab for Design Management
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design
35
+ extends Mage_Adminhtml_Block_Template
36
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
37
+ {
38
+ /**
39
+ * Set design tab template
40
+ * Set to show global icon
41
+ */
42
+ public function __construct()
43
+ {
44
+ parent::__construct();
45
+ $this->setShowGlobalIcon(true);
46
+ $this->setTemplate('xmlconnect/edit/tab/design.phtml');
47
+ }
48
+
49
+ /**
50
+ * Tab label getter
51
+ *
52
+ * @return string
53
+ */
54
+ public function getTabLabel()
55
+ {
56
+ return $this->__('Design');
57
+ }
58
+
59
+ /**
60
+ * Tab title getter
61
+ *
62
+ * @return string
63
+ */
64
+ public function getTabTitle()
65
+ {
66
+ return $this->__('Design');
67
+ }
68
+
69
+ /**
70
+ * Check if tab can be shown
71
+ *
72
+ * @return bool
73
+ */
74
+ public function canShowTab()
75
+ {
76
+ return (bool) !Mage::getSingleton('adminhtml/session')->getNewApplication();
77
+ }
78
+
79
+ /**
80
+ * Check if tab hidden
81
+ *
82
+ * @return bool
83
+ */
84
+ public function isHidden()
85
+ {
86
+ return false;
87
+ }
88
+
89
+ /**
90
+ * Check if we have to show Preview Block
91
+ *
92
+ * @return bool
93
+ */
94
+ public function canShowPreview()
95
+ {
96
+ return true;
97
+ }
98
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Tab design accordion xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Xmlconnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Accordion
35
+ extends Mage_Adminhtml_Block_Widget_Accordion
36
+ {
37
+ /**
38
+ * Add accordion item by specified block
39
+ *
40
+ * @param string $itemId
41
+ * @param mixed $block
42
+ */
43
+ public function addAccordionItem($itemId, $block)
44
+ {
45
+ if (strpos($block, '/') !== false) {
46
+ $block = $this->getLayout()->createBlock($block);
47
+ } else {
48
+ $block = $this->getLayout()->getBlock($block);
49
+ }
50
+
51
+ $this->addItem($itemId, array(
52
+ 'title' => $block->getTitle(),
53
+ 'content' => $block->toHtml(),
54
+ 'open' => $block->getIsOpen(),
55
+ ));
56
+ }
57
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Images.php ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Tab design Accordion Images xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Xmlconnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Accordion_Images
35
+ extends Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form
36
+ {
37
+ /**
38
+ * Getter for accordion item title
39
+ *
40
+ * @return string
41
+ */
42
+ public function getTitle()
43
+ {
44
+ return $this->__('Images');
45
+ }
46
+
47
+ /**
48
+ * Getter for accordion item is open flag
49
+ *
50
+ * @return bool
51
+ */
52
+ public function getIsOpen()
53
+ {
54
+ return true;
55
+ }
56
+
57
+ /**
58
+ * Prepare form
59
+ *
60
+ * @throws Mage_Core_Exception
61
+ * @return Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form
62
+ */
63
+ protected function _prepareForm()
64
+ {
65
+ $form = new Varien_Data_Form();
66
+
67
+ $fieldset = $form->addFieldset('field_logo', array());
68
+ $this->_addElementTypes($fieldset);
69
+ $this->addImage($fieldset,
70
+ 'conf[native][navigationBar][icon]',
71
+ $this->__('Logo in Header'),
72
+ $this->__('Recommended size 35px x 35px.'),
73
+ $this->_getDesignPreviewImageUrl('conf/native/navigationBar/icon'),
74
+ true
75
+ );
76
+
77
+ $deviceType = Mage::helper('xmlconnect')->getDeviceType();
78
+ switch ($deviceType) {
79
+ case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPHONE:
80
+ $this->addImage($fieldset,
81
+ 'conf[native][body][bannerImage]',
82
+ $this->__('Banner on Home Screen'),
83
+ $this->__('Recommended size 320px x 230px. Note: Image size affects the performance of your app. Keep your image size below 50 KB for optimal performance.'),
84
+ $this->_getDesignPreviewImageUrl('conf/native/body/bannerImage'),
85
+ true
86
+ );
87
+ $this->addImage($fieldset,
88
+ 'conf[native][body][backgroundImage]',
89
+ $this->__('App Background'),
90
+ $this->__('Recommended size 320px x 367px. Note: Image size affects the performance of your app. Keep your image size below 75 KB for optimal performance.'),
91
+ $this->_getDesignPreviewImageUrl('conf/native/body/backgroundImage'),
92
+ true
93
+ );
94
+ break;
95
+ case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPAD:
96
+ $this->addImage($fieldset,
97
+ 'conf[native][body][bannerIpadLandscapeImage]',
98
+ $this->__('Banner on Home Screen <br />(landscape mode)'),
99
+ $this->__('Recommended size 1024px x 344px. Note: Image size affects the performance of your app.'),
100
+ $this->_getDesignPreviewImageUrl('conf/native/body/bannerIpadLandscapeImage'),
101
+ true
102
+ );
103
+ $this->addImage($fieldset,
104
+ 'conf[native][body][bannerIpadImage]',
105
+ $this->__('Banner on Home Screen <br />(portrait mode)'),
106
+ $this->__('Recommended size 768px x 294px. Note: Image size affects the performance of your app.'),
107
+ $this->_getDesignPreviewImageUrl('conf/native/body/bannerIpadImage'),
108
+ true
109
+ );
110
+ $this->addImage($fieldset,
111
+ 'conf[native][body][backgroundIpadLandscapeImage]',
112
+ $this->__('App Background <br />(landscape mode)'),
113
+ $this->__('Recommended size 1024px x 704px. Note: Image size affects the performance of your app.'),
114
+ $this->_getDesignPreviewImageUrl('conf/native/body/backgroundIpadLandscapeImage'),
115
+ true
116
+ );
117
+ $this->addImage($fieldset,
118
+ 'conf[native][body][backgroundIpadPortraitImage]',
119
+ $this->__('App Background <br />(portrait mode)'),
120
+ $this->__('Recommended size 768px x 960px. Note: Image size affects the performance of your app.'),
121
+ $this->_getDesignPreviewImageUrl('conf/native/body/backgroundIpadPortraitImage'),
122
+ true
123
+ );
124
+ break;
125
+ case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_ANDROID:
126
+ $this->addImage($fieldset,
127
+ 'conf[native][body][bannerAndroidImage]',
128
+ $this->__('Banner on Home Screen'),
129
+ $this->__('Recommended size 320px x 258px. Note: Image size affects the performance of your app. Keep your image size below 50 KB for optimal performance.'),
130
+ $this->_getDesignPreviewImageUrl('conf/native/body/bannerAndroidImage'),
131
+ true
132
+ );
133
+ break;
134
+ default:
135
+ Mage::throwException(
136
+ $this->__('Device doesn\'t recognized: "%s". Unable to load a helper.', $deviceType)
137
+ );
138
+ break;
139
+ }
140
+
141
+ $form->setValues(Mage::helper('xmlconnect')->getApplication()->getFormData());
142
+ $this->setForm($form);
143
+ return parent::_prepareForm();
144
+ }
145
+
146
+ /**
147
+ * Retrieve url for images in the skin folder
148
+ *
149
+ * @param string $name - path to file name relative to the skin dir
150
+ * @return string
151
+ */
152
+ protected function _getDesignPreviewImageUrl($name)
153
+ {
154
+ $name = Mage::helper('xmlconnect/image')->getInterfaceImagesPaths($name);
155
+ return Mage::helper('xmlconnect/image')->getDefaultDesignUrl($name);
156
+ }
157
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Tabs.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Device tabs accordion block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Accordion_Tabs
35
+ extends Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form
36
+ {
37
+ /**
38
+ * Getter for accordion item title
39
+ *
40
+ * @return string
41
+ */
42
+ public function getTitle()
43
+ {
44
+ if (Mage::helper('xmlconnect')->getDeviceType() == Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPAD) {
45
+ $title = $this->__('Extensions');
46
+ } else {
47
+ $title = $this->__('Tabs');
48
+ }
49
+ return $title;
50
+ }
51
+
52
+ /**
53
+ * Getter for accordion item is open flag
54
+ *
55
+ * @return bool
56
+ */
57
+ public function getIsOpen()
58
+ {
59
+ return true;
60
+ }
61
+
62
+ /**
63
+ * Prepare form
64
+ *
65
+ * @return Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form
66
+ */
67
+ protected function _prepareForm()
68
+ {
69
+ $form = new Varien_Data_Form();
70
+
71
+ $fieldset = $form->addFieldset('field_tabs', array());
72
+ $this->_addElementTypes($fieldset);
73
+ $fieldset->addField('conf[extra][tabs]', 'tabs', array('name' => 'conf[extra][tabs]'));
74
+
75
+ $form->setValues(Mage::helper('xmlconnect')->getApplication()->getFormData());
76
+ $this->setForm($form);
77
+ return parent::_prepareForm();
78
+ }
79
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Themes.php ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Device design themes accordion block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Accordion_Themes
35
+ extends Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form
36
+ {
37
+ /**
38
+ * Getter for accordion item title
39
+ *
40
+ * @return string
41
+ */
42
+ public function getTitle()
43
+ {
44
+ return $this->__('Color Themes');
45
+ }
46
+
47
+ /**
48
+ * Getter for accordion item is open flag
49
+ *
50
+ * @return bool
51
+ */
52
+ public function getIsOpen()
53
+ {
54
+ return true;
55
+ }
56
+
57
+ /**
58
+ * Add theme field
59
+ *
60
+ * @return Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form
61
+ */
62
+ protected function _prepareForm()
63
+ {
64
+ $form = new Varien_Data_Form();
65
+
66
+ $fieldset = $form->addFieldset('field_colors', array());
67
+ $this->_addElementTypes($fieldset);
68
+ $fieldset->addField('theme', 'theme', array(
69
+ 'name' => 'theme',
70
+ 'themes' => Mage::helper('xmlconnect/theme')->getAllThemes(),
71
+ ));
72
+ $form->setValues(Mage::helper('xmlconnect')->getApplication()->getFormData());
73
+ $this->setForm($form);
74
+
75
+ return parent::_prepareForm();
76
+ }
77
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Preview.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Tab design preview xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Xmlconnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Preview
35
+ extends Mage_Adminhtml_Block_Template
36
+ {
37
+ /**
38
+ * Set preview template
39
+ */
40
+ public function __construct()
41
+ {
42
+ parent::__construct();
43
+
44
+ $device = Mage::helper('xmlconnect')->getDeviceType();
45
+ if (array_key_exists($device, Mage::helper('xmlconnect')->getSupportedDevices())) {
46
+ $template = 'xmlconnect/edit/tab/design/preview_' . strtolower($device) . '.phtml';
47
+ } else {
48
+ Mage::throwException(
49
+ $this->__('Device doesn\'t recognized. Unable to load a template.')
50
+ );
51
+ }
52
+
53
+ $this->setTemplate($template);
54
+ }
55
+
56
+ /**
57
+ * Retieve preview action url
58
+ *
59
+ * @param string $page
60
+ * @return string
61
+ */
62
+ public function getPreviewActionUrl($page = 'home')
63
+ {
64
+ $params = array();
65
+ $model = Mage::helper('xmlconnect')->getApplication();
66
+ if ($model !== null) {
67
+ if ($model->getId() !== null) {
68
+ $params = array('application_id' => $model->getId());
69
+ } else {
70
+ $params = array('devtype' => $model->getType());
71
+ }
72
+ }
73
+ return $this->getUrl('*/*/preview' . $page, $params);
74
+ }
75
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Themes.php ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Device design themes block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Themes extends Mage_Adminhtml_Block_Template
35
+ {
36
+ /**
37
+ * Set themes template and color fieldsets
38
+ */
39
+ public function __construct()
40
+ {
41
+ parent::__construct();
42
+
43
+ $model = Mage::helper('xmlconnect')->getApplication();
44
+ $this->setTemplate('xmlconnect/form/element/themes.phtml');
45
+
46
+ $data = $model->getFormData();
47
+ $this->setColorFieldset(array(
48
+ array('id' => 'field_colors', 'label' => $this->__('Colors'), 'fields' => array(
49
+ $this->_addColorBox(
50
+ 'conf[native][navigationBar][tintColor]',
51
+ $this->__('Header Background Color'),
52
+ $data
53
+ ),
54
+ $this->_addColorBox(
55
+ 'conf[native][body][primaryColor]',
56
+ $this->__('Primary Color'),
57
+ $data
58
+ ),
59
+ $this->_addColorBox(
60
+ 'conf[native][body][secondaryColor]',
61
+ $this->__('Secondary Color'),
62
+ $data
63
+ ),
64
+ $this->_addColorBox(
65
+ 'conf[native][categoryItem][backgroundColor]',
66
+ $this->__('Category Item Background Color'),
67
+ $data
68
+ ),
69
+ $this->_addColorBox(
70
+ 'conf[native][categoryItem][tintColor]',
71
+ $this->__('Category Button Color'),
72
+ $data
73
+ ),
74
+ )),
75
+ array('id' => 'field_fonts', 'label' => $this->__('Fonts'), 'fields' => array(
76
+ $this->_addColorBox(
77
+ 'conf[extra][fontColors][header]',
78
+ $this->__('Header Font Color'),
79
+ $data
80
+ ),
81
+ $this->_addColorBox(
82
+ 'conf[extra][fontColors][primary]',
83
+ $this->__('Primary Font Color'),
84
+ $data
85
+ ),
86
+ $this->_addColorBox(
87
+ 'conf[extra][fontColors][secondary]',
88
+ $this->__('Secondary Font Color'),
89
+ $data
90
+ ),
91
+ $this->_addColorBox(
92
+ 'conf[extra][fontColors][price]',
93
+ $this->__('Price Font Color'),
94
+ $data
95
+ ),
96
+ )),
97
+ array('id' => 'field_advanced', 'label' => $this->__('Advanced Settings'), 'fields' => array(
98
+ $this->_addColorBox(
99
+ 'conf[native][body][backgroundColor]',
100
+ $this->__('Background Color'),
101
+ $data
102
+ ),
103
+ $this->_addColorBox(
104
+ 'conf[native][body][scrollBackgroundColor]',
105
+ $this->__('Scroll Background Color'),
106
+ $data
107
+ ),
108
+ $this->_addColorBox(
109
+ 'conf[native][itemActions][relatedProductBackgroundColor]',
110
+ $this->__('Related Product Background Color'),
111
+ $data
112
+ ),
113
+ )),
114
+ ));
115
+ }
116
+
117
+ /**
118
+ * Themes array getter
119
+ *
120
+ * @return array
121
+ */
122
+ public function getAllThemes()
123
+ {
124
+ $result = array();
125
+
126
+ foreach ($this->getThemes() as $theme) {
127
+ $result[$theme->getName()] = $theme->getFormData();
128
+ }
129
+ return $result;
130
+ }
131
+
132
+ /**
133
+ * Create color field params
134
+ *
135
+ * @param id $id
136
+ * @param string $label
137
+ * @param array $data
138
+ * @return array
139
+ */
140
+ protected function _addColorBox($id, $label, $data)
141
+ {
142
+ return array(
143
+ 'id' => $id,
144
+ 'name' => $id,
145
+ 'label' => $label,
146
+ 'value' => isset($data[$id]) ? $data[$id] : ''
147
+ );
148
+ }
149
+
150
+ /**
151
+ * Getter, check if it's needed to load default theme config
152
+ *
153
+ * @return bool
154
+ */
155
+ public function getDefaultThemeLoaded()
156
+ {
157
+ return Mage::helper('xmlconnect')->getApplication()->getDefaultThemeLoaded();
158
+ }
159
+
160
+ /**
161
+ * Check if adding new Application
162
+ *
163
+ * @return bool
164
+ */
165
+ public function isNewApplication()
166
+ {
167
+ return Mage::helper('xmlconnect')->getApplication()->getId() ? false : true;
168
+ }
169
+
170
+ /**
171
+ * Save theme action url getter
172
+ *
173
+ * @return string
174
+ */
175
+ public function getSaveThemeActionUrl()
176
+ {
177
+ return $this->getUrl('*/*/saveTheme');
178
+ }
179
+
180
+ /**
181
+ * Get delete theme action url
182
+ *
183
+ * @return string
184
+ */
185
+ public function getDeleteThemeActionUrl()
186
+ {
187
+ return $this->getUrl('*/*/deleteTheme');
188
+ }
189
+
190
+ /**
191
+ * Reset theme action url getter
192
+ *
193
+ * @return string
194
+ */
195
+ public function getResetThemeActionUrl()
196
+ {
197
+ return $this->getUrl('*/*/resetTheme');
198
+ }
199
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Flurryanalytics.php ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Tab for Flurry Analytics Management
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Flurryanalytics
35
+ extends Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form
36
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
37
+ {
38
+ protected $_pages;
39
+
40
+ /**
41
+ * Constructor
42
+ * Setting view options
43
+ */
44
+ public function __construct()
45
+ {
46
+ parent::__construct();
47
+ $this->setShowGlobalIcon(true);
48
+ }
49
+
50
+ /**
51
+ * Prepare form before rendering HTML
52
+ * Setting Form Fieldsets and fields
53
+ *
54
+ * @return Mage_Adminhtml_Block_Widget_Form
55
+ */
56
+ protected function _prepareForm()
57
+ {
58
+ $form = new Varien_Data_Form();
59
+
60
+ $this->setForm($form);
61
+
62
+ $data = Mage::helper('xmlconnect')->getApplication()->getFormData();
63
+ $yesNoValues = Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray();
64
+
65
+ $fieldset = $form->addFieldset('flurryAnalytics', array('legend' => $this->__('Flurry Analytics')));
66
+
67
+ if (isset($data['conf[native][merchantFlurryTracking][isActive]'])) {
68
+ $isActiveValue = $data['conf[native][merchantFlurryTracking][isActive]'];
69
+ } else {
70
+ $isActiveValue = '0';
71
+ }
72
+
73
+ $enabled = $fieldset->addField('conf/native/merchantFlurryTracking/isActive', 'select', array(
74
+ 'label' => $this->__('Enable Flurry Analytics'),
75
+ 'name' => 'conf[native][merchantFlurryTracking][isActive]',
76
+ 'values' => $yesNoValues,
77
+ 'note' => $this->__('Enable Flurry Analytics for the merchant.'),
78
+ 'value' => $isActiveValue
79
+ ));
80
+
81
+ $flurryAnalyticsUrl = $this->escapeHtml(
82
+ Mage::getStoreConfig('xmlconnect/flurry_analytics/statistics_url')
83
+ );
84
+
85
+ $fieldset->addField('flurry_analytics_link', 'link', array(
86
+ 'title' => $this->__('Flurry Analytics Site'),
87
+ 'label' => $this->__('Flurry Analytics Site'),
88
+ 'value' => $flurryAnalyticsUrl,
89
+ 'href' => $flurryAnalyticsUrl,
90
+ 'target' => '__blank',
91
+ 'note' => $this->__('You can watch statistics here.'),
92
+ ));
93
+
94
+ if (isset($data['conf[native][merchantFlurryTracking][accountId]'])) {
95
+ $accountIdValue = $data['conf[native][merchantFlurryTracking][accountId]'];
96
+ } else {
97
+ $accountIdValue = '';
98
+ }
99
+
100
+ $flurryApiCode = $fieldset->addField('conf/native/merchantFlurryTracking/accountId', 'text', array(
101
+ 'label' => $this->__('Flurry API Code'),
102
+ 'name' => 'conf[native][merchantFlurryTracking][accountId]',
103
+ 'enabled' => true,
104
+ 'required' => true,
105
+ 'value' => $accountIdValue
106
+ ));
107
+
108
+ // field dependencies
109
+ $this->setChild('form_after', $this->getLayout()
110
+ ->createBlock('adminhtml/widget_form_element_dependence')
111
+ ->addFieldMap($flurryApiCode->getHtmlId(), $flurryApiCode->getName())
112
+ ->addFieldMap($enabled->getHtmlId(), $enabled->getName())
113
+ ->addFieldDependence(
114
+ $flurryApiCode->getName(),
115
+ $enabled->getName(),
116
+ 1
117
+ ));
118
+ return parent::_prepareForm();
119
+ }
120
+
121
+ /**
122
+ * Tab label getter
123
+ *
124
+ * @return string
125
+ */
126
+ public function getTabLabel()
127
+ {
128
+ return $this->__('Analytics');
129
+ }
130
+
131
+ /**
132
+ * Tab title getter
133
+ *
134
+ * @return string
135
+ */
136
+ public function getTabTitle()
137
+ {
138
+ return $this->__('Flurry Analytics');
139
+ }
140
+
141
+ /**
142
+ * Check if tab can be shown
143
+ *
144
+ * @return bool
145
+ */
146
+ public function canShowTab()
147
+ {
148
+ return (bool) !Mage::getSingleton('adminhtml/session')->getNewApplication()
149
+ && Mage::helper('xmlconnect')->getDeviceType() == Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPHONE;
150
+ }
151
+
152
+ /**
153
+ * Check if tab hidden
154
+ *
155
+ * @return bool
156
+ */
157
+ public function isHidden()
158
+ {
159
+ return false;
160
+ }
161
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/General.php ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Tab for General Info Management
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_General
35
+ extends Mage_Adminhtml_Block_Widget_Form
36
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
37
+ {
38
+ /**
39
+ * Prepare form before rendering HTML
40
+ * Setting Form Fieldsets and fields
41
+ *
42
+ * @return Mage_Adminhtml_Block_Widget_Form
43
+ */
44
+ protected function _prepareForm()
45
+ {
46
+ $model = Mage::helper('xmlconnect')->getApplication();
47
+
48
+ $form = new Varien_Data_Form();
49
+ $form->setHtmlIdPrefix('app_');
50
+ $fieldset = $form->addFieldset('base_fieldset', array('legend' => $this->__('App Information')));
51
+
52
+ if ($model->getId()) {
53
+ $fieldset->addField('application_id', 'hidden', array(
54
+ 'name' => 'application_id',
55
+ 'value' => $model->getId()
56
+ ));
57
+ }
58
+
59
+ $fieldset->addField('name', 'text', array(
60
+ 'name' => 'name',
61
+ 'label' => $this->__('App Name'),
62
+ 'title' => $this->__('App Name'),
63
+ 'maxlength' => '250',
64
+ 'value' => $model->getName(),
65
+ 'required' => true,
66
+ ));
67
+
68
+ if ($model->getId()) {
69
+ $fieldset->addField('code', 'label', array(
70
+ 'label' => $this->__('App Code'),
71
+ 'title' => $this->__('App Code'),
72
+ 'value' => $model->getCode(),
73
+ ));
74
+ }
75
+
76
+ /**
77
+ * Check is single store mode
78
+ */
79
+ if (!Mage::app()->isSingleStoreMode()) {
80
+ $storeElement = $fieldset->addField('store_id', 'select', array(
81
+ 'name' => 'store_id',
82
+ 'label' => $this->__('Store View'),
83
+ 'title' => $this->__('Store View'),
84
+ 'required' => true,
85
+ 'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, false),
86
+ ));
87
+ } else {
88
+ $storeElement = $fieldset->addField('store_id', 'hidden', array(
89
+ 'name' => 'store_id',
90
+ 'value' => Mage::app()->getStore(true)->getId()
91
+ ));
92
+ $model->setStoreId(Mage::app()->getStore(true)->getId());
93
+ }
94
+
95
+ if ($model->getId()) {
96
+ $storeElement->setValue($model->getStoreId());
97
+ $storeElement->setDisabled(true);
98
+ } else if ($model->getStoreId()) {
99
+ $storeElement->setValue($model->getStoreId());
100
+ }
101
+
102
+ $fieldset->addField('showdev', 'select', array(
103
+ 'name' => 'showdev',
104
+ 'label' => $this->__('Device Type'),
105
+ 'title' => $this->__('Device Type'),
106
+ 'values' => array($model->getType() => $model->getDevtype()),
107
+ 'disabled' => true,
108
+ ));
109
+
110
+ $fieldset->addField('devtype', 'hidden', array(
111
+ 'name' => 'devtype',
112
+ 'value' => $model->getType(),
113
+ ));
114
+
115
+ $yesNoValues = Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray();
116
+
117
+ $fieldset->addField('browsing_mode', 'select', array(
118
+ 'label' => $this->__('Catalog Only App?'),
119
+ 'name' => 'browsing_mode',
120
+ 'note' => $this->__('A Catalog Only App will not support functions such as add to cart, add to wishlist, or login.'),
121
+ 'value' => $model->getBrowsingMode(),
122
+ 'values' => $yesNoValues
123
+ ));
124
+
125
+ $this->setForm($form);
126
+ return parent::_prepareForm();
127
+ }
128
+
129
+ /**
130
+ * Tab label getter
131
+ *
132
+ * @return string
133
+ */
134
+ public function getTabLabel()
135
+ {
136
+ return $this->__('General');
137
+ }
138
+
139
+ /**
140
+ * Tab title getter
141
+ *
142
+ * @return string
143
+ */
144
+ public function getTabTitle()
145
+ {
146
+ return $this->__('General');
147
+ }
148
+
149
+ /**
150
+ * Check if tab can be shown
151
+ *
152
+ * @return bool
153
+ */
154
+ public function canShowTab()
155
+ {
156
+ return (bool) !Mage::getSingleton('adminhtml/session')->getNewApplication();
157
+ }
158
+
159
+ /**
160
+ * Check if tab hidden
161
+ *
162
+ * @return bool
163
+ */
164
+ public function isHidden()
165
+ {
166
+ return false;
167
+ }
168
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Notification.php ADDED
@@ -0,0 +1,216 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Tab for Notifications Management
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Notification
35
+ extends Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form
36
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
37
+ {
38
+ /**
39
+ * Constructor
40
+ * Setting view options
41
+ */
42
+ public function __construct()
43
+ {
44
+ parent::__construct();
45
+ $this->setShowGlobalIcon(true);
46
+ }
47
+
48
+ /**
49
+ * Prepare form before rendering HTML
50
+ * Setting Form Fieldsets and fields
51
+ *
52
+ * @return Mage_Adminhtml_Block_Widget_Form
53
+ */
54
+ protected function _prepareForm()
55
+ {
56
+ $form = new Varien_Data_Form();
57
+
58
+ $this->setForm($form);
59
+
60
+ $data = Mage::helper('xmlconnect')->getApplication()->getFormData();
61
+
62
+ $yesNoValues = Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray();
63
+
64
+ $fieldset = $form->addFieldset('notifications', array(
65
+ 'legend' => $this->__('Urban Airship Push Notification'),
66
+ ));
67
+
68
+ if (isset($data['conf[native][notifications][isActive]'])) {
69
+ $notificationStatus = $data['conf[native][notifications][isActive]'];
70
+ } else {
71
+ $notificationStatus = '0';
72
+ }
73
+
74
+ $notificationEnabled = $fieldset->addField('conf/native/notifisations/isActive', 'select', array(
75
+ 'label' => $this->__('Enable AirMail Message Push notification'),
76
+ 'name' => 'conf[native][notifications][isActive]',
77
+ 'values' => $yesNoValues,
78
+ 'value' => $notificationStatus,
79
+ ));
80
+
81
+ if (isset($data['conf[native][notifications][applicationKey]'])) {
82
+ $keyValue = $data['conf[native][notifications][applicationKey]'];
83
+ } else {
84
+ $keyValue = '';
85
+ }
86
+
87
+ $applicationKey = $fieldset->addField('conf/native/notifications/applicationKey', 'text', array(
88
+ 'label' => $this->__('Application Key'),
89
+ 'name' => 'conf[native][notifications][applicationKey]',
90
+ 'value' => $keyValue,
91
+ 'required' => true
92
+ ));
93
+
94
+ if (isset($data['conf[native][notifications][applicationSecret]'])) {
95
+ $secretValue = $data['conf[native][notifications][applicationSecret]'];
96
+ } else {
97
+ $secretValue = '';
98
+ }
99
+
100
+ $applicationSecret = $fieldset->addField('conf/native/notifications/applicationSecret', 'text', array(
101
+ 'label' => $this->__('Application Secret'),
102
+ 'name' => 'conf[native][notifications][applicationSecret]',
103
+ 'value' => $secretValue,
104
+ 'required' => true
105
+ ));
106
+
107
+ if (isset($data['conf[native][notifications][applicationMasterSecret]'])) {
108
+ $mSecretValue = $data['conf[native][notifications][applicationMasterSecret]'];
109
+ } else {
110
+ $mSecretValue = '';
111
+ }
112
+
113
+ $mSecretConfPath = 'conf/native/notifications/applicationMasterSecret';
114
+ $applicationMasterSecret = $fieldset->addField($mSecretConfPath, 'text', array(
115
+ 'label' => $this->__('Application Master Secret'),
116
+ 'name' => 'conf[native][notifications][applicationMasterSecret]',
117
+ 'value' => $mSecretValue,
118
+ 'required' => true
119
+ ));
120
+
121
+ if (isset($data['conf[native][notifications][mailboxTitle]'])) {
122
+ $titleValue = $data['conf[native][notifications][mailboxTitle]'];
123
+ } else {
124
+ $titleValue = '';
125
+ }
126
+
127
+ $mailboxTitle = $fieldset->addField('conf/native/notifications/mailboxTitle', 'text', array(
128
+ 'label' => $this->__('Mailbox title'),
129
+ 'name' => 'conf[native][notifications][mailboxTitle]',
130
+ 'value' => $titleValue,
131
+ 'required' => true,
132
+ 'note' => $this->__('The Mailbox title will be shown in the More Info tab. To understand more about the title, please <a target="_blank" href="http://www.magentocommerce.com/img/product/mobile/helpers/mail_box_title.png">click here</a>')
133
+ ));
134
+
135
+ // field dependencies
136
+ $this->setChild('form_after', $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence')
137
+ ->addFieldMap($applicationKey->getHtmlId(), $applicationKey->getName())
138
+ ->addFieldMap($applicationSecret->getHtmlId(), $applicationSecret->getName())
139
+ ->addFieldMap($applicationMasterSecret->getHtmlId(), $applicationMasterSecret->getName())
140
+ ->addFieldMap($mailboxTitle->getHtmlId(), $mailboxTitle->getName())
141
+ ->addFieldMap($notificationEnabled->getHtmlId(), $notificationEnabled->getName())
142
+ ->addFieldDependence(
143
+ $applicationKey->getName(),
144
+ $notificationEnabled->getName(),
145
+ 1)
146
+ ->addFieldDependence(
147
+ $applicationSecret->getName(),
148
+ $notificationEnabled->getName(),
149
+ 1)
150
+ ->addFieldDependence(
151
+ $applicationMasterSecret->getName(),
152
+ $notificationEnabled->getName(),
153
+ 1)
154
+ ->addFieldDependence(
155
+ $mailboxTitle->getName(),
156
+ $notificationEnabled->getName(),
157
+ 1)
158
+ );
159
+ return parent::_prepareForm();
160
+ }
161
+
162
+ /**
163
+ * Tab label getter
164
+ *
165
+ * @return string
166
+ */
167
+ public function getTabLabel()
168
+ {
169
+ return $this->__('Push Notification');
170
+ }
171
+
172
+ /**
173
+ * Tab title getter
174
+ *
175
+ * @return string
176
+ */
177
+ public function getTabTitle()
178
+ {
179
+ return $this->__('Push Notification');
180
+ }
181
+
182
+ /**
183
+ * Check if tab can be shown
184
+ *
185
+ * @return bool
186
+ */
187
+ public function canShowTab()
188
+ {
189
+ return (bool) !Mage::getSingleton('adminhtml/session')->getNewApplication()
190
+ && Mage::helper('xmlconnect')->isNotificationsAllowed();
191
+ }
192
+
193
+ /**
194
+ * Check if tab hidden
195
+ *
196
+ * @return bool
197
+ */
198
+ public function isHidden()
199
+ {
200
+ if (!$this->getData('conf/special/notifications_submitted')) {
201
+ return false;
202
+ } else {
203
+ return true;
204
+ }
205
+ }
206
+
207
+ /**
208
+ * Append helper above form
209
+ *
210
+ * @return string
211
+ */
212
+ protected function _toHtml()
213
+ {
214
+ return $this->getChildHtml('app_notification_helper') . parent::_toHtml();
215
+ }
216
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Payment.php ADDED
@@ -0,0 +1,288 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Tab for Payments Management
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Payment
35
+ extends Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form
36
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
37
+ {
38
+ protected $_pages;
39
+
40
+ /**
41
+ * Constructor
42
+ * Setting view options
43
+ */
44
+ public function __construct()
45
+ {
46
+ parent::__construct();
47
+ $this->setShowGlobalIcon(true);
48
+ }
49
+
50
+ /**
51
+ * Prepare form before rendering HTML
52
+ * Setting Form Fieldsets and fields
53
+ *
54
+ * @return Mage_Adminhtml_Block_Widget_Form
55
+ */
56
+ protected function _prepareForm()
57
+ {
58
+ $form = new Varien_Data_Form();
59
+
60
+ $this->setForm($form);
61
+
62
+ $data = Mage::helper('xmlconnect')->getApplication()->getFormData();
63
+ $yesNoValues = Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray();
64
+
65
+ $fieldset = $form->addFieldset('onepage_checkout', array('legend' => $this->__('Standard Checkout')));
66
+
67
+ if (isset($data['conf[native][defaultCheckout][isActive]'])) {
68
+ $checkoutStatus = $data['conf[native][defaultCheckout][isActive]'];
69
+ } else {
70
+ $checkoutStatus = '1';
71
+ }
72
+
73
+ $fieldset->addField('conf/native/defaultCheckout/isActive', 'select', array(
74
+ 'label' => $this->__('Enable Standard Checkout'),
75
+ 'name' => 'conf[native][defaultCheckout][isActive]',
76
+ 'values' => $yesNoValues,
77
+ 'note' => $this->__('Standard Checkout uses the checkout methods provided by Magento. Only inline payment methods are supported. (e.g PayPal Direct, Authorize.Net, etc.)'),
78
+ 'value' => $checkoutStatus
79
+ ));
80
+
81
+ $deviceType = Mage::helper('xmlconnect')->getDeviceType();
82
+ switch ($deviceType) {
83
+ case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPHONE:
84
+ case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPAD:
85
+ /**
86
+ * PayPal MEP management
87
+ */
88
+ $fieldsetPaypal = $form->addFieldset('paypal_mep_checkout', array(
89
+ 'legend' => $this->__('PayPal Mobile Embedded Payment (MEP)')
90
+ ));
91
+
92
+ $paypalMepIsAvailable = Mage::getModel('xmlconnect/payment_method_paypal_mep')
93
+ ->isAvailable(null);
94
+
95
+ $paypalActive = 0;
96
+ if (isset($data['conf[native][paypal][isActive]'])) {
97
+ $paypalActive = (int)($data['conf[native][paypal][isActive]'] && $paypalMepIsAvailable);
98
+ }
99
+
100
+ $paypalConfigurationUrl = $this->escapeHtml(
101
+ $this->getUrl('adminhtml/system_config/edit', array('section' => 'paypal'))
102
+ );
103
+
104
+ $activateMepMethodNote = $this->__('To activate PayPal MEP payment method activate Express checkout first. ');
105
+
106
+ $businessAccountNote = $this->__('MEP is PayPal\'s native checkout experience for the iPhone. You can choose to use MEP alongside standard checkout, or use it as your only checkout method for Magento mobile. PayPal MEP requires a <a href="%s">PayPal business account</a>', $paypalConfigurationUrl);
107
+
108
+ $paypalActiveField = $fieldsetPaypal->addField('conf/native/paypal/isActive', 'select', array(
109
+ 'label' => $this->__('Activate PayPal Checkout'),
110
+ 'name' => 'conf[native][paypal][isActive]',
111
+ 'note' => (!$paypalMepIsAvailable ? $activateMepMethodNote : $businessAccountNote),
112
+ 'values' => $yesNoValues,
113
+ 'value' => $paypalActive,
114
+ 'disabled' => !$paypalMepIsAvailable
115
+ ));
116
+
117
+ if (isset($data['conf[special][merchantLabel]'])) {
118
+ $merchantLabelValue = $data['conf[special][merchantLabel]'];
119
+ } else {
120
+ $merchantLabelValue = '';
121
+ }
122
+ $merchantlabelField = $fieldsetPaypal->addField('conf/special/merchantLabel', 'text', array(
123
+ 'name' => 'conf[special][merchantLabel]',
124
+ 'label' => $this->__('Merchant Label'),
125
+ 'title' => $this->__('Merchant Label'),
126
+ 'required' => true,
127
+ 'value' => $merchantLabelValue
128
+ ));
129
+
130
+ if (isset($data['config_data[payment][paypalmep/allowspecific]'])) {
131
+ $paypalMepAllow = (int) $data['config_data[payment][paypalmep/allowspecific]'];
132
+ } else {
133
+ $paypalMepAllow = 0;
134
+ }
135
+ $paypalMepAllowSpecific = $fieldsetPaypal->addField(
136
+ 'config_data/paypalmep/allowspecific',
137
+ 'select',
138
+ array(
139
+ 'name' => 'config_data[payment:paypalmep/allowspecific]',
140
+ 'label' => $this->__('Payment Applicable From'),
141
+ 'values' => array(
142
+ array('value' => 0, 'label' => $this->__('All Allowed Countries')),
143
+ array('value' => 1, 'label' => $this->__('Specific Countries'))
144
+ ),
145
+ 'value' => $paypalMepAllow
146
+ ));
147
+
148
+ $countries = Mage::getModel('adminhtml/system_config_source_country')->toOptionArray(true);
149
+
150
+ if (empty($data['config_data[payment][paypalmep/allowspecific]'])) {
151
+ $countrySelected = array();
152
+ } else {
153
+ $countrySelected = explode(',', $data['config_data[payment][paypalmep/applicable]']);
154
+ }
155
+
156
+ $paypalMepApplicable = $fieldsetPaypal->addField(
157
+ 'config_data/paypalmep/applicable',
158
+ 'multiselect',
159
+ array(
160
+ 'name' => 'config_data[payment:paypalmep/applicable]',
161
+ 'label' => $this->__('Countries Payment Applicable From'),
162
+ 'values' => $countries,
163
+ 'value' => $countrySelected
164
+ ));
165
+
166
+ // field dependencies
167
+ $this->setChild('form_after', $this->getLayout()
168
+ ->createBlock('adminhtml/widget_form_element_dependence')
169
+ ->addFieldMap($paypalMepAllowSpecific->getHtmlId(), $paypalMepAllowSpecific->getName())
170
+ ->addFieldMap($paypalMepApplicable->getHtmlId(), $paypalMepApplicable->getName())
171
+ ->addFieldMap($merchantlabelField->getHtmlId(), $merchantlabelField->getName())
172
+ ->addFieldMap($paypalActiveField->getHtmlId(), $paypalActiveField->getName())
173
+ ->addFieldDependence(
174
+ $paypalMepApplicable->getName(),
175
+ $paypalMepAllowSpecific->getName(),
176
+ 1
177
+ )
178
+ ->addFieldDependence(
179
+ $paypalMepAllowSpecific->getName(),
180
+ $paypalActiveField->getName(),
181
+ 1
182
+ )
183
+ ->addFieldDependence(
184
+ $paypalMepApplicable->getName(),
185
+ $paypalActiveField->getName(),
186
+ 1
187
+ )
188
+ ->addFieldDependence(
189
+ $merchantlabelField->getName(),
190
+ $paypalActiveField->getName(),
191
+ 1
192
+ )
193
+ );
194
+ break;
195
+ case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_ANDROID:
196
+ /**
197
+ * PayPal MECL management
198
+ */
199
+ if (Mage::app()->isSingleStoreMode() || Mage::helper('xmlconnect')->getApplication()->getId()) {
200
+ $paypalMeclIsAvailable = Mage::getModel('xmlconnect/payment_method_paypal_mecl')
201
+ ->isAvailable();
202
+ $activateMeclMethodNote = $this->__('You need to enable PayPal Express Checkout first from the Payment configuration before enabling PayPal MECL.');
203
+ } else {
204
+ $paypalMeclIsAvailable = false;
205
+ $activateMeclMethodNote = $this->__('Please create and save an application first.');
206
+ }
207
+
208
+ $fieldsetMecl = $form->addFieldset('paypal_mecl_checkout', array(
209
+ 'legend' => $this->__('PayPal Mobile Express Checkout Library (MECL)')
210
+ ));
211
+
212
+ $meclAccountNote = $this->__('PayPal MECL is the mobile version of PayPal\'s Express Checkout service. You can choose to use MECL alongside standard checkout, or use it as your only checkout method for Magento Mobile.');
213
+
214
+ $paypalMeclActive = 0;
215
+ if (isset($data['config_data[payment][paypalmecl_is_active]'])) {
216
+ $paypalMeclActive = (int) $data['config_data[payment][paypalmecl_is_active]'];
217
+ }
218
+
219
+ $fieldsetMecl->addField('config_data/paypalmecl_is_active', 'select', array(
220
+ 'label' => $this->__('Activate PayPal MECL'),
221
+ 'name' => 'config_data[payment:paypalmecl_is_active]',
222
+ 'note' => (!$paypalMeclIsAvailable ? $activateMeclMethodNote : $meclAccountNote),
223
+ 'values' => $yesNoValues,
224
+ 'value' => $paypalMeclActive,
225
+ 'disabled' => !$paypalMeclIsAvailable
226
+ ));
227
+
228
+ /**
229
+ * PayPal MEP management
230
+ */
231
+ $fieldsetPaypal = $form->addFieldset('paypal_mep_checkout', array(
232
+ 'legend' => $this->__('PayPal Mobile Embedded Payment (MEP)')
233
+ ));
234
+ $fieldsetPaypal->addField('paypal_note', 'note', array(
235
+ 'label' => $this->__('Notice'),
236
+ 'text' => $this->__('Currently, PayPal MEP is not available for the Android application')
237
+ ));
238
+ break;
239
+ default:
240
+ Mage::throwException(
241
+ $this->__('Device doesn\'t recognized: "%s". Unable to load preview model.', $deviceType)
242
+ );
243
+ break;
244
+ }
245
+
246
+ return parent::_prepareForm();
247
+ }
248
+
249
+ /**
250
+ * Tab label getter
251
+ *
252
+ * @return string
253
+ */
254
+ public function getTabLabel()
255
+ {
256
+ return $this->__('Payment Methods');
257
+ }
258
+
259
+ /**
260
+ * Tab title getter
261
+ *
262
+ * @return string
263
+ */
264
+ public function getTabTitle()
265
+ {
266
+ return $this->__('Payment Methods');
267
+ }
268
+
269
+ /**
270
+ * Check if tab can be shown
271
+ *
272
+ * @return bool
273
+ */
274
+ public function canShowTab()
275
+ {
276
+ return (bool) !Mage::getSingleton('adminhtml/session')->getNewApplication();
277
+ }
278
+
279
+ /**
280
+ * Check if tab hidden
281
+ *
282
+ * @return bool
283
+ */
284
+ public function isHidden()
285
+ {
286
+ return false;
287
+ }
288
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Settings.php ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Tab for Settings Management
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Settings
35
+ extends Mage_Adminhtml_Block_Widget_Form
36
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
37
+ {
38
+ protected function _prepareLayout()
39
+ {
40
+ $this->setChild('continue_button',
41
+ $this->getLayout()->createBlock('adminhtml/widget_button')
42
+ ->setData(array(
43
+ 'label' => Mage::helper('catalog')->__('Continue'),
44
+ 'onclick' => "if (editForm.submit()) { return false }",
45
+ 'class' => 'save'
46
+ )
47
+ )
48
+ );
49
+ return parent::_prepareLayout();
50
+ }
51
+
52
+ /**
53
+ * Prepare form before rendering HTML
54
+ * Setting Form Fieldsets and fields
55
+ *
56
+ * @return Mage_Adminhtml_Block_Widget_Form
57
+ */
58
+ protected function _prepareForm()
59
+ {
60
+
61
+ $form = new Varien_Data_Form();
62
+ $form->setHtmlIdPrefix('app_');
63
+ $fieldset = $form->addFieldset('base_fieldset', array('legend' => $this->__('Device Information')));
64
+
65
+ $fieldset->addField('type', 'select', array(
66
+ 'name' => 'type',
67
+ 'label' => $this->__('Device Type'),
68
+ 'title' => $this->__('Device Type'),
69
+ 'values' => Mage::helper('xmlconnect')->getDeviceTypeOptions(),
70
+ 'required' => true
71
+ ));
72
+
73
+ $fieldset->addField('continue_button', 'note', array(
74
+ 'text' => $this->getChildHtml('continue_button'),
75
+ ));
76
+
77
+ $this->setForm($form);
78
+ return parent::_prepareForm();
79
+ }
80
+
81
+ /**
82
+ * Tab label getter
83
+ *
84
+ * @return string
85
+ */
86
+ public function getTabLabel()
87
+ {
88
+ return $this->__('Settings');
89
+ }
90
+
91
+ /**
92
+ * Tab title getter
93
+ *
94
+ * @return string
95
+ */
96
+ public function getTabTitle()
97
+ {
98
+ return $this->__('Settings');
99
+ }
100
+
101
+ /**
102
+ * Check if tab can be shown
103
+ *
104
+ * @return bool
105
+ */
106
+ public function canShowTab()
107
+ {
108
+ return (bool) Mage::getSingleton('adminhtml/session')->getNewApplication();
109
+ }
110
+
111
+ /**
112
+ * Check if tab hidden
113
+ *
114
+ * @return bool
115
+ */
116
+ public function isHidden()
117
+ {
118
+ return false;
119
+ }
120
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Social.php ADDED
@@ -0,0 +1,330 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Tab for Social Networking settings
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Social
35
+ extends Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form
36
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
37
+ {
38
+ /**
39
+ * Prepare form before rendering HTML
40
+ * Setting Form Fieldsets and fields
41
+ *
42
+ * @return Mage_Adminhtml_Block_Widget_Form
43
+ */
44
+ protected function _prepareForm()
45
+ {
46
+ $form = new Varien_Data_Form();
47
+
48
+ $this->setForm($form);
49
+
50
+ $data = Mage::helper('xmlconnect')->getApplication()->getFormData();
51
+
52
+ $yesNoValues = Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray();
53
+
54
+ /**
55
+ * Default values for social networks is DISABLED
56
+ */
57
+ $twitterStatus = $facebookStatus = $linkedinStatus = 0;
58
+ $noteText = $this->__('Please <a href="%s" target="_blank">click here</a> to see how to setup and retrieve API credentials.');
59
+
60
+ /**
61
+ * Twitter fieldset options
62
+ */
63
+ $fieldsetTwitter = $form->addFieldset('twitter', array(
64
+ 'legend' => $this->__('Twitter API')
65
+ ));
66
+
67
+ if (isset($data['conf[native][socialNetworking][twitter][isActive]'])) {
68
+ $twitterStatus = (int)$data['conf[native][socialNetworking][twitter][isActive]'];
69
+ }
70
+
71
+ $twitterActiveField = $fieldsetTwitter->addField(
72
+ 'conf/native/socialNetworking/twitter/isActive',
73
+ 'select',
74
+ array(
75
+ 'label' => $this->__('Enable Twitter'),
76
+ 'name' => 'conf[native][socialNetworking][twitter][isActive]',
77
+ 'values' => $yesNoValues,
78
+ 'value' => $twitterStatus,
79
+ )
80
+ );
81
+
82
+ if (isset($data['conf[native][socialNetworking][twitter][apiKey]'])) {
83
+ $twitterApiKey = $data['conf[native][socialNetworking][twitter][apiKey]'];
84
+ } else {
85
+ $twitterApiKey = '';
86
+ }
87
+
88
+ $twitterApiKeyField = $fieldsetTwitter->addField(
89
+ 'conf/native/socialNetworking/twitter/apiKey',
90
+ 'text',
91
+ array(
92
+ 'label' => $this->__('Twitter API Key'),
93
+ 'name' => 'conf[native][socialNetworking][twitter][apiKey]',
94
+ 'required' => true,
95
+ 'value' => $twitterApiKey
96
+ )
97
+ );
98
+
99
+ if (isset($data['conf[native][socialNetworking][twitter][secretKey]'])) {
100
+ $twitterSecretKey = $data['conf[native][socialNetworking][twitter][secretKey]'];
101
+ } else {
102
+ $twitterSecretKey = '';
103
+ }
104
+
105
+ $twitterSecretKeyField = $fieldsetTwitter->addField(
106
+ 'conf/native/socialNetworking/twitter/secretKey',
107
+ 'text',
108
+ array(
109
+ 'label' => $this->__('Twitter Secret Key'),
110
+ 'name' => 'conf[native][socialNetworking][twitter][secretKey]',
111
+ 'required' => true,
112
+ 'value' => $twitterSecretKey
113
+ )
114
+ );
115
+
116
+ $fieldsetTwitter->addField(
117
+ 'twitterNote',
118
+ 'note',
119
+ array(
120
+ 'text' => sprintf(
121
+ $noteText,
122
+ Mage::getStoreConfig(Mage_XmlConnect_Model_Application::XML_PATH_HOWTO_TWITTER_URL)
123
+ ),
124
+ )
125
+ );
126
+
127
+ /**
128
+ * Facebook fieldset options
129
+ */
130
+ $fieldsetFacebook = $form->addFieldset('facebook', array(
131
+ 'legend' => $this->__('Facebook API'),
132
+ ));
133
+
134
+ if (isset($data['conf[native][socialNetworking][facebook][isActive]'])) {
135
+ $facebookStatus = (int)$data['conf[native][socialNetworking][facebook][isActive]'];
136
+ }
137
+
138
+ $facebookActiveField = $fieldsetFacebook->addField(
139
+ 'conf/native/socialNetworking/facebook/isActive',
140
+ 'select',
141
+ array(
142
+ 'label' => $this->__('Enable Facebook'),
143
+ 'name' => 'conf[native][socialNetworking][facebook][isActive]',
144
+ 'values' => $yesNoValues,
145
+ 'value' => $facebookStatus,
146
+ )
147
+ );
148
+
149
+ if (isset($data['conf[native][socialNetworking][facebook][appID]'])) {
150
+ $facebookAppID = $data['conf[native][socialNetworking][facebook][appID]'];
151
+ } else {
152
+ $facebookAppID = '';
153
+ }
154
+
155
+ $facebookAppIDField = $fieldsetFacebook->addField(
156
+ 'conf/native/socialNetworking/facebook/appID',
157
+ 'text',
158
+ array(
159
+ 'label' => $this->__('Facebook Application ID'),
160
+ 'name' => 'conf[native][socialNetworking][facebook][appID]',
161
+ 'required' => true,
162
+ 'value' => $facebookAppID
163
+ )
164
+ );
165
+
166
+ $fieldsetFacebook->addField(
167
+ 'facebookNote',
168
+ 'note',
169
+ array(
170
+ 'text' => sprintf(
171
+ $noteText,
172
+ Mage::getStoreConfig(Mage_XmlConnect_Model_Application::XML_PATH_HOWTO_FACEBOOK_URL)
173
+ ),
174
+ )
175
+ );
176
+
177
+ /**
178
+ * LinkedIn fieldset options
179
+ */
180
+ $fieldsetLinkedin = $form->addFieldset('linkedin', array(
181
+ 'legend' => $this->__('LinkedIn API'),
182
+ ));
183
+
184
+ if (isset($data['conf[native][socialNetworking][linkedin][isActive]'])) {
185
+ $linkedinStatus = (int)$data['conf[native][socialNetworking][linkedin][isActive]'];
186
+ }
187
+
188
+ $linkedinActiveField = $fieldsetLinkedin->addField(
189
+ 'conf/native/socialNetworking/linkedin/isActive',
190
+ 'select',
191
+ array(
192
+ 'label' => $this->__('Enable LinkedIn'),
193
+ 'name' => 'conf[native][socialNetworking][linkedin][isActive]',
194
+ 'values' => $yesNoValues,
195
+ 'value' => $linkedinStatus,
196
+ )
197
+ );
198
+
199
+ if (isset($data['conf[native][socialNetworking][linkedin][apiKey]'])) {
200
+ $linkedinApiKey = $data['conf[native][socialNetworking][linkedin][apiKey]'];
201
+ } else {
202
+ $linkedinApiKey = '';
203
+ }
204
+
205
+ $linkedinApiKeyField = $fieldsetLinkedin->addField(
206
+ 'conf/native/socialNetworking/linkedin/apiKey',
207
+ 'text',
208
+ array(
209
+ 'label' => $this->__('LinkedIn API Key'),
210
+ 'name' => 'conf[native][socialNetworking][linkedin][apiKey]',
211
+ 'required' => true,
212
+ 'value' => $linkedinApiKey
213
+ )
214
+ );
215
+
216
+ if (isset($data['conf[native][socialNetworking][linkedin][secretKey]'])) {
217
+ $linkedinSecretKey = $data['conf[native][socialNetworking][linkedin][secretKey]'];
218
+ } else {
219
+ $linkedinSecretKey = '';
220
+ }
221
+
222
+ $linkedinSecretKeyField = $fieldsetLinkedin->addField(
223
+ 'conf/native/socialNetworking/linkedin/secretKey',
224
+ 'text',
225
+ array(
226
+ 'label' => $this->__('LinkedIn Secret Key'),
227
+ 'name' => 'conf[native][socialNetworking][linkedin][secretKey]',
228
+ 'required' => true,
229
+ 'value' => $linkedinSecretKey
230
+ )
231
+ );
232
+
233
+ $fieldsetLinkedin->addField(
234
+ 'linkedinNote',
235
+ 'note',
236
+ array(
237
+ 'text' => sprintf(
238
+ $noteText,
239
+ Mage::getStoreConfig(Mage_XmlConnect_Model_Application::XML_PATH_HOWTO_LINKEDIN_URL)
240
+ ),
241
+ )
242
+ );
243
+
244
+ /**
245
+ * Set field dependencies
246
+ */
247
+ $this->setChild('form_after', $this->getLayout()
248
+ ->createBlock('adminhtml/widget_form_element_dependence')
249
+ /**
250
+ * Facebook field dependencies
251
+ */
252
+ ->addFieldMap($facebookActiveField->getHtmlId(), $facebookActiveField->getName())
253
+ ->addFieldMap($facebookAppIDField->getHtmlId(), $facebookAppIDField->getName())
254
+ ->addFieldDependence(
255
+ $facebookAppIDField->getName(),
256
+ $facebookActiveField->getName(),
257
+ 1)
258
+ /**
259
+ * Twitter field dependencies
260
+ */
261
+ ->addFieldMap($twitterApiKeyField->getHtmlId(), $twitterApiKeyField->getName())
262
+ ->addFieldMap($twitterActiveField->getHtmlId(), $twitterActiveField->getName())
263
+ ->addFieldMap($twitterSecretKeyField->getHtmlId(), $twitterSecretKeyField->getName())
264
+ ->addFieldDependence(
265
+ $twitterApiKeyField->getName(),
266
+ $twitterActiveField->getName(),
267
+ 1)
268
+ ->addFieldDependence(
269
+ $twitterSecretKeyField->getName(),
270
+ $twitterActiveField->getName(),
271
+ 1)
272
+ /**
273
+ * LinkedIn field dependencies
274
+ */
275
+ ->addFieldMap($linkedinApiKeyField->getHtmlId(), $linkedinApiKeyField->getName())
276
+ ->addFieldMap($linkedinActiveField->getHtmlId(), $linkedinActiveField->getName())
277
+ ->addFieldMap($linkedinSecretKeyField->getHtmlId(), $linkedinSecretKeyField->getName())
278
+ ->addFieldDependence(
279
+ $linkedinApiKeyField->getName(),
280
+ $linkedinActiveField->getName(),
281
+ 1)
282
+ ->addFieldDependence(
283
+ $linkedinSecretKeyField->getName(),
284
+ $linkedinActiveField->getName(),
285
+ 1)
286
+ );
287
+
288
+ return parent::_prepareForm();
289
+ }
290
+
291
+ /**
292
+ * Tab label getter
293
+ *
294
+ * @return string
295
+ */
296
+ public function getTabLabel()
297
+ {
298
+ return $this->__('Social Networking');
299
+ }
300
+
301
+ /**
302
+ * Tab title getter
303
+ *
304
+ * @return string
305
+ */
306
+ public function getTabTitle()
307
+ {
308
+ return $this->__('Social Networking');
309
+ }
310
+
311
+ /**
312
+ * Check if tab can be shown
313
+ *
314
+ * @return bool
315
+ */
316
+ public function canShowTab()
317
+ {
318
+ return (bool) !Mage::getSingleton('adminhtml/session')->getNewApplication();
319
+ }
320
+
321
+ /**
322
+ * Check if tab hidden
323
+ *
324
+ * @return bool
325
+ */
326
+ public function isHidden()
327
+ {
328
+ return false;
329
+ }
330
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Submission/History.php ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect application history grid
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Submission_History
35
+ extends Mage_Adminhtml_Block_Widget_Grid
36
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
37
+ {
38
+ /**
39
+ * Set order by column and order direction
40
+ * Set grid ID
41
+ * Set use AJAX for grid
42
+ *
43
+ */
44
+ public function __construct()
45
+ {
46
+ parent::__construct();
47
+ $this->setId('history_grid');
48
+ $this->setDefaultSort('created_at');
49
+ $this->setDefaultDir('ASC');
50
+ $this->setUseAjax(true);
51
+ $this->setSaveParametersInSession(true);
52
+ $this->setVarNameFilter('history_filter');
53
+ }
54
+
55
+ /**
56
+ * Tab label getter
57
+ *
58
+ * @return string
59
+ */
60
+ public function getTabLabel()
61
+ {
62
+ return $this->__('Submission History');
63
+ }
64
+
65
+ /**
66
+ * Tab title getter
67
+ *
68
+ * @return string
69
+ */
70
+ public function getTabTitle()
71
+ {
72
+ return $this->__('Submission History');
73
+ }
74
+
75
+ /**
76
+ * Check if tab can be shown
77
+ *
78
+ * @return bool
79
+ */
80
+ public function canShowTab()
81
+ {
82
+ return (bool) !Mage::getSingleton('adminhtml/session')->getNewApplication();
83
+ }
84
+
85
+ /**
86
+ * Check if tab hidden
87
+ *
88
+ * @return bool
89
+ */
90
+ public function isHidden()
91
+ {
92
+ return false;
93
+ }
94
+
95
+ /**
96
+ * Initialize history collection
97
+ * Set application filter
98
+ *
99
+ * @return Mage_Adminhtml_Block_Widget_Grid
100
+ */
101
+ protected function _prepareCollection()
102
+ {
103
+ $collection = Mage::getResourceModel('xmlconnect/history_collection')
104
+ ->addApplicationFilter($this->_getApplication()->getId());
105
+ $this->setCollection($collection);
106
+ return parent::_prepareCollection();
107
+ }
108
+
109
+ /**
110
+ * Configuration of grid
111
+ *
112
+ * @return Mage_Adminhtml_Block_Widget_Grid
113
+ */
114
+ protected function _prepareColumns()
115
+ {
116
+ $this->addColumn('activation_key', array(
117
+ 'header' => $this->__('Activation Key'),
118
+ 'align' => 'left',
119
+ 'index' => 'activation_key',
120
+ 'type' => 'text',
121
+ 'escape' => true
122
+ ));
123
+
124
+ $this->addColumn('created_at', array(
125
+ 'header' => $this->__('Date Submitted'),
126
+ 'align' => 'left',
127
+ 'index' => 'created_at',
128
+ 'type' => 'datetime'
129
+ ));
130
+
131
+ return parent::_prepareColumns();
132
+ }
133
+
134
+ /**
135
+ * Ajax grid URL getter
136
+ * @return string
137
+ */
138
+ public function getGridUrl()
139
+ {
140
+ return $this->getUrl('*/*/submissionHistoryGrid', array('_current'=>true));
141
+ }
142
+
143
+ /**
144
+ * Get current application model
145
+ *
146
+ * @return Mage_XmlConnect_Model_Application
147
+ */
148
+ protected function _getApplication()
149
+ {
150
+ return Mage::helper('xmlconnect')->getApplication();
151
+ }
152
+
153
+ /**
154
+ * Remove row click url
155
+ *
156
+ * @param Mage_Catalog_Model_Product|Varien_Object $row
157
+ * @return string
158
+ */
159
+ public function getRowUrl($row)
160
+ {
161
+ return '';
162
+ }
163
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tabs.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Application Tabs block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tabs
35
+ extends Mage_Adminhtml_Block_Widget_Tabs
36
+ {
37
+ /**
38
+ * Constructor
39
+ * Setting grid_id, DOM destination element id, Title
40
+ */
41
+ public function __construct()
42
+ {
43
+ parent::__construct();
44
+ $this->setId('mobile_app_tabs');
45
+ $this->setDestElementId('edit_form');
46
+ $this->setTitle($this->__('Manage Mobile App'));
47
+ }
48
+
49
+ /**
50
+ * Preparing global layout
51
+ *
52
+ * @return Mage_Core_Block_Abstract
53
+ */
54
+ protected function _prepareLayout()
55
+ {
56
+ if (Mage::getSingleton('adminhtml/session')->getNewApplication()) {
57
+ $this->addTab('set', array(
58
+ 'label' => $this->__('Settings'),
59
+ 'content' => $this->getLayout()
60
+ ->createBlock('xmlconnect/adminhtml_mobile_edit_tab_settings')
61
+ ->toHtml(),
62
+ 'active' => true
63
+ ));
64
+ }
65
+ return parent::_prepareLayout();
66
+ }
67
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Addrow.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Xmlconnect Add row form element
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Addrow
35
+ extends Varien_Data_Form_Element_Button
36
+ {
37
+ /**
38
+ * Render Element Html
39
+ *
40
+ * @return string
41
+ */
42
+ public function getElementHtml()
43
+ {
44
+ $html = $this->getBeforeElementHtml()
45
+ . '<button id="'.$this->getHtmlId()
46
+ . '" name="'
47
+ . $this->getName()
48
+ . '" value="'.$this->getEscapedValue()
49
+ . '" '
50
+ . $this->serialize($this->getHtmlAttributes())
51
+ . ' ><span>'
52
+ . $this->getEscapedValue()
53
+ . '</span></button>'
54
+ . $this->getAfterElementHtml();
55
+ return $html;
56
+ }
57
+
58
+ /**
59
+ * Getter for "before_element_html"
60
+ *
61
+ * @return string
62
+ */
63
+ public function getBeforeElementHtml()
64
+ {
65
+ return $this->getData('before_element_html');
66
+ }
67
+
68
+ /**
69
+ * Return label html code
70
+ *
71
+ * @param string $idSuffix
72
+ * @return string
73
+ */
74
+ public function getLabelHtml($idSuffix = '')
75
+ {
76
+ if ($this->getLabel() !== null) {
77
+ $html = '<label for="' . $this->getHtmlId() . $idSuffix . '">'
78
+ . $this->getLabel()
79
+ . ($this->getRequired() ? ' <span class="required">*</span>' : '')
80
+ . '</label>';
81
+ } else {
82
+ $html = '';
83
+ }
84
+ return $html;
85
+ }
86
+
87
+ /**
88
+ * Overriding toHtml parent method
89
+ * Adding addrow Block to element renderer
90
+ *
91
+ * @return string
92
+ */
93
+ public function toHtml()
94
+ {
95
+ $blockClassName = Mage::getConfig()->getBlockClassName('adminhtml/template');
96
+ $jsBlock = new $blockClassName;
97
+ $jsBlock->setTemplate('xmlconnect/form/element/addrow.phtml');
98
+ $jsBlock->setOptions($this->getOptions());
99
+ return parent::toHtml() . $jsBlock->toHtml();
100
+ }
101
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Color.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Xmlconnect color form element
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Color
35
+ extends Varien_Data_Form_Element_Text
36
+ {
37
+ /**
38
+ * Return html code for current block
39
+ *
40
+ * @return mixed|string
41
+ */
42
+ public function getHtml()
43
+ {
44
+ $this->addClass('color {required:false,hash:true}');
45
+ return parent::getHtml();
46
+ }
47
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Country.php ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect Country selector form element
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Country
35
+ extends Varien_Data_Form_Element_Checkboxes
36
+ {
37
+ /**
38
+ * Flag of using the border in the table's TD
39
+ *
40
+ * @var bool
41
+ */
42
+ protected $_useBorderClass = false;
43
+
44
+ /**
45
+ * Init Element
46
+ *
47
+ * @param array $attributes
48
+ */
49
+ public function __construct($attributes=array())
50
+ {
51
+ parent::__construct($attributes);
52
+ $this->setType('checkbox');
53
+ $this->setExtType('country');
54
+ }
55
+
56
+ /**
57
+ * Retrieve HTML
58
+ *
59
+ * @return string
60
+ */
61
+ public function getElementHtml()
62
+ {
63
+ $values = $this->_prepareValues();
64
+
65
+ if (empty($values)) {
66
+ return '';
67
+ }
68
+
69
+ $columns = (int)$this->getData('columns');
70
+ $columns = $columns ? $columns : 1;
71
+ $rows = ceil(count($values) / $columns);
72
+ $row = $column = 0;
73
+
74
+ $options = array();
75
+
76
+ foreach ($values as $value) {
77
+ if (empty($value['value'])) {
78
+ continue;
79
+ }
80
+ $options[$row++][$column] = $value;
81
+ if ($row == $rows) {
82
+ $row = 0;
83
+ $column++;
84
+ }
85
+ }
86
+
87
+ while ($row < $rows) {
88
+ $options[$row++][$column] = '';
89
+ }
90
+
91
+ $id = $this->getData('id');
92
+ $id = empty($id) ? '' : ' id="' . $id . '-table"';
93
+ $class = $this->getData('class');
94
+ $html = PHP_EOL . "<table class=\"countries {$class}\"{$id}>" . PHP_EOL;
95
+
96
+ $zebrine = '';
97
+ $stripy = false;
98
+ if (strpos($class, 'stripy')) {
99
+ $stripy = true;
100
+ }
101
+
102
+ $columns--;
103
+ foreach ($options as $row) {
104
+ $html .= "<tr{$zebrine}>" . PHP_EOL;
105
+
106
+ if ($stripy) {
107
+ $zebrine = empty($zebrine) ? ' class="odd"' : '';
108
+ $this->_useBorderClass = true;
109
+ foreach ($row as $idx => $option) {
110
+ /**
111
+ * for istore (as shown by $stripy) use border settings in TD
112
+ */
113
+ if ($idx == $columns) {
114
+ /**
115
+ * for last table's column TD should not have a border
116
+ */
117
+ $this->_useBorderClass = false;
118
+ }
119
+ $html .= $this->_optionToHtml($option);
120
+ }
121
+ } else {
122
+ foreach ($row as $option) {
123
+ $html .= $this->_optionToHtml($option);
124
+ }
125
+ }
126
+
127
+ $html .= PHP_EOL . '</tr>' . PHP_EOL;
128
+ }
129
+
130
+ $html .= '</table>'
131
+ . PHP_EOL
132
+ . $this->getAfterElementHtml();
133
+
134
+ return $html;
135
+ }
136
+
137
+ /**
138
+ * Get HTML code for the one option
139
+ *
140
+ * @param array $option
141
+ * @return string
142
+ */
143
+ protected function _optionToHtml($option)
144
+ {
145
+ if (empty($option)) {
146
+ $html = '<td>&nbsp;</td><td>&nbsp;</td>';
147
+ } else {
148
+ $id = $this->getHtmlId() . '_' . $this->_escape($option['value']);
149
+ $isNameLeft = $this->getData('place_name_left');
150
+
151
+ $border = $this->_useBorderClass ? ' class="border"' : '';
152
+ $html = '<td' . $border . '><input id="' . $id . '"';
153
+ foreach ($this->getHtmlAttributes() as $attribute) {
154
+ $value = $this->getDataUsingMethod($attribute, $option['value']);
155
+ if ($value) {
156
+ $html .= ' ' . $attribute . '="' . $value . '"';
157
+ }
158
+ }
159
+ $html .= ' value="' . $option['value'] . '" /></td>';
160
+
161
+ $label = '<td><label for="' . $id . '" style="white-space: nowrap;">' . $option['label'] . '</label></td>';
162
+
163
+ if ($isNameLeft) {
164
+ $html = $label . $html;
165
+ } else {
166
+ $html = $html . $label;
167
+ }
168
+ }
169
+
170
+ return $html;
171
+ }
172
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Datetime.php ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect data selector form element
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Datetime
35
+ extends Varien_Data_Form_Element_Abstract
36
+ {
37
+ /**
38
+ * Date
39
+ *
40
+ * @var Zend_Date
41
+ */
42
+ protected $_value;
43
+
44
+ public function __construct($attributes=array())
45
+ {
46
+ parent::__construct($attributes);
47
+ $this->setType('text');
48
+ $this->setExtType('textfield');
49
+ if (isset($attributes['value'])) {
50
+ $this->setValue($attributes['value']);
51
+ }
52
+ }
53
+
54
+ /**
55
+ * If script executes on x64 system, converts large
56
+ * numeric values to timestamp limit
57
+ *
58
+ * @param int $value
59
+ * @return int
60
+ */
61
+ protected function _toTimestamp($value)
62
+ {
63
+ $value = (int)$value;
64
+ if ($value > 3155760000) {
65
+ $value = 0;
66
+ }
67
+ return $value;
68
+ }
69
+
70
+ /**
71
+ * Set date value
72
+ * If Zend_Date instance is provided instead of value, other params will be ignored.
73
+ * Format and locale must be compatible with Zend_Date
74
+ *
75
+ * @param mixed $value
76
+ * @param string $format
77
+ * @param string $locale
78
+ * @return Varien_Data_Form_Element_Date
79
+ */
80
+ public function setValue($value, $format = null, $locale = null)
81
+ {
82
+ if (empty($value)) {
83
+ $this->_value = '';
84
+ return $this;
85
+ }
86
+ if ($value instanceof Zend_Date) {
87
+ $this->_value = $value;
88
+ return $this;
89
+ }
90
+ if (preg_match('/^[0-9]+$/', $value)) {
91
+ $this->_value = new Zend_Date($this->_toTimestamp($value));
92
+ //$this->_value = new Zend_Date((int)value);
93
+ return $this;
94
+ }
95
+ // last check, if input format was set
96
+ if (null === $format) {
97
+ $format = Varien_Date::DATETIME_INTERNAL_FORMAT;
98
+ if ($this->getInputFormat()) {
99
+ $format = $this->getInputFormat();
100
+ }
101
+ }
102
+ // last check, if locale was set
103
+ if (null === $locale) {
104
+ if (!$locale = $this->getLocale()) {
105
+ $locale = null;
106
+ }
107
+ }
108
+ try {
109
+ $this->_value = new Zend_Date($value, $format, $locale);
110
+ } catch (Exception $e) {
111
+ $this->_value = '';
112
+ }
113
+ return $this;
114
+ }
115
+
116
+ /**
117
+ * Get date value as string.
118
+ * Format can be specified, or it will be taken from $this->getFormat()
119
+ *
120
+ * @param string $format (compatible with Zend_Date)
121
+ * @return string
122
+ */
123
+ public function getValue($format = null)
124
+ {
125
+ if (empty($this->_value)) {
126
+ return '';
127
+ }
128
+ if (null === $format) {
129
+ $format = $this->getFormat() . " " . $this->getFormatT();
130
+ }
131
+ return $this->_value->toString($format);
132
+ }
133
+
134
+ /**
135
+ * Get value instance, if any
136
+ *
137
+ * @return Zend_Date
138
+ */
139
+ public function getValueInstance()
140
+ {
141
+ if (empty($this->_value)) {
142
+ return null;
143
+ }
144
+ return $this->_value;
145
+ }
146
+
147
+ /**
148
+ * Output the input field and assign calendar instance to it.
149
+ * In order to output the date:
150
+ * - the value must be instantiated (Zend_Date)
151
+ * - output format must be set (compatible with Zend_Date)
152
+ *
153
+ * @return string
154
+ */
155
+ public function getElementHtml()
156
+ {
157
+ $this->addClass('input-text');
158
+
159
+ $html = sprintf(
160
+ '<input name="%s" id="%s" value="%s" %s style="width:110px !important;" />'
161
+ .' <img src="%s" alt="" class="v-middle" id="%s_trig" title="%s" style="%s" />',
162
+ $this->getName(),
163
+ $this->getHtmlId(),
164
+ $this->_escape($this->getValue()),
165
+ $this->serialize($this->getHtmlAttributes()),
166
+ $this->getImage(),
167
+ $this->getHtmlId(),
168
+ 'Select Date',
169
+ ($this->getDisabled() ? 'display:none;' : '')
170
+ );
171
+ $outputFormat = $this->getFormat();
172
+ $outputTimeFormat = $this->getFormatT();
173
+ if (empty($outputFormat)) {
174
+ Mage::throwException(
175
+ $this->__('Output format is not specified. Please, specify "format" key in constructor, or set it using setFormat().')
176
+ );
177
+ }
178
+ $displayFormat = Varien_Date::convertZendToStrFtime($outputFormat, true, false);
179
+ $displayTimeFormat = Varien_Date::convertZendToStrFtime($outputTimeFormat, false, true);
180
+
181
+ $html .= sprintf('
182
+ <script type="text/javascript">
183
+ //<![CDATA[
184
+ Calendar.setup({
185
+ inputField: "%s",
186
+ ifFormat: "%s",
187
+ showsTime: %s,
188
+ button: "%s_trig",
189
+ align: "Bl",
190
+ singleClick : false,
191
+ timeFormat: 12
192
+ });
193
+ //]]>
194
+ </script>',
195
+ $this->getHtmlId(),
196
+ $displayFormat . " " . $displayTimeFormat,
197
+ $this->getTime() ? 'true' : 'false',
198
+ $this->getHtmlId()
199
+ );
200
+
201
+ $html .= $this->getAfterElementHtml();
202
+
203
+ return $html;
204
+ }
205
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Font.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect font form element
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Font
35
+ extends Varien_Data_Form_Element_Abstract
36
+ {
37
+ /**
38
+ * Init font element
39
+ *
40
+ * @param array $attributes
41
+ */
42
+ public function __construct($attributes=array())
43
+ {
44
+ parent::__construct($attributes);
45
+ $this->setType('font');
46
+ }
47
+
48
+ /**
49
+ * Setting stored data to Font element
50
+ *
51
+ * @param array $conf
52
+ */
53
+ public function initFields($conf)
54
+ {
55
+ $name = $conf['name'];
56
+
57
+ $this->addElement(new Varien_Data_Form_Element_Select(array(
58
+ 'name' => $name . '[name]',
59
+ 'values' => $conf['fontNames'],
60
+ 'style' => 'width: 206px; margin: 0',
61
+ )));
62
+
63
+ $this->addElement(new Varien_Data_Form_Element_Select(array(
64
+ 'name' => $name . '[size]',
65
+ 'values' => $conf['fontSizes'],
66
+ 'style' => 'width: 70px; margin: 0',
67
+ )));
68
+
69
+ $this->addElement(new Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Color(array(
70
+ 'name' => $name . '[color]',
71
+ 'style' => 'width: 60px; margin: 0'
72
+ )));
73
+ }
74
+
75
+ /**
76
+ * Add form element
77
+ *
78
+ * @param Varien_Data_Form_Element_Abstract $element
79
+ * @param bool|string $after also can be '^'
80
+ * @return Varien_Data_Form
81
+ */
82
+ public function addElement(Varien_Data_Form_Element_Abstract $element, $after = false)
83
+ {
84
+ $element->setId($element->getData('name'));
85
+ $element->setNoSpan(true);
86
+ parent::addElement($element, $after);
87
+ }
88
+
89
+ /**
90
+ * Get Rendered Element Html
91
+ *
92
+ * @return string
93
+ */
94
+ public function getElementHtml()
95
+ {
96
+ $elementsArray = array();
97
+ foreach ($this->getElements() as $element) {
98
+ $elementsArray[] .= $element->toHtml();
99
+ }
100
+ return $elementsArray[0]
101
+ . $elementsArray[1]
102
+ . '</td><td class="label" style="width: 2em !important">'
103
+ . $elementsArray[2];
104
+ }
105
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Image.php ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect image form element
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Image
35
+ extends Varien_Data_Form_Element_Image
36
+ {
37
+ /**
38
+ * Function fetches image Url actual or default
39
+ *
40
+ * @return string
41
+ */
42
+ protected function _getUrl()
43
+ {
44
+ if ($this->getValue()) {
45
+ if (strpos($this->getValue(), '://') === false) {
46
+ $url = Mage::helper('xmlconnect/image')->getFileDefaultSizeSuffixAsUrl($this->getValue());
47
+ $url = Mage::helper('xmlconnect/image')->getMediaUrl($url);
48
+ } else {
49
+ $url = $this->getValue();
50
+ }
51
+ } else {
52
+ $url = $this->getDefaultValue();
53
+ }
54
+ return $url;
55
+ }
56
+
57
+ /**
58
+ * Get "clear" filename from element
59
+ *
60
+ * @return string
61
+ */
62
+ public function getUploadName()
63
+ {
64
+ /**
65
+ * Ugly hack to avoid $_FILES[..]['name'][..][..]
66
+ */
67
+ $name = $this->getName();
68
+ $name = strtr($name, array('[' => '/', ']' => ''));
69
+ return $name;
70
+ }
71
+
72
+ /**
73
+ * Compose output html for element
74
+ *
75
+ * @return string
76
+ */
77
+ public function getElementHtml()
78
+ {
79
+ $html = '<div style="white-space: nowrap">';
80
+
81
+ $url = $this->_getUrl();
82
+ $html .= '<a href="' . $url . '" onclick="imagePreview(\'' . $this->getHtmlId() . '_image\'); return false;">';
83
+ $html .= '<img src="' . $url . '" id="' . $this->getHtmlId() . '_image"';
84
+ $html .= ' alt="" height="22" width="22" class="small-image-preview v-middle" /></a> ';
85
+
86
+ $html .= '<input id="' . $this->getHtmlId() . '_hidden" name="' . $this->getName();
87
+ $html .= '" value="' . $this->getEscapedValue() . '" type="hidden" />';
88
+
89
+ $this->setClass('input-file');
90
+ $html .= '<input id="' . $this->getHtmlId() . '" name="' . $this->getUploadName();
91
+ $attr = $this->serialize($this->getHtmlAttributes());
92
+ $html .= '" value="' . $this->getEscapedValue() . '" ' . $attr . '/>' . PHP_EOL;
93
+ $html .= $this->getAfterElementHtml();
94
+
95
+ $html .= '</div>';
96
+
97
+ return $html;
98
+ }
99
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Page.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect page form element
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Page
35
+ extends Varien_Data_Form_Element_Abstract
36
+ {
37
+ /**
38
+ * Init page element
39
+ *
40
+ * @param array $attributes
41
+ */
42
+ public function __construct($attributes=array())
43
+ {
44
+ parent::__construct($attributes);
45
+ $this->setType('page');
46
+ }
47
+
48
+ /**
49
+ * Setting stored data to page element
50
+ *
51
+ * @param array $conf
52
+ */
53
+ public function initFields($conf)
54
+ {
55
+ $this->addElement(new Varien_Data_Form_Element_Text(array(
56
+ 'name' => $conf['name'] . '[label]',
57
+ 'class' => 'label onclick_text',
58
+ )));
59
+
60
+ $this->addElement(new Varien_Data_Form_Element_Select(array(
61
+ 'name' => $conf['name'] . '[id]',
62
+ 'values' => $conf['values'],
63
+ )));
64
+ }
65
+
66
+ /**
67
+ * Add form element
68
+ *
69
+ * @param Varien_Data_Form_Element_Abstract $element
70
+ * @param boolean|string $after also can be '^'
71
+ * @return Varien_Data_Form
72
+ */
73
+ public function addElement(Varien_Data_Form_Element_Abstract $element, $after = false)
74
+ {
75
+ $element->setId($element->getData('name'));
76
+ parent::addElement($element, $after);
77
+ }
78
+
79
+ /**
80
+ * Getter for Label field
81
+ * fetching first element as label
82
+ *
83
+ * @param string $idSuffix
84
+ * @return string
85
+ */
86
+ public function getLabelHtml($idSuffix = '')
87
+ {
88
+ list($label, $element) = $this->getElements();
89
+ return $label->toHtml();
90
+ }
91
+
92
+ /**
93
+ * Getter for second part of rendered field ("selectbox" and "delete button")
94
+ * fetching second element as <element code>
95
+ *
96
+ * @return string
97
+ */
98
+ public function getElementHtml()
99
+ {
100
+ list($label, $element) = $this->getElements();
101
+ return $element->toHtml()
102
+ . '</td><td class="label" style="width: 5em">'
103
+ . '<button class=" scalable save onclick_button" value="&minus;"><span>'
104
+ . Mage::helper('xmlconnect')->__('Delete')
105
+ . '</span></button>';
106
+ }
107
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Tabs.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect tabs form element
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Tabs
35
+ extends Varien_Data_Form_Element_Text
36
+ {
37
+ /**
38
+ * Generate application tabs html
39
+ *
40
+ * @return string
41
+ */
42
+ public function getHtml()
43
+ {
44
+ if ((bool)Mage::getSingleton('adminhtml/session')->getNewApplication()) {
45
+ return '';
46
+ }
47
+
48
+ $blockClassName = Mage::getConfig()->getBlockClassName('adminhtml/template');
49
+ $block = new $blockClassName;
50
+ $device = Mage::helper('xmlconnect')->getDeviceType();
51
+ if (array_key_exists($device, Mage::helper('xmlconnect')->getSupportedDevices())) {
52
+ $template = 'xmlconnect/form/element/app_tabs_' . strtolower($device) . '.phtml';
53
+ } else {
54
+ Mage::throwException(
55
+ $this->__('Device doesn\'t recognized. Unable to load a template.')
56
+ );
57
+ }
58
+
59
+ $block->setTemplate($template);
60
+ $tabs = Mage::getModel('xmlconnect/tabs', $this->getValue());
61
+ $block->setTabs($tabs);
62
+ $block->setName($this->getName());
63
+ return $block->toHtml();
64
+ }
65
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Theme.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect theme form element
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Theme
35
+ extends Varien_Data_Form_Element_Text
36
+ {
37
+ /**
38
+ * Generate themes (colors) html
39
+ *
40
+ * @return string
41
+ */
42
+ public function getHtml()
43
+ {
44
+ $blockClassName = Mage::getConfig()
45
+ ->getBlockClassName('xmlconnect/adminhtml_mobile_edit_tab_design_themes');
46
+ $block = new $blockClassName;
47
+ $block->setThemes($this->getThemes());
48
+ $block->setName($this->getName());
49
+ $block->setValue($this->getValue());
50
+ return $block->toHtml();
51
+ }
52
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Application grid block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Xmlconnect_Block_Adminhtml_Mobile_Grid extends Mage_Adminhtml_Block_Widget_Grid
35
+ {
36
+ /**
37
+ * Class constructor
38
+ */
39
+ public function __construct()
40
+ {
41
+ parent::__construct();
42
+ $this->setId('mobile_apps_grid');
43
+ $this->setDefaultSort('application_id');
44
+ $this->setDefaultDir('ASC');
45
+ }
46
+
47
+ /**
48
+ * Initialize grid data collection
49
+ *
50
+ * @return Mage_Adminhtml_Block_Widget_Grid
51
+ */
52
+ protected function _prepareCollection()
53
+ {
54
+ $collection = Mage::getModel('xmlconnect/application')->getCollection();
55
+ $this->setCollection($collection);
56
+ return parent::_prepareCollection();
57
+ }
58
+
59
+ /**
60
+ * Declare grid columns
61
+ *
62
+ * @return Mage_Adminhtml_Block_Widget_Grid
63
+ */
64
+ protected function _prepareColumns()
65
+ {
66
+ $this->addColumn('name', array(
67
+ 'header' => $this->__('App Name'),
68
+ 'align' => 'left',
69
+ 'index' => 'name',
70
+ ));
71
+
72
+ $this->addColumn('code', array(
73
+ 'header' => $this->__('App Code'),
74
+ 'align' => 'left',
75
+ 'index' => 'code',
76
+ 'width' => '200',
77
+ ));
78
+
79
+ if (!Mage::app()->isSingleStoreMode()) {
80
+ $this->addColumn('store_id', array(
81
+ 'header' => $this->__('Store View'),
82
+ 'index' => 'store_id',
83
+ 'type' => 'store',
84
+ 'store_view' => true,
85
+ 'sortable' => false,
86
+ 'width' => '250',
87
+ ));
88
+ }
89
+
90
+ $this->addColumn('type', array(
91
+ 'header' => $this->__('Device'),
92
+ 'type' => 'text',
93
+ 'index' => 'type',
94
+ 'align' => 'center',
95
+ 'filter' => 'adminhtml/widget_grid_column_filter_select',
96
+ 'options' => Mage::helper('xmlconnect')->getSupportedDevices(),
97
+ 'renderer' => 'xmlconnect/adminhtml_mobile_grid_renderer_type',
98
+ ));
99
+
100
+ $this->addColumn('status', array(
101
+ 'header' => $this->__('Status'),
102
+ 'index' => 'status',
103
+ 'renderer' => 'xmlconnect/adminhtml_mobile_grid_renderer_bool',
104
+ 'align' => 'center',
105
+ 'filter' => 'adminhtml/widget_grid_column_filter_select',
106
+ 'options' => Mage::helper('xmlconnect')->getStatusOptions(),
107
+
108
+ ));
109
+
110
+ return parent::_prepareColumns();
111
+ }
112
+
113
+ /**
114
+ * Row click url
115
+ *
116
+ * @param Mage_Catalog_Model_Product|Varien_Object $row
117
+ * @return string
118
+ */
119
+ public function getRowUrl($row)
120
+ {
121
+ return $this->getUrl('*/*/edit', array('application_id' => $row->getId()));
122
+ }
123
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid/Renderer/Bool.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect status field grid renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Grid_Renderer_Bool
35
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
36
+ {
37
+ /**
38
+ * Render application status image
39
+ *
40
+ * @param Varien_Object $row
41
+ * @return string
42
+ */
43
+ public function render(Varien_Object $row)
44
+ {
45
+ $result = '';
46
+ $status = (int) $row->getData($this->getColumn()->getIndex());
47
+ $options = Mage::helper('xmlconnect')->getStatusOptions();
48
+ if ($status == Mage_XmlConnect_Model_Application::APP_STATUS_SUCCESS) {
49
+ $result = '<img src="'
50
+ . Mage::helper('xmlconnect/image')->getSkinImagesUrl('gel_green.png')
51
+ . '" >&nbsp;'
52
+ . (isset($options[$status]) ? $options[$status] : '');
53
+ } else if ($status == Mage_XmlConnect_Model_Application::APP_STATUS_INACTIVE) {
54
+ $result = '<img src="'
55
+ . Mage::helper('xmlconnect/image')->getSkinImagesUrl('gel_red.png')
56
+ . '" >&nbsp;'
57
+ . (isset($options[$status]) ? $options[$status] : '');
58
+ }
59
+ return $result;
60
+ }
61
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid/Renderer/Type.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Adminhtml catalog super product link grid checkbox renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Grid_Renderer_Type
35
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
36
+ {
37
+ /**
38
+ * Renders grid column
39
+ *
40
+ * @param Varien_Object $row
41
+ * @return string
42
+ */
43
+ public function render(Varien_Object $row)
44
+ {
45
+ $type = $row->getData($this->getColumn()->getIndex());
46
+ $devices = Mage::helper('xmlconnect')->getSupportedDevices();
47
+ if (isset($devices[$type])) {
48
+ return $devices[$type];
49
+ } else {
50
+ return $type;
51
+ }
52
+ }
53
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Preview/Content.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect preview content block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Preview_Content
35
+ extends Mage_Adminhtml_Block_Template
36
+ {
37
+ /**
38
+ * Set path to template used for generating block's output.
39
+ *
40
+ * @param string $templateType
41
+ * @return Mage_XmlConnect_Block_Adminhtml_Mobile_Preview_Content
42
+ */
43
+ public function setTemplate($templateType)
44
+ {
45
+ $deviceType = Mage::helper('xmlconnect')->getDeviceType();
46
+ parent::setTemplate(
47
+ 'xmlconnect/edit/tab/design/preview/'
48
+ . $templateType
49
+ . '_'
50
+ . $deviceType
51
+ . '.phtml'
52
+ );
53
+ return $this;
54
+ }
55
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Preview/Tabitems.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect Tab items block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Preview_Tabitems
35
+ extends Mage_Adminhtml_Block_Template
36
+ {
37
+ /**
38
+ * Set preview tab items template
39
+ */
40
+ public function __construct()
41
+ {
42
+ parent::__construct();
43
+
44
+ $deviceType = Mage::helper('xmlconnect')->getDeviceType();
45
+ $this->setTemplate(
46
+ 'xmlconnect/edit/tab/design/preview/tab_items_'
47
+ . $deviceType
48
+ . '.phtml'
49
+ );
50
+ }
51
+
52
+ /**
53
+ * Set active tab
54
+ *
55
+ * @param string $tab
56
+ * @return Mage_XmlConnect_Block_Adminhtml_Mobile_Preview_Tabitems
57
+ */
58
+ public function setActiveTab($tab)
59
+ {
60
+ Mage::helper('xmlconnect')->getPreviewModel()->setActiveTab($tab);
61
+ return $this;
62
+ }
63
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission.php ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Application submission block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Submission
35
+ extends Mage_Adminhtml_Block_Widget_Form_Container
36
+ {
37
+ /**
38
+ * Setting buttons for submit application page
39
+ */
40
+ public function __construct()
41
+ {
42
+ $this->_objectId = 'application_id';
43
+ $this->_controller = 'adminhtml_mobile';
44
+ $this->_blockGroup = 'xmlconnect';
45
+ $this->_mode = 'submission';
46
+ parent::__construct();
47
+
48
+ $this->removeButton('delete');
49
+ $this->removeButton('save');
50
+ $this->removeButton('reset');
51
+
52
+ $app = Mage::helper('xmlconnect')->getApplication();
53
+ if ($app && $app->getIsResubmitAction()) {
54
+ $label = $this->__('Resubmit App');
55
+ } else {
56
+ $label = $this->__('Submit App');
57
+ }
58
+
59
+ $this->_addButton('submission_post', array(
60
+ 'class' => 'save',
61
+ 'label' => $label,
62
+ 'onclick' => "submitApplication()",
63
+ ));
64
+
65
+ $this->_updateButton('back', 'label', $this->__('Back to App Edit'));
66
+ $this->_updateButton(
67
+ 'back',
68
+ 'onclick',
69
+ 'setLocation(\'' . $this->getUrl('*/*/edit', array('application_id' => $app->getId())) . '\')'
70
+ );
71
+ }
72
+
73
+ /**
74
+ * Adding styles to block
75
+ *
76
+ * @throws Mage_Core_Exception
77
+ * @return Mage_Adminhtml_Block_Widget_Form_Container
78
+ */
79
+ protected function _prepareLayout()
80
+ {
81
+ $this->getLayout()->getBlock('head')->addJs('jscolor/jscolor.js');
82
+ $this->getLayout()->getBlock('head')->addJs('scriptaculous/scriptaculous.js');
83
+
84
+
85
+ $deviceType = Mage::helper('xmlconnect')->getDeviceType();
86
+ switch ($deviceType) {
87
+ case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPHONE:
88
+ $this->getLayout()->getBlock('head')->addItem('skin_css', 'xmlconnect/mobile-home.css');
89
+ $this->getLayout()->getBlock('head')->addItem('skin_css', 'xmlconnect/mobile-catalog.css');
90
+ break;
91
+ case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPAD:
92
+ $this->getLayout()->getBlock('head')->addItem('skin_css', 'xmlconnect/mobile-ipad-home.css');
93
+ $this->getLayout()->getBlock('head')->addItem('skin_css', 'xmlconnect/mobile-ipad-catalog.css');
94
+ break;
95
+ case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_ANDROID:
96
+ $this->getLayout()->getBlock('head')->addItem('skin_css', 'xmlconnect/mobile-android.css');
97
+ break;
98
+ default:
99
+ Mage::throwException(
100
+ $this->__('Device doesn\'t recognized: "%s". Unable to load preview model.', $deviceType)
101
+ );
102
+ break;
103
+ }
104
+
105
+ return parent::_prepareLayout();
106
+ }
107
+
108
+ /**
109
+ * Get form header title
110
+ *
111
+ * @return string
112
+ */
113
+ public function getHeaderText()
114
+ {
115
+ $app = Mage::helper('xmlconnect')->getApplication();
116
+ if ($app && $app->getId()) {
117
+ return $this->__('Submit App "%s"', $this->htmlEscape($app->getName()));
118
+ }
119
+ return '';
120
+ }
121
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Form.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Device submission form block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Form
35
+ extends Mage_Adminhtml_Block_Widget_Form
36
+ {
37
+ /**
38
+ * Prepare form before rendering HTML
39
+ *
40
+ * @return Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Form
41
+ */
42
+ protected function _prepareForm()
43
+ {
44
+ $form = new Varien_Data_Form(array(
45
+ 'id' => 'edit_form',
46
+ 'action' => $this->getUrl('*/mobile/submission'),
47
+ 'method' => 'post',
48
+ 'enctype' => 'multipart/form-data'
49
+ ));
50
+ $form->setUseContainer(true);
51
+ $this->setForm($form);
52
+ return parent::_prepareForm();
53
+ }
54
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Renderer/Country/Androidmarket.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Country field renderer for Android Market
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Renderer_Country_Androidmarket
35
+ extends Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset_Element
36
+ implements Varien_Data_Form_Element_Renderer_Interface
37
+ {
38
+ /**
39
+ * Override setting the template
40
+ *
41
+ * @return void
42
+ */
43
+ protected function _construct()
44
+ {
45
+ $this->setTemplate('xmlconnect/form/element/country/androidmarket.phtml');
46
+ }
47
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Renderer/Country/Istore.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Country field renderer for iStore
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Renderer_Country_Istore
35
+ extends Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset_Element
36
+ implements Varien_Data_Form_Element_Renderer_Interface
37
+ {
38
+ /**
39
+ * Override setting the template
40
+ *
41
+ * @return void
42
+ */
43
+ protected function _construct()
44
+ {
45
+ $this->setTemplate('xmlconnect/form/element/country/istore.phtml');
46
+ }
47
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tab/Container.php ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Device container block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Tab_Container
35
+ extends Mage_Adminhtml_Block_Template
36
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
37
+ {
38
+ /**
39
+ * Constructor
40
+ * Setting view parameters, template
41
+ */
42
+ public function __construct()
43
+ {
44
+ parent::__construct();
45
+ $this->setShowGlobalIcon(true);
46
+ $this->setTemplate('xmlconnect/submission/container.phtml');
47
+ }
48
+
49
+ /**
50
+ * Prepare label for tab
51
+ *
52
+ * @return string
53
+ */
54
+ public function getTabLabel()
55
+ {
56
+ return $this->__('Submission');
57
+ }
58
+
59
+ /**
60
+ * Prepare title for tab
61
+ *
62
+ * @return string
63
+ */
64
+ public function getTabTitle()
65
+ {
66
+ return $this->__('Submission');
67
+ }
68
+
69
+ /**
70
+ * Returns status flag about this tab can be shown or not
71
+ *
72
+ * @return true
73
+ */
74
+ public function canShowTab()
75
+ {
76
+ return true;
77
+ }
78
+
79
+ /**
80
+ * Returns status flag about this tab hidden or not
81
+ *
82
+ * @return true
83
+ */
84
+ public function isHidden()
85
+ {
86
+ return false;
87
+ }
88
+
89
+ /**
90
+ * Retrive submission action url
91
+ *
92
+ * @return string
93
+ */
94
+ public function getActionUrl()
95
+ {
96
+ $param = array('key' => Mage::helper('xmlconnect')->getApplication()->getId());
97
+ return $this->getUrl('*/*/submissionPost', $param);
98
+ }
99
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tab/Container/Submission.php ADDED
@@ -0,0 +1,389 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Device submission container block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Tab_Container_Submission
35
+ extends Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form
36
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
37
+ {
38
+
39
+ /**
40
+ * Constructor
41
+ * Setting view parameters
42
+ */
43
+ public function __construct()
44
+ {
45
+ parent::__construct();
46
+ $this->setShowGlobalIcon(true);
47
+ }
48
+
49
+ /**
50
+ * Adding preview for images if application was submitted(so we have saved images)
51
+ *
52
+ * @return Mage_Core_Block_Abstract
53
+ */
54
+ protected function _prepareLayout()
55
+ {
56
+ $block = $this->getLayout()->createBlock('adminhtml/template')
57
+ ->setTemplate('xmlconnect/submission/app_icons_preview.phtml')
58
+ ->setImages(Mage::helper('xmlconnect')->getApplication()->getImages());
59
+ $this->setChild('images', $block);
60
+ parent::_prepareLayout();
61
+ }
62
+
63
+ /**
64
+ * Add image uploader to fieldset
65
+ *
66
+ * @param Varien_Data_Form_Element_Fieldset $fieldset
67
+ * @param string $fieldName
68
+ * @param string $title
69
+ * @param string $note
70
+ * @param string $default
71
+ * @param boolean $required
72
+ */
73
+ public function addImage($fieldset, $fieldName, $title, $note = '', $default = '', $required = false)
74
+ {
75
+ $fieldset->addField($fieldName, 'image', array(
76
+ 'name' => $fieldName,
77
+ 'label' => $title,
78
+ 'note' => !empty($note) ? $note : null,
79
+ 'default_value' => $default,
80
+ 'required' => $required,
81
+ ));
82
+ }
83
+
84
+ /**
85
+ * Prepare form before rendering HTML
86
+ *
87
+ * @return Mage_Adminhtml_Block_Widget_Form
88
+ */
89
+ protected function _prepareForm()
90
+ {
91
+ $deviceType = Mage::helper('xmlconnect')->getDeviceType();
92
+ $form = new Varien_Data_Form();
93
+ $this->setForm($form);
94
+ /** @var $app Mage_XmlConnect_Model_Application */
95
+ $app = Mage::helper('xmlconnect')->getApplication();
96
+ $form->setAction($this->getUrl('*/mobile/submission'));
97
+ $isResubmit = $app->getIsResubmitAction();
98
+ $formData = $app->getFormData();
99
+
100
+ $url = Mage::getStoreConfig('xmlconnect/mobile_application/activation_key_url');
101
+ $afterElementHtml = $this->__('In order to submit your app, you need to first purchase a <a href="%s" target="_blank">%s</a> from MagentoCommerce', $url, $this->__('Activation Key'));
102
+ $fieldset = $form->addFieldset('submit_keys', array('legend' => $this->__('Key')));
103
+ $field = $fieldset->addField('conf[submit_text][key]', 'text', array(
104
+ 'name' => 'conf[submit_text][key]',
105
+ 'label' => $this->__('Activation Key'),
106
+ 'value' => isset($formData['conf[submit_text][key]']) ? $formData['conf[submit_text][key]'] : null,
107
+ 'after_element_html' => $afterElementHtml,
108
+ ));
109
+ if (!$isResubmit) {
110
+ $field->setRequired(true);
111
+ } else {
112
+ $field->setDisabled('disabled');
113
+ $fieldset->addField('conf[submit_text][key]_hidden', 'hidden', array(
114
+ 'name' => 'conf[submit_text][key]',
115
+ 'value' => isset($formData['conf[submit_text][key]']) ? $formData['conf[submit_text][key]'] : null,
116
+ ));
117
+ }
118
+
119
+ if ($isResubmit) {
120
+ $url = Mage::getStoreConfig('xmlconnect/mobile_application/resubmission_key_url');
121
+ $rsText = $this->__('Resubmission Key');
122
+ $afterElementHtml = $this->__('In order to resubmit your app, you need to first purchase a <a href="%s" target="_blank">%s</a> from MagentoCommerce', $url, $rsText);
123
+
124
+ if (isset($formData['conf[submit_text][resubmission_activation_key]'])) {
125
+ $rsKeyVal = $formData['conf[submit_text][resubmission_activation_key]'];
126
+ } else {
127
+ $rsKeyVal = null;
128
+ }
129
+
130
+ $fieldset->addField('conf[submit_text][resubmission_activation_key]', 'text', array(
131
+ 'name' => 'conf[submit_text][resubmission_activation_key]',
132
+ 'label' => $this->__('Resubmission Key'),
133
+ 'value' => $rsKeyVal,
134
+ 'required' => true,
135
+ 'after_element_html' => $afterElementHtml,
136
+ ));
137
+ }
138
+
139
+ $fieldset = $form->addFieldset('submit_general', array('legend' => $this->__('Submission Fields')));
140
+
141
+ $fieldset->addField('submission_action', 'hidden', array(
142
+ 'name' => 'submission_action',
143
+ 'value' => '1',
144
+ ));
145
+
146
+ switch ($deviceType) {
147
+ case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPHONE:
148
+ $titleLength = Mage_XmlConnect_Helper_Iphone::SUBMISSION_TITLE_LENGTH;
149
+ $descriptionLength = Mage_XmlConnect_Helper_Iphone::SUBMISSION_DESCRIPTION_LENGTH;
150
+ $descriptionNote = $this->__('Description that appears in the iTunes App Store. %s chars maximum. ', $descriptionLength);
151
+ break;
152
+ case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPAD:
153
+ $titleLength = Mage_XmlConnect_Helper_Ipad::SUBMISSION_TITLE_LENGTH;
154
+ $descriptionLength = Mage_XmlConnect_Helper_Ipad::SUBMISSION_DESCRIPTION_LENGTH;
155
+ $descriptionNote = $this->__('Description that appears in the iTunes App Store. %s chars maximum. ', $descriptionLength);
156
+ break;
157
+ case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_ANDROID:
158
+ $titleLength = Mage_XmlConnect_Helper_Android::SUBMISSION_TITLE_LENGTH;
159
+ $descriptionLength = Mage_XmlConnect_Helper_Android::SUBMISSION_DESCRIPTION_LENGTH;
160
+ $descriptionNote = $this->__('Description that appears in Android Market. %s chars maximum. ', $descriptionLength);
161
+ break;
162
+ }
163
+
164
+ $titleNote = $this->__('Name that appears beneath your app when users install it to their device. We recommend choosing a name that is 10-12 characters and that your customers will recognize. %s chars max.', $titleLength);
165
+
166
+ $fieldset->addField('conf/submit_text/title', 'text', array(
167
+ 'name' => 'conf[submit_text][title]',
168
+ 'label' => $this->__('Title'),
169
+ 'maxlength' => $titleLength,
170
+ 'value' => isset($formData['conf[submit_text][title]']) ? $formData['conf[submit_text][title]'] : null,
171
+ 'note' => $titleNote,
172
+ 'required' => true,
173
+ ));
174
+
175
+ if (isset($formData['conf[submit_text][description]'])) {
176
+ $descrVal = $formData['conf[submit_text][description]'];
177
+ } else {
178
+ $descrVal = null;
179
+ }
180
+
181
+ $field = $fieldset->addField('conf/submit_text/description', 'textarea', array(
182
+ 'name' => 'conf[submit_text][description]',
183
+ 'label' => $this->__('Description'),
184
+ 'maxlength' => $descriptionLength,
185
+ 'value' => $descrVal,
186
+ 'note' => $descriptionNote,
187
+ 'required' => true,
188
+ ));
189
+ $field->setRows(15);
190
+
191
+ $fieldset->addField('conf/submit_text/contact_email', 'text', array(
192
+ 'name' => 'conf[submit_text][email]',
193
+ 'label' => $this->__('Contact Email'),
194
+ 'class' => 'email',
195
+ 'maxlength' => '40',
196
+ 'value' => isset($formData['conf[submit_text][email]']) ? $formData['conf[submit_text][email]'] : null,
197
+ 'note' => $this->__('Administrative contact for this app and for app submission issues.'),
198
+ 'required' => true,
199
+ ));
200
+
201
+ $fieldset->addField('conf/submit_text/price_free_label', 'label', array(
202
+ 'name' => 'conf[submit_text][price_free_label]',
203
+ 'label' => $this->__('Price'),
204
+ 'value' => $this->__('Free'),
205
+ 'maxlength' => '40',
206
+ 'checked' => 'checked',
207
+ 'note' => $this->__('Only free apps are allowed in this version.'),
208
+ ));
209
+
210
+ $fieldset->addField('conf/submit_text/price_free', 'hidden', array(
211
+ 'name' => 'conf[submit_text][price_free]',
212
+ 'value' => '1',
213
+ ));
214
+
215
+ if (isset($formData['conf[submit_text][country]'])) {
216
+ $selected = explode(',', $formData['conf[submit_text][country]']);
217
+ } else {
218
+ $selected = null;
219
+ }
220
+
221
+ $deviceHelper = Mage::helper('xmlconnect')->getDeviceHelper();
222
+ $fieldset->addType('country', 'Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Country');
223
+ $fieldset->addField('conf/submit_text/country', 'country', array(
224
+ 'id' => 'submission-countries',
225
+ 'name' => 'conf[submit_text][country][]',
226
+ 'label' => $deviceHelper->getCountryLabel(),
227
+ 'values' => Mage::helper('xmlconnect')->getCountryOptionsArray(),
228
+ 'value' => $selected,
229
+ 'note' => $this->__('Make this app available in the following territories'),
230
+ 'columns' => $deviceHelper->getCountryColumns(),
231
+ 'place_name_left' => $deviceHelper->isCountryNamePlaceLeft(),
232
+ 'class' => $deviceHelper->getCountryClass(),
233
+ 'required' => true,
234
+ ))
235
+ ->setRenderer($deviceHelper->getCountryRenderer());
236
+
237
+ if (isset($formData['conf[submit_text][copyright]'])) {
238
+ $copyVal = $formData['conf[submit_text][copyright]'];
239
+ } else {
240
+ $copyVal = null;
241
+ }
242
+
243
+ $fieldset->addField('conf/submit_text/copyright', 'text', array(
244
+ 'name' => 'conf[submit_text][copyright]',
245
+ 'label' => $this->__('Copyright'),
246
+ 'maxlength' => '200',
247
+ 'value' => $copyVal,
248
+ 'note' => $this->__('Appears in the info section of your app (example: Copyright 2010 – Your Company, Inc.)'),
249
+ 'required' => true,
250
+ ));
251
+
252
+ if ($deviceType !== Mage_XmlConnect_Helper_Data::DEVICE_TYPE_ANDROID) {
253
+ if (isset($formData['conf[submit_text][keywords]'])) {
254
+ $keyWordsVal = $formData['conf[submit_text][keywords]'];
255
+ } else {
256
+ $keyWordsVal = null;
257
+ }
258
+
259
+ $fieldset->addField('conf/submit_text/keywords', 'text', array(
260
+ 'name' => 'conf[submit_text][keywords]',
261
+ 'label' => $this->__('Keywords'),
262
+ 'maxlength' => '100',
263
+ 'value' => $keyWordsVal,
264
+ 'note' => $this->__('One or more keywords that describe your app. Keywords are matched to users\' searches in the App Store and help return accurate search results. Separate multiple keywords with commas. 100 chars is maximum.'),
265
+ ));
266
+ }
267
+
268
+ $fieldset = $form->addFieldset('submit_icons', array('legend' => $this->__('Icons')));
269
+
270
+ switch ($deviceType) {
271
+ case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPHONE:
272
+ $this->addImage($fieldset, 'conf/submit/icon', $this->__('Large iTunes Icon'),
273
+ $this->__('Large icon that appears in the iTunes App Store. You do not need to apply a gradient or soft edges (this is done automatically by Apple). Required size: 512px x 512px.'), '', true);
274
+
275
+ $this->addImage($fieldset, 'conf/submit/loader_image', $this->__('Loader Splash Screen'),
276
+ $this->__('Image that appears on first screen while your app is loading. Required size: 320px x 460px.'), '', true);
277
+
278
+ $this->addImage($fieldset, 'conf/submit/loader_image_i4', $this->__('Loader Splash Screen <br />(iPhone 4 retina)'),
279
+ $this->__('Image that appears on first screen while your app is loading. Required size: 640px x 920px.'), '', false);
280
+
281
+ $this->addImage($fieldset, 'conf/submit/logo', $this->__('Custom App Icon'),
282
+ $this->__('Icon that will appear on the user’s phone after they download your app. You do not need to apply a gradient or soft edges (this is done automatically by Apple). Recommended size: 57px x 57px at 72 dpi.'), '', true);
283
+
284
+ $this->addImage($fieldset, 'conf/submit/logo_i4', $this->__('Custom App Icon <br />(iPhone 4 retina)'),
285
+ $this->__('Icon that will appear on the user\'s phone after they download your app. You do not need to apply a gradient or soft edges (this is done automatically by Apple). Recommended size: 114px x 114px.'), '', false);
286
+
287
+ $this->addImage($fieldset, 'conf/submit/big_logo', $this->__('Copyright Page Logo'),
288
+ $this->__('Store logo that is displayed on copyright page of app. Preferred size: 100px x 100px.'), '', true);
289
+
290
+ $this->addImage($fieldset, 'conf/submit/big_logo_i4', $this->__('Copyright Page Logo <br />(iPhone 4 retina)'),
291
+ $this->__('Store logo that is displayed on copyright page of app. Preferred size: 200px x 200px.'), '', false);
292
+ break;
293
+ case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPAD:
294
+ $this->addImage($fieldset, 'conf/submit/icon', $this->__('Large iTunes Icon'),
295
+ $this->__('Large icon that appears in the iTunes App Store. You do not need to apply a gradient or soft edges (this is done automatically by Apple). Required size: 512px x 512px.'), '', true);
296
+
297
+ $this->addImage($fieldset, 'conf/submit/ipad_loader_portrait_image', $this->__('Loader Splash Screen <br />(portrait mode)'),
298
+ $this->__('Image that appears on first screen while your app is loading. Required size: 768px x 1024px.'), '', true);
299
+
300
+ $this->addImage($fieldset, 'conf/submit/ipad_loader_landscape_image', $this->__('Loader Splash Screen <br />(landscape mode)'),
301
+ $this->__('Image that appears on first screen while your app is loading. Required size: 1024px x 768px.'), '', true);
302
+
303
+ $this->addImage($fieldset, 'conf/submit/ipad_logo', $this->__('Custom App Icon'),
304
+ $this->__('Icon that will appear on the user\'s device after they download your app. You do not need to apply a gradient or soft edges (this is done automatically by Apple). Recommended size: 72px x 72px.'), '', true);
305
+
306
+ $this->addImage($fieldset, 'conf/submit/big_logo', $this->__('Copyright Page Logo'),
307
+ $this->__('Store logo that is displayed on copyright page of app. Preferred size: 100px x 100px.'), '', true);
308
+ break;
309
+ case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_ANDROID:
310
+ $this->addImage($fieldset, 'conf/submit/icon', $this->__('High Resolution Application Icon'),
311
+ $this->__('The icon that appears in the Android Market. Recommended size: 512px x 512px. Maximum size: 1024 KB.'), '', true);
312
+
313
+ $this->addImage($fieldset, 'conf/submit/android_loader_image', $this->__('Loader Splash Screen'),
314
+ $this->__('Image that appears on first screen while your app is loading. Required size: 320px x 455px.'), '', true);
315
+
316
+ $this->addImage($fieldset, 'conf/submit/android_logo', $this->__('Custom App Icon'),
317
+ $this->__('Icon that will appear on the user\'s device after they download your app. Recommended size: 48px x 48px.'), '', true);
318
+
319
+ $this->addImage($fieldset, 'conf/submit/big_logo', $this->__('Copyright Page Logo'),
320
+ $this->__('Store logo that is displayed on copyright page of app. Preferred size: 100px x 100px.'), '', true);
321
+ break;
322
+ }
323
+
324
+ return parent::_prepareForm();
325
+ }
326
+
327
+ /**
328
+ * Prepare label for tab
329
+ *
330
+ * @return string
331
+ */
332
+ public function getTabLabel()
333
+ {
334
+ return $this->__('Submission');
335
+ }
336
+
337
+ /**
338
+ * Prepare title for tab
339
+ *
340
+ * @return string
341
+ */
342
+ public function getTabTitle()
343
+ {
344
+ return $this->__('Submission');
345
+ }
346
+
347
+ /**
348
+ * Returns status flag about this tab can be shown or not
349
+ *
350
+ * @return true
351
+ */
352
+ public function canShowTab()
353
+ {
354
+ return true;
355
+ }
356
+
357
+ /**
358
+ * Returns status flag about this tab hidden or not
359
+ *
360
+ * @return false
361
+ */
362
+ public function isHidden()
363
+ {
364
+ return false;
365
+ }
366
+
367
+ /**
368
+ * Configure image element type
369
+ *
370
+ * @return array
371
+ */
372
+ protected function _getAdditionalElementTypes()
373
+ {
374
+ return array(
375
+ 'image' => Mage::getConfig()->getBlockClassName('xmlconnect/adminhtml_mobile_helper_image'),
376
+ );
377
+ }
378
+
379
+ /**
380
+ * Prepare html output
381
+ * Adding preview for images if application was submitted(so we have saved images)
382
+ *
383
+ * @return string
384
+ */
385
+ protected function _toHtml()
386
+ {
387
+ return parent::_toHtml() . $this->getChildHtml('images');
388
+ }
389
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tabs.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Device submission tabs block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Tabs
35
+ extends Mage_Adminhtml_Block_Widget_Tabs
36
+ {
37
+ /**
38
+ * Constructor
39
+ * Setting view parameters, destination element DomId and title
40
+ */
41
+ public function __construct()
42
+ {
43
+ parent::__construct();
44
+
45
+ $this->setId('mobile_app_tabs');
46
+ $this->setDestElementId('edit_form');
47
+ $this->setTitle($this->__('Manage Mobile App'));
48
+ }
49
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Widget/Form.php ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Xmlconnect widget form block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form extends Mage_Adminhtml_Block_Widget_Form
35
+ {
36
+ /**
37
+ * Add color chooser to fieldset
38
+ *
39
+ * @param Varien_Data_Form_Element_Fieldset $fieldset
40
+ * @param string $fieldName
41
+ * @param string $title
42
+ */
43
+ protected function addColor($fieldset, $fieldName, $title)
44
+ {
45
+ $fieldset->addField($fieldName, 'color', array(
46
+ 'name' => $fieldName,
47
+ 'label' => $title,
48
+ ));
49
+ }
50
+
51
+ /**
52
+ * Add image uploader to fieldset
53
+ *
54
+ * @param Varien_Data_Form_Element_Fieldset $fieldset
55
+ * @param string $fieldName
56
+ * @param string $title
57
+ * @param string|null $note
58
+ * @param string $default
59
+ * @param boolean $required
60
+ */
61
+ public function addImage($fieldset, $fieldName, $title, $note = null, $default = '', $required = false)
62
+ {
63
+ $fieldset->addField($fieldName, 'image', array(
64
+ 'name' => $fieldName,
65
+ 'label' => $title,
66
+ 'note' => $note,
67
+ 'default_value' => $default,
68
+ 'required' => $required,
69
+ ));
70
+ }
71
+
72
+ /**
73
+ * Add font selector to fieldset
74
+ *
75
+ * @param Varien_Data_Form_Element_Fieldset $fieldset
76
+ * @param string $fieldPrefix
77
+ * @param string $title
78
+ */
79
+ public function addFont($fieldset, $fieldPrefix, $title)
80
+ {
81
+ $element = $fieldset->addField($fieldPrefix, 'font', array(
82
+ 'name' => $fieldPrefix,
83
+ 'label' => $title,
84
+ ));
85
+
86
+ $element->initFields(array(
87
+ 'name' => $fieldPrefix,
88
+ 'fontNames' => Mage::helper('xmlconnect')->getDeviceHelper()->getFontList(),
89
+ 'fontSizes' => Mage::helper('xmlconnect')->getDeviceHelper()->getFontSizes(),
90
+ ));
91
+ }
92
+
93
+ /**
94
+ * Configure image element type
95
+ *
96
+ * @return array
97
+ */
98
+ protected function _getAdditionalElementTypes()
99
+ {
100
+ $config = Mage::getConfig();
101
+ return array(
102
+ 'image' => $config->getBlockClassName('xmlconnect/adminhtml_mobile_form_element_image'),
103
+ 'font' => $config->getBlockClassName('xmlconnect/adminhtml_mobile_form_element_font'),
104
+ 'color' => $config->getBlockClassName('xmlconnect/adminhtml_mobile_form_element_color'),
105
+ 'tabs' => $config->getBlockClassName('xmlconnect/adminhtml_mobile_form_element_tabs'),
106
+ 'theme' => $config->getBlockClassName('xmlconnect/adminhtml_mobile_form_element_theme'),
107
+ 'page' => $config->getBlockClassName('xmlconnect/adminhtml_mobile_form_element_page'),
108
+ 'addrow'=> $config->getBlockClassName('xmlconnect/adminhtml_mobile_form_element_addrow'),
109
+ 'datetime' => $config->getBlockClassName('xmlconnect/adminhtml_mobile_form_element_datetime'),
110
+ );
111
+ }
112
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect AirMail message queue grid
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Queue extends Mage_Adminhtml_Block_Widget_Grid_Container
35
+ {
36
+ /**
37
+ * Class constructor
38
+ */
39
+ public function __construct()
40
+ {
41
+ $this->_blockGroup = 'xmlconnect';
42
+ $this->_controller = 'adminhtml_queue';
43
+ $this->_headerText = $this->__('AirMail Messages Queue');
44
+
45
+ parent::__construct();
46
+ $this->removeButton('add');
47
+ }
48
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Edit.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Xmlconnect queue edit block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Queue_Edit
35
+ extends Mage_Adminhtml_Block_Widget_Form_Container
36
+ {
37
+ /**
38
+ * Constructor
39
+ */
40
+ public function __construct()
41
+ {
42
+ $this->_objectId = 'id';
43
+ $this->_controller = 'adminhtml_queue';
44
+ $this->_blockGroup = 'xmlconnect';
45
+ parent::__construct();
46
+
47
+ $message = Mage::registry('current_message');
48
+ if ($message && $message->getStatus() != Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE) {
49
+ $this->_removeButton('reset');
50
+ $this->_removeButton('save');
51
+ } else {
52
+ $this->_updateButton('save', 'label', $this->__('Queue Message'));
53
+ $this->_updateButton('save', 'onclick', 'if (editForm.submit()) {disableElements(\'save\')}');
54
+ }
55
+ $this->_removeButton('delete');
56
+
57
+ $this->_updateButton('back', 'onclick', 'setLocation(\'' . $this->getBackUrl() . '\')');
58
+ }
59
+
60
+ /**
61
+ * Get URL for back (reset) button
62
+ *
63
+ * @return string
64
+ */
65
+ public function getBackUrl()
66
+ {
67
+ $template = Mage::registry('current_template');
68
+ $message = Mage::registry('current_message');
69
+ return $message && !$message->getId() && $template && $template->getId()
70
+ ? $this->getUrl('*/*/template')
71
+ : $this->getUrl('*/*/queue');
72
+ }
73
+
74
+ /**
75
+ * Get header text
76
+ *
77
+ * @return string
78
+ */
79
+ public function getHeaderText()
80
+ {
81
+ $message = Mage::registry('current_message');
82
+ if ($message && $message->getId()) {
83
+ return $this->__('Edit AirMail Message Queue #%s', $this->htmlEscape($message->getId()));
84
+ } else {
85
+ return $this->__('New AirMail Message Queue');
86
+ }
87
+ }
88
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Edit/Form.php ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Xmlconnect queue edit form block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Queue_Edit_Form
35
+ extends Mage_XmlConnect_Block_Adminhtml_Template_Edit_Form
36
+ {
37
+ /**
38
+ * Prepare form before rendering HTML
39
+ * Setting Form Fieldsets and fields
40
+ *
41
+ * @return Mage_Adminhtml_Block_Widget_Form
42
+ */
43
+ protected function _prepareForm()
44
+ {
45
+ $model = Mage::registry('current_message');
46
+
47
+ if ($model->getStatus() == Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE) {
48
+ $this->_fieldsEnabled = true;
49
+ } else {
50
+ $this->_fieldsEnabled = false;
51
+ }
52
+
53
+ parent::_prepareForm();
54
+
55
+ if (null !== Mage::registry('current_template')) {
56
+ $templateModel = Mage::registry('current_template');
57
+ } else {
58
+ $templateModel = Mage::getModel('xmlconnect/template')->load($model->getTemplateId());
59
+ }
60
+
61
+ $fieldset = $this->getForm()->addFieldset(
62
+ "message_settings",
63
+ array('legend' => $this->__('Message Settings')),
64
+ '^'
65
+ );
66
+
67
+ if ($model->getId()) {
68
+ $fieldset->addField('message_id', 'hidden', array(
69
+ 'name' => 'message_id'
70
+ ));
71
+ }
72
+
73
+ // set exec_time for showing accordingly to locale datetime settings
74
+ $model->setExecTime(Mage::getSingleton('core/date')->date(null, $model->getExecTime()));
75
+
76
+ /** @var $sovereignField Varien_Data_Form_Element_Abstract */
77
+ $sovereignField = $fieldset->addField('type', 'select', array(
78
+ 'name' => 'type',
79
+ 'values' => Mage::helper('xmlconnect')->getMessageTypeOptions(),
80
+ 'label' => $this->__('Message Type'),
81
+ 'title' => $this->__('Message Type'),
82
+ 'disabled' => !$this->_fieldsEnabled,
83
+ 'required' => true,
84
+ ));
85
+
86
+ $fieldset->addField('exec_time', 'date', array(
87
+ 'name' => 'exec_time',
88
+ 'format' => Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
89
+ 'label' => $this->__('Start Date'),
90
+ 'time' => true,
91
+ 'title' => $this->__('Start Date'),
92
+ 'image' => $this->getSkinUrl('images/grid-cal.gif'),
93
+ 'note' => $this->__('If leave this field empty, the message will be sent immediately'),
94
+ 'disabled' => !$this->_fieldsEnabled,
95
+ 'required' => false,
96
+ ));
97
+
98
+ $this->_addElementTypes($fieldset);
99
+
100
+ // field dependencies
101
+ if (isset($this->_dependentFields['message_title']) || isset($this->_dependentFields['content'])) {
102
+ $dependenceBlock = $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence');
103
+
104
+ $dependenceBlock->addFieldMap(
105
+ $this->_dependentFields['message_title']->getHtmlId(),
106
+ $this->_dependentFields['message_title']->getName()
107
+ )
108
+ ->addFieldMap(
109
+ $this->_dependentFields['content']->getHtmlId(),
110
+ $this->_dependentFields['content']->getName()
111
+ )
112
+ ->addFieldMap(
113
+ $sovereignField->getHtmlId(),
114
+ $sovereignField->getName()
115
+ );
116
+
117
+ if (!empty($this->_dependentFields['message_title'])) {
118
+ $dependenceBlock->addFieldDependence(
119
+ $this->_dependentFields['message_title']->getName(),
120
+ $sovereignField->getName(),
121
+ Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL
122
+ );
123
+
124
+ if (!$this->_fieldsEnabled) {
125
+ $this->_dependentFields['message_title']->setReadonly(true, true);
126
+ }
127
+ }
128
+
129
+ if (!empty($this->_dependentFields['content'])) {
130
+ $dependenceBlock->addFieldDependence(
131
+ $this->_dependentFields['content']->getName(),
132
+ $sovereignField->getName(),
133
+ Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL
134
+ );
135
+
136
+ if (!$this->_fieldsEnabled) {
137
+ $this->_dependentFields['content']->setReadonly(true, true);
138
+ }
139
+ }
140
+ $this->setChild('form_after', $dependenceBlock);
141
+ }
142
+
143
+ if (!$model->getName()) {
144
+ $model->setName($templateModel->getName());
145
+ }
146
+ if (!$model->getPushTitle()) {
147
+ $model->setPushTitle($templateModel->getPushTitle());
148
+ }
149
+ if (!$model->getMessageTitle()) {
150
+ $model->setMessageTitle($templateModel->getMessageTitle());
151
+ }
152
+ if (!$model->getContent()) {
153
+ $model->setContent($templateModel->getContent());
154
+ }
155
+ if (!$model->getTemplateId()) {
156
+ $model->setTemplateId($templateModel->getId());
157
+ }
158
+ $model->setMessageId($model->getId());
159
+ $model->setData('app_code', $templateModel->getData('app_code'));
160
+
161
+ $this->getForm()->setAction($this->getUrl('*/*/saveMessage'));
162
+ $this->getForm()->setValues($model->getData());
163
+
164
+ $this->setForm($this->getForm());
165
+ }
166
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid.php ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect AirMail message queue grid
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Queue_Grid extends Mage_Adminhtml_Block_Widget_Grid
35
+ {
36
+
37
+ /**
38
+ * Setting grid_id, sort order and sort direction
39
+ */
40
+ public function __construct()
41
+ {
42
+ parent::__construct();
43
+ $this->setId('app_queue_grid');
44
+ $this->setDefaultSort('exec_time');
45
+ $this->setDefaultDir('DESC');
46
+ $this->setSaveParametersInSession(true);
47
+ }
48
+
49
+ /**
50
+ * Setting collection to show
51
+ *
52
+ * @return Mage_Adminhtml_Block_Widget_Grid
53
+ */
54
+ protected function _prepareCollection()
55
+ {
56
+ $collection = Mage::getModel('xmlconnect/queue')->getCollection();
57
+
58
+ $collection->addFieldToFilter(
59
+ 'main_table.status',
60
+ array('neq' => Mage_XmlConnect_Model_Queue::STATUS_DELETED)
61
+ );
62
+ $this->setCollection($collection);
63
+ return parent::_prepareCollection();
64
+ }
65
+
66
+ /**
67
+ * Configuration of grid
68
+ *
69
+ * @return Mage_Adminhtml_Block_Widget_Grid
70
+ */
71
+ protected function _prepareColumns()
72
+ {
73
+ $this->addColumn('id', array(
74
+ 'header' => $this->__('ID'),
75
+ 'align' => 'center',
76
+ 'index' => 'main_table.id',
77
+ 'width' => '40px',
78
+ 'renderer' => 'xmlconnect/adminhtml_queue_grid_renderer_id'
79
+ ));
80
+
81
+ $this->addColumn('exec_time', array(
82
+ 'header' => $this->__('Queue Date'),
83
+ 'index' => 'exec_time',
84
+ 'type' => 'datetime',
85
+ 'gmtoffset' => false,
86
+ 'default' => ' ---- '
87
+ ));
88
+
89
+ $this->addColumn('app_code', array(
90
+ 'header' => $this->__('Application Name'),
91
+ 'align' => 'left',
92
+ 'index' => 'main_table.app_code',
93
+ 'type' => 'options',
94
+ 'options' => Mage::helper('xmlconnect')->getApplications(),
95
+ 'renderer' => 'xmlconnect/adminhtml_queue_grid_renderer_application'
96
+ ));
97
+
98
+ $this->addColumn('name', array(
99
+ 'header' => $this->__('Template Name'),
100
+ 'align' => 'left',
101
+ 'index' => 't.name',
102
+ 'type' => 'text',
103
+ 'default' => '--- Parent template has been deleted ---',
104
+ 'renderer' => 'xmlconnect/adminhtml_queue_grid_renderer_template'
105
+ ));
106
+
107
+ $this->addColumn('push_title', array(
108
+ 'header' => $this->__('Push Title'),
109
+ 'align' => 'left',
110
+ 'index' => 'main_table.push_title',
111
+ 'type' => 'text',
112
+ 'renderer' => 'xmlconnect/adminhtml_queue_grid_renderer_pushtitle'
113
+ ));
114
+
115
+ $this->addColumn('message_title', array(
116
+ 'header' => $this->__('Message Title'),
117
+ 'align' => 'left',
118
+ 'index' => 'main_table.message_title',
119
+ 'type' => 'text',
120
+ 'renderer' => 'xmlconnect/adminhtml_queue_grid_renderer_msgtitle'
121
+ ));
122
+
123
+ $this->addColumn('status', array(
124
+ 'header' => $this->__('Status'),
125
+ 'align' => 'left',
126
+ 'index' => 'main_table.status',
127
+ 'type' => 'options',
128
+ 'width' => '50px',
129
+ 'options' => array(
130
+ Mage_XmlConnect_Model_Queue::STATUS_CANCELED => $this->__('Canceled'),
131
+ Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE => $this->__('In Queue'),
132
+ Mage_XmlConnect_Model_Queue::STATUS_COMPLETED => $this->__('Completed'),
133
+ ),
134
+ 'renderer' => 'xmlconnect/adminhtml_queue_grid_renderer_status',
135
+ ));
136
+
137
+ $this->addColumn('action', array(
138
+ 'header' => $this->__('Action'),
139
+ 'type' => 'action',
140
+ 'getter' => 'getId',
141
+ 'renderer' => 'xmlconnect/adminhtml_queue_grid_renderer_action',
142
+
143
+ 'filter' => false,
144
+ 'sortable' => false,
145
+ ));
146
+
147
+ return parent::_prepareColumns();
148
+ }
149
+
150
+ /**
151
+ * Prepare mass actions
152
+ *
153
+ * @return Mage_XmlConnect_Block_Adminhtml_Queue_Grid
154
+ */
155
+ protected function _prepareMassaction()
156
+ {
157
+ $this->setMassactionIdField('id');
158
+ $this->getMassactionBlock()->setFormFieldName('queue');
159
+
160
+ $this->getMassactionBlock()->addItem('delete', array(
161
+ 'label' => $this->__('Delete'),
162
+ 'url' => $this->getUrl('*/*/massDeleteQueue'),
163
+ 'confirm' => $this->__('Are you sure you what to delete selected records?')
164
+ ));
165
+
166
+ $this->getMassactionBlock()->addItem('cancel', array(
167
+ 'label' => $this->__('Cancel'),
168
+ 'url' => $this->getUrl('*/*/massCancelQueue'),
169
+ 'confirm' => $this->__('Are you sure you what to cancel selected records?')
170
+ ));
171
+ return $this;
172
+ }
173
+
174
+ /**
175
+ * Configure row click url
176
+ *
177
+ * @param Mage_Catalog_Model_Queue|Varien_Object $row
178
+ * @return string
179
+ */
180
+ public function getRowUrl($row)
181
+ {
182
+ return $this->getUrl('*/*/editQueue', array('id' => $row->getId()));
183
+ }
184
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Action.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Adminhtml airmail queue grid block action item renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Action
35
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action
36
+ {
37
+ /**
38
+ * Render grid row
39
+ *
40
+ * @param Varien_Object $row
41
+ * @return string
42
+ */
43
+ public function render(Varien_Object $row)
44
+ {
45
+ $actions = array(
46
+ array(
47
+ 'caption' => $this->__('Preview'),
48
+ 'url' => $this->getUrl('*/*/previewQueue', array('id' => $row->getId())),
49
+ 'popup' => true,
50
+ ),
51
+ );
52
+
53
+ if ($row->getStatus() == Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE) {
54
+ $actions[] = array(
55
+ 'caption' => $this->__('Edit'),
56
+ 'url' => $this->getUrl('*/*/editQueue', array('id' => $row->getId())),
57
+ );
58
+ $actions[] = array(
59
+ 'caption' => $this->__('Cancel'),
60
+ 'url' => $this->getUrl('*/*/cancelQueue', array('id' => $row->getId())),
61
+ 'confirm' => $this->__('Are you sure you whant to cancel a message?')
62
+ );
63
+ }
64
+
65
+ $actions[] = array(
66
+ 'caption' => $this->__('Delete'),
67
+ 'url' => $this->getUrl('*/*/deleteQueue', array('id' => $row->getId())),
68
+ 'confirm' => $this->__('Are you sure you whant to delete a message?')
69
+ );
70
+
71
+ $this->getColumn()->setActions($actions);
72
+ return parent::render($row);
73
+ }
74
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Application.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Adminhtml airmail queue grid block action item renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Application
35
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
36
+ {
37
+ /**
38
+ * Render grid row
39
+ *
40
+ * @param Varien_Object $row
41
+ * @return string
42
+ */
43
+ public function render(Varien_Object $row)
44
+ {
45
+ $str = $this->htmlEscape($row->getAppName());
46
+ if ($str == '') {
47
+ $str = ' --- ';
48
+ }
49
+ return $str;
50
+ }
51
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Id.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Adminhtml airmail queue grid block action item renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Id
35
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
36
+ {
37
+ /**
38
+ * Render grid row
39
+ *
40
+ * @param Varien_Object $row
41
+ * @return string
42
+ */
43
+ public function render(Varien_Object $row)
44
+ {
45
+ return $row->getId();
46
+ }
47
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Msgtitle.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Adminhtml airmail queue grid block action item renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Msgtitle
35
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
36
+ {
37
+ /**
38
+ * Render grid row
39
+ *
40
+ * @param Varien_Object $row
41
+ * @return string
42
+ */
43
+ public function render(Varien_Object $row)
44
+ {
45
+ $msgTitle = $row->getMessageTitle();
46
+ if (strlen($msgTitle) > 50) {
47
+ $msgTitle = substr($msgTitle, 0, 50) . '...';
48
+ }
49
+ return $this->htmlEscape($msgTitle);
50
+ }
51
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Pushtitle.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Adminhtml airmail queue grid block action item renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Pushtitle
35
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
36
+ {
37
+ /**
38
+ * Render grid row
39
+ *
40
+ * @param Varien_Object $row
41
+ * @return string
42
+ */
43
+ public function render(Varien_Object $row)
44
+ {
45
+ return $this->htmlEscape($row->getPushTitle());
46
+ }
47
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Status.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Adminhtml airmail queue grid block action item renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Status
35
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
36
+ {
37
+ /**
38
+ * Render grid row
39
+ *
40
+ * @param Varien_Object $row
41
+ * @return string
42
+ */
43
+ public function render(Varien_Object $row)
44
+ {
45
+ $str = '';
46
+ if (is_numeric($row->getStatus())) {
47
+ switch ($row->getStatus()) {
48
+ case Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE:
49
+ $str = $this->__('In Queue');
50
+ break;
51
+ case Mage_XmlConnect_Model_Queue::STATUS_CANCELED:
52
+ $str = $this->__('Cancelled');
53
+ break;
54
+ case Mage_XmlConnect_Model_Queue::STATUS_COMPLETED:
55
+ $str = $this->__('Completed');
56
+ break;
57
+ case Mage_XmlConnect_Model_Queue::STATUS_DELETED:
58
+ $str = $this->__('Deleted');
59
+ break;
60
+ }
61
+ }
62
+
63
+ if ($str === '') {
64
+ $str = $this->__('Undefined');
65
+ }
66
+
67
+ return $this->htmlEscape($str);
68
+ }
69
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Template.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Adminhtml airmail queue grid block action item renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Template
35
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
36
+ {
37
+ /**
38
+ * Render grid row
39
+ *
40
+ * @param Varien_Object $row
41
+ * @return string
42
+ */
43
+ public function render(Varien_Object $row)
44
+ {
45
+ $str = $this->htmlEscape($row->getTplName());
46
+ if ($str == '') {
47
+ $str .= '---';
48
+ }
49
+ return $str;
50
+ }
51
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Template.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect AirMail message template grid
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Template extends Mage_Adminhtml_Block_Widget_Grid_Container
35
+ {
36
+ /**
37
+ * Class constructor
38
+ */
39
+ public function __construct()
40
+ {
41
+ $this->_blockGroup = 'xmlconnect';
42
+ $this->_controller = 'adminhtml_template';
43
+ $this->_headerText = $this->__('AirMail templates');
44
+
45
+ parent::__construct();
46
+ $this->removeButton('add');
47
+ }
48
+
49
+ /**
50
+ * Prepare layout
51
+ * Add new button
52
+ *
53
+ * @return Mage_Adminhtml_Block_Widget_Grid_Container
54
+ */
55
+ protected function _prepareLayout()
56
+ {
57
+ $this->_addButton('add_new', array(
58
+ 'label' => $this->__('Add New Template'),
59
+ 'onclick' => "setLocation('{$this->getUrl('*/*/newTemplate')}')",
60
+ 'class' => 'add'
61
+ ));
62
+
63
+ return parent::_prepareLayout();
64
+ }
65
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Edit.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Xmlconnect template edit block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Template_Edit
35
+ extends Mage_Adminhtml_Block_Widget_Form_Container
36
+ {
37
+ /**
38
+ * Constructor
39
+ */
40
+ public function __construct()
41
+ {
42
+ $this->_objectId = 'id';
43
+ $this->_controller = 'adminhtml_template';
44
+ $this->_blockGroup = 'xmlconnect';
45
+ parent::__construct();
46
+
47
+ $this->_updateButton(
48
+ 'delete',
49
+ 'onclick',
50
+ 'deleteConfirm(\''
51
+ . $this->__('Warning: All related AirMail messages will be deleted!')
52
+ . PHP_EOL
53
+ . $this->__('Are you sure you want to do this?')
54
+ .'\', \''
55
+ . $this->getDeleteUrl()
56
+ . '\')'
57
+ );
58
+ $this->_updateButton('save', 'label', $this->__('Save'));
59
+ $this->_updateButton('save', 'onclick', 'if (editForm.submit()) {disableElements(\'save\')}');
60
+ $this->_updateButton('back', 'onclick', 'setLocation(\'' . $this->getUrl('*/*/template') . '\')');
61
+ }
62
+
63
+ /**
64
+ * Return delete url for customer group
65
+ *
66
+ * @return string
67
+ */
68
+ public function getDeleteUrl()
69
+ {
70
+ return $this->getUrl('*/*/deletetemplate', array($this->_objectId => $this->getRequest()->getParam($this->_objectId)));
71
+ }
72
+
73
+ /**
74
+ * Get text for header
75
+ *
76
+ * @return string
77
+ */
78
+ public function getHeaderText()
79
+ {
80
+ $template = Mage::registry('current_template');
81
+ if ($template && $template->getId()) {
82
+ return $this->__('Edit Template "%s"', $this->htmlEscape($template->getName()));
83
+ } else {
84
+ return $this->__('New Template');
85
+ }
86
+ }
87
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Edit/Form.php ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Xmlconnect template edit form block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Template_Edit_Form
35
+ extends Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form
36
+ {
37
+ /**
38
+ * Enabled fields flag
39
+ *
40
+ * @var bool
41
+ */
42
+ protected $_fieldsEnabled = true;
43
+
44
+ /**
45
+ * Field dependencies
46
+ *
47
+ * @var array
48
+ */
49
+ protected $_dependentFields = array();
50
+
51
+ /**
52
+ * Load Wysiwyg on demand and Prepare layout
53
+ */
54
+ protected function _prepareLayout()
55
+ {
56
+ parent::_prepareLayout();
57
+ if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
58
+ $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
59
+ }
60
+ }
61
+
62
+ /**
63
+ * Prepare form
64
+ *
65
+ * @return Mage_Adminhtml_Block_Widget_Form
66
+ */
67
+ protected function _prepareForm()
68
+ {
69
+ $model = Mage::registry('current_template');
70
+
71
+ if (!$model) {
72
+ $model = new Varien_Object();
73
+ }
74
+
75
+ $action = $this->getUrl('*/*/saveTemplate');
76
+
77
+ $form = new Varien_Data_Form(array(
78
+ 'id' => 'edit_form',
79
+ 'action' => $action,
80
+ 'method' => 'post',
81
+ 'enctype' => 'multipart/form-data'
82
+ ));
83
+ $form->setHtmlIdPrefix('template_');
84
+
85
+ $fieldset = $form->addFieldset('edit_template', array('legend' => $this->__('Template')));
86
+ $this->_addElementTypes($fieldset);
87
+
88
+ if ($model->getId()) {
89
+ $fieldset->addField('id', 'hidden', array(
90
+ 'name' => 'id',
91
+ ));
92
+ $fieldset->addField('template_id', 'hidden', array(
93
+ 'name' => 'template_id',
94
+ ));
95
+ }
96
+
97
+ $fieldset->addField('app_code', 'select', array(
98
+ 'name' => 'app_code',
99
+ 'label' => $this->__('Application'),
100
+ 'title' => $this->__('Application'),
101
+ 'disabled' => $model->getId() || !$this->_fieldsEnabled ? true : false,
102
+ 'values' => Mage::helper('xmlconnect')->getApplicationOptions(),
103
+ 'note' => $this->__('Creating a Template is allowed only for applications which have device type iPhone.'),
104
+ 'required' => true,
105
+ ));
106
+
107
+ $fieldset->addField('name', 'text', array(
108
+ 'name' => 'name',
109
+ 'label' => $this->__('Template Name'),
110
+ 'title' => $this->__('Template Name'),
111
+ 'required' => true,
112
+ 'disabled' => $model->getId() || !$this->_fieldsEnabled ? true : false,
113
+ 'note' => $this->__('Maximum length is 255'),
114
+ 'maxlength' => 255
115
+ ));
116
+
117
+ $fieldset->addField('push_title', 'text', array(
118
+ 'name' => 'push_title',
119
+ 'label' => $this->__('Push Title'),
120
+ 'title' => $this->__('Push Title'),
121
+ 'required' => true,
122
+ 'disabled' => !$this->_fieldsEnabled ? true : false,
123
+ 'note' => $this->__('Maximum length is 140'),
124
+ 'maxlength' => 140
125
+ ));
126
+
127
+ $this->_dependentFields['message_title'] = $fieldset->addField('message_title', 'text', array(
128
+ 'name' => 'message_title',
129
+ 'label' => $this->__('Message Title'),
130
+ 'title' => $this->__('Message Title'),
131
+ 'required' => true,
132
+ 'disabled' => !$this->_fieldsEnabled ? true : false,
133
+ 'note' => $this->__('Maximum length is 255'),
134
+ 'maxlength' => 255
135
+ ));
136
+
137
+ $widgetFilters = array('is_email_compatible' => 1);
138
+ $wysiwygConfig = Mage::getSingleton('cms/wysiwyg_config')->getConfig(array(
139
+ // 'add_widgets' => true,
140
+ // 'add_variables' => true,
141
+ 'widget_filters' => $widgetFilters
142
+ ));
143
+
144
+ $this->_dependentFields['content'] = $fieldset->addField('content', 'editor', array(
145
+ 'label' => $this->__('Template Content'),
146
+ 'title' => $this->__('Template Content'),
147
+ 'name' => 'content',
148
+ 'style' => 'height:30em;',
149
+ 'state' => 'html',
150
+ 'required' => true,
151
+ 'disabled' => !$this->_fieldsEnabled ? true : false,
152
+ 'config' => $wysiwygConfig
153
+ ));
154
+
155
+ $form->setValues($model->getData());
156
+ $form->setUseContainer(true);
157
+ $this->setForm($form);
158
+ return parent::_prepareForm();
159
+ }
160
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid.php ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect AirMail message queue grid
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Template_Grid extends Mage_Adminhtml_Block_Widget_Grid
35
+ {
36
+ /**
37
+ * Setting grid_id, sort order and sort direction
38
+ */
39
+ public function __construct()
40
+ {
41
+ parent::__construct();
42
+ $this->setId('app_template_grid');
43
+ $this->setDefaultSort('created_at');
44
+ $this->setDefaultDir('ASC');
45
+ $this->setSaveParametersInSession(true);
46
+ }
47
+
48
+ /**
49
+ * Setting collection to show
50
+ *
51
+ * @return Mage_Adminhtml_Block_Widget_Grid
52
+ */
53
+ protected function _prepareCollection()
54
+ {
55
+ $collection = Mage::getModel('xmlconnect/template')->getCollection();
56
+ $this->setCollection($collection);
57
+ return parent::_prepareCollection();
58
+ }
59
+
60
+ /**
61
+ * Configuration of grid
62
+ *
63
+ * @return Mage_Adminhtml_Block_Widget_Grid
64
+ */
65
+ protected function _prepareColumns()
66
+ {
67
+ $this->addColumn('id', array(
68
+ 'header' => $this->__('ID'),
69
+ 'align' => 'center',
70
+ 'index' => 'id',
71
+ 'width' => '40px'
72
+ ));
73
+
74
+ $this->addColumn('name', array(
75
+ 'header' => $this->__('Template Name'),
76
+ 'align' => 'left',
77
+ 'index' => 'name',
78
+ 'escape' => true
79
+ ));
80
+
81
+ $this->addColumn('created_at', array(
82
+ 'header' => $this->__('Date Created'),
83
+ 'align' => 'left',
84
+ 'index' => 'created_at',
85
+ 'type' => 'datetime'
86
+ ));
87
+
88
+ $this->addColumn('modified_at', array(
89
+ 'header' => $this->__('Date Updated'),
90
+ 'align' => 'left',
91
+ 'index' => 'modified_at',
92
+ 'type' => 'datetime'
93
+ ));
94
+
95
+ $this->addColumn('app_code', array(
96
+ 'header' => $this->__('Application'),
97
+ 'index' => 'app_code',
98
+ 'type' => 'options',
99
+ 'align' => 'left',
100
+ 'options' => Mage::helper('xmlconnect')->getApplications(),
101
+ 'renderer' => 'xmlconnect/adminhtml_template_grid_renderer_application',
102
+ 'escape' => true
103
+ ));
104
+
105
+ $this->addColumn('push_title', array(
106
+ 'header' => $this->__('Push Title'),
107
+ 'type' => 'text',
108
+ 'align' => 'left',
109
+ 'index' => 'push_title',
110
+ 'escape' => true
111
+ ));
112
+
113
+ $this->addColumn('message_title', array(
114
+ 'header' => $this->__('Message Title'),
115
+ 'type' => 'text',
116
+ 'align' => 'left',
117
+ 'index' => 'message_title',
118
+ 'escape' => true
119
+ ));
120
+
121
+ $this->addColumn('action', array(
122
+ 'header' => $this->__('Action'),
123
+ 'type' => 'action',
124
+ 'getter' => 'getId',
125
+ 'actions' => array(
126
+ array(
127
+ 'caption' => $this->__('Preview'),
128
+ 'url' => array(
129
+ 'base' => '*/*/previewTemplate'
130
+ ),
131
+ 'popup' => true,
132
+ 'field' => 'id'
133
+ ),
134
+ array(
135
+ 'caption' => $this->__('Queue Message'),
136
+ 'url' => array(
137
+ 'base' => '*/*/queueMessage',
138
+ ),
139
+ 'field' => 'template_id'
140
+ ),
141
+ ),
142
+ 'filter' => false,
143
+ 'sortable' => false,
144
+ ));
145
+
146
+ return parent::_prepareColumns();
147
+ }
148
+
149
+ /**
150
+ * Configure row click url
151
+ *
152
+ * @param Mage_Catalog_Model_Template|Varien_Object $row
153
+ * @return string
154
+ */
155
+ public function getRowUrl($row)
156
+ {
157
+ return $this->getUrl('*/*/editTemplate', array('id' => $row->getId()));
158
+ }
159
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid/Renderer/Application.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Adminhtml airmail queue grid block action item renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Template_Grid_Renderer_Application
35
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
36
+ {
37
+ /**
38
+ * Render grid row
39
+ *
40
+ * @param Varien_Object $row
41
+ * @return string
42
+ */
43
+ public function render(Varien_Object $row)
44
+ {
45
+ $str = $this->htmlEscape($row->getAppName());
46
+ if ($str == '') {
47
+ $str = ' --- ';
48
+ }
49
+ return $str;
50
+ }
51
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Preview.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect Adminhtml AirMail template preview block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Template_Preview extends Mage_Adminhtml_Block_Widget
35
+ {
36
+ /**
37
+ * Retrieve processed template
38
+ *
39
+ * @return string
40
+ */
41
+ protected function _toHtml()
42
+ {
43
+ if ((int)$this->getRequest()->getParam('queue_preview')) {
44
+ $id = $this->getRequest()->getParam('queue_preview');
45
+ /** @var $template Mage_XmlConnect_Model_Queue */
46
+ $template = Mage::getModel('xmlconnect/queue');
47
+ } else {
48
+ $id = (int)$this->getRequest()->getParam('id');
49
+ /** @var $template Mage_XmlConnect_Model_Template */
50
+ $template = Mage::getModel('xmlconnect/template');
51
+ }
52
+
53
+ if ($id) {
54
+ $template->load($id);
55
+ }
56
+
57
+ $storeId = (int)$this->getRequest()->getParam('store_id');
58
+
59
+ if (!$storeId) {
60
+ $storeId = Mage::app()->getDefaultStoreView()->getId();
61
+ }
62
+
63
+ $template->emulateDesign($storeId);
64
+ $templateProcessed = $template->getProcessedTemplate(array(), true);
65
+ $template->revertDesign();
66
+
67
+ return $templateProcessed;
68
+ }
69
+ }
app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Preview/Form.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Admin form widget
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Adminhtml_Template_Preview_Form
35
+ extends Mage_Adminhtml_Block_Widget_Form
36
+ {
37
+ /**
38
+ * Preparing from for revision page
39
+ *
40
+ * @return Mage_XmlConnect_Block_Adminhtml_Template_Preview_Form
41
+ */
42
+ protected function _prepareForm()
43
+ {
44
+ $form = new Varien_Data_Form(array(
45
+ 'id' => 'preview_form',
46
+ 'action' => $this->getUrl('*/*/drop', array('_current' => true)),
47
+ 'method' => 'post'
48
+ ));
49
+
50
+ if ($data = $this->getTemplateFormData()) {
51
+ $mapper = array('preview_store_id' => 'store_id');
52
+
53
+ foreach ($data as $key => $value) {
54
+ if (array_key_exists($key, $mapper)) {
55
+ $name = $mapper[$key];
56
+ } else {
57
+ $name = $key;
58
+ }
59
+ $form->addField($key, 'hidden', array('name' => $name));
60
+ }
61
+ $form->setValues($data);
62
+ }
63
+
64
+ $form->setUseContainer(true);
65
+ $this->setForm($form);
66
+ return parent::_prepareForm();
67
+ }
68
+ }
69
+
app/code/core/Mage/XmlConnect/Block/Cart.php ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Shopping cart xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Xmlconnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Cart extends Mage_Checkout_Block_Cart_Abstract
35
+ {
36
+ /**
37
+ * Render shopping cart xml
38
+ *
39
+ * @return string
40
+ */
41
+ protected function _toHtml()
42
+ {
43
+ $cartMessages = $this->getMessages();
44
+ $quote = $this->getQuote();
45
+ /** @var $xmlObject Mage_XmlConnect_Model_Simplexml_Element */
46
+ $xmlObject = Mage::getModel('xmlconnect/simplexml_element', '<cart></cart>');
47
+ $xmlObject->addAttribute('is_virtual', (int)$this->helper('checkout/cart')->getIsVirtualQuote());
48
+ $xmlObject->addAttribute('summary_qty', (int)$this->helper('checkout/cart')->getSummaryCount());
49
+ if (strlen($quote->getCouponCode())) {
50
+ $xmlObject->addAttribute('has_coupon_code', 1);
51
+ }
52
+ $products = $xmlObject->addChild('products');
53
+ /* @var $item Mage_Sales_Model_Quote_Item */
54
+ foreach ($this->getItems() as $item) {
55
+ $type = $item->getProductType();
56
+ $renderer = $this->getItemRenderer($type)->setItem($item);
57
+ /**
58
+ * General information
59
+ */
60
+ $itemXml = $products->addChild('item');
61
+ $itemXml->addChild('entity_id', $item->getProduct()->getId());
62
+ $itemXml->addChild('entity_type', $type);
63
+ $itemXml->addChild('item_id', $item->getId());
64
+ $itemXml->addChild('name', $xmlObject->escapeXml($renderer->getProductName()));
65
+ $itemXml->addChild('code', 'cart[' . $item->getId() . '][qty]');
66
+ $itemXml->addChild('qty', $renderer->getQty());
67
+ $icon = $renderer->getProductThumbnail()->resize(
68
+ Mage::helper('xmlconnect/image')->getImageSizeForContent('product_small')
69
+ );
70
+ $iconXml = $itemXml->addChild('icon', $icon);
71
+ $file = Mage::helper('xmlconnect')->urlToPath($icon);
72
+ $iconXml->addAttribute('modification_time', filemtime($file));
73
+ /**
74
+ * Price
75
+ */
76
+ $exclPrice = $inclPrice = 0;
77
+ if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) {
78
+ if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales')
79
+ && $item->getWeeeTaxAppliedAmount()
80
+ ) {
81
+ $exclPrice = $item->getCalculationPrice() + $item->getWeeeTaxAppliedAmount()
82
+ + $item->getWeeeTaxDisposition();
83
+ } else {
84
+ $exclPrice = $item->getCalculationPrice();
85
+ }
86
+ }
87
+ if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()) {
88
+ $_incl = $this->helper('checkout')->getPriceInclTax($item);
89
+ if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales')
90
+ && $item->getWeeeTaxAppliedAmount()
91
+ ) {
92
+ $inclPrice = $_incl + $item->getWeeeTaxAppliedAmount();
93
+ } else {
94
+ $inclPrice = $_incl - $item->getWeeeTaxDisposition();
95
+ }
96
+ }
97
+ $exclPrice = Mage::helper('xmlconnect')->formatPriceForXml($exclPrice);
98
+ $paypalPrice = Mage::helper('xmlconnect')->formatPriceForXml($item->getCalculationPrice());
99
+ $formattedExclPrice = $quote->getStore()->formatPrice($exclPrice, false);
100
+ $inclPrice = Mage::helper('xmlconnect')->formatPriceForXml($inclPrice);
101
+ $formattedInclPrice = $quote->getStore()->formatPrice($inclPrice, false);
102
+
103
+ $priceXmlObj = $itemXml->addChild('price');
104
+ $formattedPriceXmlObj = $itemXml->addChild('formated_price');
105
+
106
+ if ($this->helper('tax')->displayCartBothPrices()) {
107
+ $priceXmlObj->addAttribute('excluding_tax', $exclPrice);
108
+ $priceXmlObj->addAttribute('including_tax', $inclPrice);
109
+
110
+ $formattedPriceXmlObj->addAttribute('excluding_tax', $formattedExclPrice);
111
+ $formattedPriceXmlObj->addAttribute('including_tax', $formattedInclPrice);
112
+ } else {
113
+ if ($this->helper('tax')->displayCartPriceExclTax()) {
114
+ $priceXmlObj->addAttribute('regular', $exclPrice);
115
+ $formattedPriceXmlObj->addAttribute('regular', $formattedExclPrice);
116
+ }
117
+ if ($this->helper('tax')->displayCartPriceInclTax()) {
118
+ $priceXmlObj->addAttribute('regular', $inclPrice);
119
+ $formattedPriceXmlObj->addAttribute('regular', $formattedInclPrice);
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Info for paypal MEP if it's enabled
125
+ */
126
+ $appConfig = Mage::helper('xmlconnect')->getApplication()->loadConfiguration()->getRenderConf();
127
+ $isMepActive = $appConfig['paypal']['isActive'];
128
+
129
+ $paypalMepIsAvailable = Mage::getModel('xmlconnect/payment_method_paypal_mep')->isAvailable(null);
130
+ if ($paypalMepIsAvailable && $isMepActive) {
131
+ $paypalPriceXmlObj = $itemXml->addChild('paypal_price');
132
+ $paypalPriceXmlObj->addAttribute('regular', $paypalPrice);
133
+ $paypalPriceXmlObj->addAttribute(
134
+ 'subtotal', Mage::helper('xmlconnect')->formatPriceForXml($item->getRowTotal())
135
+ );
136
+ }
137
+
138
+ /**
139
+ * Subtotal
140
+ */
141
+ $exclPrice = $inclPrice = 0;
142
+ if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) {
143
+ if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales')
144
+ && $item->getWeeeTaxAppliedAmount()
145
+ ) {
146
+ $exclPrice = $item->getRowTotal() + $item->getWeeeTaxAppliedRowAmount()
147
+ + $item->getWeeeTaxRowDisposition();
148
+ } else {
149
+ $exclPrice = $item->getRowTotal();
150
+ }
151
+ }
152
+ if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()) {
153
+ $_incl = $this->helper('checkout')->getSubtotalInclTax($item);
154
+ if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales')
155
+ && $item->getWeeeTaxAppliedAmount()
156
+ ) {
157
+ $inclPrice = $_incl + $item->getWeeeTaxAppliedRowAmount();
158
+ } else {
159
+ $inclPrice = $_incl - $item->getWeeeTaxRowDisposition();
160
+ }
161
+ }
162
+
163
+ $exclPrice = Mage::helper('xmlconnect')->formatPriceForXml($exclPrice);
164
+ $formattedExclPrice = $quote->getStore()->formatPrice($exclPrice, false);
165
+
166
+ $inclPrice = Mage::helper('xmlconnect')->formatPriceForXml($inclPrice);
167
+ $formattedInclPrice = $quote->getStore()->formatPrice($inclPrice, false);
168
+
169
+ $subtotalPriceXmlObj = $itemXml->addChild('subtotal');
170
+ $subtotalFormattedPriceXmlObj = $itemXml->addChild('formated_subtotal');
171
+
172
+ if ($this->helper('tax')->displayCartBothPrices()) {
173
+ $subtotalPriceXmlObj->addAttribute('excluding_tax', $exclPrice);
174
+ $subtotalPriceXmlObj->addAttribute('including_tax', $inclPrice);
175
+
176
+ $subtotalFormattedPriceXmlObj->addAttribute('excluding_tax', $formattedExclPrice);
177
+ $subtotalFormattedPriceXmlObj->addAttribute('including_tax', $formattedInclPrice);
178
+ } else {
179
+ if ($this->helper('tax')->displayCartPriceExclTax()) {
180
+ $subtotalPriceXmlObj->addAttribute('regular', $exclPrice);
181
+ $subtotalFormattedPriceXmlObj->addAttribute('regular', $formattedExclPrice);
182
+ }
183
+ if ($this->helper('tax')->displayCartPriceInclTax()) {
184
+ $subtotalPriceXmlObj->addAttribute('regular', $inclPrice);
185
+ $subtotalFormattedPriceXmlObj->addAttribute('regular', $formattedInclPrice);
186
+ }
187
+ }
188
+
189
+ /**
190
+ * Options list
191
+ */
192
+ $_options = $renderer->getOptionList();
193
+ if ($_options) {
194
+ $itemOptionsXml = $itemXml->addChild('options');
195
+ foreach ($_options as $_option) {
196
+ $_formattedOptionValue = $renderer->getFormatedOptionValue($_option);
197
+ $optionXml = $itemOptionsXml->addChild('option');
198
+ $optionXml->addAttribute('label', $xmlObject->xmlAttribute($_option['label']));
199
+ $optionXml->addAttribute('text', $xmlObject->xmlAttribute($_formattedOptionValue['value']));
200
+ }
201
+ }
202
+
203
+ /**
204
+ * Item messages
205
+ */
206
+ $messages = $renderer->getMessages();
207
+ if ($messages) {
208
+ $itemMessagesXml = $itemXml->addChild('messages');
209
+ foreach ($messages as $message) {
210
+ $messageXml = $itemMessagesXml->addChild('option');
211
+ $messageXml->addChild('type', $message['type']);
212
+ $messageXml->addChild('text', $xmlObject->escapeXml($message['text']));
213
+ }
214
+ }
215
+ }
216
+
217
+ /**
218
+ * Cart messages
219
+ */
220
+ if ($cartMessages) {
221
+ $messagesXml = $xmlObject->addChild('messages');
222
+ foreach ($cartMessages as $status => $messages) {
223
+ foreach ($messages as $message) {
224
+ $messageXml = $messagesXml->addChild('message');
225
+ $messageXml->addChild('status', $status);
226
+ $messageXml->addChild('text', strip_tags($message));
227
+ }
228
+ }
229
+ }
230
+
231
+ /**
232
+ * Cross Sell Products
233
+ */
234
+ if (count($this->getItems())) {
235
+ $crossellXml = $this->getChildHtml('crosssell');
236
+ } else {
237
+ $crossellXml = '<crosssell></crosssell>';
238
+ }
239
+
240
+ $crossSellXmlObj = Mage::getModel('xmlconnect/simplexml_element', $crossellXml);
241
+ $xmlObject->appendChild($crossSellXmlObj);
242
+
243
+ return $xmlObject->asNiceXml();
244
+ }
245
+ }
app/code/core/Mage/XmlConnect/Block/Cart/Crosssell.php ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
17
+ * versions in the future. If you wish to customize Magento for your
18
+ * needs please refer to http://www.magentocommerce.com for more information.
19
+ *
20
+ * @category Mage
21
+ * @package Mage_XmlConnect
22
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
23
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
24
+ */
25
+
26
+ /**
27
+ * Shopping cart cross sell items xml renderer
28
+ *
29
+ * @category Mage
30
+ * @package Mage_XmlConnect
31
+ * @author Magento Core Team <core@magentocommerce.com>
32
+ */
33
+ class Mage_XmlConnect_Block_Cart_Crosssell extends Mage_Checkout_Block_Cart_Crosssell
34
+ {
35
+ /**
36
+ * Render cross sell items xml
37
+ *
38
+ * @return string
39
+ */
40
+ protected function _toHtml()
41
+ {
42
+ if (is_object(Mage::getConfig()->getNode('modules/Enterprise_TargetRule'))) {
43
+ $blockRenderer = 'enterprise_targetrule/checkout_cart_crosssell';
44
+ $blockName = 'targetrule.checkout.cart.crosssell';
45
+ $this->getLayout()->createBlock($blockRenderer, $blockName);
46
+ $this->setItems($this->getLayout()->getBlock($blockName)->getItemCollection());
47
+ }
48
+
49
+ $crossSellXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<crosssell></crosssell>');
50
+ if (!$this->getItemCount()) {
51
+ return $crossSellXmlObj->asNiceXml();
52
+ }
53
+
54
+ /** @var $product Mage_Catalog_Model_Product */
55
+ foreach ($this->getItems() as $product) {
56
+ $itemXmlObj = $crossSellXmlObj->addChild('item');
57
+ $itemXmlObj->addChild('name', $crossSellXmlObj->escapeXml($product->getName()));
58
+ $icon = $this->helper('catalog/image')->init($product, 'thumbnail')
59
+ ->resize(Mage::helper('xmlconnect/image')->getImageSizeForContent('product_small'));
60
+
61
+ $iconXml = $itemXmlObj->addChild('icon', $icon);
62
+
63
+ $file = Mage::helper('xmlconnect')->urlToPath($icon);
64
+ $iconXml->addAttribute('modification_time', filemtime($file));
65
+
66
+ $itemXmlObj->addChild('entity_id', $product->getId());
67
+ $itemXmlObj->addChild('entity_type', $product->getTypeId());
68
+
69
+ /**
70
+ * If product type is grouped than it has options as its grouped items
71
+ */
72
+ if ($product->getTypeId() == Mage_Catalog_Model_Product_Type_Grouped::TYPE_CODE
73
+ || $product->getTypeId() == Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE) {
74
+ $product->setHasOptions(true);
75
+ }
76
+
77
+ $itemXmlObj->addChild('has_options', (int)$product->getHasOptions());
78
+ $itemXmlObj->addChild('in_stock', (int)$product->getStockItem()->getIsInStock());
79
+ if ($product->getTypeId() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) {
80
+ $itemXmlObj->addChild('is_salable', 0);
81
+ } else {
82
+ $itemXmlObj->addChild('is_salable', (int)$product->isSalable());
83
+ }
84
+
85
+ if ($this->getChild('product_price')) {
86
+ $this->getChild('product_price')->setProduct($product)->setProductXmlObj($itemXmlObj)
87
+ ->collectProductPrices();
88
+ }
89
+
90
+ if (!$product->getRatingSummary()) {
91
+ Mage::getModel('review/review')
92
+ ->getEntitySummary($product, Mage::app()->getStore()->getId());
93
+ }
94
+
95
+ $itemXmlObj->addChild('rating_summary', round((int)$product->getRatingSummary()->getRatingSummary() / 10));
96
+ $itemXmlObj->addChild('reviews_count', $product->getRatingSummary()->getReviewsCount());
97
+ }
98
+ return $crossSellXmlObj->asNiceXml();
99
+ }
100
+ }
app/code/core/Mage/XmlConnect/Block/Cart/Info.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Shopping cart summary information xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Xmlconnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Cart_Info extends Mage_XmlConnect_Block_Cart
35
+ {
36
+ /**
37
+ * Render cart summary xml
38
+ *
39
+ * @return string
40
+ */
41
+ protected function _toHtml()
42
+ {
43
+ /** @var $quote Mage_Sales_Model_Quote */
44
+ $quote = $this->getQuote();
45
+ /** @var $xmlObject Mage_XmlConnect_Model_Simplexml_Element */
46
+ $xmlObject = Mage::getModel('xmlconnect/simplexml_element', '<cart></cart>');
47
+
48
+ $xmlObject->addChild(
49
+ 'is_virtual',
50
+ (int)$this->helper('checkout/cart')->getIsVirtualQuote()
51
+ );
52
+
53
+ $xmlObject->addChild(
54
+ 'summary_qty',
55
+ (int)$this->helper('checkout/cart')->getSummaryCount()
56
+ );
57
+
58
+ $xmlObject->addChild(
59
+ 'virtual_qty',
60
+ (int)$quote->getItemVirtualQty()
61
+ );
62
+
63
+ if (strlen($quote->getCouponCode())) {
64
+ $xmlObject->addChild('has_coupon_code', 1);
65
+ }
66
+
67
+ $totalsXml = $this->getChildHtml('totals');
68
+ if ($totalsXml) {
69
+ /** @var $totalsXmlObj Mage_XmlConnect_Model_Simplexml_Element */
70
+ $totalsXmlObj = Mage::getModel('xmlconnect/simplexml_element', $totalsXml);
71
+ $xmlObject->appendChild($totalsXmlObj);
72
+ }
73
+ return $xmlObject->asNiceXml();
74
+ }
75
+ }
app/code/core/Mage/XmlConnect/Block/Cart/Item/Renderer.php ADDED
@@ -0,0 +1,261 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
17
+ * versions in the future. If you wish to customize Magento for your
18
+ * needs please refer to http://www.magentocommerce.com for more information.
19
+ *
20
+ * @category Mage
21
+ * @package Mage_XmlConnect
22
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
23
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
24
+ */
25
+
26
+ /**
27
+ * Shopping cart default item xml renderer
28
+ *
29
+ * @category Mage
30
+ * @package Mage_XmlConnect
31
+ * @author Magento Core Team <core@magentocommerce.com>
32
+ */
33
+ class Mage_XmlConnect_Block_Cart_Item_Renderer extends Mage_Checkout_Block_Cart_Item_Renderer
34
+ {
35
+ /**
36
+ * Add product details to XML object
37
+ *
38
+ * @param Mage_XmlConnect_Model_Simplexml_Element $reviewXmlObj
39
+ * @return Mage_XmlConnect_Model_Simplexml_Element
40
+ */
41
+ public function addProductToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $reviewXmlObj)
42
+ {
43
+ $_item = $this->getItem();
44
+ $productXmlObj = $reviewXmlObj->addCustomChild('item');
45
+ $productXmlObj->addCustomChild('name', $this->htmlEscape($this->getProductName()));
46
+
47
+ if ($_options = $this->getOptionList()) {
48
+ $optionsXmlObj = $productXmlObj->addChild('options');
49
+ foreach ($_options as $_option) {
50
+ $_formattedOptionValue = $this->getFormatedOptionValue($_option);
51
+
52
+ if (isset($_formattedOptionValue['full_view'])) {
53
+ $value = $_formattedOptionValue['full_view'];
54
+ } else {
55
+ $value = null;
56
+ }
57
+
58
+ $optionsXmlObj->addCustomChild('option', $value, array(
59
+ 'label' => $this->htmlEscape($_option['label']),
60
+ 'value' => $_formattedOptionValue['value']
61
+ ));
62
+ }
63
+ }
64
+
65
+ $this->_addPriceToXmlObj($productXmlObj);
66
+ $this->_addSubtotalToXmlObj($productXmlObj);
67
+
68
+ $productXmlObj->addCustomChild('qty', $_item->getQty());
69
+
70
+ return $reviewXmlObj;
71
+ }
72
+
73
+ /**
74
+ * Add product subtotal info to xml object
75
+ *
76
+ * @param Mage_XmlConnect_Model_Simplexml_Element $productXmlObj
77
+ * @return Mage_XmlConnect_Model_Simplexml_Element
78
+ */
79
+ protected function _addSubtotalToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $productXmlObj)
80
+ {
81
+ $_item = $this->getItem();
82
+ $subtotalXmlObj = $productXmlObj->addCustomChild('subtotal');
83
+
84
+ if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) {
85
+ if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales')
86
+ && $_item->getWeeeTaxAppliedAmount()) {
87
+ $exclPrice = $_item->getRowTotal() + $_item->getWeeeTaxAppliedRowAmount()
88
+ + $_item->getWeeeTaxRowDisposition();
89
+ } else {
90
+ $exclPrice = $_item->getRowTotal();
91
+ }
92
+ $exclPrice = $this->_formatPrice($exclPrice);
93
+
94
+ $subtotalXmlObj->addAttribute('excluding_tax', $subtotalXmlObj->escapeXml($exclPrice));
95
+ }
96
+
97
+ if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()) {
98
+ $_incl = $this->helper('checkout')->getSubtotalInclTax($_item);
99
+
100
+ if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales')
101
+ && $_item->getWeeeTaxAppliedAmount()
102
+ ) {
103
+ $inclPrice = $_incl + $_item->getWeeeTaxAppliedRowAmount();
104
+ } else {
105
+ $inclPrice = $_incl - $_item->getWeeeTaxRowDisposition();
106
+ }
107
+ $inclPrice = $this->_formatPrice($inclPrice);
108
+
109
+ $subtotalXmlObj->addAttribute('including_tax', $subtotalXmlObj->escapeXml($inclPrice));
110
+ }
111
+
112
+ if (Mage::helper('weee')->getApplied($_item)) {
113
+ $this->_addWeeeToXmlObj($subtotalXmlObj, true);
114
+ }
115
+
116
+ return $productXmlObj;
117
+ }
118
+
119
+ /**
120
+ * Format product price
121
+ *
122
+ * @param int $price
123
+ * @return float
124
+ */
125
+ protected function _formatPrice($price)
126
+ {
127
+ return $this->getQuote()->getStore()->formatPrice($price, false);
128
+ }
129
+
130
+ /**
131
+ * Add product price info to xml object
132
+ *
133
+ * @param Mage_XmlConnect_Model_Simplexml_Element $productXmlObj
134
+ * @return Mage_XmlConnect_Model_Simplexml_Element
135
+ */
136
+ protected function _addPriceToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $productXmlObj)
137
+ {
138
+ $_item = $this->getItem();
139
+ $priceXmlObj = $productXmlObj->addCustomChild('price');
140
+
141
+ if ($this->helper('tax')->displayCartPriceExclTax()
142
+ || $this->helper('tax')->displayCartBothPrices()
143
+ ) {
144
+ if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales')
145
+ && $_item->getWeeeTaxAppliedAmount()
146
+ ) {
147
+ $exclPrice = $_item->getCalculationPrice() + $_item->getWeeeTaxAppliedAmount()
148
+ + $_item->getWeeeTaxDisposition();
149
+ } else {
150
+ $exclPrice = $_item->getCalculationPrice();
151
+ }
152
+ $exclPrice = $this->_formatPrice($exclPrice);
153
+
154
+ $priceXmlObj->addAttribute('excluding_tax', $priceXmlObj->escapeXml($exclPrice));
155
+ }
156
+
157
+ if ($this->helper('tax')->displayCartPriceInclTax()
158
+ || $this->helper('tax')->displayCartBothPrices()
159
+ ) {
160
+ $_incl = $this->helper('checkout')->getPriceInclTax($_item);
161
+
162
+ if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales')
163
+ && $_item->getWeeeTaxAppliedAmount()
164
+ ) {
165
+ $inclPrice = $_incl + $_item->getWeeeTaxAppliedAmount();
166
+ } else {
167
+ $inclPrice = $_incl - $_item->getWeeeTaxDisposition();
168
+ }
169
+ $inclPrice = $this->_formatPrice($inclPrice);
170
+
171
+ $priceXmlObj->addAttribute('including_tax', $priceXmlObj->escapeXml($inclPrice));
172
+ }
173
+
174
+ if (Mage::helper('weee')->getApplied($_item)) {
175
+ $this->_addWeeeToXmlObj($priceXmlObj);
176
+ }
177
+
178
+ return $productXmlObj;
179
+ }
180
+
181
+ /**
182
+ * Add weee tax product info to xml object
183
+ *
184
+ * @param Mage_XmlConnect_Model_Simplexml_Element $priceXmlObj
185
+ * @param bool $subtotalFlag use true to get subtotal product info
186
+ * @return Mage_XmlConnect_Model_Simplexml_Element
187
+ */
188
+ protected function _addWeeeToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $priceXmlObj, $subtotalFlag = false)
189
+ {
190
+ $_item = $this->getItem();
191
+ $weeeXmlObj = $priceXmlObj->addCustomChild('weee');
192
+
193
+ if ($subtotalFlag) {
194
+ $_incl = $this->helper('checkout')->getSubtotalInclTax($_item);
195
+ } else {
196
+ $_incl = $this->helper('checkout')->getPriceInclTax($_item);
197
+ }
198
+
199
+ $typeOfDisplay2 = Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales');
200
+
201
+ if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales') && $_item->getWeeeTaxAppliedAmount()) {
202
+ foreach (Mage::helper('weee')->getApplied($_item) as $tax) {
203
+
204
+ if ($subtotalFlag) {
205
+ $amount = $tax['row_amount'];
206
+ } else {
207
+ $amount = $tax['amount'];
208
+ }
209
+
210
+ $weeeXmlObj->addCustomChild('item', null, array(
211
+ 'name' => $tax['title'],
212
+ 'amount' => $this->_formatPrice($amount)
213
+ ));
214
+ }
215
+ } elseif ($_item->getWeeeTaxAppliedAmount()
216
+ && ($typeOfDisplay2 || Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales'))
217
+ ) {
218
+ foreach (Mage::helper('weee')->getApplied($_item) as $tax) {
219
+
220
+ if ($subtotalFlag) {
221
+ $amount = $tax['row_amount_incl_tax'];
222
+ } else {
223
+ $amount = $tax['amount_incl_tax'];
224
+ }
225
+
226
+ $weeeXmlObj->addCustomChild('item', null, array(
227
+ 'name' => $tax['title'],
228
+ 'amount' => $this->_formatPrice($amount)
229
+ ));
230
+ }
231
+ }
232
+
233
+ if ($typeOfDisplay2 && $_item->getWeeeTaxAppliedAmount()) {
234
+ if ($subtotalFlag) {
235
+ $totalExcl = $_item->getRowTotal()
236
+ + $_item->getWeeeTaxAppliedRowAmount()
237
+ + $_item->getWeeeTaxRowDisposition();
238
+ } else {
239
+ $totalExcl = $_item->getCalculationPrice()
240
+ + $_item->getWeeeTaxAppliedAmount()
241
+ + $_item->getWeeeTaxDisposition();
242
+ }
243
+
244
+ $totalExcl = $this->_formatPrice($totalExcl);
245
+ $priceXmlObj->addAttribute('total_excluding_tax', $priceXmlObj->escapeXml($totalExcl));
246
+ }
247
+
248
+ if ($typeOfDisplay2 && $_item->getWeeeTaxAppliedAmount()) {
249
+ if ($subtotalFlag) {
250
+ $totalIncl = $_incl + $_item->getWeeeTaxAppliedRowAmount();
251
+ } else {
252
+ $totalIncl = $_incl + $_item->getWeeeTaxAppliedAmount();
253
+ }
254
+
255
+ $totalIncl = $this->_formatPrice($totalIncl);
256
+ $priceXmlObj->addAttribute('total_including_tax', $priceXmlObj->escapeXml($totalIncl));
257
+ }
258
+
259
+ return $priceXmlObj;
260
+ }
261
+ }
app/code/core/Mage/XmlConnect/Block/Cart/Item/Renderer/Configurable.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
17
+ * versions in the future. If you wish to customize Magento for your
18
+ * needs please refer to http://www.magentocommerce.com for more information.
19
+ *
20
+ * @category Mage
21
+ * @package Mage_XmlConnect
22
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
23
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
24
+ */
25
+
26
+ /**
27
+ * Shopping cart configurable product xml renderer
28
+ *
29
+ * @category Mage
30
+ * @package Mage_XmlConnect
31
+ * @author Magento Core Team <core@magentocommerce.com>
32
+ */
33
+ class Mage_XmlConnect_Block_Cart_Item_Renderer_Configurable extends Mage_XmlConnect_Block_Cart_Item_Renderer
34
+ {
35
+ const CONFIGURABLE_PRODUCT_IMAGE= 'checkout/cart/configurable_product_image';
36
+ const USE_PARENT_IMAGE = 'parent';
37
+
38
+ /**
39
+ * Get item configurable product
40
+ *
41
+ * @return Mage_Catalog_Model_Product
42
+ */
43
+ public function getConfigurableProduct()
44
+ {
45
+ if ($option = $this->getItem()->getOptionByCode('product_type')) {
46
+ return $option->getProduct();
47
+ }
48
+ return $this->getProduct();
49
+ }
50
+
51
+ /**
52
+ * Get item configurable child product
53
+ *
54
+ * @return Mage_Catalog_Model_Product
55
+ */
56
+ public function getChildProduct()
57
+ {
58
+ if ($option = $this->getItem()->getOptionByCode('simple_product')) {
59
+ return $option->getProduct();
60
+ }
61
+ return $this->getProduct();
62
+ }
63
+
64
+ /**
65
+ * Get item product name
66
+ *
67
+ * @return string
68
+ */
69
+ public function getProductName()
70
+ {
71
+ return $this->getProduct()->getName();
72
+ }
73
+
74
+ /**
75
+ * Get list of all otions for product
76
+ *
77
+ * @return array
78
+ */
79
+ public function getOptionList()
80
+ {
81
+ /* @var $helper Mage_Catalog_Helper_Product_Configuration */
82
+ $helper = Mage::helper('catalog/product_configuration');
83
+ $options = $helper->getConfigurableOptions($this->getItem());
84
+ return $options;
85
+ }
86
+ }
app/code/core/Mage/XmlConnect/Block/Cart/Item/Renderer/Grouped.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
17
+ * versions in the future. If you wish to customize Magento for your
18
+ * needs please refer to http://www.magentocommerce.com for more information.
19
+ *
20
+ * @category Mage
21
+ * @package Mage_XmlConnect
22
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
23
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
24
+ */
25
+
26
+ /**
27
+ * Shopping cart grouped product xml renderer
28
+ *
29
+ * @category Mage
30
+ * @package Mage_XmlConnect
31
+ * @author Magento Core Team <core@magentocommerce.com>
32
+ */
33
+ class Mage_XmlConnect_Block_Cart_Item_Renderer_Grouped extends Mage_XmlConnect_Block_Cart_Item_Renderer
34
+ {
35
+ const GROUPED_PRODUCT_IMAGE = 'checkout/cart/grouped_product_image';
36
+ const USE_PARENT_IMAGE = 'parent';
37
+
38
+ /**
39
+ * Get item grouped product
40
+ *
41
+ * @return Mage_Catalog_Model_Product
42
+ */
43
+ public function getGroupedProduct()
44
+ {
45
+ $option = $this->getItem()->getOptionByCode('product_type');
46
+ if ($option) {
47
+ return $option->getProduct();
48
+ }
49
+ return $this->getProduct();
50
+ }
51
+ }
app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mecl/Details.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * PayPal MECL Shopping cart details xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Xmlconnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Cart_Paypal_Mecl_Details
35
+ extends Mage_Paypal_Block_Express_Review_Details
36
+ {
37
+ /**
38
+ * Add cart details to XML object
39
+ *
40
+ * @param Mage_XmlConnect_Model_Simplexml_Element $reviewXmlObj
41
+ * @return Mage_XmlConnect_Model_Simplexml_Element
42
+ */
43
+ public function addDetailsToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $reviewXmlObj)
44
+ {
45
+ $itemsXmlObj = $reviewXmlObj->addChild('ordered_items');
46
+ foreach ($this->getItems() as $_item) {
47
+ $this->getItemXml($_item, $itemsXmlObj);
48
+ }
49
+
50
+ $reviewXmlObj->appendChild(
51
+ $this->getChild('totals')->setReturnObjectFlag(true)->_toHtml()
52
+ );
53
+
54
+ return $reviewXmlObj;
55
+ }
56
+
57
+ /**
58
+ * Get item row xml
59
+ *
60
+ * @param Mage_Sales_Model_Quote_Item $item
61
+ * @param Mage_XmlConnect_Model_Simplexml_Element $reviewXmlObj
62
+ * @return Mage_XmlConnect_Model_Simplexml_Element
63
+ */
64
+ public function getItemXml(
65
+ Mage_Sales_Model_Quote_Item $item,
66
+ Mage_XmlConnect_Model_Simplexml_Element $reviewXmlObj
67
+ )
68
+ {
69
+ $renderer = $this->getItemRenderer($item->getProductType())
70
+ ->setItem($item)->setQuote($this->getQuote());
71
+ return $renderer->addProductToXmlObj($reviewXmlObj);
72
+ }
73
+
74
+ /**
75
+ * Add renderer for item product type
76
+ *
77
+ * @param string $productType
78
+ * @param string $blockType
79
+ * @param string $template
80
+ * @return Mage_Checkout_Block_Cart_Abstract
81
+ */
82
+ public function addItemRender($productType, $blockType, $template)
83
+ {
84
+ $this->_itemRenders[$productType] = array(
85
+ 'block' => $blockType,
86
+ 'template' => $template,
87
+ 'blockInstance' => null
88
+ );
89
+ return $this;
90
+ }
91
+ }
app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mecl/Review.php ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * PayPal MECL Shopping cart review xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Xmlconnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Cart_Paypal_Mecl_Review extends Mage_Paypal_Block_Express_Review
35
+ {
36
+ /**
37
+ * Render PayPal MECL details xml
38
+ *
39
+ * @return string xml
40
+ */
41
+ protected function _toHtml()
42
+ {
43
+ /** @var $reviewXmlObj Mage_XmlConnect_Model_Simplexml_Element */
44
+ $reviewXmlObj = Mage::getModel(
45
+ 'xmlconnect/simplexml_element',
46
+ '<mecl_cart_details></mecl_cart_details>'
47
+ );
48
+
49
+ if ($this->getPaypalMessages()) {
50
+ $reviewXmlObj->addChild(
51
+ 'paypal_message',
52
+ implode(PHP_EOL, $this->getPaypalMessages())
53
+ );
54
+ }
55
+
56
+ if ($this->getShippingAddress()) {
57
+ $reviewXmlObj->addCustomChild(
58
+ 'shipping_address',
59
+ $this->renderAddress($this->getShippingAddress()),
60
+ array('label' => $this->__('Shipping Address'))
61
+ );
62
+ }
63
+
64
+ if ($this->_quote->isVirtual()) {
65
+ $reviewXmlObj->addCustomChild(
66
+ 'shipping_method',
67
+ null,
68
+ array(
69
+ 'label' => $this->__('No shipping method required.')
70
+ )
71
+ );
72
+ } elseif ($this->getCanEditShippingMethod() || !$this->getCurrentShippingRate()) {
73
+ if ($groups = $this->getShippingRateGroups()) {
74
+ $currentRate = $this->getCurrentShippingRate();
75
+ foreach ($groups as $code => $rates) {
76
+ foreach ($rates as $rate) {
77
+ if ($currentRate === $rate) {
78
+ $reviewXmlObj->addCustomChild(
79
+ 'shipping_method',
80
+ null,
81
+ array(
82
+ 'rate' => strip_tags($this->renderShippingRateOption($rate)),
83
+ 'label' => $this->getCarrierName($code)
84
+ )
85
+ );
86
+ break(2);
87
+ }
88
+ }
89
+ }
90
+ }
91
+ }
92
+ $reviewXmlObj->addCustomChild(
93
+ 'payment_method',
94
+ $this->escapeHtml($this->getPaymentMethodTitle()),
95
+ array(
96
+ 'label' => $this->__('Payment Method')
97
+ )
98
+ );
99
+
100
+ $reviewXmlObj->addCustomChild(
101
+ 'billing_address',
102
+ $this->renderAddress($this->getBillingAddress()),
103
+ array(
104
+ 'label' => $this->__('Billing Address'),
105
+ 'payer_email' => $this->__('Payer Email: %s', $this->getBillingAddress()->getEmail())
106
+ )
107
+ );
108
+
109
+ $this->getChild('details')->addDetailsToXmlObj($reviewXmlObj);
110
+
111
+ return $reviewXmlObj->asNiceXml();
112
+ }
113
+
114
+ /**
115
+ * Get text output for specified address
116
+ *
117
+ * @param $address
118
+ * @return string
119
+ */
120
+ public function renderAddress($address)
121
+ {
122
+ return preg_replace(
123
+ array('@\r@', '@\n+@'),
124
+ array('', PHP_EOL),
125
+ $address->getFormated(false)
126
+ );
127
+ }
128
+ }
app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mecl/Shippingmethods.php ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * PayPal MECL Shipping method list xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Xmlconnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Cart_Paypal_Mecl_Shippingmethods
35
+ extends Mage_Paypal_Block_Express_Review
36
+ {
37
+ /**
38
+ * Render PayPal MECL shipping method list xml
39
+ *
40
+ * @return string xml
41
+ */
42
+ protected function _toHtml()
43
+ {
44
+ /** @var $listXmlObj Mage_XmlConnect_Model_Simplexml_Element */
45
+ $methodListXmlObj = Mage::getModel(
46
+ 'xmlconnect/simplexml_element',
47
+ '<shipping_method_list></shipping_method_list>'
48
+ );
49
+
50
+ $methodListXmlObj->addAttribute('label', $this->__('Shipping Method'));
51
+
52
+ if ($this->getCanEditShippingMethod() || !$this->getCurrentShippingRate()) {
53
+ if ($groups = $this->getShippingRateGroups()) {
54
+ $currentRate = $this->getCurrentShippingRate();
55
+
56
+ foreach ($groups as $code => $rates) {
57
+ $rateXmlObj = $this->_addRatesToXmlObj($methodListXmlObj, $code);
58
+ foreach ($rates as $rate) {
59
+ $rateAttributes = array(
60
+ 'label' => strip_tags($this->renderShippingRateOption($rate)),
61
+ 'code' => $this->renderShippingRateValue($rate)
62
+ );
63
+ if ($currentRate === $rate) {
64
+ $rateAttributes += array('selected' => 1);
65
+ }
66
+ $rateXmlObj->addCustomChild(
67
+ 'rate',
68
+ null,
69
+ $rateAttributes
70
+ );
71
+ }
72
+ }
73
+ } else {
74
+ $message = $this->_quote->isVirtual()
75
+ ? $this->__('No shipping method required.')
76
+ : $this->__('Sorry, no quotes are available for this order at this time.');
77
+ $methodListXmlObj->addCustomChild(
78
+ 'method',
79
+ null,
80
+ array(
81
+ 'label' => $message
82
+ )
83
+ );
84
+ }
85
+ } else {
86
+ $rateXmlObj = $this->_addRatesToXmlObj($methodListXmlObj);
87
+
88
+ $rateXmlObj->addCustomChild(
89
+ 'rate',
90
+ null,
91
+ array(
92
+ 'label' => $this->renderShippingRateOption($this->getCurrentShippingRate()),
93
+ 'selected' => 1
94
+ )
95
+ );
96
+ }
97
+
98
+ return $methodListXmlObj->asNiceXml();
99
+ }
100
+
101
+ /**
102
+ * Add cart details to XML object
103
+ *
104
+ * @param Mage_XmlConnect_Model_Simplexml_Element $methodListXmlObj
105
+ * @param string $code
106
+ * @return Mage_XmlConnect_Model_Simplexml_Element
107
+ */
108
+ protected function _addRatesToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $methodListXmlObj, $code = '')
109
+ {
110
+ $attributes = $code ? array('label' => $this->getCarrierName($code)) : array();
111
+ return $methodListXmlObj->addCustomChild(
112
+ 'method',
113
+ null,
114
+ $attributes
115
+ )
116
+ ->addCustomChild('rates');
117
+ }
118
+ }
app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mep/Totals.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * PayPal MEP Shopping cart totals xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Xmlconnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Cart_Paypal_Mep_Totals extends Mage_Checkout_Block_Cart_Totals
35
+ {
36
+ /**
37
+ * Render cart totals xml
38
+ *
39
+ * @return string
40
+ */
41
+ protected function _toHtml()
42
+ {
43
+ /** @var $paypalCart Mage_Paypal_Model_Cart */
44
+ $paypalCart = Mage::getModel('paypal/cart', array($this->getQuote()));
45
+ /** @var $totalsXmlObj Mage_XmlConnect_Model_Simplexml_Element */
46
+ $totalsXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<cart_totals></cart_totals>');
47
+ foreach ($paypalCart->getTotals(true) as $code => $amount) {
48
+ $currencyAmount = $this->helper('core')->currency($amount, false, false);
49
+ $totalsXmlObj->addChild($code, sprintf('%01.2F', $currencyAmount));
50
+ }
51
+
52
+ $paypalTotals = $totalsXmlObj->addChild('paypal_totals');
53
+ foreach ($this->getQuote()->getTotals() as $total) {
54
+ $code = $total->getCode();
55
+ if ($code == 'giftcardaccount' || $code == 'giftwrapping') {
56
+ continue;
57
+ }
58
+ $renderer = $this->_getTotalRenderer($code)->setTotal($total);
59
+ switch ($code) {
60
+ case 'subtotal':
61
+ $subtotal = intval($total->getValueExclTax()) ? $total->getValueExclTax() : $total->getValue();
62
+ $paypalTotals->addAttribute(
63
+ $code,
64
+ Mage::helper('xmlconnect')->formatPriceForXml($subtotal)
65
+ );
66
+ break;
67
+ case 'tax':
68
+ $paypalTotals->addAttribute(
69
+ $code,
70
+ Mage::helper('xmlconnect')->formatPriceForXml($total->getValue())
71
+ );
72
+ break;
73
+ case 'shipping':
74
+ $paypalTotals->addAttribute(
75
+ $code,
76
+ Mage::helper('xmlconnect')->formatPriceForXml($renderer->getShippingExcludeTax())
77
+ );
78
+ break;
79
+ default:
80
+ break;
81
+ }
82
+ }
83
+
84
+ return $totalsXmlObj->asNiceXml();
85
+ }
86
+ }
app/code/core/Mage/XmlConnect/Block/Cart/Totals.php ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Shopping cart totals xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Xmlconnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Cart_Totals extends Mage_Checkout_Block_Cart_Totals
35
+ {
36
+ /**
37
+ * Render cart totals xml
38
+ *
39
+ * @return string|Mage_XmlConnect_Model_Simplexml_Element
40
+ */
41
+ protected function _toHtml()
42
+ {
43
+ /** @var $totalsXmlObj Mage_XmlConnect_Model_Simplexml_Element */
44
+ $totalsXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<totals></totals>');
45
+ // $taxConfig = Mage::getSingleton('tax/config');
46
+
47
+ foreach ($this->getQuote()->getTotals() as $total) {
48
+ $code = $total->getCode();
49
+ if ($code == 'giftwrapping') {
50
+ continue;
51
+ }
52
+
53
+ $title = '';
54
+ $value = null;
55
+ $renderer = $this->_getTotalRenderer($code)->setTotal($total);
56
+
57
+ switch ($code) {
58
+ case 'subtotal':
59
+ if ($renderer->displayBoth()) {
60
+ $title = $this->__('Subtotal (Excl. Tax)');
61
+ $this->_addTotalDataToXmlObj(
62
+ $totalsXmlObj,
63
+ $code . '_excl_tax',
64
+ $title,
65
+ $total->getValueExclTax()
66
+ );
67
+
68
+ $code = $code . '_incl_tax';
69
+ $title = $this->__('Subtotal (Incl. Tax)');
70
+ $value = $total->getValueInclTax();
71
+ }
72
+ break;
73
+ case 'shipping':
74
+ if ($renderer->displayBoth()) {
75
+ $title = $renderer->getExcludeTaxLabel();
76
+ $this->_addTotalDataToXmlObj(
77
+ $totalsXmlObj,
78
+ $code . '_excl_tax',
79
+ $title,
80
+ $renderer->getShippingExcludeTax()
81
+ );
82
+
83
+ $code = $code . '_incl_tax';
84
+ $title = $renderer->getIncludeTaxLabel();
85
+ $value = $renderer->getShippingIncludeTax();
86
+ } else if ($renderer->displayIncludeTax()) {
87
+ $value = $renderer->getShippingIncludeTax();
88
+ } else {
89
+ $value = $renderer->getShippingExcludeTax();
90
+ }
91
+ break;
92
+ case 'grand_total':
93
+ $grandTotalExlTax = $renderer->getTotalExclTax();
94
+ $displayBoth = $renderer->includeTax() && $grandTotalExlTax >= 0;
95
+ if ($displayBoth) {
96
+ $title = $this->__('Grand Total (Excl. Tax)');
97
+ $this->_addTotalDataToXmlObj(
98
+ $totalsXmlObj,
99
+ $code . '_excl_tax',
100
+ $title,
101
+ $grandTotalExlTax
102
+ );
103
+
104
+ $code = $code . '_incl_tax';
105
+ $title = $this->__('Grand Total (Incl. Tax)');
106
+ }
107
+ break;
108
+ case 'giftwrapping':
109
+ foreach ($renderer->getValues() as $title => $value) {
110
+ $this->_addTotalDataToXmlObj($totalsXmlObj, $code, $title, $value);
111
+ }
112
+ continue 2;
113
+ case 'giftcardaccount':
114
+ $_cards = $renderer->getTotal()->getGiftCards();
115
+ if (!$_cards) {
116
+ $_cards = $renderer->getQuoteGiftCards();
117
+ }
118
+ if ($renderer->getTotal()->getValue()) {
119
+ foreach ($_cards as $cardCode) {
120
+ $title = $this->__('Gift Card (%s)', $cardCode['c']);
121
+ $value = $cardCode['c'];
122
+ $totalXmlObj = $totalsXmlObj->addChild($code);
123
+ $totalXmlObj->addChild('title', $totalsXmlObj->escapeXml($title));
124
+ $totalXmlObj->addChild('value', $value);
125
+ $value = Mage::helper('xmlconnect')->formatPriceForXml($cardCode['a']);
126
+ $formattedValue = $this->getQuote()->getStore()->formatPrice($value, false);
127
+ $totalXmlObj->addChild('formated_value', '-' . $formattedValue);
128
+ }
129
+ }
130
+ continue 2;
131
+ default:
132
+ break;
133
+ }
134
+ if (empty($title)) {
135
+ $title = $total->getTitle();
136
+ }
137
+ if (null === $value) {
138
+ $value = $total->getValue();
139
+ }
140
+ if (null !== $value) {
141
+ $this->_addTotalDataToXmlObj($totalsXmlObj, $code, $title, $value);
142
+ }
143
+ }
144
+
145
+ return $this->getReturnObjectFlag() ? $totalsXmlObj : $totalsXmlObj->asNiceXml();
146
+ }
147
+
148
+ /**
149
+ * Add total data to totals xml object
150
+ *
151
+ * @param Mage_XmlConnect_Model_Simplexml_Element $totalsXmlObj
152
+ * @param string $code
153
+ * @param string $title
154
+ * @param float $value
155
+ */
156
+ protected function _addTotalDataToXmlObj($totalsXmlObj, $code, $title, $value)
157
+ {
158
+ $value = Mage::helper('xmlconnect')->formatPriceForXml($value);
159
+ $totalXmlObj = $totalsXmlObj->addChild($code);
160
+ $totalXmlObj->addChild('title', $totalsXmlObj->escapeXml($title));
161
+ $formattedValue = $this->getQuote()->getStore()->formatPrice($value, false);
162
+ $totalXmlObj->addChild('value', $value);
163
+ $totalXmlObj->addChild('formated_value', $formattedValue);
164
+ }
165
+ }
app/code/core/Mage/XmlConnect/Block/Catalog.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Catalog xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Xmlconnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Catalog extends Mage_Core_Block_Template
35
+ {
36
+ /**
37
+ * Limit for product sorting fields to return
38
+ */
39
+ const PRODUCT_SORT_FIELDS_NUMBER = 3;
40
+
41
+ /**
42
+ * Prefix that used in specifing filters on request
43
+ */
44
+ const REQUEST_FILTER_PARAM_REFIX = 'filter_';
45
+
46
+ /**
47
+ * Prefix that used in specifing sort order params on request
48
+ */
49
+ const REQUEST_SORT_ORDER_PARAM_REFIX = 'order_';
50
+
51
+ /**
52
+ * Retrieve product sort fields as xml object
53
+ *
54
+ * @return Mage_XmlConnect_Model_Simplexml_Element
55
+ */
56
+ public function getProductSortFeildsXmlObject()
57
+ {
58
+ $ordersXmlObject = Mage::getModel('xmlconnect/simplexml_element', '<orders></orders>');
59
+ /* @var $category Mage_Catalog_Model_Category */
60
+ $category = Mage::getModel('catalog/category');
61
+ $sortOptions = $category->getAvailableSortByOptions();
62
+ $sortOptions = array_slice($sortOptions, 0, self::PRODUCT_SORT_FIELDS_NUMBER);
63
+ $defaultSort = $category->getDefaultSortBy();
64
+ foreach ($sortOptions as $code => $name) {
65
+ $item = $ordersXmlObject->addChild('item');
66
+ if ($code == $defaultSort) {
67
+ $item->addAttribute('isDefault', 1);
68
+ }
69
+ $item->addChild('code', $code);
70
+ $item->addChild('name', $ordersXmlObject->escapeXml($name));
71
+ }
72
+
73
+ return $ordersXmlObject;
74
+ }
75
+ }
app/code/core/Mage/XmlConnect/Block/Catalog/Category.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Category list xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Catalog_Category extends Mage_XmlConnect_Block_Catalog
35
+ {
36
+ /**
37
+ * Render block HTML
38
+ *
39
+ * @return string
40
+ */
41
+ protected function _toHtml()
42
+ {
43
+ /** @var $categoryXmlObj Mage_XmlConnect_Model_Simplexml_Element */
44
+ $categoryXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<category></category>');
45
+ $categoryId = $this->getRequest()->getParam('id', null);
46
+ if ($categoryId === null) {
47
+ $categoryId = Mage::app()->getStore()->getRootCategoryId();
48
+ }
49
+
50
+ $productsXmlObj = $productListBlock = false;
51
+ /** @var $categoryModel Mage_Catalog_Model_Category */
52
+ $categoryModel = Mage::getModel('catalog/category')->load($categoryId);
53
+ if ($categoryModel->getId()) {
54
+ $hasMoreProductItems = 0;
55
+ $productListBlock = $this->getChild('product_list');
56
+ if ($productListBlock && $categoryModel->getLevel() > 1) {
57
+ $layer = Mage::getSingleton('catalog/layer');
58
+ $productsXmlObj = $productListBlock->setCategory($categoryModel)
59
+ ->setLayer($layer)
60
+ ->getProductsXmlObject();
61
+ $hasMoreProductItems = (int)$productListBlock->getHasProductItems();
62
+ }
63
+
64
+ $infoBlock = $this->getChild('category_info');
65
+ if ($infoBlock) {
66
+ $categoryInfoXmlObj = $infoBlock->setCategory($categoryModel)
67
+ ->getCategoryInfoXmlObject();
68
+ $categoryInfoXmlObj->addChild('has_more_items', $hasMoreProductItems);
69
+ $categoryXmlObj->appendChild($categoryInfoXmlObj);
70
+ }
71
+ }
72
+
73
+ $categoryCollection = $this->getCurrentChildCategories();
74
+
75
+ // subcategories are exists
76
+ if (sizeof($categoryCollection)) {
77
+ $itemsXmlObj = $categoryXmlObj->addChild('items');
78
+ foreach ($categoryCollection as $item) {
79
+ /** @var $item Mage_Catalog_Model_Category */
80
+ $item = Mage::getModel('catalog/category')->load($item->getId());
81
+
82
+ $itemXmlObj = $itemsXmlObj->addChild('item');
83
+ $itemXmlObj->addChild('label', $categoryXmlObj->escapeXml($item->getName()));
84
+ $itemXmlObj->addChild('entity_id', $item->getId());
85
+ $itemXmlObj->addChild('content_type', $item->hasChildren() ? 'categories' : 'products');
86
+ if (!is_null($categoryId)) {
87
+ $itemXmlObj->addChild('parent_id', $item->getParentId());
88
+ }
89
+ $icon = Mage::helper('xmlconnect/catalog_category_image')
90
+ ->initialize($item, 'thumbnail')
91
+ ->resize(Mage::helper('xmlconnect/image')->getImageSizeForContent('category'));
92
+
93
+ $iconXml = $itemXmlObj->addChild('icon', $icon);
94
+
95
+ $file = Mage::helper('xmlconnect')->urlToPath($icon);
96
+ $iconXml->addAttribute('modification_time', filemtime($file));
97
+ }
98
+ }
99
+
100
+ if ($productListBlock && $productsXmlObj) {
101
+ $categoryXmlObj->appendChild($productsXmlObj);
102
+ }
103
+ return $categoryXmlObj->asNiceXml();
104
+ }
105
+
106
+ /**
107
+ * Retrieve child categories of current category
108
+ *
109
+ * @return Varien_Data_Tree_Node_Collection
110
+ */
111
+ public function getCurrentChildCategories()
112
+ {
113
+ $layer = Mage::getSingleton('catalog/layer');
114
+ $category = $layer->getCurrentCategory();
115
+ /* @var $category Mage_Catalog_Model_Category */
116
+ $categories = $category->getChildrenCategories();
117
+ $productCollection = Mage::getResourceModel('catalog/product_collection');
118
+ $layer->prepareProductCollection($productCollection);
119
+ $productCollection->addCountToCategories($categories);
120
+ return $categories;
121
+ }
122
+ }
app/code/core/Mage/XmlConnect/Block/Catalog/Category/Info.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Category info xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Catalog_Category_Info extends Mage_XmlConnect_Block_Catalog
35
+ {
36
+ /**
37
+ * Produce category info xml object
38
+ *
39
+ * @return Mage_XmlConnect_Model_Simplexml_Element
40
+ */
41
+ public function getCategoryInfoXmlObject()
42
+ {
43
+ $infoXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<category_info></category_info>');
44
+ $category = $this->getCategory();
45
+ if (is_object($category) && $category->getId()) {
46
+ /**
47
+ * @var string $title
48
+ *
49
+ * Copied data from "getDefaultApplicationDesignTabs()" method in "Mage_XmlConnect_Helper_Data"
50
+ */
51
+ $title = $this->__('Shop');
52
+ if ($category->getParentCategory()->getLevel() > 1) {
53
+ $title = $infoXmlObj->escapeXml($category->getParentCategory()->getName());
54
+ }
55
+
56
+ $infoXmlObj->addChild('parent_title', $title);
57
+ $pId = 0;
58
+ if ($category->getLevel() > 1) {
59
+ $pId = $category->getParentId();
60
+ }
61
+ $infoXmlObj->addChild('parent_id', $pId);
62
+ }
63
+
64
+ return $infoXmlObj;
65
+ }
66
+
67
+ /**
68
+ * Render category info xml
69
+ *
70
+ * @return string
71
+ */
72
+ protected function _toHtml()
73
+ {
74
+ return $this->getCategoryInfoXmlObject()->asNiceXml();
75
+ }
76
+ }
app/code/core/Mage/XmlConnect/Block/Catalog/Filters.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Filters xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Catalog_Filters extends Mage_XmlConnect_Block_Catalog
35
+ {
36
+ /**
37
+ * Render filters list xml
38
+ *
39
+ * @return string
40
+ */
41
+ protected function _toHtml()
42
+ {
43
+ $categoryId = $this->getRequest()->getParam('category_id', null);
44
+ $categoryXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<category></category>');
45
+ $filtersCollection = Mage::getResourceModel('xmlconnect/filter_collection')->setCategoryId($categoryId);
46
+
47
+ $filtersXmlObj = $categoryXmlObj->addChild('filters');
48
+ foreach ($filtersCollection->getItems() as $item) {
49
+ if (!sizeof($item->getValues())) {
50
+ continue;
51
+ }
52
+ $itemXmlObj = $filtersXmlObj->addChild('item');
53
+ $itemXmlObj->addChild('name', $categoryXmlObj->escapeXml($item->getName()));
54
+ $itemXmlObj->addChild('code', $categoryXmlObj->escapeXml($item->getCode()));
55
+
56
+ $valuesXmlObj = $itemXmlObj->addChild('values');
57
+ foreach ($item->getValues() as $value) {
58
+ $valueXmlObj = $valuesXmlObj->addChild('value');
59
+ $valueXmlObj->addChild('id', $categoryXmlObj->escapeXml($value->getValueString()));
60
+ $valueXmlObj->addChild('label', $categoryXmlObj->escapeXml($value->getLabel()));
61
+ $valueXmlObj->addChild('count', (int)$value->getProductsCount());
62
+ }
63
+ }
64
+ $categoryXmlObj->appendChild($this->getProductSortFeildsXmlObject());
65
+
66
+ return $categoryXmlObj->asNiceXml();
67
+ }
68
+ }
app/code/core/Mage/XmlConnect/Block/Catalog/Product.php ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Product data xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Catalog_Product extends Mage_XmlConnect_Block_Catalog
35
+ {
36
+ /**
37
+ * Retrieve product attributes as xml object
38
+ *
39
+ * @param Mage_Catalog_Model_Product $product
40
+ * @param string $itemNodeName
41
+ * @return Mage_XmlConnect_Model_Simplexml_Element
42
+ */
43
+ public function productToXmlObject(Mage_Catalog_Model_Product $product, $itemNodeName = 'item')
44
+ {
45
+ /** @var $item Mage_XmlConnect_Model_Simplexml_Element */
46
+ $item = Mage::getModel('xmlconnect/simplexml_element', '<' . $itemNodeName . '></' . $itemNodeName . '>');
47
+ if ($product && $product->getId()) {
48
+ $item->addChild('entity_id', $product->getId());
49
+ $item->addChild('name', $item->escapeXml($product->getName()));
50
+ $item->addChild('entity_type', $product->getTypeId());
51
+ $item->addChild('short_description', $item->escapeXml($product->getShortDescription()));
52
+ $description = Mage::helper('xmlconnect')->htmlize($item->xmlentities($product->getDescription()));
53
+ $item->addChild('description', $description);
54
+ $item->addChild('link', $product->getProductUrl());
55
+
56
+ if ($itemNodeName == 'item') {
57
+ $imageToResize = Mage::helper('xmlconnect/image')->getImageSizeForContent('product_small');
58
+ $propertyToResizeName = 'small_image';
59
+ } else {
60
+ $imageToResize = Mage::helper('xmlconnect/image')->getImageSizeForContent('product_big');
61
+ $propertyToResizeName = 'image';
62
+ }
63
+
64
+ $icon = clone Mage::helper('catalog/image')
65
+ ->init($product, $propertyToResizeName)
66
+ ->resize($imageToResize);
67
+
68
+ $iconXml = $item->addChild('icon', $icon);
69
+
70
+ $file = Mage::helper('xmlconnect')->urlToPath($icon);
71
+ $iconXml->addAttribute('modification_time', filemtime($file));
72
+
73
+ $item->addChild('in_stock', (int)$product->getIsInStock());
74
+ $item->addChild('is_salable', (int)$product->isSalable());
75
+ /**
76
+ * By default all products has gallery (because of collection not load gallery attribute)
77
+ */
78
+ $hasGallery = 1;
79
+ if ($product->getMediaGalleryImages()) {
80
+ $hasGallery = sizeof($product->getMediaGalleryImages()) > 0 ? 1 : 0;
81
+ }
82
+ $item->addChild('has_gallery', $hasGallery);
83
+ /**
84
+ * If product type is grouped than it has options as its grouped items
85
+ */
86
+ if ($product->getTypeId() == Mage_Catalog_Model_Product_Type_Grouped::TYPE_CODE
87
+ || $product->getTypeId() == Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE) {
88
+ $product->setHasOptions(true);
89
+ }
90
+ $item->addChild('has_options', (int)$product->getHasOptions());
91
+
92
+ if ($minSaleQty = $this->_getMinimalQty($product)) {
93
+ $item->addChild('min_sale_qty', (int) $minSaleQty);
94
+ }
95
+
96
+ if (!$product->getRatingSummary()) {
97
+ Mage::getModel('review/review')->getEntitySummary($product, Mage::app()->getStore()->getId());
98
+ }
99
+
100
+ $item->addChild('rating_summary', round((int)$product->getRatingSummary()->getRatingSummary() / 10));
101
+ $item->addChild('reviews_count', $product->getRatingSummary()->getReviewsCount());
102
+
103
+ if ($this->getChild('product_price')) {
104
+ $this->getChild('product_price')->setProduct($product)->setProductXmlObj($item)
105
+ ->collectProductPrices();
106
+ }
107
+
108
+ if ($this->getChild('additional_info')) {
109
+ $this->getChild('additional_info')->addAdditionalData($product, $item);
110
+ }
111
+ }
112
+
113
+ return $item;
114
+ }
115
+
116
+ /**
117
+ * Get MinSaleQty for product
118
+ *
119
+ * @param Mage_Catalog_Model_Product $product
120
+ * @return int|null
121
+ */
122
+ protected function _getMinimalQty($product)
123
+ {
124
+ if ($stockItem = $product->getStockItem()) {
125
+ if ($stockItem->getMinSaleQty() && $stockItem->getMinSaleQty() > 0) {
126
+ return ($stockItem->getMinSaleQty() * 1);
127
+ }
128
+ }
129
+ return null;
130
+ }
131
+
132
+ /**
133
+ * Render product info xml
134
+ *
135
+ * @throws Mage_Core_Exception
136
+ * @return string
137
+ */
138
+ protected function _toHtml()
139
+ {
140
+ /** @var $product Mage_Catalog_Model_Product */
141
+ $product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())
142
+ ->load($this->getRequest()->getParam('id', 0));
143
+
144
+ if (!$product) {
145
+ Mage::throwException($this->__('Selected product is unavailable.'));
146
+ } else {
147
+ $this->setProduct($product);
148
+ $productXmlObj = $this->productToXmlObject($product, 'product');
149
+
150
+ $relatedProductsBlock = $this->getChild('related_products');
151
+ if ($relatedProductsBlock) {
152
+ $relatedXmlObj = $relatedProductsBlock->getRelatedProductsXmlObj();
153
+ $productXmlObj->appendChild($relatedXmlObj);
154
+ }
155
+ }
156
+
157
+ $productOptions = $this->getChild('xmlconnect.catalog.product.options')
158
+ ->getProductOptionsXmlObject($product);
159
+ if ($productOptions instanceof Mage_XmlConnect_Model_Simplexml_Element) {
160
+ $productXmlObj->appendChild($productOptions);
161
+ }
162
+
163
+ return $productXmlObj->asNiceXml();
164
+ }
165
+ }
app/code/core/Mage/XmlConnect/Block/Catalog/Product/Attributes.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Product additional attributes xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Catalog_Product_Attributes
35
+ extends Mage_Catalog_Block_Product_View_Attributes
36
+ {
37
+ /**
38
+ * Add additional information (attributes) to current product xml object
39
+ *
40
+ * @param Mage_Catalog_Model_Product $product
41
+ * @param Mage_XmlConnect_Model_Simplexml_Element $productXmlObject
42
+ */
43
+ public function addAdditionalData(
44
+ Mage_Catalog_Model_Product $product,
45
+ Mage_XmlConnect_Model_Simplexml_Element $productXmlObject
46
+ )
47
+ {
48
+ if ($product && $productXmlObject && $product->getId()) {
49
+ $this->_product = $product;
50
+ $additionalData = $this->getAdditionalData();
51
+ if (!empty($additionalData)) {
52
+ $attributesXmlObj = $productXmlObject->addChild('additional_attributes');
53
+ foreach ($additionalData as $data) {
54
+ $attribute = Mage::helper('catalog/output')
55
+ ->productAttribute($product, $data['value'], $data['code']);
56
+ /** @var $attrXmlObject Mage_XmlConnect_Model_Simplexml_Element */
57
+ $attrXmlObject = $attributesXmlObj->addChild('item');
58
+ $attrXmlObject->addCustomChild('label', $data['label']);
59
+ $attrXmlObject->addCustomChild('value', strip_tags($attribute));
60
+ }
61
+ }
62
+ }
63
+ }
64
+ }
app/code/core/Mage/XmlConnect/Block/Catalog/Product/Gallery.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Product images gallery block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Catalog_Product_Gallery extends Mage_XmlConnect_Block_Catalog
35
+ {
36
+ /**
37
+ * Generate images gallery xml
38
+ *
39
+ * @return string
40
+ */
41
+ protected function _toHtml()
42
+ {
43
+ $productId = $this->getRequest()->getParam('id', null);
44
+ $product = Mage::getModel('catalog/product')
45
+ ->setStoreId(Mage::app()->getStore()->getId())
46
+ ->load($productId);
47
+ $collection = $product->getMediaGalleryImages();
48
+
49
+ $imagesNode = Mage::getModel('xmlconnect/simplexml_element', '<images></images>');
50
+ $helper = $this->helper('catalog/image');
51
+
52
+ foreach ($collection as $item) {
53
+ $imageNode = $imagesNode->addChild('image');
54
+
55
+ /**
56
+ * Big image
57
+ */
58
+ $bigImage = $helper->init($product, 'image', $item->getFile())
59
+ ->constrainOnly(true)
60
+ ->keepFrame(false)
61
+ ->resize(Mage::helper('xmlconnect/image')->getImageSizeForContent('product_gallery_big'));
62
+
63
+ $fileNode = $imageNode->addChild('file');
64
+ $fileNode->addAttribute('type', 'big');
65
+ $fileNode->addAttribute('url', $bigImage);
66
+
67
+ $file = Mage::helper('xmlconnect')->urlToPath($bigImage);
68
+
69
+ $fileNode->addAttribute('id', ($id = $item->getId()) ? (int) $id : 0);
70
+ $fileNode->addAttribute('modification_time', filemtime($file));
71
+
72
+ /**
73
+ * Small image
74
+ */
75
+ $smallImage = $helper->init($product, 'thumbnail', $item->getFile())
76
+ ->constrainOnly(true)
77
+ ->keepFrame(false)
78
+ ->resize(Mage::helper('xmlconnect/image')->getImageSizeForContent('product_gallery_small'));
79
+
80
+ $fileNode = $imageNode->addChild('file');
81
+ $fileNode->addAttribute('type', 'small');
82
+ $fileNode->addAttribute('url', $smallImage);
83
+
84
+ $file = Mage::helper('xmlconnect')->urlToPath($smallImage);
85
+ $fileNode->addAttribute('modification_time', filemtime($file));
86
+ }
87
+ return $imagesNode->asNiceXml();
88
+ }
89
+ }
app/code/core/Mage/XmlConnect/Block/Catalog/Product/List.php ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Product list xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Catalog_Product_List extends Mage_XmlConnect_Block_Catalog_Product
35
+ {
36
+ /**
37
+ * Store product collection
38
+ *
39
+ * @var Mage_Eav_Model_Entity_Collection_Abstract
40
+ */
41
+ protected $_productCollection = null;
42
+
43
+ /**
44
+ * Store collected layered navigation filters whike applying them
45
+ *
46
+ * @var array
47
+ */
48
+ protected $_collectedFilters = array();
49
+
50
+ /**
51
+ * Produce products list xml object
52
+ *
53
+ * @return Mage_XmlConnect_Model_Simplexml_Element
54
+ */
55
+ public function getProductsXmlObject()
56
+ {
57
+ $productsXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<products></products>');
58
+ $collection = $this->_getProductCollection();
59
+
60
+ if (!$collection) {
61
+ return false;
62
+ }
63
+ foreach ($collection->getItems() as $product) {
64
+ $productXmlObj = $this->productToXmlObject($product);
65
+ if ($productXmlObj) {
66
+ $productsXmlObj->appendChild($productXmlObj);
67
+ }
68
+ }
69
+
70
+ return $productsXmlObj;
71
+ }
72
+
73
+ /**
74
+ * Getter for collected layered navigation filters
75
+ *
76
+ * @return array
77
+ */
78
+ public function getCollectedFilters()
79
+ {
80
+ return $this->_collectedFilters;
81
+ }
82
+
83
+ /**
84
+ * Retrieve product collection with all prepared data and limitations
85
+ *
86
+ * @return Mage_Eav_Model_Entity_Collection_Abstract
87
+ */
88
+ protected function _getProductCollection()
89
+ {
90
+ if (is_null($this->_productCollection)) {
91
+ $filters = array();
92
+ $request = $this->getRequest();
93
+ $requestParams = $request->getParams();
94
+ $layer = $this->getLayer();
95
+ if (!$layer) {
96
+ return null;
97
+ }
98
+ $category = $this->getCategory();
99
+ if ($category && is_object($category) && $category->getId()) {
100
+ $layer->setCurrentCategory($category);
101
+ }
102
+ if (!$this->getNeedBlockApplyingFilters()) {
103
+ $attributes = $layer->getFilterableAttributes();
104
+ /**
105
+ * Apply filters
106
+ */
107
+ foreach ($attributes as $attributeItem) {
108
+ $attributeCode = $attributeItem->getAttributeCode();
109
+ list($filterModel, $filterBlock) = $this->helper('xmlconnect')->getFilterByKey($attributeCode);
110
+
111
+ $filterModel->setLayer($layer)
112
+ ->setAttributeModel($attributeItem);
113
+
114
+ $filterParam = parent::REQUEST_FILTER_PARAM_REFIX . $attributeCode;
115
+ /**
116
+ * Set new request var
117
+ */
118
+ if (isset($requestParams[$filterParam])) {
119
+ $filterModel->setRequestVar($filterParam);
120
+ }
121
+ $filterModel->apply($request, $filterBlock);
122
+ $filters[] = $filterModel;
123
+ }
124
+
125
+ /**
126
+ * Separately apply and save category filter
127
+ */
128
+ list($categoryFilter, $categoryFilterBlock) = $this->helper('xmlconnect')->getFilterByKey('category');
129
+ $filterParam = parent::REQUEST_FILTER_PARAM_REFIX . $categoryFilter->getRequestVar();
130
+ $categoryFilter->setLayer($layer)
131
+ ->setRequestVar($filterParam)
132
+ ->apply($this->getRequest(), $categoryFilterBlock);
133
+ $filters[] = $categoryFilter;
134
+
135
+ $this->_collectedFilters = $filters;
136
+ }
137
+
138
+ /**
139
+ * Products
140
+ */
141
+ $layer = $this->getLayer();
142
+ $collection = $layer->getProductCollection();
143
+
144
+ /**
145
+ * Add rating and review summary, image attribute, apply sort params
146
+ */
147
+ $this->_prepareCollection($collection);
148
+
149
+ /**
150
+ * Apply offset and count
151
+ */
152
+ $offset = (int)$request->getParam('offset', 0);
153
+ $count = (int)$request->getParam('count', 0);
154
+ $count = $count <= 0 ? 1 : $count;
155
+ if ($offset + $count < $collection->getSize()) {
156
+ $this->setHasProductItems(1);
157
+ }
158
+ $collection->getSelect()->limit($count, $offset);
159
+
160
+ $collection->setFlag('require_stock_items', true);
161
+
162
+ $this->_productCollection = $collection;
163
+ }
164
+ return $this->_productCollection;
165
+ }
166
+
167
+ /**
168
+ * Add image attribute and apply sort fields to product collection
169
+ *
170
+ * @param Mage_Eav_Model_Entity_Collection_Abstract $collection
171
+ * @return Mage_XmlConnect_Block_Catalog_Product_List
172
+ */
173
+ protected function _prepareCollection($collection)
174
+ {
175
+ /**
176
+ * Apply sort params
177
+ */
178
+ $reguest = $this->getRequest();
179
+ foreach ($reguest->getParams() as $key => $value) {
180
+ if (0 === strpos($key, parent::REQUEST_SORT_ORDER_PARAM_REFIX)) {
181
+ $key = str_replace(parent::REQUEST_SORT_ORDER_PARAM_REFIX, '', $key);
182
+ if ($value != 'desc') {
183
+ $value = 'asc';
184
+ }
185
+ $collection->addAttributeToSort($key, $value);
186
+ }
187
+ }
188
+ $collection->addAttributeToSelect(array('image', 'name', 'description'));
189
+
190
+ return $this;
191
+ }
192
+
193
+ /**
194
+ * Render products list xml
195
+ *
196
+ * @return string
197
+ */
198
+ protected function _toHtml()
199
+ {
200
+ return $this->getProductsXmlObject()->asNiceXml();
201
+ }
202
+ }
app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options.php ADDED
@@ -0,0 +1,227 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Product Options xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Catalog_Product_Options extends Mage_XmlConnect_Block_Catalog
35
+ {
36
+ const OPTION_TYPE_SELECT = 'select';
37
+ const OPTION_TYPE_CHECKBOX = 'checkbox';
38
+ const OPTION_TYPE_TEXT = 'text';
39
+
40
+ /**
41
+ * Store supported product options xml renderers based on product types
42
+ *
43
+ * @var array
44
+ */
45
+ protected $_renderers = array();
46
+
47
+ /**
48
+ * Add new product options renderer
49
+ *
50
+ * @param string $type
51
+ * @param string $renderer
52
+ * @return Mage_XmlConnect_Block_Product_Options
53
+ */
54
+ public function addRenderer($type, $renderer)
55
+ {
56
+ if (!isset($this->_renderers[$type])) {
57
+ $this->_renderers[$type] = $renderer;
58
+ }
59
+ return $this;
60
+ }
61
+
62
+ /**
63
+ * Create product custom options Mage_XmlConnect_Model_Simplexml_Element object
64
+ *
65
+ * @param Mage_Catalog_Model_Product $product
66
+ * @return Mage_XmlConnect_Model_Simplexml_Element
67
+ */
68
+ public function getProductCustomOptionsXmlObject(Mage_Catalog_Model_Product $product)
69
+ {
70
+ $xmlModel = Mage::getModel('xmlconnect/simplexml_element', '<product></product>');
71
+ $optionsNode = $xmlModel->addChild('options');
72
+
73
+ if (!$product->getId()) {
74
+ return $xmlModel;
75
+ }
76
+ $xmlModel->addAttribute('id', $product->getId());
77
+ if (!$product->isSaleable() || !sizeof($product->getOptions())) {
78
+ return $xmlModel;
79
+ }
80
+
81
+ foreach ($product->getOptions() as $option) {
82
+ $optionNode = $optionsNode->addChild('option');
83
+ $type = $this->_getOptionTypeForXmlByRealType($option->getType());
84
+ $code = 'options[' . $option->getId() . ']';
85
+ if ($type == self::OPTION_TYPE_CHECKBOX) {
86
+ $code .= '[]';
87
+ }
88
+ $optionNode->addAttribute('code', $code);
89
+ $optionNode->addAttribute('type', $type);
90
+ $optionNode->addAttribute('label', $xmlModel->escapeXml($option->getTitle()));
91
+ if ($option->getIsRequire()) {
92
+ $optionNode->addAttribute('is_required', 1);
93
+ }
94
+
95
+ /**
96
+ * Process option price
97
+ */
98
+ $price = $option->getPrice();
99
+ if ($price) {
100
+ $optionNode->addAttribute(
101
+ 'price',
102
+ Mage::helper('xmlconnect')->formatPriceForXml($price)
103
+ );
104
+ $formattedPrice = Mage::app()->getStore(
105
+ $product->getStoreId())->formatPrice($price, false
106
+ );
107
+ $optionNode->addAttribute('formated_price', $formattedPrice);
108
+ }
109
+ if ($type == self::OPTION_TYPE_CHECKBOX
110
+ || $type == self::OPTION_TYPE_SELECT
111
+ ) {
112
+ foreach ($option->getValues() as $value) {
113
+ $valueNode = $optionNode->addChild('value');
114
+ $valueNode->addAttribute('code', $value->getId());
115
+ $valueNode->addAttribute('label', $xmlModel->escapeXml($value->getTitle()));
116
+
117
+ if ($value->getPrice() != 0) {
118
+ $price = Mage::helper('xmlconnect')->formatPriceForXml($value->getPrice());
119
+ $valueNode->addAttribute('price', $price);
120
+ $formattedPrice = $this->_formatPriceString($price, $product);
121
+ $valueNode->addAttribute('formated_price', $formattedPrice);
122
+ }
123
+ }
124
+ }
125
+ }
126
+ return $xmlModel;
127
+ }
128
+
129
+ /**
130
+ * Format price with currency code and taxes
131
+ *
132
+ * @param string|int|float $price
133
+ * @param Mage_Catalog_Model_Product $product
134
+ * @return string
135
+ */
136
+ protected function _formatPriceString($price, $product)
137
+ {
138
+ $priceTax = Mage::helper('tax')->getPrice($product, $price);
139
+ $priceIncTax = Mage::helper('tax')->getPrice($product, $price, true);
140
+
141
+ if (Mage::helper('tax')->displayBothPrices() && $priceTax != $priceIncTax) {
142
+ $formatted = Mage::helper('core')->currency($priceTax, true, false)
143
+ . ' (+'
144
+ . Mage::helper('core')->currency($priceIncTax, true, false)
145
+ . ' '
146
+ . Mage::helper('tax')->__('Incl. Tax')
147
+ . ')';
148
+ } else {
149
+ $formatted = $this->helper('core')->currency($priceTax, true, false);
150
+ }
151
+
152
+ return $formatted;
153
+ }
154
+
155
+ /**
156
+ * Retrieve option type name by specified option real type name
157
+ *
158
+ * @param string $realType
159
+ * @return string
160
+ */
161
+ protected function _getOptionTypeForXmlByRealType($realType)
162
+ {
163
+ switch ($realType) {
164
+ case Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN:
165
+ case Mage_Catalog_Model_Product_Option::OPTION_TYPE_RADIO:
166
+ $type = self::OPTION_TYPE_SELECT;
167
+ break;
168
+ case Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE:
169
+ case Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX:
170
+ $type = self::OPTION_TYPE_CHECKBOX;
171
+ break;
172
+ case Mage_Catalog_Model_Product_Option::OPTION_TYPE_FIELD:
173
+ case Mage_Catalog_Model_Product_Option::OPTION_TYPE_AREA:
174
+ default:
175
+ $type = self::OPTION_TYPE_TEXT;
176
+ break;
177
+ }
178
+ return $type;
179
+ }
180
+
181
+ /**
182
+ * Create produc custom options Mage_XmlConnect_Model_Simplexml_Element object
183
+ *
184
+ * @param Mage_Catalog_Model_Product $product
185
+ * @return Mage_XmlConnect_Model_Simplexml_Element | false
186
+ */
187
+ public function getProductOptionsXmlObject(Mage_Catalog_Model_Product $product)
188
+ {
189
+ if ($product->getId()) {
190
+ $type = $product->getTypeId();
191
+ if (isset($this->_renderers[$type])) {
192
+ $renderer = $this->getLayout()->createBlock($this->_renderers[$type]);
193
+ if ($renderer) {
194
+ return $renderer->getProductOptionsXml($product, true);
195
+ }
196
+ }
197
+ }
198
+ return false;
199
+ }
200
+
201
+ /**
202
+ * Generate product options xml
203
+ *
204
+ * @return string
205
+ */
206
+ protected function _toHtml()
207
+ {
208
+ $productId = $this->getRequest()->getParam('id', null);
209
+ $product = Mage::getModel('catalog/product')
210
+ ->setStoreId(Mage::app()->getStore()->getId());
211
+
212
+ if ($productId) {
213
+ $product->load($productId);
214
+ }
215
+
216
+ if ($product->getId()) {
217
+ $type = $product->getTypeId();
218
+ if (isset($this->_renderers[$type])) {
219
+ $renderer = $this->getLayout()->createBlock($this->_renderers[$type]);
220
+ if ($renderer) {
221
+ return $renderer->getProductOptionsXml($product);
222
+ }
223
+ }
224
+ }
225
+ return '<?xml version="1.0" encoding="UTF-8"?><options/>';
226
+ }
227
+ }
app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Bundle.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Bundle product options xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Catalog_Product_Options_Bundle
35
+ extends Mage_XmlConnect_Block_Catalog_Product_Options
36
+ {
37
+ /**
38
+ * Generate bundle product options xml
39
+ *
40
+ * @param Mage_Catalog_Model_Product $product
41
+ * @param bool $isObject
42
+ * @return string | Mage_XmlConnect_Model_Simplexml_Element
43
+ */
44
+ public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObject = false)
45
+ {
46
+
47
+ $xmlModel = $this->getProductCustomOptionsXmlObject($product);
48
+ $optionsXmlObj = $xmlModel->options;
49
+
50
+ if (!$product->isSaleable()) {
51
+ return $isObject ? $xmlModel : $xmlModel->asNiceXml();
52
+ }
53
+
54
+ /**
55
+ * Bundle options
56
+ */
57
+ $product->getTypeInstance(true)->setStoreFilter($product->getStoreId(), $product);
58
+ $optionCollection = $product->getTypeInstance(true)->getOptionsCollection($product);
59
+ $selectionCollection = $product->getTypeInstance(true)->getSelectionsCollection(
60
+ $product->getTypeInstance(true)->getOptionsIds($product),
61
+ $product
62
+ );
63
+ $bundleOptions = $optionCollection->appendSelections($selectionCollection, false, false);
64
+ if (!sizeof($bundleOptions)) {
65
+ return $isObject ? $xmlModel : $xmlModel->asNiceXml();
66
+ }
67
+
68
+ foreach ($bundleOptions as $_option) {
69
+ $selections = $_option->getSelections();
70
+ if (empty($selections)) {
71
+ continue;
72
+ }
73
+
74
+ $optionNode = $optionsXmlObj->addChild('option');
75
+
76
+ $type = parent::OPTION_TYPE_SELECT;
77
+ if ($_option->isMultiSelection()) {
78
+ $type = parent::OPTION_TYPE_CHECKBOX;
79
+ }
80
+ $code = 'bundle_option[' . $_option->getId() . ']';
81
+ if ($type == parent::OPTION_TYPE_CHECKBOX) {
82
+ $code .= '[]';
83
+ }
84
+ $optionNode->addAttribute('code', $code);
85
+ $optionNode->addAttribute('type', $type);
86
+ $optionNode->addAttribute('label', $optionsXmlObj->escapeXml($_option->getTitle()));
87
+ if ($_option->getRequired()) {
88
+ $optionNode->addAttribute('is_required', 1);
89
+ }
90
+
91
+ // $_default = $_option->getDefaultSelection();
92
+
93
+ foreach ($selections as $_selection) {
94
+ if (!$_selection->isSaleable()) {
95
+ continue;
96
+ }
97
+ $_qty = !($_selection->getSelectionQty() * 1) ? '1' : $_selection->getSelectionQty() * 1;
98
+
99
+ $valueNode = $optionNode->addChild('value');
100
+ $valueNode->addAttribute('code', $_selection->getSelectionId());
101
+ $valueNode->addAttribute('label', $optionsXmlObj->escapeXml($_selection->getName()));
102
+ if (!$_option->isMultiSelection()) {
103
+ if ($_selection->getSelectionCanChangeQty()) {
104
+ $valueNode->addAttribute('is_qty_editable', 1);
105
+ }
106
+ }
107
+ $valueNode->addAttribute('qty', $_qty);
108
+
109
+ $price = $product->getPriceModel()->getSelectionPreFinalPrice($product, $_selection);
110
+ $price = Mage::helper('xmlconnect')->formatPriceForXml($price);
111
+ if ((float)$price != 0.00) {
112
+ $valueNode->addAttribute('price', Mage::helper('xmlconnect')->formatPriceForXml(
113
+ Mage::helper('core')->currency($price, false, false)
114
+ ));
115
+ $valueNode->addAttribute('formated_price', $this->_formatPriceString($price, $product));
116
+ }
117
+ // $_selection->getIsDefault();
118
+ }
119
+ }
120
+
121
+ return $isObject ? $xmlModel : $xmlModel->asNiceXml();
122
+ }
123
+ }
app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Configurable.php ADDED
@@ -0,0 +1,236 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Configurable product options xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Catalog_Product_Options_Configurable
35
+ extends Mage_XmlConnect_Block_Catalog_Product_Options
36
+ {
37
+ /**
38
+ * Generate bundle product options xml
39
+ *
40
+ * @param Mage_Catalog_Model_Product $product
41
+ * @param bool $isObject
42
+ * @return string | Mage_XmlConnect_Model_Simplexml_Element
43
+ */
44
+ public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObject = false)
45
+ {
46
+ $xmlModel = $this->getProductCustomOptionsXmlObject($product);
47
+ $optionsXmlObj = $xmlModel->options;
48
+ $options = array();
49
+
50
+ if (!$product->isSaleable()) {
51
+ return $isObject ? $xmlModel : $xmlModel->asNiceXml();
52
+ }
53
+
54
+ /**
55
+ * Configurable attributes
56
+ */
57
+ $_attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
58
+ if (!sizeof($_attributes)) {
59
+ return $isObject ? $xmlModel : $xmlModel->asNiceXml();
60
+ }
61
+
62
+ $_allowProducts = array();
63
+ $_allProducts = $product->getTypeInstance(true)->getUsedProducts(null, $product);
64
+ foreach ($_allProducts as $_product) {
65
+ if ($_product->isSaleable()) {
66
+ $_allowProducts[] = $_product;
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Allowed products options
72
+ */
73
+ foreach ($_allowProducts as $_item) {
74
+ $_productId = $_item->getId();
75
+
76
+ foreach ($_attributes as $attribute) {
77
+ $productAttribute = $attribute->getProductAttribute();
78
+ $attributeValue = $_item->getData($productAttribute->getAttributeCode());
79
+ if (!isset($options[$productAttribute->getId()])) {
80
+ $options[$productAttribute->getId()] = array();
81
+ }
82
+
83
+ if (!isset($options[$productAttribute->getId()][$attributeValue])) {
84
+ $options[$productAttribute->getId()][$attributeValue] = array();
85
+ }
86
+ $options[$productAttribute->getId()][$attributeValue][] = $_productId;
87
+ }
88
+ }
89
+
90
+ foreach ($_attributes as $attribute) {
91
+ $productAttribute = $attribute->getProductAttribute();
92
+ $attributeId = $productAttribute->getId();
93
+ $info = array(
94
+ 'id' => $productAttribute->getId(),
95
+ 'label' => $attribute->getLabel(),
96
+ 'options' => array()
97
+ );
98
+
99
+ $prices = $attribute->getPrices();
100
+ if (is_array($prices)) {
101
+ foreach ($prices as $value) {
102
+ if (!isset($options[$attributeId][$value['value_index']])) {
103
+ continue;
104
+ }
105
+ $price = Mage::helper('xmlconnect')->formatPriceForXml(
106
+ $this->_preparePrice($product, $value['pricing_value'], $value['is_percent'])
107
+ );
108
+ $optionProducts = array();
109
+ if (isset($options[$attributeId][$value['value_index']])) {
110
+ $optionProducts = $options[$attributeId][$value['value_index']];
111
+ }
112
+ $info['options'][] = array(
113
+ 'id' => $value['value_index'],
114
+ 'label' => $value['label'],
115
+ 'price' => $price,
116
+ 'formated_price' => $this->_formatPriceString($price, $product),
117
+ 'products' => $optionProducts,
118
+ );
119
+ }
120
+ }
121
+
122
+ if (sizeof($info['options']) > 0) {
123
+ $attributes[$attributeId] = $info;
124
+ }
125
+ }
126
+
127
+ $isFirst = true;
128
+
129
+ $_attributes = $attributes;
130
+ reset($_attributes);
131
+ foreach ($attributes as $id => $attribute) {
132
+ $optionNode = $optionsXmlObj->addChild('option');
133
+ $optionNode->addAttribute('code', 'super_attribute[' . $id . ']');
134
+ $optionNode->addAttribute('type', 'select');
135
+ $optionNode->addAttribute('label', $optionsXmlObj->escapeXml($attribute['label']));
136
+ $optionNode->addAttribute('is_required', 1);
137
+ if ($isFirst) {
138
+ foreach ($attribute['options'] as $option) {
139
+ $valueNode = $optionNode->addChild('value');
140
+ $valueNode->addAttribute('code', $option['id']);
141
+ $valueNode->addAttribute('label', $optionsXmlObj->escapeXml($option['label']));
142
+ if ((float)$option['price'] != 0.00) {
143
+ $valueNode->addAttribute('price', $option['price']);
144
+ $valueNode->addAttribute('formated_price', $option['formated_price']);
145
+ }
146
+ if (sizeof($_attributes) > 1) {
147
+ $this->_prepareRecursivelyRelatedValues(
148
+ $valueNode,
149
+ $_attributes,
150
+ $option['products'],
151
+ 1
152
+ );
153
+ }
154
+ }
155
+ $isFirst = false;
156
+ }
157
+ }
158
+
159
+ return $isObject ? $xmlModel : $xmlModel->asNiceXml();
160
+ }
161
+
162
+ /**
163
+ * Add recursively relations on each option
164
+ *
165
+ * @param Mage_XmlConnect_Model_Simplexml_Element &$valueNode value node object
166
+ * @param array $attributes all products attributes (options)
167
+ * @param array $productIds prodcuts to search in next levels attributes
168
+ * @param int $cycle
169
+ */
170
+ protected function _prepareRecursivelyRelatedValues(&$valueNode, $attributes, $productIds, $cycle = 1)
171
+ {
172
+ $relatedNode = null;
173
+
174
+ for ($i = 0; $i < $cycle; $i++) {
175
+ next($attributes);
176
+ }
177
+ $attribute = current($attributes);
178
+ $attrId = key($attributes);
179
+ foreach ($attribute['options'] as $option) {
180
+ /**
181
+ * Search products in option
182
+ */
183
+ $intersect = array_intersect($productIds, $option['products']);
184
+
185
+ if (empty($intersect)) {
186
+ continue;
187
+ }
188
+
189
+ if ($relatedNode === null) {
190
+ $relatedNode = $valueNode->addChild('relation');
191
+ $relatedNode->addAttribute('to', 'super_attribute[' . $attrId . ']');
192
+ }
193
+
194
+ $_valueNode = $relatedNode->addChild('value');
195
+ $_valueNode->addAttribute('code', $option['id']);
196
+ $_valueNode->addAttribute('label', $_valueNode->escapeXml($option['label']));
197
+ if ((float)$option['price'] != 0.00) {
198
+ $_valueNode->addAttribute('price', $option['price']);
199
+ $_valueNode->addAttribute('formated_price', $option['formated_price']);
200
+ }
201
+
202
+ /**
203
+ * Recursive relation adding
204
+ */
205
+ $_attrClone = $attributes;
206
+ if (next($_attrClone) != false) {
207
+ reset($_attrClone);
208
+ $this->_prepareRecursivelyRelatedValues(
209
+ $_valueNode,
210
+ $_attrClone,
211
+ $intersect,
212
+ $cycle + 1
213
+ );
214
+ }
215
+ }
216
+ }
217
+
218
+ /**
219
+ * Prepare price accordingly to percentage and store rates and round its
220
+ *
221
+ * @param Mage_Catalog_Model_Product $product
222
+ * @param float|int|string $price
223
+ * @param bool $isPercent
224
+ * @return float
225
+ */
226
+ protected function _preparePrice($product, $price, $isPercent = false)
227
+ {
228
+ if ($isPercent && !empty($price)) {
229
+ $price = $product->getFinalPrice() * $price / 100;
230
+ }
231
+
232
+ $price = Mage::app()->getStore()->convertPrice($price);
233
+ $price = Mage::app()->getStore()->roundPrice($price);
234
+ return $price;
235
+ }
236
+ }
app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Giftcard.php ADDED
@@ -0,0 +1,316 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Gift Card product options xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Catalog_Product_Options_Giftcard
35
+ extends Mage_XmlConnect_Block_Catalog_Product_Options
36
+ {
37
+ /**
38
+ * Get sender name
39
+ *
40
+ * @return string
41
+ */
42
+ public function getSenderName()
43
+ {
44
+ $senderName = $this->getDefaultValue('giftcard_sender_name');
45
+ if (!strlen($senderName)) {
46
+ $firstName = (string) Mage::getSingleton('customer/session')->getCustomer()->getFirstname();
47
+ $lastName = (string) Mage::getSingleton('customer/session')->getCustomer()->getLastname();
48
+
49
+ if ($firstName && $lastName) {
50
+ $senderName = $firstName . ' ' . $lastName;
51
+ } else {
52
+ $senderName = '';
53
+ }
54
+ }
55
+ return $senderName;
56
+ }
57
+
58
+ /**
59
+ * Get sender email
60
+ *
61
+ * @return string
62
+ */
63
+ public function getSenderEmail()
64
+ {
65
+ $senderEmail = $this->getDefaultValue('giftcard_sender_email');
66
+
67
+ if (!strlen($senderEmail)) {
68
+ $senderEmail = (string) Mage::getSingleton('customer/session')->getCustomer()->getEmail();
69
+ }
70
+ return $senderEmail;
71
+ }
72
+
73
+ /**
74
+ * Get pre-configured values from product
75
+ *
76
+ * @param $value param id
77
+ * @return string
78
+ */
79
+ protected function getDefaultValue($value)
80
+ {
81
+ if ($this->getProduct()) {
82
+ return (string) $this->getProduct()->getPreconfiguredValues()->getData($value);
83
+ } else {
84
+ return '';
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Check is message available for current product
90
+ *
91
+ * @param Mage_Catalog_Model_Product $product
92
+ * @return bool|int
93
+ */
94
+ public function isMessageAvailable(Mage_Catalog_Model_Product $product)
95
+ {
96
+ if ($product->getUseConfigAllowMessage()) {
97
+ return Mage::getStoreConfigFlag(Enterprise_GiftCard_Model_Giftcard::XML_PATH_ALLOW_MESSAGE);
98
+ } else {
99
+ return (int) $product->getAllowMessage();
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Check is email available for product
105
+ *
106
+ * @param Mage_Catalog_Model_Product $product
107
+ * @return bool
108
+ */
109
+ public function isEmailAvailable(Mage_Catalog_Model_Product $product)
110
+ {
111
+ if ($product->getTypeInstance()->isTypePhysical()) {
112
+ return false;
113
+ }
114
+ return true;
115
+ }
116
+
117
+ /**
118
+ * Is amount available for product
119
+ *
120
+ * @param Mage_Catalog_Model_Product $product
121
+ * @return bool
122
+ */
123
+ public function isAmountAvailable(Mage_Catalog_Model_Product $product)
124
+ {
125
+ if (!$product->getGiftcardAmounts()) {
126
+ return false;
127
+ }
128
+ return true;
129
+ }
130
+
131
+ /**
132
+ * Generate gift card product options xml
133
+ *
134
+ * @param Mage_Catalog_Model_Product $product
135
+ * @param bool $isObject
136
+ * @return string | Mage_XmlConnect_Model_Simplexml_Element
137
+ */
138
+ public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObject = false)
139
+ {
140
+ /** set current product object */
141
+ $this->setProduct($product);
142
+
143
+ /** @var $xmlModel Mage_XmlConnect_Model_Simplexml_Element */
144
+ $xmlModel = $this->getProductCustomOptionsXmlObject($product);
145
+
146
+ /** @var $optionsXmlObj Mage_XmlConnect_Model_Simplexml_Element */
147
+ $optionsXmlObj = $xmlModel->options;
148
+
149
+ if (!$product->isSalable()) {
150
+ return $isObject ? $xmlModel : $xmlModel->asNiceXml();
151
+ }
152
+
153
+ /** @var $priceModel Enterprise_GiftCard_Block_Catalog_Product_Price */
154
+ $priceModel = $product->getPriceModel();
155
+
156
+ /** @var $coreHelper Mage_Core_Helper_Data */
157
+ $coreHelper = Mage::helper('core');
158
+
159
+ $configValue = $this->getDefaultValue('giftcard_amount');
160
+
161
+ /**
162
+ * Render fixed amounts options
163
+ */
164
+
165
+ /** @var $fixedAmountsNode Mage_XmlConnect_Model_Simplexml_Element */
166
+ $fixedAmountsNode = $optionsXmlObj->addChild('fixed_amounts');
167
+ if ($this->isAmountAvailable($product)) {
168
+ $amounts = $priceModel->getSortedAmounts($product);
169
+ if (count($amounts)) {
170
+ foreach ($amounts as $price) {
171
+ $amountNode = $fixedAmountsNode->addChild('amount');
172
+ if ($configValue == $price) {
173
+ $amountNode->addAttribute('selected', 1);
174
+ }
175
+ $amountNode->addAttribute(
176
+ 'formatted_price',
177
+ $xmlModel->xmlAttribute(
178
+ $coreHelper->currency($price, true, false)
179
+ )
180
+ );
181
+ $amountNode->addAttribute('price', $price);
182
+ }
183
+ }
184
+ }
185
+
186
+ /**
187
+ * Render open amount options
188
+ */
189
+
190
+ /** @var $openAmountNode Mage_XmlConnect_Model_Simplexml_Element */
191
+ $openAmountNode = $optionsXmlObj->addChild('open_amount');
192
+ if ($product->getAllowOpenAmount()) {
193
+ $openAmountNode->addAttribute('enabled', 1);
194
+
195
+ if ($configValue == 'custom') {
196
+ $openAmountNode->addAttribute(
197
+ 'selected_amount',
198
+ $this->getDefaultValue('custom_giftcard_amount')
199
+ );
200
+ }
201
+ if ($priceModel->getMinAmount($product)) {
202
+ $minPrice = $product->getOpenAmountMin();
203
+ $minAmount = $coreHelper->currency($minPrice, true, false);
204
+ } else {
205
+ $minAmount = $minPrice = 0;
206
+ }
207
+ $openAmountNode->addAttribute(
208
+ 'formatted_min_amount',
209
+ $xmlModel->xmlAttribute($minAmount)
210
+ );
211
+ $openAmountNode->addAttribute('min_amount', $minPrice);
212
+
213
+ if ($priceModel->getMaxAmount($product)) {
214
+ $maxPrice = $product->getOpenAmountMax();
215
+ $maxAmount = $coreHelper->currency($maxPrice, true, false);
216
+ } else {
217
+ $maxAmount = $maxPrice = 0;
218
+ }
219
+ $openAmountNode->addAttribute(
220
+ 'formatted_max_amount',
221
+ $xmlModel->xmlAttribute($maxAmount)
222
+ );
223
+ $openAmountNode->addAttribute('max_amount', $maxPrice);
224
+ } else {
225
+ $openAmountNode->addAttribute('enabled', 0);
226
+ }
227
+
228
+ /**
229
+ * Render Gift Card form options
230
+ */
231
+ $form = $optionsXmlObj->addCustomChild(
232
+ 'form',
233
+ null,
234
+ array(
235
+ 'name' => 'giftcard-send-form',
236
+ 'method' => 'post'
237
+ )
238
+ );
239
+
240
+ $senderFieldset = $form->addCustomChild(
241
+ 'fieldset',
242
+ null,
243
+ array(
244
+ 'legend' => $this->__('Sender Information')
245
+ )
246
+ );
247
+
248
+ $senderFieldset->addField(
249
+ 'giftcard_sender_name',
250
+ 'text',
251
+ array(
252
+ 'label' => Mage::helper('enterprise_giftcard')->__('Sender Name'),
253
+ 'required' => 'true',
254
+ 'value' => $this->getSenderName()
255
+ )
256
+ );
257
+
258
+ $recipientFieldset = $form->addCustomChild(
259
+ 'fieldset',
260
+ null,
261
+ array(
262
+ 'legend' => $this->__('Recipient Information')
263
+ )
264
+ );
265
+
266
+ $recipientFieldset->addField(
267
+ 'giftcard_recipient_name',
268
+ 'text',
269
+ array(
270
+ 'label' => Mage::helper('enterprise_giftcard')->__('Recipient Name'),
271
+ 'required' => 'true',
272
+ 'value' => $this->getDefaultValue('giftcard_recipient_name')
273
+ )
274
+ );
275
+
276
+ if ($this->isEmailAvailable($product)) {
277
+ $senderFieldset->addField(
278
+ 'giftcard_sender_email',
279
+ 'email',
280
+ array(
281
+ 'label' => Mage::helper('enterprise_giftcard')->__('Sender Email'),
282
+ 'required' => 'true',
283
+ 'value' => $this->getSenderEmail()
284
+ )
285
+ );
286
+
287
+ $recipientFieldset->addField(
288
+ 'giftcard_recipient_email',
289
+ 'email',
290
+ array(
291
+ 'label' => Mage::helper('enterprise_giftcard')->__('Recipient Email'),
292
+ 'required' => 'true',
293
+ 'value' => $this->getDefaultValue('giftcard_recipient_email')
294
+ )
295
+ );
296
+ }
297
+
298
+ if ($this->isMessageAvailable($product)) {
299
+ $messageMaxLength = (int) Mage::getStoreConfig(
300
+ Enterprise_GiftCard_Model_Giftcard::XML_PATH_MESSAGE_MAX_LENGTH
301
+ );
302
+ $recipientFieldset->addField(
303
+ 'giftcard_message',
304
+ 'textarea',
305
+ array(
306
+ 'label' => Mage::helper('enterprise_giftcard')->__('Message'),
307
+ 'required' => 'false',
308
+ 'max_length'=> $messageMaxLength,
309
+ 'value' => $this->getDefaultValue('giftcard_message')
310
+ )
311
+ );
312
+ }
313
+
314
+ return $isObject ? $xmlModel : $xmlModel->asNiceXml();
315
+ }
316
+ }
app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Grouped.php ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Grouped product options xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Catalog_Product_Options_Grouped
35
+ extends Mage_XmlConnect_Block_Catalog_Product_Options
36
+ {
37
+ /**
38
+ * Generate bundle product options xml
39
+ *
40
+ * @param Mage_Catalog_Model_Product $product
41
+ * @param bool $isObject
42
+ * @return string | Mage_XmlConnect_Model_Simplexml_Element
43
+ */
44
+ public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObject = false)
45
+ {
46
+ $xmlModel = Mage::getModel('xmlconnect/simplexml_element', '<product></product>');
47
+ $optionsNode = $xmlModel->addChild('options');
48
+
49
+ if (!$product->getId()) {
50
+ return $isObject ? $xmlModel : $xmlModel->asNiceXml();
51
+ }
52
+ $xmlModel->addAttribute('id', $product->getId());
53
+ if (!$product->isSaleable()) {
54
+ return $isObject ? $xmlModel : $xmlModel->asNiceXml();
55
+ }
56
+ /**
57
+ * Grouped (associated) products
58
+ */
59
+ $_associatedProducts = $product->getTypeInstance(true)->getAssociatedProducts($product);
60
+ if (!sizeof($_associatedProducts)) {
61
+ return $isObject ? $xmlModel : $xmlModel->asNiceXml();
62
+ }
63
+
64
+ foreach ($_associatedProducts as $_item) {
65
+ if (!$_item->isSaleable()) {
66
+ continue;
67
+ }
68
+ $optionNode = $optionsNode->addChild('option');
69
+
70
+ $optionNode->addAttribute('code', 'super_group[' . $_item->getId() . ']');
71
+ $optionNode->addAttribute('type', 'product');
72
+ $optionNode->addAttribute('label', $xmlModel->escapeXml($_item->getName()));
73
+ $optionNode->addAttribute('is_qty_editable', 1);
74
+ $optionNode->addAttribute('qty', $_item->getQty()*1);
75
+
76
+ /**
77
+ * Process product price
78
+ */
79
+ if ($_item->getPrice() != $_item->getFinalPrice()) {
80
+ $productPrice = $_item->getFinalPrice();
81
+ } else {
82
+ $productPrice = $_item->getPrice();
83
+ }
84
+
85
+ if ($productPrice != 0) {
86
+ $productPrice = Mage::helper('xmlconnect')->formatPriceForXml($productPrice);
87
+ $optionNode->addAttribute(
88
+ 'price',
89
+ Mage::helper('xmlconnect')->formatPriceForXml(
90
+ Mage::helper('core')->currency($productPrice, false, false)
91
+ )
92
+ );
93
+ $optionNode->addAttribute(
94
+ 'formated_price',
95
+ $this->_formatPriceString($productPrice, $product)
96
+ );
97
+ }
98
+ }
99
+
100
+ return $isObject ? $xmlModel : $xmlModel->asNiceXml();
101
+ }
102
+ }
app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Simple.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Simple product options xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Catalog_Product_Options_Simple
35
+ extends Mage_XmlConnect_Block_Catalog_Product_Options
36
+ {
37
+ /**
38
+ * Generate simple product options xml
39
+ *
40
+ * @param Mage_Catalog_Model_Product $product
41
+ * @param bool $isObject
42
+ * @return string | Mage_XmlConnect_Model_Simplexml_Element
43
+ */
44
+ public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObject = false)
45
+ {
46
+ $xmlModel = $this->getProductCustomOptionsXmlObject($product);
47
+ return $isObject ? $xmlModel : $xmlModel->asNiceXml();
48
+ }
49
+ }
app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Virtual.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Virtual product options xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Catalog_Product_Options_Virtual
35
+ extends Mage_XmlConnect_Block_Catalog_Product_Options
36
+ {
37
+ /**
38
+ * Generate virtual product options xml
39
+ *
40
+ * @param Mage_Catalog_Model_Product $product
41
+ * @param bool $isObject
42
+ * @return string | Mage_XmlConnect_Model_Simplexml_Element
43
+ */
44
+ public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObject = false)
45
+ {
46
+ $xmlModel = $this->getProductCustomOptionsXmlObject($product);
47
+ return $isObject ? $xmlModel : $xmlModel->asNiceXml();
48
+ }
49
+ }
app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price.php ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Product price xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Catalog_Product_Price extends Mage_XmlConnect_Block_Catalog
35
+ {
36
+ /**
37
+ * Default product price renderer block factory name
38
+ *
39
+ * @var string
40
+ */
41
+ protected $_defaultPriceRenderer = 'xmlconnect/catalog_product_price_default';
42
+
43
+ /**
44
+ * Store supported product price xml renderers based on product types
45
+ *
46
+ * @var array
47
+ */
48
+ protected $_renderers = array();
49
+
50
+ /**
51
+ * Store already initialized renderers instances
52
+ *
53
+ * @var array
54
+ */
55
+ protected $_renderersInstances = array();
56
+
57
+ /**
58
+ * Add new product price renderer
59
+ *
60
+ * @param string $type
61
+ * @param string $renderer
62
+ * @return Mage_XmlConnect_Block_Product_Options
63
+ */
64
+ public function addRenderer($type, $renderer)
65
+ {
66
+ if (!isset($this->_renderers[$type])) {
67
+ $this->_renderers[$type] = $renderer;
68
+ }
69
+ return $this;
70
+ }
71
+
72
+ /**
73
+ * Collect product prices to current xml object
74
+ */
75
+ public function collectProductPrices()
76
+ {
77
+ $product = $this->getProduct();
78
+ $xmlObject = $this->getProductXmlObj();
79
+
80
+ if ($product && $product->getId()) {
81
+ $type = $product->getTypeId();
82
+ if (isset($this->_renderers[$type])) {
83
+ $blockName = $this->_renderers[$type];
84
+ } else {
85
+ $blockName = $this->_defaultPriceRenderer;
86
+ }
87
+
88
+ $renderer = $this->getLayout()->getBlock($blockName);
89
+ if (!$renderer) {
90
+ $renderer = $this->getLayout()->createBlock($blockName);
91
+ }
92
+
93
+ if ($renderer) {
94
+ $renderer->collectProductPrices($product, $xmlObject);
95
+ }
96
+ }
97
+ }
98
+ }
app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Bundle.php ADDED
@@ -0,0 +1,425 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Bundle product price xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Catalog_Product_Price_Bundle
35
+ extends Mage_Bundle_Block_Catalog_Product_Price
36
+ {
37
+ /**
38
+ * Collect product prices to specified item xml object
39
+ *
40
+ * @param Mage_Catalog_Model_Product $product
41
+ * @param Mage_XmlConnect_Model_Simplexml_Element $item
42
+ */
43
+ public function collectProductPrices(
44
+ Mage_Catalog_Model_Product $product,
45
+ Mage_XmlConnect_Model_Simplexml_Element $item
46
+ )
47
+ {
48
+ $this->setProduct($product)
49
+ ->setDisplayMinimalPrice(true)
50
+ ->setUseLinkForAsLowAs(false);
51
+
52
+ $priceXmlObj = $item->addChild('price');
53
+
54
+ /** @var $_coreHelper Mage_Core_Helper_Data */
55
+ $_coreHelper = $this->helper('core');
56
+ /** @var $_weeeHelper Mage_Weee_Helper_Data */
57
+ $_weeeHelper = $this->helper('weee');
58
+ /** @var $_taxHelper Mage_Tax_Helper_Data */
59
+ $_taxHelper = $this->helper('tax');
60
+
61
+ $_tierPrices = $this->_getTierPrices($product);
62
+
63
+ if (count($_tierPrices) > 0) {
64
+ $tierPricesTextArray = array();
65
+ foreach ($_tierPrices as $_price) {
66
+ $discount = ' ' . ($_price['price'] * 1) . '%';
67
+ $tierPricesTextArray[] = $this->__('Buy %1$s with %2$s discount each', $_price['price_qty'], $discount);
68
+ }
69
+ $item->addChild('price_tier', implode(PHP_EOL, $tierPricesTextArray));
70
+ }
71
+
72
+ list($_minimalPrice, $_maximalPrice) = $product->getPriceModel()->getPrices($product);
73
+
74
+ $_weeeTaxAmount = 0;
75
+ $_minimalPriceTax = $_taxHelper->getPrice($product, $_minimalPrice);
76
+ $_minimalPriceInclTax = $_taxHelper->getPrice($product, $_minimalPrice, true);
77
+
78
+ if ($product->getPriceType() == 1) {
79
+ $_weeeTaxAmount = $_weeeHelper->getAmount($product);
80
+ if ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, array(0, 1, 4))) {
81
+ $_minimalPriceTax += $_weeeTaxAmount;
82
+ $_minimalPriceInclTax += $_weeeTaxAmount;
83
+ }
84
+ if ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 2)) {
85
+ $_minimalPriceInclTax += $_weeeTaxAmount;
86
+ }
87
+
88
+ if ($_weeeHelper->typeOfDisplay($product, array(1, 2, 4))) {
89
+ $_weeeTaxAttributes = $_weeeHelper->getProductWeeeAttributesForDisplay($product);
90
+ }
91
+ }
92
+
93
+ if ($product->getPriceView()) {
94
+ if ($_taxHelper->displayBothPrices()) {
95
+ $priceXmlObj->addAttribute(
96
+ 'as_low_as_excluding_tax',
97
+ $_coreHelper->currency($_minimalPriceTax, true, false)
98
+ );
99
+ if ($_weeeTaxAmount && $product->getPriceType() == 1
100
+ && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4))
101
+ ) {
102
+ $weeeXmlObj = $priceXmlObj->addChild('weee');
103
+ $_weeeSeparator = ' + ';
104
+ $weeeXmlObj->addAttribute('separator', $_weeeSeparator);
105
+ foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
106
+ if ($_weeeHelper->typeOfDisplay($product, array(2, 4))) {
107
+ $amount = $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount();
108
+ } else {
109
+ $amount = $_weeeTaxAttribute->getAmount();
110
+ }
111
+ $weeeItemXmlObj = $weeeXmlObj->addChild('item');
112
+ $weeeItemXmlObj->addAttribute(
113
+ 'name',
114
+ $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
115
+ );
116
+ $weeeItemXmlObj->addAttribute(
117
+ 'amount',
118
+ $_coreHelper->currency($amount, true, false)
119
+ );
120
+ }
121
+ }
122
+ $priceXmlObj->addAttribute(
123
+ 'as_low_as_including_tax',
124
+ $_coreHelper->currency($_minimalPriceInclTax, true, false)
125
+ );
126
+ } else {
127
+ $priceXmlObj->addAttribute(
128
+ 'as_low_as',
129
+ $_coreHelper->currency($_minimalPriceTax, true, false)
130
+ );
131
+ if ($_weeeTaxAmount && $product->getPriceType() == 1
132
+ && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4))
133
+ ) {
134
+ $weeeXmlObj = $priceXmlObj->addChild('weee');
135
+ $_weeeSeparator = ' + ';
136
+ $weeeXmlObj->addAttribute('separator', $_weeeSeparator);
137
+ foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
138
+ if ($_weeeHelper->typeOfDisplay($product, array(2, 4))) {
139
+ $amount = $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount();
140
+ } else {
141
+ $amount = $_weeeTaxAttribute->getAmount();
142
+ }
143
+ $weeeItemXmlObj = $weeeXmlObj->addChild('item');
144
+ $weeeItemXmlObj->addAttribute(
145
+ 'name',
146
+ $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
147
+ );
148
+ $weeeItemXmlObj->addAttribute(
149
+ 'amount',
150
+ $_coreHelper->currency($amount, true, false)
151
+ );
152
+ }
153
+ }
154
+ if ($_weeeHelper->typeOfDisplay($product, 2) && $_weeeTaxAmount) {
155
+ $priceXmlObj->addAttribute(
156
+ 'as_low_as_including_tax',
157
+ $_coreHelper->currency($_minimalPriceInclTax, true, false)
158
+ );
159
+ }
160
+ }
161
+ /**
162
+ * if ($product->getPriceView()) {
163
+ */
164
+ } else {
165
+ if ($_minimalPrice <> $_maximalPrice) {
166
+ if ($_taxHelper->displayBothPrices()) {
167
+ $priceXmlObj->addAttribute(
168
+ 'from_excluding_tax',
169
+ $_coreHelper->currency($_minimalPriceTax, true, false)
170
+ );
171
+ if ($_weeeTaxAmount && $product->getPriceType() == 1
172
+ && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4))
173
+ ) {
174
+ $weeeXmlObj = $priceXmlObj->addChild('from_weee');
175
+ $_weeeSeparator = ' + ';
176
+ $weeeXmlObj->addAttribute('separator', $_weeeSeparator);
177
+ foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
178
+ if ($_weeeHelper->typeOfDisplay($product, array(2, 4))) {
179
+ $amount = $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount();
180
+ } else {
181
+ $amount = $_weeeTaxAttribute->getAmount();
182
+ }
183
+ $weeeItemXmlObj = $weeeXmlObj->addChild('item');
184
+ $weeeItemXmlObj->addAttribute(
185
+ 'name',
186
+ $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
187
+ );
188
+ $weeeItemXmlObj->addAttribute(
189
+ 'amount',
190
+ $_coreHelper->currency($amount, true, false)
191
+ );
192
+ }
193
+ }
194
+ $priceXmlObj->addAttribute(
195
+ 'from_including_tax',
196
+ $_coreHelper->currency($_minimalPriceInclTax, true, false)
197
+ );
198
+ } else {
199
+ $priceXmlObj->addAttribute(
200
+ 'from',
201
+ $_coreHelper->currency($_minimalPriceTax, true, false)
202
+ );
203
+ if ($_weeeTaxAmount && $product->getPriceType() == 1
204
+ && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4))
205
+ ) {
206
+ $weeeXmlObj = $priceXmlObj->addChild('from_weee');
207
+ $_weeeSeparator = ' + ';
208
+ $weeeXmlObj->addAttribute('separator', $_weeeSeparator);
209
+ foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
210
+ if ($_weeeHelper->typeOfDisplay($product, array(2, 4))) {
211
+ $amount = $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount();
212
+ } else {
213
+ $amount = $_weeeTaxAttribute->getAmount();
214
+ }
215
+ $weeeItemXmlObj = $weeeXmlObj->addChild('item');
216
+ $weeeItemXmlObj->addAttribute(
217
+ 'name',
218
+ $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
219
+ );
220
+ $weeeItemXmlObj->addAttribute(
221
+ 'amount',
222
+ $_coreHelper->currency($amount, true, false)
223
+ );
224
+ }
225
+ }
226
+ if ($_weeeHelper->typeOfDisplay($product, 2) && $_weeeTaxAmount) {
227
+ $priceXmlObj->addAttribute(
228
+ 'from_including_tax',
229
+ $_coreHelper->currency($_minimalPriceInclTax, true, false)
230
+ );
231
+ }
232
+ }
233
+
234
+ $_maximalPriceTax = Mage::helper('tax')->getPrice($product, $_maximalPrice);
235
+ $_maximalPriceInclTax = Mage::helper('tax')->getPrice($product, $_maximalPrice, true);
236
+
237
+ if ($product->getPriceType() == 1) {
238
+ if ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, array(0, 1, 4))) {
239
+ $_maximalPriceTax += $_weeeTaxAmount;
240
+ $_maximalPriceInclTax += $_weeeTaxAmount;
241
+ }
242
+ if ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 2)) {
243
+ $_maximalPriceInclTax += $_weeeTaxAmount;
244
+ }
245
+ }
246
+
247
+ if ($_taxHelper->displayBothPrices()) {
248
+ $priceXmlObj->addAttribute(
249
+ 'to_excluding_tax',
250
+ $_coreHelper->currency($_maximalPriceTax, true, false)
251
+ );
252
+ if ($_weeeTaxAmount && $product->getPriceType() == 1
253
+ && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4))
254
+ ) {
255
+ $weeeXmlObj = $priceXmlObj->addChild('to_weee');
256
+ $_weeeSeparator = ' + ';
257
+ $weeeXmlObj->addAttribute('separator', $_weeeSeparator);
258
+ foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
259
+ if ($_weeeHelper->typeOfDisplay($product, array(2, 4))) {
260
+ $amount = $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount();
261
+ } else {
262
+ $amount = $_weeeTaxAttribute->getAmount();
263
+ }
264
+ $weeeItemXmlObj = $weeeXmlObj->addChild('item');
265
+ $weeeItemXmlObj->addAttribute(
266
+ 'name',
267
+ $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
268
+ );
269
+ $weeeItemXmlObj->addAttribute(
270
+ 'amount',
271
+ $_coreHelper->currency($amount, true, false)
272
+ );
273
+ }
274
+ }
275
+ $priceXmlObj->addAttribute(
276
+ 'to_including_tax',
277
+ $_coreHelper->currency($_maximalPriceInclTax, true, false)
278
+ );
279
+ } else {
280
+ $priceXmlObj->addAttribute(
281
+ 'to',
282
+ $_coreHelper->currency($_maximalPriceTax, true, false)
283
+ );
284
+ if ($_weeeTaxAmount && $product->getPriceType() == 1
285
+ && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4))
286
+ ) {
287
+ $weeeXmlObj = $priceXmlObj->addChild('to_weee');
288
+ $_weeeSeparator = ' + ';
289
+ $weeeXmlObj->addAttribute('separator', $_weeeSeparator);
290
+ foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
291
+ if ($_weeeHelper->typeOfDisplay($product, array(2, 4))) {
292
+ $amount = $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount();
293
+ } else {
294
+ $amount = $_weeeTaxAttribute->getAmount();
295
+ }
296
+ $weeeItemXmlObj = $weeeXmlObj->addChild('item');
297
+ $weeeItemXmlObj->addAttribute(
298
+ 'name',
299
+ $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
300
+ );
301
+ $weeeItemXmlObj->addAttribute(
302
+ 'amount',
303
+ $_coreHelper->currency($amount, true, false)
304
+ );
305
+ }
306
+ }
307
+ if ($_weeeHelper->typeOfDisplay($product, 2) && $_weeeTaxAmount) {
308
+ $priceXmlObj->addAttribute(
309
+ 'to_including_tax',
310
+ $_coreHelper->currency($_maximalPriceInclTax, true, false)
311
+ );
312
+ }
313
+ }
314
+ /**
315
+ * if ($_minimalPrice <> $_maximalPrice) {
316
+ */
317
+ } else {
318
+ if ($_taxHelper->displayBothPrices()) {
319
+ $priceXmlObj->addAttribute(
320
+ 'excluding_tax',
321
+ $_coreHelper->currency($_minimalPriceTax, true, false)
322
+ );
323
+ if ($_weeeTaxAmount && $product->getPriceType() == 1
324
+ && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4))
325
+ ) {
326
+ $weeeXmlObj = $priceXmlObj->addChild('weee');
327
+ $_weeeSeparator = ' + ';
328
+ $weeeXmlObj->addAttribute('separator', $_weeeSeparator);
329
+ foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
330
+ if ($_weeeHelper->typeOfDisplay($product, array(2, 4))) {
331
+ $amount = $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount();
332
+ } else {
333
+ $amount = $_weeeTaxAttribute->getAmount();
334
+ }
335
+ $weeeItemXmlObj = $weeeXmlObj->addChild('item');
336
+ $weeeItemXmlObj->addAttribute(
337
+ 'name',
338
+ $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
339
+ );
340
+ $weeeItemXmlObj->addAttribute(
341
+ 'amount',
342
+ $_coreHelper->currency($amount, true, false)
343
+ );
344
+ }
345
+ }
346
+ $priceXmlObj->addAttribute(
347
+ 'including_tax',
348
+ $_coreHelper->currency($_minimalPriceInclTax, true, false)
349
+ );
350
+ } else {
351
+ $priceXmlObj->addAttribute(
352
+ 'regular',
353
+ $_coreHelper->currency($_minimalPriceTax, true, false)
354
+ );
355
+ if ($_weeeTaxAmount && $product->getPriceType() == 1
356
+ && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4))
357
+ ) {
358
+ $weeeXmlObj = $priceXmlObj->addChild('weee');
359
+ $_weeeSeparator = ' + ';
360
+ $weeeXmlObj->addAttribute('separator', $_weeeSeparator);
361
+ foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
362
+ if ($_weeeHelper->typeOfDisplay($product, array(2, 4))) {
363
+ $amount = $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount();
364
+ } else {
365
+ $amount = $_weeeTaxAttribute->getAmount();
366
+ }
367
+ $weeeItemXmlObj = $weeeXmlObj->addChild('item');
368
+ $weeeItemXmlObj->addAttribute(
369
+ 'name',
370
+ $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
371
+ );
372
+ $weeeItemXmlObj->addAttribute(
373
+ 'amount',
374
+ $_coreHelper->currency($amount, true, false)
375
+ );
376
+ }
377
+ }
378
+ if ($_weeeHelper->typeOfDisplay($product, 2) && $_weeeTaxAmount) {
379
+ $priceXmlObj->addAttribute(
380
+ 'including_tax',
381
+ $_coreHelper->currency($_minimalPriceInclTax, true, false)
382
+ );
383
+ }
384
+ }
385
+ }
386
+ }
387
+ }
388
+
389
+ /**
390
+ * Get tier prices (formatted)
391
+ *
392
+ * @param Mage_Catalog_Model_Product $product
393
+ * @return array
394
+ */
395
+ protected function _getTierPrices($product)
396
+ {
397
+ if (is_null($product)) {
398
+ return array();
399
+ }
400
+ $prices = $product->getFormatedTierPrice();
401
+
402
+ $res = array();
403
+ if (is_array($prices)) {
404
+ foreach ($prices as $price) {
405
+ $price['price_qty'] = $price['price_qty']*1;
406
+ $price['savePercent'] = ceil(100 - $price['price']);
407
+ $price['formated_price'] = Mage::app()->getStore()->formatPrice(
408
+ Mage::app()->getStore()->convertPrice(
409
+ Mage::helper('tax')->getPrice($product, $price['website_price'])
410
+ ),
411
+ false
412
+ );
413
+ $price['formated_price_incl_tax'] = Mage::app()->getStore()->formatPrice(
414
+ Mage::app()->getStore()->convertPrice(
415
+ Mage::helper('tax')->getPrice($product, $price['website_price'], true)
416
+ ),
417
+ false
418
+ );
419
+ $res[] = $price;
420
+ }
421
+ }
422
+
423
+ return $res;
424
+ }
425
+ }
app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Default.php ADDED
@@ -0,0 +1,828 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Default product price xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Catalog_Product_Price_Default
35
+ extends Mage_Catalog_Block_Product_Price
36
+ {
37
+ /**
38
+ * Collect product prices to specified item xml object
39
+ *
40
+ * @param Mage_Catalog_Model_Product $product
41
+ * @param Mage_XmlConnect_Model_Simplexml_Element $item
42
+ */
43
+ public function collectProductPrices(
44
+ Mage_Catalog_Model_Product $product,
45
+ Mage_XmlConnect_Model_Simplexml_Element $item
46
+ )
47
+ {
48
+ $this->setProduct($product)
49
+ ->setDisplayMinimalPrice(true)
50
+ ->setUseLinkForAsLowAs(false);
51
+
52
+ $priceXmlObj = $item->addChild('price');
53
+ $_tierPrices = $this->_getTierPrices($product);
54
+ if (count($_tierPrices) > 0) {
55
+ $tierPricesTextArray = $this->_getTierPricesTextArray($_tierPrices, $product);
56
+ $item->addChild('price_tier', implode(PHP_EOL, $tierPricesTextArray));
57
+ }
58
+
59
+ /** @var $_coreHelper Mage_Core_Helper_Data */
60
+ $_coreHelper = $this->helper('core');
61
+ /** @var $_weeeHelper Mage_Weee_Helper_Data */
62
+ $_weeeHelper = $this->helper('weee');
63
+ /** @var $_taxHelper Mage_Tax_Helper_Data */
64
+ $_taxHelper = $this->helper('tax');
65
+
66
+ $_simplePricesTax = ($_taxHelper->displayPriceIncludingTax() || $_taxHelper->displayBothPrices());
67
+ $_minimalPriceValue = $product->getMinimalPrice();
68
+ $_minimalPrice = $_taxHelper->getPrice($product, $_minimalPriceValue, $_simplePricesTax);
69
+
70
+ if (!$product->isGrouped()) {
71
+ $_weeeTaxAmount = $_weeeHelper->getAmountForDisplay($product);
72
+ if ($_weeeHelper->typeOfDisplay($product, array(1, 2, 4))) {
73
+ $_weeeTaxAmount = $_weeeHelper->getAmount($product);
74
+ $_weeeTaxAttributes = $_weeeHelper->getProductWeeeAttributesForDisplay($product);
75
+ }
76
+
77
+ $_price = $_taxHelper->getPrice($product, $product->getPrice());
78
+ $_regularPrice = $_taxHelper->getPrice($product, $product->getPrice(), $_simplePricesTax);
79
+ $_finalPrice = $_taxHelper->getPrice($product, $product->getFinalPrice());
80
+ $_finalPriceInclTax = $_taxHelper->getPrice($product, $product->getFinalPrice(), true);
81
+ $_weeeHelper->getPriceDisplayType();
82
+ if ($_finalPrice == $_price) {
83
+ if ($_taxHelper->displayBothPrices()) {
84
+ /**
85
+ * Including
86
+ */
87
+ if ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 0)) {
88
+ $priceXmlObj->addAttribute(
89
+ 'excluding_tax',
90
+ $_coreHelper->currency($_price + $_weeeTaxAmount, true, false)
91
+ );
92
+ $priceXmlObj->addAttribute(
93
+ 'including_tax',
94
+ $_coreHelper->currency($_finalPriceInclTax + $_weeeTaxAmount, true, false)
95
+ );
96
+ } elseif ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 1)) {
97
+ /**
98
+ * Including + Weee
99
+ */
100
+ $priceXmlObj->addAttribute(
101
+ 'excluding_tax',
102
+ $_coreHelper->currency($_price + $_weeeTaxAmount, true, false)
103
+ );
104
+ $priceXmlObj->addAttribute(
105
+ 'including_tax',
106
+ $_coreHelper->currency($_finalPriceInclTax + $_weeeTaxAmount, true, false)
107
+ );
108
+ $weeeXmlObj = $priceXmlObj->addChild('weee');
109
+ $_weeeSeparator = ' + ';
110
+ $weeeXmlObj->addAttribute('separator', $_weeeSeparator);
111
+ foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
112
+ $weeeItemXmlObj = $weeeXmlObj->addChild('item');
113
+ $weeeItemXmlObj->addAttribute(
114
+ 'name',
115
+ $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
116
+ );
117
+ $weeeItemXmlObj->addAttribute(
118
+ 'amount',
119
+ $_coreHelper->currency($_weeeTaxAttribute->getAmount(), true, false)
120
+ );
121
+ }
122
+ } elseif ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 4)) {
123
+ /**
124
+ * Including + Weee
125
+ */
126
+ $priceXmlObj->addAttribute(
127
+ 'excluding_tax',
128
+ $_coreHelper->currency($_price + $_weeeTaxAmount, true, false)
129
+ );
130
+ $priceXmlObj->addAttribute(
131
+ 'including_tax',
132
+ $_coreHelper->currency($_finalPriceInclTax + $_weeeTaxAmount, true, false)
133
+ );
134
+ $weeeXmlObj = $priceXmlObj->addChild('weee');
135
+ $_weeeSeparator = ' + ';
136
+ $weeeXmlObj->addAttribute('separator', $_weeeSeparator);
137
+ foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
138
+ $weeeItemXmlObj = $weeeXmlObj->addChild('item');
139
+ $weeeItemXmlObj->addAttribute(
140
+ 'name',
141
+ $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
142
+ );
143
+ $weeeItemXmlObj->addAttribute(
144
+ 'amount',
145
+ $_coreHelper->currency(
146
+ $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount(),
147
+ true,
148
+ false
149
+ )
150
+ );
151
+ }
152
+ } elseif ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 2)) {
153
+ /**
154
+ * Excluding + Weee + Final
155
+ */
156
+ $priceXmlObj->addAttribute(
157
+ 'excluding_tax',
158
+ $_coreHelper->currency($_price, true, false)
159
+ );
160
+ $weeeXmlObj = $priceXmlObj->addChild('weee');
161
+ foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
162
+ $weeeItemXmlObj = $weeeXmlObj->addChild('item');
163
+ $weeeItemXmlObj->addAttribute(
164
+ 'name',
165
+ $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
166
+ );
167
+ $weeeItemXmlObj->addAttribute(
168
+ 'amount',
169
+ $_coreHelper->currency($_weeeTaxAttribute->getAmount(), true, false)
170
+ );
171
+ }
172
+ $priceXmlObj->addAttribute(
173
+ 'including_tax',
174
+ $_coreHelper->currency(
175
+ $_finalPriceInclTax + $_weeeTaxAmount,
176
+ true,
177
+ false
178
+ )
179
+ );
180
+ } else {
181
+ $priceXmlObj->addAttribute(
182
+ 'excluding_tax',
183
+ $_coreHelper->currency($_price, true, false)
184
+ );
185
+ $priceXmlObj->addAttribute(
186
+ 'including_tax',
187
+ $_coreHelper->currency($_finalPriceInclTax, true, false)
188
+ );
189
+ }
190
+ /**
191
+ * if ($_taxHelper->displayBothPrices()) {
192
+ */
193
+ } else {
194
+ /**
195
+ * Including
196
+ */
197
+ if ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 0)) {
198
+ $priceXmlObj->addAttribute(
199
+ 'regular',
200
+ $_coreHelper->currency(
201
+ $_price + $_weeeTaxAmount,
202
+ true,
203
+ false
204
+ )
205
+ );
206
+ } elseif ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 1)) {
207
+ /**
208
+ * Including + Weee
209
+ */
210
+
211
+ $priceXmlObj->addAttribute(
212
+ 'regular',
213
+ $_coreHelper->currency(
214
+ $_price + $_weeeTaxAmount,
215
+ true,
216
+ false
217
+ )
218
+ );
219
+ $weeeXmlObj = $priceXmlObj->addChild('weee');
220
+ $_weeeSeparator = ' + ';
221
+ $weeeXmlObj->addAttribute('separator', $_weeeSeparator);
222
+ foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
223
+ $weeeItemXmlObj = $weeeXmlObj->addChild('item');
224
+ $weeeItemXmlObj->addAttribute(
225
+ 'name',
226
+ $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
227
+ );
228
+ $weeeItemXmlObj->addAttribute(
229
+ 'amount',
230
+ $_coreHelper->currency($_weeeTaxAttribute->getAmount(), true, false)
231
+ );
232
+ }
233
+ } elseif ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 4)) {
234
+ /**
235
+ * Including + Weee
236
+ */
237
+ $priceXmlObj->addAttribute(
238
+ 'regular',
239
+ $_coreHelper->currency(
240
+ $_price + $_weeeTaxAmount,
241
+ true,
242
+ false
243
+ )
244
+ );
245
+ $weeeXmlObj = $priceXmlObj->addChild('weee');
246
+ $_weeeSeparator = ' + ';
247
+ $weeeXmlObj->addAttribute('separator', $_weeeSeparator);
248
+ foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
249
+ $weeeItemXmlObj = $weeeXmlObj->addChild('item');
250
+ $weeeItemXmlObj->addAttribute(
251
+ 'name',
252
+ $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
253
+ );
254
+ $weeeItemXmlObj->addAttribute(
255
+ 'amount',
256
+ $_coreHelper->currency(
257
+ $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount(),
258
+ true,
259
+ false
260
+ )
261
+ );
262
+ }
263
+ } elseif ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 2)) {
264
+ /**
265
+ * Excluding + Weee + Final
266
+ */
267
+ $priceXmlObj->addAttribute(
268
+ 'regular',
269
+ $_coreHelper->currency($_price, true, false)
270
+ );
271
+ $weeeXmlObj = $priceXmlObj->addChild('weee');
272
+ foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
273
+ $weeeItemXmlObj = $weeeXmlObj->addChild('item');
274
+ $weeeItemXmlObj->addAttribute(
275
+ 'name',
276
+ $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
277
+ );
278
+ $weeeItemXmlObj->addAttribute(
279
+ 'amount',
280
+ $_coreHelper->currency($_weeeTaxAttribute->getAmount(), true, false)
281
+ );
282
+ }
283
+ $priceXmlObj->addAttribute(
284
+ 'including_tax',
285
+ $_coreHelper->currency($_price + $_weeeTaxAmount, true, false)
286
+ );
287
+ } else {
288
+ $priceXmlObj->addAttribute(
289
+ 'regular',
290
+ $_coreHelper->currency($_price, true, false)
291
+ );
292
+ }
293
+ }
294
+ /**
295
+ * if ($_finalPrice == $_price) {
296
+ */
297
+ } else {
298
+ $_originalWeeeTaxAmount = $_weeeHelper->getOriginalAmount($product);
299
+ /**
300
+ * Including
301
+ */
302
+ if ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 0)) {
303
+ $priceXmlObj->addAttribute(
304
+ 'regular',
305
+ $_coreHelper->currency(
306
+ $_regularPrice + $_originalWeeeTaxAmount,
307
+ true,
308
+ false
309
+ )
310
+ );
311
+ if ($_taxHelper->displayBothPrices()) {
312
+ $priceXmlObj->addAttribute(
313
+ 'special_excluding_tax',
314
+ $_coreHelper->currency(
315
+ $_finalPrice + $_weeeTaxAmount,
316
+ true,
317
+ false
318
+ )
319
+ );
320
+ $priceXmlObj->addAttribute(
321
+ 'special_including_tax',
322
+ $_coreHelper->currency(
323
+ $_finalPriceInclTax + $_weeeTaxAmount,
324
+ true,
325
+ false
326
+ )
327
+ );
328
+ } else {
329
+ $priceXmlObj->addAttribute(
330
+ 'special',
331
+ $_coreHelper->currency(
332
+ $_finalPrice + $_weeeTaxAmount,
333
+ true,
334
+ false
335
+ )
336
+ );
337
+ }
338
+ } elseif ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 1)) {
339
+ /**
340
+ * Including + Weee
341
+ */
342
+ $priceXmlObj->addAttribute(
343
+ 'regular',
344
+ $_coreHelper->currency(
345
+ $_regularPrice + $_originalWeeeTaxAmount,
346
+ true,
347
+ false
348
+ )
349
+ );
350
+ $priceXmlObj->addAttribute(
351
+ 'special_excluding_tax',
352
+ $_coreHelper->currency(
353
+ $_finalPrice + $_weeeTaxAmount,
354
+ true,
355
+ false
356
+ )
357
+ );
358
+ $weeeXmlObj = $priceXmlObj->addChild('weee');
359
+ $_weeeSeparator = ' + ';
360
+ $weeeXmlObj->addAttribute('separator', $_weeeSeparator);
361
+ foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
362
+ $weeeItemXmlObj = $weeeXmlObj->addChild('item');
363
+ $weeeItemXmlObj->addAttribute(
364
+ 'name',
365
+ $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
366
+ );
367
+ $weeeItemXmlObj->addAttribute(
368
+ 'amount',
369
+ $_coreHelper->currency(
370
+ $_weeeTaxAttribute->getAmount(),
371
+ true,
372
+ false
373
+ )
374
+ );
375
+ }
376
+ $priceXmlObj->addAttribute(
377
+ 'special_including_tax',
378
+ $_coreHelper->currency(
379
+ $_finalPriceInclTax + $_weeeTaxAmount,
380
+ true,
381
+ false
382
+ )
383
+ );
384
+ } elseif ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 4)) {
385
+ /**
386
+ * Including + Weee
387
+ */
388
+ $priceXmlObj->addAttribute(
389
+ 'regular',
390
+ $_coreHelper->currency(
391
+ $_regularPrice + $_originalWeeeTaxAmount,
392
+ true,
393
+ false
394
+ )
395
+ );
396
+ $priceXmlObj->addAttribute(
397
+ 'special_excluding_tax',
398
+ $_coreHelper->currency(
399
+ $_finalPrice + $_weeeTaxAmount,
400
+ true,
401
+ false
402
+ )
403
+ );
404
+ $weeeXmlObj = $priceXmlObj->addChild('weee');
405
+ $_weeeSeparator = ' + ';
406
+ $weeeXmlObj->addAttribute('separator', $_weeeSeparator);
407
+ foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
408
+ $weeeItemXmlObj = $weeeXmlObj->addChild('item');
409
+ $weeeItemXmlObj->addAttribute(
410
+ 'name',
411
+ $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
412
+ );
413
+ $weeeItemXmlObj->addAttribute(
414
+ 'amount',
415
+ $_coreHelper->currency(
416
+ $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount(),
417
+ true,
418
+ false
419
+ )
420
+ );
421
+ }
422
+ $priceXmlObj->addAttribute(
423
+ 'special_including_tax',
424
+ $_coreHelper->currency(
425
+ $_finalPriceInclTax + $_weeeTaxAmount,
426
+ true,
427
+ false
428
+ )
429
+ );
430
+ } elseif ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 2)) {
431
+ /**
432
+ * Excluding + Weee + Final
433
+ */
434
+ $priceXmlObj->addAttribute(
435
+ 'regular',
436
+ $_coreHelper->currency($_regularPrice, true, false)
437
+ );
438
+ $priceXmlObj->addAttribute(
439
+ 'special_excluding_tax',
440
+ $_coreHelper->currency($_finalPrice, true, false)
441
+ );
442
+ $weeeXmlObj = $priceXmlObj->addChild('weee');
443
+ foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
444
+ $weeeItemXmlObj = $weeeXmlObj->addChild('item');
445
+ $weeeItemXmlObj->addAttribute(
446
+ 'name',
447
+ $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
448
+ );
449
+ $weeeItemXmlObj->addAttribute(
450
+ 'amount',
451
+ $_coreHelper->currency(
452
+ $_weeeTaxAttribute->getAmount(),
453
+ true,
454
+ false
455
+ )
456
+ );
457
+ }
458
+ $priceXmlObj->addAttribute(
459
+ 'special_including_tax',
460
+ $_coreHelper->currency(
461
+ $_finalPriceInclTax + $_weeeTaxAmount,
462
+ true,
463
+ false
464
+ )
465
+ );
466
+ } else {
467
+ /**
468
+ * Excluding
469
+ */
470
+ $priceXmlObj->addAttribute(
471
+ 'regular',
472
+ $_coreHelper->currency($_regularPrice, true, false)
473
+ );
474
+ if ($_taxHelper->displayBothPrices()) {
475
+ $priceXmlObj->addAttribute(
476
+ 'special_excluding_tax',
477
+ $_coreHelper->currency($_finalPrice, true, false)
478
+ );
479
+ $priceXmlObj->addAttribute(
480
+ 'special_including_tax',
481
+ $_coreHelper->currency($_finalPriceInclTax, true, false)
482
+ );
483
+ } else {
484
+ $priceXmlObj->addAttribute(
485
+ 'special',
486
+ $_coreHelper->currency($_finalPrice, true, false)
487
+ );
488
+ }
489
+ }
490
+ }
491
+
492
+ if ($this->getDisplayMinimalPrice()
493
+ && $_minimalPriceValue
494
+ && $_minimalPriceValue < $product->getFinalPrice()
495
+ ) {
496
+ $_minimalPriceDisplayValue = $_minimalPrice;
497
+
498
+ if ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, array(0, 1, 4))) {
499
+ $_minimalPriceDisplayValue = $_minimalPrice + $_weeeTaxAmount;
500
+ }
501
+
502
+ if (!$this->getUseLinkForAsLowAs()) {
503
+ $priceXmlObj->addAttribute(
504
+ 'as_low_as',
505
+ $_coreHelper->currency(
506
+ $_minimalPriceDisplayValue,
507
+ true,
508
+ false
509
+ )
510
+ );
511
+ }
512
+ }
513
+ /**
514
+ * if (!$product->isGrouped()) {
515
+ */
516
+ } else {
517
+ $_exclTax = $_taxHelper->getPrice($product, $_minimalPriceValue, null);
518
+ $_inclTax = $_taxHelper->getPrice($product, $_minimalPriceValue, true);
519
+
520
+ if ($this->getDisplayMinimalPrice() && $_minimalPriceValue) {
521
+ if ($_taxHelper->displayBothPrices()) {
522
+ $priceXmlObj->addAttribute(
523
+ 'starting_at_excluding_tax',
524
+ $_coreHelper->currency(
525
+ $_exclTax,
526
+ true,
527
+ false
528
+ )
529
+ );
530
+ $priceXmlObj->addAttribute(
531
+ 'starting_at_including_tax',
532
+ $_coreHelper->currency(
533
+ $_inclTax,
534
+ true,
535
+ false
536
+ )
537
+ );
538
+ } else {
539
+ $_showPrice = $_inclTax;
540
+ if (!$_taxHelper->displayPriceIncludingTax()) {
541
+ $_showPrice = $_exclTax;
542
+ }
543
+ $priceXmlObj->addAttribute(
544
+ 'starting_at',
545
+ $_coreHelper->currency(
546
+ $_showPrice,
547
+ true,
548
+ false
549
+ )
550
+ );
551
+ }
552
+ }
553
+ }
554
+ }
555
+
556
+ /**
557
+ * Get tier prices (formatted)
558
+ *
559
+ * @param Mage_Catalog_Model_Product $product
560
+ * @return array
561
+ */
562
+ protected function _getTierPrices(Mage_Catalog_Model_Product $product)
563
+ {
564
+ if (is_null($product)) {
565
+ return array();
566
+ }
567
+ $prices = $product->getFormatedTierPrice();
568
+
569
+ $res = array();
570
+ if (is_array($prices)) {
571
+ foreach ($prices as $price) {
572
+ $price['price_qty'] = $price['price_qty']*1;
573
+ if ($product->getPrice() != $product->getFinalPrice()) {
574
+ if ($price['price'] < $product->getFinalPrice()) {
575
+ $price['savePercent'] = ceil(100 - ((100 / $product->getFinalPrice()) * $price['price']));
576
+ $price['formated_price'] = Mage::app()->getStore()->formatPrice(
577
+ Mage::app()->getStore()->convertPrice(
578
+ Mage::helper('tax')->getPrice(
579
+ $product,
580
+ $price['website_price']
581
+ )
582
+ ),
583
+ false
584
+ );
585
+ $price['formated_price_incl_tax'] = Mage::app()->getStore()->formatPrice(
586
+ Mage::app()->getStore()->convertPrice(
587
+ Mage::helper('tax')->getPrice(
588
+ $product,
589
+ $price['website_price'],
590
+ true
591
+ )
592
+ ),
593
+ false
594
+ );
595
+ $res[] = $price;
596
+ }
597
+ } else {
598
+ if ($price['price'] < $product->getPrice()) {
599
+ $price['savePercent'] = ceil(100 - ((100 / $product->getPrice()) * $price['price']));
600
+ $price['formated_price'] = Mage::app()->getStore()->formatPrice(
601
+ Mage::app()->getStore()->convertPrice(
602
+ Mage::helper('tax')->getPrice(
603
+ $product,
604
+ $price['website_price']
605
+ )
606
+ ),
607
+ false
608
+ );
609
+ $price['formated_price_incl_tax'] = Mage::app()->getStore()->formatPrice(
610
+ Mage::app()->getStore()->convertPrice(
611
+ Mage::helper('tax')->getPrice(
612
+ $product,
613
+ $price['website_price'],
614
+ true
615
+ )
616
+ ),
617
+ false
618
+ );
619
+ $res[] = $price;
620
+ }
621
+ }
622
+ }
623
+ }
624
+
625
+ return $res;
626
+ }
627
+
628
+ /**
629
+ * Get tier prices (formatted) as array of strings
630
+ *
631
+ * @param array $_tierPrices
632
+ * @param Mage_Catalog_Model_Product $_product
633
+ *
634
+ * @return array
635
+ */
636
+ protected function _getTierPricesTextArray($_tierPrices, $_product)
637
+ {
638
+
639
+ $pricesArray = array();
640
+ if (Mage::helper('weee')->typeOfDisplay($_product, array(1, 2, 4))) {
641
+ $_weeeTaxAttributes = Mage::helper('weee')->getProductWeeeAttributesForDisplay($_product);
642
+ }
643
+
644
+ if ($_product->isGrouped()) {
645
+ $_tierPrices = $this->getTierPrices($_product);
646
+ }
647
+ Mage::helper('weee')->processTierPrices($_product, $_tierPrices);
648
+
649
+ foreach ($_tierPrices as $_price) {
650
+ $s = '';
651
+ if ($this->helper('tax')->displayBothPrices()) {
652
+ if (Mage::helper('weee')->typeOfDisplay($_product, 0)) {
653
+ $s .= $this->__('Buy %1$s for %2$s (%3$s incl. tax) each', $_price['price_qty'], $_price['formated_price_incl_weee_only'], $_price['formated_price_incl_weee']);
654
+ } else if (Mage::helper('weee')->typeOfDisplay($_product, 1)) {
655
+ $s .= $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price_incl_weee_only']);
656
+ if ($_weeeTaxAttributes) {
657
+ $s .= '(';
658
+ $s .= $this->__('%1$s incl tax.', $_price['formated_price_incl_weee']);
659
+ $separator = ' + ';
660
+ foreach ($_weeeTaxAttributes as $_attribute) {
661
+ $s .= $separator;
662
+ $s .= $_attribute->getName();
663
+ $s .= ': ';
664
+ $s .= Mage::helper('core')->currency($_attribute->getAmount());
665
+ }
666
+ $s .= ')';
667
+ }
668
+ $s .= $this->__('each');
669
+ } else if (Mage::helper('weee')->typeOfDisplay($_product, 4)) {
670
+ $s .= $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price_incl_weee_only']);
671
+ if ($_weeeTaxAttributes) {
672
+ $s .= '(';
673
+ $s .= $this->__('%1$s incl tax.', $_price['formated_price_incl_weee']);
674
+ $separator = ' + ';
675
+ foreach ($_weeeTaxAttributes as $_attribute) {
676
+ $s .= $separator;
677
+ $s .= $_attribute->getName();
678
+ $s .= ': ';
679
+ $s .= Mage::helper('core')->currency(
680
+ $_attribute->getAmount() + $_attribute->getTaxAmount()
681
+ );
682
+ }
683
+ $s .= ')';
684
+ }
685
+ $s .= $this->__('each');
686
+ } else if (Mage::helper('weee')->typeOfDisplay($_product, 2)) {
687
+ $s .= $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price']);
688
+ if ($_weeeTaxAttributes) {
689
+ $s .= '(';
690
+ foreach ($_weeeTaxAttributes as $_attribute) {
691
+ $s .= $_attribute->getName();
692
+ $s .= ': ';
693
+ $s .= Mage::helper('core')->currency($_attribute->getAmount());
694
+ }
695
+ $s .= $this->__('Total incl. Tax: %1$s', $_price['formated_price_incl_weee']);
696
+ $s .= ')';
697
+ }
698
+ $s .= $this->__('each');
699
+ } else {
700
+ $s .= $this->__('Buy %1$s for %2$s (%3$s incl. tax) each', $_price['price_qty'], $_price['formated_price'], $_price['formated_price_incl_tax']);
701
+ }
702
+ } else {
703
+ if ($this->helper('tax')->displayPriceIncludingTax()) {
704
+ if (Mage::helper('weee')->typeOfDisplay($_product, 0)) {
705
+ $s .= $this->__('Buy %1$s for %2$s each', $_price['price_qty'], $_price['formated_price_incl_weee']);
706
+ } else if (Mage::helper('weee')->typeOfDisplay($_product, 1)) {
707
+ $s .= $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price_incl_weee']);
708
+ if ($_weeeTaxAttributes) {
709
+ $s .= '(';
710
+ $separator = '';
711
+ foreach ($_weeeTaxAttributes as $_attribute) {
712
+ $s .= $separator;
713
+ $s .= $_attribute->getName();
714
+ $s .= ': ';
715
+ $s .= Mage::helper('core')->currency($_attribute->getAmount());
716
+ $separator = ' + ';
717
+ }
718
+ $s .= ')';
719
+ }
720
+ $s .= $this->__('each');
721
+ } else if (Mage::helper('weee')->typeOfDisplay($_product, 4)) {
722
+ $s .= $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price_incl_weee']);
723
+ if ($_weeeTaxAttributes) {
724
+ $s .= '(';
725
+ $separator = '';
726
+ foreach ($_weeeTaxAttributes as $_attribute) {
727
+ $s .= $separator;
728
+ $s .= $_attribute->getName();
729
+ $s .= ': ';
730
+ $s .= Mage::helper('core')->currency(
731
+ $_attribute->getAmount() + $_attribute->getTaxAmount()
732
+ );
733
+ $separator = ' + ';
734
+ }
735
+ $s .= ')';
736
+ }
737
+ $s .= $this->__('each');
738
+ } else if (Mage::helper('weee')->typeOfDisplay($_product, 2)) {
739
+ $s .= $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price_incl_tax']);
740
+ if ($_weeeTaxAttributes) {
741
+ $s .= '(';
742
+ foreach ($_weeeTaxAttributes as $_attribute) {
743
+ $s .= $_attribute->getName();
744
+ $s .= ': ';
745
+ $s .= Mage::helper('core')->currency($_attribute->getAmount());
746
+ }
747
+ $s .= $this->__('Total incl. Tax: %1$s', $_price['formated_price_incl_weee']);
748
+ $s .= ')';
749
+ }
750
+ $s .= $this->__('each');
751
+ } else {
752
+ $s .= $this->__('Buy %1$s for %2$s each', $_price['price_qty'], $_price['formated_price_incl_tax']);
753
+ }
754
+ } else {
755
+ if (Mage::helper('weee')->typeOfDisplay($_product, 0)) {
756
+ $s .= $this->__('Buy %1$s for %2$s each', $_price['price_qty'], $_price['formated_price_incl_weee_only']);
757
+ } else if (Mage::helper('weee')->typeOfDisplay($_product, 1)) {
758
+ $s .= $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price_incl_weee_only']);
759
+ if ($_weeeTaxAttributes) {
760
+ $s .= '(';
761
+ $separator = '';
762
+ foreach ($_weeeTaxAttributes as $_attribute) {
763
+ $s .= $separator;
764
+ $s .= $_attribute->getName();
765
+ $s .= ': ';
766
+ $s .= Mage::helper('core')->currency($_attribute->getAmount());
767
+ $separator = ' + ';
768
+ }
769
+ $s .= ')';
770
+ }
771
+ $s .= $this->__('each');
772
+ } else if (Mage::helper('weee')->typeOfDisplay($_product, 4)) {
773
+ $s .= $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price_incl_weee_only']);
774
+ if ($_weeeTaxAttributes) {
775
+ $s .= '(';
776
+ $separator = '';
777
+ foreach ($_weeeTaxAttributes as $_attribute) {
778
+ $s .= $separator;
779
+ $s .= $_attribute->getName();
780
+ $s .= ': ';
781
+ $s .= Mage::helper('core')->currency(
782
+ $_attribute->getAmount() + $_attribute->getTaxAmount()
783
+ );
784
+ $separator = ' + ';
785
+ }
786
+ $s .= ')';
787
+ }
788
+ $s .= $this->__('each');
789
+ } else if (Mage::helper('weee')->typeOfDisplay($_product, 2)) {
790
+ $s .= $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price']);
791
+ if ($_weeeTaxAttributes) {
792
+ $s .= '(';
793
+ foreach ($_weeeTaxAttributes as $_attribute) {
794
+ $s .= $_attribute->getName();
795
+ $s .= ': ';
796
+ $s .= Mage::helper('core')->currency($_attribute->getAmount());
797
+ }
798
+ $s .= $this->__('Total incl. Tax: %1$s', $_price['formated_price_incl_weee_only']);
799
+ $s .= ')';
800
+ }
801
+ $s .= $this->__('each');
802
+ } else {
803
+ $s .= $this->__('Buy %1$s for %2$s each', $_price['price_qty'], $_price['formated_price']);
804
+ }
805
+ }
806
+ }
807
+ if (!$_product->isGrouped()) {
808
+ $condition1 = ($_product->getPrice() == $_product->getFinalPrice()
809
+ && $_product->getPrice() > $_price['price']);
810
+
811
+ $condition2 = ($_product->getPrice() != $_product->getFinalPrice()
812
+ && $_product->getFinalPrice() > $_price['price']);
813
+
814
+ if ($condition1 || $condition2) {
815
+ $s .= ' ';
816
+ $s .= $this->__('and');
817
+ $s .= ' ';
818
+ $s .= $this->__('save');
819
+ $s .= ' ';
820
+ $s .= $_price['savePercent'];
821
+ $s .= '%';
822
+ }
823
+ }
824
+ $pricesArray[] = $s;
825
+ }
826
+ return $pricesArray;
827
+ }
828
+ }
app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Giftcard.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Giftcard product price xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Catalog_Product_Price_Giftcard
35
+ extends Mage_Bundle_Block_Catalog_Product_Price
36
+ {
37
+ /**
38
+ * Return minimal amount for Giftcard product using price model
39
+ *
40
+ * @param Mage_Catalog_Model_Product $product
41
+ * @return float
42
+ */
43
+ public function getMinAmount($product = null)
44
+ {
45
+ if (is_null($product)) {
46
+ $product = $this->getProduct();
47
+ }
48
+ return $product->getPriceModel()->getMinAmount($product);
49
+ }
50
+
51
+ /**
52
+ * Return maximal amount for Giftcard product using price model
53
+ *
54
+ * @param Mage_Catalog_Model_Product $product
55
+ * @return float
56
+ */
57
+ public function getMaxAmount($product = null)
58
+ {
59
+ if (is_null($product)) {
60
+ $product = $this->getProduct();
61
+ }
62
+ return $product->getPriceModel()->getMaxAmount($product);
63
+ }
64
+
65
+ /**
66
+ * Collect product prices to specified item xml object
67
+ *
68
+ * @param Mage_Catalog_Model_Product $product
69
+ * @param Mage_XmlConnect_Model_Simplexml_Element $item
70
+ */
71
+ public function collectProductPrices(
72
+ Mage_Catalog_Model_Product $product,
73
+ Mage_XmlConnect_Model_Simplexml_Element $item
74
+ )
75
+ {
76
+ $this->setProduct($product);
77
+
78
+ if ($product->getCanShowPrice() !== false) {
79
+ $priceXmlObj = $item->addChild('price');
80
+
81
+ if (($_min = $this->getMinAmount()) && ($_max = $this->getMaxAmount()) && ($_min == $_max)) {
82
+ $priceXmlObj->addAttribute(
83
+ 'regular',
84
+ Mage::helper('core')->currency($_min, true, false)
85
+ );
86
+ } elseif (($_min = $this->getMinAmount()) && $_min != 0) {
87
+ $priceXmlObj->addAttribute(
88
+ 'regular',
89
+ Mage::helper('enterprise_giftcard')->__('From')
90
+ . ': '
91
+ . Mage::helper('core')->currency($_min, true, false)
92
+ );
93
+ }
94
+ }
95
+ }
96
+ }
app/code/core/Mage/XmlConnect/Block/Catalog/Product/Related.php ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Related products block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Catalog_Product_Related extends Mage_XmlConnect_Block_Catalog_Product_List
35
+ {
36
+ /**
37
+ * Retrieve related products xml object based on current product
38
+ *
39
+ * @return Mage_XmlConnect_Model_Simplexml_Element
40
+ * @see $this->getProduct()
41
+ */
42
+ public function getRelatedProductsXmlObj()
43
+ {
44
+ /** @var $relatedXmlObj Mage_XmlConnect_Model_Simplexml_Element */
45
+ $relatedXmlObj = Mage::getModel(
46
+ 'xmlconnect/simplexml_element',
47
+ '<related_products></related_products>'
48
+ );
49
+
50
+ $productObj = $this->getParentBlock()->getProduct();
51
+
52
+ if (is_object(Mage::getConfig()->getNode('modules/Enterprise_TargetRule'))) {
53
+ Mage::register('product', $productObj);
54
+
55
+ $productBlock = $this->getLayout()
56
+ ->addBlock(
57
+ 'enterprise_targetrule/catalog_product_list_related',
58
+ 'relatedProducts'
59
+ );
60
+
61
+ $collection = $productBlock->getItemCollection();
62
+ } else {
63
+ if ($productObj->getId() > 0) {
64
+ $collection = $this->_getProductCollection();
65
+ if (!$collection) {
66
+ return $relatedXmlObj;
67
+ }
68
+ $collection = $collection->getItems();
69
+ }
70
+ }
71
+
72
+ $this->_addProductXmlObj($relatedXmlObj, $collection);
73
+
74
+ return $relatedXmlObj;
75
+ }
76
+
77
+ /**
78
+ * Add related products info to xml object
79
+ *
80
+ * @param Mage_XmlConnect_Model_Simplexml_Element $relatedXmlObj
81
+ * @param array $collection
82
+ * @return Mage_XmlConnect_Model_Simplexml_Element
83
+ */
84
+ protected function _addProductXmlObj(Mage_XmlConnect_Model_Simplexml_Element $relatedXmlObj, $collection)
85
+ {
86
+ foreach ($collection as $product) {
87
+ $productXmlObj = $this->productToXmlObject($product);
88
+ if ($productXmlObj) {
89
+ if ($this->getParentBlock()->getChild('product_price')) {
90
+ $this->getParentBlock()->getChild('product_price')
91
+ ->setProduct($product)
92
+ ->setProductXmlObj($productXmlObj)
93
+ ->collectProductPrices();
94
+ }
95
+ $relatedXmlObj->appendChild($productXmlObj);
96
+ }
97
+ }
98
+ return $relatedXmlObj;
99
+ }
100
+
101
+ /**
102
+ * Generate related products xml
103
+ *
104
+ * @return string
105
+ */
106
+ protected function _toHtml()
107
+ {
108
+ return $this->getRelatedProductsXmlObj()->asNiceXml();
109
+ }
110
+
111
+ /**
112
+ * Retrieve product collection with all prepared data
113
+ *
114
+ * @return Mage_Eav_Model_Entity_Collection_Abstract
115
+ */
116
+ protected function _getProductCollection()
117
+ {
118
+ if (is_null($this->_productCollection)) {
119
+ $collection = $this->getParentBlock()
120
+ ->getProduct()
121
+ ->getRelatedProductCollection();
122
+ Mage::getSingleton('catalog/layer')->prepareProductCollection($collection);
123
+ /**
124
+ * Add rating and review summary, image attribute, apply sort params
125
+ */
126
+ $this->_prepareCollection($collection);
127
+
128
+ $this->_productCollection = $collection;
129
+ }
130
+ return $this->_productCollection;
131
+ }
132
+ }
app/code/core/Mage/XmlConnect/Block/Catalog/Product/Review.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Review xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Catalog_Product_Review extends Mage_XmlConnect_Block_Catalog
35
+ {
36
+ /**
37
+ * Limit to product review text length
38
+ */
39
+ const REVIEW_DETAIL_TRUNCATE_LEN = 200;
40
+
41
+ /**
42
+ * Retrieve review data as xml object
43
+ *
44
+ * @param Mage_Review_Model_Review $review
45
+ * @param string $itemNodeName
46
+ * @return Mage_XmlConnect_Model_Simplexml_Element
47
+ */
48
+ public function reviewToXmlObject(Mage_Review_Model_Review $review, $itemNodeName = 'item')
49
+ {
50
+ $rating = 0;
51
+ $item = Mage::getModel('xmlconnect/simplexml_element', '<' . $itemNodeName . '></' . $itemNodeName . '>');
52
+ if ($review->getId()) {
53
+ $item->addChild('review_id', $review->getId());
54
+ $item->addChild('created_at', $this->formatDate($review->getCreatedAt()));
55
+ $item->addChild('title', $item->escapeXml($review->getTitle()));
56
+ $item->addChild('nickname', $item->escapeXml($review->getNickname()));
57
+ $detail = $item->escapeXml($review->getDetail());
58
+ if ($itemNodeName == 'item') {
59
+ $remainder = '';
60
+ $deviceType = Mage::helper('xmlconnect')->getDeviceType();
61
+ if ($deviceType != Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPAD) {
62
+ $detail = Mage::helper('core/string')
63
+ ->truncate($detail, self::REVIEW_DETAIL_TRUNCATE_LEN, '', $remainder, false);
64
+ }
65
+ }
66
+ $item->addChild('detail', $detail);
67
+
68
+ $summary = Mage::getModel('rating/rating')->getReviewSummary($review->getId());
69
+ if ($summary->getCount() > 0) {
70
+ $rating = round($summary->getSum() / $summary->getCount() / 10);
71
+ }
72
+ if ($rating) {
73
+ $item->addChild('rating_votes', $rating);
74
+ }
75
+ }
76
+ return $item;
77
+ }
78
+
79
+ /**
80
+ * Render review xml
81
+ *
82
+ * @return string
83
+ */
84
+ protected function _toHtml()
85
+ {
86
+ $review = Mage::getModel('review/review')
87
+ ->load((int)$this->getRequest()->getParam('id', 0));
88
+ return $this->reviewToXmlObject($review, 'review')->asNiceXml();
89
+ }
90
+ }
app/code/core/Mage/XmlConnect/Block/Catalog/Product/Review/List.php ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Review block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Catalog_Product_Review_List
35
+ extends Mage_XmlConnect_Block_Catalog_Product_Review
36
+ {
37
+ /**
38
+ * Store reviews collection
39
+ *
40
+ * @var Mage_Review_Model_Mysql4_Review_Collection
41
+ */
42
+ protected $_reviewCollection = null;
43
+
44
+ /**
45
+ * Produce reviews list xml object
46
+ *
47
+ * @return Mage_XmlConnect_Model_Simplexml_Element
48
+ */
49
+ public function getReviewsXmlObject()
50
+ {
51
+ $reviewsXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<reviews></reviews>');
52
+ $collection = $this->_getReviewCollection();
53
+
54
+ if (!$collection) {
55
+ return $reviewsXmlObj;
56
+ }
57
+ foreach ($collection->getItems() as $review) {
58
+ $reviewXmlObj = $this->reviewToXmlObject($review);
59
+ if ($reviewXmlObj) {
60
+ $reviewsXmlObj->appendChild($reviewXmlObj);
61
+ }
62
+ }
63
+
64
+ return $reviewsXmlObj;
65
+ }
66
+
67
+ /**
68
+ * Retrieve reviews collection with all prepared data and limitations
69
+ *
70
+ * @return Mage_Eav_Model_Entity_Collection_Abstract
71
+ */
72
+ protected function _getReviewCollection()
73
+ {
74
+ if (is_null($this->_reviewCollection)) {
75
+ $product = $this->getProduct();
76
+ $request = $this->getRequest();
77
+ if (!$product) {
78
+ return null;
79
+ }
80
+ /** @var $collection Mage_Review_Model_Mysql4_Review_Collection */
81
+ $collection = Mage::getResourceModel('review/review_collection')
82
+ ->addEntityFilter('product', $product->getId())
83
+ ->addStoreFilter(Mage::app()->getStore()->getId())
84
+ ->addStatusFilter('approved')
85
+ ->setDateOrder();
86
+
87
+ /**
88
+ * Apply offset and count
89
+ */
90
+ $offset = (int)$request->getParam('offset', 0);
91
+ $count = (int)$request->getParam('count', 0);
92
+ $count = $count <= 0 ? 1 : $count;
93
+ $collection->getSelect()->limit($count, $offset);
94
+
95
+ $this->_reviewCollection = $collection;
96
+ }
97
+ return $this->_reviewCollection;
98
+ }
99
+
100
+ /**
101
+ * Render reviews list xml
102
+ *
103
+ * @return string
104
+ */
105
+ protected function _toHtml()
106
+ {
107
+ $product = Mage::getModel('catalog/product')
108
+ ->load((int)$this->getRequest()->getParam('id', 0));
109
+ if ($product->getId()) {
110
+ $this->setProduct($product);
111
+ }
112
+
113
+ return $this->getReviewsXmlObject()->asNiceXml();
114
+ }
115
+ }
app/code/core/Mage/XmlConnect/Block/Catalog/Search.php ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Product search results renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Catalog_Search extends Mage_XmlConnect_Block_Catalog
35
+ {
36
+ /**
37
+ * Search results xml renderer
38
+ * XML also contains filters that can be apply (accorfingly already applyed filters
39
+ * and search query) and sort fields
40
+ *
41
+ * @return string
42
+ */
43
+ protected function _toHtml()
44
+ {
45
+ $searchXmlObject = Mage::getModel('xmlconnect/simplexml_element', '<search></search>');
46
+ $filtersXmlObject = Mage::getModel('xmlconnect/simplexml_element', '<filters></filters>');
47
+
48
+ $helper = Mage::helper('catalogsearch');
49
+ if (method_exists($helper, 'getEngine')) {
50
+ $engine = Mage::helper('catalogsearch')->getEngine();
51
+ $isLayeredNavigationAllowed = ($engine instanceof Varien_Object)
52
+ ? $engine->isLeyeredNavigationAllowed()
53
+ : true;
54
+ } else {
55
+ $isLayeredNavigationAllowed = true;
56
+ }
57
+
58
+ $hasMoreProductItems = 0;
59
+
60
+ /**
61
+ * Products
62
+ */
63
+ $productListBlock = $this->getChild('product_list');
64
+ if ($productListBlock) {
65
+ $layer = Mage::getSingleton('catalogsearch/layer');
66
+ $productsXmlObj = $productListBlock->setLayer($layer)
67
+ ->setNeedBlockApplyingFilters(!$isLayeredNavigationAllowed)
68
+ ->getProductsXmlObject();
69
+ $searchXmlObject->appendChild($productsXmlObj);
70
+ $hasMoreProductItems = (int)$productListBlock->getHasProductItems();
71
+ }
72
+
73
+ $searchXmlObject->addAttribute('has_more_items', $hasMoreProductItems);
74
+
75
+ /**
76
+ * Filters
77
+ */
78
+ $showFiltersAndOrders = (bool) count($productsXmlObj);
79
+ $requestParams = $this->getRequest()->getParams();
80
+ foreach ($requestParams as $key => $value) {
81
+ if (0 === strpos($key, parent::REQUEST_SORT_ORDER_PARAM_REFIX)
82
+ || 0 === strpos($key, parent::REQUEST_FILTER_PARAM_REFIX)
83
+ ) {
84
+ $showFiltersAndOrders = false;
85
+ break;
86
+ }
87
+ }
88
+ if ($isLayeredNavigationAllowed && $productListBlock && $showFiltersAndOrders) {
89
+ $filters = $productListBlock->getCollectedFilters();
90
+ /**
91
+ * Render filters xml
92
+ */
93
+ foreach ($filters as $filter) {
94
+ if (!$this->_isFilterItemsHasValues($filter)) {
95
+ continue;
96
+ }
97
+ $item = $filtersXmlObject->addChild('item');
98
+ $item->addChild('name', $searchXmlObject->escapeXml($filter->getName()));
99
+ $item->addChild('code', $filter->getRequestVar());
100
+ $values = $item->addChild('values');
101
+
102
+ foreach ($filter->getItems() as $valueItem) {
103
+ $count = (int)$valueItem->getCount();
104
+ if (!$count) {
105
+ continue;
106
+ }
107
+ $value = $values->addChild('value');
108
+ $value->addChild('id', $valueItem->getValueString());
109
+ $value->addChild('label', $searchXmlObject->escapeXml($valueItem->getLabel()));
110
+ $value->addChild('count', $count);
111
+ }
112
+ }
113
+ $searchXmlObject->appendChild($filtersXmlObject);
114
+ }
115
+
116
+ /**
117
+ * Sort fields
118
+ */
119
+ if ($showFiltersAndOrders) {
120
+ $searchXmlObject->appendChild($this->getProductSortFeildsXmlObject());
121
+ }
122
+
123
+ return $searchXmlObject->asNiceXml();
124
+ }
125
+
126
+ /**
127
+ * Check if items of specified filter have values
128
+ *
129
+ * @param object $filter filter model
130
+ * @return bool
131
+ */
132
+ protected function _isFilterItemsHasValues($filter)
133
+ {
134
+ if (!$filter->getItemsCount()) {
135
+ return false;
136
+ }
137
+ foreach ($filter->getItems() as $valueItem) {
138
+ if ((int)$valueItem->getCount()) {
139
+ return true;
140
+ }
141
+ }
142
+ return false;
143
+ }
144
+ }
app/code/core/Mage/XmlConnect/Block/Catalog/Search/Suggest.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Product search suggestions renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Catalog_Search_Suggest extends Mage_CatalogSearch_Block_Autocomplete
35
+ {
36
+ /**
37
+ * Suggest item separator
38
+ */
39
+ const SUGGEST_ITEM_SEPARATOR = '::sep::';
40
+
41
+ /**
42
+ * Search suggestions xml renderer
43
+ *
44
+ * @return string
45
+ */
46
+ protected function _toHtml()
47
+ {
48
+ $suggestXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<suggestions></suggestions>');
49
+
50
+ if (!$this->getRequest()->getParam(Mage_CatalogSearch_Helper_Data::QUERY_VAR_NAME, false)) {
51
+ return $suggestXmlObj->asNiceXml();
52
+ }
53
+
54
+ $suggestData = $this->getSuggestData();
55
+ if (!count($suggestData)) {
56
+ return $suggestXmlObj->asNiceXml();
57
+ }
58
+
59
+ $items = '';
60
+ foreach ($suggestData as $item) {
61
+ $items .= $suggestXmlObj->escapeXml($item['title']) . self::SUGGEST_ITEM_SEPARATOR
62
+ . (int)$item['num_of_results'] . self::SUGGEST_ITEM_SEPARATOR;
63
+ }
64
+
65
+ $suggestXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<suggestions>' . $items . '</suggestions>');
66
+
67
+ return $suggestXmlObj->asNiceXml();
68
+ }
69
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Address/Billing.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * One page checkout billing addresses xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Address_Billing extends Mage_Checkout_Block_Onepage_Billing
35
+ {
36
+ /**
37
+ * Render billing addresses xml
38
+ *
39
+ * @return string
40
+ */
41
+ protected function _toHtml()
42
+ {
43
+ $billingXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<billing></billing>');
44
+
45
+ $addressId = $this->getAddress()->getId();
46
+ $address = $this->getCustomer()->getPrimaryBillingAddress();
47
+ if ($address) {
48
+ $addressId = $address->getId();
49
+ }
50
+
51
+ foreach ($this->getCustomer()->getAddresses() as $address) {
52
+ $item = $billingXmlObj->addChild('item');
53
+ if ($addressId == $address->getId()) {
54
+ $item->addAttribute('selected', 1);
55
+ }
56
+ $this->getChild('address_list')->prepareAddressData($address, $item);
57
+ $item->addChild('address_line', $billingXmlObj->escapeXml($address->format('oneline')));
58
+ }
59
+
60
+ return $billingXmlObj->asNiceXml();
61
+ }
62
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Address/Form.php ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer address form xml renderer for onepage checkout
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Address_Form extends Mage_Core_Block_Template
35
+ {
36
+ /**
37
+ * Render customer address form xml
38
+ *
39
+ * @return string
40
+ */
41
+ protected function _toHtml()
42
+ {
43
+ /** @var $xmlModel Mage_XmlConnect_Model_Simplexml_Element */
44
+ $xmlModel = Mage::getModel('xmlconnect/simplexml_element', '<form></form>');
45
+ $xmlModel->addAttribute('name', 'address_form');
46
+ $xmlModel->addAttribute('method', 'post');
47
+
48
+ $addressType = $this->getType();
49
+ if (!$addressType) {
50
+ $addressType = 'billing';
51
+ }
52
+
53
+ $isAllowedGuestCheckout = Mage::getSingleton('checkout/session')
54
+ ->getQuote()
55
+ ->isAllowedGuestCheckout();
56
+
57
+ $countries = $this->_getCountryOptions();
58
+
59
+ $xmlModel->addField($addressType . '[firstname]', 'text', array(
60
+ 'label' => $this->__('First Name'),
61
+ 'required' => 'true',
62
+ 'value' => ''
63
+ )
64
+ );
65
+
66
+ $xmlModel->addField($addressType . '[lastname]', 'text', array(
67
+ 'label' => $this->__('Last Name'),
68
+ 'required' => 'true',
69
+ 'value' => ''
70
+ )
71
+ );
72
+
73
+ $xmlModel->addField($addressType . '[company]', 'text', array(
74
+ 'label' => $this->__('Company'),
75
+ 'required' => 'true',
76
+ 'value' => ''
77
+ )
78
+ );
79
+
80
+ if ($isAllowedGuestCheckout
81
+ && !Mage::getSingleton('customer/session')->isLoggedIn()
82
+ && $addressType == 'billing'
83
+ ) {
84
+ $emailField = $xmlModel->addField($addressType . '[email]', 'text', array(
85
+ 'label' => $this->__('Email Address'),
86
+ 'required' => 'true',
87
+ 'value' => ''
88
+ )
89
+ );
90
+ $emailValidator = $emailField->addChild('validators')->addChild('validator');
91
+ $emailValidator->addAttribute('type', 'email');
92
+ $emailValidator->addAttribute('message', $this->__('Wrong email format'));
93
+ }
94
+
95
+ $xmlModel->addField($addressType . '[street][]', 'text', array(
96
+ 'label' => $this->__('Address'),
97
+ 'required' => 'true',
98
+ 'value' => ''
99
+ )
100
+ );
101
+
102
+ $xmlModel->addField($addressType . '[street][]', 'text', array(
103
+ 'label' => $this->__('Address 2'),
104
+ 'value' => ''
105
+ )
106
+ );
107
+
108
+ $xmlModel->addField($addressType . '[city]', 'text', array(
109
+ 'label' => $this->__('City'),
110
+ 'required' => 'true',
111
+ 'value' => ''
112
+ )
113
+ );
114
+
115
+ $countryOptionsXml = $xmlModel->addField($addressType . '[country_id]', 'select', array(
116
+ 'label' => $this->__('Country'),
117
+ 'required' => 'true',
118
+ 'value' => ''
119
+ )
120
+ )
121
+ ->addChild('values');
122
+
123
+ foreach ($countries as $data) {
124
+ $regions = array();
125
+
126
+ if ($data['value']) {
127
+ $regions = $this->_getRegionOptions($data['value']);
128
+ }
129
+
130
+ $regionStr = (!empty($regions) ? 'region_id' : 'region');
131
+
132
+ $countryXml = $countryOptionsXml->addCustomChild('item', null, array(
133
+ 'relation' => $regionStr
134
+ )
135
+ );
136
+ $countryXml->addCustomChild('label', (string)$data['label']);
137
+ $countryXml->addCustomChild('value', (string)$data['value']);
138
+ if (!empty($regions)) {
139
+ $regionXml = $countryXml->addChild('regions');
140
+
141
+ foreach ($regions as $_data) {
142
+ $regionItemXml = $regionXml->addChild('region_item');
143
+ $regionItemXml->addCustomChild('label', (string)$_data['label']);
144
+ $regionItemXml->addCustomChild('value', (string)$_data['value']);
145
+ }
146
+ }
147
+ }
148
+
149
+ $xmlModel->addField($addressType . '[region]', 'text', array(
150
+ 'label' => $this->__('State/Province'),
151
+ 'value' => ''
152
+ )
153
+ );
154
+
155
+ $xmlModel->addField($addressType . '[region_id]', 'select', array(
156
+ 'label' => $this->__('State/Province'),
157
+ 'required' => 'true',
158
+ 'value' => ''
159
+ )
160
+ );
161
+
162
+ $xmlModel->addField($addressType . '[postcode]', 'text', array(
163
+ 'label' => $this->__('Zip/Postal Code'),
164
+ 'required' => 'true',
165
+ 'value' => ''
166
+ )
167
+ );
168
+
169
+ $xmlModel->addField($addressType . '[telephone]', 'text', array(
170
+ 'label' => $this->__('Telephone'),
171
+ 'required' => 'true',
172
+ 'value' => ''
173
+ )
174
+ );
175
+
176
+ $xmlModel->addField($addressType . '[fax]', 'text', array(
177
+ 'label' => $this->__('Fax'),
178
+ 'value' => ''
179
+ )
180
+ );
181
+
182
+ $xmlModel->addField($addressType . '[save_in_address_book]', 'checkbox', array(
183
+ 'label' => $this->__('Save in address book'),
184
+ )
185
+ );
186
+
187
+ return $xmlModel->asNiceXml();
188
+ }
189
+
190
+ /**
191
+ * Retrieve regions by country
192
+ *
193
+ * @param string $countryId
194
+ * @return array
195
+ */
196
+ protected function _getRegionOptions($countryId)
197
+ {
198
+ $cacheKey = 'DIRECTORY_REGION_SELECT_STORE' . Mage::app()->getStore()->getId() . $countryId;
199
+ if (Mage::app()->useCache('config') && $cache = Mage::app()->loadCache($cacheKey)) {
200
+ $options = unserialize($cache);
201
+ } else {
202
+ $collection = Mage::getModel('directory/region')->getResourceCollection()
203
+ ->addCountryFilter($countryId)
204
+ ->load();
205
+ $options = $collection->toOptionArray();
206
+ if (Mage::app()->useCache('config')) {
207
+ Mage::app()->saveCache(serialize($options), $cacheKey, array('config'));
208
+ }
209
+ }
210
+ return $options;
211
+ }
212
+
213
+ /**
214
+ * Retrieve countries
215
+ *
216
+ * @return array
217
+ */
218
+ protected function _getCountryOptions()
219
+ {
220
+ $cacheKey = 'DIRECTORY_COUNTRY_SELECT_STORE_' . Mage::app()->getStore()->getCode();
221
+ if (Mage::app()->useCache('config') && $cache = Mage::app()->loadCache($cacheKey)) {
222
+ $options = unserialize($cache);
223
+ } else {
224
+ /** @var $collection Mage_Directory_Model_Mysql4_Country_Collection */
225
+ $collection = Mage::getModel('directory/country')->getResourceCollection()
226
+ ->loadByStore();
227
+ $options = $collection->toOptionArray(false);
228
+ if (Mage::app()->useCache('config')) {
229
+ Mage::app()->saveCache(serialize($options), $cacheKey, array('config'));
230
+ }
231
+ }
232
+ return $options;
233
+ }
234
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Address/Shipping.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * One page checkout shipping addresses xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Address_Shipping extends Mage_Checkout_Block_Onepage_Shipping
35
+ {
36
+ /**
37
+ * Render billing shipping xml
38
+ *
39
+ * @return string
40
+ */
41
+ protected function _toHtml()
42
+ {
43
+ $shippingXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<shipping></shipping>');
44
+
45
+ $addressId = $this->getAddress()->getId();
46
+ $address = $this->getCustomer()->getPrimaryShippingAddress();
47
+ if ($address) {
48
+ $addressId = $address->getId();
49
+ }
50
+
51
+ foreach ($this->getCustomer()->getAddresses() as $address) {
52
+ $item = $shippingXmlObj->addChild('item');
53
+ if ($addressId == $address->getId()) {
54
+ $item->addAttribute('selected', 1);
55
+ }
56
+ $this->getChild('address_list')->prepareAddressData($address, $item);
57
+ $item->addChild('address_line', $shippingXmlObj->escapeXml($address->format('oneline')));
58
+ }
59
+
60
+ return $shippingXmlObj->asNiceXml();
61
+ }
62
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Agreements.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * One page checkout agreements xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Agreements extends Mage_Checkout_Block_Agreements
35
+ {
36
+ /**
37
+ * Render agreements xml
38
+ *
39
+ * @return string
40
+ */
41
+ protected function _toHtml()
42
+ {
43
+ $agreementsXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<agreements></agreements>');
44
+ if ($this->getAgreements()) {
45
+ foreach ($this->getAgreements() as $agreement) {
46
+ $itemXmlObj = $agreementsXmlObj->addChild('item');
47
+ $content = $agreement->getContent();
48
+ if (!$agreement->getIsHtml()) {
49
+ $content = nl2br($agreementsXmlObj->escapeXml($content));
50
+ } else {
51
+ $agreementsXmlObj->xmlentities($content);
52
+ }
53
+ $agreementText = $agreementsXmlObj->escapeXml($agreement->getCheckboxText());
54
+ $itemXmlObj->addChild('label', $agreementText);
55
+ $itemXmlObj->addChild('content', $content);
56
+ $itemXmlObj->addChild('code', 'agreement[' . $agreement->getId() . ']');
57
+ $itemXmlObj->addChild('agreement_id', $agreement->getId());
58
+ }
59
+ }
60
+
61
+ return $agreementsXmlObj->asNiceXml();
62
+ }
63
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Order/Review.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * One page checkout order review xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Order_Review extends Mage_Checkout_Block_Onepage_Review
35
+ {
36
+ /**
37
+ * Render order review xml
38
+ *
39
+ * @return string
40
+ */
41
+ protected function _toHtml()
42
+ {
43
+ $orderXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<order></order>');
44
+
45
+ /**
46
+ * Order items
47
+ */
48
+ $products = $this->getChildHtml('order_products');
49
+ if ($products) {
50
+ $productsXmlObj = Mage::getModel('xmlconnect/simplexml_element', $products);
51
+ $orderXmlObj->appendChild($productsXmlObj);
52
+ }
53
+
54
+ /**
55
+ * Totals
56
+ */
57
+ $totalsXml = $this->getChildHtml('totals');
58
+ if ($totalsXml) {
59
+ $totalsXmlObj = Mage::getModel('xmlconnect/simplexml_element', $totalsXml);
60
+ $orderXmlObj->appendChild($totalsXmlObj);
61
+ }
62
+
63
+ /**
64
+ * Agreements
65
+ */
66
+ $agreements = $this->getChildHtml('agreements');
67
+ if ($agreements) {
68
+ $agreementsXmlObj = Mage::getModel('xmlconnect/simplexml_element', $agreements);
69
+ $orderXmlObj->appendChild($agreementsXmlObj);
70
+ }
71
+
72
+ return $orderXmlObj->asNiceXml();
73
+ }
74
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Order/Review/Info.php ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * One page checkout order info xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Order_Review_Info
35
+ extends Mage_Checkout_Block_Onepage_Review_Info
36
+ {
37
+ /**
38
+ * Render order review items
39
+ *
40
+ * @return string
41
+ */
42
+ protected function _toHtml()
43
+ {
44
+ $itemsXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<products></products>');
45
+ $quote = Mage::getSingleton('xmlconnect/corefix_checkout_session')->getQuote();
46
+
47
+ /* @var $item Mage_Sales_Model_Quote_Item */
48
+ foreach ($this->getItems() as $item) {
49
+ $type = $this->_getItemType($item);
50
+ $renderer = $this->getItemRenderer($type)->setItem($item);
51
+
52
+ /**
53
+ * General information
54
+ */
55
+ $itemXml = $itemsXmlObj->addChild('item');
56
+ $itemXml->addChild('entity_id', $item->getProduct()->getId());
57
+ $itemXml->addChild('entity_type', $type);
58
+ $itemXml->addChild('item_id', $item->getId());
59
+ $itemXml->addChild('name', $itemsXmlObj->escapeXml($renderer->getProductName()));
60
+ $itemXml->addChild('qty', $renderer->getQty());
61
+ $icon = $renderer->getProductThumbnail()->resize(
62
+ Mage::helper('xmlconnect/image')->getImageSizeForContent('product_small')
63
+ );
64
+
65
+ $iconXml = $itemXml->addChild('icon', $icon);
66
+
67
+ $file = Mage::helper('xmlconnect')->urlToPath($icon);
68
+ $iconXml->addAttribute('modification_time', filemtime($file));
69
+
70
+ /**
71
+ * Price
72
+ */
73
+ $exclPrice = $inclPrice = 0.00;
74
+ if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) {
75
+ $typeOfDisplay = Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales');
76
+ if ($typeOfDisplay && $item->getWeeeTaxAppliedAmount()) {
77
+ $exclPrice = $item->getCalculationPrice()
78
+ + $item->getWeeeTaxAppliedAmount()
79
+ + $item->getWeeeTaxDisposition();
80
+ } else {
81
+ $exclPrice = $item->getCalculationPrice();
82
+ }
83
+ }
84
+
85
+ if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()) {
86
+ $_incl = $this->helper('checkout')->getPriceInclTax($item);
87
+ $typeOfDisplay = Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales');
88
+ if ($typeOfDisplay && $item->getWeeeTaxAppliedAmount()) {
89
+ $inclPrice = $_incl + $item->getWeeeTaxAppliedAmount();
90
+ } else {
91
+ $inclPrice = $_incl - $item->getWeeeTaxDisposition();
92
+ }
93
+ }
94
+
95
+ $exclPrice = Mage::helper('xmlconnect')->formatPriceForXml($exclPrice);
96
+ $formattedExclPrice = $quote->getStore()->formatPrice($exclPrice, false);
97
+
98
+ $inclPrice = Mage::helper('xmlconnect')->formatPriceForXml($inclPrice);
99
+ $formattedInclPrice = $quote->getStore()->formatPrice($inclPrice, false);
100
+
101
+ $priceXmlObj = $itemXml->addChild('price');
102
+ $formattedPriceXmlObj = $itemXml->addChild('formated_price');
103
+
104
+ if ($this->helper('tax')->displayCartBothPrices()) {
105
+ $priceXmlObj->addAttribute('excluding_tax', $exclPrice);
106
+ $priceXmlObj->addAttribute('including_tax', $inclPrice);
107
+
108
+ $formattedPriceXmlObj->addAttribute('excluding_tax', $formattedExclPrice);
109
+ $formattedPriceXmlObj->addAttribute('including_tax', $formattedInclPrice);
110
+ } else {
111
+ if ($this->helper('tax')->displayCartPriceExclTax()) {
112
+ $priceXmlObj->addAttribute('regular', $exclPrice);
113
+ $formattedPriceXmlObj->addAttribute('regular', $formattedExclPrice);
114
+ }
115
+ if ($this->helper('tax')->displayCartPriceInclTax()) {
116
+ $priceXmlObj->addAttribute('regular', $inclPrice);
117
+ $formattedPriceXmlObj->addAttribute('regular', $formattedInclPrice);
118
+ }
119
+ }
120
+
121
+ /**
122
+ * Subtotal
123
+ */
124
+ $exclPrice = $inclPrice = 0.00;
125
+ if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) {
126
+ $typeOfDisplay = Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales');
127
+ if ($typeOfDisplay && $item->getWeeeTaxAppliedAmount()) {
128
+ $exclPrice = $item->getRowTotal()
129
+ + $item->getWeeeTaxAppliedRowAmount()
130
+ + $item->getWeeeTaxRowDisposition();
131
+ } else {
132
+ $exclPrice = $item->getRowTotal();
133
+ }
134
+ }
135
+ if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()) {
136
+ $_incl = $this->helper('checkout')->getSubtotalInclTax($item);
137
+ if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales')
138
+ && $item->getWeeeTaxAppliedAmount()
139
+ ) {
140
+ $inclPrice = $_incl + $item->getWeeeTaxAppliedRowAmount();
141
+ } else {
142
+ $inclPrice = $_incl - $item->getWeeeTaxRowDisposition();
143
+ }
144
+ }
145
+
146
+ $exclPrice = Mage::helper('xmlconnect')->formatPriceForXml($exclPrice);
147
+ $formattedExclPrice = $quote->getStore()->formatPrice($exclPrice, false);
148
+
149
+ $inclPrice = Mage::helper('xmlconnect')->formatPriceForXml($inclPrice);
150
+ $formattedInclPrice = $quote->getStore()->formatPrice($inclPrice, false);
151
+
152
+ $subtotalPriceXmlObj = $itemXml->addChild('subtotal');
153
+ $subtotalFormattedPriceXmlObj = $itemXml->addChild('formated_subtotal');
154
+
155
+ if ($this->helper('tax')->displayCartBothPrices()) {
156
+ $subtotalPriceXmlObj->addAttribute('excluding_tax', $exclPrice);
157
+ $subtotalPriceXmlObj->addAttribute('including_tax', $inclPrice);
158
+
159
+ $subtotalFormattedPriceXmlObj->addAttribute('excluding_tax', $formattedExclPrice);
160
+ $subtotalFormattedPriceXmlObj->addAttribute('including_tax', $formattedInclPrice);
161
+ } else {
162
+ if ($this->helper('tax')->displayCartPriceExclTax()) {
163
+ $subtotalPriceXmlObj->addAttribute('regular', $exclPrice);
164
+ $subtotalFormattedPriceXmlObj->addAttribute('regular', $formattedExclPrice);
165
+ }
166
+ if ($this->helper('tax')->displayCartPriceInclTax()) {
167
+ $subtotalPriceXmlObj->addAttribute('regular', $inclPrice);
168
+ $subtotalFormattedPriceXmlObj->addAttribute('regular', $formattedInclPrice);
169
+ }
170
+ }
171
+
172
+ /**
173
+ * Options list
174
+ */
175
+ $_options = $renderer->getOptionList();
176
+ if ($_options) {
177
+ $itemOptionsXml = $itemXml->addChild('options');
178
+ foreach ($_options as $_option) {
179
+ $_formattedOptionValue = $renderer->getFormatedOptionValue($_option);
180
+ $optionXml = $itemOptionsXml->addChild('option');
181
+ $labelValue = $itemsXmlObj->escapeXml($_option['label']);
182
+ $optionXml->addAttribute('label', $labelValue);
183
+ $textValue = $itemsXmlObj->escapeXml($_formattedOptionValue['value']);
184
+ $optionXml->addAttribute('text', $textValue);
185
+ }
186
+ }
187
+ }
188
+
189
+ return $itemsXmlObj->asNiceXml();
190
+ }
191
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Authorizenet.php ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Credit Card (Authorize.net) Payment method xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Payment_Method_Authorizenet extends Mage_Payment_Block_Form_Ccsave
35
+ {
36
+ /**
37
+ * Prevent any rendering
38
+ *
39
+ * @return string
40
+ */
41
+ protected function _toHtml()
42
+ {
43
+ return '';
44
+ }
45
+
46
+ /**
47
+ * Retrieve payment method model
48
+ *
49
+ * @return Mage_Payment_Model_Method_Abstract
50
+ */
51
+ public function getMethod()
52
+ {
53
+ $method = $this->getData('method');
54
+ if (!$method) {
55
+ $method = Mage::getModel('paygate/authorizenet');
56
+ $this->setData('method', $method);
57
+ }
58
+
59
+ return $method;
60
+ }
61
+
62
+ /**
63
+ * Add Authorize.net payment method form to payment XML object
64
+ *
65
+ * @param Mage_XmlConnect_Model_Simplexml_Element $paymentItemXmlObj
66
+ * @return Mage_XmlConnect_Model_Simplexml_Element
67
+ */
68
+ public function addPaymentFormToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $paymentItemXmlObj)
69
+ {
70
+ $helper = Mage::helper('xmlconnect');
71
+ $method = $this->getMethod();
72
+ if (!$method) {
73
+ return $paymentItemXmlObj;
74
+ }
75
+ $formXmlObj = $paymentItemXmlObj->addChild('form');
76
+ $formXmlObj->addAttribute('name', 'payment_form_' . $method->getCode());
77
+ $formXmlObj->addAttribute('method', 'post');
78
+
79
+ $ccTypes = $helper->getArrayAsXmlItemValues($this->getCcAvailableTypes(), $this->getInfoData('cc_type'));
80
+
81
+ $ccMonths = $helper->getArrayAsXmlItemValues($this->getCcMonths(), $this->getInfoData('cc_exp_month'));
82
+
83
+ $ccYears = $helper->getArrayAsXmlItemValues($this->getCcYears(), $this->getInfoData('cc_exp_year'));
84
+
85
+ $verification = '';
86
+ if ($this->hasVerification()) {
87
+ $cvnText = $this->__('Card Verification Number');
88
+ $cvnValidationText = $this->__('Card verification number is wrong');
89
+ $verification =
90
+ '<field name="payment[cc_cid]" type="text" label="' . $cvnText . '" required="true">
91
+ <validators>
92
+ <validator relation="payment[cc_type]" type="credit_card_svn" message="' . $cvnValidationText . '"/>
93
+ </validators>
94
+ </field>';
95
+ }
96
+
97
+ $cvnValidationText = $this->__('Credit card number does not match credit card type.');
98
+ $expMonthText = $this->__('Expiration Date - Month');
99
+ $expYearText = $this->__('Expiration Date - Year');
100
+ $xml = <<<EOT
101
+ <fieldset>
102
+ <field name="payment[cc_type]" type="select" label="{$this->__('Credit Card Type')}" required="true">
103
+ <values>
104
+ {$ccTypes}
105
+ </values>
106
+ </field>
107
+ <field name="payment[cc_number]" type="text" label="{$this->__('Credit Card Number')}" required="true">
108
+ <validators>
109
+ <validator relation="payment[cc_type]" type="credit_card" message="{$cvnValidationText}"/>
110
+ </validators>
111
+ </field>
112
+ <field name="payment[cc_exp_month]" type="select" label="{$expMonthText}" required="true">
113
+ <values>
114
+ {$ccMonths}
115
+ </values>
116
+ </field>
117
+ <field name="payment[cc_exp_year]" type="select" label="{$expYearText}" required="true">
118
+ <values>
119
+ {$ccYears}
120
+ </values>
121
+ </field>
122
+ {$verification}
123
+ </fieldset>
124
+ EOT;
125
+ $fieldsetXmlObj = Mage::getModel('xmlconnect/simplexml_element', $xml);
126
+ $formXmlObj->appendChild($fieldsetXmlObj);
127
+ }
128
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Ccsave.php ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * CC Save Payment method xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Payment_Method_Ccsave
35
+ extends Mage_Payment_Block_Form_Ccsave
36
+ {
37
+ /**
38
+ * Prevent any rendering
39
+ *
40
+ * @return string
41
+ */
42
+ protected function _toHtml()
43
+ {
44
+ return '';
45
+ }
46
+
47
+ /**
48
+ * Retrieve payment method model
49
+ *
50
+ * @return Mage_Payment_Model_Method_Abstract
51
+ */
52
+ public function getMethod()
53
+ {
54
+ $method = $this->getData('method');
55
+ if (!$method) {
56
+ $method = Mage::getModel('payment/method_ccsave');
57
+ $this->setData('method', $method);
58
+ }
59
+
60
+ return $method;
61
+ }
62
+
63
+ /**
64
+ * Add cc save payment method form to payment XML object
65
+ *
66
+ * @param Mage_XmlConnect_Model_Simplexml_Element $paymentItemXmlObj
67
+ * @return Mage_XmlConnect_Model_Simplexml_Element
68
+ */
69
+ public function addPaymentFormToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $paymentItemXmlObj)
70
+ {
71
+ $helper = Mage::helper('xmlconnect');
72
+ $method = $this->getMethod();
73
+ if (!$method) {
74
+ return $paymentItemXmlObj;
75
+ }
76
+ $formXmlObj = $paymentItemXmlObj->addChild('form');
77
+ $formXmlObj->addAttribute('name', 'payment_form_' . $method->getCode());
78
+ $formXmlObj->addAttribute('method', 'post');
79
+
80
+ $owner = $this->getInfoData('cc_owner');
81
+
82
+ $ccTypes = $helper->getArrayAsXmlItemValues($this->getCcAvailableTypes(), $this->getInfoData('cc_type'));
83
+
84
+ $_ccMonthArray = $this->getCcMonths();
85
+ $ccMonths = $helper->getArrayAsXmlItemValues($_ccMonthArray, $this->getInfoData('cc_exp_month'));
86
+
87
+ $ccYears = $helper->getArrayAsXmlItemValues($this->getCcYears(), $this->getInfoData('cc_exp_year'));
88
+
89
+ $verification = '';
90
+ if ($this->hasVerification()) {
91
+ $verification =
92
+ '<field name="payment[cc_cid]" type="text" label="'
93
+ . $this->__('Card Verification Number') . '" required="true">
94
+ <validators>
95
+ <validator relation="payment[cc_type]" type="credit_card_svn" message="'
96
+ . $this->__('Card verification number is wrong') . '"/>
97
+ </validators>
98
+ </field>';
99
+ }
100
+
101
+ $solo = '';
102
+ if ($this->hasSsCardType()) {
103
+ $ssCcMonths = $helper->getArrayAsXmlItemValues(
104
+ $_ccMonthArray, $this->getInfoData('cc_ss_start_month')
105
+ );
106
+ $ssCcYears = $helper->getArrayAsXmlItemValues(
107
+ $this->getSsStartYears(), $this->getInfoData('cc_ss_start_year')
108
+ );
109
+ $solo = $helper->getSoloXml($ssCcMonths, $ssCcYears);
110
+ }
111
+
112
+ $xml = <<<EOT
113
+ <fieldset>
114
+ <field name="payment[cc_owner]" type="text" label="{$this->__('Name on Card')}" value="$owner" required="true" />
115
+ <field name="payment[cc_type]" type="select" label="{$this->__('Credit Card Type')}" required="true">
116
+ <values>
117
+ {$ccTypes}
118
+ </values>
119
+ {$solo}
120
+ </field>
121
+ <field name="payment[cc_number]" type="text" label="{$this->__('Credit Card Number')}" required="true">
122
+ <validators>
123
+ <validator relation="payment[cc_type]" type="credit_card" message="{$this->__('Credit card number does not match credit card type.')}"/>
124
+ </validators>
125
+ </field>
126
+ <field name="payment[cc_exp_month]" type="select" label="{$this->__('Expiration Date - Month')}" required="true">
127
+ <values>
128
+ {$ccMonths}
129
+ </values>
130
+ </field>
131
+ <field name="payment[cc_exp_year]" type="select" label="{$this->__('Expiration Date - Year')}" required="true">
132
+ <values>
133
+ {$ccYears}
134
+ </values>
135
+ </field>
136
+ $verification
137
+ </fieldset>
138
+ EOT;
139
+ $fieldsetXmlObj = Mage::getModel('xmlconnect/simplexml_element', $xml);
140
+ $formXmlObj->appendChild($fieldsetXmlObj);
141
+ }
142
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Checkmo.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Check / Money order Payment method xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Payment_Method_Checkmo
35
+ extends Mage_Payment_Block_Form_Checkmo
36
+ {
37
+ /**
38
+ * Prevent any rendering
39
+ *
40
+ * @return string
41
+ */
42
+ protected function _toHtml()
43
+ {
44
+ return '';
45
+ }
46
+
47
+ /**
48
+ * Retrieve payment method model
49
+ *
50
+ * @return Mage_Payment_Model_Method_Abstract
51
+ */
52
+ public function getMethod()
53
+ {
54
+ $method = $this->getData('method');
55
+ if (!$method) {
56
+ $method = Mage::getModel('payment/method_checkmo');
57
+ $this->setData('method', $method);
58
+ }
59
+
60
+ return $method;
61
+ }
62
+
63
+ /**
64
+ * Add cc save payment method form to payment XML object
65
+ *
66
+ * @param Mage_XmlConnect_Model_Simplexml_Element $paymentItemXmlObj
67
+ * @return Mage_XmlConnect_Model_Simplexml_Element
68
+ */
69
+ public function addPaymentFormToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $paymentItemXmlObj)
70
+ {
71
+ return $paymentItemXmlObj;
72
+ }
73
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Authorizenet.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Authorizenet Payment info xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Authorizenet
35
+ extends Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Pbridge_Verisign
36
+ {
37
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Ccsave.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * CC Save Payment info xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Ccsave extends Mage_Payment_Block_Info_Ccsave
35
+ {
36
+ /**
37
+ * Add CC Save Payment info to order XML object
38
+ *
39
+ * @param Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj
40
+ * @return Mage_XmlConnect_Model_Simplexml_Element
41
+ */
42
+ public function addPaymentInfoToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj)
43
+ {
44
+ $orderItemXmlObj->addAttribute('type', $this->getMethod()->getCode());
45
+ $orderItemXmlObj->addAttribute(
46
+ 'title',
47
+ $orderItemXmlObj->xmlAttribute($this->getMethod()->getTitle())
48
+ );
49
+
50
+ if ($_specificInfo = $this->getSpecificInformation()) {
51
+ foreach ($_specificInfo as $label => $value) {
52
+ $orderItemXmlObj->addCustomChild(
53
+ 'item',
54
+ implode($this->getValueAsArray($value, true), PHP_EOL),
55
+ array(
56
+ 'label' => $label
57
+ )
58
+ );
59
+ }
60
+ }
61
+ }
62
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Checkmo.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Check / Money order Payment info xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Checkmo extends Mage_Payment_Block_Info_Checkmo
35
+ {
36
+ /**
37
+ * Add Check / Money order info to order XML object
38
+ *
39
+ * @param Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj
40
+ * @return Mage_XmlConnect_Model_Simplexml_Element
41
+ */
42
+ public function addPaymentInfoToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj)
43
+ {
44
+ $orderItemXmlObj->addAttribute('type', $this->getMethod()->getCode());
45
+ $orderItemXmlObj->addAttribute(
46
+ 'title',
47
+ $orderItemXmlObj->xmlAttribute($this->getMethod()->getTitle())
48
+ );
49
+
50
+ if ($this->getInfo()->getAdditionalData()) {
51
+ if ($this->getPayableTo()) {
52
+ $orderItemXmlObj->addCustomChild(
53
+ 'item',
54
+ $this->getPayableTo(),
55
+ array(
56
+ 'label' => Mage::helper('sales')->__('Make Check payable to:')
57
+ )
58
+ );
59
+ }
60
+ if ($this->getMailingAddress()) {
61
+ $orderItemXmlObj->addCustomChild(
62
+ 'item',
63
+ $this->getMailingAddress(),
64
+ array(
65
+ 'label' => Mage::helper('payment')->__('Send Check to:')
66
+ )
67
+ );
68
+ }
69
+ }
70
+ }
71
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Free.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Free Payment info xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Free extends Mage_Payment_Block_Info
35
+ {
36
+ /**
37
+ * Add Check / Money order info to order XML object
38
+ *
39
+ * @param Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj
40
+ * @return Mage_XmlConnect_Model_Simplexml_Element
41
+ */
42
+ public function addPaymentInfoToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj)
43
+ {
44
+ $orderItemXmlObj->addAttribute('type', $this->getMethod()->getCode());
45
+ $orderItemXmlObj->addAttribute(
46
+ 'title',
47
+ $orderItemXmlObj->xmlAttribute($this->getMethod()->getTitle())
48
+ );
49
+ }
50
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Paypal/Abstract.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Abstract PayPal Payment info xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ abstract class Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Paypal_Abstract
35
+ extends Mage_Paypal_Block_Payment_Info
36
+ {
37
+ /**
38
+ * Add CC Save Payment info to order XML object
39
+ *
40
+ * @param Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj
41
+ * @return Mage_XmlConnect_Model_Simplexml_Element
42
+ */
43
+ public function addPaymentInfoToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj)
44
+ {
45
+ $orderItemXmlObj->addAttribute('type', $this->getMethod()->getCode());
46
+ $orderItemXmlObj->addAttribute(
47
+ 'title',
48
+ $orderItemXmlObj->xmlAttribute($this->getMethod()->getTitle())
49
+ );
50
+
51
+ if ($_specificInfo = $this->getSpecificInformation()) {
52
+ foreach ($_specificInfo as $label => $value) {
53
+ $orderItemXmlObj->addCustomChild(
54
+ 'item',
55
+ implode($this->getValueAsArray($value, true), PHP_EOL),
56
+ array(
57
+ 'label' => $label
58
+ )
59
+ );
60
+ }
61
+ }
62
+ }
63
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Paypal/Express.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * PayPal Express Payment info xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Paypal_Express
35
+ extends Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Paypal_Abstract
36
+ {
37
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Paypal/Mecl.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * PayPal Mobile Express Payment info xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Paypal_Mecl
35
+ extends Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Paypal_Abstract
36
+ {
37
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Pbridge/Authorizenet.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Authorizenet Payment info xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Pbridge_Authorizenet
35
+ extends Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Authorizenet
36
+ {
37
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Pbridge/Paypal/Direct.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * PayPal Direct Payment (PBridge) info xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Pbridge_Paypal_Direct
35
+ extends Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Paypal_Abstract
36
+ {
37
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Pbridge/Paypaluk/Direct.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * PayPal Direct Payment Payflow Edition (PBridge) info xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Pbridge_Paypaluk_Direct
35
+ extends Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Paypal_Abstract
36
+ {
37
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Pbridge/Verisign.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Payflow Pro (PBridge) Payment info xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Pbridge_Verisign
35
+ extends Mage_Payment_Block_Info_Cc
36
+ {
37
+ /**
38
+ * Add CC Save Payment info to order XML object
39
+ *
40
+ * @param Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj
41
+ * @return Mage_XmlConnect_Model_Simplexml_Element
42
+ */
43
+ public function addPaymentInfoToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj)
44
+ {
45
+ $orderItemXmlObj->addAttribute('type', $this->getMethod()->getCode());
46
+ $orderItemXmlObj->addAttribute(
47
+ 'title',
48
+ $orderItemXmlObj->xmlAttribute($this->getMethod()->getTitle())
49
+ );
50
+
51
+ if ($_specificInfo = $this->getSpecificInformation()) {
52
+ foreach ($_specificInfo as $label => $value) {
53
+ $orderItemXmlObj->addCustomChild(
54
+ 'item',
55
+ implode($this->getValueAsArray($value, true), PHP_EOL),
56
+ array(
57
+ 'label' => $label
58
+ )
59
+ );
60
+ }
61
+ }
62
+ }
63
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Purchaseorder.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Purchase Order Payment info xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Purchaseorder
35
+ extends Mage_Payment_Block_Info_Purchaseorder
36
+ {
37
+ /**
38
+ * Add Purchase Order Payment info to order XML object
39
+ *
40
+ * @param Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj
41
+ * @return Mage_XmlConnect_Model_Simplexml_Element
42
+ */
43
+ public function addPaymentInfoToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj)
44
+ {
45
+ $orderItemXmlObj->addAttribute('type', $this->getMethod()->getCode());
46
+ $orderItemXmlObj->addAttribute(
47
+ 'title',
48
+ $orderItemXmlObj->xmlAttribute($this->getMethod()->getTitle())
49
+ );
50
+
51
+ $orderItemXmlObj->addCustomChild(
52
+ 'item',
53
+ $this->getInfo()->getPoNumber(),
54
+ array(
55
+ 'label' => Mage::helper('sales')->__('Purchase Order Number:')
56
+ )
57
+ );
58
+ }
59
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/List.php ADDED
@@ -0,0 +1,366 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * One page checkout payment methods xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Payment_Method_List
35
+ extends Mage_Payment_Block_Form_Container
36
+ {
37
+ /**
38
+ * Pre-defined array of methods that we are going to render
39
+ *
40
+ * @var array
41
+ */
42
+ protected $_methodArray = array(
43
+ 'payment_ccsave' => 'Mage_Payment_Model_Method_Cc',
44
+ 'payment_checkmo' => 'Mage_Payment_Model_Method_Checkmo',
45
+ 'payment_purchaseorder' => 'Mage_Payment_Model_Method_Purchaseorder',
46
+ );
47
+
48
+ /**
49
+ * Payment bridge methods array
50
+ *
51
+ * Core block renderer by method code
52
+ * - 'pbridge_authorizenet' => 'Enterprise_Pbridge_Model_Payment_Method_Authorizenet',
53
+ * - 'pbridge_paypal' => 'Enterprise_Pbridge_Model_Payment_Method_Paypal',
54
+ * - 'pbridge_verisign' => 'Enterprise_Pbridge_Model_Payment_Method_Payflow_Pro',
55
+ * - 'pbridge_paypaluk' => 'Enterprise_Pbridge_Model_Payment_Method_Paypaluk',
56
+ *
57
+ * @var array
58
+ */
59
+ protected $_pbridgeMethodArray = array(
60
+ 'pbridge_authorizenet',
61
+ 'pbridge_paypal',
62
+ 'pbridge_verisign',
63
+ 'pbridge_paypaluk',
64
+ );
65
+
66
+ /**
67
+ * Prevent parent set children
68
+ *
69
+ * @return Mage_XmlConnect_Block_Checkout_Payment_Method_List
70
+ */
71
+ protected function _prepareLayout()
72
+ {
73
+ return $this;
74
+ }
75
+
76
+ /**
77
+ * Retrieve quote model object
78
+ *
79
+ * @return Mage_Sales_Model_Quote
80
+ */
81
+ public function getQuote()
82
+ {
83
+ return Mage::getSingleton('xmlconnect/corefix_checkout_session')->getQuote();
84
+ }
85
+
86
+ /**
87
+ * Add customer balance details to XML object
88
+ *
89
+ * @param Mage_XmlConnect_Model_Simplexml_Element $methodsXmlObj
90
+ */
91
+ public function addCustomerBalanceToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $methodsXmlObj)
92
+ {
93
+ /** @var $customerBalanceBlock Enterprise_CustomerBalance_Block_Checkout_Onepage_Payment_Additional */
94
+ $customerBalanceBlock = $this->getLayout()
95
+ ->addBlock('enterprise_customerbalance/checkout_onepage_payment_additional', 'customer_balance');
96
+ $storeCreditFlag = (int) Mage::getStoreConfig(Enterprise_CustomerBalance_Helper_Data::XML_PATH_ENABLED);
97
+ if ($storeCreditFlag && $customerBalanceBlock->isDisplayContainer()) {
98
+ $balance = $this->getQuote()->getStore()->formatPrice($customerBalanceBlock->getBalance(), false);
99
+ $methodsXmlObj->addCustomChild(
100
+ 'customer_balance',
101
+ null,
102
+ array(
103
+ 'post_name' => 'payment[use_customer_balance]',
104
+ 'code' => 1,
105
+ 'label' => $this->__('Use Store Credit (%s available)', $balance),
106
+ 'is_cover_a_quote' => intval($customerBalanceBlock->isFullyPaidAfterApplication()),
107
+ 'selected' => intval($customerBalanceBlock->isCustomerBalanceUsed())
108
+ )
109
+ );
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Add gift card details to XML object
115
+ *
116
+ * @param Mage_XmlConnect_Model_Simplexml_Element $methodsXmlObj
117
+ */
118
+ public function addGiftcardToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $methodsXmlObj)
119
+ {
120
+ $giftcardInfoBlock = $this->getLayout()->addBlock(
121
+ 'enterprise_giftcardaccount/checkout_onepage_payment_additional',
122
+ 'giftcard_info'
123
+ );
124
+
125
+ if (intval($giftcardInfoBlock->getAppliedGiftCardAmount())) {
126
+ $amount = $this->getQuote()
127
+ ->getStore()
128
+ ->formatPrice($giftcardInfoBlock->getAppliedGiftCardAmount(), false);
129
+ $amount = $this->__('Gift Card amount applied to order: %s', $amount);
130
+
131
+ $methodsXmlObj->addCustomChild(
132
+ 'information',
133
+ null,
134
+ array(
135
+ 'label' => $amount,
136
+ 'disabled' => '1'
137
+ )
138
+ );
139
+
140
+ if ($this->_isPaymentRequired()) {
141
+ $methodsXmlObj->addCustomChild(
142
+ 'method',
143
+ null,
144
+ array(
145
+ 'post_name' => 'payment[method]',
146
+ 'code' => 'free',
147
+ 'label' => $this->__('No Payment Information Required'),
148
+ 'selected' => '1',
149
+ 'disabled' => '1'
150
+ )
151
+ );
152
+ }
153
+ $this->setIsUsedGiftCard(true);
154
+ }
155
+ }
156
+
157
+ /**
158
+ * Check is payment required for a quote
159
+ *
160
+ * @return bool
161
+ */
162
+ protected function _isPaymentRequired()
163
+ {
164
+ $this->getQuote()->collectTotals();
165
+ return !intval($this->getQuote()->getGrandTotal()) && !$this->getQuote()->hasNominalItems();
166
+ }
167
+
168
+ /**
169
+ * Get payment methods array as code => renderer and set payment blocks to layout
170
+ *
171
+ * @return array
172
+ */
173
+ protected function _getPaymentMethodArray()
174
+ {
175
+ $methodArray = $this->_methodArray;
176
+
177
+ /**
178
+ * Check is available Payment Bridge and add methods for rendering
179
+ */
180
+ if (is_object(Mage::getConfig()->getNode('modules/Enterprise_Pbridge'))) {
181
+
182
+ $pbBlockRenderer = 'xmlconnect/checkout_payment_method_';
183
+ $pbBlockName = 'xmlconnect.checkout.payment.method.';
184
+
185
+ foreach ($this->_pbridgeMethodArray as $block) {
186
+ $currentBlockRenderer = $pbBlockRenderer . $block;
187
+ $currentBlockName = $pbBlockName . $block;
188
+ $this->getLayout()->addBlock($currentBlockRenderer, $currentBlockName);
189
+ $this->setChild($block, $currentBlockName);
190
+ }
191
+ $methodArray = $methodArray + $this->_pbridgeMethodArray;
192
+ }
193
+ return $methodArray;
194
+ }
195
+
196
+ /**
197
+ * Render payment methods xml
198
+ *
199
+ * @return string
200
+ * @throw Mage_Core_Exception
201
+ */
202
+ protected function _toHtml()
203
+ {
204
+ /** @var $methodsXmlObj Mage_XmlConnect_Model_Simplexml_Element */
205
+ $methodsXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<payment_methods></payment_methods>');
206
+
207
+ if (is_object(Mage::getConfig()->getNode('modules/Enterprise_GiftCardAccount'))) {
208
+ $this->addGiftcardToXmlObj($methodsXmlObj);
209
+ if ($this->getIsUsedGiftCard() && $this->_isPaymentRequired()) {
210
+ return $methodsXmlObj->asNiceXml();
211
+ }
212
+ }
213
+
214
+ if (is_object(Mage::getConfig()->getNode('modules/Enterprise_CustomerBalance'))) {
215
+ $this->addCustomerBalanceToXmlObj($methodsXmlObj);
216
+ }
217
+
218
+ $methodArray = $this->_getPaymentMethodArray();
219
+ $usedMethods = $sortedAvailableMethodCodes = $usedCodes = array();
220
+
221
+ /**
222
+ * Receive available methods for checkout
223
+ */
224
+ $allAvailableMethods = Mage::helper('payment')->getStoreMethods(
225
+ Mage::app()->getStore(), $this->getQuote()
226
+ );
227
+
228
+ /**
229
+ * Get sorted codes of available methods
230
+ */
231
+ foreach ($allAvailableMethods as $method) {
232
+ $sortedAvailableMethodCodes[] = $method->getCode();
233
+ }
234
+
235
+ /**
236
+ * Get blocks for layout to check available renderers
237
+ */
238
+ $methodBlocks = $this->getChild();
239
+
240
+ /**
241
+ * Collect directly supported by xmlconnect methods
242
+ */
243
+ if (!empty($methodBlocks) && is_array($methodBlocks)) {
244
+ foreach ($methodBlocks as $block) {
245
+ if (!$block) {
246
+ continue;
247
+ }
248
+
249
+ $method = $block->getMethod();
250
+ if (!$this->_canUseMethod($method) || in_array($method->getCode(), $usedCodes)) {
251
+ continue;
252
+ }
253
+ $this->_assignMethod($method);
254
+ $usedCodes[] = $method->getCode();
255
+ $usedMethods[$method->getCode()] = array('renderer' => $block, 'method' => $method);
256
+ }
257
+ }
258
+
259
+ /**
260
+ * Collect all "Credit Card" / "CheckMo" / "Purchaseorder" method compatible methods
261
+ */
262
+ foreach ($methodArray as $methodName => $methodModelClassName) {
263
+ $methodRenderer = $this->getChild($methodName);
264
+ if (!empty($methodRenderer)) {
265
+ foreach ($sortedAvailableMethodCodes as $methodCode) {
266
+ /**
267
+ * Skip used methods
268
+ */
269
+ if (in_array($methodCode, $usedCodes)) {
270
+ continue;
271
+ }
272
+ try {
273
+ $method = Mage::helper('payment')->getMethodInstance($methodCode);
274
+ if (!is_subclass_of($method, $methodModelClassName)) {
275
+ continue;
276
+ }
277
+ if (!$this->_canUseMethod($method)) {
278
+ continue;
279
+ }
280
+
281
+ $this->_assignMethod($method);
282
+ $usedCodes[] = $method->getCode();
283
+ $usedMethods[$method->getCode()] = array('renderer' => $methodRenderer, 'method' => $method);
284
+ } catch (Exception $e) {
285
+ Mage::logException($e);
286
+ }
287
+ }
288
+ }
289
+ }
290
+
291
+ /**
292
+ * Generate methods XML according to sort order
293
+ */
294
+ foreach ($sortedAvailableMethodCodes as $code) {
295
+ if (!in_array($code, $usedCodes)) {
296
+ continue;
297
+ }
298
+ $method = $usedMethods[$code]['method'];
299
+ $renderer = $usedMethods[$code]['renderer'];
300
+ /**
301
+ * Render all Credit Card method compatible methods
302
+ */
303
+ if ($renderer instanceOf Mage_XmlConnect_Block_Checkout_Payment_Method_Ccsave) {
304
+ $renderer->setData('method', $method);
305
+ }
306
+
307
+ $methodItemXmlObj = $methodsXmlObj->addChild('method');
308
+ $methodItemXmlObj->addAttribute('post_name', 'payment[method]');
309
+ $methodItemXmlObj->addAttribute('code', $method->getCode());
310
+ $methodItemXmlObj->addAttribute('label', $methodsXmlObj->escapeXml($method->getTitle()));
311
+ if ($this->getQuote()->getPayment()->getMethod() == $method->getCode()) {
312
+ $methodItemXmlObj->addAttribute('selected', 1);
313
+ }
314
+ $renderer->addPaymentFormToXmlObj($methodItemXmlObj);
315
+ }
316
+ if (!count($usedMethods)) {
317
+ Mage::throwException(
318
+ $this->__('Sorry, no payment options are available for this order at this time.')
319
+ );
320
+ }
321
+ return $methodsXmlObj->asNiceXml();
322
+ }
323
+
324
+ /**
325
+ * Check and prepare payment method model
326
+ *
327
+ * @param mixed $method
328
+ * @return bool
329
+ */
330
+ protected function _canUseMethod($method)
331
+ {
332
+ if (!($method instanceof Mage_Payment_Model_Method_Abstract)
333
+ || !$method->canUseCheckout()
334
+ || !$method->isAvailable($this->getQuote())
335
+ ) {
336
+ return false;
337
+ }
338
+ return parent::_canUseMethod($method);
339
+ }
340
+
341
+ /**
342
+ * Deprecated function adding Payment method to the xml
343
+ *
344
+ * @deprecated after 1.4.2.0
345
+ * @param Mage_Core_Block_Template $block
346
+ * @param Mage_XmlConnect_Model_Simplexml_Element $methodsXmlObj
347
+ * @param array $usedCodes
348
+ * @return bool
349
+ */
350
+ protected function _addToXml($block, $methodsXmlObj, $usedCodes)
351
+ {
352
+ return false;
353
+ }
354
+
355
+ /**
356
+ * Deprecated function check method status
357
+ *
358
+ * @deprecated after 1.4.2.0
359
+ * @param Mage_Payment_Model_Method_Abstract $method
360
+ * @return bool
361
+ */
362
+ public function isAvailable($method)
363
+ {
364
+ return $method->isAvailable($this->getQuote());
365
+ }
366
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Paypal/Direct.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * PayPal Direct Payment method xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Payment_Method_Paypal_Direct
35
+ extends Mage_XmlConnect_Block_Checkout_Payment_Method_Paypal_Payflow
36
+ {
37
+ /**
38
+ * Prevent any rendering
39
+ *
40
+ * @return string
41
+ */
42
+ protected function _toHtml()
43
+ {
44
+ return '';
45
+ }
46
+
47
+ /**
48
+ * Retrieve payment method model
49
+ *
50
+ * @return Mage_Payment_Model_Method_Abstract
51
+ */
52
+ public function getMethod()
53
+ {
54
+ $method = $this->getData('method');
55
+ if (!$method) {
56
+ $method = Mage::getModel('paypal/direct');
57
+ $this->setData('method', $method);
58
+ }
59
+
60
+ return $method;
61
+ }
62
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Paypal/Payflow.php ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Credit Card (Payflow Pro) Payment method xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Payment_Method_Paypal_Payflow
35
+ extends Mage_Payment_Block_Form_Ccsave
36
+ {
37
+ /**
38
+ * Prevent any rendering
39
+ *
40
+ * @return string
41
+ */
42
+ protected function _toHtml()
43
+ {
44
+ return '';
45
+ }
46
+
47
+ /**
48
+ * Retrieve payment method model
49
+ *
50
+ * @return Mage_Payment_Model_Method_Abstract
51
+ */
52
+ public function getMethod()
53
+ {
54
+ $method = $this->getData('method');
55
+ if (!$method) {
56
+ $method = Mage::getModel('paypal/payflowpro');
57
+ $this->setData('method', $method);
58
+ }
59
+
60
+ return $method;
61
+ }
62
+
63
+ /**
64
+ * Add Payflow Pro payment method form to payment XML object
65
+ *
66
+ * @param Mage_XmlConnect_Model_Simplexml_Element $paymentItemXmlObj
67
+ * @return Mage_XmlConnect_Model_Simplexml_Element
68
+ */
69
+ public function addPaymentFormToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $paymentItemXmlObj)
70
+ {
71
+ $method = $this->getMethod();
72
+ if (!$method) {
73
+ return $paymentItemXmlObj;
74
+ }
75
+ $formXmlObj = $paymentItemXmlObj->addChild('form');
76
+ $formXmlObj->addAttribute('name', 'payment_form_' . $method->getCode());
77
+ $formXmlObj->addAttribute('method', 'post');
78
+
79
+ $_ccType = $this->getInfoData('cc_type');
80
+ $ccTypes = '';
81
+
82
+ foreach ($this->getCcAvailableTypes() as $_typeCode => $_typeName) {
83
+ if (!$_typeCode) {
84
+ continue;
85
+ }
86
+ $ccTypes .= '
87
+ <item' . ($_typeCode == $_ccType ? ' selected="1"' : '') . '>
88
+ <label>' . $_typeName . '</label>
89
+ <value>' . $_typeCode . '</value>
90
+ </item>';
91
+ }
92
+
93
+ $ccMonthes = '';
94
+
95
+ $_ccExpMonth = $this->getInfoData('cc_exp_month');
96
+ foreach ($this->getCcMonths() as $k => $v) {
97
+ if (!$k) {
98
+ continue;
99
+ }
100
+ $ccMonthes .= '
101
+ <item' . ($k == $_ccExpMonth ? ' selected="1"' : '') . '>
102
+ <label>' . $v . '</label>
103
+ <value>' . ($k ? $k : '') . '</value>
104
+ </item>';
105
+ }
106
+
107
+ $ccYears = '';
108
+
109
+ $_ccExpYear = $this->getInfoData('cc_exp_year');
110
+ foreach ($this->getCcYears() as $k => $v) {
111
+ if (!$k) {
112
+ continue;
113
+ }
114
+ $ccYears .= '
115
+ <item' . ($k == $_ccExpYear ? ' selected="1"' : '') . '>
116
+ <label>' . $v . '</label>
117
+ <value>' . ($k ? $k : '') . '</value>
118
+ </item>';
119
+ }
120
+
121
+ $verification = '';
122
+ if ($this->hasVerification()) {
123
+ $verification = <<<EOT
124
+ <field name="payment[cc_cid]" type="text" label="{$this->__('Card Verification Number')}" required="true">
125
+ <validators>
126
+ <validator relation="payment[cc_type]" type="credit_card_svn" message="{$this->__('Card verification number is wrong')}'"/>
127
+ </validators>
128
+ </field>
129
+ EOT;
130
+ }
131
+
132
+ $xml = <<<EOT
133
+ <fieldset>
134
+ <field name="payment[cc_type]" type="select" label="{$this->__('Credit Card Type')}" required="true">
135
+ <values>
136
+ $ccTypes
137
+ </values>
138
+ </field>
139
+ <field name="payment[cc_number]" type="text" label="{$this->__('Credit Card Number')}" required="true">
140
+ <validators>
141
+ <validator relation="payment[cc_type]" type="credit_card" message="{$this->__('Credit card number does not match credit card type.')}"/>
142
+ </validators>
143
+ </field>
144
+ <field name="payment[cc_exp_month]" type="select" label="{$this->__('Expiration Date - Month')}" required="true">
145
+ <values>
146
+ $ccMonthes
147
+ </values>
148
+ </field>
149
+ <field name="payment[cc_exp_year]" type="select" label="{$this->helper('xmlconnect')->__('Expiration Date - Year')}" required="true">
150
+ <values>
151
+ $ccYears
152
+ </values>
153
+ </field>
154
+ $verification
155
+ </fieldset>
156
+ EOT;
157
+ $fieldsetXmlObj = Mage::getModel('xmlconnect/simplexml_element', $xml);
158
+ $formXmlObj->appendChild($fieldsetXmlObj);
159
+ }
160
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Abstract.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Abstract Pbridge Payment method xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ abstract class Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Abstract
35
+ extends Enterprise_Pbridge_Block_Payment_Form_Abstract
36
+ {
37
+ /**
38
+ * Retrieve payment method model
39
+ *
40
+ * @return Mage_Payment_Model_Method_Abstract
41
+ */
42
+ public function getMethod()
43
+ {
44
+ $method = $this->getData('method');
45
+ if (!$method) {
46
+ $method = Mage::getModel('enterprise_pbridge/payment_method_' . $this->_model);
47
+ $this->setData('method', $method);
48
+ }
49
+ return $method;
50
+ }
51
+
52
+ /**
53
+ * Return redirect url for Payment Bridge application
54
+ *
55
+ * @return string
56
+ */
57
+ public function getRedirectUrl()
58
+ {
59
+ return $this->getUrl('xmlconnect/pbridge/result', array('_current' => true, '_secure' => true));
60
+ }
61
+
62
+ /**
63
+ * Add payment method through Pbridge iframe XML object
64
+ *
65
+ * @param Mage_XmlConnect_Model_Simplexml_Element $paymentItemXmlObj
66
+ * @return Mage_XmlConnect_Model_Simplexml_Element
67
+ */
68
+ public function addPaymentFormToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $paymentItemXmlObj)
69
+ {
70
+ $paymentItemXmlObj->addAttribute('is_pbridge', 1);
71
+ $paymentItemXmlObj->addChild('pb_iframe', $paymentItemXmlObj->xmlentities($this->createIframe()));
72
+ return $paymentItemXmlObj;
73
+ }
74
+
75
+ /**
76
+ * Create html page with iframe for devices
77
+ *
78
+ * @return string html
79
+ */
80
+ protected function createIframe()
81
+ {
82
+ $code = $this->getMethodCode();
83
+ $body = <<<EOT
84
+ <div id="payment_form_{$code}" style="margin:0 auto; max-width:500px;">
85
+ {$this->getIframeBlock()->toHtml()}
86
+ </div>
87
+ EOT;
88
+ return $this->helper('xmlconnect')->htmlize($body);
89
+ }
90
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Authorizenet.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Authorize.Net through Pbridge Payment method xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Authorizenet
35
+ extends Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Abstract
36
+ {
37
+ /**
38
+ * Payment model path
39
+ *
40
+ * @var string
41
+ */
42
+ protected $_model = 'authorizenet';
43
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Paypal.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * PayPal Direct through Pbridge Payment method xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Paypal
35
+ extends Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Abstract
36
+ {
37
+ /**
38
+ * Payment model path
39
+ *
40
+ * @var string
41
+ */
42
+ protected $_model = 'paypal';
43
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Paypaluk.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * PayPalUK Direct through Pbridge Payment method xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Paypaluk
35
+ extends Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Abstract
36
+ {
37
+ /**
38
+ * Payment model path
39
+ *
40
+ * @var string
41
+ */
42
+ protected $_model = 'paypaluk';
43
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Verisign.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Payflow Pro through Pbridge Payment method xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Verisign
35
+ extends Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Abstract
36
+ {
37
+ /**
38
+ * Payment model path
39
+ *
40
+ * @var string
41
+ */
42
+ protected $_model = 'payflow_pro';
43
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Purchaseorder.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Check / Money order Payment method xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Payment_Method_Purchaseorder
35
+ extends Mage_Payment_Block_Form_Purchaseorder
36
+ {
37
+ /**
38
+ * Prevent any rendering
39
+ *
40
+ * @return string
41
+ */
42
+ protected function _toHtml()
43
+ {
44
+ return '';
45
+ }
46
+
47
+ /**
48
+ * Retrieve payment method model
49
+ *
50
+ * @return Mage_Payment_Model_Method_Abstract
51
+ */
52
+ public function getMethod()
53
+ {
54
+ $method = $this->getData('method');
55
+ if (!$method) {
56
+ $method = Mage::getModel('payment/method_purchaseorder');
57
+ $this->setData('method', $method);
58
+ }
59
+
60
+ return $method;
61
+ }
62
+
63
+ /**
64
+ * Add payment method form to payment XML object
65
+ *
66
+ * @param Mage_XmlConnect_Model_Simplexml_Element $paymentItemXmlObj
67
+ * @return Mage_XmlConnect_Model_Simplexml_Element
68
+ */
69
+ public function addPaymentFormToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $paymentItemXmlObj)
70
+ {
71
+ $method = $this->getMethod();
72
+ if (!$method) {
73
+ return $paymentItemXmlObj;
74
+ }
75
+ $formXmlObj = $paymentItemXmlObj->addChild('form');
76
+ $formXmlObj->addAttribute('name', 'payment_form_' . $method->getCode());
77
+ $formXmlObj->addAttribute('method', 'post');
78
+
79
+ $poNumber = $this->getInfoData('po_number');
80
+ $poNumberText = $this->__('Purchase Order Number');
81
+ $xml = <<<EOT
82
+ <fieldset>
83
+ <field name="payment[po_number]" type="text" label="{$poNumberText}" value="$poNumber" required="true" />
84
+ </fieldset>
85
+ EOT;
86
+ $fieldsetXmlObj = Mage::getModel('xmlconnect/simplexml_element', $xml);
87
+ $formXmlObj->appendChild($fieldsetXmlObj);
88
+
89
+ return $paymentItemXmlObj;
90
+ }
91
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Pbridge/Result.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Pbridge result payment block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Pbridge_Result extends Mage_Core_Block_Template
35
+ {
36
+ /**
37
+ * Return url for redirect with params of Payment Bridge incoming data
38
+ *
39
+ * @return string
40
+ */
41
+ public function getPbridgeParamsAsUrl()
42
+ {
43
+ $pbParams = Mage::helper('enterprise_pbridge')->getPbridgeParams();
44
+ $params = array_merge(
45
+ array('_nosid' => true, 'method' => 'pbridge_' . $pbParams['original_payment_method']),
46
+ $pbParams
47
+ );
48
+ return Mage::getUrl('xmlconnect/pbridge/output', $params);
49
+ }
50
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Shipping/Method/Available.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * One page checkout shipping methods xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Checkout_Shipping_Method_Available
35
+ extends Mage_Checkout_Block_Onepage_Shipping_Method_Available
36
+ {
37
+ /**
38
+ * Render shipping methods xml
39
+ *
40
+ * @return string
41
+ */
42
+ protected function _toHtml()
43
+ {
44
+ /** @var $methodsXmlObj Mage_XmlConnect_Model_Simplexml_Element */
45
+ $methodsXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<shipping_methods></shipping_methods>');
46
+ $_shippingRateGroups = $this->getShippingRates();
47
+ if ($_shippingRateGroups) {
48
+ $store = $this->getQuote()->getStore();
49
+ $_sole = count($_shippingRateGroups) == 1;
50
+ foreach ($_shippingRateGroups as $code => $_rates) {
51
+ $methodXmlObj = $methodsXmlObj->addChild('method');
52
+ $methodXmlObj->addAttribute('label', $methodsXmlObj->escapeXml($this->getCarrierName($code)));
53
+ $ratesXmlObj = $methodXmlObj->addChild('rates');
54
+
55
+ $_sole = $_sole && count($_rates) == 1;
56
+ foreach ($_rates as $_rate) {
57
+ $rateXmlObj = $ratesXmlObj->addChild('rate');
58
+ $rateXmlObj->addAttribute('label', $methodsXmlObj->escapeXml($_rate->getMethodTitle()));
59
+ $rateXmlObj->addAttribute('code', $_rate->getCode());
60
+ if ($_rate->getErrorMessage()) {
61
+ $rateXmlObj->addChild('error_message', $methodsXmlObj->escapeXml($_rate->getErrorMessage()));
62
+ } else {
63
+ $price = Mage::helper('tax')->getShippingPrice(
64
+ $_rate->getPrice(),
65
+ Mage::helper('tax')->displayShippingPriceIncludingTax(),
66
+ $this->getAddress()
67
+ );
68
+ $formattedPrice = $store->convertPrice($price, true, false);
69
+ $rateXmlObj->addAttribute('price', Mage::helper('xmlconnect')->formatPriceForXml(
70
+ $store->convertPrice($price, false, false)
71
+ ));
72
+ $rateXmlObj->addAttribute('formated_price', $formattedPrice);
73
+ }
74
+ }
75
+ }
76
+ } else {
77
+ Mage::throwException($this->__('Shipping to this address is not possible.'));
78
+ }
79
+ return $methodsXmlObj->asNiceXml();
80
+ }
81
+ }
app/code/core/Mage/XmlConnect/Block/Checkout/Shipping/Method/Avaliable.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Wrongly named class is now replaced
29
+ * This class is an alias for properly named class
30
+ *
31
+ * @deprecated Misspelling has been fixed
32
+ * @category Mage
33
+ * @package Mage_XmlConnect
34
+ * @author Magento Core Team <core@magentocommerce.com>
35
+ */
36
+ class Mage_XmlConnect_Block_Checkout_Shipping_Method_Avaliable
37
+ extends Mage_XmlConnect_Block_Checkout_Shipping_Method_Available
38
+ {
39
+ }
app/code/core/Mage/XmlConnect/Block/Cms/Page.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Cms Page xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Cms_Page extends Mage_Cms_Block_Page
35
+ {
36
+ /**
37
+ * Page Id getter
38
+ *
39
+ * @return int
40
+ */
41
+ public function getPageId()
42
+ {
43
+ return $this->getRequest()->getParam('id');
44
+ }
45
+ }
app/code/core/Mage/XmlConnect/Block/Configuration.php ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Application configuration renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Configuration extends Mage_Core_Block_Template
35
+ {
36
+ /**
37
+ * Current application model
38
+ *
39
+ * @var Mage_XmlConnect_Model_Application
40
+ */
41
+ protected $_app;
42
+
43
+ /**
44
+ * Init current application
45
+ *
46
+ * @return Mage_XmlConnect_Block_Configuration
47
+ */
48
+ protected function _beforeToHtml()
49
+ {
50
+ $app = Mage::helper('xmlconnect')->getApplication();
51
+ if ($app) {
52
+ $this->_app = $app;
53
+ } else {
54
+ $this->_app = Mage::getModel('xmlconnect/application');
55
+ $this->_app->loadDefaultConfiguration();
56
+ }
57
+ return $this;
58
+ }
59
+
60
+ /**
61
+ * Recursively build XML configuration tree
62
+ *
63
+ * @param Mage_XmlConnect_Model_Simplexml_Element $section
64
+ * @param array $subtree
65
+ * @return Mage_XmlConnect_Model_Simplexml_Element
66
+ */
67
+ protected function _buildRecursive($section, $subtree)
68
+ {
69
+ Mage::helper('xmlconnect')->getDeviceHelper()->checkRequiredConfigFields($subtree);
70
+
71
+ foreach ($subtree as $key => $value) {
72
+ if (is_array($value)) {
73
+ if ($key == 'fonts') {
74
+ $subsection = $section->addChild('fonts');
75
+ foreach ($value as $label=>$v) {
76
+ if (empty($v['name']) || empty($v['size']) || empty($v['color'])) {
77
+ continue;
78
+ }
79
+ $font = $subsection->addChild('font');
80
+ $font->addAttribute('label', $label);
81
+ $font->addAttribute('name', $v['name']);
82
+ $font->addAttribute('size', $v['size']);
83
+ $font->addAttribute('color', $v['color']);
84
+ }
85
+ } elseif ($key == 'pages') {
86
+ $subsection = $section->addChild('content');
87
+ foreach ($value as $page) {
88
+ $this->_buildRecursive($subsection->addChild('page'), $page);
89
+ }
90
+ } else {
91
+ $subsection = $section->addChild($key);
92
+ $this->_buildRecursive($subsection, $value);
93
+ }
94
+ } elseif ($value instanceof Mage_XmlConnect_Model_Tabs) {
95
+ foreach ($value->getRenderTabs() as $tab) {
96
+ $subsection = $section->addChild('tab');
97
+ $this->_buildRecursive($subsection, $tab);
98
+ }
99
+ } else {
100
+ $value = (string)$value;
101
+ if ($value != '') {
102
+ $section->addChild($key, Mage::helper('core')->htmlEscape($value));
103
+ }
104
+ }
105
+ }
106
+ }
107
+
108
+ /**
109
+ * Render block
110
+ *
111
+ * @return string
112
+ */
113
+ protected function _toHtml()
114
+ {
115
+ $xml = Mage::getModel('xmlconnect/simplexml_element', '<configuration></configuration>');
116
+ $this->_buildRecursive(
117
+ $xml,
118
+ Mage::helper('xmlconnect')
119
+ ->excludeXmlConfigKeys(
120
+ $this->_app->getRenderConf()
121
+ )
122
+ );
123
+ return $xml->asNiceXml();
124
+ }
125
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Address/Form.php ADDED
@@ -0,0 +1,466 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer address form xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Address_Form extends Mage_Customer_Block_Address_Edit
35
+ {
36
+ /**
37
+ * Customer name widget block
38
+ *
39
+ * @var Mage_Customer_Block_Widget_Name
40
+ */
41
+ protected $_nameWidgetBlock;
42
+
43
+ /**
44
+ * Enterprise customer field renderer list as type => renderer block
45
+ *
46
+ * Original block relations:
47
+ * - 'text' => 'enterprise_customer/form_renderer_text',
48
+ * - 'textarea' => 'enterprise_customer/form_renderer_textarea',
49
+ * - 'multiline' => 'enterprise_customer/form_renderer_multiline',
50
+ * - 'date' => 'enterprise_customer/form_renderer_date',
51
+ * - 'select' => 'enterprise_customer/form_renderer_select',
52
+ * - 'multiselect' => 'enterprise_customer/form_renderer_multiselect',
53
+ * - 'boolean' => 'enterprise_customer/form_renderer_boolean',
54
+ * - 'file' => 'enterprise_customer/form_renderer_file'
55
+ * - 'image' => 'enterprise_customer/form_renderer_image'
56
+ *
57
+ * @see customer.xml layout customer_form_template_handle node
58
+ * @var array
59
+ */
60
+ protected $_customerFiledRenderer = array(
61
+ 'text' => 'xmlconnect/customer_form_renderer_text',
62
+ 'textarea' => 'xmlconnect/customer_form_renderer_textarea',
63
+ 'multiline' => 'xmlconnect/customer_form_renderer_multiline',
64
+ 'date' => 'xmlconnect/customer_form_renderer_date',
65
+ 'select' => 'xmlconnect/customer_form_renderer_select',
66
+ 'multiselect' => 'xmlconnect/customer_form_renderer_multiselect',
67
+ 'boolean' => 'xmlconnect/customer_form_renderer_boolean',
68
+ 'file' => 'xmlconnect/customer_form_renderer_file',
69
+ 'image' => 'xmlconnect/customer_form_renderer_image'
70
+ );
71
+
72
+ /**
73
+ * Render customer address form xml
74
+ *
75
+ * @return string
76
+ */
77
+ protected function _toHtml()
78
+ {
79
+ $address = $this->getAddress();
80
+
81
+ /**
82
+ * Init address object and save its data to variables
83
+ */
84
+ $addressId = (int)$this->getRequest()->getParam('id');
85
+ $billingChecked = $shippingChecked = false;
86
+
87
+ if ($addressId && $address && $address->getId()) {
88
+ $defaultBillingAddressId = Mage::getSingleton('customer/session')
89
+ ->getCustomer()
90
+ ->getDefaultBilling();
91
+ $defaultShippingAddressId = Mage::getSingleton('customer/session')
92
+ ->getCustomer()
93
+ ->getDefaultShipping();
94
+
95
+ $billingChecked = (int)$addressId == $defaultBillingAddressId;
96
+ $shippingChecked = (int)$addressId == $defaultShippingAddressId;
97
+
98
+ $company = $address->getCompany();
99
+ $street1 = $address->getStreet(1);
100
+ $street2 = $address->getStreet(2);
101
+ $city = $address->getCity();
102
+ $regionId = $address->getRegionId();
103
+ $region = $address->getRegion();
104
+ $postcode = $address->getPostcode();
105
+ $countryId = $address->getCountryId();
106
+ $telephone = $address->getTelephone();
107
+ $fax = $address->getFax();
108
+ }
109
+
110
+ $action = Mage::helper('xmlconnect')
111
+ ->getActionUrl('xmlconnect/customer/saveaddress');
112
+
113
+ /** @var Mage_XmlConnect_Model_Simplexml_Form $fromXmlObj */
114
+ $fromXmlObj = Mage::getModel('xmlconnect/simplexml_form', array(
115
+ 'xml_id' => 'address_form',
116
+ 'action' => $action,
117
+ 'use_container' => true
118
+ ));
119
+
120
+ $contactInfoFieldset = $fromXmlObj->addFieldset(
121
+ 'contact_info',
122
+ array('legend' => $this->__('Contact Information'))
123
+ )
124
+ ->setCustomAttributes(
125
+ array('legend')
126
+ );
127
+
128
+ $this->_addCustomerContactInfo($contactInfoFieldset);
129
+
130
+ $contactInfoFieldset->addField('company', 'text', array(
131
+ 'label' => $this->__('Company'),
132
+ 'value' => isset($company) ? $company : ''
133
+ ));
134
+ $contactInfoFieldset->addField('telephone', 'text', array(
135
+ 'label' => $this->__('Telephone'),
136
+ 'required' => 'true',
137
+ 'value' => isset($telephone) ? $telephone : ''
138
+ ));
139
+ $contactInfoFieldset->addField('fax', 'text', array(
140
+ 'label' => $this->__('Fax'),
141
+ 'value' => isset($fax) ? $fax : ''
142
+ ));
143
+
144
+ $addressFieldset = $fromXmlObj->addFieldset(
145
+ 'address_info',
146
+ array('legend' => $this->__('Address'))
147
+ )
148
+ ->setCustomAttributes(
149
+ array('legend')
150
+ );
151
+
152
+ $addressFieldset->addField('street', 'text', array(
153
+ 'name' => 'street[]',
154
+ 'label' => $this->__('Street Address'),
155
+ 'required' => 'true',
156
+ 'value' => isset($street1) ? $street1 : ''
157
+ ));
158
+ $addressFieldset->addField('street_2', 'text', array(
159
+ 'name' => 'street[]',
160
+ 'label' => $this->__('Street Address 2'),
161
+ 'value' => isset($street2) ? $street2 : ''
162
+ ));
163
+ $addressFieldset->addField('city', 'text', array(
164
+ 'label' => $this->__('City'),
165
+ 'required' => 'true',
166
+ 'value' => isset($city) ? $city : ''
167
+ ));
168
+
169
+ $countryId = isset($countryId) ? $countryId : null;
170
+ $regionId = isset($regionId) ? $regionId : null;
171
+ $region = isset($region) ? $region : null;
172
+
173
+ $addressFieldset->addField('country_id', 'countryListSelect', array(
174
+ 'label' => $this->__('Country'),
175
+ 'required' => 'true',
176
+ 'value' => array(
177
+ 'country_id' => $countryId,
178
+ 'region_id' => $regionId,
179
+ 'region' => $region
180
+ ),
181
+ 'old_format' => true
182
+ ));
183
+ $addressFieldset->addField('region', 'text', array(
184
+ 'label' => $this->__('State/Province'),
185
+ 'value' => isset($region) ? $region : ''
186
+ ));
187
+ $addressFieldset->addField('region_id', 'select', array(
188
+ 'label' => $this->__('State/Province'),
189
+ 'required' => 'true',
190
+ ));
191
+ $addressFieldset->addField('postcode', 'text', array(
192
+ 'label' => $this->__('Zip/Postal Code'),
193
+ 'required' => 'true',
194
+ 'value' => isset($postcode) ? $postcode : ''
195
+ ));
196
+ $addressFieldset->addField('default_billing', 'checkbox', array(
197
+ 'label' => $this->__('Use as my default billing address'),
198
+ 'value' => $billingChecked ? $billingChecked : 0
199
+ ));
200
+
201
+ $addressFieldset->addField('default_shipping', 'checkbox', array(
202
+ 'label' => $this->__('Use as my default shipping address'),
203
+ 'value' => $shippingChecked ? $shippingChecked : 0
204
+ ));
205
+
206
+ $this->_addCustomAddressAttributes($addressFieldset);
207
+
208
+ return $fromXmlObj->getXml();
209
+ }
210
+
211
+ /**
212
+ * Add customer contact attributes
213
+ *
214
+ * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $contactInfoFieldset
215
+ * @return Mage_XmlConnect_Block_Customer_Address_Form
216
+ */
217
+ protected function _addCustomerContactInfo(
218
+ Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $contactInfoFieldset
219
+ )
220
+ {
221
+ if (is_object(Mage::getConfig()->getNode('modules/Enterprise_Customer'))) {
222
+ $this->setNameWidgetBlock($this->getLayout()
223
+ ->createBlock('customer/widget_name')
224
+ ->setObject($this->getAddress()->getFirstname() ? $this->getAddress() : $this->getCustomer())
225
+ );
226
+
227
+ if ($this->getNameWidgetBlock()->showPrefix()) {
228
+ $this->_addPrefix($contactInfoFieldset);
229
+ }
230
+
231
+ $this->_addFirstName($contactInfoFieldset);
232
+
233
+ if ($this->getNameWidgetBlock()->showMiddlename()) {
234
+ $this->_addMiddleName($contactInfoFieldset);
235
+ }
236
+
237
+ $this->_addLastName($contactInfoFieldset);
238
+
239
+ if ($this->getNameWidgetBlock()->showSuffix()) {
240
+ $this->_addSuffix($contactInfoFieldset);
241
+ }
242
+ } else {
243
+ $this->_addFirstName($contactInfoFieldset);
244
+ $this->_addLastName($contactInfoFieldset);
245
+ }
246
+ return $this;
247
+ }
248
+
249
+ /**
250
+ * Add customer prefix field
251
+ *
252
+ * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $contactInfoFieldset
253
+ * @return Mage_XmlConnect_Block_Customer_Address_Form
254
+ */
255
+ protected function _addPrefix(
256
+ Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $contactInfoFieldset
257
+ )
258
+ {
259
+ $attributes = array();
260
+ $attributes += $contactInfoFieldset->checkAttribute(
261
+ 'value',
262
+ $this->getNameWidgetBlock()->getObject()->getPrefix()
263
+ );
264
+
265
+ $attributes += $contactInfoFieldset->checkAttribute(
266
+ 'required',
267
+ (int)$this->getNameWidgetBlock()->isPrefixRequired()
268
+ );
269
+
270
+ if ($this->getNameWidgetBlock()->getPrefixOptions() === false) {
271
+ $contactInfoFieldset->addField($this->getNameWidgetBlock()->getFieldId('prefix'), 'text', array(
272
+ 'label' => $this->getNameWidgetBlock()->__('Prefix'),
273
+ 'name' => $this->getNameWidgetBlock()->getFieldName('prefix')
274
+ ) + $attributes
275
+ );
276
+ } else {
277
+ $contactInfoFieldset->addField($this->getNameWidgetBlock()->getFieldId('prefix'), 'select', array(
278
+ 'label' => $this->getNameWidgetBlock()->__('Prefix'),
279
+ 'name' => $this->getNameWidgetBlock()->getFieldName('prefix'),
280
+ 'options' => $this->getNameWidgetBlock()->getPrefixOptions()
281
+ ) + $attributes
282
+ );
283
+ }
284
+ return $this;
285
+ }
286
+
287
+ /**
288
+ * Add customer suffix field
289
+ *
290
+ * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $contactInfoFieldset
291
+ * @return Mage_XmlConnect_Block_Customer_Address_Form
292
+ */
293
+ protected function _addSuffix(
294
+ Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $contactInfoFieldset
295
+ )
296
+ {
297
+ $attributes = array();
298
+ $attributes += $contactInfoFieldset->checkAttribute(
299
+ 'value',
300
+ $this->getNameWidgetBlock()->getObject()->getSuffix()
301
+ );
302
+
303
+ $attributes += $contactInfoFieldset->checkAttribute(
304
+ 'required',
305
+ (int)$this->getNameWidgetBlock()->isSuffixRequired()
306
+ );
307
+
308
+ if ($this->getNameWidgetBlock()->getSuffixOptions() === false) {
309
+ $contactInfoFieldset->addField($this->getNameWidgetBlock()->getFieldId('suffix'), 'text', array(
310
+ 'label' => $this->getNameWidgetBlock()->__('Suffix'),
311
+ 'name' => $this->getNameWidgetBlock()->getFieldName('suffix')
312
+ ) + $attributes
313
+ );
314
+ } else {
315
+ $contactInfoFieldset->addField($this->getNameWidgetBlock()->getFieldId('suffix'), 'select', array(
316
+ 'label' => $this->getNameWidgetBlock()->__('Suffix'),
317
+ 'name' => $this->getNameWidgetBlock()->getFieldName('suffix'),
318
+ 'options' => $this->getNameWidgetBlock()->getSuffixOptions()
319
+ ) + $attributes
320
+ );
321
+ }
322
+ return $this;
323
+ }
324
+
325
+ /**
326
+ * Add customer middle name field
327
+ *
328
+ * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $contactInfoFieldset
329
+ * @return Mage_XmlConnect_Block_Customer_Address_Form
330
+ */
331
+ protected function _addMiddleName(
332
+ Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $contactInfoFieldset
333
+ )
334
+ {
335
+ $attributes = array();
336
+ $attributes += $contactInfoFieldset->checkAttribute(
337
+ 'value',
338
+ $this->getNameWidgetBlock()->getObject()->getMiddlename()
339
+ );
340
+
341
+ $contactInfoFieldset->addField($this->getNameWidgetBlock()->getFieldId('middlename'), 'text', array(
342
+ 'label' => $this->getNameWidgetBlock()->__('M.I.'),
343
+ 'name' => $this->getNameWidgetBlock()->getFieldName('middlename')
344
+ ) + $attributes
345
+ );
346
+ return $this;
347
+ }
348
+
349
+ /**
350
+ * Add customer first name field
351
+ *
352
+ * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $contactInfoFieldset
353
+ * @return Mage_XmlConnect_Block_Customer_Address_Form
354
+ */
355
+ protected function _addFirstName(
356
+ Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $contactInfoFieldset
357
+ )
358
+ {
359
+ $firstName = $this->getAddress()->getFirstname();
360
+ $contactInfoFieldset->addField('firstname', 'text',array(
361
+ 'label' => $this->__('First Name'),
362
+ 'required' => 'true',
363
+ 'value' => isset($firstName) ? $firstName : ''
364
+ ));
365
+ return $this;
366
+ }
367
+
368
+ /**
369
+ * Add customer last name field
370
+ *
371
+ * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $contactInfoFieldset
372
+ * @return Mage_XmlConnect_Block_Customer_Address_Form
373
+ */
374
+ protected function _addLastName(
375
+ Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $contactInfoFieldset
376
+ )
377
+ {
378
+ $lastName = $this->getAddress()->getLastname();
379
+ $contactInfoFieldset->addField('lastname', 'text', array(
380
+ 'label' => $this->__('Last Name'),
381
+ 'required' => 'true',
382
+ 'value' => isset($lastName) ? $lastName : ''
383
+ ));
384
+ return $this;
385
+ }
386
+
387
+ /**
388
+ * Add custom customer attributes
389
+ *
390
+ * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $addressFieldset
391
+ * @return Mage_XmlConnect_Block_Customer_Address_Form
392
+ */
393
+ protected function _addCustomAddressAttributes(
394
+ Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $addressFieldset
395
+ )
396
+ {
397
+ if (is_object(Mage::getConfig()->getNode('modules/Enterprise_Customer'))) {
398
+ /** @var $addressAttrBlock Enterprise_Customer_Block_Form */
399
+ $addressAttrBlock = $this->getLayout()
400
+ ->addBlock('enterprise_customer/form', 'customer_address_attr');
401
+ $addressAttrBlock->setFormCode('customer_address_edit');
402
+ $addressAttrBlock->setEntity($this->getAddress());
403
+
404
+ foreach ($this->_customerFiledRenderer as $type => $rendererBlock) {
405
+ $addressAttrBlock->addRenderer($type, $rendererBlock, 'customer/form/renderer/text.phtml');
406
+ }
407
+
408
+ if ($addressAttrBlock->hasUserDefinedAttributes()) {
409
+ foreach ($addressAttrBlock->getUserDefinedAttributes() as $code => $attribute) {
410
+ $type = $attribute->getFrontendInput();
411
+ $block = $addressAttrBlock->getRenderer($type);
412
+ if ($block) {
413
+ $block->setAttributeObject($attribute)
414
+ ->setEntity($addressAttrBlock->getEntity())
415
+ ->addFieldToXmlObj($addressFieldset);
416
+ }
417
+ }
418
+ }
419
+ }
420
+ return $this;
421
+ }
422
+
423
+ /**
424
+ * Get customer name widget block
425
+ *
426
+ * @return Mage_Customer_Block_Widget_Name
427
+ */
428
+ public function getNameWidgetBlock()
429
+ {
430
+ return $this->_nameWidgetBlock;
431
+ }
432
+
433
+ /**
434
+ * Set customer name widget block
435
+ *
436
+ * @param Mage_Customer_Block_Widget_Name $nameWidgetBlock
437
+ * @return Mage_XmlConnect_Block_Customer_Address_Form
438
+ */
439
+ public function setNameWidgetBlock($nameWidgetBlock)
440
+ {
441
+ $this->_nameWidgetBlock = $nameWidgetBlock;
442
+ return $this;
443
+ }
444
+
445
+ /**
446
+ * Get enterprise customer fields renderer
447
+ *
448
+ * @return array
449
+ */
450
+ public function getCustomerFiledRenderer()
451
+ {
452
+ return $this->_customerFiledRenderer;
453
+ }
454
+
455
+ /**
456
+ * Set enterprise customer fields renderer
457
+ *
458
+ * @param array $customerFiledRenderer
459
+ * @return Mage_XmlConnect_Block_Customer_Address_Form
460
+ */
461
+ public function setCustomerFiledRenderer($customerFiledRenderer)
462
+ {
463
+ $this->_customerFiledRenderer = $customerFiledRenderer;
464
+ return $this;
465
+ }
466
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Address/List.php ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer address book xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Address_List extends Mage_Core_Block_Template
35
+ {
36
+ /**
37
+ * Render customer address list xml
38
+ *
39
+ * @return string
40
+ */
41
+ protected function _toHtml()
42
+ {
43
+ $addressXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<address></address>');
44
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
45
+
46
+ $_billingAddssesId = $customer->getDefaultBilling();
47
+ $_shippingAddssesId = $customer->getDefaultShipping();
48
+ $billingAddress = $customer->getAddressById($_billingAddssesId);
49
+ $shippingAddress = $customer->getAddressById($_shippingAddssesId);
50
+
51
+ if ($billingAddress && $billingAddress->getId()) {
52
+ $item = $addressXmlObj->addChild('item');
53
+ $item->addAttribute('label', $this->__('Default Billing Address'));
54
+ $item->addAttribute('default_billing', 1);
55
+ $this->prepareAddressData($billingAddress, $item);
56
+ }
57
+ if ($shippingAddress && $shippingAddress->getId()) {
58
+ $item = $addressXmlObj->addChild('item');
59
+ $item->addAttribute('label', $this->__('Default Shipping Address'));
60
+ $item->addAttribute('default_shipping', 1);
61
+ $this->prepareAddressData($shippingAddress, $item);
62
+ }
63
+ $_additionalAddresses = $customer->getAdditionalAddresses();
64
+ if ($_additionalAddresses) {
65
+ foreach ($_additionalAddresses as $_address) {
66
+ $item = $addressXmlObj->addChild('item');
67
+ $item->addAttribute('label', $this->__('Additional Address'));
68
+ $item->addAttribute('additional', 1);
69
+ $this->prepareAddressData($_address, $item);
70
+ }
71
+ }
72
+
73
+ return $addressXmlObj->asNiceXml();
74
+ }
75
+
76
+ /**
77
+ * Collect address data to xml node
78
+ * Remove objects from data array and escape data values
79
+ *
80
+ * @param Mage_Customer_Model_Address $address
81
+ * @param Mage_XmlConnect_Model_Simplexml_Element $item
82
+ * @return array
83
+ */
84
+ public function prepareAddressData(
85
+ Mage_Customer_Model_Address $address, Mage_XmlConnect_Model_Simplexml_Element $item
86
+ ) {
87
+ if (!$address) {
88
+ return array();
89
+ }
90
+
91
+ $attributes = Mage::helper('customer/address')->getAttributes();
92
+
93
+ $data = array(
94
+ 'entity_id' => $address->getId()
95
+ );
96
+
97
+ foreach ($attributes as $attribute) {
98
+ /* @var $attribute Mage_Customer_Model_Attribute */
99
+ if (!$attribute->getIsVisible()) {
100
+ continue;
101
+ }
102
+ if ($attribute->getAttributeCode() == 'country_id') {
103
+ $data['country'] = $address->getCountryModel()->getName();
104
+ $data['country_id'] = $address->getCountryId();
105
+ } else if ($attribute->getAttributeCode() == 'region') {
106
+ $data['region'] = $address->getRegion();
107
+ } else {
108
+ $dataModel = Mage_Customer_Model_Attribute_Data::factory($attribute, $address);
109
+ $value = $dataModel->outputValue(Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_ONELINE);
110
+ if ($attribute->getFrontendInput() == 'multiline') {
111
+ $values = $dataModel->outputValue(Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_ARRAY);
112
+ // explode lines
113
+ foreach ($values as $k => $v) {
114
+ $key = sprintf('%s%d', $attribute->getAttributeCode(), $k + 1);
115
+ $data[$key] = $v;
116
+ }
117
+ }
118
+ $data[$attribute->getAttributeCode()] = $value;
119
+ }
120
+ }
121
+
122
+ foreach ($data as $key => $value) {
123
+ if (!empty($value)) {
124
+ $item->addChild($key, $item->escapeXml($value));
125
+ }
126
+ }
127
+ }
128
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Form.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer form xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Form extends Mage_Core_Block_Template
35
+ {
36
+ /**
37
+ * Render customer form xml
38
+ *
39
+ * @return string
40
+ */
41
+ protected function _toHtml()
42
+ {
43
+ $editFlag = (int)$this->getRequest()->getParam('edit');
44
+ $customer = $this->getCustomer();
45
+ /** @var $xmlModel Mage_XmlConnect_Model_Simplexml_Element */
46
+ $xmlModel = Mage::getModel('xmlconnect/simplexml_element', '<node></node>');
47
+ //Enterprise_Customer
48
+ if ($editFlag == 1 && $customer && $customer->getId()) {
49
+ $firstname = $xmlModel->escapeXml($customer->getFirstname());
50
+ $lastname = $xmlModel->escapeXml($customer->getLastname());
51
+ $email = $xmlModel->escapeXml($customer->getEmail());
52
+ } else {
53
+ $firstname = $lastname = $email = '';
54
+ }
55
+
56
+ if ($editFlag) {
57
+ $passwordManageXml = '
58
+ <field name="change_password" type="checkbox" label="' . $xmlModel->escapeXml($this->__('Change Password')) . '"/>
59
+ </fieldset>
60
+ <fieldset>
61
+ <field name="current_password" type="password" label="' . $xmlModel->escapeXml($this->__('Current Password')) . '"/>
62
+ <field name="password" type="password" label="' . $xmlModel->escapeXml($this->__('New Password')) . '"/>
63
+ <field name="confirmation" type="password" label="' . $xmlModel->escapeXml($this->__('Confirm New Password')) . '">
64
+ <validators>
65
+ <validator type="confirmation" message="' . $xmlModel->escapeXml($this->__('Regular and confirmation passwords must be equal')) . '">password</validator>
66
+ </validators>
67
+ </field>
68
+ </fieldset>';
69
+ } else {
70
+ $passwordManageXml = '
71
+ <field name="password" type="password" label="' . $xmlModel->escapeXml($this->__('Password')) . '" required="true"/>
72
+ <field name="confirmation" type="password" label="' . $xmlModel->escapeXml($this->__('Confirm Password')) . '" required="true">
73
+ <validators>
74
+ <validator type="confirmation" message="' . $xmlModel->escapeXml($this->__('Regular and confirmation passwords must be equal')) . '">password</validator>
75
+ </validators>
76
+ </field>
77
+ </fieldset>';
78
+ }
79
+
80
+ $xml = <<<EOT
81
+ <form name="account_form" method="post">
82
+ <fieldset>
83
+ <field name="firstname" type="text" label="{$xmlModel->escapeXml($this->__('First Name'))}" required="true" value="$firstname" />
84
+ <field name="lastname" type="text" label="{$xmlModel->escapeXml($this->__('Last Name'))}" required="true" value="$lastname" />
85
+ <field name="email" type="text" label="{$xmlModel->escapeXml($this->__('Email'))}" required="true" value="$email">
86
+ <validators>
87
+ <validator type="email" message="{$xmlModel->escapeXml($this->__('Wrong email format'))}"/>
88
+ </validators>
89
+ </field>
90
+ $passwordManageXml
91
+ </form>
92
+ EOT;
93
+
94
+ return $xml;
95
+ }
96
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Boolean.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer boolean select field form xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Form_Renderer_Boolean
35
+ extends Mage_XmlConnect_Block_Customer_Form_Renderer_Select
36
+ {
37
+ /**
38
+ * Return array of select options
39
+ *
40
+ * @return array
41
+ */
42
+ public function getOptions()
43
+ {
44
+ return array(
45
+ array(
46
+ 'value' => '',
47
+ 'label' => ''
48
+ ),
49
+ array(
50
+ 'value' => '0',
51
+ 'label' => Mage::helper('enterprise_customer')->__('No')
52
+ ),
53
+ array(
54
+ 'value' => '1',
55
+ 'label' => Mage::helper('enterprise_customer')->__('Yes')
56
+ ),
57
+ );
58
+ }
59
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Date.php ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer date field form xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Form_Renderer_Date
35
+ extends Enterprise_Customer_Block_Form_Renderer_Date
36
+ {
37
+ /**
38
+ * Field type
39
+ *
40
+ * @var string
41
+ */
42
+ protected $_filedType = 'date';
43
+
44
+ /**
45
+ * Prepare values for renderer
46
+ *
47
+ * @return array
48
+ */
49
+ protected function _prepareValues()
50
+ {
51
+ return array(
52
+ 'day' => array(
53
+ 'id' => $this->getHtmlId('day'),
54
+ 'title' => $this->__('Day'),
55
+ 'label' => $this->__('DD'),
56
+ 'value' => $this->getDay()
57
+ ),
58
+ 'month' => array(
59
+ 'id' => $this->getHtmlId('month'),
60
+ 'title' => $this->__('Month'),
61
+ 'label' => $this->__('MM'),
62
+ 'value' => $this->getMonth()
63
+ ),
64
+ 'year' => array(
65
+ 'id' => $this->getHtmlId('year'),
66
+ 'title' => $this->__('Year'),
67
+ 'label' => $this->__('YYYY'),
68
+ 'value' => $this->getYear()
69
+ )
70
+ );
71
+ }
72
+
73
+ /**
74
+ * Add date field to fieldset xml object
75
+ *
76
+ * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $fieldsetXmlObj
77
+ * @return Mage_XmlConnect_Block_Customer_Form_Renderer_Date
78
+ */
79
+ public function addFieldToXmlObj(Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $fieldsetXmlObj)
80
+ {
81
+ $attributes = array(
82
+ 'label' => $this->getLabel(),
83
+ 'name' => $this->getFieldName(),
84
+ 'format' => $this->getDateFormat(),
85
+ 'value' => $this->_prepareValues()
86
+ );
87
+
88
+ $attributes += Mage::helper('xmlconnect/customer_form_renderer')
89
+ ->addTitleAndRequiredAttr($fieldsetXmlObj, $this);
90
+
91
+ $fieldXmlObj = $fieldsetXmlObj->addField(
92
+ $this->getHtmlId('full'),
93
+ $this->_filedType,
94
+ $attributes
95
+ );
96
+
97
+ $validateRules = $this->getAttributeObject()->getValidateRules();
98
+
99
+ if (!empty($validateRules)) {
100
+ $validatorXmlObj = $fieldXmlObj->addValidator();
101
+ if (!empty($validateRules['input_validation'])) {
102
+ $validatorXmlObj->addRule(array (
103
+ 'type' => $validateRules['input_validation']
104
+ ));
105
+ }
106
+ }
107
+
108
+ return $this;
109
+ }
110
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/File.php ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer file field form xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Form_Renderer_File
35
+ extends Enterprise_Customer_Block_Form_Renderer_File
36
+ {
37
+ /**
38
+ * Field type
39
+ *
40
+ * @var string
41
+ */
42
+ protected $_filedType = 'file';
43
+
44
+ /**
45
+ * Change form post params for file upload compliance
46
+ *
47
+ * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract $fieldsetXmlObj
48
+ * @return Mage_XmlConnect_Block_Customer_Form_Renderer_File
49
+ */
50
+ protected function _setFormPostParams(Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract $fieldsetXmlObj)
51
+ {
52
+ $fieldsetXmlObj->getForm()->setData('method', 'post');
53
+ $fieldsetXmlObj->getForm()->setData('enctype', 'multipart/form-data');
54
+ return $this;
55
+ }
56
+
57
+ /**
58
+ * Add file field to fieldset xml object
59
+ *
60
+ * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $fieldsetXmlObj
61
+ * @return Mage_XmlConnect_Block_Customer_Form_Renderer_File
62
+ */
63
+ public function addFieldToXmlObj(Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $fieldsetXmlObj)
64
+ {
65
+ $this->_setFormPostParams($fieldsetXmlObj);
66
+
67
+ $attributes = array(
68
+ 'label' => $this->getLabel(),
69
+ 'name' => $this->getFieldName(),
70
+ 'value' => $this->getEscapedValue()
71
+ );
72
+
73
+ $attributes += Mage::helper('xmlconnect/customer_form_renderer')
74
+ ->addTitleAndRequiredAttr($fieldsetXmlObj, $this);
75
+
76
+ $fieldXmlObj = $fieldsetXmlObj->addField(
77
+ $this->getHtmlId(),
78
+ $this->_filedType,
79
+ $attributes
80
+ );
81
+ $this->_addValidator($fieldXmlObj);
82
+
83
+ return $this;
84
+ }
85
+
86
+ /**
87
+ * Add validator for file field to fieldset xml object
88
+ *
89
+ * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract $fieldXmlObj
90
+ * @return Mage_XmlConnect_Block_Customer_Form_Renderer_File
91
+ */
92
+ protected function _addValidator(Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract $fieldXmlObj)
93
+ {
94
+ $validateRules = $this->getAttributeObject()->getValidateRules();
95
+
96
+ if (!empty($validateRules)) {
97
+ $validatorXmlObj = $fieldXmlObj->addValidator();
98
+
99
+ if (!empty($validateRules['max_file_size'])) {
100
+ $minTextLength = (int) $validateRules['max_file_size'];
101
+ $validatorXmlObj->addRule(array (
102
+ 'type' => 'max_file_size',
103
+ 'value' => $minTextLength,
104
+ 'field_label' => $this->getLabel()
105
+ ));
106
+ }
107
+
108
+ if (!empty($validateRules['file_extensions'])) {
109
+ $maxTextLength = $validateRules['file_extensions'];
110
+ $validatorXmlObj->addRule(array (
111
+ 'type' => 'file_extensions',
112
+ 'value' => $maxTextLength,
113
+ 'field_label' => $this->getLabel()
114
+ ));
115
+ }
116
+ }
117
+ return $this;
118
+ }
119
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Image.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer image file field form xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Form_Renderer_Image
35
+ extends Mage_XmlConnect_Block_Customer_Form_Renderer_File
36
+ {
37
+ /**
38
+ * Field type
39
+ *
40
+ * @var string
41
+ */
42
+ protected $_filedType = 'image';
43
+
44
+ /**
45
+ * Add validator for image file field to fieldset xml object
46
+ *
47
+ * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract $fieldXmlObj
48
+ * @return Mage_XmlConnect_Block_Customer_Form_Renderer_Image
49
+ */
50
+ protected function _addValidator(Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract $fieldXmlObj)
51
+ {
52
+ parent::_addValidator($fieldXmlObj);
53
+
54
+ $validateRules = $this->getAttributeObject()->getValidateRules();
55
+
56
+ if (!empty($validateRules)) {
57
+
58
+ foreach ($fieldXmlObj->getElements() as $element) {
59
+ if ($element->getType() == 'validator') {
60
+ $validatorXmlObj = $element;
61
+ }
62
+ }
63
+
64
+ if (!isset($validatorXmlObj)) {
65
+ $validatorXmlObj = $fieldXmlObj->addValidator();
66
+ }
67
+
68
+ if (!empty($validateRules['max_image_width'])) {
69
+ $minTextLength = (int) $validateRules['max_image_width'];
70
+ $validatorXmlObj->addRule(array (
71
+ 'type' => 'max_image_width',
72
+ 'value' => $minTextLength,
73
+ 'field_label' => $this->getLabel()
74
+ ));
75
+ }
76
+
77
+ if (!empty($validateRules['max_image_heght'])) {
78
+ $maxTextLength = $validateRules['max_image_heght'];
79
+ $validatorXmlObj->addRule(array (
80
+ 'type' => 'max_image_height',
81
+ 'value' => $maxTextLength,
82
+ 'field_label' => $this->getLabel()
83
+ ));
84
+ }
85
+ }
86
+ return $this;
87
+ }
88
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Multiline.php ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer multi-line field form xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Form_Renderer_Multiline
35
+ extends Enterprise_Customer_Block_Form_Renderer_Multiline
36
+ {
37
+ /**
38
+ * Field type
39
+ *
40
+ * @var string
41
+ */
42
+ protected $_filedType = 'multiline';
43
+
44
+ /**
45
+ * Add multiline field to fieldset xml object
46
+ *
47
+ * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $fieldsetXmlObj
48
+ * @return Mage_XmlConnect_Block_Customer_Form_Renderer_Multiline
49
+ */
50
+ public function addFieldToXmlObj(Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $fieldsetXmlObj)
51
+ {
52
+ $attributes = array(
53
+ 'label' => $this->getLabel(),
54
+ 'name' => $this->getFieldName(),
55
+ 'line_count' => $this->getLineCount(),
56
+ 'attribute_code' => $this->getAttributeObject()->getAttributeCode(),
57
+ 'value' => $this->getValues()
58
+ );
59
+
60
+ $attributes += Mage::helper('xmlconnect/customer_form_renderer')
61
+ ->addTitleAndRequiredAttr($fieldsetXmlObj, $this);
62
+
63
+ $fieldXmlObj = $fieldsetXmlObj->addField(
64
+ $this->_filedType . '_' . $this->getHtmlId(),
65
+ $this->_filedType,
66
+ $attributes
67
+ );
68
+
69
+ $validateRules = $this->getAttributeObject()->getValidateRules();
70
+
71
+ if (!empty($validateRules)) {
72
+ $validatorXmlObj = $fieldXmlObj->addValidator();
73
+
74
+ if (!empty($validateRules['min_text_length'])) {
75
+ $minTextLength = (int) $validateRules['min_text_length'];
76
+ $validatorXmlObj->addRule(array (
77
+ 'type' => 'min_length',
78
+ 'value' => $minTextLength,
79
+ ));
80
+ }
81
+
82
+ if (!empty($validateRules['max_text_length'])) {
83
+ $maxTextLength = (int) $validateRules['max_text_length'];
84
+ $validatorXmlObj->addRule(array (
85
+ 'type' => 'max_length',
86
+ 'value' => $maxTextLength
87
+ ));
88
+ }
89
+
90
+ if (!empty($validateRules['input_validation'])) {
91
+ $validatorXmlObj->addRule(array (
92
+ 'type' => $validateRules['input_validation']
93
+ ));
94
+ }
95
+ }
96
+
97
+ return $this;
98
+ }
99
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Multiselect.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer select field form xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Form_Renderer_Multiselect
35
+ extends Enterprise_Customer_Block_Form_Renderer_Multiselect
36
+ {
37
+ /**
38
+ * Field type
39
+ *
40
+ * @var string
41
+ */
42
+ protected $_filedType = 'multiselect';
43
+
44
+ /**
45
+ * Add select field to fieldset xml object
46
+ *
47
+ * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $fieldsetXmlObj
48
+ * @return Mage_XmlConnect_Block_Customer_Form_Renderer_Select
49
+ */
50
+ public function addFieldToXmlObj(Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $fieldsetXmlObj)
51
+ {
52
+ $attributes = array(
53
+ 'label' => $this->getLabel(),
54
+ 'name' => $this->getFieldName(''),
55
+ 'value' => $this->getValues(),
56
+ 'options' => $this->getOptions()
57
+ );
58
+
59
+ $attributes += Mage::helper('xmlconnect/customer_form_renderer')
60
+ ->addTitleAndRequiredAttr($fieldsetXmlObj, $this);
61
+
62
+ $fieldsetXmlObj->addField($this->getHtmlId(), $this->_filedType, $attributes);
63
+
64
+ return $this;
65
+ }
66
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Select.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer select field form xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Form_Renderer_Select
35
+ extends Enterprise_Customer_Block_Form_Renderer_Select
36
+ {
37
+ /**
38
+ * Field type
39
+ *
40
+ * @var string
41
+ */
42
+ protected $_filedType = 'select';
43
+
44
+ /**
45
+ * Add select field to fieldset xml object
46
+ *
47
+ * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $fieldsetXmlObj
48
+ * @return Mage_XmlConnect_Block_Customer_Form_Renderer_Select
49
+ */
50
+ public function addFieldToXmlObj(Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $fieldsetXmlObj)
51
+ {
52
+ $attributes = array(
53
+ 'label' => $this->getLabel(),
54
+ 'name' => $this->getFieldName(),
55
+ 'value' => $this->getValue(),
56
+ 'options' => $this->getOptions()
57
+ );
58
+
59
+ $attributes += Mage::helper('xmlconnect/customer_form_renderer')
60
+ ->addTitleAndRequiredAttr($fieldsetXmlObj, $this);
61
+
62
+ $fieldsetXmlObj->addField($this->getHtmlId(), $this->_filedType, $attributes);
63
+
64
+ return $this;
65
+ }
66
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Text.php ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer text field form xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Form_Renderer_Text
35
+ extends Enterprise_Customer_Block_Form_Renderer_Text
36
+ {
37
+ /**
38
+ * Field type
39
+ *
40
+ * @var string
41
+ */
42
+ protected $_filedType = 'text';
43
+
44
+ /**
45
+ * Add text field to fieldset xml object
46
+ *
47
+ * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $fieldsetXmlObj
48
+ * @return Mage_XmlConnect_Block_Customer_Form_Renderer_Text
49
+ */
50
+ public function addFieldToXmlObj(
51
+ Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $fieldsetXmlObj
52
+ )
53
+ {
54
+ $attributes = array(
55
+ 'label' => $this->getLabel(),
56
+ 'name' => $this->getFieldName(),
57
+ 'value' => $this->getEscapedValue()
58
+ );
59
+
60
+ $attributes += Mage::helper('xmlconnect/customer_form_renderer')
61
+ ->addTitleAndRequiredAttr($fieldsetXmlObj, $this);
62
+
63
+ $fieldXmlObj = $fieldsetXmlObj->addField(
64
+ $this->getHtmlId(),
65
+ $this->_filedType,
66
+ $attributes
67
+ );
68
+
69
+ $validateRules = $this->getAttributeObject()->getValidateRules();
70
+
71
+ if (!empty($validateRules)) {
72
+ $validatorXmlObj = $fieldXmlObj->addValidator();
73
+
74
+ if (!empty($validateRules['min_text_length'])) {
75
+ $minTextLength = (int) $validateRules['min_text_length'];
76
+ $validatorXmlObj->addRule(array (
77
+ 'type' => 'min_length',
78
+ 'value' => $minTextLength,
79
+ ));
80
+ }
81
+
82
+ if (!empty($validateRules['max_text_length'])) {
83
+ $maxTextLength = (int) $validateRules['max_text_length'];
84
+ $validatorXmlObj->addRule(array (
85
+ 'type' => 'max_length',
86
+ 'value' => $maxTextLength
87
+ ));
88
+ }
89
+
90
+ if (!empty($validateRules['input_validation'])) {
91
+ $validatorXmlObj->addRule(array (
92
+ 'type' => $validateRules['input_validation']
93
+ ));
94
+ }
95
+ }
96
+
97
+ return $this;
98
+ }
99
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Textarea.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer textarea field form xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Form_Renderer_Textarea
35
+ extends Mage_XmlConnect_Block_Customer_Form_Renderer_Text
36
+ {
37
+ /**
38
+ * Field type
39
+ *
40
+ * @var string
41
+ */
42
+ protected $_filedType = 'textarea';
43
+ }
app/code/core/Mage/XmlConnect/Block/Customer/GiftcardCheck.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Check Gift card xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_GiftcardCheck extends Enterprise_GiftCardAccount_Block_Check
35
+ {
36
+ /**
37
+ * Render gift card info xml
38
+ *
39
+ * @return string
40
+ */
41
+ protected function _toHtml()
42
+ {
43
+ $card = $this->getCard();
44
+ if ($card->getId()) {
45
+ /** @var $xmlModel Mage_XmlConnect_Model_Simplexml_Element */
46
+ $xmlModel = Mage::getModel(
47
+ 'xmlconnect/simplexml_element',
48
+ '<gift_card_account></gift_card_account>'
49
+ );
50
+
51
+ $balance = Mage::helper('core')->currency($card->getBalance(), true, false);
52
+
53
+ $result[] = $this->__("Gift Card: %s", $card->getCode());
54
+ $result[] = $this->__('Current Balance: %s', $balance);
55
+
56
+ if ($card->getDateExpires()) {
57
+ $result[] = $this->__('Expires: %s', $this->formatDate($card->getDateExpires(), 'short'));
58
+ }
59
+ $xmlModel->addCustomChild('info', implode(PHP_EOL, $result));
60
+ } else {
61
+ $xmlModel = Mage::getModel(
62
+ 'xmlconnect/simplexml_element',
63
+ '<message></message>'
64
+ );
65
+
66
+ $xmlModel->addCustomChild(
67
+ 'status',
68
+ Mage_XmlConnect_Controller_Action::MESSAGE_STATUS_ERROR
69
+ );
70
+
71
+ $xmlModel->addCustomChild(
72
+ 'text',
73
+ $this->__('Wrong or expired Gift Card Code.')
74
+ );
75
+ }
76
+
77
+ return $xmlModel->asNiceXml();
78
+ }
79
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Order/Details.php ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer order details xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Order_Details extends Mage_Payment_Block_Info
35
+ {
36
+ /**
37
+ * Pre-defined array of methods that we are going to render
38
+ *
39
+ * Core renderer list:
40
+ * - 'ccsave' => Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Ccsave
41
+ * - 'checkmo' => Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Checkmo
42
+ * - 'purchaseorder' => Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Purchaseorder
43
+ * - 'authorizenet' => Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Authorizenet
44
+ * - 'pbridge_authorizenet' => Mage_Paygate_Block_Authorizenet_Info_Cc
45
+ * - 'pbridge_verisign' => Mage_Payment_Block_Info_Cc
46
+ * - 'paypal_express' => Mage_Paypal_Block_Payment_Info
47
+ * - 'paypal_mecl' => Mage_Paypal_Block_Payment_Info
48
+ * - 'pbridge_paypal_direct' => Mage_Paypal_Block_Payment_Info
49
+ * - 'pbridge_paypaluk_direct' => Mage_Paypal_Block_Payment_Info
50
+ * - 'free' => Mage_Payment_Block_Info
51
+ */
52
+ protected $_methodArray = array(
53
+ 'ccsave',
54
+ 'checkmo',
55
+ 'purchaseorder',
56
+ 'authorizenet',
57
+ 'pbridge_authorizenet',
58
+ 'pbridge_verisign',
59
+ 'paypal_express',
60
+ 'paypal_mecl',
61
+ 'pbridge_paypal_direct',
62
+ 'pbridge_paypaluk_direct',
63
+ 'free'
64
+ );
65
+
66
+ /**
67
+ * Render customer orders list xml
68
+ *
69
+ * @return string
70
+ */
71
+ protected function _toHtml()
72
+ {
73
+ /** @var $orderXmlObj Mage_XmlConnect_Model_Simplexml_Element */
74
+ $orderXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<order_details></order_details>');
75
+
76
+ $order = $this->_getOrder();
77
+
78
+ $orderDate = $this->formatDate($order->getCreatedAtStoreDate(), 'long');
79
+ $orderXmlObj->addCustomChild(
80
+ 'order',
81
+ null,
82
+ array(
83
+ 'label' => $this->__('Order #%s - %s', $order->getRealOrderId(), $order->getStatusLabel()),
84
+ 'order_date' => $this->__('Order Date: %s', $orderDate)
85
+ )
86
+ );
87
+ if (!$order->getIsVirtual()) {
88
+ $shipping = $this->_formatAddress($order->getShippingAddress()->format('text'));
89
+ $billing = $this->_formatAddress($order->getBillingAddress()->format('text'));
90
+
91
+ $orderXmlObj->addCustomChild('shipping_address', $shipping);
92
+ $orderXmlObj->addCustomChild('billing_address', $billing);
93
+
94
+ if ($order->getShippingDescription()) {
95
+ $shippingMethodDescription = $order->getShippingDescription();
96
+ } else {
97
+ $shippingMethodDescription = Mage::helper('sales')->__('No shipping information available');
98
+ }
99
+ $orderXmlObj->addCustomChild('shipping_method', $shippingMethodDescription);
100
+ }
101
+
102
+ $this->_addPaymentMethodInfoToXmlObj($orderXmlObj);
103
+
104
+ $itemsBlock = $this->getLayout()->getBlock('xmlconnect.customer.order.items');
105
+ if ($itemsBlock) {
106
+ /** @var $itemsBlock Mage_XmlConnect_Block_Customer_Order_Items */
107
+ $itemsBlock->setItems($order->getItemsCollection());
108
+ $itemsBlock->addItemsToXmlObject($orderXmlObj);
109
+ $totalsBlock = $this->getLayout()->getBlock('xmlconnect.customer.order.totals');
110
+ if ($totalsBlock) {
111
+ $totalsBlock->setOrder($order);
112
+ $totalsBlock->addTotalsToXmlObject($orderXmlObj);
113
+ }
114
+ } else {
115
+ $orderXmlObj->addChild('ordered_items');
116
+ }
117
+
118
+ return $orderXmlObj->asNiceXml();
119
+ }
120
+
121
+ /**
122
+ * Add payment method info to order xml object
123
+ *
124
+ * @param Mage_XmlConnect_Model_Simplexml_Element $orderXmlObj
125
+ * @return Mage_XmlConnect_Model_Simplexml_Element
126
+ */
127
+ protected function _addPaymentMethodInfoToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $orderXmlObj)
128
+ {
129
+ $order = $this->_getOrder();
130
+
131
+ // TODO: it's need to create an info blocks for other payment methods (including Enterprise)
132
+ $method = $this->helper('payment')->getInfoBlock($order->getPayment())->getMethod();
133
+ $methodCode = $method->getCode();
134
+
135
+ $paymentNode = $orderXmlObj->addChild('payment_method');
136
+
137
+ if (in_array($methodCode, $this->_methodArray, true)) {
138
+ $currentBlockRenderer = 'xmlconnect/checkout_payment_method_info_' . $methodCode;
139
+ $currentBlockName = 'xmlconnect.checkout.payment.method.info.' . $methodCode;
140
+ $this->getLayout()->addBlock($currentBlockRenderer, $currentBlockName);
141
+ $this->setChild($methodCode, $currentBlockName);
142
+ $renderer = $this->getChild($methodCode)->setInfo($order->getPayment());
143
+ $renderer->addPaymentInfoToXmlObj($paymentNode);
144
+ } else {
145
+ $paymentNode->addAttribute('type', $methodCode);
146
+ $paymentNode->addAttribute('title', $orderXmlObj->xmlAttribute($method->getTitle()));
147
+
148
+ $this->setInfo($order->getPayment());
149
+
150
+ $specificInfo = array_merge(
151
+ (array)$order->getPayment()->getAdditionalInformation(),
152
+ (array)$this->getSpecificInformation()
153
+ );
154
+ if (!empty($specificInfo)) {
155
+ foreach ($specificInfo as $label => $value) {
156
+ if ($value) {
157
+ $paymentNode->addCustomChild(
158
+ 'item',
159
+ implode($this->getValueAsArray($value, true), PHP_EOL),
160
+ array('label' => $label)
161
+ );
162
+ }
163
+ }
164
+ }
165
+ }
166
+
167
+ return $orderXmlObj;
168
+ }
169
+
170
+ /**
171
+ * Get order model
172
+ *
173
+ * @through Mage_Core_Exception
174
+ * @return Mage_Sales_Model_Order
175
+ */
176
+ protected function _getOrder()
177
+ {
178
+ $order = Mage::registry('current_order');
179
+ if (!($order instanceof Mage_Sales_Model_Order)) {
180
+ Mage::throwException($this->__('Order is not available.'));
181
+ }
182
+ return $order;
183
+ }
184
+
185
+ /**
186
+ * Format address string
187
+ *
188
+ * @param string $address
189
+ * @return string
190
+ */
191
+ protected function _formatAddress($address)
192
+ {
193
+ return preg_replace(
194
+ array('@\r@', '@\n+@'),
195
+ array('', PHP_EOL),
196
+ $address
197
+ );
198
+ }
199
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Bundle.php ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer order item xml renderer for bundle product type
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Order_Item_Renderer_Bundle
35
+ extends Mage_Bundle_Block_Sales_Order_Items_Renderer
36
+ {
37
+ /**
38
+ * Add item to XML object
39
+ * (get from template: bundle/sales/order/items/renderer.phtml)
40
+ *
41
+ * @param Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj
42
+ * @return void
43
+ */
44
+ public function addItemToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj)
45
+ {
46
+ /** @var $parentItem Mage_Sales_Model_Order_Item */
47
+ $parentItem = $this->getItem();
48
+
49
+ $items = array_merge(array($parentItem), $parentItem->getChildrenItems());
50
+ $_prevOptionId = '';
51
+
52
+ /** @var $weeeHelper Mage_Weee_Helper_Data */
53
+ $weeeHelper = $this->helper('weee');
54
+ /** @var $taxHelper Mage_Tax_Helper_Data */
55
+ $taxHelper = $this->helper('tax');
56
+
57
+ /** @var $itemXml Mage_XmlConnect_Model_Simplexml_Element */
58
+ $itemXml = $orderItemXmlObj->addChild('item');
59
+ /** @var $optionsXml Mage_XmlConnect_Model_Simplexml_Element */
60
+ $optionsXml = $itemXml->addChild('related_products');
61
+
62
+ $this->setWeeeTaxAppliedAmount($parentItem->getWeeeTaxAppliedAmount());
63
+ $this->setWeeeTaxDisposition($parentItem->getWeeeTaxDisposition());
64
+
65
+ $typeOfDisplay1 = $weeeHelper->typeOfDisplay($parentItem, 1, 'sales')
66
+ && $this->getWeeeTaxAppliedAmount();
67
+ $typeOfDisplay2 = $weeeHelper->typeOfDisplay($parentItem, 2, 'sales')
68
+ && $this->getWeeeTaxAppliedAmount();
69
+ $typeOfDisplay4 = $weeeHelper->typeOfDisplay($parentItem, 4, 'sales')
70
+ && $this->getWeeeTaxAppliedAmount();
71
+ $typeOfDisplay014 = $weeeHelper->typeOfDisplay($parentItem, array(0, 1, 4), 'sales')
72
+ && $this->getWeeeTaxAppliedAmount();
73
+
74
+ $this->setTypesOfDisplay(array(
75
+ 1 => $typeOfDisplay1,
76
+ 2 => $typeOfDisplay2,
77
+ 4 => $typeOfDisplay4,
78
+ 14 => $typeOfDisplay014,
79
+ ));
80
+ $this->setWeeeTaxes($weeeHelper->getApplied($parentItem));
81
+
82
+ /** @var $item Mage_Sales_Model_Order_Item */
83
+ foreach ($items as $item) {
84
+ $isOption = $item->getParentItem() ? true : false;
85
+
86
+ /** @var $objectXml Mage_XmlConnect_Model_Simplexml_Element */
87
+ if ($isOption) {
88
+ $objectXml = $optionsXml->addChild('item');
89
+ } else {
90
+ $objectXml = $itemXml;
91
+ }
92
+ $objectXml->addAttribute('product_id', $item->getProductId());
93
+ $objectXml->addCustomChild('entity_type', $item->getProductType());
94
+
95
+ if ($isOption) {
96
+ $attributes = $this->getSelectionAttributes($item);
97
+ if ($_prevOptionId != $attributes['option_id']) {
98
+ $objectXml->addAttribute('label', $objectXml->xmlAttribute($attributes['option_label']));
99
+ $_prevOptionId = $attributes['option_id'];
100
+ }
101
+ }
102
+
103
+ $objectXml->addCustomChild('sku', Mage::helper('core/string')->splitInjection($item->getSku()));
104
+
105
+ if ($isOption) {
106
+ $name = $this->getValueHtml($item);
107
+ } else {
108
+ $name = $item->getName();
109
+ }
110
+ $objectXml->addCustomChild('name', $name);
111
+
112
+ // set prices exactly for the Bundle product, but not for related products
113
+ if (!$isOption) {
114
+ /** @var $priceXml Mage_XmlConnect_Model_Simplexml_Element */
115
+ $priceXml = $objectXml->addChild('price');
116
+ /** @var $subtotalXml Mage_XmlConnect_Model_Simplexml_Element */
117
+ $subtotalXml = $objectXml->addChild('subtotal');
118
+
119
+ // Price excluding tax
120
+ if ($taxHelper->displaySalesBothPrices() || $taxHelper->displaySalesPriceExclTax()) {
121
+ Mage::helper('xmlconnect/customer_order')->addPriceAndSubtotalToXml(
122
+ $this,
123
+ $parentItem,
124
+ $priceXml,
125
+ $subtotalXml
126
+ );
127
+ }
128
+
129
+ // Price including tax
130
+ if ($taxHelper->displaySalesBothPrices() || $taxHelper->displaySalesPriceInclTax()) {
131
+ Mage::helper('xmlconnect/customer_order')->addPriceAndSubtotalToXml(
132
+ $this,
133
+ $parentItem,
134
+ $priceXml,
135
+ $subtotalXml,
136
+ true
137
+ );
138
+ }
139
+ }
140
+
141
+ // set quantities
142
+ /** @var $qtyXml Mage_XmlConnect_Model_Simplexml_Element */
143
+ if (($isOption && $this->isChildCalculated())
144
+ || (!$isOption && !$this->isChildCalculated())
145
+ ) {
146
+ $qtyXml = $objectXml->addChild('qty');
147
+ if ($item->getQtyOrdered() > 0) {
148
+ $qtyXml->addCustomChild(
149
+ 'value',
150
+ $item->getQtyOrdered() * 1,
151
+ array('label' => Mage::helper('sales')->__('Ordered'))
152
+ );
153
+ }
154
+ if ($item->getQtyShipped() > 0 && !$this->isShipmentSeparately()) {
155
+ $qtyXml->addCustomChild(
156
+ 'value',
157
+ $item->getQtyShipped() * 1,
158
+ array('label' => Mage::helper('sales')->__('Shipped'))
159
+ );
160
+ }
161
+ if ($item->getQtyCanceled() > 0) {
162
+ $qtyXml->addCustomChild(
163
+ 'value',
164
+ $item->getQtyCanceled() * 1,
165
+ array('label' => Mage::helper('sales')->__('Canceled'))
166
+ );
167
+ }
168
+ if ($item->getQtyRefunded() > 0) {
169
+ $qtyXml->addCustomChild(
170
+ 'value',
171
+ $item->getQtyRefunded() * 1,
172
+ array('label' => Mage::helper('sales')->__('Refunded'))
173
+ );
174
+ }
175
+ } elseif ($item->getQtyShipped() > 0 && $isOption && $this->isShipmentSeparately()) {
176
+ $qtyXml = $objectXml->addChild('qty');
177
+ $qtyXml->addCustomChild(
178
+ 'value',
179
+ $item->getQtyShipped() * 1,
180
+ array('label' => Mage::helper('sales')->__('Shipped'))
181
+ );
182
+ }
183
+ }
184
+
185
+ if ($parentItem->getDescription()) {
186
+ $itemXml->addCustomChild(
187
+ 'description',
188
+ $parentItem->getDescription()
189
+ );
190
+ }
191
+
192
+ Mage::helper('xmlconnect/customer_order')->addItemOptionsToXml(
193
+ $this,
194
+ $itemXml
195
+ );
196
+ }
197
+
198
+ /**
199
+ * Prepare option data for output
200
+ *
201
+ * @param Mage_Sales_Model_Order_Item $item
202
+ * @return string
203
+ */
204
+ public function getValueHtml($item)
205
+ {
206
+ $attributes = $this->getSelectionAttributes($item);
207
+ if ($attributes) {
208
+ return sprintf('%d', $attributes['qty']) . ' x '
209
+ . $item->getName()
210
+ . ' - ' . $this->_formatPrice($attributes['price']);
211
+ } else {
212
+ return $item->getName();
213
+ }
214
+ }
215
+
216
+ /**
217
+ * Format price using order currency
218
+ *
219
+ * @param float $price
220
+ * @return string
221
+ */
222
+ protected function _formatPrice($price)
223
+ {
224
+ return Mage::helper('xmlconnect/customer_order')->formatPrice($this, $price);
225
+ }
226
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Default.php ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer order details item xml
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Order_Item_Renderer_Default
35
+ extends Mage_Sales_Block_Order_Item_Renderer_Default
36
+ {
37
+ /**
38
+ * Add item to XML object
39
+ * (get from template: sales/order/items/renderer/default.phtml)
40
+ *
41
+ * @param Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj
42
+ * @return void
43
+ */
44
+ public function addItemToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj)
45
+ {
46
+ /** @var $item Mage_Sales_Model_Order_Item */
47
+ $item = $this->getItem();
48
+
49
+ /** @var $itemXml Mage_XmlConnect_Model_Simplexml_Element */
50
+ $itemXml = $orderItemXmlObj->addCustomChild(
51
+ 'item',
52
+ null,
53
+ array(
54
+ 'product_id' => $item->getProductId()
55
+ )
56
+ );
57
+ $itemXml->addCustomChild('name', $item->getName());
58
+
59
+ /** @var $weeeHelper Mage_Weee_Helper_Data */
60
+ $weeeHelper = $this->helper('weee');
61
+ /** @var $taxHelper Mage_Tax_Helper_Data */
62
+ $taxHelper = $this->helper('tax');
63
+
64
+ Mage::helper('xmlconnect/customer_order')->addItemOptionsToXml(
65
+ $this,
66
+ $itemXml
67
+ );
68
+
69
+ $addtInfoBlock = $this->getProductAdditionalInformationBlock();
70
+ if ($addtInfoBlock) {
71
+ // TODO: find how to set additional info block
72
+ // $addtInfoBlock->setItem($item)->toHtml();
73
+ }
74
+
75
+ $itemXml->addCustomChild('entity_type', $item->getProductType());
76
+ $itemXml->addCustomChild('description', $item->getDescription());
77
+ $itemXml->addCustomChild('sku', Mage::helper('core/string')->splitInjection($this->getSku()));
78
+
79
+ $this->setWeeeTaxAppliedAmount($item->getWeeeTaxAppliedAmount());
80
+ $this->setWeeeTaxDisposition($item->getWeeeTaxDisposition());
81
+
82
+ $typeOfDisplay1 = $weeeHelper->typeOfDisplay($item, 1, 'sales')
83
+ && $this->getWeeeTaxAppliedAmount();
84
+ $typeOfDisplay2 = $weeeHelper->typeOfDisplay($item, 2, 'sales')
85
+ && $this->getWeeeTaxAppliedAmount();
86
+ $typeOfDisplay4 = $weeeHelper->typeOfDisplay($item, 4, 'sales')
87
+ && $this->getWeeeTaxAppliedAmount();
88
+ $typeOfDisplay014 = $weeeHelper->typeOfDisplay($item, array(0, 1, 4), 'sales')
89
+ && $this->getWeeeTaxAppliedAmount();
90
+
91
+ $this->setTypesOfDisplay(array(
92
+ 1 => $typeOfDisplay1,
93
+ 2 => $typeOfDisplay2,
94
+ 4 => $typeOfDisplay4,
95
+ 14 => $typeOfDisplay014,
96
+ ));
97
+ $this->setWeeeTaxes($weeeHelper->getApplied($item));
98
+
99
+ /** @var $priceXml Mage_XmlConnect_Model_Simplexml_Element */
100
+ $priceXml = $itemXml->addChild('price');
101
+
102
+ // Quantity: Ordered, Shipped, Cancelled, Refunded
103
+ Mage::helper('xmlconnect/customer_order')->addQuantityToXml(
104
+ $this,
105
+ $itemXml->addChild('qty'),
106
+ $item
107
+ );
108
+
109
+ /** @var $subtotalXml Mage_XmlConnect_Model_Simplexml_Element */
110
+ $subtotalXml = $itemXml->addChild('subtotal');
111
+
112
+ // Price & subtotal - excluding tax
113
+ if ($taxHelper->displaySalesBothPrices() || $taxHelper->displaySalesPriceExclTax()) {
114
+ Mage::helper('xmlconnect/customer_order')->addPriceAndSubtotalToXml(
115
+ $this,
116
+ $item,
117
+ $priceXml,
118
+ $subtotalXml
119
+ );
120
+ }
121
+
122
+ // Price & subtotal - including tax
123
+ if ($taxHelper->displaySalesBothPrices() || $taxHelper->displaySalesPriceInclTax()) {
124
+ Mage::helper('xmlconnect/customer_order')->addPriceAndSubtotalToXml(
125
+ $this,
126
+ $item,
127
+ $priceXml,
128
+ $subtotalXml,
129
+ true
130
+ );
131
+ }
132
+ }
133
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Downloadable.php ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer order details item xml
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Order_Item_Renderer_Downloadable
35
+ extends Mage_Downloadable_Block_Sales_Order_Item_Renderer_Downloadable
36
+ {
37
+ /**
38
+ * Add item to XML object
39
+ * (get from template: downloadable/sales/order/items/renderer/downloadable.phtml)
40
+ *
41
+ * @param Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj
42
+ * @return void
43
+ */
44
+ public function addItemToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj)
45
+ {
46
+ /** @var $item Mage_Sales_Model_Order_Item */
47
+ $item = $this->getItem();
48
+
49
+ /** @var $itemXml Mage_XmlConnect_Model_Simplexml_Element */
50
+ $itemXml = $orderItemXmlObj->addCustomChild(
51
+ 'item',
52
+ null,
53
+ array(
54
+ 'product_id' => $item->getProductId()
55
+ )
56
+ );
57
+ $itemXml->addCustomChild('name', $item->getName());
58
+
59
+ /** @var $weeeHelper Mage_Weee_Helper_Data */
60
+ $weeeHelper = $this->helper('weee');
61
+ /** @var $taxHelper Mage_Tax_Helper_Data */
62
+ $taxHelper = $this->helper('tax');
63
+
64
+ Mage::helper('xmlconnect/customer_order')->addItemOptionsToXml(
65
+ $this,
66
+ $itemXml
67
+ );
68
+
69
+ $addtInfoBlock = $this->getProductAdditionalInformationBlock();
70
+ if ($addtInfoBlock) {
71
+ // TODO: find how to set additional info block
72
+ // $addtInfoBlock->setItem($item)->toHtml();
73
+ }
74
+
75
+ $links = $this->getLinks();
76
+ if ($links) {
77
+ $linksXml = $itemXml->addCustomChild(
78
+ 'links',
79
+ null,
80
+ array('label' => $this->getLinksTitle())
81
+ );
82
+ foreach ($links->getPurchasedItems() as $link) {
83
+ $linksXml->addCustomChild(
84
+ 'link',
85
+ $link->getLinkTitle()
86
+ );
87
+ }
88
+ }
89
+
90
+ $itemXml->addCustomChild('entity_type', $item->getProductType());
91
+ $itemXml->addCustomChild('description', $item->getDescription());
92
+ $itemXml->addCustomChild('sku', Mage::helper('core/string')->splitInjection($this->getSku()));
93
+
94
+ /** @var $priceXml Mage_XmlConnect_Model_Simplexml_Element */
95
+ $priceXml = $itemXml->addChild('price');
96
+
97
+ // Quantity: Ordered, Shipped, Cancelled, Refunded
98
+ Mage::helper('xmlconnect/customer_order')->addQuantityToXml(
99
+ $this,
100
+ $itemXml->addChild('qty'),
101
+ $item
102
+ );
103
+
104
+ /** @var $subtotalXml Mage_XmlConnect_Model_Simplexml_Element */
105
+ $subtotalXml = $itemXml->addChild('subtotal');
106
+
107
+ $this->setWeeeTaxAppliedAmount($item->getWeeeTaxAppliedAmount());
108
+ $this->setWeeeTaxDisposition($item->getWeeeTaxDisposition());
109
+
110
+ $typeOfDisplay1 = $weeeHelper->typeOfDisplay($item, 1, 'sales')
111
+ && $this->getWeeeTaxAppliedAmount();
112
+ $typeOfDisplay2 = $weeeHelper->typeOfDisplay($item, 2, 'sales')
113
+ && $this->getWeeeTaxAppliedAmount();
114
+ $typeOfDisplay4 = $weeeHelper->typeOfDisplay($item, 4, 'sales')
115
+ && $this->getWeeeTaxAppliedAmount();
116
+ $typeOfDisplay014 = $weeeHelper->typeOfDisplay($item, array(0, 1, 4), 'sales')
117
+ && $this->getWeeeTaxAppliedAmount();
118
+
119
+ $this->setTypesOfDisplay(array(
120
+ 1 => $typeOfDisplay1,
121
+ 2 => $typeOfDisplay2,
122
+ 4 => $typeOfDisplay4,
123
+ 14 => $typeOfDisplay014,
124
+ ));
125
+ $this->setWeeeTaxes($weeeHelper->getApplied($item));
126
+
127
+ // Price & subtotal - excluding tax
128
+ if ($taxHelper->displaySalesBothPrices() || $taxHelper->displaySalesPriceExclTax()) {
129
+ Mage::helper('xmlconnect/customer_order')->addPriceAndSubtotalToXml(
130
+ $this,
131
+ $item,
132
+ $priceXml,
133
+ $subtotalXml
134
+ );
135
+ }
136
+
137
+ // Price & subtotal - including tax
138
+ if ($taxHelper->displaySalesBothPrices() || $taxHelper->displaySalesPriceInclTax()) {
139
+ Mage::helper('xmlconnect/customer_order')->addPriceAndSubtotalToXml(
140
+ $this,
141
+ $item,
142
+ $priceXml,
143
+ $subtotalXml,
144
+ true
145
+ );
146
+ }
147
+ }
148
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Giftcard.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer order Giftcard xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Order_Item_Renderer_Giftcard
35
+ extends Enterprise_GiftCard_Block_Sales_Order_Item_Renderer
36
+ {
37
+ /**
38
+ * Prepare custom option for display, returns false if there's no value
39
+ *
40
+ * @param string $code
41
+ * @return mixed
42
+ */
43
+ protected function _prepareCustomOption($code)
44
+ {
45
+ if ($option = $this->getOrderItem()->getProductOptionByCode($code)) {
46
+ return strip_tags($option);
47
+ }
48
+ return false;
49
+ }
50
+
51
+ /**
52
+ * Prepare a string containing name and email
53
+ *
54
+ * @param string $name
55
+ * @param string $email
56
+ * @return mixed
57
+ */
58
+ protected function _getNameEmailString($name, $email)
59
+ {
60
+ return $name . ' (' . $email . ')';
61
+ }
62
+
63
+ /**
64
+ * Add item to XML object
65
+ * (get from template: sales/order/items/renderer/default.phtml)
66
+ *
67
+ * @param Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj
68
+ * @return void
69
+ */
70
+ public function addItemToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj)
71
+ {
72
+ $item = $this->getOrderItem();
73
+ $item->setProductOptions(array('additional_options' => $this->getItemOptions()));
74
+
75
+ $defaultRenderer = $this->getLayout()->getBlock('xmlconnect.customer.order.items')->getItemRenderer(null);
76
+ $defaultRenderer->setItem($item);
77
+ $defaultRenderer->addItemToXmlObject($orderItemXmlObj);
78
+ }
79
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Grouped.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer order item xml renderer for grouped product type
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Order_Item_Renderer_Grouped
35
+ extends Mage_Sales_Block_Order_Item_Renderer_Grouped
36
+ {
37
+ /**
38
+ * Default product type
39
+ */
40
+ const DEFAULT_PRODUCT_TYPE = 'default';
41
+
42
+ /**
43
+ * Add item to XML object
44
+ * (get from template: sales/order/items/renderer/default.phtml)
45
+ *
46
+ * @param Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj
47
+ * @return void
48
+ */
49
+ public function addItemToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj)
50
+ {
51
+ if (!($item = $this->getItem()->getOrderItem())) {
52
+ $item = $this->getItem();
53
+ }
54
+ if (!($productType = $item->getRealProductType())) {
55
+ $productType = self::DEFAULT_PRODUCT_TYPE;
56
+ }
57
+ $renderer = $this->getRenderedBlock()->getItemRenderer($productType);
58
+ $renderer->setItem($this->getItem());
59
+
60
+ $renderer->addItemToXmlObject($orderItemXmlObj);
61
+ }
62
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Order/Items.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer order view items xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Order_Items extends Mage_Sales_Block_Order_Items
35
+ {
36
+ /**
37
+ * Initialize default item renderer
38
+ */
39
+ protected function _construct()
40
+ {
41
+ parent::_construct();
42
+ $this->addItemRender('default', 'xmlconnect/customer_order_item_renderer_default', null);
43
+ }
44
+
45
+ /**
46
+ * Retrieve item renderer block
47
+ *
48
+ * @param string $type
49
+ * @return Mage_Core_Block_Abstract
50
+ */
51
+ public function getItemRenderer($type)
52
+ {
53
+ if (empty($type) || !isset($this->_itemRenders[$type])) {
54
+ $type = 'default';
55
+ }
56
+
57
+ if (is_null($this->_itemRenders[$type]['renderer'])) {
58
+ $this->_itemRenders[$type]['renderer'] = $this->getLayout()
59
+ ->createBlock($this->_itemRenders[$type]['block'])
60
+ ->setRenderedBlock($this);
61
+ }
62
+ return $this->_itemRenders[$type]['renderer'];
63
+ }
64
+
65
+ /**
66
+ * Render XML for items
67
+ * (get from template: sales/order/items.phtml)
68
+ *
69
+ * @param Mage_XmlConnect_Model_Simplexml_Element $orderXmlObj
70
+ * @return void
71
+ */
72
+ public function addItemsToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orderXmlObj)
73
+ {
74
+ $itemsXml = $orderXmlObj->addChild('ordered_items');
75
+
76
+ foreach ($this->getItems() as $item) {
77
+ if ($item->getParentItem()) {
78
+ // if Item is option of grouped product - do not render it
79
+ continue;
80
+ }
81
+ $type = $this->_getItemType($item);
82
+
83
+ // TODO: take out all Enterprise renderers from layout update into array an realize checking of their using
84
+ // Check if the Enterprise_GiftCard module is available for rendering
85
+ if ($type == 'giftcard' && !is_object(Mage::getConfig()->getNode('modules/Enterprise_GiftCard'))) {
86
+ continue;
87
+ }
88
+ $renderer = $this->getItemRenderer($type)->setItem($item);
89
+ if (method_exists($renderer, 'addItemToXmlObject')) {
90
+ $renderer->addItemToXmlObject($itemsXml);
91
+ }
92
+ }
93
+ }
94
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Order/List.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer orders history xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Order_List extends Mage_Core_Block_Template
35
+ {
36
+ /**
37
+ * Orders count limit
38
+ */
39
+ const ORDERS_LIST_LIMIT = 10;
40
+
41
+ /**
42
+ * Render customer orders list xml
43
+ *
44
+ * @return string
45
+ */
46
+ protected function _toHtml()
47
+ {
48
+ $ordersXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<orders></orders>');
49
+
50
+ $orders = Mage::getResourceModel('sales/order_collection')->addFieldToSelect('*')
51
+ ->addFieldToFilter('customer_id', Mage::getSingleton('customer/session')->getCustomer()->getId())
52
+ ->addFieldToFilter('state', array(
53
+ 'in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()
54
+ ))->setOrder('created_at', 'desc');
55
+
56
+ $orders->getSelect()->limit(self::ORDERS_LIST_LIMIT, 0);
57
+ $orders->load();
58
+
59
+ if (sizeof($orders->getItems())) {
60
+ foreach ($orders as $_order) {
61
+ $item = $ordersXmlObj->addChild('item');
62
+ $item->addChild('entity_id', $_order->getId());
63
+ $item->addChild('number', $_order->getRealOrderId());
64
+ $item->addChild('date', $this->formatDate($_order->getCreatedAtStoreDate()));
65
+ if ($_order->getShippingAddress()) {
66
+ $item->addChild('ship_to', $ordersXmlObj->escapeXml($_order->getShippingAddress()->getName()));
67
+ }
68
+ $item->addChild('total', $_order->getOrderCurrency()->formatPrecision(
69
+ $_order->getGrandTotal(), 2, array(), false, false
70
+ ));
71
+ $item->addChild('status', $_order->getStatusLabel());
72
+ }
73
+ }
74
+ return $ordersXmlObj->asNiceXml();
75
+ }
76
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals.php ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer order totals xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Order_Totals extends Mage_Sales_Block_Order_Totals
35
+ {
36
+ /**
37
+ * Add order totals rendered to XML object
38
+ * (get from template: sales/order/totals.phtml)
39
+ *
40
+ * @param Mage_XmlConnect_Model_Simplexml_Element $orderXmlObj
41
+ * @return void
42
+ */
43
+ public function addTotalsToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orderXmlObj)
44
+ {
45
+ // all Enterprise renderers from layout update into array an realize checking of their using
46
+ $enterpriseBlocks = array(
47
+ 'reward.sales.order.total' => array(
48
+ 'module' => 'Enterprise_Reward',
49
+ 'block' => 'enterprise_reward/sales_order_total'
50
+ ),
51
+ 'customerbalance' => array(
52
+ 'module' => 'Enterprise_CustomerBalance',
53
+ 'block' => 'xmlconnect/customer_order_totals_customerbalance',
54
+ 'template' => 'customerbalance/order/customerbalance.phtml'
55
+ ),
56
+ 'customerbalance_total_refunded' => array(
57
+ 'module' => 'Enterprise_CustomerBalance',
58
+ 'block' => 'xmlconnect/customer_order_totals_customerbalance_refunded',
59
+ 'template' => 'customerbalance/order/customerbalance_refunded.phtml',
60
+ 'after' => '-',
61
+ 'action' => array(
62
+ 'method' => 'setAfterTotal',
63
+ 'value' => 'grand_total'
64
+ )
65
+ ),
66
+ 'giftwrapping' => array(
67
+ 'module' => 'Enterprise_GiftWrapping',
68
+ 'block' => 'enterprise_giftwrapping/sales_totals'
69
+ ),
70
+ 'giftcards' => array(
71
+ 'module' => 'Enterprise_GiftCardAccount',
72
+ 'block' => 'xmlconnect/customer_order_totals_giftcards',
73
+ 'template' => 'giftcardaccount/order/giftcards.phtml'
74
+ ),
75
+ );
76
+
77
+ foreach ($enterpriseBlocks as $name => $block) {
78
+ // create blocks only for Enterprise/Pro modules which is in system
79
+ if (is_object(Mage::getConfig()->getNode('modules/' . $block['module']))) {
80
+ $blockInstance = $this->getLayout()->createBlock($block['block'], $name);
81
+ $this->setChild($name, $blockInstance);
82
+ if (isset($block['action']['method']) && isset($block['action']['value'])) {
83
+ $method = $block['action']['method'];
84
+ $blockInstance->$method($block['action']['value']);
85
+ }
86
+ }
87
+ }
88
+
89
+ $this->_beforeToHtml();
90
+
91
+ $totalsXml = $orderXmlObj->addChild('totals');
92
+ foreach ($this->getTotals() as $total) {
93
+ if ($total->getValue()) {
94
+ $total->setValue(strip_tags($total->getValue()));
95
+ }
96
+ if ($total->getBlockName()) {
97
+ $block = $this->getLayout()->getBlock($total->getBlockName());
98
+ if (is_object($block)) {
99
+ if (method_exists($block, 'addToXmlObject')) {
100
+ $block->setTotal($total)->addToXmlObject($totalsXml);
101
+ } else {
102
+ $this->_addTotalToXml($total, $totalsXml);
103
+ }
104
+ }
105
+ } else {
106
+ $this->_addTotalToXml($total, $totalsXml);
107
+ }
108
+ }
109
+ }
110
+
111
+ /**
112
+ * Add total to totals XML
113
+ *
114
+ * @param Varien_Object $total
115
+ * @param Mage_XmlConnect_Model_Simplexml_Element $totalsXml
116
+ * @return void
117
+ */
118
+ private function _addTotalToXml($total, Mage_XmlConnect_Model_Simplexml_Element $totalsXml)
119
+ {
120
+ if (
121
+ $total instanceof Varien_Object
122
+ && $total->getCode()
123
+ && $total->getLabel()
124
+ && $total->hasData('value')
125
+ ) {
126
+ $totalsXml->addCustomChild(
127
+ preg_replace('@[\W]+@', '_', trim($total->getCode())),
128
+ $this->_formatPrice($total),
129
+ array('label' => strip_tags($total->getLabel()))
130
+ );
131
+ }
132
+ }
133
+
134
+ /**
135
+ * Format price using order currency
136
+ *
137
+ * @param Varien_Object $total
138
+ * @return string
139
+ */
140
+ protected function _formatPrice($total)
141
+ {
142
+ if (!$total->getIsFormated()) {
143
+ return Mage::helper('xmlconnect/customer_order')->formatPrice($this, $total->getValue());
144
+ }
145
+ return $total->getValue();
146
+ }
147
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals/Customerbalance.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer order Customer balance totals xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Order_Totals_Customerbalance
35
+ extends Enterprise_CustomerBalance_Block_Sales_Order_Customerbalance
36
+ {
37
+ /**
38
+ * Add order total rendered to XML object
39
+ * (get from template: )
40
+ *
41
+ * @param $totalsXml Mage_XmlConnect_Model_Simplexml_Element
42
+ * @return void
43
+ */
44
+ public function addToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $totalsXml)
45
+ {
46
+ $balance = $this->getSource()->getCustomerBalanceAmount();
47
+ if ($balance) {
48
+ $totalsXml->addCustomChild(
49
+ $this->getTotal()->getCode(),
50
+ '-' . $this->_formatPrice($balance),
51
+ array('label' => Mage::helper('enterprise_giftcardaccount')->__('Store Credit'))
52
+ );
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Format price using order currency
58
+ *
59
+ * @param float $amount
60
+ * @return string
61
+ */
62
+ protected function _formatPrice($amount)
63
+ {
64
+ return Mage::helper('xmlconnect/customer_order')->formatPrice($this, $amount);
65
+ }
66
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals/Customerbalance/Refunded.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer order Customer balance totals xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Order_Totals_Customerbalance_Refunded
35
+ extends Enterprise_CustomerBalance_Block_Sales_Order_Customerbalance
36
+ {
37
+ /**
38
+ * Add order total rendered to XML object
39
+ * (get from template: )
40
+ *
41
+ * @param $totalsXml Mage_XmlConnect_Model_Simplexml_Element
42
+ * @return void
43
+ */
44
+ public function addToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $totalsXml)
45
+ {
46
+ $balance = $this->getSource()->getCustomerBalanceTotalRefunded();
47
+ if ($balance) {
48
+ $totalsXml->addCustomChild(
49
+ $this->getTotal()->getCode(),
50
+ $this->_formatPrice($balance),
51
+ array('label' => Mage::helper('enterprise_giftcardaccount')->__('Refunded to Store Credit'))
52
+ );
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Format price using order currency
58
+ *
59
+ * @param float $amount
60
+ * @return string
61
+ */
62
+ protected function _formatPrice($amount)
63
+ {
64
+ return Mage::helper('xmlconnect/customer_order')->formatPrice($this, $amount);
65
+ }
66
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals/Giftcards.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer order Customer balance totals xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Order_Totals_Giftcards
35
+ extends Enterprise_GiftCardAccount_Block_Sales_Order_Giftcards
36
+ {
37
+ /**
38
+ * Add order total rendered to XML object
39
+ * (get from template: )
40
+ *
41
+ * @param $totalsXml Mage_XmlConnect_Model_Simplexml_Element
42
+ * @return void
43
+ */
44
+ public function addToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $totalsXml)
45
+ {
46
+ $cards = $this->getGiftCards();
47
+ if ($cards) {
48
+ foreach ($cards as $card) {
49
+ $label = Mage::helper('enterprise_giftcardaccount')->__('Gift Card (%s)', $card->getCode());
50
+ $totalsXml->addCustomChild(
51
+ $this->getTotal()->getCode(),
52
+ '-' . $this->_formatPrice($card->getAmount()),
53
+ array('label' => $label)
54
+ );
55
+ }
56
+ } else {
57
+ $cardsAmount = $this->getSource()->getGiftCardsAmount();
58
+ if ($cardsAmount > 0) {
59
+ $totalsXml->addCustomChild(
60
+ $this->getTotal()->getCode(),
61
+ '-' . $this->_formatPrice($cardsAmount),
62
+ array('label' => Mage::helper('enterprise_giftcardaccount')->__('Gift Card'))
63
+ );
64
+ }
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Format price using order currency
70
+ *
71
+ * @param float $amount
72
+ * @return string
73
+ */
74
+ protected function _formatPrice($amount)
75
+ {
76
+ return Mage::helper('xmlconnect/customer_order')->formatPrice($this, $amount);
77
+ }
78
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals/Tax.php ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer order taxes xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Order_Totals_Tax extends Mage_Tax_Block_Sales_Order_Tax
35
+ {
36
+ /**
37
+ * Add order taxes rendered to XML object
38
+ * (get from template: )
39
+ *
40
+ * @param Mage_XmlConnect_Model_Simplexml_Element $totalsXmlObj
41
+ * @return void
42
+ */
43
+ public function addToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $totalsXmlObj)
44
+ {
45
+ /** @var $taxesXmlObj Mage_XmlConnect_Model_Simplexml_Element */
46
+ $taxesXmlObj = $totalsXmlObj->addChild('tax');
47
+
48
+ $fullInfo = $this->getOrder()->getFullTaxInfo();
49
+
50
+ if ($this->displayFullSummary() && !empty($fullInfo)) {
51
+ foreach ((array)$fullInfo as $info) {
52
+ if (isset($info['hidden']) && $info['hidden']) {
53
+ continue;
54
+ }
55
+
56
+ foreach ((array)$info['rates'] as $rate) {
57
+ if (isset($info['amount'])) {
58
+ $config = array(
59
+ 'label' => $rate['title']
60
+ );
61
+ if (!is_null($rate['percent'])) {
62
+ $config['percent'] = sprintf('(%0.2f%%)', $rate['percent']);
63
+ }
64
+ $taxesXmlObj->addCustomChild(
65
+ 'item',
66
+ is_null($rate['percent']) ? '' : $this->_formatPrice($info['amount']),
67
+ $config
68
+ );
69
+ }
70
+ }
71
+ }
72
+ }
73
+
74
+ $taxesXmlObj->addCustomChild(
75
+ 'summary',
76
+ $this->_formatPrice($this->getSource()->getTaxAmount()),
77
+ array(
78
+ 'label' => $this->__('Tax')
79
+ )
80
+ );
81
+ }
82
+
83
+ /**
84
+ * Format price using order currency
85
+ *
86
+ * @param float $amount
87
+ * @return string
88
+ */
89
+ protected function _formatPrice($amount)
90
+ {
91
+ return Mage::helper('xmlconnect/customer_order')->formatPrice($this, $amount);
92
+ }
93
+ }
app/code/core/Mage/XmlConnect/Block/Customer/Storecredit.php ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Store Credits xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Customer_Storecredit extends Mage_Core_Block_Template
35
+ {
36
+ /**
37
+ * Render customer store credits xml
38
+ *
39
+ * @return string
40
+ */
41
+ protected function _toHtml()
42
+ {
43
+ /** @var $xmlModel Mage_XmlConnect_Model_Simplexml_Element */
44
+ $xmlModel = Mage::getModel(
45
+ 'xmlconnect/simplexml_element',
46
+ '<store_credits_info></store_credits_info>'
47
+ );
48
+
49
+ $accountBalance = $this->getLayout()
50
+ ->addBlock('enterprise_customerbalance/account_balance', 'account_balance');
51
+
52
+ $customerBalanceHelper = Mage::helper('enterprise_customerbalance');
53
+
54
+ $xmlModel->addCustomChild(
55
+ 'balance',
56
+ null,
57
+ array(
58
+ 'label' => $customerBalanceHelper->__('Your current balance is:'),
59
+ 'value' => $accountBalance->getBalance(),
60
+ 'formatted_value' => Mage::helper('core')->currency($accountBalance->getBalance(), true, false)
61
+ )
62
+ );
63
+
64
+ $accountHistory = $this->getLayout()
65
+ ->addBlock('enterprise_customerbalance/account_history', 'account_history');
66
+
67
+ if ($accountHistory->canShow()
68
+ && $accountHistory->getEvents()
69
+ && count($accountHistory->getEvents())
70
+ ) {
71
+ $balanceHistory = $xmlModel->addCustomChild(
72
+ 'balance_history',
73
+ null,
74
+ array(
75
+ 'label' => $customerBalanceHelper->__('Balance History'),
76
+ 'action_label' => $customerBalanceHelper->__('Action'),
77
+ 'balance_change_label' => $customerBalanceHelper->__('Balance Change'),
78
+ 'balance_label' => $customerBalanceHelper->__('Balance'),
79
+ 'date_label' => $customerBalanceHelper->__('Date')
80
+ )
81
+ );
82
+
83
+ foreach ($accountHistory->getEvents() as $event) {
84
+ $item = $balanceHistory->addCustomChild('item');
85
+ $item->addCustomChild(
86
+ 'action',
87
+ null,
88
+ array(
89
+ 'value' => $accountHistory->getActionLabel($event->getAction())
90
+ )
91
+ );
92
+
93
+ $item->addCustomChild(
94
+ 'balance_change',
95
+ null,
96
+ array(
97
+ 'value' => Mage::helper('core')->currency($event->getBalanceDelta(), true, false)
98
+ )
99
+ );
100
+
101
+ $item->addCustomChild(
102
+ 'balance',
103
+ null,
104
+ array(
105
+ 'value' => Mage::helper('core')->currency($event->getBalanceAmount(), true, false)
106
+ )
107
+ );
108
+
109
+ $item->addCustomChild(
110
+ 'date',
111
+ null,
112
+ array(
113
+ 'value' => Mage::helper('core')->formatDate($event->getUpdatedAt(), 'short', true)
114
+ )
115
+ );
116
+ }
117
+ }
118
+
119
+ return $xmlModel->asNiceXml();
120
+ }
121
+ }
app/code/core/Mage/XmlConnect/Block/Home.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Home categories list renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Home extends Mage_XmlConnect_Block_Catalog
35
+ {
36
+ /**
37
+ * Category list limitation
38
+ */
39
+ const HOME_PAGE_CATEGORIES_COUNT = 6;
40
+
41
+ /**
42
+ * Render home category list xml
43
+ *
44
+ * @return string
45
+ */
46
+ protected function _toHtml()
47
+ {
48
+ /** @var $homeXmlObj Mage_XmlConnect_Model_Simplexml_Element */
49
+ $homeXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<home></home>');
50
+
51
+ $categoryCollection = array();
52
+ $helper = Mage::helper('catalog/category');
53
+ $categoryCount = 0;
54
+ foreach ($helper->getStoreCategories() as $child) {
55
+ if ($child->getIsActive()) {
56
+ $categoryCollection[] = $child;
57
+ $categoryCount++;
58
+ }
59
+ if ($categoryCount == self::HOME_PAGE_CATEGORIES_COUNT) {
60
+ break;
61
+ }
62
+ }
63
+
64
+ if (sizeof($categoryCollection)) {
65
+ $itemsXmlObj = $homeXmlObj->addChild('categories');
66
+ }
67
+
68
+ foreach ($categoryCollection as $item) {
69
+ /** @var $item Mage_Catalog_Model_Category */
70
+ $item = Mage::getModel('catalog/category')->load($item->getId());
71
+ $itemXmlObj = $itemsXmlObj->addChild('item');
72
+ $itemXmlObj->addChild('label', $homeXmlObj->escapeXml($item->getName()));
73
+ $itemXmlObj->addChild('entity_id', $item->getId());
74
+ $itemXmlObj->addChild('content_type', $item->hasChildren() ? 'categories' : 'products');
75
+ $icon = Mage::helper('xmlconnect/catalog_category_image')->initialize($item, 'thumbnail')
76
+ ->resize(Mage::helper('xmlconnect/image')->getImageSizeForContent('category'));
77
+
78
+ $iconXml = $itemXmlObj->addChild('icon', $icon);
79
+
80
+ $file = Mage::helper('xmlconnect')->urlToPath($icon);
81
+
82
+ $iconXml->addAttribute('modification_time', filemtime($file));
83
+ }
84
+ $homeXmlObj->addChild('home_banner', '/current/media/catalog/category/banner_home.png');
85
+
86
+ return $homeXmlObj->asNiceXml();
87
+ }
88
+ }
app/code/core/Mage/XmlConnect/Block/Review/Form.php ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Product review form xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Review_Form extends Mage_Core_Block_Template
35
+ {
36
+ /**
37
+ * Collection of ratings
38
+ *
39
+ * @var array
40
+ */
41
+ protected $_ratings = null;
42
+
43
+ /**
44
+ * Render product review form xml
45
+ *
46
+ * @return string
47
+ */
48
+ protected function _toHtml()
49
+ {
50
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
51
+ /** @var $xmlReview Mage_XmlConnect_Model_Simplexml_Element */
52
+ $xmlReview = Mage::getModel('xmlconnect/simplexml_element', '<form></form>');
53
+ $xmlReview->addAttribute('name', 'review_form');
54
+ $xmlReview->addAttribute('method', 'post');
55
+
56
+ $nickname = '';
57
+ if ($customer->getId()) {
58
+ $nickname = $xmlReview->escapeXml($customer->getFirstname());
59
+ }
60
+
61
+ if ($this->getRatings()) {
62
+ $ratingsFieldset = $xmlReview->addCustomChild('fieldset', null, array(
63
+ 'label' => $this->__('How do you rate this product?')
64
+ ));
65
+
66
+ foreach ($this->getRatings() as $rating) {
67
+ $ratingField = $ratingsFieldset->addField('ratings[' . $rating->getId() . ']', 'radio', array(
68
+ 'label' => $rating->getRatingCode(),
69
+ 'required' => 'true'
70
+ ));
71
+ foreach ($rating->getOptions() as $option) {
72
+ $ratingField->addCustomChild('value', $option->getId());
73
+ }
74
+ }
75
+ }
76
+
77
+ $reviewFieldset = $xmlReview->addCustomChild('fieldset');
78
+ $reviewFieldset->addField('nickname', 'text', array(
79
+ 'label' => $this->__('Nickname'),
80
+ 'required' => 'true',
81
+ 'value' => $nickname
82
+ ));
83
+ $reviewFieldset->addField('title', 'text', array(
84
+ 'label' => $this->__('Summary of Your Review'),
85
+ 'required' => 'true'
86
+ ));
87
+ $reviewFieldset->addField('detail', 'textarea', array(
88
+ 'label' => $this->__('Review'),
89
+ 'required' => 'true'
90
+ ));
91
+
92
+ return $xmlReview->asNiceXml();
93
+ }
94
+
95
+ /**
96
+ * Returns collection of ratings
97
+ *
98
+ * @return array | false
99
+ */
100
+ public function getRatings()
101
+ {
102
+ if (is_null($this->_ratings)) {
103
+ $this->_ratings = Mage::getModel('rating/rating')->getResourceCollection()->addEntityFilter('product')
104
+ ->setPositionOrder()->addRatingPerStoreName(Mage::app()->getStore()->getId())
105
+ ->setStoreFilter(Mage::app()->getStore()->getId())->load()->addOptionToItems();
106
+
107
+ if (!$this->_ratings->getSize()) {
108
+ $this->_ratings = false;
109
+ }
110
+ }
111
+ return $this->_ratings;
112
+ }
113
+ }
app/code/core/Mage/XmlConnect/Block/Wishlist.php ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer wishlist xml renderer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Block_Wishlist extends Mage_Wishlist_Block_Customer_Wishlist
35
+ {
36
+ /**
37
+ * Render customer wishlist xml
38
+ *
39
+ * @return string
40
+ */
41
+ protected function _toHtml()
42
+ {
43
+ /** @var Mage_XmlConnect_Model_Simplexml_Element $wishlistXmlObj */
44
+ $wishlistXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<wishlist></wishlist>');
45
+ /**
46
+ * Apply offset and count
47
+ */
48
+ $request= $this->getRequest();
49
+ $offset = (int)$request->getParam('offset', 0);
50
+ $count = (int)$request->getParam('count', 0);
51
+ $offset = $offset < 0 ? 0 : $offset;
52
+ $count = $count <= 0 ? 1 : $count;
53
+ $hasMoreItems = 0;
54
+ if ($offset + $count < $this->getWishlistItems()->getSize()) {
55
+ $hasMoreItems = 1;
56
+ }
57
+ $this->getWishlistItems()->getSelect()->limit($count, $offset);
58
+
59
+ $wishlistXmlObj->addAttribute('items_count', $this->getWishlistItemsCount());
60
+ $wishlistXmlObj->addAttribute('has_more_items', $hasMoreItems);
61
+
62
+ if ($this->hasWishlistItems()) {
63
+ /**
64
+ * @var Mage_Wishlist_Model_Mysql4_Product_Collection
65
+ */
66
+ foreach ($this->getWishlistItems() as $item) {
67
+ /** @var $item Mage_Wishlist_Model_Item */
68
+ $itemXmlObj = $wishlistXmlObj->addChild('item');
69
+ $itemXmlObj->addChild('item_id', $item->getWishlistItemId());
70
+ $itemXmlObj->addChild('entity_id', $item->getProductId());
71
+ $itemXmlObj->addChild('entity_type_id', $item->getTypeId());
72
+ $itemXmlObj->addChild('name', $wishlistXmlObj->escapeXml($item->getName()));
73
+ $itemXmlObj->addChild('in_stock', (int)$item->getStockItem()->getIsInStock());
74
+ $itemXmlObj->addChild('is_salable', (int)$item->isSalable());
75
+ /**
76
+ * If product type is grouped than it has options as its grouped items
77
+ */
78
+ if ($item->getTypeId() == Mage_Catalog_Model_Product_Type_Grouped::TYPE_CODE
79
+ || $item->getTypeId() == Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE) {
80
+ $item->setHasOptions(true);
81
+ }
82
+ $itemXmlObj->addChild('has_options', (int)$item->getHasOptions());
83
+
84
+ $icon = $this->helper('catalog/image')->init($item, 'small_image')
85
+ ->resize(Mage::helper('xmlconnect/image')->getImageSizeForContent('product_small'));
86
+
87
+ $iconXml = $itemXmlObj->addChild('icon', $icon);
88
+
89
+ $file = Mage::helper('xmlconnect')->urlToPath($icon);
90
+ $iconXml->addAttribute('modification_time', filemtime($file));
91
+
92
+ $description = $wishlistXmlObj->escapeXml($item->getWishlistItemDescription());
93
+ $itemXmlObj->addChild('description', $description);
94
+
95
+ $addedDate = $wishlistXmlObj->escapeXml($this->getFormatedDate($item->getAddedAt()));
96
+ $itemXmlObj->addChild('added_date', $addedDate);
97
+
98
+ if ($this->getChild('product_price')) {
99
+ $this->getChild('product_price')->setProduct($item)->setProductXmlObj($itemXmlObj)
100
+ ->collectProductPrices();
101
+ }
102
+
103
+ if (!$item->getRatingSummary()) {
104
+ Mage::getModel('review/review')
105
+ ->getEntitySummary($item, Mage::app()->getStore()->getId());
106
+ }
107
+ $ratingSummary = (int)$item->getRatingSummary()->getRatingSummary();
108
+ $itemXmlObj->addChild('rating_summary', round($ratingSummary / 10));
109
+ $itemXmlObj->addChild('reviews_count', $item->getRatingSummary()->getReviewsCount());
110
+ }
111
+ }
112
+
113
+ return $wishlistXmlObj->asNiceXml();
114
+ }
115
+ }
app/code/core/Mage/XmlConnect/Controller/Action.php ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect controller abstract
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ abstract class Mage_XmlConnect_Controller_Action extends Mage_Core_Controller_Front_Action
35
+ {
36
+ /**
37
+ * Message status `error`
38
+ */
39
+ const MESSAGE_STATUS_ERROR = 'error';
40
+
41
+ /**
42
+ * Message status `warning`
43
+ */
44
+ const MESSAGE_STATUS_WARNING = 'warning';
45
+
46
+ /**
47
+ * Message status `success`
48
+ */
49
+ const MESSAGE_STATUS_SUCCESS = 'success';
50
+
51
+ /**
52
+ * Message type `alert`
53
+ */
54
+ const MESSAGE_TYPE_ALERT = 'alert';
55
+
56
+ /**
57
+ * Message type `prompt`
58
+ */
59
+ const MESSAGE_TYPE_PROMPT = 'prompt';
60
+
61
+ /**
62
+ * Declare content type header
63
+ * Validate current application
64
+ *
65
+ * @return void
66
+ */
67
+ public function preDispatch()
68
+ {
69
+ parent::preDispatch();
70
+
71
+ $this->getResponse()->setHeader('Content-type', 'text/xml; charset=UTF-8');
72
+ /**
73
+ * Load application by specified code and make sure that application exists
74
+ */
75
+ $cookieName = Mage_XmlConnect_Model_Application::APP_CODE_COOKIE_NAME;
76
+ $appCode = isset($_COOKIE[$cookieName]) ? (string) $_COOKIE[$cookieName] : '';
77
+ $screenSizeCookieName = Mage_XmlConnect_Model_Application::APP_SCREEN_SIZE_NAME;
78
+ $screenSize = isset($_COOKIE[$screenSizeCookieName]) ? (string) $_COOKIE[$screenSizeCookieName] : '';
79
+ if (!$appCode) {
80
+ $this->_message(
81
+ Mage::helper('xmlconnect')->__('Specified invalid app code.'),
82
+ self::MESSAGE_STATUS_ERROR
83
+ );
84
+ $this->setFlag('', self::FLAG_NO_DISPATCH, true);
85
+ return;
86
+ }
87
+ /**
88
+ * Check is website offline
89
+ */
90
+ if ((int)Mage::getStoreConfig('general/restriction/is_active')
91
+ && (int)Mage::getStoreConfig('general/restriction/mode') == 0
92
+ ) {
93
+ $this->_message(
94
+ Mage::helper('xmlconnect')->__('Website is offline.'),
95
+ self::MESSAGE_STATUS_SUCCESS
96
+ );
97
+ $this->setFlag('', self::FLAG_NO_DISPATCH, true);
98
+ return;
99
+ }
100
+ /** @var $appModel Mage_XmlConnect_Model_Application */
101
+ $appModel = Mage::getModel('xmlconnect/application')->loadByCode($appCode);
102
+ $appModel->setScreenSize($screenSize);
103
+ if ($appModel && $appModel->getId()) {
104
+ Mage::app()->setCurrentStore(
105
+ Mage::app()->getStore($appModel->getStoreId())->getCode()
106
+ );
107
+ Mage::getSingleton('core/locale')->emulate($appModel->getStoreId());
108
+ Mage::register('current_app', $appModel);
109
+ } else {
110
+ $this->_message(
111
+ Mage::helper('xmlconnect')->__('Specified invalid app code.'),
112
+ self::MESSAGE_STATUS_ERROR
113
+ );
114
+ $this->setFlag('', self::FLAG_NO_DISPATCH, true);
115
+ return;
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Validate response body
121
+ *
122
+ * @return void
123
+ */
124
+ public function postDispatch()
125
+ {
126
+ parent::postDispatch();
127
+ $body = $this->getResponse()->getBody();
128
+ if (empty($body)) {
129
+ $this->_message(
130
+ Mage::helper('xmlconnect')->__('An error occurred while processing your request.'),
131
+ self::MESSAGE_STATUS_ERROR
132
+ );
133
+ }
134
+ }
135
+
136
+ /**
137
+ * Generate message xml and set it to response body
138
+ *
139
+ * @param string $text
140
+ * @param string $status
141
+ * @param array $children
142
+ * @return void
143
+ */
144
+ protected function _message($text, $status, $children = array())
145
+ {
146
+ /** @var $message Mage_XmlConnect_Model_Simplexml_Element */
147
+ $message = Mage::getModel('xmlconnect/simplexml_element', '<message></message>');
148
+ $message->addCustomChild('status', $status);
149
+ $message->addCustomChild('text', $text);
150
+
151
+ foreach ($children as $node => $value) {
152
+ $message->addCustomChild($node, $value);
153
+ }
154
+
155
+ $this->getResponse()->setBody($message->asNiceXml());
156
+ }
157
+ }
app/code/core/Mage/XmlConnect/Helper/Android.php ADDED
@@ -0,0 +1,725 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect device helper for Android
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Helper_Android extends Mage_Core_Helper_Abstract
35
+ {
36
+ /**
37
+ * Submission title length
38
+ */
39
+ const SUBMISSION_TITLE_LENGTH = 30;
40
+
41
+ /**
42
+ * Submission description length
43
+ */
44
+ const SUBMISSION_DESCRIPTION_LENGTH = 4000;
45
+
46
+ /**
47
+ * Android preview banner widht
48
+ */
49
+ const PREVIEW_BANNER_WIDTH = 320;
50
+
51
+ /**
52
+ * Android preview banner image height
53
+ */
54
+ const PREVIEW_BANNER_HEIGHT = 258;
55
+
56
+ /**
57
+ * Tags identifier for title bar
58
+ */
59
+ const TAGS_ID_FOR_TITLE_BAR = 1;
60
+
61
+ /**
62
+ * Tags identifier for options menu
63
+ */
64
+ const TAGS_ID_FOR_OPTION_MENU = 2;
65
+
66
+ /**
67
+ * Country renderer for submission
68
+ */
69
+ const SUBMISSION_COUNTRY_RENDERER = 'androidmarket';
70
+
71
+ /**
72
+ * Country columns for submission
73
+ */
74
+ const SUBMISSION_COUNTRY_COLUMNS = 2;
75
+
76
+ /**
77
+ * Submit images that are stored in "params" field of history table
78
+ *
79
+ * @var array
80
+ */
81
+ protected $_imageIds = array('icon', 'android_loader_image', 'android_logo', 'big_logo');
82
+
83
+ /**
84
+ * Country field renderer
85
+ *
86
+ * @var Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Renderer_Country_Androidmarket
87
+ */
88
+ protected $_countryRenderer = null;
89
+
90
+ /**
91
+ * List of coutries that allowed in Ituens by Apple Store
92
+ *
93
+ * array(
94
+ * 'country name' => 'country id at directory model'
95
+ * )
96
+ *
97
+ * @var array
98
+ */
99
+ protected $_allowedCountries = array(
100
+ 'Argentina' => 'AR',
101
+ 'Australia' => 'AU',
102
+ 'Austria' => 'AT',
103
+ 'Belgium' => 'BE',
104
+ 'Brazil' =>'BR',
105
+ 'Canada' => 'CA',
106
+ 'Denmark' => 'DK',
107
+ 'Finland' => 'FI',
108
+ 'France' => 'FR',
109
+ 'Germany' => 'DE',
110
+ 'Hong Kong SAR China' => 'HK',
111
+ 'Ireland' => 'IE',
112
+ 'Israel' => 'IL',
113
+ 'Italy' => 'IT',
114
+ 'Japan' => 'JP',
115
+ 'Mexico' => 'MX',
116
+ 'Netherlands' => 'NL',
117
+ 'New Zealand' => 'NZ',
118
+ 'Norway' => 'NO',
119
+ 'Portugal' => 'PT',
120
+ 'Russia' => 'RU',
121
+ 'Singapore' => 'SG',
122
+ 'Spain' => 'ES',
123
+ 'South Korea' => 'KR',
124
+ 'Sweden' => 'SE',
125
+ 'Switzerland' => 'CH',
126
+ 'Taiwan' => 'TW',
127
+ 'United Kingdom' => 'GB',
128
+ 'United States' => 'US',
129
+ );
130
+
131
+ /**
132
+ * Get submit images that are required for application submit
133
+ *
134
+ * @return array
135
+ */
136
+ public function getSubmitImages()
137
+ {
138
+ return $this->_imageIds;
139
+ }
140
+
141
+ /**
142
+ * Get default application tabs
143
+ *
144
+ * @return array
145
+ */
146
+ public function getDefaultDesignTabs()
147
+ {
148
+ if (!isset($this->_tabs)) {
149
+ $this->_tabs = array(
150
+ array(
151
+ 'label' => Mage::helper('xmlconnect')->__('Home'),
152
+ 'image' => 'tab_home_android.png',
153
+ 'action' => 'Home',
154
+ 'menu' => self::TAGS_ID_FOR_TITLE_BAR,
155
+ ),
156
+ array(
157
+ 'label' => Mage::helper('xmlconnect')->__('Search'),
158
+ 'image' => 'tab_search_android.png',
159
+ 'action' => 'Search',
160
+ 'menu' => self::TAGS_ID_FOR_TITLE_BAR,
161
+ ),
162
+ array(
163
+ 'label' => Mage::helper('xmlconnect')->__('Account'),
164
+ 'image' => 'tab_account_android.png',
165
+ 'action' => 'Account',
166
+ 'menu' => self::TAGS_ID_FOR_TITLE_BAR,
167
+ ),
168
+ array(
169
+ 'label' => Mage::helper('xmlconnect')->__('Shop'),
170
+ 'image' => 'tab_shop_android.png',
171
+ 'action' => 'Shop',
172
+ 'menu' => self::TAGS_ID_FOR_OPTION_MENU,
173
+ ),
174
+ array(
175
+ 'label' => Mage::helper('xmlconnect')->__('Cart'),
176
+ 'image' => 'tab_cart_android.png',
177
+ 'action' => 'Cart',
178
+ 'menu' => self::TAGS_ID_FOR_OPTION_MENU,
179
+ ),
180
+ array(
181
+ 'label' => Mage::helper('xmlconnect')->__('More Info'),
182
+ 'image' => 'tab_info_android.png',
183
+ 'action' => 'AboutUs',
184
+ 'menu' => self::TAGS_ID_FOR_OPTION_MENU,
185
+ ),
186
+ );
187
+ }
188
+ return $this->_tabs;
189
+ }
190
+
191
+ /**
192
+ * Default application configuration
193
+ *
194
+ * @return array
195
+ */
196
+ public function getDefaultConfiguration()
197
+ {
198
+ return array(
199
+ 'native' => array(
200
+ 'body' => array(
201
+ 'backgroundColor' => '#ABABAB',
202
+ 'scrollBackgroundColor' => '#EDEDED',
203
+ ),
204
+ 'itemActions' => array(
205
+ 'relatedProductBackgroundColor' => '#404040',
206
+ ),
207
+ 'fonts' => array(
208
+ 'Title1' => array(
209
+ 'name' => 'HelveticaNeue-Bold',
210
+ 'size' => '14',
211
+ 'color' => '#FEFEFE',
212
+ ),
213
+ 'Title2' => array(
214
+ 'name' => 'HelveticaNeue-Bold',
215
+ 'size' => '12',
216
+ 'color' => '#222222',
217
+ ),
218
+ 'Title3' => array(
219
+ 'name' => 'HelveticaNeue',
220
+ 'size' => '13',
221
+ 'color' => '#000000',
222
+ ),
223
+ 'Title4' => array(
224
+ 'name' => 'HelveticaNeue',
225
+ 'size' => '12',
226
+ 'color' => '#FFFFFF',
227
+ ),
228
+ 'Title5' => array(
229
+ 'name' => 'HelveticaNeue-Bold',
230
+ 'size' => '13',
231
+ 'color' => '#dc5f02',
232
+ ),
233
+ 'Title6' => array(
234
+ 'name' => 'HelveticaNeue-Bold',
235
+ 'size' => '16',
236
+ 'color' => '#222222',
237
+ ),
238
+ 'Title7' => array(
239
+ 'name' => 'HelveticaNeue-Bold',
240
+ 'size' => '13',
241
+ 'color' => '#000000',
242
+ ),
243
+ 'Title8' => array(
244
+ 'name' => 'HelveticaNeue-Bold',
245
+ 'size' => '11',
246
+ 'color' => '#FFFFFF',
247
+ ),
248
+ 'Title9' => array(
249
+ 'name' => 'HelveticaNeue-Bold',
250
+ 'size' => '12',
251
+ 'color' => '#FFFFFF',
252
+ ),
253
+ 'Text1' => array(
254
+ 'name' => 'HelveticaNeue-Bold',
255
+ 'size' => '12',
256
+ 'color' => '#777777',
257
+ ),
258
+ 'Text2' => array(
259
+ 'name' => 'HelveticaNeue',
260
+ 'size' => '10',
261
+ 'color' => '#555555',
262
+ ),
263
+ ),
264
+ ),
265
+ );
266
+ }
267
+
268
+ /**
269
+ * List of allowed fonts for Android application
270
+ *
271
+ * @return array
272
+ */
273
+ public function getFontList()
274
+ {
275
+ return array(
276
+ array(
277
+ 'value' => 'HiraKakuProN-W3',
278
+ 'label' => 'HiraKakuProN-W3',
279
+ ),
280
+ array(
281
+ 'value' => 'Courier',
282
+ 'label' => 'Courier',
283
+ ),
284
+ array(
285
+ 'value' => 'Courier-BoldOblique',
286
+ 'label' => 'Courier-BoldOblique',
287
+ ),
288
+ array(
289
+ 'value' => 'Courier-Oblique',
290
+ 'label' => 'Courier-Oblique',
291
+ ),
292
+ array(
293
+ 'value' => 'Courier-Bold',
294
+ 'label' => 'Courier-Bold',
295
+ ),
296
+ array(
297
+ 'value' => 'ArialMT',
298
+ 'label' => 'ArialMT',
299
+ ),
300
+ array(
301
+ 'value' => 'Arial-BoldMT',
302
+ 'label' => 'Arial-BoldMT',
303
+ ),
304
+ array(
305
+ 'value' => 'Arial-BoldItalicMT',
306
+ 'label' => 'Arial-BoldItalicMT',
307
+ ),
308
+ array(
309
+ 'value' => 'Arial-ItalicMT',
310
+ 'label' => 'Arial-ItalicMT',
311
+ ),
312
+ array(
313
+ 'value' => 'STHeitiTC-Light',
314
+ 'label' => 'STHeitiTC-Light',
315
+ ),
316
+ array(
317
+ 'value' => 'STHeitiTC-Medium',
318
+ 'label' => 'STHeitiTC-Medium',
319
+ ),
320
+ array(
321
+ 'value' => 'AppleGothic',
322
+ 'label' => 'AppleGothic',
323
+ ),
324
+ array(
325
+ 'value' => 'CourierNewPS-BoldMT',
326
+ 'label' => 'CourierNewPS-BoldMT',
327
+ ),
328
+ array(
329
+ 'value' => 'CourierNewPS-ItalicMT',
330
+ 'label' => 'CourierNewPS-ItalicMT',
331
+ ),
332
+ array(
333
+ 'value' => 'CourierNewPS-BoldItalicMT',
334
+ 'label' => 'CourierNewPS-BoldItalicMT',
335
+ ),
336
+ array(
337
+ 'value' => 'CourierNewPSMT',
338
+ 'label' => 'CourierNewPSMT',
339
+ ),
340
+ array(
341
+ 'value' => 'Zapfino',
342
+ 'label' => 'Zapfino',
343
+ ),
344
+ array(
345
+ 'value' => 'HiraKakuProN-W6',
346
+ 'label' => 'HiraKakuProN-W6',
347
+ ),
348
+ array(
349
+ 'value' => 'ArialUnicodeMS',
350
+ 'label' => 'ArialUnicodeMS',
351
+ ),
352
+ array(
353
+ 'value' => 'STHeitiSC-Medium',
354
+ 'label' => 'STHeitiSC-Medium',
355
+ ),
356
+ array(
357
+ 'value' => 'STHeitiSC-Light',
358
+ 'label' => 'STHeitiSC-Light',
359
+ ),
360
+ array(
361
+ 'value' => 'AmericanTypewriter',
362
+ 'label' => 'AmericanTypewriter',
363
+ ),
364
+ array(
365
+ 'value' => 'AmericanTypewriter-Bold',
366
+ 'label' => 'AmericanTypewriter-Bold',
367
+ ),
368
+ array(
369
+ 'value' => 'Helvetica-Oblique',
370
+ 'label' => 'Helvetica-Oblique',
371
+ ),
372
+ array(
373
+ 'value' => 'Helvetica-BoldOblique',
374
+ 'label' => 'Helvetica-BoldOblique',
375
+ ),
376
+ array(
377
+ 'value' => 'Helvetica',
378
+ 'label' => 'Helvetica',
379
+ ),
380
+ array(
381
+ 'value' => 'Helvetica-Bold',
382
+ 'label' => 'Helvetica-Bold',
383
+ ),
384
+ array(
385
+ 'value' => 'MarkerFelt-Thin',
386
+ 'label' => 'MarkerFelt-Thin',
387
+ ),
388
+ array(
389
+ 'value' => 'HelveticaNeue',
390
+ 'label' => 'HelveticaNeue',
391
+ ),
392
+ array(
393
+ 'value' => 'HelveticaNeue-Bold',
394
+ 'label' => 'HelveticaNeue-Bold',
395
+ ),
396
+ array(
397
+ 'value' => 'DBLCDTempBlack',
398
+ 'label' => 'DBLCDTempBlack',
399
+ ),
400
+ array(
401
+ 'value' => 'Verdana-Bold',
402
+ 'label' => 'Verdana-Bold',
403
+ ),
404
+ array(
405
+ 'value' => 'Verdana-BoldItalic',
406
+ 'label' => 'Verdana-BoldItalic',
407
+ ),
408
+ array(
409
+ 'value' => 'Verdana',
410
+ 'label' => 'Verdana',
411
+ ),
412
+ array(
413
+ 'value' => 'Verdana-Italic',
414
+ 'label' => 'Verdana-Italic',
415
+ ),
416
+ array(
417
+ 'value' => 'TimesNewRomanPSMT',
418
+ 'label' => 'TimesNewRomanPSMT',
419
+ ),
420
+ array(
421
+ 'value' => 'TimesNewRomanPS-BoldMT',
422
+ 'label' => 'TimesNewRomanPS-BoldMT',
423
+ ),
424
+ array(
425
+ 'value' => 'TimesNewRomanPS-BoldItalicMT',
426
+ 'label' => 'TimesNewRomanPS-BoldItalicMT',
427
+ ),
428
+ array(
429
+ 'value' => 'TimesNewRomanPS-ItalicMT',
430
+ 'label' => 'TimesNewRomanPS-ItalicMT',
431
+ ),
432
+ array(
433
+ 'value' => 'Georgia-Bold',
434
+ 'label' => 'Georgia-Bold',
435
+ ),
436
+ array(
437
+ 'value' => 'Georgia',
438
+ 'label' => 'Georgia',
439
+ ),
440
+ array(
441
+ 'value' => 'Georgia-BoldItalic',
442
+ 'label' => 'Georgia-BoldItalic',
443
+ ),
444
+ array(
445
+ 'value' => 'Georgia-Italic',
446
+ 'label' => 'Georgia-Italic',
447
+ ),
448
+ array(
449
+ 'value' => 'STHeitiJ-Medium',
450
+ 'label' => 'STHeitiJ-Medium',
451
+ ),
452
+ array(
453
+ 'value' => 'STHeitiJ-Light',
454
+ 'label' => 'STHeitiJ-Light',
455
+ ),
456
+ array(
457
+ 'value' => 'ArialRoundedMTBold',
458
+ 'label' => 'ArialRoundedMTBold',
459
+ ),
460
+ array(
461
+ 'value' => 'TrebuchetMS-Italic',
462
+ 'label' => 'TrebuchetMS-Italic',
463
+ ),
464
+ array(
465
+ 'value' => 'TrebuchetMS',
466
+ 'label' => 'TrebuchetMS',
467
+ ),
468
+ array(
469
+ 'value' => 'Trebuchet-BoldItalic',
470
+ 'label' => 'Trebuchet-BoldItalic',
471
+ ),
472
+ array(
473
+ 'value' => 'TrebuchetMS-Bold',
474
+ 'label' => 'TrebuchetMS-Bold',
475
+ ),
476
+ array(
477
+ 'value' => 'STHeitiK-Medium',
478
+ 'label' => 'STHeitiK-Medium',
479
+ ),
480
+ array(
481
+ 'value' => 'STHeitiK-Light',
482
+ 'label' => 'STHeitiK-Light',
483
+ ),
484
+ );
485
+ }
486
+
487
+ /**
488
+ * List of allowed font sizes for Android application
489
+ *
490
+ * @return array
491
+ */
492
+ public function getFontSizes()
493
+ {
494
+ $result = array();
495
+ for ($i = 6; $i < 32; $i++) {
496
+ $result[] = array(
497
+ 'value' => $i,
498
+ 'label' => $i . ' pt',
499
+ );
500
+ }
501
+ return $result;
502
+ }
503
+
504
+ /**
505
+ * Validate submit application data
506
+ *
507
+ * @param array $params
508
+ * @return array
509
+ */
510
+ public function validateSubmit($params)
511
+ {
512
+ $errors = array();
513
+
514
+ if (!Zend_Validate::is(isset($params['title']) ? $params['title'] : null, 'NotEmpty')) {
515
+ $errors[] = Mage::helper('xmlconnect')->__('Please enter the Title.');
516
+ }
517
+
518
+ if (isset($params['title'])) {
519
+ $titleLength = self::SUBMISSION_TITLE_LENGTH;
520
+ $strRules = array('min' => '1', 'max' => $titleLength);
521
+ if (!Zend_Validate::is($params['title'], 'StringLength', $strRules)) {
522
+ $errors[] = Mage::helper('xmlconnect')->__('"Title" is more than %d characters long', $strRules['max']);
523
+ }
524
+ }
525
+
526
+ if (!Zend_Validate::is(isset($params['description']) ? $params['description'] : null, 'NotEmpty')) {
527
+ $errors[] = Mage::helper('xmlconnect')->__('Please enter the Description.');
528
+ }
529
+
530
+ if (isset($params['description'])) {
531
+ $descriptionLength = self::SUBMISSION_DESCRIPTION_LENGTH;
532
+ $strRules = array('min' => '1', 'max' => $descriptionLength);
533
+ if (!Zend_Validate::is($params['title'], 'StringLength', $strRules)) {
534
+ $errors[] = Mage::helper('xmlconnect')->__('"Description" is more than %d characters long', $strRules['max']);
535
+ }
536
+ }
537
+
538
+ if (!Zend_Validate::is(isset($params['copyright']) ? $params['copyright'] : null, 'NotEmpty')) {
539
+ $errors[] = Mage::helper('xmlconnect')->__('Please enter the Copyright.');
540
+ }
541
+
542
+ if (empty($params['price_free'])) {
543
+ if (!Zend_Validate::is(isset($params['price']) ? $params['price'] : null, 'NotEmpty')) {
544
+ $errors[] = Mage::helper('xmlconnect')->__('Please enter the Price.');
545
+ }
546
+ }
547
+
548
+ if (!Zend_Validate::is(isset($params['country']) ? $params['country'] : null, 'NotEmpty')) {
549
+ $errors[] = Mage::helper('xmlconnect')->__('Please select at least one country.');
550
+ }
551
+
552
+ $keyLenght = Mage_XmlConnect_Model_Application::APP_MAX_KEY_LENGTH;
553
+ if (Mage::helper('xmlconnect')->getApplication()->getIsResubmitAction()) {
554
+ if (isset($params['resubmission_activation_key'])) {
555
+ $resubmissionKey = $params['resubmission_activation_key'];
556
+ } else {
557
+ $resubmissionKey = null;
558
+ }
559
+
560
+ if (!Zend_Validate::is($resubmissionKey, 'NotEmpty')) {
561
+ $errors[] = Mage::helper('xmlconnect')->__('Please enter the Resubmission Key.');
562
+ } elseif (!Zend_Validate::is($resubmissionKey, 'StringLength', array(1, $keyLenght))) {
563
+ $errors[] = Mage::helper('xmlconnect')->__('Submit App failure. Invalid activation key provided');
564
+ }
565
+ } else {
566
+ $key = isset($params['key']) ? $params['key'] : null;
567
+ if (!Zend_Validate::is($key, 'NotEmpty')) {
568
+ $errors[] = Mage::helper('xmlconnect')->__('Please enter the Activation Key.');
569
+ } elseif (!Zend_Validate::is($key, 'StringLength', array(1, $keyLenght))) {
570
+ $errors[] = Mage::helper('xmlconnect')->__('Submit App failure. Invalid activation key provided');
571
+ }
572
+ }
573
+ return $errors;
574
+ }
575
+
576
+ /**
577
+ * Check config for valid values
578
+ *
579
+ * @param array $native
580
+ * @return array
581
+ */
582
+ public function validateConfig($native)
583
+ {
584
+ $errors = array();
585
+ if ($native === false
586
+ || !isset($native['navigationBar']['icon'])
587
+ || !Zend_Validate::is($native['navigationBar']['icon'], 'NotEmpty')
588
+ ) {
589
+ $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "Logo in Header" field from Design Tab.');
590
+ }
591
+
592
+ if (!Mage::helper('xmlconnect')->validateConfFieldNotEmpty('bannerAndroidImage', $native)) {
593
+ $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "Banner on Home Screen" field from Design Tab.');
594
+ }
595
+
596
+ return $errors;
597
+ }
598
+
599
+ /**
600
+ * Get renderer for submission country
601
+ *
602
+ * @return Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Renderer_Country_Androidmarket
603
+ */
604
+ public function getCountryRenderer()
605
+ {
606
+ if (empty($this->_countryRenderer)) {
607
+ $renderer = 'xmlconnect/adminhtml_mobile_submission_renderer_country_'
608
+ . self::SUBMISSION_COUNTRY_RENDERER;
609
+ $this->_countryRenderer = Mage::app()->getLayout()->createBlock($renderer);
610
+ }
611
+ return $this->_countryRenderer;
612
+ }
613
+
614
+ /**
615
+ * Get label for submission country
616
+ *
617
+ * @return string
618
+ */
619
+ public function getCountryLabel()
620
+ {
621
+ return Mage::helper('xmlconnect')->__('Locations');
622
+ }
623
+
624
+ /**
625
+ * Get columns for submission country
626
+ *
627
+ * @return int
628
+ */
629
+ public function getCountryColumns()
630
+ {
631
+ return self::SUBMISSION_COUNTRY_COLUMNS;
632
+ }
633
+
634
+ /**
635
+ * Get placement of Country Names for submission country
636
+ *
637
+ * @return bool
638
+ */
639
+ public function isCountryNamePlaceLeft()
640
+ {
641
+ return false;
642
+ }
643
+
644
+ /**
645
+ * Get class name for submission country
646
+ *
647
+ * @return string
648
+ */
649
+ public function getCountryClass()
650
+ {
651
+ return self::SUBMISSION_COUNTRY_RENDERER;
652
+ }
653
+
654
+ /**
655
+ * Get list of countries that allowed by Magento Inc. for Android
656
+ *
657
+ * @return array
658
+ */
659
+ public function getAndroidMarketCountriesArray()
660
+ {
661
+ return $this->_allowedCountries;
662
+ }
663
+
664
+ /**
665
+ * Check image fields
666
+ *
667
+ * We set empty value for image field if file was missed in some reason
668
+ *
669
+ * @param array $data
670
+ * @return array
671
+ */
672
+ public function checkImages(array $data)
673
+ {
674
+ /** @var $helper Mage_XmlConnect_Helper_Image */
675
+ $helper = Mage::helper('xmlconnect/image');
676
+
677
+ $icon =& $data['conf']['native']['navigationBar']['icon'];
678
+
679
+ if (!empty($icon) && !$helper->checkAndGetImagePath($icon)) {
680
+ $icon = '';
681
+ }
682
+
683
+ $banner =& $data['conf']['native']['body']['bannerAndroidImage'];
684
+ if (!empty($banner) && !$helper->checkAndGetImagePath($banner)) {
685
+ $banner = '';
686
+ }
687
+ return $data;
688
+ }
689
+
690
+ /**
691
+ * Check required fields of a config for a front-end
692
+ *
693
+ * @throws Mage_Core_Exception
694
+ * @param array $data
695
+ * @return void
696
+ */
697
+ public function checkRequiredConfigFields($data)
698
+ {
699
+ if (!is_array($data)) {
700
+ return;
701
+ }
702
+
703
+ if (isset($data['navigationBar']['icon']) && empty($data['navigationBar']['icon'])) {
704
+ Mage::throwException(
705
+ Mage::helper('xmlconnect')->__('Logo in Header image missing.')
706
+ );
707
+ }
708
+
709
+ if (isset($data['body']['bannerAndroidImage']) && empty($data['body']['bannerAndroidImage'])) {
710
+ Mage::throwException(
711
+ Mage::helper('xmlconnect')->__('Banner on Home Screen image missing.')
712
+ );
713
+ }
714
+ }
715
+
716
+ /**
717
+ * Check the notifications are allowed for current type of application
718
+ *
719
+ * @return bool
720
+ */
721
+ public function isNotificationsAllowed()
722
+ {
723
+ return true;
724
+ }
725
+ }
app/code/core/Mage/XmlConnect/Helper/Catalog/Category/Image.php ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Catalog image helper
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Helper_Catalog_Category_Image extends Mage_Catalog_Helper_Image
35
+ {
36
+ /**
37
+ * Init
38
+ *
39
+ * @param Mage_Catalog_Model_Product $product
40
+ * @param string $attributeName
41
+ * @param string $imageFile
42
+ * @return Mage_XmlConnect_Helper_Catalog_Category_Image
43
+ */
44
+ public function init(Mage_Catalog_Model_Product $product, $attributeName, $imageFile = null)
45
+ {
46
+ return $this;
47
+ }
48
+
49
+ /**
50
+ * Init image helper object
51
+ *
52
+ * @param Mage_Catalog_Model_Abstract $category
53
+ * @param string $attributeName
54
+ * @param string $imageFile
55
+ * @return Mage_XmlConnect_Helper_Catalog_Category_Image
56
+ */
57
+ public function initialize(Mage_Catalog_Model_Abstract $category, $attributeName, $imageFile = null)
58
+ {
59
+ $this->_reset();
60
+ $this->_setModel(Mage::getModel('xmlconnect/catalog_category_image'));
61
+ $this->_getModel()->setDestinationSubdir($attributeName);
62
+ $this->setProduct($category);
63
+
64
+ $this->setWatermark(
65
+ Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_image")
66
+ );
67
+ $this->setWatermarkImageOpacity(
68
+ Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_imageOpacity")
69
+ );
70
+ $this->setWatermarkPosition(
71
+ Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_position")
72
+ );
73
+ $this->setWatermarkSize(
74
+ Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_size")
75
+ );
76
+
77
+ if ($imageFile) {
78
+ $this->setImageFile($imageFile);
79
+ } else {
80
+ /*
81
+ * add for work original size
82
+ */
83
+ $this->_getModel()->setBaseFile(
84
+ $this->getProduct()->getData($this->_getModel()->getDestinationSubdir())
85
+ );
86
+ }
87
+ return $this;
88
+ }
89
+
90
+ /**
91
+ * Return placeholder image file path
92
+ *
93
+ * @return string
94
+ */
95
+ public function getPlaceholder()
96
+ {
97
+ if (!$this->_placeholder) {
98
+ $attr = $this->_getModel()->getDestinationSubdir();
99
+ $this->_placeholder = 'images/xmlconnect/catalog/category/placeholder/' . $attr . '.jpg';
100
+ }
101
+ return $this->_placeholder;
102
+ }
103
+ }
app/code/core/Mage/XmlConnect/Helper/Customer/Form/Renderer.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer form renderer helper
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Helper_Customer_Form_Renderer extends Mage_Core_Helper_Abstract
35
+ {
36
+ /**
37
+ * Get title and required attributes for a field
38
+ *
39
+ * @param Mage_XmlConnect_Model_Simplexml_Form_Abstract $fieldsetXmlObj
40
+ * @param Enterprise_Eav_Block_Form_Renderer_Abstract $blockObject
41
+ * @return array
42
+ */
43
+ public function addTitleAndRequiredAttr(
44
+ Mage_XmlConnect_Model_Simplexml_Form_Abstract $fieldsetXmlObj,
45
+ Enterprise_Eav_Block_Form_Renderer_Abstract $blockObject
46
+ ) {
47
+ $attributes = array();
48
+
49
+ if ($blockObject->isRequired()) {
50
+ $attributes += $fieldsetXmlObj->checkAttribute('required', (int)$blockObject->isRequired());
51
+ }
52
+
53
+ if ($blockObject->getAdditionalDescription()) {
54
+ $attributes += $fieldsetXmlObj->checkAttribute('title', $blockObject->getAdditionalDescription());
55
+ }
56
+
57
+ return $attributes;
58
+ }
59
+ }
app/code/core/Mage/XmlConnect/Helper/Customer/Order.php ADDED
@@ -0,0 +1,304 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer order details helper
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Helper_Customer_Order extends Mage_Core_Helper_Abstract
35
+ {
36
+ /**
37
+ * Add Weee taxes child to the XML
38
+ *
39
+ * @param Mage_Core_Block_Template $renderer Product renderer
40
+ * @param Mage_Sales_Model_Order_Item $item
41
+ * @param Mage_XmlConnect_Model_Simplexml_Element $priceXml
42
+ * @param Mage_XmlConnect_Model_Simplexml_Element $subtotalXml
43
+ * @param bool $isIncludeTax
44
+ * @return void
45
+ */
46
+ public function addPriceAndSubtotalToXml(
47
+ Mage_Core_Block_Template $renderer,
48
+ Mage_Sales_Model_Order_Item $item,
49
+ Mage_XmlConnect_Model_Simplexml_Element $priceXml,
50
+ Mage_XmlConnect_Model_Simplexml_Element $subtotalXml,
51
+ $isIncludeTax = false
52
+ )
53
+ {
54
+ $weeeParams = array();
55
+
56
+ $typesOfDisplay = $renderer->getTypesOfDisplay();
57
+ if ($isIncludeTax) {
58
+ $nodeName = 'including_tax';
59
+ $nodeLabel = $renderer->__('Incl. Tax');
60
+
61
+ $inclPrice = $renderer->helper('checkout')->getPriceInclTax($item);
62
+ $inclSubtotal = $renderer->helper('checkout')->getSubtotalInclTax($item);
63
+
64
+ if ($typesOfDisplay[14]) {
65
+ $price = $inclPrice + $renderer->getWeeeTaxAppliedAmount();
66
+ $subtotal = $inclSubtotal + $item->getWeeeTaxAppliedRowAmount();
67
+ } else {
68
+ $price = $inclPrice - $renderer->getWeeeTaxDisposition();
69
+ $subtotal = $inclSubtotal - $item->getWeeeTaxRowDisposition();
70
+ }
71
+ $weeeParams['include'] = $inclPrice;
72
+ } else {
73
+ $nodeName = 'excluding_tax';
74
+ $nodeLabel = $renderer->__('Excl. Tax');
75
+
76
+ if ($typesOfDisplay[14]) {
77
+ $price = $item->getPrice()
78
+ + $renderer->getWeeeTaxAppliedAmount()
79
+ + $renderer->getWeeeTaxDisposition();
80
+ $subtotal = $item->getRowTotal()
81
+ + $item->getWeeeTaxAppliedRowAmount()
82
+ + $item->getWeeeTaxRowDisposition();
83
+ } else {
84
+ $price = $item->getPrice();
85
+ $subtotal = $item->getRowTotal();
86
+ }
87
+ }
88
+
89
+ $configNode = array(
90
+ 'value' => $this->formatPrice($renderer, $price)
91
+ );
92
+ if ($renderer->helper('tax')->displaySalesBothPrices()) {
93
+ $configNode['label'] = $nodeLabel;
94
+ }
95
+
96
+ $this->addWeeeTaxesToPriceXml(
97
+ $renderer,
98
+ $item,
99
+ $priceXml->addCustomChild(
100
+ $nodeName,
101
+ null,
102
+ $configNode
103
+ ),
104
+ $weeeParams
105
+ );
106
+
107
+ $configNode['value'] = $this->formatPrice($renderer, $subtotal);
108
+ $weeeParams['include'] = $isIncludeTax ? $inclSubtotal : null;
109
+ $weeeParams['is_subtotal'] = true;
110
+ $this->addWeeeTaxesToPriceXml(
111
+ $renderer,
112
+ $item,
113
+ $subtotalXml->addCustomChild(
114
+ $nodeName,
115
+ null,
116
+ $configNode
117
+ ),
118
+ $weeeParams
119
+ );
120
+ }
121
+
122
+ /**
123
+ * Add Product options to XML
124
+ *
125
+ * @param Mage_Core_Block_Template $renderer Product renderer
126
+ * @param Mage_XmlConnect_Model_Simplexml_Element $itemXml
127
+ * @return void
128
+ */
129
+ public function addItemOptionsToXml(
130
+ Mage_Core_Block_Template $renderer,
131
+ Mage_XmlConnect_Model_Simplexml_Element $itemXml
132
+ )
133
+ {
134
+ $options = $renderer->getItemOptions();
135
+ if (!empty($options)) {
136
+ $optionsXml = $itemXml->addChild('options');
137
+
138
+ foreach ($options as $option) {
139
+ $value = false;
140
+ $formatedOptionValue = $renderer->getFormatedOptionValue($option);
141
+ if (isset($formatedOptionValue['full_view']) && isset($formatedOptionValue['value'])) {
142
+ $value = $formatedOptionValue['value'];
143
+ } elseif (isset($option['print_value'])) {
144
+ $value = $option['print_value'];
145
+ } elseif (isset($option['value'])) {
146
+ $value = $option['value'];
147
+ }
148
+ if ($value) {
149
+ $optionsXml->addCustomChild(
150
+ 'option',
151
+ strip_tags($value),
152
+ array('label' => $option['label'])
153
+ );
154
+ }
155
+ }
156
+ }
157
+ }
158
+
159
+ /**
160
+ * Add Weee taxes child to the XML
161
+ *
162
+ * @param Mage_Core_Block_Template $renderer Product renderer
163
+ * @param Mage_Sales_Model_Order_Item $item
164
+ * @param Mage_XmlConnect_Model_Simplexml_Element $parentXml
165
+ * @param array $params Params for Weee taxes: 'include' - Price including tax, 'is_subtotal' - Flag of subtotal
166
+ * @return void
167
+ */
168
+ public function addWeeeTaxesToPriceXml(
169
+ Mage_Core_Block_Template $renderer,
170
+ Mage_Sales_Model_Order_Item $item,
171
+ Mage_XmlConnect_Model_Simplexml_Element $parentXml,
172
+ $params = array()
173
+ )
174
+ {
175
+ $weeTaxes = $renderer->getWeeeTaxes();
176
+ if (empty($weeTaxes)) {
177
+ return;
178
+ }
179
+
180
+ $typesOfDisplay = $renderer->getTypesOfDisplay();
181
+
182
+ $row = isset($params['is_subtotal']) && $params['is_subtotal'] ? 'row_' : '';
183
+
184
+ /** @var $weeeXml Mage_XmlConnect_Model_Simplexml_Element */
185
+ if ($typesOfDisplay[1]) {
186
+ $weeeXml = $parentXml->addChild('weee');
187
+ foreach ($weeTaxes as $tax) {
188
+ $weeeXml->addCustomChild(
189
+ 'tax',
190
+ $this->formatPrice($renderer, $tax[$row . 'amount']),
191
+ array('label' => $tax['title'])
192
+ );
193
+ }
194
+ } elseif ($typesOfDisplay[2] || $typesOfDisplay[4]) {
195
+ $weeeXml = $parentXml->addChild('weee');
196
+ foreach ($weeTaxes as $tax) {
197
+ $weeeXml->addCustomChild(
198
+ 'tax',
199
+ $this->formatPrice($renderer, $tax[$row . 'amount_incl_tax']),
200
+ array('label' => $tax['title'])
201
+ );
202
+ }
203
+ }
204
+
205
+ if ($typesOfDisplay[2]) {
206
+ if (!is_null($params['include'])) {
207
+ // including tax
208
+ if (isset($params['is_subtotal'])) {
209
+ $total = $params['include'] + $item->getWeeeTaxAppliedRowAmount();
210
+ } else {
211
+ $total = $params['include'] + $renderer->getWeeeTaxAppliedAmount();
212
+ }
213
+ } else {
214
+ // excluding tax
215
+ if ($params['is_subtotal']) {
216
+ $total = $item->getRowTotal()
217
+ + $item->getWeeeTaxAppliedRowAmount()
218
+ + $item->getWeeeTaxRowDisposition();
219
+ } else {
220
+ $total = $item->getPrice()
221
+ + $renderer->getWeeeTaxAppliedAmount()
222
+ + $renderer->getWeeeTaxDisposition();
223
+ }
224
+ }
225
+
226
+ if (!isset($weeeXml)) {
227
+ $weeeXml = $parentXml->addChild('weee');
228
+ }
229
+ $weeeXml->addCustomChild(
230
+ 'total',
231
+ $this->formatPrice($renderer, $total),
232
+ array('label' => $renderer->helper('weee')->__('Total'))
233
+ );
234
+ }
235
+ }
236
+
237
+ /**
238
+ * Add item quantites to the XML
239
+ *
240
+ * @param Mage_Core_Block_Template $renderer Product renderer
241
+ * @param Mage_XmlConnect_Model_Simplexml_Element $parentXml
242
+ * @param Mage_Sales_Model_Order_Item $item
243
+ * @return void
244
+ */
245
+ public function addQuantityToXml(
246
+ Mage_Core_Block_Template $renderer,
247
+ Mage_XmlConnect_Model_Simplexml_Element $quantityXml,
248
+ Mage_Sales_Model_Order_Item $item
249
+ )
250
+ {
251
+ $qty = 1 * $item->getQtyOrdered();
252
+ if ($qty > 0) {
253
+ $quantityXml->addCustomChild(
254
+ 'value',
255
+ $qty,
256
+ array(
257
+ 'label' => $renderer->__('Ordered')
258
+ )
259
+ );
260
+ }
261
+ $qty = 1 * $item->getQtyShipped();
262
+ if ($qty > 0) {
263
+ $quantityXml->addCustomChild(
264
+ 'value',
265
+ $qty,
266
+ array(
267
+ 'label' => $renderer->__('Shipped')
268
+ )
269
+ );
270
+ }
271
+ $qty = 1 * $item->getQtyCanceled();
272
+ if ($qty > 0) {
273
+ $quantityXml->addCustomChild(
274
+ 'value',
275
+ $qty,
276
+ array(
277
+ 'label' => $renderer->__('Canceled')
278
+ )
279
+ );
280
+ }
281
+ $qty = 1 * $item->getQtyRefunded();
282
+ if ($qty > 0) {
283
+ $quantityXml->addCustomChild(
284
+ 'value',
285
+ $qty,
286
+ array(
287
+ 'label' => $renderer->__('Refunded')
288
+ )
289
+ );
290
+ }
291
+ }
292
+
293
+ /**
294
+ * Format price using order currency
295
+ *
296
+ * @param Mage_Core_Block_Template $renderer Product renderer
297
+ * @param float $price
298
+ * @return string
299
+ */
300
+ public function formatPrice(Mage_Core_Block_Template $renderer, $price)
301
+ {
302
+ return $renderer->getOrder()->getOrderCurrency()->formatPrecision($price, 2, array(), false);
303
+ }
304
+ }
app/code/core/Mage/XmlConnect/Helper/Data.php ADDED
@@ -0,0 +1,865 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect default helper
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Helper_Data extends Mage_Core_Helper_Abstract
35
+ {
36
+ /**
37
+ * Push title length
38
+ */
39
+ const PUSH_TITLE_LENGTH = 140;
40
+
41
+ /**
42
+ * Message title length
43
+ */
44
+ const MESSAGE_TITLE_LENGTH = 255;
45
+
46
+ /**
47
+ * List of the keys for xml config that have to be excluded form application config
48
+ *
49
+ * @var array
50
+ */
51
+ protected $_excludedXmlConfigKeys = array('notifications/applicationMasterSecret');
52
+
53
+ /**
54
+ * Application names array
55
+ *
56
+ * @var array
57
+ */
58
+ protected $_appNames = array();
59
+
60
+ /**
61
+ * Template names array
62
+ *
63
+ * @var array
64
+ */
65
+ protected $_tplNames = array();
66
+
67
+ /**
68
+ * XML path to nodes to be excluded
69
+ */
70
+ const XML_NODE_CONFIG_EXCLUDE_FROM_XML = 'xmlconnect/mobile_application/nodes_excluded_from_config_xml';
71
+
72
+ /**
73
+ * Default device type
74
+ */
75
+ const DEVICE_TYPE_DEFAULT = 'unknown';
76
+
77
+ /**
78
+ * iPhone device identifier
79
+ */
80
+ const DEVICE_TYPE_IPHONE = 'iphone';
81
+
82
+ /**
83
+ * iPad device identifier
84
+ */
85
+ const DEVICE_TYPE_IPAD = 'ipad';
86
+
87
+ /**
88
+ * Android device identifier
89
+ */
90
+ const DEVICE_TYPE_ANDROID = 'android';
91
+
92
+ /**
93
+ * Social network Twitter id
94
+ */
95
+ const SOCIAL_NETWORK_TWITTER = 'twitter';
96
+
97
+ /**
98
+ * Social network Facebook id
99
+ */
100
+ const SOCIAL_NETWORK_FACEBOOK = 'facebook';
101
+
102
+ /**
103
+ * Social network LinkedIn id
104
+ */
105
+ const SOCIAL_NETWORK_LINKEDIN = 'linkedin';
106
+
107
+ /**
108
+ * Get device preview model
109
+ *
110
+ * @throws Mage_Core_Exception
111
+ * @return Mage_XmlConnect_Model_Preview_Abstract
112
+ */
113
+ public function getPreviewModel()
114
+ {
115
+ $deviceType = $this->getDeviceType();
116
+
117
+ switch ($deviceType) {
118
+ case self::DEVICE_TYPE_IPHONE:
119
+ case self::DEVICE_TYPE_IPAD:
120
+ case self::DEVICE_TYPE_ANDROID:
121
+ $previewModel = Mage::getSingleton('xmlconnect/preview_' . strtolower($deviceType));
122
+ break;
123
+ default:
124
+ Mage::throwException(
125
+ Mage::helper('xmlconnect')->__('Device doesn\'t recognized: "%s". Unable to load preview model.', $deviceType)
126
+ );
127
+ break;
128
+ }
129
+ return $previewModel;
130
+ }
131
+
132
+ /**
133
+ * Get device helper
134
+ *
135
+ * @throws Mage_Core_Exception
136
+ * @param Mage_XmlConnect_Model_Application $application
137
+ * @return Mage_Core_Helper_Abstract
138
+ */
139
+ public function getDeviceHelper($application = null)
140
+ {
141
+ $deviceType = $this->getDeviceType($application);
142
+
143
+ switch ($deviceType) {
144
+ case self::DEVICE_TYPE_IPHONE:
145
+ case self::DEVICE_TYPE_IPAD:
146
+ case self::DEVICE_TYPE_ANDROID:
147
+ $helper = Mage::helper('xmlconnect/' . $deviceType);
148
+ break;
149
+ default:
150
+ Mage::throwException(
151
+ Mage::helper('xmlconnect')->__('Device doesn\'t recognized: "%s". Unable to load a helper.', $deviceType)
152
+ );
153
+ break;
154
+ }
155
+ return $helper;
156
+ }
157
+
158
+ /**
159
+ * Get device tipe from application
160
+ *
161
+ * @param Mage_XmlConnect_Model_Application $application
162
+ * @return string
163
+ */
164
+ public function getDeviceType($application = null)
165
+ {
166
+ $deviceType = null;
167
+ if (empty($application) && Mage::registry('current_app') !== null) {
168
+ $deviceType = (string) $this->getApplication()->getType();
169
+ } elseif ($application instanceof Mage_XmlConnect_Model_Application) {
170
+ $deviceType = (string) $application->getType();
171
+ }
172
+ if (empty($deviceType)) {
173
+ $deviceType = self::DEVICE_TYPE_DEFAULT;
174
+ }
175
+ return $deviceType;
176
+ }
177
+
178
+ /**
179
+ * Getter for current loaded application model
180
+ *
181
+ * @throws Mage_Core_Exception
182
+ * @return Mage_XmlConnect_Model_Application
183
+ */
184
+ public function getApplication()
185
+ {
186
+ $model = Mage::registry('current_app');
187
+ if (!($model instanceof Mage_XmlConnect_Model_Application)) {
188
+ Mage::throwException(Mage::helper('xmlconnect')->__('App model not loaded.'));
189
+ }
190
+
191
+ return $model;
192
+ }
193
+
194
+ /**
195
+ * Create array with filter model and filter block by key
196
+ *
197
+ * Create array with:
198
+ * - Mage_Catalog_Model_Layer_Filter_Abstract
199
+ * - Mage_Catalog_Block_Layer_Filter_Abstract
200
+ *
201
+ * @param string $key
202
+ * @return array
203
+ */
204
+ public function getFilterByKey($key)
205
+ {
206
+ switch ($key) {
207
+ case 'price':
208
+ $filterModelName = 'catalog/layer_filter_price';
209
+ break;
210
+ case 'decimal':
211
+ $filterModelName = 'catalog/layer_filter_decimal';
212
+ break;
213
+ case 'category':
214
+ $filterModelName = 'catalog/layer_filter_category';
215
+ break;
216
+ default:
217
+ $filterModelName = 'catalog/layer_filter_attribute';
218
+ break;
219
+ }
220
+ return array(Mage::getModel($filterModelName), $this->getLayout()->createBlock($filterModelName));
221
+ }
222
+
223
+ /**
224
+ * Export $this->_getUrl() function to public
225
+ *
226
+ * @param string $route
227
+ * @param array $params
228
+ * @return array
229
+ */
230
+ public function getUrl($route, $params = array())
231
+ {
232
+ return $this->_getUrl($route, $params);
233
+ }
234
+
235
+ /**
236
+ * Retrieve device specific country options array
237
+ *
238
+ * @throws Mage_Core_Exception
239
+ * @return array
240
+ */
241
+ public function getCountryOptionsArray()
242
+ {
243
+ Varien_Profiler::start('TEST: ' . __METHOD__);
244
+ $deviceType = $this->getDeviceType();
245
+ switch ($deviceType) {
246
+ case self::DEVICE_TYPE_IPHONE:
247
+ case self::DEVICE_TYPE_IPAD:
248
+ $cacheKey = 'XMLCONNECT_COUNTRY_ITUNES_SELECT_STORE_' . Mage::app()->getStore()->getCode();
249
+ $deviceCountries = $this->getDeviceHelper()->getItunesCountriesArray();
250
+ break;
251
+ case self::DEVICE_TYPE_ANDROID:
252
+ $cacheKey = 'XMLCONNECT_COUNTRY_ANDROID_SELECT_STORE_' . Mage::app()->getStore()->getCode();
253
+ $deviceCountries = $this->getDeviceHelper()->getAndroidMarketCountriesArray();
254
+ break;
255
+ default:
256
+ Mage::throwException(
257
+ Mage::helper('xmlconnect')->__('Country options don\'t recognized for "%s".', $deviceType)
258
+ );
259
+ break;
260
+ }
261
+
262
+ if (Mage::app()->useCache('config') && $cache = Mage::app()->loadCache($cacheKey)) {
263
+ $options = unserialize($cache);
264
+ } else {
265
+ if (isset($deviceCountries)) {
266
+ $options = Mage::getModel('directory/country')
267
+ ->getResourceCollection()
268
+ ->addFieldToFilter('country_id', array('in' => $deviceCountries))
269
+ ->loadByStore()
270
+ ->toOptionArray(false);
271
+ }
272
+ if (Mage::app()->useCache('config')) {
273
+ Mage::app()->saveCache(serialize($options), $cacheKey, array('config'));
274
+ }
275
+ }
276
+ Varien_Profiler::stop('TEST: ' . __METHOD__);
277
+
278
+ if (count($options)) {
279
+ $options[] = array(
280
+ 'value' => 'NEW_COUNTRIES',
281
+ 'label' => 'New Territories As Added'
282
+ );
283
+ }
284
+
285
+ return $options;
286
+ }
287
+
288
+ /**
289
+ * Get list of predefined and supported Devices
290
+ *
291
+ * @return array
292
+ */
293
+ static public function getSupportedDevices()
294
+ {
295
+ $devices = array (
296
+ self::DEVICE_TYPE_IPAD => Mage::helper('xmlconnect')->__('iPad'),
297
+ self::DEVICE_TYPE_IPHONE => Mage::helper('xmlconnect')->__('iPhone'),
298
+ self::DEVICE_TYPE_ANDROID => Mage::helper('xmlconnect')->__('Android')
299
+ );
300
+
301
+ return $devices;
302
+ }
303
+
304
+ /**
305
+ * Get list of predefined and supported Devices
306
+ *
307
+ * @return array
308
+ */
309
+ public function getStatusOptions()
310
+ {
311
+ $options = array (
312
+ Mage_XmlConnect_Model_Application::APP_STATUS_SUCCESS => Mage::helper('xmlconnect')->__('Submitted'),
313
+ Mage_XmlConnect_Model_Application::APP_STATUS_INACTIVE => Mage::helper('xmlconnect')->__('Not Submitted'),
314
+ );
315
+ return $options;
316
+ }
317
+
318
+ /**
319
+ * Retrieve supported device types as "html select options"
320
+ *
321
+ * @return array
322
+ */
323
+ public function getDeviceTypeOptions()
324
+ {
325
+ $devices = self::getSupportedDevices();
326
+ $options = array();
327
+ $options[] = array('value' => '', 'label' => Mage::helper('xmlconnect')->__('Please Select Device Type'));
328
+ foreach ($devices as $type => $label) {
329
+ $options[] = array('value' => $type, 'label' => $label);
330
+ }
331
+ return $options;
332
+ }
333
+
334
+ /**
335
+ * Get default application tabs
336
+ *
337
+ * @return array
338
+ */
339
+ public function getDefaultApplicationDesignTabs()
340
+ {
341
+ return $this->getDeviceHelper()->getDefaultDesignTabs();
342
+ }
343
+
344
+ /**
345
+ * Get default Cache Lifetime
346
+ *
347
+ * @return int
348
+ */
349
+ public function getDefaultCacheLifetime()
350
+ {
351
+ return (int)Mage::getStoreConfig(
352
+ Mage_XmlConnect_Model_Application::XML_PATH_DEFAULT_CACHE_LIFETIME
353
+ );
354
+ }
355
+
356
+ /**
357
+ * Return array for tabs like label -> action array
358
+ *
359
+ * @return array
360
+ */
361
+ protected function _getTabLabelActionArray()
362
+ {
363
+ if (!isset($this->_tabLabelActionArray)) {
364
+ $this->_tabLabelActionArray = array();
365
+ foreach ($this->getDefaultApplicationDesignTabs() as $tab) {
366
+ $this->_tabLabelActionArray[$tab['action']] = $tab['label'];
367
+ }
368
+ }
369
+ return $this->_tabLabelActionArray;
370
+ }
371
+
372
+ /**
373
+ * Return Translated tab label for given $action
374
+ *
375
+ * @param string $action
376
+ * @return string|bool
377
+ */
378
+ public function getTabLabel($action)
379
+ {
380
+ $action = (string) $action;
381
+ $tabs = $this->_getTabLabelActionArray();
382
+ return (isset($tabs[$action])) ? $tabs[$action] : false;
383
+ }
384
+
385
+ /**
386
+ * Merges $changes array to $target array recursive, overwriting existing key, and adding new one
387
+ *
388
+ * @param mixed $target
389
+ * @param mixed $changes
390
+ * @return array
391
+ */
392
+ static public function arrayMergeRecursive($target, $changes)
393
+ {
394
+ if (!is_array($target)) {
395
+ $target = empty($target) ? array() : array($target);
396
+ }
397
+ if (!is_array($changes)) {
398
+ $changes = array($changes);
399
+ }
400
+ foreach ($changes as $key => $value) {
401
+ if (!array_key_exists($key, $target) and !is_numeric($key)) {
402
+ $target[$key] = $changes[$key];
403
+ continue;
404
+ }
405
+ if (is_array($value) or is_array($target[$key])) {
406
+ $target[$key] = self::arrayMergeRecursive($target[$key], $changes[$key]);
407
+ } else if (is_numeric($key)) {
408
+ if (!in_array($value, $target)) {
409
+ $target[] = $value;
410
+ }
411
+ } else {
412
+ $target[$key] = $value;
413
+ }
414
+ }
415
+
416
+ return $target;
417
+ }
418
+
419
+ /**
420
+ * Wrap $body with HTML4 headers
421
+ *
422
+ * @param string $body
423
+ * @return string
424
+ */
425
+ public function htmlize($body)
426
+ {
427
+ $w3cUrl = 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd';
428
+ return <<<EOT
429
+ &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;$w3cUrl&quot;&gt;
430
+ &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;&gt;
431
+ &lt;head&gt;
432
+ &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;style.css&quot; media=&quot;screen&quot;/&gt;
433
+ &lt;/head&gt;
434
+ &lt;body&gt;$body&lt;/body&gt;&lt;/html&gt;
435
+ EOT;
436
+ }
437
+
438
+ /**
439
+ * Return select options for xml from array
440
+ *
441
+ * @param array $dataArray source array
442
+ * @param string $selected selected item
443
+ * @return string
444
+ */
445
+ public function getArrayAsXmlItemValues($dataArray, $selected)
446
+ {
447
+ $items = array();
448
+ foreach ($dataArray as $k => $v) {
449
+ if (!$k) {
450
+ continue;
451
+ }
452
+ $items[] = '
453
+ <item' . ($k == $selected ? ' selected="1"' : '') . '>
454
+ <label>' . $v . '</label>
455
+ <value>' . ($k ? $k : '') . '</value>
456
+ </item>';
457
+ }
458
+ $result = implode(PHP_EOL, $items);
459
+ return $result;
460
+ }
461
+
462
+ /**
463
+ * Return Solo Xml optional fieldset
464
+ *
465
+ * @param string $ssCcMonths
466
+ * @param string $ssCcYears
467
+ * @return string
468
+ */
469
+ public function getSoloXml($ssCcMonths, $ssCcYears)
470
+ {
471
+ $validatorMessage = $this->__('Please enter issue number or start date for switch/solo card type.');
472
+ // issue number ==== validate-cc-ukss cvv
473
+ $solo = <<<EOT
474
+ <fieldset_optional>
475
+ <depend_on name="payment[cc_type]">
476
+ <show_value>
477
+ <item>SS</item>
478
+ <item>SM</item>
479
+ <item>SO</item>
480
+ </show_value>
481
+ </depend_on>
482
+
483
+ <field name="payment[cc_ss_issue]" type="text" label="{$this->__('Issue Number')}">
484
+ <validators>
485
+ <validator relation="payment[cc_type]" type="credit_card_ukss" message="{$validatorMessage}"/>
486
+ </validators>
487
+ </field>;
488
+ <field name="payment[cc_ss_start_month]" type="select" label="{$this->__('Start Date - Month')}">
489
+ <values>
490
+ $ssCcMonths
491
+ </values>
492
+ </field>
493
+ <field name="payment[cc_ss_start_year]" type="select" label="{$this->__('Start Date - Year')}">
494
+ <values>
495
+ $ssCcYears
496
+ </values>
497
+ </field>
498
+ </fieldset_optional>
499
+ EOT;
500
+ return $solo;
501
+ }
502
+
503
+ /**
504
+ * Format price for correct view inside xml strings
505
+ *
506
+ * @param float $price
507
+ * @return string
508
+ */
509
+ public function formatPriceForXml($price)
510
+ {
511
+ return sprintf('%01.2F', $price);
512
+ }
513
+
514
+ /**
515
+ * Get list of predefined and supported message types
516
+ *
517
+ * @return array
518
+ */
519
+ static public function getSupportedMessageTypes()
520
+ {
521
+ $messages = array (
522
+ Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_PUSH => Mage::helper('xmlconnect')->__('Push message'),
523
+ Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL => Mage::helper('xmlconnect')->__('AirMail message'),
524
+ );
525
+
526
+ return $messages;
527
+ }
528
+
529
+ /**
530
+ * Retrieve supported message types as "html select options"
531
+ *
532
+ * @return array
533
+ */
534
+ public function getMessageTypeOptions()
535
+ {
536
+ $options = array();
537
+ $messages = self::getSupportedMessageTypes();
538
+ foreach ($messages as $type => $label) {
539
+ $options[] = array('value' => $type, 'label' => $label);
540
+ }
541
+ return $options;
542
+ }
543
+
544
+ /**
545
+ * Get push title length
546
+ *
547
+ * @return int
548
+ */
549
+ public function getPushTitleLength()
550
+ {
551
+ return self::PUSH_TITLE_LENGTH;
552
+ }
553
+
554
+ /**
555
+ * Get message title length
556
+ *
557
+ * @return int
558
+ */
559
+ public function getMessageTitleLength()
560
+ {
561
+ return self::MESSAGE_TITLE_LENGTH;
562
+ }
563
+
564
+ /**
565
+ * Retrieve applications as "html select options"
566
+ *
567
+ * @return array
568
+ */
569
+ public function getApplicationOptions()
570
+ {
571
+ $options = array();
572
+ /** @var $app Mage_XmlConnect_Model_Application */
573
+ foreach (Mage::getModel('xmlconnect/application')->getCollection() as $app) {
574
+ $options[] = array(
575
+ 'value' => $app->getCode(),
576
+ 'label' => $app->getName()
577
+ );
578
+ }
579
+ if (count($options) > 1) {
580
+ array_unshift(
581
+ $options,
582
+ array(
583
+ 'value' => '',
584
+ 'label' => Mage::helper('xmlconnect')->__('Please Select Application')
585
+ )
586
+ );
587
+ }
588
+ return $options;
589
+ }
590
+
591
+ /**
592
+ * Get applications array like `code` as `name`
593
+ *
594
+ * @static array $apps
595
+ * @return array
596
+ */
597
+ public function getApplications()
598
+ {
599
+ static $apps = array();
600
+
601
+ if (empty($apps)) {
602
+ foreach (Mage::getModel('xmlconnect/application')->getCollection() as $app) {
603
+ $apps[$app->getCode()] = $app->getName();
604
+ }
605
+ }
606
+ return $apps;
607
+ }
608
+
609
+ /**
610
+ * Send broadcast message
611
+ *
612
+ * @throws Mage_Core_Exception
613
+ * @param Mage_XmlConnect_Model_Queue $queue
614
+ */
615
+ public function sendBroadcastMessage(Mage_XmlConnect_Model_Queue $queue)
616
+ {
617
+ if ($queue->getStatus() != Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE) {
618
+ return;
619
+ }
620
+
621
+ try {
622
+ $appCode = $queue->getAppCode();
623
+ /** @var $app Mage_XmlConnect_Model_Application */
624
+ $app = Mage::getModel('xmlconnect/application')->loadByCode($appCode);
625
+
626
+ if (!$app->getId()) {
627
+ Mage::throwException(
628
+ Mage::helper('xmlconnect')->__('Can\'t load application with code "%s"', $appCode)
629
+ );
630
+ }
631
+
632
+ if (!$app->isNotificationsActive()) {
633
+ $queue->setStatus(Mage_XmlConnect_Model_Queue::STATUS_CANCELED);
634
+ return;
635
+ }
636
+
637
+ $sendType = $queue->getData('type');
638
+ switch ($sendType) {
639
+ case Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL:
640
+ $configPath = 'xmlconnect/' . Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL . '/broadcast_url';
641
+ $params = $queue->getAirmailBroadcastParams();
642
+ break;
643
+
644
+ case Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_PUSH:
645
+ default:
646
+ $configPath = 'xmlconnect/' . Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_PUSH . '/broadcast_url';
647
+ $params = $queue->getPushBroadcastParams();
648
+ break;
649
+ }
650
+
651
+ $curlHandler = curl_init(Mage::getStoreConfig($configPath));
652
+
653
+ $httpHeaders = $this->getHttpHeaders();
654
+
655
+ curl_setopt($curlHandler, CURLOPT_POST, 1);
656
+ curl_setopt($curlHandler, CURLOPT_HTTPHEADER, $httpHeaders);
657
+ curl_setopt($curlHandler, CURLOPT_POSTFIELDS, $params);
658
+ curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, 1);
659
+ curl_setopt($curlHandler, CURLOPT_USERPWD, $app->getUserpwd());
660
+ curl_setopt($curlHandler, CURLOPT_TIMEOUT, 60);
661
+
662
+ // Execute the request.
663
+ curl_exec($curlHandler);
664
+ $succeeded = curl_errno($curlHandler) == 0;
665
+ $responseCode = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE) == 200;
666
+ // close cURL resource, and free up system resources
667
+ curl_close($curlHandler);
668
+
669
+ if ($succeeded && $responseCode) {
670
+ $queue->setStatus(Mage_XmlConnect_Model_Queue::STATUS_COMPLETED);
671
+ }
672
+ $queue->setIsSent(true);
673
+ $queue->save();
674
+ return;
675
+ } catch (Exception $e) {
676
+ Mage::logException($e);
677
+ throw $e;
678
+ }
679
+ }
680
+
681
+ /**
682
+ * Get headers for broadcast message
683
+ *
684
+ * @return array
685
+ */
686
+ public function getHttpHeaders()
687
+ {
688
+ return array('Content-Type: application/json');
689
+ }
690
+
691
+ /**
692
+ * Remove from array the unnecessary parameters by given keys
693
+ *
694
+ * @param array $data Source array
695
+ * @param array $excludedKeys Keys to be excluded from array. Keys must be in xPath notation
696
+ * @return array
697
+ */
698
+ public function excludeXmlConfigKeys($data, $excludedKeys = array())
699
+ {
700
+ $excludedKeys = $this->getExcludedXmlConfigKeys();
701
+ if (!empty($excludedKeys)) {
702
+ foreach ($excludedKeys as $keyToExclude) {
703
+ if (strpos($keyToExclude, '/')) {
704
+ $keys = array();
705
+ foreach (explode('/', $keyToExclude) as $key) {
706
+ $key = trim($key);
707
+ if (!empty($key)) {
708
+ $keys[] = $key;
709
+ }
710
+ }
711
+ if (!empty($keys)) {
712
+ $keys = '$data["' . implode('"]["', $keys) . '"]';
713
+ eval('if (isset(' . $keys . ')) unset(' . $keys . ');');
714
+ }
715
+ } elseif (!empty($keyToExclude) && isset($data[$keyToExclude])) {
716
+ unset($data[$keyToExclude]);
717
+ }
718
+ }
719
+ }
720
+ return $data;
721
+ }
722
+
723
+ /**
724
+ * Get excluded keys as array
725
+ *
726
+ * @return array
727
+ */
728
+ public function getExcludedXmlConfigKeys()
729
+ {
730
+ $toExclude = Mage::getStoreConfig(self::XML_NODE_CONFIG_EXCLUDE_FROM_XML);
731
+ $nodes = array();
732
+ foreach ($toExclude as $value) {
733
+ $nodes[] = trim($value, '/');
734
+ }
735
+
736
+ return $nodes;
737
+ }
738
+
739
+ /**
740
+ * Returns Application name by it's code
741
+ * @param string $appCode
742
+ * @return string
743
+ */
744
+ public function getApplicationName($appCode = null)
745
+ {
746
+ if (empty($appCode)) {
747
+ return '';
748
+ }
749
+ if (!isset($this->_appNames[$appCode])) {
750
+ $app = Mage::getModel('xmlconnect/application')->loadByCode($appCode);
751
+ if ($app->getId()) {
752
+ $this->_appNames[$appCode] = $app->getName();
753
+ } else {
754
+ return '';
755
+ }
756
+ }
757
+ return $this->_appNames[$appCode];
758
+ }
759
+
760
+ /**
761
+ * Returns Application name by it's code
762
+ * @param string $templateId
763
+ * @return string
764
+ */
765
+ public function getTemplateName($templateId = null)
766
+ {
767
+ if (empty($templateId)) {
768
+ return '';
769
+ }
770
+ if (!isset($this->_tplNames[$templateId])) {
771
+ $template = Mage::getModel('xmlconnect/template')->load($templateId);
772
+ if ($template->getId()) {
773
+ $this->_tplNames[$templateId] = $template->getName();
774
+ } else {
775
+ return '';
776
+ }
777
+ }
778
+ return $this->_tplNames[$templateId];
779
+ }
780
+
781
+ /**
782
+ * Set value into multidimensional array 'conf/native/navigationBar/icon'
783
+ *
784
+ * @param array &$target pointer to target array
785
+ * @param string $fieldPath 'conf/native/navigationBar/icon'
786
+ * @param mixed $fieldValue 'Some Value' || 12345 || array(1=>3, 'aa'=>43)
787
+ * @param string $delimiter path delimiter
788
+ * @return null
789
+ */
790
+ public function _injectFieldToArray(&$target, $fieldPath, $fieldValue, $delimiter = '/')
791
+ {
792
+ $nameParts = explode($delimiter, $fieldPath);
793
+ foreach ($nameParts as $next) {
794
+ if (!isset($target[$next])) {
795
+ $target[$next] = array();
796
+ }
797
+ $target =& $target[$next];
798
+ }
799
+ $target = $fieldValue;
800
+ return null;
801
+ }
802
+
803
+ /**
804
+ * Convert Url link to file path for images
805
+ *
806
+ * @param string $icon
807
+ * @return string
808
+ */
809
+ public function urlToPath($icon)
810
+ {
811
+ $baseUrl = Mage::getBaseUrl('media');
812
+ $path = str_replace($baseUrl, '', $icon);
813
+ $filePath = Mage::getBaseDir('media') . DS . str_replace('/', DS, $path);
814
+ return $filePath;
815
+
816
+ }
817
+
818
+ /**
819
+ * Validate config body field is not empty
820
+ *
821
+ * @param string $field
822
+ * @param array $native
823
+ * @return bool
824
+ */
825
+ public function validateConfFieldNotEmpty($field, $native)
826
+ {
827
+ if (($native === false)
828
+ || (!isset($native['body']) || !is_array($native['body'])
829
+ || !isset($native['body'][$field])
830
+ || !Zend_Validate::is($native['body'][$field], 'NotEmpty'))
831
+ ) {
832
+ return false;
833
+ }
834
+ return true;
835
+ }
836
+
837
+ /**
838
+ * Check the notifications are allowed for current type of application
839
+ *
840
+ * @param Mage_XmlConnect_Model_Application $application
841
+ * @return bool
842
+ */
843
+ public function isNotificationsAllowed($application = null)
844
+ {
845
+ return $this->getDeviceHelper($application)->isNotificationsAllowed();
846
+ }
847
+
848
+ /**
849
+ * Get front url for action
850
+ *
851
+ * @param string $action
852
+ * @param array $params
853
+ * @return string url
854
+ */
855
+ public function getActionUrl($action, $params = array())
856
+ {
857
+ $defaultParams = array(
858
+ '_store' => $this->getApplication()->getStoreId(),
859
+ '_nosid' => true,
860
+ '_secure' => $this->getApplication()->getUseSecureURLInFrontend()
861
+ );
862
+ $params = array_merge($defaultParams, $params);
863
+ return Mage::getUrl($action, $params);
864
+ }
865
+ }
app/code/core/Mage/XmlConnect/Helper/Image.php ADDED
@@ -0,0 +1,788 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect image helper
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Helper_Image extends Mage_Core_Helper_Abstract
35
+ {
36
+ /**
37
+ * Xml connect glue
38
+ */
39
+ const XMLCONNECT_GLUE = '_';
40
+
41
+ /**
42
+ * Image limits for content
43
+ *
44
+ * @var array|null
45
+ */
46
+ protected $_content = null;
47
+
48
+ /**
49
+ * Image limits for interface
50
+ *
51
+ * @var array|null
52
+ */
53
+ protected $_interface = null;
54
+
55
+ /**
56
+ * Array of interface image paths in xmlConfig
57
+ *
58
+ * @var array
59
+ */
60
+ protected $_interfacePath = array();
61
+
62
+ /**
63
+ * Image limits array
64
+ *
65
+ * @var array
66
+ */
67
+ protected $_imageLimits = array();
68
+
69
+ /**
70
+ * Images paths in the config
71
+ *
72
+ * @var array|null
73
+ */
74
+ protected $_confPaths = null;
75
+
76
+ /**
77
+ * Process uploaded file
78
+ * setup file names to the configuration
79
+ *
80
+ * @param string $field
81
+ * @retun string
82
+ */
83
+ public function handleUpload($field)
84
+ {
85
+ $uploadedFilename = '';
86
+ $uploadDir = $this->getOriginalSizeUploadDir();
87
+
88
+ try {
89
+ $this->_forcedConvertPng($field);
90
+
91
+ $uploader = new Varien_File_Uploader($field);
92
+ $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
93
+ $uploader->setAllowRenameFiles(true);
94
+ $uploader->save($uploadDir);
95
+ $uploadedFilename = $uploader->getUploadedFileName();
96
+ $uploadedFilename = $this->_getResizedFilename($field, $uploadedFilename, true);
97
+ } catch (Exception $e) {
98
+ /**
99
+ * Hard coded exception catch
100
+ */
101
+ if (!strlen($_FILES[$field]['tmp_name'])) {
102
+ Mage::throwException(Mage::helper('xmlconnect')->__('File can\'t be uploaded.'));
103
+ } elseif ($e->getMessage() == 'Disallowed file type.') {
104
+ $filename = $_FILES[$field]['name'];
105
+ Mage::throwException(
106
+ Mage::helper('xmlconnect')->__('Error while uploading file "%s". Disallowed file type. Only "jpg", "jpeg", "gif", "png" are allowed.', $filename)
107
+ );
108
+ } else {
109
+ Mage::logException($e);
110
+ }
111
+ }
112
+ return basename($uploadedFilename);
113
+ }
114
+
115
+ /**
116
+ * Return current screen_size parameter
117
+ *
118
+ * @return string
119
+ */
120
+ protected function _getScreenSize()
121
+ {
122
+ return Mage::helper('xmlconnect')->getApplication()->getScreenSize();
123
+ }
124
+
125
+ /**
126
+ * Return correct system filename for current screenSize
127
+ *
128
+ * @throws Mage_Core_Exception
129
+ * @param string $fieldPath
130
+ * @param string $fileName
131
+ * @param bool $default
132
+ * @return string
133
+ */
134
+ protected function _getResizedFilename($fieldPath, $fileName, $default = false)
135
+ {
136
+ $fileName = basename($fileName);
137
+ if ($default) {
138
+ $dir = $this->getDefaultSizeUploadDir();
139
+ } else {
140
+ $dir = $this->getCustomSizeUploadDir($this->_getScreenSize());
141
+ }
142
+ $customSizeFileName = $dir . DS . $fileName;
143
+ $originalSizeFileName = $this->getOriginalSizeUploadDir(). DS . $fileName;
144
+
145
+ /**
146
+ * Compatibility with old versions of XmlConnect
147
+ */
148
+ if (!file_exists($originalSizeFileName)) {
149
+ $oldFileName = $this->getOldUploadDir() . DS . $fileName;
150
+ if (file_exists($oldFileName)) {
151
+ if (!(copy($oldFileName, $originalSizeFileName)
152
+ && (is_readable($customSizeFileName) || chmod($customSizeFileName, 0644))
153
+ )) {
154
+ Mage::throwException(
155
+ Mage::helper('xmlconnect')->__('Error while processing file "%s".', $fileName)
156
+ );
157
+ }
158
+ } else {
159
+ Mage::throwException(Mage::helper('xmlconnect')->__('No such file "%s".', $fileName));
160
+ }
161
+ }
162
+
163
+ $isCopied = copy($originalSizeFileName, $customSizeFileName);
164
+ clearstatcache();
165
+ if ($isCopied
166
+ && (is_readable($customSizeFileName)
167
+ || chmod($customSizeFileName, 0644)
168
+ )
169
+ ) {
170
+ $this->_handleResize($fieldPath, $customSizeFileName);
171
+ } else {
172
+ $fileName = '';
173
+ if (isset($_FILES[$fieldPath]) && is_array($_FILES[$fieldPath]) && isset($_FILES[$fieldPath]['name'])) {
174
+ $fileName = $_FILES[$fieldPath]['name'];
175
+ }
176
+ Mage::throwException(Mage::helper('xmlconnect')->__('Error while uploading file "%s".', $fileName));
177
+ }
178
+ return $customSizeFileName;
179
+ }
180
+
181
+ /**
182
+ * Resize uploaded file
183
+ *
184
+ * @param string $fieldPath
185
+ * @param string $file
186
+ * @return void
187
+ */
188
+ protected function _handleResize($fieldPath, $file)
189
+ {
190
+ $nameParts = explode('/', $fieldPath);
191
+ array_shift($nameParts);
192
+ $conf = $this->getInterfaceImageLimits();
193
+ while (count($nameParts)) {
194
+ $next = array_shift($nameParts);
195
+ if (isset($conf[$next])) {
196
+ $conf = $conf[$next];
197
+ } else {
198
+ /**
199
+ * No config data - nothing to resize
200
+ */
201
+ return;
202
+ }
203
+ }
204
+
205
+ $image = new Varien_Image($file);
206
+ $width = $image->getOriginalWidth();
207
+ $height = $image->getOriginalHeight();
208
+
209
+ if (isset($conf['widthMax']) && ($conf['widthMax'] < $width)) {
210
+ $width = $conf['widthMax'];
211
+ } elseif (isset($conf['width'])) {
212
+ $width = $conf['width'];
213
+ }
214
+
215
+ if (isset($conf['heightMax']) && ($conf['heightMax'] < $height)) {
216
+ $height = $conf['heightMax'];
217
+ } elseif (isset($conf['height'])) {
218
+ $height = $conf['height'];
219
+ }
220
+
221
+ if (($width != $image->getOriginalWidth())
222
+ || ($height != $image->getOriginalHeight())
223
+ ) {
224
+ $image->keepTransparency(true);
225
+ $image->keepFrame(true);
226
+ $image->keepAspectRatio(true);
227
+ $image->backgroundColor(array(255, 255, 255));
228
+ $image->resize($width, $height);
229
+ $image->save(null, basename($file));
230
+ }
231
+ }
232
+
233
+ /**
234
+ * Convert uploaded file to PNG
235
+ *
236
+ * @param string $field
237
+ */
238
+ protected function _forcedConvertPng($field)
239
+ {
240
+ $file =& $_FILES[$field];
241
+
242
+ $dotPosition = strrpos($file['name'], '.');
243
+ if ($dotPosition !== false) {
244
+ $file['name'] = substr($file['name'], 0 , $dotPosition);
245
+ }
246
+ $file['name'] .= '.png';
247
+
248
+ // We can't use exif extension, because magento doesn't require it.
249
+ // $fileType = exif_imagetype($file['tmp_name']);
250
+ list($unnecessaryVar, $unnecessaryVar, $fileType) = getimagesize($file['tmp_name']);
251
+ unset($unnecessaryVar);
252
+
253
+ if ($fileType != IMAGETYPE_PNG) {
254
+ switch ($fileType) {
255
+ case IMAGETYPE_GIF:
256
+ $img = imagecreatefromgif($file['tmp_name']);
257
+ imagealphablending($img, false);
258
+ imagesavealpha($img, true);
259
+ break;
260
+ case IMAGETYPE_JPEG:
261
+ $img = imagecreatefromjpeg($file['tmp_name']);
262
+ break;
263
+ case IMAGETYPE_WBMP:
264
+ $img = imagecreatefromwbmp($file['tmp_name']);
265
+ break;
266
+ case IMAGETYPE_XBM:
267
+ $img = imagecreatefromxbm($file['tmp_name']);
268
+ break;
269
+ default:
270
+ return;
271
+ }
272
+ imagepng($img, $file['tmp_name']);
273
+ imagedestroy($img);
274
+ }
275
+ }
276
+
277
+ /**
278
+ * Retrieve xmlconnect images skin url
279
+ *
280
+ * @param string $name
281
+ * @return string
282
+ */
283
+ public function getSkinImagesUrl($name = null)
284
+ {
285
+ return Mage::getDesign()->getSkinUrl('images/xmlconnect/' . $name);
286
+ }
287
+
288
+ /**
289
+ * Return CustomSizeDirPrefix
290
+ *
291
+ * @return string
292
+ */
293
+ public function getCustomSizeDirPrefix()
294
+ {
295
+ return $this->_getScreenSize() . DS . 'custom';
296
+ }
297
+
298
+ /**
299
+ * Return FileDefaultSizeSuffixAsUrl
300
+ *
301
+ * @param string $fileName
302
+ * @return string
303
+ */
304
+ public function getFileDefaultSizeSuffixAsUrl($fileName)
305
+ {
306
+ return 'custom' . '/' . $this->_getScreenSize() . '/' . basename($fileName);
307
+ }
308
+
309
+ /**
310
+ * Return getFileCustomDirSuffixAsUrl
311
+ *
312
+ * @param string $confPath
313
+ * @param string $fileName
314
+ * @return string
315
+ */
316
+ public function getFileCustomDirSuffixAsUrl($confPath, $fileName)
317
+ {
318
+ return 'custom'
319
+ . '/'
320
+ . $this->_getScreenSize()
321
+ . '/'
322
+ . basename($this->_getResizedFilename($confPath, $fileName));
323
+ }
324
+
325
+ /**
326
+ * Return correct size for given $imageName and device screen_size
327
+ *
328
+ * @param string $imageName
329
+ * @return int
330
+ */
331
+ public function getImageSizeForContent($imageName)
332
+ {
333
+ if (!isset($this->_content)) {
334
+ $imageLimits = $this->getImageLimits($this->_getScreenSize());
335
+ if (($imageLimits['content']) && is_array($imageLimits['content'])) {
336
+ $this->_content = $imageLimits['content'];
337
+ } else {
338
+ $this->_content = array();
339
+ }
340
+ }
341
+ $size = isset($this->_content[$imageName]) ? (int) $this->_content[$imageName] : 0;
342
+ return $size;
343
+ }
344
+
345
+ /**
346
+ * Return setting for interface images (image size limits)
347
+ *
348
+ * @return array
349
+ */
350
+ public function getInterfaceImageLimits()
351
+ {
352
+ if (!isset($this->_interface)) {
353
+ $imageLimits = $this->getImageLimits($this->_getScreenSize());
354
+ $this->_interface = $imageLimits['interface'];
355
+ }
356
+ return $this->_interface;
357
+ }
358
+
359
+ /**
360
+ * Return correct size for given $imageName and device screen_size
361
+ *
362
+ * @param string $imagePath
363
+ * @return int
364
+ */
365
+ public function getImageSizeForInterface($imagePath)
366
+ {
367
+ if (!isset($this->_interfacePath[$imagePath])) {
368
+ /** @var $app Mage_XmlConnect_Model_Application */
369
+ $app = Mage::helper('xmlconnect')->getApplication();
370
+ if (!$app) {
371
+ return 0;
372
+ } else {
373
+ $imageLimits = $this->getImageLimits($this->_getScreenSize());
374
+ $size = $this->findPath($imageLimits, $imagePath);
375
+ $this->_interfacePath[$imagePath] = $size;
376
+ }
377
+ }
378
+ $size = isset($this->_interfacePath[$imagePath]) ? (int) $this->_interfacePath[$imagePath] : 0;
379
+ return $size;
380
+ }
381
+
382
+ /**
383
+ * Return the filesystem path to XmlConnect media files
384
+ *
385
+ * @param string $path Right part of the path
386
+ * @return string
387
+ */
388
+ public function getMediaPath($path = '')
389
+ {
390
+ $path = trim($path);
391
+ $result = Mage::getBaseDir('media') . DS . 'xmlconnect';
392
+
393
+ if (!empty($path)) {
394
+ if (strpos($path, DS) === 0) {
395
+ $path = substr($path, 1);
396
+ }
397
+ $result .= DS . $path;
398
+ }
399
+ return $result;
400
+ }
401
+
402
+ /**
403
+ * Return Url for media image
404
+ *
405
+ * @param string $image
406
+ * @return string
407
+ */
408
+ public function getMediaUrl($image = '')
409
+ {
410
+ $image = trim($image);
411
+ $result = Mage::getBaseUrl('media') . 'xmlconnect';
412
+
413
+ if (!empty($image)) {
414
+ if (strpos($image, '/') === 0) {
415
+ $image = substr($image, 1);
416
+ }
417
+ $result .= '/' . $image;
418
+ }
419
+ return $result;
420
+ }
421
+
422
+ /**
423
+ * Return URL for default design image
424
+ *
425
+ * @param string $image
426
+ * @return string
427
+ */
428
+ public function getDefaultDesignUrl($image = '')
429
+ {
430
+ return $this->getSkinImagesUrl($this->getDefaultDesignSuffixAsUrl($image));
431
+ }
432
+
433
+ /**
434
+ * Return suffix as URL for default design image
435
+ *
436
+ * @param string $image
437
+ * @return string
438
+ */
439
+ public function getDefaultDesignSuffixAsUrl($image = '')
440
+ {
441
+ return 'design_default/' . trim(ltrim($image, '/'));
442
+ }
443
+
444
+ /**
445
+ * Retrieve thumbnail image url
446
+ *
447
+ * @param string $imageUrl
448
+ * @param int $width
449
+ * @param int $height
450
+ * @return string|null
451
+ */
452
+ public function getCustomSizeImageUrl($imageUrl, $width = 100, $height = 100)
453
+ {
454
+ $screenSize = $width . 'x' . $height;
455
+ $customDir = $this->getMediaPath('custom' . DS . $screenSize);
456
+ $this->_verifyDirExist($customDir);
457
+ $imageUrl = explode('/', $imageUrl);
458
+ $file = $imageUrl[count($imageUrl)-1];
459
+ $filePath = $this->getDefaultSizeUploadDir() . DS . $file;
460
+ if (!file_exists($customDir . DS . $file)) {
461
+ $image = new Varien_Image($filePath);
462
+ $widthOriginal = $image->getOriginalWidth();
463
+ $heightOriginal = $image->getOriginalHeight();
464
+
465
+ if ($width != $widthOriginal) {
466
+ $widthOriginal = $width;
467
+ }
468
+
469
+ if ($height != $heightOriginal) {
470
+ $heightOriginal = $height;
471
+ }
472
+
473
+ if (($widthOriginal != $image->getOriginalWidth()) ||
474
+ ($heightOriginal != $image->getOriginalHeight()) ) {
475
+ $image->keepTransparency(true);
476
+ $image->keepFrame(true);
477
+ $image->keepAspectRatio(true);
478
+ $image->backgroundColor(array(255, 255, 255));
479
+ $image->resize($widthOriginal, $heightOriginal);
480
+ $image->save($customDir, basename($file));
481
+ }
482
+ }
483
+ return $this->getMediaUrl("custom/{$screenSize}/" . basename($file));
484
+ }
485
+
486
+ /**
487
+ * Ensure correct $screenSize value
488
+ *
489
+ * @param string $screenSize
490
+ * @return string
491
+ */
492
+ public function filterScreenSize($screenSize)
493
+ {
494
+ $screenSize = preg_replace('/[^0-9A-z_]/', '', $screenSize);
495
+ if (isset($this->_imageLimits[$screenSize])) {
496
+ return $screenSize;
497
+ }
498
+ $screenSizeExplodeArray = explode(self::XMLCONNECT_GLUE, $screenSize);
499
+ $version = '';
500
+ switch (count($screenSizeExplodeArray)) {
501
+ case 2:
502
+ $version = $screenSizeExplodeArray[1];
503
+ case 1:
504
+ $resolution = $screenSizeExplodeArray[0];
505
+ break;
506
+ default:
507
+ $resolution = Mage_XmlConnect_Model_Application::APP_SCREEN_SIZE_DEFAULT;
508
+ break;
509
+ }
510
+
511
+ $sourcePath = empty($version) ? Mage_XmlConnect_Model_Application::APP_SCREEN_SOURCE_DEFAULT : $version;
512
+ $xmlPath = 'screen_size/' . self::XMLCONNECT_GLUE . $resolution . '/' . $sourcePath . '/source';
513
+
514
+ $source = Mage::getStoreConfig($xmlPath);
515
+ if (!empty($source)) {
516
+ $screenSize = $resolution . (empty($version) ? '' : self::XMLCONNECT_GLUE . $version);
517
+ } else {
518
+ $screenSize = Mage_XmlConnect_Model_Application::APP_SCREEN_SIZE_DEFAULT;
519
+ }
520
+ return $screenSize;
521
+ }
522
+
523
+ /**
524
+ * Return correct size array for given device screen_size(320x480/640x960_a)
525
+ *
526
+ * @param string $screenSize
527
+ * @return array
528
+ */
529
+ public function getImageLimits($screenSize = Mage_XmlConnect_Model_Application::APP_SCREEN_SIZE_DEFAULT)
530
+ {
531
+ $defaultScreenSize = Mage_XmlConnect_Model_Application::APP_SCREEN_SIZE_DEFAULT;
532
+ $defaultScreenSource = Mage_XmlConnect_Model_Application::APP_SCREEN_SOURCE_DEFAULT;
533
+
534
+ $screenSize = preg_replace('/[^0-9A-z_]/', '', $screenSize);
535
+ if (isset($this->_imageLimits[$screenSize])) {
536
+ return $this->_imageLimits[$screenSize];
537
+ }
538
+
539
+ $screenSizeExplodeArray = explode(self::XMLCONNECT_GLUE, $screenSize);
540
+ $version = '';
541
+ switch (count($screenSizeExplodeArray)) {
542
+ case 2:
543
+ $version = $screenSizeExplodeArray[1];
544
+ case 1:
545
+ $resolution = $screenSizeExplodeArray[0];
546
+ break;
547
+ default:
548
+ $resolution = $defaultScreenSize;
549
+ break;
550
+ }
551
+
552
+ $sourcePath = empty($version) ? $defaultScreenSource : $version;
553
+ $xmlPath = 'screen_size/' . self::XMLCONNECT_GLUE . $resolution . '/' . $sourcePath;
554
+
555
+ $root = Mage::getStoreConfig($xmlPath);
556
+ $updates = array();
557
+
558
+ if (!empty($root)) {
559
+ $screenSize = $resolution . (empty($version) ? '' : self::XMLCONNECT_GLUE . $version);
560
+ $source = !empty($root['source']) ? $root['source'] : $defaultScreenSource;
561
+ $updates = isset($root['updates']) && is_array($root['updates']) ? $root['updates'] : array();
562
+ } else {
563
+ $screenSize = $defaultScreenSize;
564
+ $source = $defaultScreenSource;
565
+ }
566
+
567
+ $imageLimits = Mage::getStoreConfig('screen_size/' . $source);
568
+ if (!is_array($imageLimits)) {
569
+ $imageLimits = Mage::getStoreConfig('screen_size/default');
570
+ }
571
+
572
+ foreach ($updates as $update) {
573
+ $path = $update['path'];
574
+ $function = $update['function'];
575
+ switch ($function) {
576
+ case 'zoom':
577
+ $data = $update['data'];
578
+ $target =& $this->findPath($imageLimits, $path);
579
+ if (is_array($target)) {
580
+ array_walk_recursive($target, array($this, '_zoom'), $data);
581
+ } else {
582
+ $this->_zoom($target, null, $data);
583
+ }
584
+ break;
585
+ case 'update':
586
+ $data = $update['data'];
587
+ $target =& $this->findPath($imageLimits, $path);
588
+ $target = $data;
589
+ break;
590
+ case 'insert':
591
+ $data = $update['data'];
592
+ $target =& $this->findPath($imageLimits, $path);
593
+ if (($target !== null) && (is_array($target)) && (is_array($data))) {
594
+ foreach ($data as $key => $val) {
595
+ $target[$key] = $val;
596
+ }
597
+ }
598
+ break;
599
+ case 'delete':
600
+ $data = $update['data'];
601
+ $target =& $this->findPath($imageLimits, $path);
602
+ if (isset($target[$data])) {
603
+ unset($target[$data]);
604
+ }
605
+ break;
606
+ default:
607
+ break;
608
+ }
609
+
610
+ }
611
+ if (!is_array($imageLimits)) {
612
+ $imageLimits = array();
613
+ }
614
+
615
+ $this->_imageLimits[$screenSize] = $imageLimits;
616
+ return $imageLimits;
617
+ }
618
+
619
+ /**
620
+ * Return reference to the $path in $array
621
+ *
622
+ * @param array &$array
623
+ * @param string $path
624
+ * @return mixed reference
625
+ */
626
+ public function &findPath(&$array, $path)
627
+ {
628
+ $target =& $array;
629
+ if ($path !== '/') {
630
+ $pathArray = explode('/', $path);
631
+ foreach ($pathArray as $node) {
632
+ if (is_array($target) && isset($target[$node])) {
633
+ $target =& $target[$node];
634
+ } else {
635
+ $targetNull = null;
636
+ return $targetNull;
637
+ }
638
+ }
639
+ }
640
+ return $target;
641
+ }
642
+
643
+ /**
644
+ * Multiply given $item by $value if non array
645
+ *
646
+ * @param mixed $item (argument to change)
647
+ * @param mixed $key (used with array_walk_recursive function as a key of given array)
648
+ * @param string $value (contains float)
649
+ * @return void
650
+ */
651
+ protected function _zoom(&$item, $key, $value)
652
+ {
653
+ if (is_string($item)) {
654
+ $item = (int) round($item * $value);
655
+ }
656
+ }
657
+
658
+ /**
659
+ * Ensure $dir exists (if not then create one)
660
+ *
661
+ * @param string $dir
662
+ * @throw Mage_Core_Exception
663
+ */
664
+ protected function _verifyDirExist($dir)
665
+ {
666
+ try {
667
+ $ioFile = new Varien_Io_File();
668
+ $ioFile->checkAndCreateFolder($dir);
669
+ } catch (Exception $e) {
670
+ Mage::throwException($e->getMessage());
671
+ }
672
+ }
673
+
674
+ /**
675
+ * Return customSizeUploadDir path
676
+ *
677
+ * @param string $screenSize
678
+ * @return string
679
+ */
680
+ public function getCustomSizeUploadDir($screenSize)
681
+ {
682
+ $screenSize = $this->filterScreenSize($screenSize);
683
+ $customDir = $this->getMediaPath('custom' . DS . $screenSize);
684
+ $this->_verifyDirExist($customDir);
685
+ return $customDir;
686
+ }
687
+
688
+ /**
689
+ * Return originalSizeUploadDir path
690
+ *
691
+ * @return string
692
+ */
693
+ public function getOriginalSizeUploadDir()
694
+ {
695
+ $dir = $this->getMediaPath('original');
696
+ $this->_verifyDirExist($dir);
697
+ return $dir;
698
+ }
699
+
700
+ /**
701
+ * Return oldUpload dir path (media/xmlconnect)
702
+ *
703
+ * @return string
704
+ */
705
+ public function getOldUploadDir()
706
+ {
707
+ $dir = $this->getMediaPath();
708
+ $this->_verifyDirExist($dir);
709
+ return $dir;
710
+ }
711
+
712
+ /**
713
+ * Return default size upload dir path
714
+ *
715
+ * @return string
716
+ */
717
+ public function getDefaultSizeUploadDir()
718
+ {
719
+ return $this->getCustomSizeUploadDir(Mage_XmlConnect_Model_Application::APP_SCREEN_SIZE_DEFAULT);
720
+ }
721
+
722
+ /**
723
+ * Return array for interface images paths in the config
724
+ *
725
+ * @return array
726
+ */
727
+ public function getInterfaceImagesPathsConf()
728
+ {
729
+ if (!isset($this->_confPaths)) {
730
+ $this->_confPaths = array();
731
+ $paths = $this->getInterfaceImagesPaths();
732
+ if (is_array($paths)) {
733
+ $len = strlen('conf/native/');
734
+ while (list($path,) = each($paths)) {
735
+ $this->_confPaths[$path] = substr($path, $len);
736
+ }
737
+ }
738
+ }
739
+ return $this->_confPaths;
740
+ }
741
+
742
+ /**
743
+ * Return
744
+ * - default interface image path for specified $imagePath
745
+ * - array of image paths
746
+ *
747
+ * @param string $imagePath
748
+ * @return array|string
749
+ */
750
+ public function getInterfaceImagesPaths($imagePath = null)
751
+ {
752
+ $paths = array (
753
+ 'conf/native/navigationBar/icon' => 'smallIcon_1_6.png',
754
+ 'conf/native/body/bannerImage' => 'banner_1_2.png',
755
+ 'conf/native/body/bannerIpadLandscapeImage' => 'banner_ipad_l.png',
756
+ 'conf/native/body/bannerIpadImage' => 'banner_ipad.png',
757
+ 'conf/native/body/bannerAndroidImage' => 'banner_android.png',
758
+ 'conf/native/body/backgroundImage' => 'accordion_open.png',
759
+ 'conf/native/body/backgroundIpadLandscapeImage' => 'accordion_open_ipad_l.png',
760
+ 'conf/native/body/backgroundIpadPortraitImage' => 'accordion_open_ipad_p.png',
761
+ 'conf/native/body/backgroundAndroidLandscapeImage' => 'accordion_open_android_l.png',
762
+ 'conf/native/body/backgroundAndroidPortraitImage' => 'accordion_open_android_p.png',
763
+ );
764
+ if ($imagePath == null) {
765
+ return $paths;
766
+ } else if (isset($paths[$imagePath])) {
767
+ return $paths[$imagePath];
768
+ } else {
769
+ return null;
770
+ }
771
+ }
772
+
773
+ /**
774
+ * Check image and get full file path
775
+ *
776
+ * @param string &$icon
777
+ * @return bool
778
+ */
779
+ public function checkAndGetImagePath(&$icon)
780
+ {
781
+ $icon = basename($icon);
782
+ if (is_file($this->getDefaultSizeUploadDir() . DS . $icon)) {
783
+ $icon = $this->getDefaultSizeUploadDir() . DS . $icon;
784
+ return true;
785
+ }
786
+ return false;
787
+ }
788
+ }
app/code/core/Mage/XmlConnect/Helper/Ipad.php ADDED
@@ -0,0 +1,750 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect device helper for iPad
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Helper_Ipad extends Mage_Core_Helper_Abstract
35
+ {
36
+ /**
37
+ * Submission title length
38
+ */
39
+ const SUBMISSION_TITLE_LENGTH = 200;
40
+
41
+ /**
42
+ * Submission description length
43
+ */
44
+ const SUBMISSION_DESCRIPTION_LENGTH = 500;
45
+
46
+ /**
47
+ * Ipad landscape orientation identificator
48
+ */
49
+ const ORIENTATION_LANDSCAPE = 'landscape';
50
+
51
+ /**
52
+ * Ipad portrait orientation identificator
53
+ */
54
+ const ORIENTATION_PORTRAIT = 'portrait';
55
+
56
+ /**
57
+ * Ipad portrait preview banner widht
58
+ */
59
+ const PREVIEW_PORTRAIT_BANNER_WIDTH = 350;
60
+
61
+ /**
62
+ * Ipad portrait preview banner image height
63
+ */
64
+ const PREVIEW_PORTRAIT_BANNER_HEIGHT = 135;
65
+
66
+ /**
67
+ * Ipad landscape preview banner widht
68
+ */
69
+ const PREVIEW_LANDSCAPE_BANNER_WIDTH = 467;
70
+
71
+ /**
72
+ * Ipad landscape preview banner image height
73
+ */
74
+ const PREVIEW_LANDSCAPE_BANNER_HEIGHT = 157;
75
+
76
+ /**
77
+ * Ipad landscape orientation preview image widht
78
+ */
79
+ const PREVIEW_LANDSCAPE_BACKGROUND_WIDTH = 467;
80
+
81
+ /**
82
+ * Ipad landscape orientation preview image height
83
+ */
84
+ const PREVIEW_LANDSCAPE_BACKGROUND_HEIGHT = 321;
85
+
86
+ /**
87
+ * Ipad portrait orientation preview image widht
88
+ */
89
+ const PREVIEW_PORTRAIT_BACKGROUND_WIDTH = 350;
90
+
91
+ /**
92
+ * Ipad portrait orientation preview image height
93
+ */
94
+ const PREVIEW_PORTRAIT_BACKGROUND_HEIGHT = 438;
95
+
96
+ /**
97
+ * Submit images that are stored in "params" field of history table
98
+ *
99
+ * @var array
100
+ */
101
+ protected $_imageIds = array('icon',
102
+ 'ipad_loader_portrait_image',
103
+ 'ipad_loader_landscape_image',
104
+ 'ipad_logo',
105
+ 'big_logo'
106
+ );
107
+
108
+ /**
109
+ * Country field renderer
110
+ *
111
+ * @var Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Renderer_Country_Istore
112
+ */
113
+ protected $_countryRenderer = null;
114
+
115
+ /**
116
+ * Get submit images that are required for application submit
117
+ *
118
+ * @return array
119
+ */
120
+ public function getSubmitImages()
121
+ {
122
+ return $this->_imageIds;
123
+ }
124
+
125
+ /**
126
+ * Get default application tabs
127
+ *
128
+ * @return array
129
+ */
130
+ public function getDefaultDesignTabs()
131
+ {
132
+ if (!isset($this->_tabs)) {
133
+ $this->_tabs = array(
134
+ array(
135
+ 'label' => Mage::helper('xmlconnect')->__('Home'),
136
+ 'image' => 'tab_home.png',
137
+ 'action' => 'Home',
138
+ ),
139
+ array(
140
+ 'label' => Mage::helper('xmlconnect')->__('Search'),
141
+ 'image' => 'tab_search.png',
142
+ 'action' => 'Search',
143
+ ),
144
+ array(
145
+ 'label' => Mage::helper('xmlconnect')->__('Cart'),
146
+ 'image' => 'tab_cart.png',
147
+ 'action' => 'Cart',
148
+ ),
149
+ array(
150
+ 'label' => Mage::helper('xmlconnect')->__('Account'),
151
+ 'image' => 'tab_account_ipad.png',
152
+ 'action' => 'Account',
153
+ ),
154
+ );
155
+ }
156
+ return $this->_tabs;
157
+ }
158
+
159
+ /**
160
+ * Default application configuration
161
+ *
162
+ * @return array
163
+ */
164
+ public function getDefaultConfiguration()
165
+ {
166
+ return array(
167
+ 'native' => array(
168
+ 'body' => array(
169
+ 'backgroundColor' => '#ABABAB',
170
+ 'scrollBackgroundColor' => '#EDEDED',
171
+ ),
172
+ 'itemActions' => array(
173
+ 'relatedProductBackgroundColor' => '#404040',
174
+ ),
175
+ 'fonts' => array(
176
+ 'Title1' => array(
177
+ 'name' => 'HelveticaNeue-Bold',
178
+ 'size' => '20',
179
+ 'color' => '#FEFEFE',
180
+ ),
181
+ 'Title2' => array(
182
+ 'name' => 'HelveticaNeue-Bold',
183
+ 'size' => '15',
184
+ 'color' => '#222222',
185
+ ),
186
+ 'Title3' => array(
187
+ 'name' => 'HelveticaNeue',
188
+ 'size' => '14',
189
+ 'color' => '#222222',
190
+ ),
191
+ 'Title4' => array(
192
+ 'name' => 'HelveticaNeue',
193
+ 'size' => '12',
194
+ 'color' => '#FFFFFF',
195
+ ),
196
+ 'Title5' => array(
197
+ 'name' => 'HelveticaNeue-Bold',
198
+ 'size' => '18',
199
+ 'color' => '#d55000',
200
+ ),
201
+ 'Title6' => array(
202
+ 'name' => 'HelveticaNeue-Bold',
203
+ 'size' => '16',
204
+ 'color' => '#FFFFFF',
205
+ ),
206
+ 'Title7' => array(
207
+ 'name' => 'HelveticaNeue-Bold',
208
+ 'size' => '13',
209
+ 'color' => '#222222',
210
+ ),
211
+ 'Title8' => array(
212
+ 'name' => 'HelveticaNeue-Bold',
213
+ 'size' => '13',
214
+ 'color' => '#FFFFFF',
215
+ ),
216
+ 'Title9' => array(
217
+ 'name' => 'HelveticaNeue-Bold',
218
+ 'size' => '18',
219
+ 'color' => '#FFFFFF',
220
+ ),
221
+ 'Text1' => array(
222
+ 'name' => 'HelveticaNeue-Bold',
223
+ 'size' => '14',
224
+ 'color' => '#222222',
225
+ ),
226
+ 'Text2' => array(
227
+ 'name' => 'HelveticaNeue',
228
+ 'size' => '12',
229
+ 'color' => '#222222',
230
+ ),
231
+ ),
232
+ ),
233
+ );
234
+ }
235
+
236
+ /**
237
+ * List of allowed fonts for iPad application
238
+ *
239
+ * @return array
240
+ */
241
+ public function getFontList()
242
+ {
243
+ return array(
244
+ array(
245
+ 'value' => 'HiraKakuProN-W3',
246
+ 'label' => 'HiraKakuProN-W3',
247
+ ),
248
+ array(
249
+ 'value' => 'Courier',
250
+ 'label' => 'Courier',
251
+ ),
252
+ array(
253
+ 'value' => 'Courier-BoldOblique',
254
+ 'label' => 'Courier-BoldOblique',
255
+ ),
256
+ array(
257
+ 'value' => 'Courier-Oblique',
258
+ 'label' => 'Courier-Oblique',
259
+ ),
260
+ array(
261
+ 'value' => 'Courier-Bold',
262
+ 'label' => 'Courier-Bold',
263
+ ),
264
+ array(
265
+ 'value' => 'ArialMT',
266
+ 'label' => 'ArialMT',
267
+ ),
268
+ array(
269
+ 'value' => 'Arial-BoldMT',
270
+ 'label' => 'Arial-BoldMT',
271
+ ),
272
+ array(
273
+ 'value' => 'Arial-BoldItalicMT',
274
+ 'label' => 'Arial-BoldItalicMT',
275
+ ),
276
+ array(
277
+ 'value' => 'Arial-ItalicMT',
278
+ 'label' => 'Arial-ItalicMT',
279
+ ),
280
+ array(
281
+ 'value' => 'STHeitiTC-Light',
282
+ 'label' => 'STHeitiTC-Light',
283
+ ),
284
+ array(
285
+ 'value' => 'STHeitiTC-Medium',
286
+ 'label' => 'STHeitiTC-Medium',
287
+ ),
288
+ array(
289
+ 'value' => 'AppleGothic',
290
+ 'label' => 'AppleGothic',
291
+ ),
292
+ array(
293
+ 'value' => 'CourierNewPS-BoldMT',
294
+ 'label' => 'CourierNewPS-BoldMT',
295
+ ),
296
+ array(
297
+ 'value' => 'CourierNewPS-ItalicMT',
298
+ 'label' => 'CourierNewPS-ItalicMT',
299
+ ),
300
+ array(
301
+ 'value' => 'CourierNewPS-BoldItalicMT',
302
+ 'label' => 'CourierNewPS-BoldItalicMT',
303
+ ),
304
+ array(
305
+ 'value' => 'CourierNewPSMT',
306
+ 'label' => 'CourierNewPSMT',
307
+ ),
308
+ array(
309
+ 'value' => 'Zapfino',
310
+ 'label' => 'Zapfino',
311
+ ),
312
+ array(
313
+ 'value' => 'HiraKakuProN-W6',
314
+ 'label' => 'HiraKakuProN-W6',
315
+ ),
316
+ array(
317
+ 'value' => 'ArialUnicodeMS',
318
+ 'label' => 'ArialUnicodeMS',
319
+ ),
320
+ array(
321
+ 'value' => 'STHeitiSC-Medium',
322
+ 'label' => 'STHeitiSC-Medium',
323
+ ),
324
+ array(
325
+ 'value' => 'STHeitiSC-Light',
326
+ 'label' => 'STHeitiSC-Light',
327
+ ),
328
+ array(
329
+ 'value' => 'AmericanTypewriter',
330
+ 'label' => 'AmericanTypewriter',
331
+ ),
332
+ array(
333
+ 'value' => 'AmericanTypewriter-Bold',
334
+ 'label' => 'AmericanTypewriter-Bold',
335
+ ),
336
+ array(
337
+ 'value' => 'Helvetica-Oblique',
338
+ 'label' => 'Helvetica-Oblique',
339
+ ),
340
+ array(
341
+ 'value' => 'Helvetica-BoldOblique',
342
+ 'label' => 'Helvetica-BoldOblique',
343
+ ),
344
+ array(
345
+ 'value' => 'Helvetica',
346
+ 'label' => 'Helvetica',
347
+ ),
348
+ array(
349
+ 'value' => 'Helvetica-Bold',
350
+ 'label' => 'Helvetica-Bold',
351
+ ),
352
+ array(
353
+ 'value' => 'MarkerFelt-Thin',
354
+ 'label' => 'MarkerFelt-Thin',
355
+ ),
356
+ array(
357
+ 'value' => 'HelveticaNeue',
358
+ 'label' => 'HelveticaNeue',
359
+ ),
360
+ array(
361
+ 'value' => 'HelveticaNeue-Bold',
362
+ 'label' => 'HelveticaNeue-Bold',
363
+ ),
364
+ array(
365
+ 'value' => 'DBLCDTempBlack',
366
+ 'label' => 'DBLCDTempBlack',
367
+ ),
368
+ array(
369
+ 'value' => 'Verdana-Bold',
370
+ 'label' => 'Verdana-Bold',
371
+ ),
372
+ array(
373
+ 'value' => 'Verdana-BoldItalic',
374
+ 'label' => 'Verdana-BoldItalic',
375
+ ),
376
+ array(
377
+ 'value' => 'Verdana',
378
+ 'label' => 'Verdana',
379
+ ),
380
+ array(
381
+ 'value' => 'Verdana-Italic',
382
+ 'label' => 'Verdana-Italic',
383
+ ),
384
+ array(
385
+ 'value' => 'TimesNewRomanPSMT',
386
+ 'label' => 'TimesNewRomanPSMT',
387
+ ),
388
+ array(
389
+ 'value' => 'TimesNewRomanPS-BoldMT',
390
+ 'label' => 'TimesNewRomanPS-BoldMT',
391
+ ),
392
+ array(
393
+ 'value' => 'TimesNewRomanPS-BoldItalicMT',
394
+ 'label' => 'TimesNewRomanPS-BoldItalicMT',
395
+ ),
396
+ array(
397
+ 'value' => 'TimesNewRomanPS-ItalicMT',
398
+ 'label' => 'TimesNewRomanPS-ItalicMT',
399
+ ),
400
+ array(
401
+ 'value' => 'Georgia-Bold',
402
+ 'label' => 'Georgia-Bold',
403
+ ),
404
+ array(
405
+ 'value' => 'Georgia',
406
+ 'label' => 'Georgia',
407
+ ),
408
+ array(
409
+ 'value' => 'Georgia-BoldItalic',
410
+ 'label' => 'Georgia-BoldItalic',
411
+ ),
412
+ array(
413
+ 'value' => 'Georgia-Italic',
414
+ 'label' => 'Georgia-Italic',
415
+ ),
416
+ array(
417
+ 'value' => 'STHeitiJ-Medium',
418
+ 'label' => 'STHeitiJ-Medium',
419
+ ),
420
+ array(
421
+ 'value' => 'STHeitiJ-Light',
422
+ 'label' => 'STHeitiJ-Light',
423
+ ),
424
+ array(
425
+ 'value' => 'ArialRoundedMTBold',
426
+ 'label' => 'ArialRoundedMTBold',
427
+ ),
428
+ array(
429
+ 'value' => 'TrebuchetMS-Italic',
430
+ 'label' => 'TrebuchetMS-Italic',
431
+ ),
432
+ array(
433
+ 'value' => 'TrebuchetMS',
434
+ 'label' => 'TrebuchetMS',
435
+ ),
436
+ array(
437
+ 'value' => 'Trebuchet-BoldItalic',
438
+ 'label' => 'Trebuchet-BoldItalic',
439
+ ),
440
+ array(
441
+ 'value' => 'TrebuchetMS-Bold',
442
+ 'label' => 'TrebuchetMS-Bold',
443
+ ),
444
+ array(
445
+ 'value' => 'STHeitiK-Medium',
446
+ 'label' => 'STHeitiK-Medium',
447
+ ),
448
+ array(
449
+ 'value' => 'STHeitiK-Light',
450
+ 'label' => 'STHeitiK-Light',
451
+ ),
452
+ );
453
+ }
454
+
455
+ /**
456
+ * List of allowed font sizes for iPad application
457
+ *
458
+ * @return array
459
+ */
460
+ public function getFontSizes()
461
+ {
462
+ $result = array();
463
+ for ($i = 6; $i < 32; $i++) {
464
+ $result[] = array(
465
+ 'value' => $i,
466
+ 'label' => $i . ' pt',
467
+ );
468
+ }
469
+ return $result;
470
+ }
471
+
472
+ /**
473
+ * Get list of countries that allowed in Itunes by Apple Store for Ipad
474
+ * (we get info from Iphone helper)
475
+ *
476
+ * @return array
477
+ */
478
+ public function getItunesCountriesArray()
479
+ {
480
+ return Mage::helper('xmlconnect/iphone')->getItunesCountriesArray();
481
+ }
482
+
483
+ /**
484
+ * Validate submit application data
485
+ *
486
+ * @param array $params
487
+ * @return array
488
+ */
489
+ public function validateSubmit($params)
490
+ {
491
+ $errors = array();
492
+
493
+ if (!Zend_Validate::is(isset($params['title']) ? $params['title'] : null, 'NotEmpty')) {
494
+ $errors[] = Mage::helper('xmlconnect')->__('Please enter the Title.');
495
+ }
496
+
497
+ if (isset($params['title'])) {
498
+ $titleLength = self::SUBMISSION_TITLE_LENGTH;
499
+ $strRules = array('min' => '1', 'max' => $titleLength);
500
+ if (!Zend_Validate::is($params['title'], 'StringLength', $strRules)) {
501
+ $errors[] = Mage::helper('xmlconnect')->__('"Title" is more than %d characters long', $strRules['max']);
502
+ }
503
+ }
504
+
505
+ if (!Zend_Validate::is(isset($params['description']) ? $params['description'] : null, 'NotEmpty')) {
506
+ $errors[] = Mage::helper('xmlconnect')->__('Please enter the Description.');
507
+ }
508
+
509
+ if (isset($params['description'])) {
510
+ $descriptionLength = self::SUBMISSION_DESCRIPTION_LENGTH;
511
+ $strRules = array('min' => '1', 'max' => $descriptionLength);
512
+ if (!Zend_Validate::is($params['title'], 'StringLength', $strRules)) {
513
+ $errors[] = Mage::helper('xmlconnect')->__('"Description" is more than %d characters long', $strRules['max']);
514
+ }
515
+ }
516
+
517
+ if (!Zend_Validate::is(isset($params['copyright']) ? $params['copyright'] : null, 'NotEmpty')) {
518
+ $errors[] = Mage::helper('xmlconnect')->__('Please enter the Copyright.');
519
+ }
520
+
521
+ if (empty($params['price_free'])) {
522
+ if (!Zend_Validate::is(isset($params['price']) ? $params['price'] : null, 'NotEmpty')) {
523
+ $errors[] = Mage::helper('xmlconnect')->__('Please enter the Price.');
524
+ }
525
+ }
526
+
527
+ if (!Zend_Validate::is(isset($params['country']) ? $params['country'] : null, 'NotEmpty')) {
528
+ $errors[] = Mage::helper('xmlconnect')->__('Please select at least one country.');
529
+ }
530
+
531
+ $keyLenght = Mage_XmlConnect_Model_Application::APP_MAX_KEY_LENGTH;
532
+ if (Mage::helper('xmlconnect')->getApplication()->getIsResubmitAction()) {
533
+ if (isset($params['resubmission_activation_key'])) {
534
+ $resubmissionKey = $params['resubmission_activation_key'];
535
+ } else {
536
+ $resubmissionKey = null;
537
+ }
538
+ if (!Zend_Validate::is($resubmissionKey, 'NotEmpty')) {
539
+ $errors[] = Mage::helper('xmlconnect')->__('Please enter the Resubmission Key.');
540
+ } elseif (!Zend_Validate::is($resubmissionKey, 'StringLength', array(1, $keyLenght))) {
541
+ $errors[] = Mage::helper('xmlconnect')->__('Submit App failure. Invalid activation key provided');
542
+ }
543
+ } else {
544
+ $key = isset($params['key']) ? $params['key'] : null;
545
+ if (!Zend_Validate::is($key, 'NotEmpty')) {
546
+ $errors[] = Mage::helper('xmlconnect')->__('Please enter the Activation Key.');
547
+ } elseif (!Zend_Validate::is($key, 'StringLength', array(1, $keyLenght))) {
548
+ $errors[] = Mage::helper('xmlconnect')->__('Submit App failure. Invalid activation key provided');
549
+ }
550
+ }
551
+ return $errors;
552
+ }
553
+
554
+ /**
555
+ * Check config for valid values
556
+ *
557
+ * @param array $native
558
+ * @return array
559
+ */
560
+ public function validateConfig($native)
561
+ {
562
+ $errors = array();
563
+ if ($native === false
564
+ || (!isset($native['navigationBar']['icon'])
565
+ || !Zend_Validate::is($native['navigationBar']['icon'], 'NotEmpty')
566
+ )
567
+ ) {
568
+ $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "Logo in Header" field from Design Tab.');
569
+ }
570
+
571
+ if (!Mage::helper('xmlconnect')->validateConfFieldNotEmpty('bannerIpadLandscapeImage', $native)) {
572
+ $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "Banner on Home Screen (landscape mode)" field from Design Tab.');
573
+ }
574
+
575
+ if (!Mage::helper('xmlconnect')->validateConfFieldNotEmpty('bannerIpadImage', $native)) {
576
+ $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "Banner on Home Screen (portrait mode)" field from Design Tab.');
577
+ }
578
+
579
+ if (!Mage::helper('xmlconnect')->validateConfFieldNotEmpty('backgroundIpadLandscapeImage', $native)) {
580
+ $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "App Background (landscape mode)" field from Design Tab.');
581
+ }
582
+
583
+ if (!Mage::helper('xmlconnect')->validateConfFieldNotEmpty('backgroundIpadPortraitImage', $native)) {
584
+ $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "App Background (portrait mode)" field from Design Tab.');
585
+ }
586
+
587
+ return $errors;
588
+ }
589
+
590
+ /**
591
+ * Get renderer for submission country
592
+ *
593
+ * @return Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Renderer_Country_Istore
594
+ */
595
+ public function getCountryRenderer()
596
+ {
597
+ if (empty($this->_countryRenderer)) {
598
+ $renderer = 'xmlconnect/adminhtml_mobile_submission_renderer_country_'
599
+ . Mage_XmlConnect_Helper_Iphone::SUBMISSION_COUNTRY_RENDERER;
600
+ $this->_countryRenderer = Mage::app()->getLayout()->createBlock($renderer);
601
+ }
602
+ return $this->_countryRenderer;
603
+ }
604
+
605
+ /**
606
+ * Get label for submission country
607
+ *
608
+ * @return string
609
+ */
610
+ public function getCountryLabel()
611
+ {
612
+ return Mage::helper('xmlconnect')->__('App Stores');
613
+ }
614
+
615
+ /**
616
+ * Get columns for submission country
617
+ *
618
+ * @return int
619
+ */
620
+ public function getCountryColumns()
621
+ {
622
+ return Mage_XmlConnect_Helper_Iphone::SUBMISSION_COUNTRY_COLUMNS;
623
+ }
624
+
625
+ /**
626
+ * Get placement of Country Names for submission country
627
+ *
628
+ * @return bool
629
+ */
630
+ public function isCountryNamePlaceLeft()
631
+ {
632
+ return true;
633
+ }
634
+
635
+ /**
636
+ * Get class name for submission country
637
+ *
638
+ * @return string
639
+ */
640
+ public function getCountryClass()
641
+ {
642
+ return Mage_XmlConnect_Helper_Iphone::SUBMISSION_COUNTRY_RENDERER . ' stripy';
643
+ }
644
+
645
+ /**
646
+ * Check image fields
647
+ *
648
+ * We set empty value for image field if file was missed in some reason
649
+ *
650
+ * @param array $data
651
+ * @return array
652
+ */
653
+ public function checkImages(array $data)
654
+ {
655
+ /** @var $helper Mage_XmlConnect_Helper_Image */
656
+ $helper = Mage::helper('xmlconnect/image');
657
+
658
+ $icon =& $data['conf']['native']['navigationBar']['icon'];
659
+
660
+ if (!empty($icon) && !$helper->checkAndGetImagePath($icon)) {
661
+ $icon = '';
662
+ }
663
+
664
+ $bannerLand =& $data['conf']['native']['body']['bannerIpadLandscapeImage'];
665
+
666
+ if (!empty($bannerLand) && !$helper->checkAndGetImagePath($bannerLand)) {
667
+ $bannerLand = '';
668
+ }
669
+
670
+ $banner =& $data['conf']['native']['body']['bannerIpadImage'];
671
+
672
+ if (!empty($banner) && !$helper->checkAndGetImagePath($banner)) {
673
+ $banner = '';
674
+ }
675
+
676
+ $backgroundLand =& $data['conf']['native']['body']['backgroundIpadLandscapeImage'];
677
+
678
+ if (!empty($backgroundLand) && !$helper->checkAndGetImagePath($backgroundLand)) {
679
+ $backgroundLand = '';
680
+ }
681
+
682
+ $background =& $data['conf']['native']['body']['backgroundIpadPortraitImage'];
683
+
684
+ if (!empty($background) && !$helper->checkAndGetImagePath($background)) {
685
+ $background = '';
686
+ }
687
+
688
+ return $data;
689
+ }
690
+
691
+ /**
692
+ * Check required fields of a config for a front-end
693
+ *
694
+ * @throws Mage_Core_Exception
695
+ * @param array $data
696
+ * @return void
697
+ */
698
+ public function checkRequiredConfigFields($data)
699
+ {
700
+ if (!is_array($data)) {
701
+ return;
702
+ }
703
+
704
+ if (isset($data['navigationBar']['icon'])
705
+ && empty($data['navigationBar']['icon'])
706
+ ) {
707
+ Mage::throwException(
708
+ Mage::helper('xmlconnect')->__('Logo in Header image missing.')
709
+ );
710
+ }
711
+ if (isset($data['body']['bannerIpadImage'])
712
+ && empty($data['body']['bannerIpadImage'])
713
+ ) {
714
+ Mage::throwException(
715
+ Mage::helper('xmlconnect')->__('Banner on Home Screen (portrait mode) image missing.')
716
+ );
717
+ }
718
+ if (isset($data['body']['bannerIpadLandscapeImage'])
719
+ && empty($data['body']['bannerIpadLandscapeImage'])
720
+ ) {
721
+ Mage::throwException(
722
+ Mage::helper('xmlconnect')->__('Banner on Home Screen (landscape mode) image missing.')
723
+ );
724
+ }
725
+ if (isset($data['body']['backgroundIpadLandscapeImage'])
726
+ && empty($data['body']['backgroundIpadLandscapeImage'])
727
+ ) {
728
+ Mage::throwException(
729
+ Mage::helper('xmlconnect')->__('App Background (landscape mode).')
730
+ );
731
+ }
732
+ if (isset($data['body']['backgroundIpadPortraitImage'])
733
+ && empty($data['body']['backgroundIpadPortraitImage'])
734
+ ) {
735
+ Mage::throwException(
736
+ Mage::helper('xmlconnect')->__('App Background (portrait mode).')
737
+ );
738
+ }
739
+ }
740
+
741
+ /**
742
+ * Check the notifications are allowed for current type of application
743
+ *
744
+ * @return bool
745
+ */
746
+ public function isNotificationsAllowed()
747
+ {
748
+ return true;
749
+ }
750
+ }
app/code/core/Mage/XmlConnect/Helper/Iphone.php ADDED
@@ -0,0 +1,797 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect device helper for iPhone
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Helper_Iphone extends Mage_Core_Helper_Abstract
35
+ {
36
+ /**
37
+ * Submission title length
38
+ */
39
+ const SUBMISSION_TITLE_LENGTH = 12;
40
+
41
+ /**
42
+ * Submission description length
43
+ */
44
+ const SUBMISSION_DESCRIPTION_LENGTH = 500;
45
+
46
+ /**
47
+ * Country renderer for submission page
48
+ */
49
+ const SUBMISSION_COUNTRY_RENDERER = 'istore';
50
+
51
+ /**
52
+ * Country columns for submission page
53
+ */
54
+ const SUBMISSION_COUNTRY_COLUMNS = 4;
55
+
56
+ /**
57
+ * Submit images that are stored in "params" field of history table
58
+ *
59
+ * @var array
60
+ */
61
+ protected $_imageIds = array(
62
+ 'icon',
63
+ 'loader_image',
64
+ 'loader_image_i4',
65
+ 'logo',
66
+ 'logo_i4',
67
+ 'big_logo',
68
+ 'big_logo_i4'
69
+ );
70
+
71
+ /**
72
+ * List of coutries that allowed in Ituens by Apple Store
73
+ *
74
+ * array(
75
+ * 'country name' => 'country id at directory model'
76
+ * )
77
+ *
78
+ * @var array
79
+ */
80
+ protected $_allowedCountries = array(
81
+ 'Argentina' => 'AR',
82
+ 'Armenia' => 'AM',
83
+ 'Australia' => 'AU',
84
+ 'Austria' => 'AT',
85
+ 'Belgium' => 'BE',
86
+ 'Botswana' => 'BW',
87
+ 'Brazil' => 'BR',
88
+ 'Bulgaria' => 'BG',
89
+ 'Canada' => 'CA',
90
+ 'Chile' => 'CL',
91
+ 'China' => 'CN',
92
+ 'Colombia' => 'CO',
93
+ 'Costa Rica' => 'CR',
94
+ 'Croatia' => 'HR',
95
+ 'Czech Republic' => 'CZ',
96
+ 'Denmark' => 'DK',
97
+ 'Dominican Republic' => 'DO',
98
+ 'Ecuador' => 'EC',
99
+ 'Egypt' => 'EG',
100
+ 'El Salvador' => 'SV',
101
+ 'Estonia' => 'EE',
102
+ 'Finland' => 'FI',
103
+ 'France' => 'FR',
104
+ 'Germany' => 'DE',
105
+ 'Greece' => 'GR',
106
+ 'Guatemala' => 'GT',
107
+ 'Honduras' => 'HN',
108
+ 'Hong Kong SAR China' => 'HK',
109
+ 'Hungary' => 'HU',
110
+ 'India' => 'IN',
111
+ 'Indonesia' => 'ID',
112
+ 'Ireland' => 'IE',
113
+ 'Israel' => 'IL',
114
+ 'Italy' => 'IT',
115
+ 'Jamaica' => 'JM',
116
+ 'Japan' => 'JP',
117
+ 'Jordan' => 'JO',
118
+ 'Kazakstan' => 'KZ',
119
+ 'Kenya' => 'KE',
120
+ 'South Korea' => 'KR',
121
+ 'Kuwait' => 'KW',
122
+ 'Latvia' => 'LV',
123
+ 'Lebanon' => 'LB',
124
+ 'Lithuania' => 'LT',
125
+ 'Luxembourg' => 'LU',
126
+ 'Macau SAR China' => 'MO',
127
+ 'Macedonia' => 'MK',
128
+ 'Madagascar' => 'MG',
129
+ 'Malaysia' => 'MY',
130
+ 'Mali' => 'ML',
131
+ 'Malta' => 'MT',
132
+ 'Mauritius' => 'MU',
133
+ 'Mexico' => 'MX',
134
+ 'Moldova' => 'MD',
135
+ 'Netherlands' => 'NL',
136
+ 'New Zealand' => 'NZ',
137
+ 'Nicaragua' => 'NI',
138
+ 'Niger' => 'NE',
139
+ 'Norway' => 'NO',
140
+ 'Pakistan' => 'PK',
141
+ 'Panama' => 'PA',
142
+ 'Paraguay' => 'PY',
143
+ 'Peru' => 'PE',
144
+ 'Philippines' => 'PH',
145
+ 'Poland' => 'PL',
146
+ 'Portugal' => 'PT',
147
+ 'Qatar' => 'QA',
148
+ 'Romania' => 'RO',
149
+ 'Russia' => 'RU',
150
+ 'Saudi Arabia' => 'SA',
151
+ 'Senegal' => 'SN',
152
+ 'Singapore' => 'SG',
153
+ 'Slovakia' => 'SK',
154
+ 'Slovenia' => 'SI',
155
+ 'South Africa' => 'ZA',
156
+ 'Spain' => 'ES',
157
+ 'Sri Lanka' => 'LK',
158
+ 'Sweden' => 'SE',
159
+ 'Switzerland' => 'CH',
160
+ 'Taiwan' => 'TW',
161
+ 'Thailand' => 'TH',
162
+ 'Tunisia' => 'TN',
163
+ 'Turkey' => 'TR',
164
+ 'Uganda' => 'UG',
165
+ 'United Arab Emirates' => 'AE',
166
+ 'United Kingdom' => 'GB',
167
+ 'United States' => 'US',
168
+ 'Uruguay' => 'UY',
169
+ 'Venezuela' => 'VE',
170
+ 'Vietnam' => 'VN',
171
+ );
172
+
173
+ /**
174
+ * Country field renderer
175
+ *
176
+ * @var Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Renderer_Country_Istore
177
+ */
178
+ protected $_countryRenderer = null;
179
+
180
+ /**
181
+ * Get submit images that are required for application submit
182
+ *
183
+ * @return array
184
+ */
185
+ public function getSubmitImages()
186
+ {
187
+ return $this->_imageIds;
188
+ }
189
+
190
+ /**
191
+ * Get default application tabs
192
+ *
193
+ * @return array
194
+ */
195
+ public function getDefaultDesignTabs()
196
+ {
197
+ if (!isset($this->_tabs)) {
198
+ $this->_tabs = array(
199
+ array(
200
+ 'label' => Mage::helper('xmlconnect')->__('Home'),
201
+ 'image' => 'tab_home.png',
202
+ 'action' => 'Home',
203
+ ),
204
+ array(
205
+ 'label' => Mage::helper('xmlconnect')->__('Shop'),
206
+ 'image' => 'tab_shop.png',
207
+ 'action' => 'Shop',
208
+ ),
209
+ array(
210
+ 'label' => Mage::helper('xmlconnect')->__('Search'),
211
+ 'image' => 'tab_search.png',
212
+ 'action' => 'Search',
213
+ ),
214
+ array(
215
+ 'label' => Mage::helper('xmlconnect')->__('Cart'),
216
+ 'image' => 'tab_cart.png',
217
+ 'action' => 'Cart',
218
+ ),
219
+ array(
220
+ 'label' => Mage::helper('xmlconnect')->__('More'),
221
+ 'image' => 'tab_more.png',
222
+ 'action' => 'More',
223
+ ),
224
+ array(
225
+ 'label' => Mage::helper('xmlconnect')->__('Account'),
226
+ 'image' => 'tab_account.png',
227
+ 'action' => 'Account',
228
+ ),
229
+ array(
230
+ 'label' => Mage::helper('xmlconnect')->__('More Info'),
231
+ 'image' => 'tab_page.png',
232
+ 'action' => 'AboutUs',
233
+ ),
234
+ );
235
+ }
236
+ return $this->_tabs;
237
+ }
238
+
239
+ /**
240
+ * Default application configuration
241
+ *
242
+ * @return array
243
+ */
244
+ public function getDefaultConfiguration()
245
+ {
246
+ return array(
247
+ 'native' => array(
248
+ 'body' => array(
249
+ 'backgroundColor' => '#ABABAB',
250
+ 'scrollBackgroundColor' => '#EDEDED',
251
+ ),
252
+ 'itemActions' => array(
253
+ 'relatedProductBackgroundColor' => '#404040',
254
+ ),
255
+ 'fonts' => array(
256
+ 'Title1' => array(
257
+ 'name' => 'HelveticaNeue-Bold',
258
+ 'size' => '14',
259
+ 'color' => '#FEFEFE',
260
+ ),
261
+ 'Title2' => array(
262
+ 'name' => 'HelveticaNeue-Bold',
263
+ 'size' => '12',
264
+ 'color' => '#222222',
265
+ ),
266
+ 'Title3' => array(
267
+ 'name' => 'HelveticaNeue',
268
+ 'size' => '13',
269
+ 'color' => '#000000',
270
+ ),
271
+ 'Title4' => array(
272
+ 'name' => 'HelveticaNeue',
273
+ 'size' => '12',
274
+ 'color' => '#FFFFFF',
275
+ ),
276
+ 'Title5' => array(
277
+ 'name' => 'HelveticaNeue-Bold',
278
+ 'size' => '13',
279
+ 'color' => '#dc5f02',
280
+ ),
281
+ 'Title6' => array(
282
+ 'name' => 'HelveticaNeue-Bold',
283
+ 'size' => '16',
284
+ 'color' => '#222222',
285
+ ),
286
+ 'Title7' => array(
287
+ 'name' => 'HelveticaNeue-Bold',
288
+ 'size' => '13',
289
+ 'color' => '#000000',
290
+ ),
291
+ 'Title8' => array(
292
+ 'name' => 'HelveticaNeue-Bold',
293
+ 'size' => '11',
294
+ 'color' => '#FFFFFF',
295
+ ),
296
+ 'Title9' => array(
297
+ 'name' => 'HelveticaNeue-Bold',
298
+ 'size' => '12',
299
+ 'color' => '#FFFFFF',
300
+ ),
301
+ 'Text1' => array(
302
+ 'name' => 'HelveticaNeue-Bold',
303
+ 'size' => '12',
304
+ 'color' => '#777777',
305
+ ),
306
+ 'Text2' => array(
307
+ 'name' => 'HelveticaNeue',
308
+ 'size' => '10',
309
+ 'color' => '#555555',
310
+ ),
311
+ ),
312
+ ),
313
+ );
314
+ }
315
+
316
+ /**
317
+ * List of allowed fonts for iPhone application
318
+ *
319
+ * @return array
320
+ */
321
+ public function getFontList()
322
+ {
323
+ return array(
324
+ array(
325
+ 'value' => 'HiraKakuProN-W3',
326
+ 'label' => 'HiraKakuProN-W3',
327
+ ),
328
+ array(
329
+ 'value' => 'Courier',
330
+ 'label' => 'Courier',
331
+ ),
332
+ array(
333
+ 'value' => 'Courier-BoldOblique',
334
+ 'label' => 'Courier-BoldOblique',
335
+ ),
336
+ array(
337
+ 'value' => 'Courier-Oblique',
338
+ 'label' => 'Courier-Oblique',
339
+ ),
340
+ array(
341
+ 'value' => 'Courier-Bold',
342
+ 'label' => 'Courier-Bold',
343
+ ),
344
+ array(
345
+ 'value' => 'ArialMT',
346
+ 'label' => 'ArialMT',
347
+ ),
348
+ array(
349
+ 'value' => 'Arial-BoldMT',
350
+ 'label' => 'Arial-BoldMT',
351
+ ),
352
+ array(
353
+ 'value' => 'Arial-BoldItalicMT',
354
+ 'label' => 'Arial-BoldItalicMT',
355
+ ),
356
+ array(
357
+ 'value' => 'Arial-ItalicMT',
358
+ 'label' => 'Arial-ItalicMT',
359
+ ),
360
+ array(
361
+ 'value' => 'STHeitiTC-Light',
362
+ 'label' => 'STHeitiTC-Light',
363
+ ),
364
+ array(
365
+ 'value' => 'STHeitiTC-Medium',
366
+ 'label' => 'STHeitiTC-Medium',
367
+ ),
368
+ array(
369
+ 'value' => 'AppleGothic',
370
+ 'label' => 'AppleGothic',
371
+ ),
372
+ array(
373
+ 'value' => 'CourierNewPS-BoldMT',
374
+ 'label' => 'CourierNewPS-BoldMT',
375
+ ),
376
+ array(
377
+ 'value' => 'CourierNewPS-ItalicMT',
378
+ 'label' => 'CourierNewPS-ItalicMT',
379
+ ),
380
+ array(
381
+ 'value' => 'CourierNewPS-BoldItalicMT',
382
+ 'label' => 'CourierNewPS-BoldItalicMT',
383
+ ),
384
+ array(
385
+ 'value' => 'CourierNewPSMT',
386
+ 'label' => 'CourierNewPSMT',
387
+ ),
388
+ array(
389
+ 'value' => 'Zapfino',
390
+ 'label' => 'Zapfino',
391
+ ),
392
+ array(
393
+ 'value' => 'HiraKakuProN-W6',
394
+ 'label' => 'HiraKakuProN-W6',
395
+ ),
396
+ array(
397
+ 'value' => 'ArialUnicodeMS',
398
+ 'label' => 'ArialUnicodeMS',
399
+ ),
400
+ array(
401
+ 'value' => 'STHeitiSC-Medium',
402
+ 'label' => 'STHeitiSC-Medium',
403
+ ),
404
+ array(
405
+ 'value' => 'STHeitiSC-Light',
406
+ 'label' => 'STHeitiSC-Light',
407
+ ),
408
+ array(
409
+ 'value' => 'AmericanTypewriter',
410
+ 'label' => 'AmericanTypewriter',
411
+ ),
412
+ array(
413
+ 'value' => 'AmericanTypewriter-Bold',
414
+ 'label' => 'AmericanTypewriter-Bold',
415
+ ),
416
+ array(
417
+ 'value' => 'Helvetica-Oblique',
418
+ 'label' => 'Helvetica-Oblique',
419
+ ),
420
+ array(
421
+ 'value' => 'Helvetica-BoldOblique',
422
+ 'label' => 'Helvetica-BoldOblique',
423
+ ),
424
+ array(
425
+ 'value' => 'Helvetica',
426
+ 'label' => 'Helvetica',
427
+ ),
428
+ array(
429
+ 'value' => 'Helvetica-Bold',
430
+ 'label' => 'Helvetica-Bold',
431
+ ),
432
+ array(
433
+ 'value' => 'MarkerFelt-Thin',
434
+ 'label' => 'MarkerFelt-Thin',
435
+ ),
436
+ array(
437
+ 'value' => 'HelveticaNeue',
438
+ 'label' => 'HelveticaNeue',
439
+ ),
440
+ array(
441
+ 'value' => 'HelveticaNeue-Bold',
442
+ 'label' => 'HelveticaNeue-Bold',
443
+ ),
444
+ array(
445
+ 'value' => 'DBLCDTempBlack',
446
+ 'label' => 'DBLCDTempBlack',
447
+ ),
448
+ array(
449
+ 'value' => 'Verdana-Bold',
450
+ 'label' => 'Verdana-Bold',
451
+ ),
452
+ array(
453
+ 'value' => 'Verdana-BoldItalic',
454
+ 'label' => 'Verdana-BoldItalic',
455
+ ),
456
+ array(
457
+ 'value' => 'Verdana',
458
+ 'label' => 'Verdana',
459
+ ),
460
+ array(
461
+ 'value' => 'Verdana-Italic',
462
+ 'label' => 'Verdana-Italic',
463
+ ),
464
+ array(
465
+ 'value' => 'TimesNewRomanPSMT',
466
+ 'label' => 'TimesNewRomanPSMT',
467
+ ),
468
+ array(
469
+ 'value' => 'TimesNewRomanPS-BoldMT',
470
+ 'label' => 'TimesNewRomanPS-BoldMT',
471
+ ),
472
+ array(
473
+ 'value' => 'TimesNewRomanPS-BoldItalicMT',
474
+ 'label' => 'TimesNewRomanPS-BoldItalicMT',
475
+ ),
476
+ array(
477
+ 'value' => 'TimesNewRomanPS-ItalicMT',
478
+ 'label' => 'TimesNewRomanPS-ItalicMT',
479
+ ),
480
+ array(
481
+ 'value' => 'Georgia-Bold',
482
+ 'label' => 'Georgia-Bold',
483
+ ),
484
+ array(
485
+ 'value' => 'Georgia',
486
+ 'label' => 'Georgia',
487
+ ),
488
+ array(
489
+ 'value' => 'Georgia-BoldItalic',
490
+ 'label' => 'Georgia-BoldItalic',
491
+ ),
492
+ array(
493
+ 'value' => 'Georgia-Italic',
494
+ 'label' => 'Georgia-Italic',
495
+ ),
496
+ array(
497
+ 'value' => 'STHeitiJ-Medium',
498
+ 'label' => 'STHeitiJ-Medium',
499
+ ),
500
+ array(
501
+ 'value' => 'STHeitiJ-Light',
502
+ 'label' => 'STHeitiJ-Light',
503
+ ),
504
+ array(
505
+ 'value' => 'ArialRoundedMTBold',
506
+ 'label' => 'ArialRoundedMTBold',
507
+ ),
508
+ array(
509
+ 'value' => 'TrebuchetMS-Italic',
510
+ 'label' => 'TrebuchetMS-Italic',
511
+ ),
512
+ array(
513
+ 'value' => 'TrebuchetMS',
514
+ 'label' => 'TrebuchetMS',
515
+ ),
516
+ array(
517
+ 'value' => 'Trebuchet-BoldItalic',
518
+ 'label' => 'Trebuchet-BoldItalic',
519
+ ),
520
+ array(
521
+ 'value' => 'TrebuchetMS-Bold',
522
+ 'label' => 'TrebuchetMS-Bold',
523
+ ),
524
+ array(
525
+ 'value' => 'STHeitiK-Medium',
526
+ 'label' => 'STHeitiK-Medium',
527
+ ),
528
+ array(
529
+ 'value' => 'STHeitiK-Light',
530
+ 'label' => 'STHeitiK-Light',
531
+ ),
532
+ );
533
+ }
534
+
535
+ /**
536
+ * List of allowed font sizes for iPhone application
537
+ *
538
+ * @return array
539
+ */
540
+ public function getFontSizes()
541
+ {
542
+ $result = array();
543
+ for ($i = 6; $i < 32; $i++) {
544
+ $result[] = array(
545
+ 'value' => $i,
546
+ 'label' => $i . ' pt',
547
+ );
548
+ }
549
+ return $result;
550
+ }
551
+
552
+ /**
553
+ * Get list of countries that allowed in Itunes by Apple Store for Iphone
554
+ *
555
+ * @return array
556
+ */
557
+ public function getItunesCountriesArray()
558
+ {
559
+ return $this->_allowedCountries;
560
+ }
561
+
562
+ /**
563
+ * Validate submit application data
564
+ *
565
+ * @param array $params
566
+ * @return array
567
+ */
568
+ public function validateSubmit($params)
569
+ {
570
+ $errors = array();
571
+
572
+ if (!Zend_Validate::is(isset($params['title']) ? $params['title'] : null, 'NotEmpty')) {
573
+ $errors[] = Mage::helper('xmlconnect')->__('Please enter the Title.');
574
+ }
575
+
576
+ if (isset($params['title'])) {
577
+ $titleLength = self::SUBMISSION_TITLE_LENGTH;
578
+ $strRules = array('min' => '1', 'max' => $titleLength);
579
+ if (!Zend_Validate::is($params['title'], 'StringLength', $strRules)) {
580
+ $errors[] = Mage::helper('xmlconnect')->__('"Title" is more than %d characters long', $strRules['max']);
581
+ }
582
+ }
583
+
584
+ if (!Zend_Validate::is(isset($params['description']) ? $params['description'] : null, 'NotEmpty')) {
585
+ $errors[] = Mage::helper('xmlconnect')->__('Please enter the Description.');
586
+ }
587
+
588
+ if (isset($params['description'])) {
589
+ $descriptionLength = self::SUBMISSION_DESCRIPTION_LENGTH;
590
+ $strRules = array('min' => '1', 'max' => $descriptionLength);
591
+ if (!Zend_Validate::is($params['title'], 'StringLength', $strRules)) {
592
+ $errors[] = Mage::helper('xmlconnect')->__('"Description" is more than %d characters long', $strRules['max']);
593
+ }
594
+ }
595
+
596
+ if (!Zend_Validate::is(isset($params['copyright']) ? $params['copyright'] : null, 'NotEmpty')) {
597
+ $errors[] = Mage::helper('xmlconnect')->__('Please enter the Copyright.');
598
+ }
599
+
600
+ if (empty($params['price_free'])) {
601
+ if (!Zend_Validate::is(isset($params['price']) ? $params['price'] : null, 'NotEmpty')) {
602
+ $errors[] = Mage::helper('xmlconnect')->__('Please enter the Price.');
603
+ }
604
+ }
605
+
606
+ if (!Zend_Validate::is(isset($params['country']) ? $params['country'] : null, 'NotEmpty')) {
607
+ $errors[] = Mage::helper('xmlconnect')->__('Please select at least one country.');
608
+ }
609
+
610
+ $keyLenght = Mage_XmlConnect_Model_Application::APP_MAX_KEY_LENGTH;
611
+ if (Mage::helper('xmlconnect')->getApplication()->getIsResubmitAction()) {
612
+ if (isset($params['resubmission_activation_key'])) {
613
+ $resubmissionKey = $params['resubmission_activation_key'];
614
+ } else {
615
+ $resubmissionKey = null;
616
+ }
617
+
618
+ if (!Zend_Validate::is($resubmissionKey, 'NotEmpty')) {
619
+ $errors[] = Mage::helper('xmlconnect')->__('Please enter the Resubmission Key.');
620
+ } elseif (!Zend_Validate::is($resubmissionKey, 'StringLength', array(1, $keyLenght))) {
621
+ $errors[] = Mage::helper('xmlconnect')->__('Submit App failure. Invalid activation key provided');
622
+ }
623
+ } else {
624
+ $key = isset($params['key']) ? $params['key'] : null;
625
+ if (!Zend_Validate::is($key, 'NotEmpty')) {
626
+ $errors[] = Mage::helper('xmlconnect')->__('Please enter the Activation Key.');
627
+ } elseif (!Zend_Validate::is($key, 'StringLength', array(1, $keyLenght))) {
628
+ $errors[] = Mage::helper('xmlconnect')->__('Submit App failure. Invalid activation key provided');
629
+ }
630
+ }
631
+ return $errors;
632
+ }
633
+
634
+ /**
635
+ * Check config for valid values
636
+ *
637
+ * @param array $native
638
+ * @return array
639
+ */
640
+ public function validateConfig($native)
641
+ {
642
+ $errors = array();
643
+
644
+ if ($native === false
645
+ || (!isset($native['navigationBar']['icon'])
646
+ || !Zend_Validate::is($native['navigationBar']['icon'], 'NotEmpty')
647
+ )
648
+ ) {
649
+ $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "Logo in Header" field from Design Tab.');
650
+ }
651
+
652
+ if (!Mage::helper('xmlconnect')->validateConfFieldNotEmpty('bannerImage', $native)) {
653
+ $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "Banner on Home Screen" field from Design Tab.');
654
+ }
655
+
656
+ if (!Mage::helper('xmlconnect')->validateConfFieldNotEmpty('backgroundImage', $native)) {
657
+ $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "App Background" field from Design Tab.');
658
+ }
659
+
660
+ return $errors;
661
+ }
662
+
663
+ /**
664
+ * Get renderer for submission country
665
+ *
666
+ * @return Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Renderer_Country_Istore
667
+ */
668
+ public function getCountryRenderer()
669
+ {
670
+ if (empty($this->_countryRenderer)) {
671
+ $renderer = 'xmlconnect/adminhtml_mobile_submission_renderer_country_'
672
+ . self::SUBMISSION_COUNTRY_RENDERER;
673
+ $this->_countryRenderer = Mage::app()->getLayout()->createBlock($renderer);
674
+ }
675
+ return $this->_countryRenderer;
676
+ }
677
+
678
+ /**
679
+ * Get label for submission country
680
+ *
681
+ * @return string
682
+ */
683
+ public function getCountryLabel()
684
+ {
685
+ return Mage::helper('xmlconnect')->__('App Stores');
686
+ }
687
+
688
+ /**
689
+ * Get columns for submission country
690
+ *
691
+ * @return int
692
+ */
693
+ public function getCountryColumns()
694
+ {
695
+ return self::SUBMISSION_COUNTRY_COLUMNS;
696
+ }
697
+
698
+ /**
699
+ * Get placement of Country Names for submission country
700
+ *
701
+ * @return bool
702
+ */
703
+ public function isCountryNamePlaceLeft()
704
+ {
705
+ return true;
706
+ }
707
+
708
+ /**
709
+ * Get class name for submission country
710
+ *
711
+ * @return string
712
+ */
713
+ public function getCountryClass()
714
+ {
715
+ return self::SUBMISSION_COUNTRY_RENDERER . ' stripy';
716
+ }
717
+
718
+ /**
719
+ * Check image fields
720
+ *
721
+ * We set empty value for image field if file was missed in some reason
722
+ *
723
+ * @param array $data
724
+ * @return array
725
+ */
726
+ public function checkImages(array $data)
727
+ {
728
+ /** @var $helper Mage_XmlConnect_Helper_Image */
729
+ $helper = Mage::helper('xmlconnect/image');
730
+
731
+ $icon =& $data['conf']['native']['navigationBar']['icon'];
732
+
733
+ if (!empty($icon) && !$helper->checkAndGetImagePath($icon)) {
734
+ $icon = '';
735
+ }
736
+
737
+ $banner =& $data['conf']['native']['body']['bannerImage'];
738
+
739
+ if (!empty($banner) && !$helper->checkAndGetImagePath($banner)) {
740
+ $banner = '';
741
+ }
742
+
743
+ $background =& $data['conf']['native']['body']['backgroundImage'];
744
+
745
+ if (!empty($background) && !$helper->checkAndGetImagePath($background)) {
746
+ $background = '';
747
+ }
748
+
749
+ return $data;
750
+ }
751
+
752
+ /**
753
+ * Check required fields of a config for a front-end
754
+ *
755
+ * @throws Mage_Core_Exception
756
+ * @param array $data
757
+ * @return void
758
+ */
759
+ public function checkRequiredConfigFields($data)
760
+ {
761
+ if (!is_array($data)) {
762
+ return;
763
+ }
764
+
765
+ if (isset($data['navigationBar']['icon'])
766
+ && empty($data['navigationBar']['icon'])
767
+ ) {
768
+ Mage::throwException(
769
+ Mage::helper('xmlconnect')->__('Logo in Header image missing.')
770
+ );
771
+ }
772
+ if (isset($data['body']['bannerImage'])
773
+ && empty($data['body']['bannerImage'])
774
+ ) {
775
+ Mage::throwException(
776
+ Mage::helper('xmlconnect')->__('Banner on Home Screen image missing.')
777
+ );
778
+ }
779
+ if (isset($data['body']['backgroundImage'])
780
+ && empty($data['body']['backgroundImage'])
781
+ ) {
782
+ Mage::throwException(
783
+ Mage::helper('xmlconnect')->__('App Background image missing.')
784
+ );
785
+ }
786
+ }
787
+
788
+ /**
789
+ * Check the notifications are allowed for current type of application
790
+ *
791
+ * @return bool
792
+ */
793
+ public function isNotificationsAllowed()
794
+ {
795
+ return true;
796
+ }
797
+ }
app/code/core/Mage/XmlConnect/Helper/Payment.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * @deprecated after 1.4.2.0
29
+ */
30
+ class Mage_XmlConnect_Helper_Payment extends Mage_Core_Helper_Abstract
31
+ {
32
+ /**
33
+ * Return paymentMethod => methodCode array
34
+ *
35
+ * @deprecated after 1.4.2.0
36
+ * @return array
37
+ */
38
+ public function getPaymentMethodCodeList()
39
+ {
40
+ return array();
41
+ }
42
+ }
app/code/core/Mage/XmlConnect/Helper/Theme.php ADDED
@@ -0,0 +1,395 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Theme helper
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Helper_Theme extends Mage_Adminhtml_Helper_Data
35
+ {
36
+ /**
37
+ * Color Themes Cache
38
+ *
39
+ * @param array|null
40
+ */
41
+ protected $_themeArray = null;
42
+
43
+ /**
44
+ * Return for Color Themes Fields array.
45
+ *
46
+ * @return array
47
+ */
48
+ public function getThemeAjaxParameters()
49
+ {
50
+ $themesArray = array (
51
+ 'conf_native_navigationBar_tintColor'
52
+ => 'conf[native][navigationBar][tintColor]',
53
+ 'conf_native_body_primaryColor'
54
+ => 'conf[native][body][primaryColor]',
55
+ 'conf_native_body_secondaryColor'
56
+ => 'conf[native][body][secondaryColor]',
57
+ 'conf_native_categoryItem_backgroundColor'
58
+ => 'conf[native][categoryItem][backgroundColor]',
59
+ 'conf_native_categoryItem_tintColor'
60
+ => 'conf[native][categoryItem][tintColor]',
61
+
62
+ 'conf_extra_fontColors_header'
63
+ => 'conf[extra][fontColors][header]',
64
+ 'conf_extra_fontColors_primary'
65
+ => 'conf[extra][fontColors][primary]',
66
+ 'conf_extra_fontColors_secondary'
67
+ => 'conf[extra][fontColors][secondary]',
68
+ 'conf_extra_fontColors_price'
69
+ => 'conf[extra][fontColors][price]',
70
+
71
+ 'conf_native_body_backgroundColor'
72
+ => 'conf[native][body][backgroundColor]',
73
+ 'conf_native_body_scrollBackgroundColor'
74
+ => 'conf[native][body][scrollBackgroundColor]',
75
+ 'conf_native_itemActions_relatedProductBackgroundColor'
76
+ => 'conf[native][itemActions][relatedProductBackgroundColor]'
77
+ );
78
+ return $themesArray;
79
+ }
80
+
81
+ /**
82
+ * Returns JSON ready Themes array
83
+ *
84
+ * @param bool $flushCache load defaults
85
+ * @return array
86
+ */
87
+ public function getAllThemesArray($flushCache = false)
88
+ {
89
+ $result = array();
90
+ $themes = $this->getAllThemes($flushCache);
91
+ foreach ($themes as $theme) {
92
+ $result[$theme->getName()] = $theme->getFormData();
93
+ }
94
+ return $result;
95
+ }
96
+
97
+ /**
98
+ * Get dropdown select image for theme
99
+ *
100
+ * @param string $themeId
101
+ * @return string Image url
102
+ */
103
+ public function getThemeImageUrl($themeId)
104
+ {
105
+ $themeImage = array_key_exists($themeId, $this->getDefaultThemes()) ? $themeId : 'user_custom';
106
+ return Mage::helper('xmlconnect/image')->getSkinImagesUrl('swatch_' . $themeImage . '.gif');
107
+ }
108
+
109
+ /**
110
+ * Get themes dropdown selector html
111
+ *
112
+ * @param string $themeId
113
+ * @return string
114
+ */
115
+ public function getThemesSelector($themeId = '')
116
+ {
117
+ if (Mage::registry('current_app') !== null) {
118
+ $themeId = Mage::registry('current_app')->getData('conf/extra/theme');
119
+ }
120
+
121
+ if (!$themeId) {
122
+ $themeId = $this->getDefaultThemeName();
123
+ }
124
+
125
+ $currentTheme = $this->getThemeByName($themeId);
126
+ if ($currentTheme === null) {
127
+ $themeId = $this->getDefaultThemeName();
128
+ $currentTheme = $this->getThemeByName($themeId);
129
+ }
130
+
131
+ if (!($currentTheme instanceof Mage_XmlConnect_Model_Theme)) {
132
+ Mage::throwException(
133
+ Mage::helper('xmlconnect')->__('Can\'t load selected theme. Please check your media folder permissions.')
134
+ );
135
+ }
136
+
137
+ $themeList = '';
138
+ foreach ($this->getAllThemes(true) as $theme) {
139
+ $themeList .= '<li id="' . $theme->getName() . '">';
140
+ $themeList .= '<a rel="' . $theme->getName() . '" style="cursor:pointer;">' . $theme->getLabel();
141
+ $themeList .= '<span>';
142
+ $themeList .= '<img src="' . $this->getThemeImageUrl($theme->getName()) . '"/>';
143
+ $themeList .= '</span></a></li>';
144
+ }
145
+
146
+ $themesDdl = <<<EOT
147
+ <ul class="dropdown theme_selector" id="theme_selector_id">
148
+ <li class="ddtitle theme_selector">
149
+ <a style="cursor:pointer;">{$currentTheme->getLabel()}
150
+ <span>
151
+ <img src="{$this->getThemeImageUrl($themeId)}"/>
152
+ </span>
153
+ </a>
154
+ </li>
155
+ <li style="display:none;" class="ddlist">
156
+ <ul>
157
+ {$themeList}
158
+ </ul>
159
+ </li>
160
+ </ul>
161
+ EOT;
162
+ return $themesDdl;
163
+ }
164
+
165
+ /**
166
+ * Reads directory media/xmlconnect/themes/*
167
+ *
168
+ * @param bool $flushCache Reads default color Themes
169
+ * @return array contains Mage_XmlConnect_Model_Theme
170
+ */
171
+ public function getAllThemes($flushCache = false)
172
+ {
173
+ if (!$this->_themeArray || $flushCache) {
174
+ $saveLibxmlErrors = libxml_use_internal_errors(true);
175
+ $this->_themeArray = array();
176
+ $themeDir = $this->getMediaThemePath();
177
+ $ioFile = new Varien_Io_File();
178
+ $ioFile->checkAndCreateFolder($themeDir);
179
+ $ioFile->open(array('path' => $themeDir));
180
+ try {
181
+ $fileList = $ioFile->ls(Varien_Io_File::GREP_FILES);
182
+ if (!count($fileList)) {
183
+ $this->resetTheme();
184
+ $this->getAllThemes(true);
185
+ }
186
+ foreach ($fileList as $file) {
187
+ $src = $themeDir . DS . $file['text'];
188
+ if (is_readable($src)) {
189
+ $theme = Mage::getModel('xmlconnect/theme', $src);
190
+ $this->_themeArray[$theme->getName()] = $theme;
191
+ }
192
+ }
193
+ asort($this->_themeArray);
194
+ libxml_use_internal_errors($saveLibxmlErrors);
195
+ } catch (Exception $e) {
196
+ Mage::logException($e);
197
+ }
198
+ }
199
+ return $this->_themeArray;
200
+ }
201
+
202
+ /**
203
+ * Reads default theme directory
204
+ *
205
+ * @throws Mage_Core_Exception
206
+ * @return array contains Mage_XmlConnect_Model_Theme
207
+ */
208
+ public function getDefaultThemes()
209
+ {
210
+ $saveLibxmlErrors = libxml_use_internal_errors(true);
211
+ $defaultThemeArray = array();
212
+ $themeDir = $this->_getDefaultThemePath();
213
+ $ioFile = new Varien_Io_File();
214
+ $ioFile->open(array('path' => $themeDir));
215
+ try {
216
+ $fileList = $ioFile->ls(Varien_Io_File::GREP_FILES);
217
+ foreach ($fileList as $file) {
218
+ $src = $themeDir . DS . $file['text'];
219
+ if (is_readable($src)) {
220
+ $theme = Mage::getModel('xmlconnect/theme', $src);
221
+ $defaultThemeArray[$theme->getName()] = $theme;
222
+ }
223
+ }
224
+ libxml_use_internal_errors($saveLibxmlErrors);
225
+ } catch (Exception $e) {
226
+ Mage::logException($e);
227
+ }
228
+ if (!count($defaultThemeArray)) {
229
+ Mage::throwException(
230
+ Mage::helper('xmlconnect')->__('Can\'t load default themes.')
231
+ );
232
+ }
233
+ return $defaultThemeArray;
234
+ }
235
+
236
+ /**
237
+ * Create new custom theme
238
+ *
239
+ * @param $themeName string
240
+ * @param $data array
241
+ * @return Mage_XmlConnect_Model_Theme
242
+ */
243
+ public function createNewTheme($themeName, $data)
244
+ {
245
+ /** @var $defaultTheme Mage_XmlConnect_Model_Theme */
246
+ $defaultTheme = $this->getThemeByName($this->getDefaultThemeName());
247
+ return $defaultTheme->createNewTheme($themeName, $data);
248
+ }
249
+
250
+ /**
251
+ * Get default theme path: /xmlconnect/etc/themes/*
252
+ *
253
+ * @return string
254
+ */
255
+ protected function _getDefaultThemePath()
256
+ {
257
+ return Mage::getModuleDir('etc', 'Mage_XmlConnect') . DS . 'themes';
258
+ }
259
+
260
+ /**
261
+ * Get media theme path: media/xmlconnect/themes/*
262
+ *
263
+ * @return string
264
+ */
265
+ public function getMediaThemePath()
266
+ {
267
+ return Mage::getBaseDir('media') . DS . 'xmlconnect' . DS . 'themes';
268
+ }
269
+
270
+ /**
271
+ * Reset themes color changes
272
+ * Copy /xmlconnect/etc/themes/* to media/xmlconnect/themes/*
273
+ *
274
+ * @throws Mage_Core_Exception
275
+ * @param null $theme
276
+ * @return void
277
+ */
278
+ public function resetTheme($theme = null)
279
+ {
280
+ $themeDir = $this->getMediaThemePath();
281
+ $defaultThemeDir = $this->_getDefaultThemePath();
282
+
283
+ $ioFile = new Varien_Io_File();
284
+ $ioFile->open(array('path' => $defaultThemeDir));
285
+ $fileList = $ioFile->ls(Varien_Io_File::GREP_FILES);
286
+ foreach ($fileList as $file) {
287
+ $f = $file['text'];
288
+ $src = $defaultThemeDir . DS . $f;
289
+ $dst = $themeDir . DS .$f;
290
+
291
+ if ($theme && ($theme . '.xml') != $f) {
292
+ continue;
293
+ }
294
+
295
+ if (!$ioFile->cp($src, $dst)) {
296
+ Mage::throwException(
297
+ Mage::helper('xmlconnect')->__('Can\'t copy file "%s" to "%s".', $src, $dst)
298
+ );
299
+ } else {
300
+ $ioFile->chmod($dst, 0755);
301
+ }
302
+ }
303
+ }
304
+
305
+ /**
306
+ * Get theme object by name
307
+ *
308
+ * @param string $name
309
+ * @return Mage_XmlConnect_Model_Theme|null
310
+ */
311
+ public function getThemeByName($name)
312
+ {
313
+ $themes = $this->getAllThemes();
314
+ $theme = isset($themes[$name]) ? $themes[$name] : null;
315
+ return $theme;
316
+ }
317
+
318
+ /**
319
+ * Return predefined custom theme name
320
+ *
321
+ * @return string
322
+ */
323
+ public function getCustomThemeName()
324
+ {
325
+ return 'custom';
326
+ }
327
+
328
+ /**
329
+ * Return predefined default theme name
330
+ *
331
+ * @return string
332
+ */
333
+ public function getDefaultThemeName()
334
+ {
335
+ return 'default';
336
+ }
337
+
338
+ /**
339
+ * Get current theme name
340
+ *
341
+ * @return string
342
+ */
343
+ public function getThemeId()
344
+ {
345
+ $themeId = Mage::helper('xmlconnect')->getApplication()->getData('conf/extra/theme');
346
+
347
+ if ($this->getThemeByName($themeId) === null) {
348
+ $themeId = null;
349
+ }
350
+
351
+ if (empty($themeId)) {
352
+ $themeId = $this->getDefaultThemeName();
353
+ }
354
+ return $themeId;
355
+ }
356
+
357
+ /**
358
+ * Get theme label by theme name
359
+ *
360
+ * @param array $themes
361
+ * @param bool $themeId
362
+ * @return string
363
+ */
364
+ public function getThemeLabel(array $themes, $themeId = false)
365
+ {
366
+ $themeLabel = '';
367
+ $themeId = $themeId ? $themeId : $this->getThemeId();
368
+
369
+ foreach ($themes as $theme) {
370
+ if ($theme->getName() == $themeId) {
371
+ $themeLabel = $theme->getLabel();
372
+ break;
373
+ }
374
+ }
375
+ return $themeLabel;
376
+ }
377
+
378
+ /**
379
+ * Delete theme by id
380
+ *
381
+ * @param $themeId
382
+ * @return bool
383
+ */
384
+ public function deleteTheme($themeId)
385
+ {
386
+ $result = false;
387
+ $ioFile = new Varien_Io_File();
388
+ $ioFile->cd($this->getMediaThemePath());
389
+ $themeFile = $themeId . '.xml';
390
+ if ($ioFile->fileExists($themeFile)) {
391
+ $result = $ioFile->rm($themeFile);
392
+ }
393
+ return $result;
394
+ }
395
+ }
app/code/core/Mage/XmlConnect/Model/Adminhtml/System/Config/Backend/Baseurl.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Xmlconnect system config base url model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Xmlconnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Model_Adminhtml_System_Config_Backend_Baseurl
35
+ extends Mage_Adminhtml_Model_System_Config_Backend_Baseurl
36
+ {
37
+ /**
38
+ * Update all applications "updated at" parameter with current date
39
+ *
40
+ * @return this
41
+ */
42
+ protected function _afterSave()
43
+ {
44
+ parent::_afterSave();
45
+ if ($this->isValueChanged()) {
46
+ Mage::getModel('xmlconnect/application')->updateAllAppsUpdatedAtParameter();
47
+ }
48
+ return $this;
49
+ }
50
+ }
app/code/core/Mage/XmlConnect/Model/Adminhtml/System/Config/Backend/Currency/Default.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Xmlconnect system config currency model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Xmlconnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Model_Adminhtml_System_Config_Backend_Currency_Default
35
+ extends Mage_Adminhtml_Model_System_Config_Backend_Currency_Default
36
+ {
37
+ /**
38
+ * Update all applications "updated at" parameter with current date
39
+ *
40
+ * @return this
41
+ */
42
+ protected function _afterSave()
43
+ {
44
+ parent::_afterSave();
45
+ if ($this->isValueChanged()) {
46
+ Mage::getModel('xmlconnect/application')->updateAllAppsUpdatedAtParameter();
47
+ }
48
+ return $this;
49
+ }
50
+ }
app/code/core/Mage/XmlConnect/Model/Application.php ADDED
@@ -0,0 +1,1219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Xmlconnect Application model
29
+ *
30
+ * @method Mage_XmlConnect_Model_Mysql4_Application _getResource()
31
+ * @method Mage_XmlConnect_Model_Mysql4_Application getResource()
32
+ * @method string getName()
33
+ * @method Mage_XmlConnect_Model_Application setName(string $value)
34
+ * @method string getCode()
35
+ * @method Mage_XmlConnect_Model_Application setCode(string $value)
36
+ * @method string getType()
37
+ * @method Mage_XmlConnect_Model_Application setType(string $value)
38
+ * @method Mage_XmlConnect_Model_Application setStoreId(int $value)
39
+ * @method string getActiveFrom()
40
+ * @method Mage_XmlConnect_Model_Application setActiveFrom(string $value)
41
+ * @method string getActiveTo()
42
+ * @method Mage_XmlConnect_Model_Application setActiveTo(string $value)
43
+ * @method string getUpdatedAt()
44
+ * @method Mage_XmlConnect_Model_Application setUpdatedAt(string $value)
45
+ * @method int getStatus()
46
+ * @method Mage_XmlConnect_Model_Application setStatus(int $value)
47
+ * @method int getBrowsingMode()
48
+ * @method Mage_XmlConnect_Model_Application setBrowsingMode(int $value)
49
+ *
50
+ * @category Mage
51
+ * @package Mage_XmlConnect
52
+ * @author Magento Core Team <core@magentocommerce.com>
53
+ */
54
+ class Mage_XmlConnect_Model_Application extends Mage_Core_Model_Abstract
55
+ {
56
+ /**
57
+ * Application code cookie name
58
+ */
59
+ const APP_CODE_COOKIE_NAME = 'app_code';
60
+
61
+ /**
62
+ * Device screen size name
63
+ */
64
+ const APP_SCREEN_SIZE_NAME = 'screen_size';
65
+
66
+ /**
67
+ * Device screen size name
68
+ */
69
+ const APP_SCREEN_SIZE_DEFAULT = '320x480';
70
+
71
+ /**
72
+ * Device screen size source name
73
+ */
74
+ const APP_SCREEN_SOURCE_DEFAULT = 'default';
75
+
76
+ /**
77
+ * Application status "submitted" value
78
+ */
79
+ const APP_STATUS_SUCCESS = 1;
80
+
81
+ /**
82
+ * Application status "not submitted" value
83
+ */
84
+ const APP_STATUS_INACTIVE = 0;
85
+
86
+ /**
87
+ * Application prefix length of cutted part of deviceType and storeCode
88
+ */
89
+ const APP_PREFIX_CUT_LENGTH = 3;
90
+
91
+ /**
92
+ * Last submitted data from history table
93
+ *
94
+ * @var null|array
95
+ */
96
+ protected $_lastParams;
97
+
98
+ /**
99
+ * Application submit info
100
+ *
101
+ * @var array
102
+ */
103
+ protected $submit_params = array();
104
+
105
+ /**
106
+ * Application submit action type
107
+ *
108
+ * @var bool
109
+ */
110
+ protected $is_resubmit_action = false;
111
+
112
+ /**
113
+ * Full application code
114
+ *
115
+ * @var null|string
116
+ */
117
+ protected $code;
118
+
119
+ /**
120
+ * Main configuration of current application
121
+ *
122
+ * @deprecated Serialized config storage has been removed
123
+ * @var null|array
124
+ */
125
+ protected $conf;
126
+
127
+ /**
128
+ * Configuration model
129
+ *
130
+ * @var Mage_XmlConnect_Model_ConfigData
131
+ */
132
+ protected $_configModel;
133
+
134
+ /**
135
+ * Flag of loaded configuration
136
+ *
137
+ * @var bool
138
+ */
139
+ protected $_isConfigurationLoaded = false;
140
+
141
+ /**
142
+ * Social networking validation array
143
+ *
144
+ * Social networking validation array specified as
145
+ * array (
146
+ * network id => API key string length
147
+ * )
148
+ *
149
+ * @var array
150
+ */
151
+ protected $_socialNetValidationArray = array(
152
+ Mage_XmlConnect_Helper_Data::SOCIAL_NETWORK_TWITTER,
153
+ Mage_XmlConnect_Helper_Data::SOCIAL_NETWORK_FACEBOOK,
154
+ Mage_XmlConnect_Helper_Data::SOCIAL_NETWORK_LINKEDIN,
155
+ );
156
+
157
+ /**
158
+ * Submission/Resubmission key max length
159
+ */
160
+ const APP_MAX_KEY_LENGTH = 40;
161
+
162
+ /**
163
+ * XML path to config with an email address
164
+ * for contact to receive credentials
165
+ * of Urban Airship notifications
166
+ */
167
+ const XML_PATH_CONTACT_CREDENTIALS_EMAIL = 'xmlconnect/mobile_application/urbanairship_credentials_email';
168
+
169
+ /**
170
+ * XML path to config with Urban Airship Terms of Service URL
171
+ */
172
+ const XML_PATH_URBAN_AIRSHIP_TOS_URL = 'xmlconnect/mobile_application/urbanairship_terms_of_service_url';
173
+
174
+ /**
175
+ * XML path to config with Urban Airship partner's login URL
176
+ */
177
+ const XML_PATH_URBAN_AIRSHIP_PARTNER_LOGIN_URL = 'xmlconnect/mobile_application/urbanairship_login_url';
178
+
179
+ /**
180
+ * XML path to config with Urban Airship Push notifications product URL
181
+ */
182
+ const XML_PATH_URBAN_AIRSHIP_ABOUT_PUSH_URL = 'xmlconnect/mobile_application/urbanairship_push_url';
183
+
184
+ /**
185
+ * XML path to config with Urban Airship Rich Push notifications product URL
186
+ */
187
+ const XML_PATH_URBAN_AIRSHIP_ABOUT_RICH_PUSH_URL = 'xmlconnect/mobile_application/urbanairship_rich_push_url';
188
+
189
+ /**
190
+ * XML path to config copyright data
191
+ */
192
+ const XML_PATH_DESIGN_FOOTER_COPYRIGHT = 'design/footer/copyright';
193
+
194
+ /**
195
+ * XML path to config restriction status
196
+ * (EE module)
197
+ */
198
+ const XML_PATH_GENERAL_RESTRICTION_IS_ACTIVE = 'general/restriction/is_active';
199
+
200
+ /**
201
+ * XML path to config restriction mode
202
+ * (EE module)
203
+ */
204
+ const XML_PATH_GENERAL_RESTRICTION_MODE = 'general/restriction/mode';
205
+
206
+ /**
207
+ * XML path to config secure base link URL
208
+ */
209
+ const XML_PATH_SECURE_BASE_LINK_URL = 'web/secure/base_link_url';
210
+
211
+ /**
212
+ * XML path to config for paypal business account
213
+ */
214
+ const XML_PATH_PAYPAL_BUSINESS_ACCOUNT = 'paypal/general/business_account';
215
+
216
+ /**
217
+ * XML path to config for default cache time
218
+ */
219
+ const XML_PATH_DEFAULT_CACHE_LIFETIME = 'xmlconnect/mobile_application/cache_lifetime';
220
+
221
+ /**
222
+ * XML path to How-To URL for twitter
223
+ */
224
+ const XML_PATH_HOWTO_TWITTER_URL = 'xmlconnect/social_networking/howto_twitter_url';
225
+
226
+ /**
227
+ * XML path to How-To URL for facebook
228
+ */
229
+ const XML_PATH_HOWTO_FACEBOOK_URL = 'xmlconnect/social_networking/howto_facebook_url';
230
+
231
+ /**
232
+ * XML path to How-To URL for linkedin
233
+ */
234
+ const XML_PATH_HOWTO_LINKEDIN_URL = 'xmlconnect/social_networking/howto_linkedin_url';
235
+
236
+ /**
237
+ * XML path to XmlConnect module version
238
+ */
239
+ const XML_PATH_MODULE_VERSION = 'modules/Mage_XmlConnect/innerVersion';
240
+
241
+ /**
242
+ * Deprecated config flag
243
+ *
244
+ * @deprecated Serialized config storage has been removed
245
+ */
246
+ const DEPRECATED_CONFIG_FLAG = 'deprecated';
247
+
248
+ /**
249
+ * Delete on update paths for config data
250
+ *
251
+ * @var array
252
+ */
253
+ protected $_deleteOnUpdateConfig = array(
254
+ self::DEPRECATED_CONFIG_FLAG => 'native/pages'
255
+ );
256
+
257
+ /**
258
+ * Initialize application
259
+ *
260
+ * @return void
261
+ */
262
+ protected function _construct()
263
+ {
264
+ $this->_init('xmlconnect/application');
265
+ $this->_configModel = Mage::getModel('xmlconnect/configData');
266
+ $this->_configModel->setDeleteOnUpdate(
267
+ $this->getDeleteOnUpdateConfig()
268
+ );
269
+ }
270
+
271
+ /**
272
+ * Checks is it app is submitted
273
+ * (edit is premitted only before submission)
274
+ *
275
+ * @return bool
276
+ */
277
+ public function getIsSubmitted()
278
+ {
279
+ return $this->getStatus() == Mage_XmlConnect_Model_Application::APP_STATUS_SUCCESS;
280
+ }
281
+
282
+ /**
283
+ * Load data (flat array) for Varien_Data_Form
284
+ *
285
+ * @return array
286
+ */
287
+ public function getFormData()
288
+ {
289
+ $data = $this->getData();
290
+ $data = Mage::helper('xmlconnect')->getDeviceHelper()->checkImages($data);
291
+ return $this->_flatArray($data);
292
+ }
293
+
294
+ /**
295
+ * Load data (flat array) for Varien_Data_Form
296
+ *
297
+ * @param array $subtree
298
+ * @param string $prefix
299
+ * @return array
300
+ */
301
+ protected function _flatArray($subtree, $prefix=null)
302
+ {
303
+ $result = array();
304
+ foreach ($subtree as $key => $value) {
305
+ if (is_null($prefix)) {
306
+ $name = $key;
307
+ } else {
308
+ $name = $prefix . '[' . $key . ']';
309
+ }
310
+
311
+ if (is_array($value)) {
312
+ $result = array_merge($result, $this->_flatArray($value, $name));
313
+ } else {
314
+ $result[$name] = $value;
315
+ }
316
+ }
317
+ return $result;
318
+ }
319
+
320
+ /**
321
+ * Like array_merge_recursive(), but string values will be replaced
322
+ *
323
+ * @param array $array1
324
+ * @param array $array2
325
+ * @return array
326
+ */
327
+ protected function _configMerge(array $array1, array $array2)
328
+ {
329
+ $result = array();
330
+ $keys = array_unique(array_merge(array_keys($array1), array_keys($array2)));
331
+ foreach ($keys as $key) {
332
+ if (!isset($array1[$key])) {
333
+ $result[$key] = $array2[$key];
334
+ } elseif (!isset($array2[$key])) {
335
+ $result[$key] = $array1[$key];
336
+ } elseif (is_scalar($array1[$key]) || is_scalar($array2[$key])) {
337
+ $result[$key] = $array2[$key];
338
+ } else {
339
+ $result[$key] = $this->_configMerge($array1[$key], $array2[$key]);
340
+ }
341
+ }
342
+ return $result;
343
+ }
344
+
345
+ /**
346
+ * Set default configuration data
347
+ *
348
+ * @return void
349
+ */
350
+ public function loadDefaultConfiguration()
351
+ {
352
+ $this->setCode($this->getCodePrefix());
353
+ $this->setConf(Mage::helper('xmlconnect')->getDeviceHelper()->getDefaultConfiguration());
354
+ }
355
+
356
+ /**
357
+ * Return first part for application code field
358
+ *
359
+ * @return string
360
+ */
361
+ public function getCodePrefix()
362
+ {
363
+ return substr(Mage::app()->getStore($this->getStoreId())->getCode(), 0, self::APP_PREFIX_CUT_LENGTH)
364
+ . substr($this->getType(), 0, self::APP_PREFIX_CUT_LENGTH);
365
+ }
366
+
367
+ /**
368
+ * Checks if application code field has autoincrement
369
+ *
370
+ * @return bool
371
+ */
372
+ public function isCodePrefixed()
373
+ {
374
+ $suffix = substr($this->getCode(), self::APP_PREFIX_CUT_LENGTH * 2);
375
+ return !empty($suffix);
376
+ }
377
+
378
+ /**
379
+ * Load application configuration
380
+ *
381
+ * @deprecated Serialized config storage has been removed
382
+ * @return array
383
+ */
384
+ public function prepareConfiguration()
385
+ {
386
+ return $this->getData('conf');
387
+ }
388
+
389
+ /**
390
+ * Get config formatted for rendering
391
+ *
392
+ * @return array
393
+ */
394
+ public function getRenderConf()
395
+ {
396
+ $result = Mage::helper('xmlconnect')->getDeviceHelper()->getDefaultConfiguration();
397
+ $result = $result['native'];
398
+
399
+ if (isset($this->_data['conf'])) {
400
+ if (isset($this->_data['conf']['native'])) {
401
+ $result = $this->_configMerge($result, $this->_data['conf']['native']);
402
+ }
403
+ if (isset($this->_data['conf']['extra'])) {
404
+ $extra = $this->_data['conf']['extra'];
405
+ if (isset($extra['tabs'])) {
406
+ $tabs = Mage::getModel('xmlconnect/tabs', $extra['tabs']);
407
+ $result['tabBar']['tabs'] = $tabs;
408
+ }
409
+ if (isset($extra['fontColors'])) {
410
+ if (!empty($extra['fontColors']['header'])) {
411
+ $result['fonts']['Title1']['color'] = $extra['fontColors']['header'];
412
+ }
413
+ if (!empty($extra['fontColors']['primary'])) {
414
+ $result['fonts']['Title2']['color'] = $extra['fontColors']['primary'];
415
+ $result['fonts']['Title3']['color'] = $extra['fontColors']['primary'];
416
+ $result['fonts']['Text1']['color'] = $extra['fontColors']['primary'];
417
+ $result['fonts']['Text2']['color'] = $extra['fontColors']['primary'];
418
+ $result['fonts']['Title7']['color'] = $extra['fontColors']['primary'];
419
+ }
420
+ if (!empty($extra['fontColors']['secondary'])) {
421
+ $result['fonts']['Title4']['color'] = $extra['fontColors']['secondary'];
422
+ $result['fonts']['Title6']['color'] = $extra['fontColors']['secondary'];
423
+ $result['fonts']['Title8']['color'] = $extra['fontColors']['secondary'];
424
+ $result['fonts']['Title9']['color'] = $extra['fontColors']['secondary'];
425
+ }
426
+ if (!empty($extra['fontColors']['price'])) {
427
+ $result['fonts']['Title5']['color'] = $extra['fontColors']['price'];
428
+ }
429
+ }
430
+ }
431
+ }
432
+
433
+ /** @var $helperImage Mage_XmlConnect_Helper_Image */
434
+ $helperImage = Mage::helper('xmlconnect/image');
435
+ $paths = $helperImage->getInterfaceImagesPathsConf();
436
+
437
+ foreach ($paths as $confPath => $dataPath) {
438
+ $imageNodeValue =& $helperImage->findPath($result, $dataPath);
439
+
440
+ if (!$helperImage->checkAndGetImagePath($imageNodeValue)) {
441
+ /**
442
+ * We set empty string to get default image if original was missing in some reason
443
+ */
444
+ $imageNodeValue = '';
445
+ } else {
446
+ /**
447
+ * Creating file ending (some_inner/some_dir/filename.png) For url
448
+ */
449
+ $imageNodeValue = $helperImage->getFileCustomDirSuffixAsUrl($confPath, $imageNodeValue);
450
+ }
451
+ }
452
+ $result = $this->_absPath($result);
453
+
454
+ /**
455
+ * General configuration
456
+ */
457
+ $result['general']['updateTimeUTC'] = strtotime($this->getUpdatedAt());
458
+ $result['general']['browsingMode'] = $this->getBrowsingMode();
459
+ $result['general']['currencyCode'] = Mage::app()->getStore($this->getStoreId())->getDefaultCurrencyCode();
460
+ $result['general']['secureBaseUrl'] = $this->getSecureBaseUrl();
461
+
462
+ $maxRecipients = 0;
463
+ $allowGuest = 0;
464
+ if (Mage::getStoreConfig(Mage_Sendfriend_Helper_Data::XML_PATH_ENABLED)) {
465
+ $maxRecipients = Mage::getStoreConfig(Mage_Sendfriend_Helper_Data::XML_PATH_MAX_RECIPIENTS);
466
+ $allowGuest = Mage::getStoreConfig(Mage_Sendfriend_Helper_Data::XML_PATH_ALLOW_FOR_GUEST);
467
+ }
468
+ $result['general']['emailToFriendMaxRecepients'] = $maxRecipients;
469
+ $result['general']['emailAllowGuest'] = $allowGuest;
470
+ $result['general']['primaryStoreLang'] = Mage::app()
471
+ ->getStore($this->getStoreId())->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE);
472
+ $result['general']['magentoVersion'] = Mage::getVersion();
473
+ $result['general']['copyright'] = Mage::getStoreConfig(
474
+ self::XML_PATH_DESIGN_FOOTER_COPYRIGHT,
475
+ $this->getStoreId()
476
+ );
477
+ $result['general']['xmlconnectVersion'] = Mage::getConfig()->getNode(self::XML_PATH_MODULE_VERSION);
478
+
479
+ $result['general']['isAllowedGuestCheckout'] = (int)Mage::getSingleton('checkout/session')
480
+ ->getQuote()->isAllowedGuestCheckout();
481
+
482
+ /**
483
+ * Check is guest can post product reviews
484
+ */
485
+ if (Mage::helper('review')->getIsGuestAllowToWrite()) {
486
+ $result['general']['isAllowedGuestReview'] = '1';
487
+ } else {
488
+ $result['general']['isAllowedGuestReview'] = '0';
489
+ }
490
+
491
+ /**
492
+ * Check is wishlist enabled in a config
493
+ */
494
+ if (Mage::getStoreConfigFlag('wishlist/general/active')) {
495
+ $result['general']['wishlistEnable'] = '1';
496
+ } else {
497
+ $result['general']['wishlistEnable'] = '0';
498
+ }
499
+
500
+ /**
501
+ * "Use Secure URLs in Frontend" flag
502
+ */
503
+ $result['general']['useSecureURLInFrontend'] = $this->getUseSecureURLInFrontend();
504
+
505
+ /**
506
+ * Is enabled Store credit functionality
507
+ */
508
+ if (is_object(Mage::getConfig()->getNode('modules/Enterprise_CustomerBalance'))) {
509
+ $storeCreditFlag = Mage::getStoreConfig(Enterprise_CustomerBalance_Helper_Data::XML_PATH_ENABLED);
510
+ $isStoreCreditEnable = (int)$storeCreditFlag;
511
+ $canShowHistoryFlag = (int) Mage::getStoreConfigFlag(
512
+ 'customer/enterprise_customerbalance/show_history'
513
+ );
514
+ } else {
515
+ $isStoreCreditEnable = $canShowHistoryFlag = 0;
516
+ }
517
+ $result['general']['isStoreCreditEnabled'] = $isStoreCreditEnable;
518
+ $result['general']['isStoreCreditHistoryEnabled'] = $canShowHistoryFlag;
519
+
520
+ /**
521
+ * Is available Gift Card functionality
522
+ */
523
+ $result['general']['isGiftcardEnabled'] = (int) is_object(
524
+ Mage::getConfig()->getNode('modules/Enterprise_GiftCard')
525
+ );
526
+
527
+ /**
528
+ * PayPal configuration
529
+ */
530
+ $result['paypal']['businessAccount'] = Mage::getModel('paypal/config')->businessAccount;
531
+ $result['paypal']['merchantLabel'] = $this->getData('conf/special/merchantLabel');
532
+
533
+ $isActive = 0;
534
+ $paypalMepIsAvailable = Mage::getModel('xmlconnect/payment_method_paypal_mep')->isAvailable(null);
535
+ if ($paypalMepIsAvailable && isset($result['paypal']['isActive'])) {
536
+ $isActive = (int) $result['paypal']['isActive'];
537
+ }
538
+ $result['paypal']['isActive'] = $isActive;
539
+
540
+ $paypalMeclIsAvailable = Mage::getModel('xmlconnect/payment_method_paypal_mecl')->isAvailable(null);
541
+
542
+ /**
543
+ * PayPal Mobile Express Library Checkout
544
+ */
545
+ $result['paypalMecl']['isActive'] = (int) (
546
+ $paypalMeclIsAvailable
547
+ && $this->getData('config_data/payment/paypalmecl_is_active')
548
+ );
549
+
550
+ if ((int)Mage::getStoreConfig(self::XML_PATH_GENERAL_RESTRICTION_IS_ACTIVE)) {
551
+ $result['website_restrictions']['mode'] = (int)Mage::getStoreConfig(
552
+ self::XML_PATH_GENERAL_RESTRICTION_MODE
553
+ );
554
+ }
555
+
556
+ ksort($result);
557
+ return $result;
558
+ }
559
+
560
+ /**
561
+ * Get secure base url
562
+ *
563
+ * @return string
564
+ */
565
+ public function getSecureBaseUrl()
566
+ {
567
+ return Mage::getStoreConfig(
568
+ self::XML_PATH_SECURE_BASE_LINK_URL,
569
+ $this->getStoreId()
570
+ );
571
+ }
572
+
573
+ /**
574
+ * Is forced front secure url
575
+ *
576
+ * @return int
577
+ */
578
+ public function getUseSecureURLInFrontend()
579
+ {
580
+ return (int) Mage::getStoreConfigFlag(
581
+ Mage_Core_Model_Store::XML_PATH_SECURE_IN_FRONTEND
582
+ );
583
+ }
584
+
585
+ /**
586
+ * Return current screen_size parameter
587
+ *
588
+ * @return string
589
+ */
590
+ public function getScreenSize()
591
+ {
592
+ if (!isset($this->_data['screen_size'])) {
593
+ $this->_data['screen_size'] = self::APP_SCREEN_SIZE_DEFAULT;
594
+ }
595
+ return $this->_data['screen_size'];
596
+ }
597
+
598
+ /**
599
+ * Setter
600
+ * for current screen_size parameter
601
+ *
602
+ * @param string $screenSize
603
+ * @return this
604
+ */
605
+ public function setScreenSize($screenSize)
606
+ {
607
+ $this->_data['screen_size'] = Mage::helper('xmlconnect/image')->filterScreenSize((string) $screenSize);
608
+ return $this;
609
+ }
610
+
611
+ /**
612
+ * Return Enabled Tabs array from actual config
613
+ *
614
+ * @return array:
615
+ */
616
+ public function getEnabledTabsArray()
617
+ {
618
+ if ($this->getData('conf/extra/tabs')) {
619
+ return Mage::getModel('xmlconnect/tabs', $this->getData('conf/extra/tabs'))->getRenderTabs();
620
+ }
621
+ return array();
622
+ }
623
+
624
+ /**
625
+ * Change URLs to absolute
626
+ *
627
+ * @param array $subtree
628
+ * @return array
629
+ */
630
+ protected function _absPath($subtree)
631
+ {
632
+ foreach ($subtree as $key => $value) {
633
+ if (!empty($value)) {
634
+ if (is_array($value)) {
635
+ $subtree[$key] = $this->_absPath($value);
636
+ } elseif (strtolower(substr($key, -4)) == 'icon'
637
+ || strtolower(substr($key, -5)) == 'image'
638
+ ) {
639
+ $subtree[$key] = Mage::getBaseUrl('media') . 'xmlconnect/' . $value;
640
+ }
641
+ }
642
+ }
643
+ return $subtree;
644
+ }
645
+
646
+ /**
647
+ * Return content pages
648
+ *
649
+ * @return array
650
+ */
651
+ public function getPages()
652
+ {
653
+ if (isset($this->_data['conf']['native']['pages'])) {
654
+ return $this->_data['conf']['native']['pages'];
655
+ }
656
+ return array();
657
+ }
658
+
659
+ /**
660
+ * Get configuration model
661
+ *
662
+ * @return Mage_XmlConnect_Model_ConfigData
663
+ */
664
+ public function getConfigModel()
665
+ {
666
+ return $this->_configModel;
667
+ }
668
+
669
+ /**
670
+ * Processing object before save data
671
+ *
672
+ * @return Mage_XmlConnect_Model_Application
673
+ */
674
+ protected function _beforeSave()
675
+ {
676
+ $this->setUpdatedAt(
677
+ Mage::getSingleton('core/date')->gmtDate()
678
+ );
679
+ return $this;
680
+ }
681
+
682
+ /**
683
+ * Processing object after save data
684
+ *
685
+ * @return Mage_XmlConnect_Model_Application
686
+ */
687
+ protected function _afterSave()
688
+ {
689
+ $this->_saveConfigData();
690
+ $this->_saveDeprecatedConfig();
691
+ parent::_afterSave();
692
+ return $this;
693
+ }
694
+
695
+ /**
696
+ * Save configuration data of application model
697
+ *
698
+ * @return Mage_XmlConnect_Model_Application
699
+ */
700
+ protected function _saveConfigData()
701
+ {
702
+ $configuration = $this->getData('config_data');
703
+ if (is_array($configuration)) {
704
+ $this->getConfigModel()
705
+ ->setConfigData($this->getId(), $configuration)
706
+ ->initSaveConfig();
707
+ }
708
+ return $this;
709
+ }
710
+
711
+ /**
712
+ * Save old deprecated config to application config data table
713
+ *
714
+ * @deprecated Serialized config storage has been removed
715
+ * @return Mage_XmlConnect_Model_Application
716
+ */
717
+ private function _saveDeprecatedConfig()
718
+ {
719
+ $deprecatedConfig = $this->getData('conf');
720
+ if (is_array($deprecatedConfig)) {
721
+ $this->getConfigModel()->saveConfig(
722
+ $this->getId(),
723
+ $this->convertOldConfing($deprecatedConfig),
724
+ self::DEPRECATED_CONFIG_FLAG
725
+ );
726
+ }
727
+ return $this;
728
+ }
729
+
730
+ /**
731
+ * Convert deprecated configuration array to new standard
732
+ *
733
+ * @deprecated Serialized config storage has been removed
734
+ * @param array $conf
735
+ * @param bool $path
736
+ * @return array
737
+ */
738
+ public function convertOldConfing(array $conf, $path = false)
739
+ {
740
+ $result = array();
741
+ foreach ($conf as $key => $val) {
742
+ $key = $path ? $path . '/' . $key : $key;
743
+ if (is_array($val)) {
744
+ $result += $this->convertOldConfing($val, $key);
745
+ } else {
746
+ $result[$key] = $val;
747
+ }
748
+ }
749
+ return $result;
750
+ }
751
+
752
+ /**
753
+ * Load configuration data (from serialized blob)
754
+ *
755
+ * @return Mage_XmlConnect_Model_Application
756
+ */
757
+ public function loadConfiguration()
758
+ {
759
+ if (!$this->_isConfigurationLoaded) {
760
+ if ($this->getId()) {
761
+ $this->_loadDeprecatedConfig()
762
+ ->_loadConfigData();
763
+ $this->_isConfigurationLoaded = true;
764
+ }
765
+ }
766
+ return $this;
767
+ }
768
+
769
+ /**
770
+ * Load configuration data
771
+ *
772
+ * @internal re-factoring in progress
773
+ * @return Mage_XmlConnect_Model_Application
774
+ */
775
+ protected function _loadConfigData()
776
+ {
777
+ $configuration = $this->getConfigModel()
778
+ ->getCollection()
779
+ ->addArrayFilter(
780
+ array(
781
+ 'application_id' => $this->getId(),
782
+ 'category' => 'payment'
783
+ )
784
+ )
785
+ ->toOptionArray();
786
+ $this->setData('config_data', $configuration);
787
+ return $this;
788
+ }
789
+
790
+ /**
791
+ * Load deprecated configuration
792
+ *
793
+ * @deprecated Serialized config storage has been removed
794
+ * @return Mage_XmlConnect_Model_Application
795
+ */
796
+ private function _loadDeprecatedConfig()
797
+ {
798
+ $configuration = $this->_convertConfig(
799
+ $this->getConfigModel()
800
+ ->getCollection()
801
+ ->addArrayFilter(
802
+ array(
803
+ 'application_id' => $this->getId(),
804
+ 'category' => self::DEPRECATED_CONFIG_FLAG
805
+ )
806
+ )
807
+ ->toOptionArray()
808
+ );
809
+ $this->setData('conf', $configuration);
810
+ return $this;
811
+ }
812
+
813
+ /**
814
+ * Convert old config data array
815
+ *
816
+ * @deprecated Serialized config storage has been removed
817
+ * @param $config
818
+ * @return array
819
+ */
820
+ protected function _convertConfig($config)
821
+ {
822
+ $result = array();
823
+ foreach ($config as $values) {
824
+ foreach ($values as $path => $value) {
825
+ if (preg_match('@[^\w\/]@', $path)) {
826
+ Mage::throwException(
827
+ Mage::helper('xmlconnect')->__('Unsupported character in path: "%s"', $path)
828
+ );
829
+ }
830
+ $keyArray = explode('/', $path);
831
+ $keys = '$result["' . implode('"]["', $keyArray) . '"]';
832
+ eval($keys . ' = $value;');
833
+ }
834
+ }
835
+ return $result;
836
+ }
837
+
838
+ /**
839
+ * Load application by code
840
+ *
841
+ * @param string $code
842
+ * @return Mage_XmlConnect_Model_Application
843
+ */
844
+ public function loadByCode($code)
845
+ {
846
+ $this->_getResource()->load($this, $code, 'code');
847
+ return $this;
848
+ }
849
+
850
+ /**
851
+ * Loads submit tab data from xmlconnect/history table
852
+ *
853
+ * @return bool
854
+ */
855
+ public function loadSubmit()
856
+ {
857
+ $isResubmitAction = false;
858
+ if ($this->getId()) {
859
+ $params = $this->getLastParams();
860
+ if (!empty($params)) {
861
+ // Using Pointer !
862
+ $conf = &$this->_data['conf'];
863
+ if (!isset($conf['submit_text']) || !is_array($conf['submit_text'])) {
864
+ $conf['submit_text'] = array();
865
+ }
866
+ if (!isset($conf['submit_restore']) || !is_array($conf['submit_restore'])) {
867
+ $conf['submit_restore'] = array();
868
+ }
869
+ foreach ($params as $id => $value) {
870
+ $deviceImages = Mage::helper('xmlconnect')
871
+ ->getDeviceHelper()
872
+ ->getSubmitImages();
873
+
874
+ if (!in_array($id, $deviceImages)) {
875
+ $conf['submit_text'][$id] = $value;
876
+ } else {
877
+ $conf['submit_restore'][$id] = $value;
878
+ }
879
+ $isResubmitAction = true;
880
+ }
881
+ }
882
+ }
883
+ $this->setIsResubmitAction($isResubmitAction);
884
+ return $isResubmitAction;
885
+ }
886
+
887
+ /**
888
+ * Returns ( image[ ID ] => "SRC" ) array
889
+ *
890
+ * @return array
891
+ */
892
+ public function getImages()
893
+ {
894
+ $images = array();
895
+ $params = $this->getLastParams();
896
+ $deviceImages = Mage::helper('xmlconnect')
897
+ ->getDeviceHelper()
898
+ ->getSubmitImages();
899
+
900
+ foreach ($deviceImages as $id) {
901
+ $path = $this->getData('conf/submit/'.$id);
902
+ $basename = null;
903
+ if (!empty($path)) {
904
+ /**
905
+ * Fetching data from session restored array
906
+ */
907
+ $basename = basename($path);
908
+ } elseif (isset($params[$id])) {
909
+ /**
910
+ * Fetching data from submission history table record
911
+ *
912
+ * converting : "@\var\somedir\media\xmlconnect\form_icon_6.png"
913
+ * to "\var\somedir\media\xmlconnect\forn_icon_6.png"
914
+ */
915
+ $basename = basename($params[$id]);
916
+ }
917
+ if (!empty($basename)) {
918
+ $images['conf/submit/'.$id] = Mage::getBaseUrl('media') . 'xmlconnect/'
919
+ . Mage::helper('xmlconnect/image')->getFileDefaultSizeSuffixAsUrl($basename);
920
+ }
921
+ }
922
+ return $images;
923
+ }
924
+
925
+ /**
926
+ * Return last submitted data from history table
927
+ *
928
+ * @return array
929
+ */
930
+ public function getLastParams()
931
+ {
932
+ if (!isset($this->_lastParams)) {
933
+ $this->_lastParams = Mage::getModel('xmlconnect/history')->getLastParams($this->getId());
934
+ }
935
+ return $this->_lastParams;
936
+ }
937
+
938
+ /**
939
+ * Validate application data
940
+ *
941
+ * @return array|bool
942
+ */
943
+ public function validate()
944
+ {
945
+ $errors = array();
946
+
947
+ $validateConf = $this->_validateConf();
948
+ if ($validateConf !== true) {
949
+ $errors = $validateConf;
950
+ }
951
+
952
+ if (!Zend_Validate::is($this->getName(), 'NotEmpty')) {
953
+ $errors[] = Mage::helper('xmlconnect')->__('Please enter "App Title".');
954
+ }
955
+
956
+ if (empty($errors)) {
957
+ return true;
958
+ }
959
+ return $errors;
960
+ }
961
+
962
+ /**
963
+ * Validate submit application data
964
+ *
965
+ * @param array $params
966
+ * @return array|bool
967
+ */
968
+ public function validateSubmit($params)
969
+ {
970
+ $errors = array();
971
+ $validateConf = $this->_validateConf();
972
+ if ($validateConf !== true) {
973
+ $errors = $validateConf;
974
+ }
975
+
976
+ $submitErrors = Mage::helper('xmlconnect')->getDeviceHelper($this)->validateSubmit($params);
977
+
978
+ if (count($submitErrors)) {
979
+ $errors = array_merge($errors, $submitErrors);
980
+ }
981
+ if (empty($errors)) {
982
+ return true;
983
+ }
984
+ return $errors;
985
+ }
986
+
987
+ /**
988
+ * Check config for valid values
989
+ *
990
+ * @return bool|array
991
+ */
992
+ protected function _validateConf()
993
+ {
994
+ $conf = $this->getConf();
995
+ $native = isset($conf['native']) && is_array($conf['native']) ? $conf['native'] : false;
996
+ $errors = Mage::helper('xmlconnect')->getDeviceHelper($this)->validateConfig($native);
997
+
998
+ foreach ($this->_socialNetValidationArray as $networkKey) {
999
+ if (isset($native['socialNetworking'][$networkKey]['isActive'])
1000
+ && $native['socialNetworking'][$networkKey]['isActive']
1001
+ ) {
1002
+ if ($networkKey !== Mage_XmlConnect_Helper_Data::SOCIAL_NETWORK_FACEBOOK) {
1003
+ $networkName = ucfirst($networkKey);
1004
+ if (!isset($native['socialNetworking'][$networkKey]['apiKey'])
1005
+ || !Zend_Validate::is($native['socialNetworking'][$networkKey]['apiKey'], 'NotEmpty')
1006
+ ) {
1007
+ $errors[] = Mage::helper('xmlconnect')->__('%s API Key required.', $networkName);
1008
+ }
1009
+ if (!isset($native['socialNetworking'][$networkKey]['secretKey'])
1010
+ || !Zend_Validate::is($native['socialNetworking'][$networkKey]['secretKey'], 'NotEmpty')
1011
+ ) {
1012
+ $errors[] = Mage::helper('xmlconnect')->__('%s Secret Key required.', $networkName);
1013
+ }
1014
+ } else {
1015
+ $networkName = ucfirst($networkKey);
1016
+ if (!isset($native['socialNetworking'][$networkKey]['appID'])
1017
+ || !Zend_Validate::is($native['socialNetworking'][$networkKey]['appID'], 'NotEmpty')
1018
+ ) {
1019
+ $errors[] = Mage::helper('xmlconnect')->__('%s Application ID required.', $networkName);
1020
+ }
1021
+ }
1022
+ }
1023
+ }
1024
+
1025
+ if (empty($errors)) {
1026
+ return true;
1027
+ }
1028
+ return $errors;
1029
+ }
1030
+
1031
+ /**
1032
+ * Imports post/get data into the model
1033
+ *
1034
+ * @param array $data - $_REQUEST[]
1035
+ * @return array
1036
+ */
1037
+ public function prepareSubmitParams($data)
1038
+ {
1039
+ $params = array();
1040
+ if (isset($data['conf']) && is_array($data['conf'])) {
1041
+
1042
+ if (isset($data['conf']['submit_text']) && is_array($data['conf']['submit_text'])) {
1043
+ $params = $data['conf']['submit_text'];
1044
+ }
1045
+
1046
+ $params['name'] = $this->getName();
1047
+ $params['code'] = $this->getCode();
1048
+ $params['type'] = $this->getType();
1049
+ $params['url'] = Mage::getUrl('xmlconnect/configuration/index', array(
1050
+ '_store' => $this->getStoreId(),
1051
+ '_nosid' => true,
1052
+ 'app_code' => $this->getCode()
1053
+ ));
1054
+
1055
+ $params['magentoversion'] = Mage::getVersion();
1056
+
1057
+ if (isset($params['country']) && is_array($params['country'])) {
1058
+ $params['country'] = implode(',', $params['country']);
1059
+ }
1060
+ if ($this->getIsResubmitAction()) {
1061
+ if (isset($params['resubmission_activation_key'])) {
1062
+ $params['resubmission_activation_key'] = trim($params['resubmission_activation_key']);
1063
+ $params['key'] = $params['resubmission_activation_key'];
1064
+ } else {
1065
+ $params['key'] = '';
1066
+ }
1067
+ } else {
1068
+ $params['key'] = isset($params['key']) ? trim($params['key']) : '';
1069
+ }
1070
+
1071
+ // processing files
1072
+ $submit = array();
1073
+ if (isset($this->_data['conf']['submit']) && is_array($this->_data['conf']['submit'])) {
1074
+ $submit = $this->_data['conf']['submit'];
1075
+ }
1076
+
1077
+ $submitRestore = array();
1078
+ if (isset($this->_data['conf']['submit_restore']) && is_array($this->_data['conf']['submit_restore'])) {
1079
+ $submitRestore = $this->_data['conf']['submit_restore'];
1080
+ }
1081
+
1082
+ $deviceImages = Mage::helper('xmlconnect')
1083
+ ->getDeviceHelper()
1084
+ ->getSubmitImages();
1085
+
1086
+ foreach ($deviceImages as $id) {
1087
+ if (isset($submit[$id])) {
1088
+ $params[$id] = '@' . Mage::helper('xmlconnect/image')->getDefaultSizeUploadDir() . DS
1089
+ . $submit[$id];
1090
+ } elseif (isset($submitRestore[$id])) {
1091
+ $params[$id] = $submitRestore[$id];
1092
+ }
1093
+ }
1094
+ }
1095
+ $this->setSubmitParams($params);
1096
+ return $params;
1097
+ }
1098
+
1099
+ /**
1100
+ * Retrieve Store Id
1101
+ *
1102
+ * @return int
1103
+ */
1104
+ public function getStoreId()
1105
+ {
1106
+ if ($this->hasData('store_id')) {
1107
+ return $this->getData('store_id');
1108
+ }
1109
+ return Mage::app()->getStore()->getId();
1110
+ }
1111
+
1112
+ /**
1113
+ * Getter, returns activation key for current application
1114
+ *
1115
+ * @return string|null
1116
+ */
1117
+ public function getActivationKey()
1118
+ {
1119
+ $key = null;
1120
+ if (isset($this->_data['conf']['submit_text']['key'])) {
1121
+ $key = $this->_data['conf']['submit_text']['key'];
1122
+ }
1123
+ return $key;
1124
+ }
1125
+
1126
+ /**
1127
+ * Perform update for all applications "updated at" parameter with current date
1128
+ *
1129
+ * @return Mage_XmlConnect_Model_Application
1130
+ */
1131
+ public function updateAllAppsUpdatedAtParameter()
1132
+ {
1133
+ $this->_getResource()->updateAllAppsUpdatedAtParameter();
1134
+ return $this;
1135
+ }
1136
+
1137
+ /**
1138
+ * Checks if notifications is active
1139
+ *
1140
+ * @return boolean
1141
+ */
1142
+ public function isNotificationsActive()
1143
+ {
1144
+ return (boolean)$this->loadConfiguration()->getData('conf/native/notifications/isActive');
1145
+ }
1146
+
1147
+ /**
1148
+ * Getter return concatenated user and password
1149
+ *
1150
+ * @return string
1151
+ */
1152
+ public function getUserpwd()
1153
+ {
1154
+ return $this->loadConfiguration()->getAppKey() . ':' . $this->getAppMasterSecret();
1155
+ }
1156
+
1157
+ /**
1158
+ * Getter for Application Key
1159
+ *
1160
+ * @return string
1161
+ */
1162
+ public function getAppKey()
1163
+ {
1164
+ return $this->getData('conf/native/notifications/applicationKey');
1165
+ }
1166
+
1167
+ /**
1168
+ * Getter for Application Secret
1169
+ *
1170
+ * @return string
1171
+ */
1172
+ public function getAppSecret()
1173
+ {
1174
+ return $this->getData('conf/native/notifications/applicationSecret');
1175
+ }
1176
+
1177
+ /**
1178
+ * Getter for Application Master Secret
1179
+ *
1180
+ * @return string
1181
+ */
1182
+ public function getAppMasterSecret()
1183
+ {
1184
+ return $this->getData('conf/native/notifications/applicationMasterSecret');
1185
+ }
1186
+
1187
+ /**
1188
+ * Getter for Application Cache Lifetime
1189
+ *
1190
+ * @return int|string
1191
+ */
1192
+ public function getCacheLifetime()
1193
+ {
1194
+ $lifetime = (int)$this->loadConfiguration()->getData('conf/native/cacheLifetime');
1195
+ return $lifetime <= 0 ? '' : $lifetime;
1196
+ }
1197
+
1198
+ /**
1199
+ * Get delete on update paths for config data
1200
+ *
1201
+ * @return array
1202
+ */
1203
+ public function getDeleteOnUpdateConfig()
1204
+ {
1205
+ return $this->_deleteOnUpdateConfig;
1206
+ }
1207
+
1208
+ /**
1209
+ * Set delete on update paths for config data
1210
+ *
1211
+ * @param array $pathsToDelete
1212
+ * @return Mage_XmlConnect_Model_Application
1213
+ */
1214
+ public function setDeleteOnUpdateConfig(array $pathsToDelete)
1215
+ {
1216
+ $this->_deleteOnUpdateConfig = array_merge($this->_deleteOnUpdateConfig, $pathsToDelete);
1217
+ return $this;
1218
+ }
1219
+ }
app/code/core/Mage/XmlConnect/Model/Catalog/Category/Image.php ADDED
@@ -0,0 +1,206 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Catalog category link model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Model_Catalog_Category_Image extends Mage_Catalog_Model_Product_Image
35
+ {
36
+ /**
37
+ * Set filenames for base file and new file
38
+ *
39
+ * @param string $file
40
+ * @return Mage_Catalog_Model_Product_Image
41
+ */
42
+ public function setBaseFile($file)
43
+ {
44
+ $this->_isBaseFilePlaceholder = false;
45
+
46
+ if (($file) && (0 !== strpos($file, '/', 0))) {
47
+ $file = '/' . $file;
48
+ }
49
+ $baseDir = Mage::getSingleton('xmlconnect/catalog_category_media_config')->getBaseMediaPath();
50
+
51
+ if ('/no_selection' == $file) {
52
+ $file = null;
53
+ }
54
+ if ($file) {
55
+ if ((!file_exists($baseDir . $file)) || !$this->_checkMemory($baseDir . $file)) {
56
+ $file = null;
57
+ }
58
+ }
59
+ if (!$file) {
60
+ // check if placeholder defined in config
61
+ $isConfigPlaceholder = Mage::getStoreConfig(
62
+ 'catalog/placeholder/'
63
+ . $this->getDestinationSubdir()
64
+ . '_placeholder'
65
+ );
66
+ $configPlaceholder = '/placeholder/' . $isConfigPlaceholder;
67
+ if ($isConfigPlaceholder && file_exists($baseDir . $configPlaceholder)) {
68
+ $file = $configPlaceholder;
69
+ } else {
70
+ // replace file with skin or default skin placeholder
71
+ $skinBaseDir = Mage::getDesign()->getSkinBaseDir();
72
+ $skinPlaceholder = '/images/xmlconnect/catalog/category/placeholder/'
73
+ . $this->getDestinationSubdir()
74
+ . '.jpg';
75
+
76
+ $file = $skinPlaceholder;
77
+ if (file_exists($skinBaseDir . $file)) {
78
+ $baseDir = $skinBaseDir;
79
+ } else {
80
+ $baseDir = Mage::getDesign()->getSkinBaseDir(
81
+ array('_theme' => 'default')
82
+ );
83
+ if (!file_exists($baseDir . $file)) {
84
+ $baseDir = Mage::getDesign()->getSkinBaseDir(
85
+ array('_theme' => 'default', '_package' => 'base')
86
+ );
87
+ }
88
+ }
89
+ }
90
+ $this->_isBaseFilePlaceholder = true;
91
+ }
92
+
93
+ $baseFile = $baseDir . $file;
94
+
95
+ if ((!$file) || (!file_exists($baseFile))) {
96
+ Mage::throwException(
97
+ Mage::helper('xmlconnect')->__('Image file was not found.')
98
+ );
99
+ }
100
+
101
+ $this->_baseFile = $baseFile;
102
+
103
+ // build new filename (most important params)
104
+ $path = array(
105
+ Mage::getSingleton('xmlconnect/catalog_category_media_config')->getBaseMediaPath(),
106
+ 'cache',
107
+ Mage::app()->getStore()->getId(),
108
+ $path[] = $this->getDestinationSubdir()
109
+ );
110
+ if ((!empty($this->_width)) || (!empty($this->_height))) {
111
+ $path[] = "{$this->_width}x{$this->_height}";
112
+ }
113
+
114
+ // add misk params as a hash
115
+ $miscParams = array(
116
+ ($this->_keepAspectRatio ? '' : 'non') . 'proportional',
117
+ ($this->_keepFrame ? '' : 'no') . 'frame',
118
+ ($this->_keepTransparency ? '' : 'no') . 'transparency',
119
+ ($this->_constrainOnly ? 'do' : 'not') . 'constrainonly',
120
+ $this->_rgbToString($this->_backgroundColor),
121
+ 'angle' . $this->_angle,
122
+ 'quality' . $this->_quality
123
+ );
124
+
125
+ // if has watermark add watermark params to hash
126
+ if ($this->getWatermarkFile()) {
127
+ $miscParams[] = $this->getWatermarkFile();
128
+ $miscParams[] = $this->getWatermarkImageOpacity();
129
+ $miscParams[] = $this->getWatermarkPosition();
130
+ $miscParams[] = $this->getWatermarkWidth();
131
+ $miscParams[] = $this->getWatermarkHeigth();
132
+ }
133
+
134
+ $path[] = md5(implode('_', $miscParams));
135
+
136
+ // append prepared filename
137
+ $this->_newFile = implode('/', $path) . $file; // the $file contains heading slash
138
+
139
+ return $this;
140
+ }
141
+
142
+ /**
143
+ * Get relative watermark file path
144
+ * or false if file not found
145
+ *
146
+ * @return string | bool
147
+ */
148
+ protected function _getWatermarkFilePath()
149
+ {
150
+ $filePath = false;
151
+
152
+ if (!$file = $this->getWatermarkFile()) {
153
+ return $filePath;
154
+ }
155
+
156
+ $baseDir = Mage::getSingleton('xmlconnect/catalog_category_media_config')->getBaseMediaPath();
157
+
158
+ if (file_exists($baseDir . '/watermark/stores/' . Mage::app()->getStore()->getId() . $file)) {
159
+ $filePath = $baseDir . '/watermark/stores/' . Mage::app()->getStore()->getId() . $file;
160
+ } elseif (file_exists($baseDir . '/watermark/websites/' . Mage::app()->getWebsite()->getId() . $file)) {
161
+ $filePath = $baseDir . '/watermark/websites/' . Mage::app()->getWebsite()->getId() . $file;
162
+ } elseif (file_exists($baseDir . '/watermark/default/' . $file)) {
163
+ $filePath = $baseDir . '/watermark/default/' . $file;
164
+ } elseif (file_exists($baseDir . '/watermark/' . $file)) {
165
+ $filePath = $baseDir . '/watermark/' . $file;
166
+ } else {
167
+ $baseDir = Mage::getDesign()->getSkinBaseDir();
168
+ if (file_exists($baseDir . $file)) {
169
+ $filePath = $baseDir . $file;
170
+ }
171
+ }
172
+
173
+ return $filePath;
174
+ }
175
+
176
+ /**
177
+ * Clear catalog cache
178
+ *
179
+ * @return void
180
+ */
181
+ public function clearCache()
182
+ {
183
+ $directory = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category' . DS . 'cache' . DS;
184
+ $ioFile = new Varien_Io_File();
185
+ $ioFile->rmdir($directory, true);
186
+ }
187
+
188
+ /**
189
+ * Convert array of 3 items (decimal r, g, b) to string of their hex values
190
+ *
191
+ * @param array $rgbArray
192
+ * @return string
193
+ */
194
+ protected function _rgbToString($rgbArray)
195
+ {
196
+ $result = array();
197
+ foreach ($rgbArray as $value) {
198
+ if (null === $value) {
199
+ $result[] = 'null';
200
+ } else {
201
+ $result[] = sprintf('%02s', dechex($value));
202
+ }
203
+ }
204
+ return implode($result);
205
+ }
206
+ }
app/code/core/Mage/XmlConnect/Model/Catalog/Category/Media/Config.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Catalog category media config
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Catalog
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Model_Catalog_Category_Media_Config extends Mage_Catalog_Model_Product_Media_Config
35
+ {
36
+ /**
37
+ * Getter, return Catalog baseMediaPath
38
+ *
39
+ * @return string
40
+ */
41
+ public function getBaseMediaPath()
42
+ {
43
+ return Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category';
44
+ }
45
+
46
+ /**
47
+ * Getter, return catalog baseMediaUrl
48
+ *
49
+ * @return string
50
+ */
51
+ public function getBaseMediaUrl()
52
+ {
53
+ return Mage::getBaseUrl('media') . 'catalog/category';
54
+ }
55
+
56
+ /**
57
+ * Getter, return catalog baseMedia temporary dir path
58
+ *
59
+ * @return string
60
+ */
61
+ public function getBaseTmpMediaPath()
62
+ {
63
+ return Mage::getBaseDir('media') . DS . 'tmp' . DS . 'catalog' . DS . 'category';
64
+ }
65
+
66
+ /**
67
+ * Getter, return catalog baseMedia temporary dir URL
68
+ *
69
+ * @return string
70
+ */
71
+ public function getBaseTmpMediaUrl()
72
+ {
73
+ return Mage::getBaseUrl('media') . 'tmp/catalog/category';
74
+ }
75
+ }
app/code/core/Mage/XmlConnect/Model/ConfigData.php ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Configuration data model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Xmlconnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Model_ConfigData extends Mage_Core_Model_Abstract
35
+ {
36
+ /**
37
+ * Default category
38
+ */
39
+ const DEFAULT_CATEGORY = 'default';
40
+
41
+ /**
42
+ * Configuration prefix
43
+ */
44
+ const CONFIG_PREFIX = 'app_';
45
+
46
+ /**
47
+ * Delete on update paths array
48
+ *
49
+ * @var array
50
+ */
51
+ protected $_deleteOnUpdate = array();
52
+
53
+ /**
54
+ * Configuration data
55
+ *
56
+ * @var array
57
+ */
58
+ protected $_configuration = array();
59
+
60
+ /**
61
+ * Initialize configuration data
62
+ *
63
+ * @return void
64
+ */
65
+ protected function _construct()
66
+ {
67
+ $this->_init('xmlconnect/configData');
68
+ }
69
+
70
+ /**
71
+ * Create an array that will be stored in configuration data
72
+ *
73
+ * Create an array: application id with a prefix as key and
74
+ * configuration data as value
75
+ *
76
+ * @param $applicationId
77
+ * @param $configData
78
+ * @return array
79
+ */
80
+ protected function _assignConfig($applicationId, $configData)
81
+ {
82
+ return array(self::CONFIG_PREFIX . $applicationId => $configData);
83
+ }
84
+
85
+ /**
86
+ * Prepare posted data to store at configuration.
87
+ *
88
+ * Posted data have to be in predefined format:
89
+ * - array('category:config/path/param' => 'value')
90
+ * where : is a separator of category
91
+ * - array('config/path/param' => 'value')
92
+ * if key doesn't have a separator category will be set as default
93
+ *
94
+ * @param $configuration posted data array
95
+ * @return array configuration data array
96
+ */
97
+ protected function _prepareData($configuration)
98
+ {
99
+ $configData = array();
100
+ foreach ($configuration as $key => $val) {
101
+ list($category, $path) = explode(':', $key, 2) + array('', '');
102
+ if (empty($path)) {
103
+ $path = $category;
104
+ $category = self::DEFAULT_CATEGORY;
105
+ }
106
+ $val = is_array($val) ? implode(',', $val) : $val;
107
+ $configData[strtolower($category)][strtolower($path)] = $val;
108
+ }
109
+ return $configData;
110
+ }
111
+
112
+ /**
113
+ * Prepare and set configuration data
114
+ *
115
+ * @param $applicationId
116
+ * @param array $configData
117
+ * @param bool $replace
118
+ * @return Mage_XmlConnect_Model_ConfigData
119
+ */
120
+ public function setConfigData($applicationId, array $configData, $replace = true)
121
+ {
122
+ $configData = $this->_prepareData($configData);
123
+ $arrayToStore = $this->_assignConfig($applicationId, $configData);
124
+ if ($replace) {
125
+ $this->_configuration = array_merge($this->_configuration, $arrayToStore);
126
+ } else {
127
+ $this->_configuration = $this->_configuration + $arrayToStore;
128
+ }
129
+ return $this;
130
+ }
131
+
132
+ /**
133
+ * Get configuration data
134
+ *
135
+ * @param bool $applicationId
136
+ * @return array
137
+ */
138
+ public function getConfigData($applicationId = false)
139
+ {
140
+ if ($applicationId && isset($this->_configuration[self::CONFIG_PREFIX . $applicationId])) {
141
+ return $this->_configuration[self::CONFIG_PREFIX . $applicationId];
142
+ }
143
+ return $this->_configuration;
144
+ }
145
+
146
+ /**
147
+ * Save predefined configuration data
148
+ *
149
+ * @return Mage_XmlConnect_Model_ConfigData
150
+ */
151
+ public function initSaveConfig()
152
+ {
153
+ foreach ($this->_configuration as $application => $data) {
154
+ $applicationId = str_ireplace(self::CONFIG_PREFIX, '', $application);
155
+ $this->_deleteOnUpdate($applicationId);
156
+ foreach ($data as $category => $config) {
157
+ $this->saveConfig(
158
+ $applicationId,
159
+ $config,
160
+ $category
161
+ );
162
+ }
163
+ }
164
+ return $this;
165
+ }
166
+
167
+ /**
168
+ * Save configuration data by given params
169
+ *
170
+ * @param $applicationId
171
+ * @param array $configData
172
+ * @param string $category
173
+ * @return Mage_XmlConnect_Model_ConfigData
174
+ */
175
+ public function saveConfig($applicationId, array $configData, $category = self::DEFAULT_CATEGORY)
176
+ {
177
+ foreach ($configData as $path => $value) {
178
+ if (!is_scalar($value)) {
179
+ Mage::throwException(
180
+ Mage::helper('xmlconnect')->__('Unsupported value type received')
181
+ );
182
+ }
183
+ $this->getResource()->saveConfig($applicationId, $category, $path, $value);
184
+ }
185
+ return $this;
186
+ }
187
+
188
+ /**
189
+ * Get delete on update array paths
190
+ *
191
+ * @return array
192
+ */
193
+ public function getDeleteOnUpdate()
194
+ {
195
+ return $this->_deleteOnUpdate;
196
+ }
197
+
198
+ /**
199
+ * Set delete on update array paths
200
+ *
201
+ * @param array $pathsToDelete
202
+ * @return Mage_XmlConnect_Model_ConfigData
203
+ */
204
+ public function setDeleteOnUpdate(array $pathsToDelete)
205
+ {
206
+ $this->_deleteOnUpdate = array_merge($this->_deleteOnUpdate, $pathsToDelete);
207
+ return $this;
208
+ }
209
+
210
+ /**
211
+ * @param $applicationId
212
+ * @return Mage_XmlConnect_Model_ConfigData
213
+ */
214
+ protected function _deleteOnUpdate($applicationId)
215
+ {
216
+ foreach ($this->_deleteOnUpdate as $category => $path) {
217
+ $this->getResource()->deleteConfig($applicationId, $category, $path);
218
+ }
219
+ return $this;
220
+ }
221
+ }
app/code/core/Mage/XmlConnect/Model/Corefix/Checkout/Session.php ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Override the original Checkout session model
29
+ * The represented methods are overridden to fix Core bug:
30
+ * Order review - no data verifying in "Billing address" and "Shiping address" fields
31
+ *
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Model_Corefix_Checkout_Session extends Mage_Checkout_Model_Session
35
+ {
36
+ /**
37
+ * Get checkout quote instance by current session
38
+ * Core fix
39
+ *
40
+ * @return Mage_XmlConnect_Model_Corefix_Sales_Quote
41
+ */
42
+ public function getQuote()
43
+ {
44
+ if ($this->_quote === null) {
45
+ $quote = Mage::getModel('xmlconnect/corefix_sales_quote')
46
+ ->setStoreId(Mage::app()->getStore()->getId());
47
+
48
+ /** @var $quote Mage_XmlConnect_Model_Corefix_Sales_Quote */
49
+ if ($this->getQuoteId()) {
50
+ $quote->loadActive($this->getQuoteId());
51
+ if ($quote->getId()) {
52
+ /**
53
+ * If current currency code of quote is not equal current currency code of store,
54
+ * need recalculate totals of quote. It is possible if customer use currency switcher or
55
+ * store switcher.
56
+ */
57
+ if ($quote->getQuoteCurrencyCode() != Mage::app()->getStore()->getCurrentCurrencyCode()) {
58
+ $quote->setStore(Mage::app()->getStore());
59
+ $quote->collectTotals()->save();
60
+ /**
61
+ * We mast to create new quote object, because collectTotals()
62
+ * can to create links with other objects.
63
+ */
64
+ $quote = Mage::getModel('xmlconnect/corefix_sales_quote')
65
+ ->setStoreId(Mage::app()->getStore()->getId());
66
+ $quote->load($this->getQuoteId());
67
+ }
68
+ } else {
69
+ $this->setQuoteId(null);
70
+ }
71
+ }
72
+
73
+ $customerSession = Mage::getSingleton('customer/session');
74
+
75
+ if (!$this->getQuoteId()) {
76
+ if ($customerSession->isLoggedIn()) {
77
+ $quote->loadByCustomer($customerSession->getCustomer());
78
+ $this->setQuoteId($quote->getId());
79
+ } else {
80
+ $quote->setIsCheckoutCart(true);
81
+ Mage::dispatchEvent('checkout_quote_init', array('quote' => $quote));
82
+ }
83
+ }
84
+
85
+ if ($this->getQuoteId()) {
86
+ if ($customerSession->isLoggedIn()) {
87
+ $quote->setCustomer($customerSession->getCustomer());
88
+ }
89
+ }
90
+
91
+ $quote->setStore(Mage::app()->getStore());
92
+ $this->_quote = $quote;
93
+ }
94
+
95
+ if ($remoteAddr = Mage::helper('core/http')->getRemoteAddr()) {
96
+ $this->_quote->setRemoteIp($remoteAddr);
97
+ $xForwardIp = Mage::app()->getRequest()->getServer('HTTP_X_FORWARDED_FOR');
98
+ $this->_quote->setXForwardedFor($xForwardIp);
99
+ }
100
+ return $this->_quote;
101
+ }
102
+
103
+ /**
104
+ * Load data for customer quote and merge with current quote
105
+ * Core fix
106
+ *
107
+ * @return Mage_XmlConnect_Model_Corefix_Checkout_Session
108
+ */
109
+ public function loadCustomerQuote()
110
+ {
111
+ if (!Mage::getSingleton('customer/session')->getCustomerId()) {
112
+ return $this;
113
+ }
114
+ $customerQuote = Mage::getModel('xmlconnect/corefix_sales_quote')
115
+ ->setStoreId(Mage::app()->getStore()->getId())
116
+ ->loadByCustomer(Mage::getSingleton('customer/session')->getCustomerId());
117
+
118
+ if ($customerQuote->getId() && $this->getQuoteId() != $customerQuote->getId()) {
119
+ if ($this->getQuoteId()) {
120
+ $customerQuote->merge($this->getQuote())
121
+ ->collectTotals()
122
+ ->save();
123
+ }
124
+
125
+ $this->setQuoteId($customerQuote->getId());
126
+
127
+ if ($this->_quote) {
128
+ $this->_quote->delete();
129
+ }
130
+ $this->_quote = $customerQuote;
131
+ } else {
132
+ $this->getQuote()->setCustomer(Mage::getSingleton('customer/session')->getCustomer())
133
+ ->save();
134
+ }
135
+ return $this;
136
+ }
137
+ }
app/code/core/Mage/XmlConnect/Model/Corefix/Checkout/Type/Onepage.php ADDED
@@ -0,0 +1,465 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Override the original One page checkout processing model
29
+ * The represented methods are overridden to fix Core bug:
30
+ * Order review - no data verifying in "Billing address" and "Shiping address" fields
31
+ *
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Model_Corefix_Checkout_Type_Onepage extends Mage_Checkout_Model_Type_Onepage
35
+ {
36
+ /**
37
+ * Class constructor
38
+ * Set customer already exists message
39
+ * Core fix
40
+ */
41
+ public function __construct()
42
+ {
43
+ $this->_helper = Mage::helper('checkout');
44
+ $this->_customerEmailExistsMessage = $this->_helper->__('There is already a customer registered using this email address. Please login using this email address or enter a different email address to register your account.');
45
+ $this->_checkoutSession = Mage::getSingleton('xmlconnect/corefix_checkout_session');
46
+ $this->_customerSession = Mage::getSingleton('customer/session');
47
+ }
48
+
49
+ /**
50
+ * Save billing address information to quote
51
+ * This method is called by One Page Checkout JS (AJAX) while saving the billing information.
52
+ * Core fix
53
+ *
54
+ * @param array $data
55
+ * @param int $customerAddressId
56
+ * @return array
57
+ */
58
+ public function saveBilling($data, $customerAddressId)
59
+ {
60
+ if (empty($data)) {
61
+ return array('error' => -1, 'message' => $this->_helper->__('Invalid data.'));
62
+ }
63
+
64
+ $address = $this->getQuote()->getBillingAddress();
65
+ /** @var $addressForm Mage_Customer_Model_Form */
66
+ $addressForm = Mage::getModel('customer/form');
67
+ $addressForm->setFormCode('customer_address_edit')
68
+ ->setEntityType('customer_address')
69
+ ->setIsAjaxRequest(Mage::app()->getRequest()->isAjax());
70
+
71
+ if (!empty($customerAddressId)) {
72
+ $customerAddress = Mage::getModel('customer/address')->load($customerAddressId);
73
+ if ($customerAddress->getId()) {
74
+ if ($customerAddress->getCustomerId() != $this->getQuote()->getCustomerId()) {
75
+ return array(
76
+ 'error' => 1,
77
+ 'message' => $this->_helper->__('Customer Address is not valid.')
78
+ );
79
+ }
80
+
81
+ $address->importCustomerAddress($customerAddress)->setSaveInAddressBook(0);
82
+ $addressForm->setEntity($address);
83
+ $addressErrors = $addressForm->validateData($address->getData());
84
+ if ($addressErrors !== true) {
85
+ return array('error' => 1, 'message' => $addressErrors);
86
+ }
87
+ }
88
+ } else {
89
+ $addressForm->setEntity($address);
90
+ // emulate request object
91
+ $addressData = $addressForm->extractData($addressForm->prepareRequest($data));
92
+ $addressErrors = $addressForm->validateData($addressData);
93
+ if ($addressErrors !== true) {
94
+ return array('error' => 1, 'message' => $addressErrors);
95
+ }
96
+ $addressForm->compactData($addressData);
97
+
98
+ // Additional form data, not fetched by extractData (as it fetches only attributes)
99
+ $address->setSaveInAddressBook(empty($data['save_in_address_book']) ? 0 : 1);
100
+ }
101
+
102
+ // validate billing address
103
+ if (($validateRes = $address->validate()) !== true) {
104
+ return array('error' => 1, 'message' => $validateRes);
105
+ }
106
+
107
+ $address->implodeStreetAddress();
108
+
109
+ if (true !== ($result = $this->_validateCustomerData($data))) {
110
+ return $result;
111
+ }
112
+
113
+ if (!$this->getQuote()->getCustomerId() && self::METHOD_REGISTER == $this->getQuote()->getCheckoutMethod()) {
114
+ if ($this->_customerEmailExists($address->getEmail(), Mage::app()->getWebsite()->getId())) {
115
+ return array('error' => 1, 'message' => $this->_customerEmailExistsMessage);
116
+ }
117
+ }
118
+
119
+ if (!$this->getQuote()->isVirtual()) {
120
+ /**
121
+ * Billing address using otions
122
+ */
123
+ $usingCase = isset($data['use_for_shipping']) ? (int)$data['use_for_shipping'] : 0;
124
+
125
+ switch($usingCase) {
126
+ case 0:
127
+ $shipping = $this->getQuote()->getShippingAddress();
128
+ $shipping->setSameAsBilling(0);
129
+ break;
130
+ case 1:
131
+ $billing = clone $address;
132
+ $billing->unsAddressId()->unsAddressType();
133
+ $shipping = $this->getQuote()->getShippingAddress();
134
+ $shippingMethod = $shipping->getShippingMethod();
135
+ $shipping->addData($billing->getData())
136
+ ->setSameAsBilling(1)
137
+ ->setSaveInAddressBook(0)
138
+ ->setShippingMethod($shippingMethod)
139
+ ->setCollectShippingRates(true);
140
+ $this->getCheckout()->setStepData('shipping', 'complete', true);
141
+ break;
142
+ }
143
+ }
144
+
145
+ $this->getQuote()->collectTotals();
146
+ $this->getQuote()->save();
147
+
148
+ $this->getCheckout()
149
+ ->setStepData('billing', 'allow', true)
150
+ ->setStepData('billing', 'complete', true)
151
+ ->setStepData('shipping', 'allow', true);
152
+
153
+ return array();
154
+ }
155
+
156
+ /**
157
+ * Validate customer data and set some its data for further usage in quote
158
+ * Will return either true or array with error messages
159
+ * Core fix
160
+ *
161
+ * @param array $data
162
+ * @return bool | array
163
+ */
164
+ protected function _validateCustomerData(array $data)
165
+ {
166
+ /** @var $customerForm Mage_Customer_Model_Form */
167
+ $customerForm = Mage::getModel('customer/form');
168
+ $customerForm->setFormCode('checkout_register')
169
+ ->setIsAjaxRequest(Mage::app()->getRequest()->isAjax());
170
+
171
+ $quote = $this->getQuote();
172
+ if ($quote->getCustomerId()) {
173
+ $customer = $quote->getCustomer();
174
+ $customerForm->setEntity($customer);
175
+ $customerData = $quote->getCustomer()->getData();
176
+ } else {
177
+ /** @var $customer Mage_Customer_Model_Customer */
178
+ $customer = Mage::getModel('customer/customer');
179
+ $customerForm->setEntity($customer);
180
+ $customerRequest = $customerForm->prepareRequest($data);
181
+ $customerData = $customerForm->extractData($customerRequest);
182
+ }
183
+
184
+ $customerErrors = $customerForm->validateData($customerData);
185
+ if ($customerErrors !== true) {
186
+ return array(
187
+ 'error' => -1,
188
+ 'message' => implode(', ', $customerErrors)
189
+ );
190
+ }
191
+
192
+ if ($quote->getCustomerId()) {
193
+ return true;
194
+ }
195
+
196
+ $customerForm->compactData($customerData);
197
+
198
+ if ($quote->getCheckoutMethod() == self::METHOD_REGISTER) {
199
+ // set customer password
200
+ $customer->setPassword($customerRequest->getParam('customer_password'));
201
+ $customer->setConfirmation($customerRequest->getParam('confirm_password'));
202
+ } else {
203
+ // emulate customer password for quest
204
+ $password = $customer->generatePassword();
205
+ $customer->setPassword($password);
206
+ $customer->setConfirmation($password);
207
+ }
208
+
209
+ $result = $customer->validate();
210
+ if (true !== $result && is_array($result)) {
211
+ return array(
212
+ 'error' => -1,
213
+ 'message' => implode(', ', $result)
214
+ );
215
+ }
216
+
217
+ if ($quote->getCheckoutMethod() == self::METHOD_REGISTER) {
218
+ // save customer encrypted password in quote
219
+ $quote->setPasswordHash($customer->encryptPassword($customer->getPassword()));
220
+ }
221
+
222
+ // copy customer/guest email to address
223
+ $quote->getBillingAddress()->setEmail($customer->getEmail());
224
+
225
+ // copy customer data to quote
226
+ Mage::helper('core')->copyFieldset('customer_account', 'to_quote', $customer, $quote);
227
+
228
+ return true;
229
+ }
230
+
231
+ /**
232
+ * Save checkout shipping address
233
+ * Core fix
234
+ *
235
+ * @param array $data
236
+ * @param int $customerAddressId
237
+ * @return array
238
+ */
239
+ public function saveShipping($data, $customerAddressId)
240
+ {
241
+ if (empty($data)) {
242
+ return array('error' => -1, 'message' => $this->_helper->__('Invalid data.'));
243
+ }
244
+ $address = $this->getQuote()->getShippingAddress();
245
+
246
+ /** @var $addressForm Mage_Customer_Model_Form */
247
+ $addressForm = Mage::getModel('customer/form');
248
+ $addressForm->setFormCode('customer_address_edit')
249
+ ->setEntityType('customer_address')
250
+ ->setIsAjaxRequest(Mage::app()->getRequest()->isAjax());
251
+
252
+ if (!empty($customerAddressId)) {
253
+ /** @var $customerAddress Mage_Customer_Model_Address */
254
+ $customerAddress = Mage::getModel('customer/address')->load($customerAddressId);
255
+ if ($customerAddress->getId()) {
256
+ if ($customerAddress->getCustomerId() != $this->getQuote()->getCustomerId()) {
257
+ return array(
258
+ 'error' => 1,
259
+ 'message' => $this->_helper->__('Customer Address is not valid.')
260
+ );
261
+ }
262
+
263
+ $address->importCustomerAddress($customerAddress)->setSaveInAddressBook(0);
264
+ $addressForm->setEntity($address);
265
+ $addressErrors = $addressForm->validateData($address->getData());
266
+ if ($addressErrors !== true) {
267
+ return array('error' => 1, 'message' => $addressErrors);
268
+ }
269
+ }
270
+ } else {
271
+ $addressForm->setEntity($address);
272
+ // emulate request object
273
+ $addressData = $addressForm->extractData($addressForm->prepareRequest($data));
274
+ $addressErrors = $addressForm->validateData($addressData);
275
+ if ($addressErrors !== true) {
276
+ return array('error' => 1, 'message' => $addressErrors);
277
+ }
278
+ $addressForm->compactData($addressData);
279
+
280
+ // Additional form data, not fetched by extractData (as it fetches only attributes)
281
+ $address->setSaveInAddressBook(empty($data['save_in_address_book']) ? 0 : 1);
282
+ $address->setSameAsBilling(empty($data['same_as_billing']) ? 0 : 1);
283
+ }
284
+
285
+ $address->implodeStreetAddress();
286
+ $address->setCollectShippingRates(true);
287
+
288
+ if (($validateRes = $address->validate()) !== true) {
289
+ return array('error' => 1, 'message' => $validateRes);
290
+ }
291
+
292
+ $this->getQuote()->collectTotals()->save();
293
+
294
+ $this->getCheckout()
295
+ ->setStepData('shipping', 'complete', true)
296
+ ->setStepData('shipping_method', 'allow', true);
297
+
298
+ return array();
299
+ }
300
+
301
+ /**
302
+ * Specify quote payment method
303
+ * Core fix
304
+ *
305
+ * @param array $data
306
+ * @return array
307
+ */
308
+ public function savePayment($data)
309
+ {
310
+ if (empty($data)) {
311
+ return array('error' => -1, 'message' => $this->_helper->__('Invalid data.'));
312
+ }
313
+ $quote = $this->getQuote();
314
+ if ($quote->isVirtual()) {
315
+ $quote->getBillingAddress()->setPaymentMethod(isset($data['method']) ? $data['method'] : null);
316
+ } else {
317
+ $quote->getShippingAddress()->setPaymentMethod(isset($data['method']) ? $data['method'] : null);
318
+ }
319
+
320
+ // shipping totals may be affected by payment method
321
+ if (!$quote->isVirtual() && $quote->getShippingAddress()) {
322
+ $quote->getShippingAddress()->setCollectShippingRates(true);
323
+ }
324
+
325
+ $payment = $quote->getPayment();
326
+ $payment->importData($data);
327
+
328
+ $quote->save();
329
+
330
+ $this->getCheckout()
331
+ ->setStepData('payment', 'complete', true)
332
+ ->setStepData('review', 'allow', true);
333
+
334
+ return array();
335
+ }
336
+
337
+ /**
338
+ * Prepare quote for customer order submit
339
+ * Core fix
340
+ *
341
+ * @return void
342
+ */
343
+ protected function _prepareCustomerQuote()
344
+ {
345
+ $quote = $this->getQuote();
346
+ $billing = $quote->getBillingAddress();
347
+ $shipping = $quote->isVirtual() ? null : $quote->getShippingAddress();
348
+
349
+ $customer = $this->getCustomerSession()->getCustomer();
350
+ if (!$billing->getCustomerId() || $billing->getSaveInAddressBook()) {
351
+ $customerBilling = $billing->exportCustomerAddress();
352
+ $customer->addAddress($customerBilling);
353
+ $billing->setCustomerAddress($customerBilling);
354
+ }
355
+ if ($shipping && !$shipping->getSameAsBilling()
356
+ && (!$shipping->getCustomerId() || $shipping->getSaveInAddressBook())
357
+ ) {
358
+ $customerShipping = $shipping->exportCustomerAddress();
359
+ $customer->addAddress($customerShipping);
360
+ $shipping->setCustomerAddress($customerShipping);
361
+ }
362
+
363
+ if (isset($customerBilling) && !$customer->getDefaultBilling()) {
364
+ $customerBilling->setIsDefaultBilling(true);
365
+ }
366
+ if ($shipping && isset($customerShipping) && !$customer->getDefaultShipping()) {
367
+ $customerShipping->setIsDefaultShipping(true);
368
+ } elseif (isset($customerBilling) && !$customer->getDefaultShipping()) {
369
+ $customerBilling->setIsDefaultShipping(true);
370
+ }
371
+ $quote->setCustomer($customer);
372
+ }
373
+
374
+ /**
375
+ * Create order based on checkout type. Create customer if necessary.
376
+ *
377
+ * @return Mage_XmlConnect_Model_Corefix_Checkout_Type_Onepage
378
+ */
379
+ public function saveOrder()
380
+ {
381
+ $this->validate();
382
+ $isNewCustomer = false;
383
+ switch ($this->getCheckoutMethod()) {
384
+ case self::METHOD_GUEST:
385
+ $this->_prepareGuestQuote();
386
+ break;
387
+ case self::METHOD_REGISTER:
388
+ $this->_prepareNewCustomerQuote();
389
+ $isNewCustomer = true;
390
+ break;
391
+ default:
392
+ $this->_prepareCustomerQuote();
393
+ break;
394
+ }
395
+
396
+ /** @var $service Mage_Sales_Model_Service_Quote */
397
+ $service = Mage::getModel('sales/service_quote', $this->getQuote());
398
+ $service->submitAll();
399
+
400
+ if ($isNewCustomer) {
401
+ try {
402
+ $this->_involveNewCustomer();
403
+ } catch (Exception $e) {
404
+ Mage::logException($e);
405
+ }
406
+ }
407
+
408
+ $this->_checkoutSession->setLastQuoteId($this->getQuote()->getId())
409
+ ->setLastSuccessQuoteId($this->getQuote()->getId())
410
+ ->clearHelperData();
411
+
412
+ $order = $service->getOrder();
413
+ if ($order) {
414
+ Mage::dispatchEvent(
415
+ 'checkout_type_onepage_save_order_after',
416
+ array('order' => $order, 'quote' => $this->getQuote())
417
+ );
418
+
419
+ /**
420
+ * a flag to set that there will be redirect to third party after confirmation
421
+ * eg: paypal standard ipn
422
+ */
423
+ $redirectUrl = $this->getQuote()->getPayment()->getOrderPlaceRedirectUrl();
424
+ /**
425
+ * we only want to send to customer about new order when there is no redirect to third party
426
+ */
427
+ if (!$redirectUrl) {
428
+ try {
429
+ $order->sendNewOrderEmail();
430
+ } catch (Exception $e) {
431
+ Mage::logException($e);
432
+ }
433
+ }
434
+
435
+ // add order information to the session
436
+ $this->_checkoutSession->setLastOrderId($order->getId())
437
+ ->setRedirectUrl($redirectUrl)
438
+ ->setLastRealOrderId($order->getIncrementId());
439
+
440
+ // as well a billing agreement can be created
441
+ $agreement = $order->getPayment()->getBillingAgreement();
442
+ if ($agreement) {
443
+ $this->_checkoutSession->setLastBillingAgreementId($agreement->getId());
444
+ }
445
+ }
446
+
447
+ // add recurring profiles information to the session
448
+ $profiles = $service->getRecurringPaymentProfiles();
449
+ if ($profiles) {
450
+ $ids = array();
451
+ foreach ($profiles as $profile) {
452
+ $ids[] = $profile->getId();
453
+ }
454
+ $this->_checkoutSession->setLastRecurringProfileIds($ids);
455
+ // TODO: send recurring profile emails
456
+ }
457
+
458
+ Mage::dispatchEvent(
459
+ 'checkout_submit_all_after',
460
+ array('order' => $order, 'quote' => $this->getQuote(), 'recurring_profiles' => $profiles)
461
+ );
462
+
463
+ return $this;
464
+ }
465
+ }
app/code/core/Mage/XmlConnect/Model/Corefix/Sales/Quote.php ADDED
@@ -0,0 +1,427 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Override the original Quote model
29
+ * The represented methods are overridden to fix Core bug:
30
+ * Order review - no data verifying in "Billing address" and "Shiping address" fields
31
+ *
32
+ * Supported events:
33
+ * sales_quote_load_after
34
+ * sales_quote_save_before
35
+ * sales_quote_save_after
36
+ * sales_quote_delete_before
37
+ * sales_quote_delete_after
38
+ *
39
+ * @author Magento Core Team <core@magentocommerce.com>
40
+ */
41
+ class Mage_XmlConnect_Model_Corefix_Sales_Quote extends Mage_Sales_Model_Quote
42
+ {
43
+ /**
44
+ * Loading quote by identifier
45
+ * Core fix
46
+ *
47
+ * @param int $quoteId
48
+ * @return Mage_XmlConnect_Model_Corefix_Sales_Quote
49
+ */
50
+ public function loadByIdWithoutStore($quoteId)
51
+ {
52
+ $this->_getResource()->loadByIdWithoutStore($this, $quoteId);
53
+ $this->_afterLoad();
54
+ return $this;
55
+ }
56
+
57
+ /**
58
+ * Assign customer model object data to quote
59
+ * Core fix
60
+ *
61
+ * @param Mage_Customer_Model_Customer $customer
62
+ * @return Mage_XmlConnect_Model_Corefix_Sales_Quote
63
+ */
64
+ public function assignCustomer(Mage_Customer_Model_Customer $customer)
65
+ {
66
+ return $this->assignCustomerWithAddressChange($customer);
67
+ }
68
+
69
+ /**
70
+ * Assign customer model to quote with billing and shipping address change
71
+ * Core fix
72
+ *
73
+ * @param Mage_Customer_Model_Customer $customer
74
+ * @param Mage_Sales_Model_Quote_Address $billingAddress
75
+ * @param Mage_Sales_Model_Quote_Address $shippingAddress
76
+ * @return Mage_XmlConnect_Model_Corefix_Sales_Quote
77
+ */
78
+ public function assignCustomerWithAddressChange(
79
+ Mage_Customer_Model_Customer $customer,
80
+ Mage_Sales_Model_Quote_Address $billingAddress = null,
81
+ Mage_Sales_Model_Quote_Address $shippingAddress = null
82
+ )
83
+ {
84
+ if ($customer->getId()) {
85
+ $this->setCustomer($customer);
86
+
87
+ if (!is_null($billingAddress)) {
88
+ $this->setBillingAddress($billingAddress);
89
+ } else {
90
+ $defaultBillingAddress = $customer->getDefaultBillingAddress();
91
+ if ($defaultBillingAddress && $defaultBillingAddress->getId()) {
92
+ $billingAddress = Mage::getModel('sales/quote_address')
93
+ ->importCustomerAddress($defaultBillingAddress);
94
+ $this->setBillingAddress($billingAddress);
95
+ }
96
+ }
97
+
98
+ if (is_null($shippingAddress)) {
99
+ $defaultShippingAddress = $customer->getDefaultShippingAddress();
100
+ if ($defaultShippingAddress && $defaultShippingAddress->getId()) {
101
+ $shippingAddress = Mage::getModel('sales/quote_address')
102
+ ->importCustomerAddress($defaultShippingAddress);
103
+ } else {
104
+ $shippingAddress = Mage::getModel('sales/quote_address');
105
+ }
106
+ }
107
+ $this->setShippingAddress($shippingAddress);
108
+ }
109
+
110
+ return $this;
111
+ }
112
+
113
+ /**
114
+ * Retrieve customer group id
115
+ * Core fix
116
+ *
117
+ * @return int
118
+ */
119
+ public function getCustomerGroupId()
120
+ {
121
+ if ($this->getCustomerId()) {
122
+ return ($this->getData('customer_group_id'))
123
+ ? $this->getData('customer_group_id')
124
+ : $this->getCustomer()->getGroupId();
125
+ } else {
126
+ return Mage_Customer_Model_Group::NOT_LOGGED_IN_ID;
127
+ }
128
+ }
129
+
130
+ /**
131
+ * Checking product exist in Quote
132
+ * Core fix
133
+ *
134
+ * @param int $productId
135
+ * @return bool
136
+ */
137
+ public function hasProductId($productId)
138
+ {
139
+ foreach ($this->getAllItems() as $item) {
140
+ if ($item->getProductId() == $productId) {
141
+ return true;
142
+ }
143
+ }
144
+ return false;
145
+ }
146
+
147
+ /**
148
+ * Remove quote item by item identifier
149
+ * Core fix
150
+ *
151
+ * @param int $itemId
152
+ * @return Mage_XmlConnect_Model_Corefix_Sales_Quote
153
+ */
154
+ public function removeItem($itemId)
155
+ {
156
+ $item = $this->getItemById($itemId);
157
+ if ($item) {
158
+ $item->setQuote($this);
159
+ /**
160
+ * If we remove item from quote - we can't use multishipping mode
161
+ */
162
+ $this->setIsMultiShipping(false);
163
+ $item->isDeleted(true);
164
+ if ($item->getHasChildren()) {
165
+ foreach ($item->getChildren() as $child) {
166
+ $child->isDeleted(true);
167
+ }
168
+ }
169
+ Mage::dispatchEvent('sales_quote_remove_item', array('quote_item' => $item));
170
+ }
171
+ return $this;
172
+ }
173
+
174
+ /**
175
+ * Advanced func to add product to quote - processing mode can be specified there.
176
+ * Returns error message if product type instance can't prepare product.
177
+ * Core fix
178
+ *
179
+ * @param Mage_Catalog_Model_Product $product
180
+ * @param null | float | Varien_Object $request
181
+ * @param null | string $processMode
182
+ * @throws Mage_Core_Exception
183
+ * @return Mage_Sales_Model_Quote_Item | string
184
+ */
185
+ public function addProductAdvanced(Mage_Catalog_Model_Product $product, $request = null, $processMode = null)
186
+ {
187
+ if ($request === null) {
188
+ $request = 1;
189
+ }
190
+ if (is_numeric($request)) {
191
+ $request = new Varien_Object(array('qty' => $request));
192
+ }
193
+ if (!($request instanceof Varien_Object)) {
194
+ Mage::throwException(Mage::helper('sales')->__('Invalid request for adding product to quote.'));
195
+ }
196
+
197
+ $cartCandidates = $product->getTypeInstance(true)
198
+ ->prepareForCartAdvanced($request, $product, $processMode);
199
+
200
+ /**
201
+ * Error message
202
+ */
203
+ if (is_string($cartCandidates)) {
204
+ return $cartCandidates;
205
+ }
206
+
207
+ /**
208
+ * If prepare process return one object
209
+ */
210
+ if (!is_array($cartCandidates)) {
211
+ $cartCandidates = array($cartCandidates);
212
+ }
213
+
214
+ $parentItem = null;
215
+ $errors = array();
216
+ $items = array();
217
+ foreach ($cartCandidates as $candidate) {
218
+ $item = $this->_addCatalogProduct($candidate, $candidate->getCartQty());
219
+ $items[] = $item;
220
+
221
+ /**
222
+ * As parent item we should always use the item of first added product
223
+ */
224
+ if (!$parentItem) {
225
+ $parentItem = $item;
226
+ }
227
+ if ($parentItem && $candidate->getParentProductId() && !$item->getId()) {
228
+ $item->setParentItem($parentItem);
229
+ }
230
+
231
+ /**
232
+ * We specify qty after we know about parent (for stock)
233
+ */
234
+ $item->addQty($candidate->getCartQty());
235
+
236
+ // collect errors instead of throwing first one
237
+ if ($item->getHasError()) {
238
+ $errors[] = $item->getMessage();
239
+ }
240
+ }
241
+ if (!empty($errors)) {
242
+ Mage::throwException(implode("\n", $errors));
243
+ }
244
+
245
+ Mage::dispatchEvent('sales_quote_product_add_after', array('items' => $items));
246
+
247
+ return $item;
248
+ }
249
+
250
+
251
+ /**
252
+ * Add product to quote
253
+ * return error message if product type instance can't prepare product
254
+ * Core fix
255
+ *
256
+ * @param mixed $product
257
+ * @param null | float | Varien_Object $request
258
+ * @return Mage_Sales_Model_Quote_Item | string
259
+ */
260
+ public function addProduct(Mage_Catalog_Model_Product $product, $request = null)
261
+ {
262
+ return $this->addProductAdvanced($product, $request, Mage_Catalog_Model_Product_Type_Abstract::PROCESS_MODE_FULL);
263
+ }
264
+
265
+ /**
266
+ * Adding catalog product object data to quote
267
+ * Core fix
268
+ *
269
+ * @param Mage_Catalog_Model_Product $product
270
+ * @return Mage_Sales_Model_Quote_Item
271
+ */
272
+ protected function _addCatalogProduct(Mage_Catalog_Model_Product $product, $qty = 1)
273
+ {
274
+ $newItem = false;
275
+ $item = $this->getItemByProduct($product);
276
+ if (!$item) {
277
+ $item = Mage::getModel('sales/quote_item');
278
+ $item->setQuote($this);
279
+ if (Mage::app()->getStore()->isAdmin()) {
280
+ $item->setStoreId($this->getStore()->getId());
281
+ } else {
282
+ $item->setStoreId(Mage::app()->getStore()->getId());
283
+ }
284
+ $newItem = true;
285
+ }
286
+
287
+ /**
288
+ * We can't modify existing child items
289
+ */
290
+ if ($item->getId() && $product->getParentProductId()) {
291
+ return $item;
292
+ }
293
+
294
+ $item->setOptions($product->getCustomOptions())
295
+ ->setProduct($product);
296
+
297
+ // Add only item that is not in quote already (there can be other new or already saved item
298
+ if ($newItem) {
299
+ $this->addItem($item);
300
+ }
301
+
302
+ return $item;
303
+ }
304
+
305
+ /**
306
+ * Updates quote item with new configuration
307
+ *
308
+ * $params sets how current item configuration must be taken into account and additional options.
309
+ * It's passed to Mage_Catalog_Helper_Product->addParamsToBuyRequest() to compose resulting buyRequest.
310
+ *
311
+ * Basically it can hold
312
+ * - 'current_config', Varien_Object or array - current buyRequest that configures product in this item,
313
+ * used to restore currently attached files
314
+ * - 'files_prefix': string[a-z0-9_] - prefix that was added at frontend to names of file options (file inputs), so they won't
315
+ * intersect with other submitted options
316
+ *
317
+ * For more options see Mage_Catalog_Helper_Product->addParamsToBuyRequest()
318
+ *
319
+ * Core fix
320
+ *
321
+ * @param int $itemId
322
+ * @param Varien_Object $buyRequest
323
+ * @param null | array | Varien_Object $params
324
+ * @throws Mage_Core_Exception
325
+ * @return Mage_Sales_Model_Quote_Item
326
+ *
327
+ * @see Mage_Catalog_Helper_Product::addParamsToBuyRequest()
328
+ */
329
+ public function updateItem($itemId, $buyRequest, $params = null)
330
+ {
331
+ $item = $this->getItemById($itemId);
332
+ if (!$item) {
333
+ Mage::throwException(Mage::helper('sales')->__('Wrong quote item id to update configuration.'));
334
+ }
335
+ $productId = $item->getProduct()->getId();
336
+
337
+ //We need to create new clear product instance with same $productId
338
+ //to set new option values from $buyRequest
339
+ $product = Mage::getModel('catalog/product')
340
+ ->setStoreId($this->getStore()->getId())
341
+ ->load($productId);
342
+
343
+ if (!$params) {
344
+ $params = new Varien_Object();
345
+ } elseif (is_array($params)) {
346
+ $params = new Varien_Object($params);
347
+ }
348
+ $params->setCurrentConfig($item->getBuyRequest());
349
+ $buyRequest = Mage::helper('catalog/product')->addParamsToBuyRequest($buyRequest, $params);
350
+
351
+ $resultItem = $this->addProduct($product, $buyRequest);
352
+
353
+ if (is_string($resultItem)) {
354
+ Mage::throwException($resultItem);
355
+ }
356
+
357
+ if ($resultItem->getParentItem()) {
358
+ $resultItem = $resultItem->getParentItem();
359
+ }
360
+
361
+ if ($resultItem->getId() != $itemId) {
362
+ /**
363
+ * Product configuration didn't stick to original quote item
364
+ * It either has same configuration as some other quote item's product or completely new configuration
365
+ */
366
+ $this->removeItem($itemId);
367
+
368
+ $items = $this->getAllItems();
369
+ foreach ($items as $item) {
370
+ if (($item->getProductId() == $productId) && ($item->getId() != $resultItem->getId())) {
371
+ if ($resultItem->compare($item)) {
372
+ // Product configuration is same as in other quote item
373
+ $resultItem->setQty($resultItem->getQty() + $item->getQty());
374
+ $this->removeItem($item->getId());
375
+ break;
376
+ }
377
+ }
378
+ }
379
+ } else {
380
+ $resultItem->setQty($buyRequest->getQty());
381
+ }
382
+
383
+ return $resultItem;
384
+ }
385
+
386
+ /**
387
+ * Retrieve quote item by product id
388
+ * Core fix
389
+ *
390
+ * @param Mage_Catalog_Model_Product $product
391
+ * @return Mage_Sales_Model_Quote_Item | false
392
+ */
393
+ public function getItemByProduct($product)
394
+ {
395
+ foreach ($this->getAllItems() as $item) {
396
+ if ($item->representProduct($product)) {
397
+ return $item;
398
+ }
399
+ }
400
+ return false;
401
+ }
402
+
403
+ /**
404
+ * Check quote for virtual product only
405
+ * Core fix
406
+ *
407
+ * @return bool
408
+ */
409
+ public function isVirtual()
410
+ {
411
+ $isVirtual = true;
412
+ $countItems = 0;
413
+ foreach ($this->getItemsCollection() as $_item) {
414
+ /** @var $_item Mage_Sales_Model_Quote_Item */
415
+ if ($_item->isDeleted() || $_item->getParentItemId()) {
416
+ continue;
417
+ }
418
+ $countItems ++;
419
+ if (!$_item->getProduct()->getIsVirtual()) {
420
+ $isVirtual = false;
421
+ break;
422
+ }
423
+ }
424
+ return $countItems == 0 ? false : $isVirtual;
425
+ }
426
+
427
+ }
app/code/core/Mage/XmlConnect/Model/History.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Xmlconnect history model
29
+ *
30
+ * @method Mage_XmlConnect_Model_Mysql4_History _getResource()
31
+ * @method Mage_XmlConnect_Model_Mysql4_History getResource()
32
+ * @method int getApplicationId()
33
+ * @method Mage_XmlConnect_Model_History setApplicationId(int $value)
34
+ * @method string getCreatedAt()
35
+ * @method Mage_XmlConnect_Model_History setCreatedAt(string $value)
36
+ * @method int getStoreId()
37
+ * @method Mage_XmlConnect_Model_History setStoreId(int $value)
38
+ * @method string getParams()
39
+ * @method Mage_XmlConnect_Model_History setParams(string $value)
40
+ * @method string getTitle()
41
+ * @method Mage_XmlConnect_Model_History setTitle(string $value)
42
+ * @method string getActivationKey()
43
+ * @method Mage_XmlConnect_Model_History setActivationKey(string $value)
44
+ * @method string getCode()
45
+ * @method Mage_XmlConnect_Model_History setCode(string $value)
46
+ *
47
+ * @category Mage
48
+ * @package Mage_Xmlconnect
49
+ * @author Magento Core Team <core@magentocommerce.com>
50
+ */
51
+ class Mage_XmlConnect_Model_History extends Mage_Core_Model_Abstract
52
+ {
53
+ /**
54
+ * Initialize application
55
+ *
56
+ * @return void
57
+ */
58
+ protected function _construct()
59
+ {
60
+ $this->_init('xmlconnect/history');
61
+ }
62
+
63
+ /**
64
+ * Get array of existing images
65
+ *
66
+ * @param int $id Application instance Id
67
+ * @return array
68
+ */
69
+ public function getLastParams($id)
70
+ {
71
+ return $this->_getResource()->getLastParams($id);
72
+ }
73
+ }
app/code/core/Mage/XmlConnect/Model/Input/Filter/MaliciousCode.php ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Filter for removing malicious code from HTML
29
+ *
30
+ * Current class is a copy of Mage_Core_Model_Input_Filter_MaliciousCode
31
+ * and added for back compatibility with older versions of Magento
32
+ * due to the fact that we use these code for packages in Magento Connect
33
+ *
34
+ * @category Mage
35
+ * @package Mage_XmlConnect
36
+ * @author Magento Core Team <core@magentocommerce.com>
37
+ */
38
+ class Mage_XmlConnect_Model_Input_Filter_MaliciousCode implements Zend_Filter_Interface
39
+ {
40
+ /**
41
+ * Regular expressions for cutting malicious code
42
+ *
43
+ * @var array
44
+ */
45
+ protected $_expressions = array(
46
+ //comments, must be first
47
+ '/(\/\*.*\*\/)/Us',
48
+ //tabs
49
+ '/(\t)/',
50
+ //javasript prefix
51
+ '/(javascript\s*:)/Usi',
52
+ //import styles
53
+ '/(@import)/Usi',
54
+ //js in the style attribute
55
+ '/style=[^<]*((expression\s*?\([^<]*?\))|(behavior\s*:))[^<]*(?=\>)/Uis',
56
+ //js attributes
57
+ '/(ondblclick|onclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|onload|onunload|onerror)=[^<]*(?=\>)/Uis',
58
+ //tags
59
+ '/<\/?(script|meta|link|frame|iframe).*>/Uis',
60
+ //base64 usage
61
+ '/src=[^<]*base64[^<]*(?=\>)/Uis',
62
+ );
63
+
64
+ /**
65
+ * Filter value
66
+ *
67
+ * @param string|array $value
68
+ * @return string|array Filtered value
69
+ */
70
+ public function filter($value)
71
+ {
72
+ return preg_replace($this->_expressions, '', $value);
73
+ }
74
+
75
+ /**
76
+ * Add expression
77
+ *
78
+ * @param string $expression
79
+ * @return Mage_Core_Model_Input_Filter_MaliciousCode
80
+ */
81
+ public function addExpression($expression)
82
+ {
83
+ if (!in_array($expression, $this->_expressions)) {
84
+ $this->_expressions[] = $expression;
85
+ }
86
+ return $this;
87
+ }
88
+
89
+ /**
90
+ * Set expressions
91
+ *
92
+ * @param array $expressions
93
+ * @return Mage_Core_Model_Input_Filter_MaliciousCode
94
+ */
95
+ public function setExpressions(array $expressions)
96
+ {
97
+ $this->_expressions = $expressions;
98
+ return $this;
99
+ }
100
+ }
app/code/core/Mage/XmlConnect/Model/Mysql4/Application.php ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Application recourse model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Model_Mysql4_Application extends Mage_Core_Model_Mysql4_Abstract
35
+ {
36
+ /**
37
+ * Constructor, setting table and index field
38
+ *
39
+ * @return void
40
+ */
41
+ protected function _construct()
42
+ {
43
+ $this->_init('xmlconnect/application', 'application_id');
44
+ }
45
+
46
+ /**
47
+ * Update Application Status field, insert data to history table
48
+ *
49
+ * @param int $applicationId
50
+ * @param string $status
51
+ * @return Mage_XmlConnect_Model_Mysql4_Application
52
+ */
53
+ public function updateApplicationStatus($applicationId, $status)
54
+ {
55
+ $this->_getWriteAdapter()->update(
56
+ $this->getMainTable(),
57
+ array('status' => $status),
58
+ $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . '=?', $applicationId)
59
+ );
60
+ return $this;
61
+ }
62
+
63
+ /**
64
+ * Processing object before save data
65
+ * Update app_code as Store + Device
66
+ *
67
+ * @param Mage_Core_Model_Abstract $object
68
+ * @return Mage_Core_Model_Abstract
69
+ */
70
+ protected function _beforeSave(Mage_Core_Model_Abstract $object)
71
+ {
72
+ if (!$object->getId()) {
73
+ $object->setCode($object->getCodePrefix());
74
+ }
75
+ return parent::_beforeSave($object);
76
+ }
77
+
78
+ /**
79
+ * Processing object after save data
80
+ * Update app_code as Store + Device + 123 (increment).
81
+ *
82
+ * @param Mage_Core_Model_Abstract $object
83
+ * @return Mage_Core_Model_Abstract
84
+ */
85
+ protected function _afterSave(Mage_Core_Model_Abstract $object)
86
+ {
87
+ $appCode = $object->getCode();
88
+ $isCodePrefixed = $object->isCodePrefixed();
89
+ if (!$isCodePrefixed) {
90
+ $this->_getWriteAdapter()->update(
91
+ $this->getMainTable(),
92
+ array('code' => $appCode . $object->getId()),
93
+ $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . '=?', $object->getId())
94
+ );
95
+ }
96
+ return parent::_afterSave($object);
97
+ }
98
+
99
+ /**
100
+ * Collect existing stores and type unique pairs
101
+ *
102
+ * @return array
103
+ */
104
+ public function getExistingStoreDeviceType()
105
+ {
106
+ $select = $this->_getWriteAdapter()->select()
107
+ ->from($this->getMainTable(), array('store_id', 'type'))
108
+ ->group(array('store_id', 'type'))
109
+ ->order(array('store_id', 'type'));
110
+ return $this->_getReadAdapter()->fetchAll($select, array('store_id', 'type'));
111
+ }
112
+
113
+ /**
114
+ * Update all applications "updated at" parameter with current date
115
+ *
116
+ * @return Mage_XmlConnect_Model_Mysql4_Application
117
+ */
118
+ public function updateAllAppsUpdatedAtParameter()
119
+ {
120
+ $this->_getWriteAdapter()->update(
121
+ $this->getMainTable(),
122
+ array(
123
+ 'updated_at' => date('Y-m-d H:i:s')
124
+ )
125
+ );
126
+ return $this;
127
+ }
128
+ }
app/code/core/Mage/XmlConnect/Model/Mysql4/Application/Collection.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+ class Mage_XmlConnect_Model_Mysql4_Application_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
27
+ {
28
+ /**
29
+ * Constructor, setting table
30
+ *
31
+ * @return void
32
+ */
33
+ protected function _construct()
34
+ {
35
+ $this->_init('xmlconnect/application');
36
+ }
37
+ }
app/code/core/Mage/XmlConnect/Model/Mysql4/Cms/Page/Collection.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Extended CMS page collection
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+
35
+ class Mage_XmlConnect_Model_Mysql4_Cms_Page_Collection extends Mage_Cms_Model_Mysql4_Page_Collection
36
+ {
37
+ /**
38
+ * Returns pairs identifier - title for unique identifiers
39
+ * and pairs identifier|page_id - title for non-unique after first
40
+ *
41
+ * @return array
42
+ */
43
+ public function toOptionIdArray()
44
+ {
45
+ $res = array();
46
+ $existingIdentifiers = array();
47
+ foreach ($this as $item) {
48
+ $identifier = $item->getData('identifier');
49
+
50
+ $data['value'] = $identifier;
51
+ $data['label'] = $item->getData('title');
52
+ if (in_array($identifier, $existingIdentifiers)) {
53
+ $data['value'] .= '|' . $item->getData('page_id');
54
+ } else {
55
+ $existingIdentifiers[] = $identifier;
56
+ }
57
+
58
+ $res[] = $data;
59
+ }
60
+
61
+ return $res;
62
+ }
63
+ }
app/code/core/Mage/XmlConnect/Model/Mysql4/ConfigData.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Configuration data recourse model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Xmlconnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Model_Mysql4_ConfigData extends Mage_Core_Model_Mysql4_Abstract
35
+ {
36
+ /**
37
+ * Initialize configuration data
38
+ *
39
+ * @return void
40
+ */
41
+ protected function _construct()
42
+ {
43
+ $this->_init('xmlconnect/configData', null);
44
+ }
45
+
46
+ /**
47
+ * Save config value
48
+ *
49
+ * @param int $applicationId
50
+ * @param string $category
51
+ * @param string $path
52
+ * @param string $value
53
+ * @return Mage_XmlConnect_Model_Mysql4_ConfigData
54
+ */
55
+ public function saveConfig($applicationId, $category, $path, $value)
56
+ {
57
+ $newData = array(
58
+ 'application_id' => $applicationId,
59
+ 'category' => $category,
60
+ 'path' => $path,
61
+ 'value' => $value
62
+ );
63
+
64
+ $this->_getWriteAdapter()->insertOnDuplicate(
65
+ $this->getMainTable(),
66
+ $newData,
67
+ array('value')
68
+ );
69
+ return $this;
70
+ }
71
+
72
+ /**
73
+ * Delete config value
74
+ *
75
+ * @param int $applicationId
76
+ * @param bool $category
77
+ * @param bool $path
78
+ * @param bool $pathLike
79
+ * @return Mage_XmlConnect_Model_Mysql4_ConfigData
80
+ */
81
+ public function deleteConfig($applicationId, $category = false, $path = false, $pathLike = true)
82
+ {
83
+ try {
84
+ $this->_getWriteAdapter()->beginTransaction();
85
+ $writeAdapter = $this->_getWriteAdapter();
86
+ $deleteWhere[] = $writeAdapter->quoteInto('application_id=?', $applicationId);
87
+ if ($category) {
88
+ $deleteWhere[] = $writeAdapter->quoteInto('category=?', $category);
89
+ }
90
+ if ($path) {
91
+ $deleteWhere[] = $pathLike
92
+ ? $writeAdapter->quoteInto('path like ?', $path . '/%')
93
+ : $writeAdapter->quoteInto('path=?', $path);
94
+ }
95
+ $writeAdapter->delete($this->getMainTable(), $deleteWhere);
96
+ $this->_getWriteAdapter()->commit();
97
+ } catch (Mage_Core_Exception $e) {
98
+ $this->_getWriteAdapter()->rollBack();
99
+ throw $e;
100
+ } catch (Exception $e){
101
+ $this->_getWriteAdapter()->rollBack();
102
+ Mage::logException($e);
103
+ }
104
+
105
+ return $this;
106
+ }
107
+ }
app/code/core/Mage/XmlConnect/Model/Mysql4/ConfigData/Collection.php ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Configuration data collection
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Xmlconnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Model_Mysql4_ConfigData_Collection
35
+ extends Mage_Core_Model_Mysql4_Collection_Abstract
36
+ {
37
+ /**
38
+ * Is application filter applied
39
+ *
40
+ * @var bool
41
+ */
42
+ protected $_applicationFilter = false;
43
+
44
+ /**
45
+ * Internal constructor
46
+ */
47
+ protected function _construct()
48
+ {
49
+ $this->_init('xmlconnect/configData');
50
+ }
51
+
52
+ /**
53
+ * Add application filter
54
+ *
55
+ * @param $applicationId
56
+ * @return Mage_XmlConnect_Model_Mysql4_ConfigData_Collection
57
+ */
58
+ public function addApplicationIdFilter($applicationId)
59
+ {
60
+ $this->_applicationFilter = true;
61
+ $this->getSelect()
62
+ ->where('application_id=?', $applicationId);
63
+ return $this;
64
+ }
65
+
66
+ /**
67
+ * Add path filter
68
+ *
69
+ * @param $path
70
+ * @param bool $like
71
+ * @return Mage_XmlConnect_Model_Mysql4_ConfigData_Collection
72
+ */
73
+ public function addPathFilter($path, $like = true)
74
+ {
75
+ if ($like) {
76
+ $this->getSelect()
77
+ ->where('path like ?', $path . '/%');
78
+ } else {
79
+ $this->getSelect()
80
+ ->where('path=?', $path);
81
+ }
82
+ return $this;
83
+ }
84
+
85
+ /**
86
+ * Add category filter
87
+ *
88
+ * @param $category
89
+ * @return Mage_XmlConnect_Model_Mysql4_ConfigData_Collection
90
+ */
91
+ public function addCategoryFilter($category)
92
+ {
93
+ $this->getSelect()->where('category=?', $category);
94
+ return $this;
95
+ }
96
+
97
+ /**
98
+ * Add value filter
99
+ *
100
+ * @param $value
101
+ * @return Mage_XmlConnect_Model_Mysql4_ConfigData_Collection
102
+ */
103
+ public function addValueFilter($value)
104
+ {
105
+ $this->getSelect()->where('value=?', $value);
106
+ return $this;
107
+ }
108
+
109
+ /**
110
+ * Add filter by array
111
+ *
112
+ * @param array $array
113
+ * @return Mage_XmlConnect_Model_Mysql4_ConfigData_Collection
114
+ */
115
+ public function addArrayFilter(array $array)
116
+ {
117
+ foreach ($array as $key => $val) {
118
+ $method = 'add' . uc_words($key, '') . 'Filter';
119
+ if (is_callable($this->$method($val))) {
120
+ return $this->$method($val);
121
+ }
122
+ }
123
+ return $this;
124
+ }
125
+
126
+ /**
127
+ * Convert items array to array for select options
128
+ *
129
+ * return items array
130
+ * array(
131
+ * application_id => array(
132
+ * category => array(
133
+ * path
134
+ * )
135
+ * )
136
+ * )
137
+ *
138
+ * @return array
139
+ */
140
+ public function toOptionArray()
141
+ {
142
+ $result = array();
143
+ foreach ($this as $item) {
144
+ $appId = $item->getData('application_id');
145
+ $category = $item->getData('category');
146
+ $path = $item->getData('path');
147
+ $value = $item->getData('value');
148
+
149
+ if ($this->_applicationFilter) {
150
+ $result[$category][$path] = $value;
151
+ } else {
152
+ $result[$appId][$category][$path] = $value;
153
+ }
154
+ }
155
+ return $result;
156
+ }
157
+
158
+ /**
159
+ * Get Application filter status
160
+ *
161
+ * @return boolean
162
+ */
163
+ public function getApplicationFilter()
164
+ {
165
+ return $this->_applicationFilter;
166
+ }
167
+
168
+ /**
169
+ * Set Application filter status
170
+ *
171
+ * @param boolean $applicationFilter
172
+ */
173
+ public function setApplicationFilter($applicationFilter)
174
+ {
175
+ $this->_applicationFilter = $applicationFilter;
176
+ }
177
+ }
app/code/core/Mage/XmlConnect/Model/Mysql4/Filter/Collection.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Filter collection
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Xmlconnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Model_Mysql4_Filter_Collection extends Varien_Data_Collection
35
+ {
36
+ /**
37
+ * Set CategoryId filter
38
+ *
39
+ * @param int $categoryId
40
+ * @return Mage_XmlConnect_Model_Mysql4_Filter_Collection
41
+ */
42
+ public function setCategoryId($categoryId)
43
+ {
44
+ if ((int)$categoryId > 0) {
45
+ $this->addFilter('category_id', $categoryId);
46
+ }
47
+ return $this;
48
+ }
49
+
50
+ /**
51
+ * Load data
52
+ *
53
+ * @param bool $printQuery
54
+ * @param bool $logQuery
55
+ * @return Mage_XmlConnect_Model_Mysql4_Filter_Collection
56
+ */
57
+ public function load($printQuery = false, $logQuery = false)
58
+ {
59
+ if (empty($this->_items)) {
60
+ $layer = Mage::getSingleton('catalog/layer');
61
+ foreach ($this->_filters as $filter) {
62
+ if ('category_id' == $filter['field']) {
63
+ $layer->setCurrentCategory((int)$filter['value']);
64
+ }
65
+ }
66
+ if ($layer->getCurrentCategory()->getIsAnchor()) {
67
+ foreach ($layer->getFilterableAttributes() as $attributeItem) {
68
+ $filterModelName = 'catalog/layer_filter_attribute';
69
+ switch ($attributeItem->getAttributeCode()) {
70
+ case 'price':
71
+ $filterModelName = 'catalog/layer_filter_price';
72
+ break;
73
+ case 'decimal':
74
+ $filterModelName = 'catalog/layer_filter_decimal';
75
+ break;
76
+ default:
77
+ $filterModelName = 'catalog/layer_filter_attribute';
78
+ break;
79
+ }
80
+
81
+ $filterModel = Mage::getModel($filterModelName);
82
+ $filterModel->setLayer($layer)->setAttributeModel($attributeItem);
83
+ $filterValues = new Varien_Data_Collection;
84
+ foreach ($filterModel->getItems() as $valueItem) {
85
+ $valueObject = new Varien_Object();
86
+ $valueObject->setLabel($valueItem->getLabel());
87
+ $valueObject->setValueString($valueItem->getValueString());
88
+ $valueObject->setProductsCount($valueItem->getCount());
89
+ $filterValues->addItem($valueObject);
90
+ }
91
+ $item = new Varien_Object;
92
+ $item->setCode($attributeItem->getAttributeCode());
93
+ $item->setName($filterModel->getName());
94
+ $item->setValues($filterValues);
95
+ $this->addItem($item);
96
+ }
97
+ }
98
+ }
99
+ return $this;
100
+ }
101
+ }
app/code/core/Mage/XmlConnect/Model/Mysql4/History.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+ class Mage_XmlConnect_Model_Mysql4_History extends Mage_Core_Model_Mysql4_Abstract
27
+ {
28
+ /**
29
+ * Constructor, setting table and index field
30
+ *
31
+ * @return void
32
+ */
33
+ protected function _construct()
34
+ {
35
+ $this->_init('xmlconnect/history', 'history_id');
36
+ }
37
+
38
+ /**
39
+ * Serialization for 'params' variable
40
+ *
41
+ * @param Mage_Core_Model_Abstract $object
42
+ * @return Mage_Core_Model_Abstract
43
+ */
44
+ protected function _beforeSave(Mage_Core_Model_Abstract $object)
45
+ {
46
+ $object->setParams(serialize($object->getParams()));
47
+ return parent::_beforeSave($object);
48
+ }
49
+
50
+ /**
51
+ * Deserialization for 'params' variable
52
+ *
53
+ * @param Mage_Core_Model_Abstract $object
54
+ * @return Mage_Core_Model_Abstract
55
+ */
56
+ protected function _afterLoad(Mage_Core_Model_Abstract $object)
57
+ {
58
+ $object->setParams(unserialize($object->getParams()));
59
+ return parent::_afterLoad($object);
60
+ }
61
+
62
+ /**
63
+ * Returns array of existing images
64
+ *
65
+ * @param int $id - application instance Id
66
+ * @return array
67
+ */
68
+ public function getLastParams($id)
69
+ {
70
+ $paramArray = array();
71
+ $idFieldName = Mage::getModel('xmlconnect/application')->getIdFieldName();
72
+ $select = $this->_getReadAdapter()->select()
73
+ ->from($this->getMainTable(), 'params')
74
+ ->where($idFieldName . '=?', $id)
75
+ ->order(array('created_at DESC'));
76
+
77
+ $params = $this->_getReadAdapter()->fetchOne($select);
78
+
79
+ if (isset($params)) {
80
+ $paramArray = unserialize($params);
81
+ }
82
+ return $paramArray;
83
+ }
84
+ }
app/code/core/Mage/XmlConnect/Model/Mysql4/History/Collection.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ /**
29
+ * History resource collection
30
+ *
31
+ * @category Mage
32
+ * @package Mage_XmlConnect
33
+ * @author Magento Core Team <core@magentocommerce.com>
34
+ */
35
+ class Mage_XmlConnect_Model_Mysql4_History_Collection
36
+ extends Mage_Core_Model_Mysql4_Collection_Abstract
37
+ {
38
+ /**
39
+ * Internal constructor
40
+ */
41
+ protected function _construct()
42
+ {
43
+ $this->_init('xmlconnect/history');
44
+ }
45
+
46
+ /**
47
+ * Filter collection by store
48
+ *
49
+ * @param int $storeId
50
+ * @return Mage_Core_Model_Mysql4_Collection_Abstract
51
+ */
52
+ public function addStoreFilter($storeId)
53
+ {
54
+ $this->addFieldToFilter('store_id', $storeId);
55
+ return $this;
56
+ }
57
+
58
+ /**
59
+ * Filter collection by application_id
60
+ *
61
+ * @param int $applicationId
62
+ * @return Mage_Core_Model_Mysql4_Collection_Abstract
63
+ */
64
+ public function addApplicationFilter($applicationId)
65
+ {
66
+ $this->addFieldToFilter('application_id', $applicationId);
67
+ return $this;
68
+ }
69
+ }
app/code/core/Mage/XmlConnect/Model/Mysql4/Queue.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+ class Mage_XmlConnect_Model_Mysql4_Queue extends Mage_Core_Model_Mysql4_Abstract
27
+ {
28
+ /**
29
+ * Constructor, setting table and index field
30
+ *
31
+ * @return void
32
+ */
33
+ protected function _construct()
34
+ {
35
+ $this->_init('xmlconnect/queue', 'id');
36
+ }
37
+ }
app/code/core/Mage/XmlConnect/Model/Mysql4/Queue/Collection.php ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ /**
29
+ * Queue resource collection
30
+ *
31
+ * @category Mage
32
+ * @package Mage_XmlConnect
33
+ * @author Magento Core Team <core@magentocommerce.com>
34
+ */
35
+ class Mage_XmlConnect_Model_Mysql4_Queue_Collection
36
+ extends Mage_Core_Model_Mysql4_Collection_Abstract
37
+ {
38
+ /**
39
+ * Internal constructor
40
+ *
41
+ * @return void
42
+ */
43
+ protected function _construct()
44
+ {
45
+ $this->_init('xmlconnect/queue');
46
+ }
47
+
48
+ /**
49
+ * Initialize collection select
50
+ *
51
+ * @return Mage_XmlConnect_Model_Mysql4_Queue_Collection
52
+ */
53
+ protected function _initSelect()
54
+ {
55
+ parent::_initSelect();
56
+ $this->_joinTemplateName()
57
+ ->_joinApplicationName();
58
+ return $this;
59
+ }
60
+
61
+ /**
62
+ * Join Template Name to collection
63
+ *
64
+ * @return Mage_XmlConnect_Model_Mysql4_Queue_Collection
65
+ */
66
+ protected function _joinTemplateName()
67
+ {
68
+ $this->getSelect()
69
+ ->joinLeft(array('t' => $this->getTable('xmlconnect/template')), 't.id = template_id', array(
70
+ 'template_name' => 't.name',
71
+ ));
72
+ return $this;
73
+ }
74
+
75
+ /**
76
+ * Join Application Name to collection
77
+ *
78
+ * @return Mage_XmlConnect_Model_Mysql4_Queue_Collection
79
+ */
80
+ protected function _joinApplicationName()
81
+ {
82
+ $this->getSelect()
83
+ ->joinLeft(array('app' => $this->getTable('xmlconnect/application')), 'app.code = main_table.app_code', array(
84
+ 'application_name' => 'app.name',
85
+ ));
86
+ return $this;
87
+ }
88
+
89
+ /**
90
+ * Add filter by only ready fot sending item
91
+ *
92
+ * @return Mage_XmlConnect_Model_Mysql4_Queue_Collection
93
+ */
94
+ public function addOnlyForSendingFilter()
95
+ {
96
+ $this->getSelect()
97
+ ->where('main_table.status in (?)', array(Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE))
98
+ ->where('main_table.exec_time < ?', Mage::getSingleton('core/date')->gmtDate())
99
+ ->order(new Zend_Db_Expr('main_table.exec_time ' . Zend_Db_Select::SQL_ASC));
100
+
101
+ return $this;
102
+ }
103
+ }
app/code/core/Mage/XmlConnect/Model/Mysql4/Setup.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+ class Mage_XmlConnect_Model_Mysql4_Setup extends Mage_Catalog_Model_Resource_Eav_Mysql4_Setup
27
+ {
28
+
29
+ }
app/code/core/Mage/XmlConnect/Model/Mysql4/Template.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+ class Mage_XmlConnect_Model_Mysql4_Template extends Mage_Core_Model_Mysql4_Abstract
27
+ {
28
+ /**
29
+ * Constructor, setting table and index field
30
+ *
31
+ * @return void
32
+ */
33
+ protected function _construct()
34
+ {
35
+ $this->_init('xmlconnect/template', 'id');
36
+ }
37
+ }
app/code/core/Mage/XmlConnect/Model/Mysql4/Template/Collection.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Template resource collection
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Model_Mysql4_Template_Collection
35
+ extends Mage_Core_Model_Mysql4_Collection_Abstract
36
+ {
37
+ /**
38
+ * Internal constructor
39
+ *
40
+ * @return void
41
+ */
42
+ protected function _construct()
43
+ {
44
+ $this->_init('xmlconnect/template');
45
+ }
46
+
47
+ /**
48
+ * Initialize collection select
49
+ *
50
+ * @return Mage_XmlConnect_Model_Mysql4_Template_Collection
51
+ */
52
+ protected function _initSelect()
53
+ {
54
+ parent::_initSelect();
55
+ $this->_joinApplicationName();
56
+ return $this;
57
+ }
58
+
59
+ /**
60
+ * Join Application Name to collection
61
+ *
62
+ * @return Mage_XmlConnect_Model_Mysql4_Template_Collection
63
+ */
64
+ protected function _joinApplicationName()
65
+ {
66
+ $this->getSelect()
67
+ ->joinLeft(array('app' => $this->getTable('xmlconnect/application')), 'app.code = app_code', array(
68
+ 'app_name' => 'app.name',
69
+ ));
70
+ return $this;
71
+ }
72
+ }
app/code/core/Mage/XmlConnect/Model/Observer.php ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect module observer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Xmlconnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Model_Observer
35
+ {
36
+ /**
37
+ * List of config field names which changing affects mobile applications behaviour
38
+ *
39
+ * @var array
40
+ */
41
+ protected $_appDependOnConfigFieldPathes = array(
42
+ Mage_XmlConnect_Model_Application::XML_PATH_PAYPAL_BUSINESS_ACCOUNT,
43
+ 'sendfriend/email/max_recipients',
44
+ 'sendfriend/email/allow_guest',
45
+ 'general/locale/code',
46
+ 'currency/options/default',
47
+ Mage_XmlConnect_Model_Application::XML_PATH_SECURE_BASE_LINK_URL,
48
+ Mage_XmlConnect_Model_Application::XML_PATH_GENERAL_RESTRICTION_IS_ACTIVE,
49
+ Mage_XmlConnect_Model_Application::XML_PATH_GENERAL_RESTRICTION_MODE,
50
+ Mage_XmlConnect_Model_Application::XML_PATH_DEFAULT_CACHE_LIFETIME
51
+ );
52
+
53
+ /**
54
+ * Stop website stub or private sales restriction
55
+ *
56
+ * @param Varien_Event_Observer $observer
57
+ */
58
+ public function restrictWebsite($observer)
59
+ {
60
+ if (Mage::app()->getRequest()->getModuleName() == 'xmlconnect') {
61
+ $observer->getEvent()->getResult()->setShouldProceed(false);
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Update all applications "updated at" parameter with current date on save some configurations
67
+ *
68
+ * @param Varien_Event_Observer $observer
69
+ */
70
+ public function changeUpdatedAtParamOnConfigSave($observer)
71
+ {
72
+ $configData = $observer->getEvent()->getConfigData();
73
+ if ($configData
74
+ && (int)$configData->isValueChanged()
75
+ && in_array($configData->getPath(), $this->_appDependOnConfigFieldPathes)
76
+ ) {
77
+ Mage::getModel('xmlconnect/application')->updateAllAppsUpdatedAtParameter();
78
+ }
79
+ }
80
+
81
+ /**
82
+ * Send a message if Start Date (Queue Date) is empty
83
+ *
84
+ * @param Varien_Event_Observer $observer
85
+ * @return bool
86
+ */
87
+ public function sendMessageImmediately($observer)
88
+ {
89
+ $message = $observer->getEvent()->getData('queueMessage');
90
+ if ($message instanceof Mage_XmlConnect_Model_Queue
91
+ && (strtolower($message->getExecTime()) == 'null'
92
+ || !$message->getExecTime()
93
+ )
94
+ ) {
95
+ $message->setExecTime(Mage::getSingleton('core/date')->gmtDate());
96
+ Mage::helper('xmlconnect')->sendBroadcastMessage($message);
97
+ return true;
98
+ }
99
+
100
+ return false;
101
+ }
102
+
103
+ /**
104
+ * Send scheduled messages
105
+ *
106
+ * @return void
107
+ */
108
+ public function scheduledSend()
109
+ {
110
+ $countOfQueue = Mage::getStoreConfig(Mage_XmlConnect_Model_Queue::XML_PATH_CRON_MESSAGES_COUNT);
111
+
112
+ $collection = Mage::getModel('xmlconnect/queue')->getCollection()->addOnlyForSendingFilter()
113
+ ->setPageSize($countOfQueue)->setCurPage(1)->load();
114
+
115
+ foreach ($collection as $message) {
116
+ if ($message->getId()) {
117
+ Mage::helper('xmlconnect')->sendBroadcastMessage($message);
118
+ }
119
+ }
120
+ }
121
+ }
app/code/core/Mage/XmlConnect/Model/Payment/Method/Paypal/Config.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * PayPal Mobile Express Checkout Library config
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Model_Payment_Method_Paypal_Config
35
+ extends Mage_Paypal_Model_Config
36
+ {
37
+ /**
38
+ * PayPal Website Payments Pro - PayPal Mobile Express Checkout Library
39
+ */
40
+ const METHOD_WPP_MECL = 'paypal_mecl';
41
+
42
+ /**
43
+ * Get url for dispatching customer to express checkout start
44
+ *
45
+ * @param string $token
46
+ * @return string
47
+ */
48
+ public function getExpressCheckoutStartUrl($token)
49
+ {
50
+ return $this->getPaypalUrl(array(
51
+ 'cmd' => '_express-checkout-mobile',
52
+ 'token' => $token,
53
+ ));
54
+ }
55
+ }
app/code/core/Mage/XmlConnect/Model/Payment/Method/Paypal/Mecl.php ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect PayPal Mobile Express Checkout Library model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Model_Payment_Method_Paypal_Mecl
35
+ extends Mage_Paypal_Model_Express
36
+ {
37
+ /**
38
+ * Store MECL payment method code
39
+ */
40
+ const MECL_METHOD_CODE = 'paypal_mecl';
41
+
42
+ /**
43
+ * Payment method code
44
+ *
45
+ * @var string
46
+ */
47
+ protected $_code = self::MECL_METHOD_CODE;
48
+
49
+ /**
50
+ * Check whether payment method can be used
51
+ *
52
+ * @param Mage_Sales_Model_Quote $quote
53
+ * @return bool
54
+ */
55
+ public function isAvailable($quote = null)
56
+ {
57
+ $storeId = false;
58
+ $model = Mage::registry('current_app');
59
+
60
+ if (($model instanceof Mage_XmlConnect_Model_Application)) {
61
+ $storeId = $model->getStoreId();
62
+ }
63
+
64
+ if (!$storeId) {
65
+ $storeId = $quote ? $quote->getStoreId() : Mage::app()->getStore()->getId();
66
+ }
67
+
68
+ return (bool) Mage::getModel('paypal/config')
69
+ ->setStoreId($storeId)
70
+ ->isMethodAvailable(Mage_Paypal_Model_Config::METHOD_WPP_EXPRESS);
71
+ }
72
+
73
+ /**
74
+ * Return title of the PayPal Mobile Express Checkout Payment method
75
+ *
76
+ * @return string
77
+ */
78
+ public function getTitle()
79
+ {
80
+ return Mage::helper('xmlconnect')->__('PayPal Mobile Express Checkout');
81
+ }
82
+ }
app/code/core/Mage/XmlConnect/Model/Payment/Method/Paypal/Mep.php ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * PayPal Mobile Embedded Payments Checkout Module
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Model_Payment_Method_Paypal_Mep extends Mage_Paypal_Model_Express
35
+ {
36
+ /**
37
+ * Store MEP payment method code
38
+ */
39
+ const MEP_METHOD_CODE = 'paypal_mep';
40
+
41
+ /**
42
+ * Payment method code
43
+ *
44
+ * @var string
45
+ */
46
+ protected $_code = self::MEP_METHOD_CODE;
47
+
48
+ protected $_canUseInternal = false;
49
+ protected $_canUseForMultishipping = false;
50
+ protected $_isInitializeNeeded = false;
51
+ protected $_canUseCheckout = false;
52
+ protected $_canManageRecurringProfiles = false;
53
+
54
+ /**
55
+ * Get config payment action url
56
+ * Used to universalize payment actions when processing payment place
57
+ *
58
+ * @return string
59
+ */
60
+ public function getConfigPaymentAction()
61
+ {
62
+ return Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE;
63
+ }
64
+
65
+ /**
66
+ * Check whether payment method can be used
67
+ *
68
+ * @param Mage_Sales_Model_Quote $quote
69
+ * @return bool
70
+ */
71
+ public function isAvailable($quote = null)
72
+ {
73
+ $storeId = false;
74
+ $model = Mage::registry('current_app');
75
+
76
+ if (($model instanceof Mage_XmlConnect_Model_Application)) {
77
+ $storeId = $model->getStoreId();
78
+ }
79
+
80
+ if (!$storeId) {
81
+ $storeId = $quote ? $quote->getStoreId() : Mage::app()->getStore()->getId();
82
+ }
83
+
84
+ return (bool) Mage::getModel('paypal/config')
85
+ ->setStoreId($storeId)
86
+ ->isMethodAvailable(Mage_Paypal_Model_Config::METHOD_WPP_EXPRESS);
87
+ }
88
+
89
+ /**
90
+ * Capture payment
91
+ *
92
+ * @param Varien_Object $payment
93
+ * @param float $amount
94
+ * @return Mage_Payment_Model_Abstract
95
+ */
96
+ public function capture(Varien_Object $payment, $amount)
97
+ {
98
+ $transactionId = $payment->getAdditionalInformation(
99
+ Mage_XmlConnect_Model_Paypal_Mep_Checkout::PAYMENT_INFO_TRANSACTION_ID
100
+ );
101
+ $payment->setTransactionId($transactionId);
102
+ return $this;
103
+ }
104
+
105
+ /**
106
+ * Return title of the PayPal Mobile Embedded Payment method
107
+ *
108
+ * @return string
109
+ */
110
+ public function getTitle()
111
+ {
112
+ return Mage::helper('xmlconnect')->__('PayPal MEP');
113
+ }
114
+ }
app/code/core/Mage/XmlConnect/Model/Paypal/Mecl/Checkout.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * XmlConnect PayPal Mobile Express Checkout Library model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Model_Paypal_Mecl_Checkout
35
+ extends Mage_Paypal_Model_Express_Checkout
36
+ {
37
+ /**
38
+ * Payment method type
39
+ *
40
+ * @var string
41
+ */
42
+ protected $_methodType = Mage_XmlConnect_Model_Payment_Method_Paypal_Config::METHOD_WPP_MECL;
43
+ }
app/code/core/Mage/XmlConnect/Model/Paypal/Mep/Checkout.php ADDED
@@ -0,0 +1,358 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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 Mage
22
+ * @package Mage_XmlConnect
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Wrapper that performs Paypal MEP and Checkout communication
29
+ *
30
+ * @category Mage
31
+ * @package Mage_XmlConnect
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_XmlConnect_Model_Paypal_Mep_Checkout
35
+ {
36
+ /**#@+
37
+ * Keys for passthrough variables in sales/quote_payment and sales/order_payment
38
+ * Uses additional_information as storage
39
+ */
40
+ const PAYMENT_INFO_PAYER_EMAIL = 'paypal_payer_email';
41
+ const PAYMENT_INFO_TRANSACTION_ID = 'paypal_mep_checkout_transaction_id';
42
+ /**#@-*/
43
+
44
+ /**
45
+ * Payment method type
46
+ *
47
+ * @var string
48
+ */
49
+ protected $_methodType = Mage_XmlConnect_Model_Payment_Method_Paypal_Mep::MEP_METHOD_CODE;
50
+
51
+ /**
52
+ * Quote model
53
+ *
54
+ * @var Mage_Sales_Model_Quote
55
+ */
56
+ protected $_quote = null;
57
+
58
+ /**
59
+ * Checkout session model
60
+ *
61
+ * @var Mage_Checkout_Model_Session
62
+ */
63
+ protected $_checkoutSession;
64
+
65
+ /**
66
+ * XmlConnect default helper
67
+ *
68
+ * @var Mage_XmlConnect_Helper_Data
69
+ */
70
+ protected $_helper;
71
+
72
+ /**
73
+ * Set quote instances
74
+ *
75
+ * @throws Mage_Core_Exception
76
+ * @param array $params
77
+ * @return void
78
+ */
79
+ public function __construct($params = array())
80
+ {
81
+ $this->_checkoutSession = Mage::getSingleton('xmlconnect/corefix_checkout_session');
82
+ if (isset($params['quote']) && $params['quote'] instanceof Mage_Sales_Model_Quote) {
83
+ $this->_quote