BxShopifyTemplate.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. /*
  12. * Module representation.
  13. */
  14. class BxShopifyTemplate extends BxBaseModTextTemplate
  15. {
  16. /**
  17. * Constructor
  18. */
  19. function __construct(&$oConfig, &$oDb)
  20. {
  21. $this->MODULE = 'bx_shopify';
  22. parent::__construct($oConfig, $oDb);
  23. }
  24. public function getIncludeCssJs()
  25. {
  26. $this->addCss(array(
  27. 'unit.css'
  28. ));
  29. $sProto = bx_proto();
  30. $this->addJs(array(
  31. $sProto . '://sdks.shopifycdn.com/js-buy-sdk/v1/latest/index.umd.min.js',
  32. 'shop.js'
  33. ));
  34. }
  35. public function getIncludeCode($iProfileId, $aSettings)
  36. {
  37. if(empty($aSettings))
  38. return '';
  39. $sCode = $this->getJsCode('shop', array(
  40. 'sDomain' => $aSettings['domain'],
  41. 'sAccessToken' => $aSettings['access_token'],
  42. ));
  43. $this->addJsTranslation(array(
  44. '_bx_shopify_err_load_product',
  45. '_bx_shopify_err_load_collection'
  46. ));
  47. return bx_replace_markers($sCode, array(
  48. 'profile_id' => $iProfileId
  49. ));
  50. }
  51. public function entryBuy($aData)
  52. {
  53. $CNF = &$this->getModule()->_oConfig->CNF;
  54. return $this->parseHtmlByName('entry-buy.html', array(
  55. 'js_object' => $this->_oConfig->getJsObjectShop($aData[$CNF['FIELD_AUTHOR']]),
  56. 'html_id' => $this->_oConfig->getHtmlIds('entry_buy'),
  57. 'entry_code' => $aData[$CNF['FIELD_CODE']]
  58. ));
  59. }
  60. public function entryText ($aData, $sTemplateName = 'entry-text.html')
  61. {
  62. $CNF = &$this->getModule()->_oConfig->CNF;
  63. $aVars = parent::getTmplVarsText($aData);
  64. $aVars = array_merge($aVars, array(
  65. 'js_object' => $this->_oConfig->getJsObjectShop($aData[$CNF['FIELD_AUTHOR']]),
  66. 'html_id' => $this->_oConfig->getHtmlIds('entry_content'),
  67. 'entry_title' => $this->getTitle($aData),
  68. 'entry_code' => $aData[$CNF['FIELD_CODE']]
  69. ));
  70. return $this->parseHtmlByName($sTemplateName, $aVars);
  71. }
  72. public function entryAttachments ($aData, $aParams = array())
  73. {
  74. $sPopupId = 'bx-messages-atachment-popup-{id}';
  75. return $this->parseHtmlByName('attachments.html', array(
  76. 'html_id' => $this->_oConfig->getHtmlIds('entry_attachments'),
  77. 'html_id_sample' => $this->_oConfig->getHtmlIds('entry_attachment_sample'),
  78. 'popup_id' => $sPopupId,
  79. 'popup' => BxTemplFunctions::getInstance()->transBox($sPopupId, '<img class="bx-spf-attachment-popup-img" src="" />', true, true),
  80. ));
  81. }
  82. public function getJsCode($sType, $aParams = array(), $bWrap = true)
  83. {
  84. $aParams = array_merge(array(
  85. 'aHtmlIds' => $this->_oConfig->getHtmlIds()
  86. ), $aParams);
  87. return parent::getJsCode($sType, $aParams, $bWrap);
  88. }
  89. protected function getUnit($aData, $aParams = array())
  90. {
  91. $CNF = &$this->getModule()->_oConfig->CNF;
  92. $iProfileId = $aData[$CNF['FIELD_AUTHOR']];
  93. $sCode = $aData[$CNF['FIELD_CODE']];
  94. $sClass = $this->_getUnitClass($aData,(isset($aParams['template_name']) ? $aParams['template_name'] : ''));
  95. return array_merge(parent::getUnit($aData, $aParams), array(
  96. 'js_object' => $this->_oConfig->getJsObjectShop($iProfileId),
  97. 'js_content' => $this->_oModule->serviceIncludeCode($iProfileId),
  98. 'class' => (!empty($sClass) ? $sClass . ' ' : '') . $this->_oConfig->getHtmlIds('unit') . $sCode,
  99. 'entry_code' => $sCode
  100. ));
  101. }
  102. }
  103. /** @} */