BxBasePaymentsServices.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * System services related to Payments.
  11. */
  12. class BxBasePaymentsServices extends BxDol
  13. {
  14. protected $_sPrelistsCurrency;
  15. public function __construct()
  16. {
  17. parent::__construct();
  18. $this->_sPrelistsCurrency = 'Currency';
  19. }
  20. public function serviceGetOptionsCurrencyCodeDefault()
  21. {
  22. $aCurrencies = BxDolForm::getDataItems($this->_sPrelistsCurrency);
  23. $aResult = array();
  24. foreach($aCurrencies as $sKey => $sValue)
  25. $aResult[] = array(
  26. 'key' => $sKey,
  27. 'value' => $sValue
  28. );
  29. return $aResult;
  30. }
  31. public function serviceGetOptionsCurrencySignDefault()
  32. {
  33. $aCurrencies = BxDolForm::getDataItems($this->_sPrelistsCurrency, false, BX_DATA_VALUES_ALL);
  34. $aResult = array();
  35. foreach($aCurrencies as $aCurrency) {
  36. $aData = array();
  37. if(empty($aCurrency['Data']) || !($aData = unserialize($aCurrency['Data'])))
  38. continue;
  39. $aResult[] = array(
  40. 'key' => htmlspecialchars($aData['sign'], ENT_XHTML),
  41. 'value' => $aData['sign']
  42. );
  43. }
  44. return $aResult;
  45. }
  46. public function serviceGetPayments()
  47. {
  48. return BxDolPayments::getInstance()->getPayments();
  49. }
  50. /**
  51. * @page service Service Calls
  52. * @section bx_system_general System Services
  53. * @subsection bx_system_general-payments Payments
  54. * @subsubsection bx_system_general-get_cart_items_count get_cart_items_count
  55. *
  56. * @code bx_srv('system', 'get_cart_items_count', [], 'TemplPaymentsServices'); @endcode
  57. * @code {{~system:get_cart_items_count:TemplPaymentsServices~}} @endcode
  58. *
  59. * Get number of items in shopping cart for currently logged in profile.
  60. *
  61. * @see BxBasePaymentsServices::serviceGetChartStats
  62. */
  63. /**
  64. * @ref bx_system_general-get_cart_items_count "get_cart_items_count"
  65. */
  66. public function serviceGetCartItemsCount()
  67. {
  68. return BxDolPayments::getInstance()->getCartItemsCount();
  69. }
  70. /**
  71. * @page service Service Calls
  72. * @section bx_system_general System Services
  73. * @subsection bx_system_general-payments Payments
  74. * @subsubsection bx_system_general-get_orders_count get_orders_count
  75. *
  76. * @code bx_srv('system', 'get_orders_count', ["new"], 'TemplPaymentsServices'); @endcode
  77. * @code {{~system:get_orders_count:TemplPaymentsServices["new"]~}} @endcode
  78. *
  79. * Get number of order by type for currently logged in profile.
  80. * @param $sType type, for example: new
  81. *
  82. * @see BxBasePaymentsServices::serviceGetOrdersCount
  83. */
  84. /**
  85. * @ref bx_system_general-get_orders_count "get_orders_count"
  86. */
  87. public function serviceGetOrdersCount($sType)
  88. {
  89. return BxDolPayments::getInstance()->getOrdersCount($sType);
  90. }
  91. /**
  92. * @page service Service Calls
  93. * @section bx_system_general System Services
  94. * @subsection bx_system_general-payments Payments
  95. * @subsubsection bx_system_general-get_invoices_count get_invoices_count
  96. *
  97. * @code bx_srv('system', 'get_invoices_count', ["unpaid"], 'TemplPaymentsServices'); @endcode
  98. * @code {{~system:get_invoices_count:TemplPaymentsServices["unpaid"]~}} @endcode
  99. *
  100. * Get number of invoices by type for currently logged in profile.
  101. * @param $sType type, for example: unpaid
  102. *
  103. * @see BxBasePaymentsServices::serviceGetInvoicesCount
  104. */
  105. /**
  106. * @ref bx_system_general-get_invoices_count "get_invoices_count"
  107. */
  108. public function serviceGetInvoicesCount($sType)
  109. {
  110. return BxDolPayments::getInstance()->getInvoicesCount($sType);
  111. }
  112. public function serviceGetLiveUpdatesCart($aMenuItemParent, $aMenuItemChild, $iCount = 0)
  113. {
  114. $iCountNew = BxDolPayments::getInstance()->getCartItemsCount();
  115. if($iCountNew == $iCount)
  116. return false;
  117. return array(
  118. 'count' => $iCountNew, // required
  119. 'method' => 'bx_menu_show_live_update(oData)', // required
  120. 'data' => array(
  121. 'code' => BxDolTemplate::getInstance()->parseHtmlByTemplateName('menu_item_addon', array(
  122. 'content' => '{count}'
  123. )),
  124. 'mi_parent' => $aMenuItemParent,
  125. 'mi_child' => $aMenuItemChild
  126. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  127. );
  128. }
  129. public function serviceGetLiveUpdatesOrders($aMenuItemParent, $aMenuItemChild, $iCount = 0)
  130. {
  131. $iCountNew = BxDolPayments::getInstance()->getOrdersCount('new');
  132. if($iCountNew == $iCount)
  133. return false;
  134. return array(
  135. 'count' => $iCountNew, // required
  136. 'method' => 'bx_menu_show_live_update(oData)', // required
  137. 'data' => array(
  138. 'code' => BxDolTemplate::getInstance()->parseHtmlByTemplateName('menu_item_addon', array(
  139. 'content' => '{count}'
  140. )),
  141. 'mi_parent' => $aMenuItemParent,
  142. 'mi_child' => $aMenuItemChild
  143. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  144. );
  145. }
  146. public function serviceGetLiveUpdatesInvoices($aMenuItemParent, $aMenuItemChild, $iCount = 0)
  147. {
  148. $iCountNew = BxDolPayments::getInstance()->getInvoicesCount('unpaid');
  149. if($iCountNew == $iCount)
  150. return false;
  151. return array(
  152. 'count' => $iCountNew, // required
  153. 'method' => 'bx_menu_show_live_update(oData)', // required
  154. 'data' => array(
  155. 'code' => BxDolTemplate::getInstance()->parseHtmlByTemplateName('menu_item_addon', array(
  156. 'content' => '{count}'
  157. )),
  158. 'mi_parent' => $aMenuItemParent,
  159. 'mi_child' => $aMenuItemChild
  160. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  161. );
  162. }
  163. }
  164. /** @} */