BxSnipcartModule.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 serviceIncludeCssJs($iProfileId = 0)
  23. {
  24. $iProfileId = !empty($iProfileId) ? $iProfileId : $this->_iProfileId;
  25. if(empty($iProfileId))
  26. return '';
  27. $aSettings = $this->_oDb->getSettings(array('type' => 'author', 'author' => $iProfileId));
  28. if(empty($aSettings) || !is_array($aSettings))
  29. return '';
  30. return $this->_oTemplate->getSctInclude($aSettings);
  31. }
  32. public function serviceEntityCreate ()
  33. {
  34. $CNF = &$this->_oConfig->CNF;
  35. $aSettings = $this->_oDb->getSettings(array('type' => 'author', 'author' => $this->_iProfileId));
  36. if(empty($aSettings) || !is_array($aSettings))
  37. return MsgBox(_t('_bx_snipcart_err_not_configured', BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_SETTINGS'])));
  38. $this->_oTemplate->addJs(array('entry.js'));
  39. return $this->_oTemplate->getJsCode('entry') . parent::serviceEntityCreate();
  40. }
  41. public function serviceSettings()
  42. {
  43. $CNF = &$this->_oConfig->CNF;
  44. if(!$this->_iProfileId)
  45. return MsgBox(_t('_Access denied'));
  46. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_SETTINGS'], $CNF['OBJECT_FORM_SETTINGS_DISPLAY_EDIT'], $this->_oTemplate);
  47. if(!$oForm)
  48. return MsgBox(_t('_sys_txt_error_occured'));
  49. $aSettings = $this->_oDb->getSettings(array('type' => 'author', 'author' => $this->_iProfileId));
  50. $bSettings = !empty($aSettings) && is_array($aSettings);
  51. $oForm->initChecker($aSettings);
  52. if(!$oForm->isSubmittedAndValid())
  53. return $oForm->getCode();
  54. if(!$bSettings) {
  55. $aValsToAdd = array('author' => $this->_iProfileId);
  56. $iSettings = $oForm->insert($aValsToAdd);
  57. if(!$iSettings) {
  58. if(!$oForm->isValid())
  59. return $oForm->getCode();
  60. else
  61. return MsgBox(_t('_sys_txt_error_entry_creation'));
  62. }
  63. }
  64. else {
  65. if(!$oForm->update($aSettings['id'])) {
  66. if(!$oForm->isValid())
  67. return $oForm->getCode();
  68. else
  69. return MsgBox(_t('_sys_txt_error_entry_update'));
  70. }
  71. }
  72. return array(
  73. 'content' => $oForm->getCode()
  74. );
  75. }
  76. }
  77. /** @} */