BxShopifyTemplate.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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/v0/latest/shopify-buy.umd.polyfilled.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. 'sAPIKey' => $aSettings['api_key'],
  41. 'sDomain' => $aSettings['domain'],
  42. 'sAppId' => $aSettings['app_id'],
  43. ));
  44. $this->addJsTranslation(array(
  45. '_bx_shopify_err_load_product',
  46. '_bx_shopify_err_load_collection'
  47. ));
  48. return bx_replace_markers($sCode, array(
  49. 'profile_id' => $iProfileId
  50. ));
  51. }
  52. public function entryBuy($aData)
  53. {
  54. return $this->parseHtmlByName('entry-buy.html', array(
  55. 'html_id' => $this->_oConfig->getHtmlIds('entry_buy')
  56. ));
  57. }
  58. public function entryText ($aData, $sTemplateName = 'entry-text.html')
  59. {
  60. $CNF = &$this->getModule()->_oConfig->CNF;
  61. return $this->parseHtmlByName($sTemplateName, array(
  62. 'js_object' => $this->_oConfig->getJsObjectShop($aData[$CNF['FIELD_AUTHOR']]),
  63. 'html_id' => $this->_oConfig->getHtmlIds('entry_content'),
  64. 'entry_title' => $this->getTitle($aData),
  65. 'entry_code' => $aData[$CNF['FIELD_CODE']]
  66. ));
  67. }
  68. public function entryAttachments ($aData, $aParams = array())
  69. {
  70. $sPopupId = 'bx-messages-atachment-popup-{id}';
  71. return $this->parseHtmlByName('attachments.html', array(
  72. 'html_id' => $this->_oConfig->getHtmlIds('entry_attachments'),
  73. 'html_id_sample' => $this->_oConfig->getHtmlIds('entry_attachment_sample'),
  74. 'popup_id' => $sPopupId,
  75. 'popup' => BxTemplFunctions::getInstance()->transBox($sPopupId, '<img class="bx-spf-attachment-popup-img" src="" />', true, true),
  76. ));
  77. }
  78. public function getJsCode($sType, $aParams = array(), $bWrap = true)
  79. {
  80. $aParams = array_merge(array(
  81. 'aHtmlIds' => $this->_oConfig->getHtmlIds()
  82. ), $aParams);
  83. return parent::getJsCode($sType, $aParams, $bWrap);
  84. }
  85. protected function getUnit($aData, $aParams = array())
  86. {
  87. $CNF = &$this->getModule()->_oConfig->CNF;
  88. $iProfileId = $aData[$CNF['FIELD_AUTHOR']];
  89. $sCode = $aData[$CNF['FIELD_CODE']];
  90. $sClass = $this->_getUnitClass($aData,(isset($aParams['template_name']) ? $aParams['template_name'] : ''));
  91. return array_merge(parent::getUnit($aData, $aParams), array(
  92. 'js_object' => $this->_oConfig->getJsObjectShop($iProfileId),
  93. 'js_content' => $this->_oModule->serviceIncludeCode($iProfileId),
  94. 'class' => $this->_oConfig->getHtmlIds('unit') . $sClass,
  95. 'entry_code' => $sCode,
  96. ));
  97. }
  98. }
  99. /** @} */