BxSnipcartModule.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 Snipcart Snipcart
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. define('BX_SNIPCART_MODE_TEST', 'test');
  12. define('BX_SNIPCART_MODE_LIVE', 'live');
  13. /**
  14. * Snipcart module
  15. */
  16. class BxSnipcartModule 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 serviceIncludeCssJs($iProfileId = 0)
  32. {
  33. $iProfileId = !empty($iProfileId) ? $iProfileId : $this->_iProfileId;
  34. if(empty($iProfileId))
  35. return '';
  36. return $this->_oTemplate->getSctInclude($iProfileId);
  37. }
  38. public function serviceEntityCreate ()
  39. {
  40. $CNF = &$this->_oConfig->CNF;
  41. $aSettings = $this->_oDb->getSettings(array('type' => 'author', 'author' => $this->_iProfileId));
  42. if(empty($aSettings) || !is_array($aSettings))
  43. return MsgBox(_t('_bx_snipcart_err_not_configured', BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_SETTINGS'])));
  44. return parent::serviceEntityCreate();
  45. }
  46. public function serviceSettings()
  47. {
  48. $CNF = &$this->_oConfig->CNF;
  49. if(!$this->_iProfileId)
  50. return MsgBox(_t('_Access denied'));
  51. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_SETTINGS'], $CNF['OBJECT_FORM_SETTINGS_DISPLAY_EDIT'], $this->_oTemplate);
  52. if(!$oForm)
  53. return MsgBox(_t('_sys_txt_error_occured'));
  54. $aSettings = $this->_oDb->getSettings(array('type' => 'author', 'author' => $this->_iProfileId));
  55. $bSettings = !empty($aSettings) && is_array($aSettings);
  56. $oForm->initChecker($aSettings);
  57. if(!$oForm->isSubmittedAndValid())
  58. return $oForm->getCode();
  59. if(!$bSettings) {
  60. $aValsToAdd = array('author' => $this->_iProfileId);
  61. $iSettings = $oForm->insert($aValsToAdd);
  62. if(!$iSettings) {
  63. if(!$oForm->isValid())
  64. return $oForm->getCode();
  65. else
  66. return MsgBox(_t('_sys_txt_error_entry_creation'));
  67. }
  68. }
  69. else {
  70. if(!$oForm->update($aSettings['id'])) {
  71. if(!$oForm->isValid())
  72. return $oForm->getCode();
  73. else
  74. return MsgBox(_t('_sys_txt_error_entry_update'));
  75. }
  76. }
  77. return array(
  78. 'content' => $oForm->getCode()
  79. );
  80. }
  81. protected function _getContentForTimelinePost($aEvent, $aContentInfo)
  82. {
  83. $aResult = parent::_getContentForTimelinePost($aEvent, $aContentInfo);
  84. $aResult['raw'] = $this->_oTemplate->getBuyButton($aContentInfo);
  85. return $aResult;
  86. }
  87. }
  88. /** @} */