BxShopifyModule.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. }
  22. public function getSettings($iProfileId = 0)
  23. {
  24. if(empty($iProfileId))
  25. $iProfileId = bx_get_logged_profile_id();
  26. $aSettings = $this->_oDb->getSettings(array('type' => 'author', 'author' => $iProfileId));
  27. if(empty($aSettings) || !is_array($aSettings))
  28. return array();
  29. return $aSettings;
  30. }
  31. public function serviceInclude($iProfileId = 0)
  32. {
  33. $this->serviceIncludeCssJs();
  34. return $this->serviceIncludeCode($iProfileId);
  35. }
  36. public function serviceIncludeCssJs()
  37. {
  38. $this->_oTemplate->getIncludeCssJs();
  39. }
  40. public function serviceIncludeCode($iProfileId = 0)
  41. {
  42. $iProfileId = !empty($iProfileId) ? $iProfileId : $this->_iProfileId;
  43. if(empty($iProfileId))
  44. return '';
  45. $aSettings = $this->getSettings($iProfileId);
  46. if(empty($aSettings))
  47. return '';
  48. return $this->_oTemplate->getIncludeCode($iProfileId, $aSettings);
  49. }
  50. public function serviceEntityCreate ()
  51. {
  52. $CNF = &$this->_oConfig->CNF;
  53. $aSettings = $this->_oDb->getSettings(array('type' => 'author', 'author' => $this->_iProfileId));
  54. if(empty($aSettings) || !is_array($aSettings))
  55. return MsgBox(_t('_bx_shopify_err_not_configured', BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_SETTINGS'])));
  56. return parent::serviceEntityCreate();
  57. }
  58. public function serviceSettings()
  59. {
  60. $CNF = &$this->_oConfig->CNF;
  61. if(!$this->_iProfileId)
  62. return MsgBox(_t('_Access denied'));
  63. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_SETTINGS'], $CNF['OBJECT_FORM_SETTINGS_DISPLAY_EDIT'], $this->_oTemplate);
  64. if(!$oForm)
  65. return MsgBox(_t('_sys_txt_error_occured'));
  66. $aSettings = $this->_oDb->getSettings(array('type' => 'author', 'author' => $this->_iProfileId));
  67. $bSettings = !empty($aSettings) && is_array($aSettings);
  68. $oForm->initChecker($aSettings);
  69. if(!$oForm->isSubmittedAndValid())
  70. return $oForm->getCode();
  71. if(!$bSettings) {
  72. $aValsToAdd = array('author' => $this->_iProfileId);
  73. $iSettings = $oForm->insert($aValsToAdd);
  74. if(!$iSettings) {
  75. if(!$oForm->isValid())
  76. return $oForm->getCode();
  77. else
  78. return MsgBox(_t('_sys_txt_error_entry_creation'));
  79. }
  80. }
  81. else {
  82. if(!$oForm->update($aSettings['id'])) {
  83. if(!$oForm->isValid())
  84. return $oForm->getCode();
  85. else
  86. return MsgBox(_t('_sys_txt_error_entry_update'));
  87. }
  88. }
  89. return array(
  90. 'content' => $oForm->getCode()
  91. );
  92. }
  93. // ====== PERMISSION METHODS
  94. public function isAllowedViewDashboard()
  95. {
  96. $aSettings = $this->getSettings();
  97. if(empty($aSettings))
  98. return false;
  99. return true;
  100. }
  101. public function checkAllowedSetThumb()
  102. {
  103. return _t('_sys_txt_access_denied');
  104. }
  105. }
  106. /** @} */