1
0

BxShopifyModule.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 Shopify Shopify
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. define('BX_SHOPIFY_MODE_TEST', 'test');
  12. define('BX_SHOPIFY_MODE_LIVE', 'live');
  13. /**
  14. * Shopify module
  15. */
  16. class BxShopifyModule extends BxBaseModTextModule
  17. {
  18. function __construct(&$aModule)
  19. {
  20. parent::__construct($aModule);
  21. $this->_aSearchableNamesExcept[] = $this->_oConfig->CNF['FIELD_CODE'];
  22. }
  23. public function getSettings($iProfileId = 0)
  24. {
  25. if(empty($iProfileId))
  26. $iProfileId = bx_get_logged_profile_id();
  27. $aSettings = $this->_oDb->getSettings(array('type' => 'author', 'author' => $iProfileId));
  28. if(empty($aSettings) || !is_array($aSettings))
  29. return array();
  30. return $aSettings;
  31. }
  32. /**
  33. * @page service Service Calls
  34. * @section bx_shopify Shopify
  35. * @subsection bx_shopify-integration Integration
  36. * @subsubsection bx_shopify-include include
  37. *
  38. * @code bx_srv('bx_shopify', 'include', [...]); @endcode
  39. *
  40. * Get integration code with all necessary CSS and JS includes.
  41. *
  42. * @return HTML sting with integration code to display on the site, all necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  43. *
  44. * @see BxShopifyModule::serviceInclude
  45. */
  46. /**
  47. * @ref bx_shopify-include "include"
  48. */
  49. public function serviceInclude($iProfileId = 0)
  50. {
  51. $this->serviceIncludeCssJs();
  52. return $this->serviceIncludeCode($iProfileId);
  53. }
  54. /**
  55. * @page service Service Calls
  56. * @section bx_shopify Shopify
  57. * @subsection bx_shopify-integration Integration
  58. * @subsubsection bx_shopify-include_css_js include_css_js
  59. *
  60. * @code bx_srv('bx_shopify', 'include_css_js', [...]); @endcode
  61. *
  62. * Include all necessary CSS and JS files.
  63. *
  64. * @see BxShopifyModule::serviceIncludeCssJs
  65. */
  66. /**
  67. * @ref bx_shopify-include_css_js "include_css_js"
  68. */
  69. public function serviceIncludeCssJs()
  70. {
  71. $this->_oTemplate->getIncludeCssJs();
  72. }
  73. /**
  74. * @page service Service Calls
  75. * @section bx_shopify Shopify
  76. * @subsection bx_shopify-integration Integration
  77. * @subsubsection bx_shopify-include_code include_code
  78. *
  79. * @code bx_srv('bx_shopify', 'include_code', [...]); @endcode
  80. *
  81. * Get integration code.
  82. *
  83. * @return HTML sting with integration code to display on the site. Empty string is returned if there is no enough input data.
  84. *
  85. * @see BxShopifyModule::serviceIncludeCode
  86. */
  87. /**
  88. * @ref bx_shopify-include_code "include_code"
  89. */
  90. public function serviceIncludeCode($iProfileId = 0)
  91. {
  92. $iProfileId = !empty($iProfileId) ? $iProfileId : $this->_iProfileId;
  93. if(empty($iProfileId))
  94. return '';
  95. $aSettings = $this->getSettings($iProfileId);
  96. if(empty($aSettings))
  97. return '';
  98. return $this->_oTemplate->getIncludeCode($iProfileId, $aSettings);
  99. }
  100. /**
  101. * @page service Service Calls
  102. * @section bx_shopify Shopify
  103. * @subsection bx_shopify-page_blocks Page Blocks
  104. * @subsubsection bx_shopify-get_results_search_extended get_results_search_extended
  105. *
  106. * @code bx_srv('bx_shopify', 'get_results_search_extended', [...]); @endcode
  107. *
  108. * Get page block with the results of Extended Search.
  109. *
  110. * @param $aParams an array with search params.
  111. * @return HTML string with block content to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  112. *
  113. * @see BxShopifyModule::serviceGetResultsSearchExtended
  114. */
  115. /**
  116. * @ref bx_shopify-get_results_search_extended "get_results_search_extended"
  117. */
  118. public function serviceGetResultsSearchExtended($aParams)
  119. {
  120. $this->serviceIncludeCssJs();
  121. return BxDolService::call('system', 'get_results', array($aParams), 'TemplSearchExtendedServices');
  122. }
  123. /**
  124. * @page service Service Calls
  125. * @section bx_shopify Shopify
  126. * @subsection bx_shopify-page_blocks Page Blocks
  127. * @subsubsection bx_shopify-entity_create entity_create
  128. *
  129. * @code bx_srv('bx_shopify', 'entity_create', [...]); @endcode
  130. *
  131. * Get page block with product creation form or an error message if something wasn't configured correctly.
  132. *
  133. * @param $sDisplay form display name to use
  134. * @return HTML string with block content to display on the site, all necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  135. *
  136. * @see BxShopifyModule::serviceEntityCreate
  137. */
  138. /**
  139. * @ref bx_shopify-entity_create "entity_create"
  140. */
  141. public function serviceEntityCreate ($sDisplay = false)
  142. {
  143. $CNF = &$this->_oConfig->CNF;
  144. $aSettings = $this->_oDb->getSettings(array('type' => 'author', 'author' => $this->_iProfileId));
  145. if(empty($aSettings) || !is_array($aSettings))
  146. return MsgBox(_t('_bx_shopify_err_not_configured', bx_absolute_url(BxDolPermalinks::getInstance()->permalink($CNF['URL_SETTINGS']))));
  147. return parent::serviceEntityCreate($sDisplay);
  148. }
  149. /**
  150. * @page service Service Calls
  151. * @section bx_shopify Shopify
  152. * @subsection bx_shopify-page_blocks Page Blocks
  153. * @subsubsection bx_shopify-settings settings
  154. *
  155. * @code bx_srv('bx_shopify', 'settings', [...]); @endcode
  156. *
  157. * Get page block with configuration settings form.
  158. *
  159. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  160. *
  161. * @see BxShopifyModule::serviceSettings
  162. */
  163. /**
  164. * @ref bx_shopify-settings "settings"
  165. */
  166. public function serviceSettings()
  167. {
  168. $CNF = &$this->_oConfig->CNF;
  169. if(!$this->_iProfileId)
  170. return array(
  171. 'content' => MsgBox(_t('_Access denied'))
  172. );
  173. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_SETTINGS'], $CNF['OBJECT_FORM_SETTINGS_DISPLAY_EDIT'], $this->_oTemplate);
  174. if(!$oForm)
  175. return array(
  176. 'content' => MsgBox(_t('_sys_txt_error_occured'))
  177. );
  178. $aSettings = $this->_oDb->getSettings(array('type' => 'author', 'author' => $this->_iProfileId));
  179. $bSettings = !empty($aSettings) && is_array($aSettings);
  180. $sResultTimer = 0;
  181. $sResultMessage = '';
  182. $oForm->initChecker($aSettings);
  183. if($oForm->isSubmittedAndValid()) {
  184. if(!$bSettings) {
  185. if((int)$oForm->insert(array('author' => $this->_iProfileId)) > 0) {
  186. $sResultTimer = 3;
  187. $sResultMessage = '_bx_shopify_msg_save_settings';
  188. }
  189. else
  190. $sResultMessage = '_bx_shopify_err_save_settings';
  191. }
  192. else {
  193. if($oForm->update($aSettings['id']) !== false) {
  194. $sResultTimer = 3;
  195. $sResultMessage = '_bx_shopify_msg_save_settings';
  196. }
  197. else
  198. $sResultMessage = '_bx_shopify_err_save_settings';
  199. }
  200. }
  201. return array(
  202. 'content' => (!empty($sResultMessage) ? MsgBox(_t($sResultMessage), $sResultTimer) : '') . $oForm->getCode()
  203. );
  204. }
  205. // ====== PERMISSION METHODS
  206. public function isAllowedViewDashboard()
  207. {
  208. $aSettings = $this->getSettings();
  209. if(empty($aSettings))
  210. return false;
  211. return true;
  212. }
  213. public function checkAllowedSetThumb($iContentId = 0)
  214. {
  215. return _t('_sys_txt_access_denied');
  216. }
  217. }
  218. /** @} */