BxShopifyModule.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. * @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.
  134. *
  135. * @see BxShopifyModule::serviceEntityCreate
  136. */
  137. /**
  138. * @ref bx_shopify-entity_create "entity_create"
  139. */
  140. public function serviceEntityCreate ()
  141. {
  142. $CNF = &$this->_oConfig->CNF;
  143. $aSettings = $this->_oDb->getSettings(array('type' => 'author', 'author' => $this->_iProfileId));
  144. if(empty($aSettings) || !is_array($aSettings))
  145. return MsgBox(_t('_bx_shopify_err_not_configured', BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_SETTINGS'])));
  146. return parent::serviceEntityCreate();
  147. }
  148. /**
  149. * @page service Service Calls
  150. * @section bx_shopify Shopify
  151. * @subsection bx_shopify-page_blocks Page Blocks
  152. * @subsubsection bx_shopify-settings settings
  153. *
  154. * @code bx_srv('bx_shopify', 'settings', [...]); @endcode
  155. *
  156. * Get page block with configuration settings form.
  157. *
  158. * @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.
  159. *
  160. * @see BxShopifyModule::serviceSettings
  161. */
  162. /**
  163. * @ref bx_shopify-settings "settings"
  164. */
  165. public function serviceSettings()
  166. {
  167. $CNF = &$this->_oConfig->CNF;
  168. if(!$this->_iProfileId)
  169. return array(
  170. 'content' => MsgBox(_t('_Access denied'))
  171. );
  172. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_SETTINGS'], $CNF['OBJECT_FORM_SETTINGS_DISPLAY_EDIT'], $this->_oTemplate);
  173. if(!$oForm)
  174. return array(
  175. 'content' => MsgBox(_t('_sys_txt_error_occured'))
  176. );
  177. $aSettings = $this->_oDb->getSettings(array('type' => 'author', 'author' => $this->_iProfileId));
  178. $bSettings = !empty($aSettings) && is_array($aSettings);
  179. $sResultTimer = 0;
  180. $sResultMessage = '';
  181. $oForm->initChecker($aSettings);
  182. if($oForm->isSubmittedAndValid()) {
  183. if(!$bSettings) {
  184. if((int)$oForm->insert(array('author' => $this->_iProfileId)) > 0) {
  185. $sResultTimer = 3;
  186. $sResultMessage = '_bx_shopify_msg_save_settings';
  187. }
  188. else
  189. $sResultMessage = '_bx_shopify_err_save_settings';
  190. }
  191. else {
  192. if($oForm->update($aSettings['id']) !== false) {
  193. $sResultTimer = 3;
  194. $sResultMessage = '_bx_shopify_msg_save_settings';
  195. }
  196. else
  197. $sResultMessage = '_bx_shopify_err_save_settings';
  198. }
  199. }
  200. return array(
  201. 'content' => (!empty($sResultMessage) ? MsgBox(_t($sResultMessage), $sResultTimer) : '') . $oForm->getCode()
  202. );
  203. }
  204. // ====== PERMISSION METHODS
  205. public function isAllowedViewDashboard()
  206. {
  207. $aSettings = $this->getSettings();
  208. if(empty($aSettings))
  209. return false;
  210. return true;
  211. }
  212. public function checkAllowedSetThumb($iContentId = 0)
  213. {
  214. return _t('_sys_txt_access_denied');
  215. }
  216. }
  217. /** @} */