BxMarketMenuView.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 Market Market
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * View entry menu
  13. */
  14. class BxMarketMenuView extends BxBaseModTextMenuView
  15. {
  16. public function __construct($aObject, $oTemplate = false)
  17. {
  18. $this->MODULE = 'bx_market';
  19. parent::__construct($aObject, $oTemplate);
  20. }
  21. public function getCode ()
  22. {
  23. return parent::getCode() . BxDolPayments::getInstance()->getCartJs();
  24. }
  25. protected function _isVisible ($a)
  26. {
  27. $CNF = &$this->_oModule->_oConfig->CNF;
  28. if(!parent::_isVisible($a))
  29. return false;
  30. $oPayment = BxDolPayments::getInstance();
  31. $bResult = false;
  32. switch ($a['name']) {
  33. case 'download':
  34. if((int)$this->_aContentInfo[$CNF['FIELD_PACKAGE']] == 0)
  35. break;
  36. $bResult = true;
  37. break;
  38. case 'add-to-cart':
  39. if((float)$this->_aContentInfo[$CNF['FIELD_PRICE_SINGLE']] == 0)
  40. break;
  41. $aJs = $oPayment->getAddToCartJs($this->_aContentInfo['author'], $this->MODULE, $this->_aContentInfo['id'], 1, true);
  42. if(empty($aJs) || !is_array($aJs))
  43. break;
  44. list($sJsCode, $sJsMethod) = $aJs;
  45. $aCurrency = $this->_oModule->_oConfig->getCurrency();
  46. $bResult = true;
  47. $this->addMarkers(array(
  48. 'add_to_cart_title' => _t('_bx_market_menu_item_title_add_to_cart', $aCurrency['sign'], $this->_aContentInfo[$CNF['FIELD_PRICE_SINGLE']]),
  49. 'add_to_cart_onclick' => $sJsMethod
  50. ));
  51. break;
  52. case 'subscribe':
  53. if((float)$this->_aContentInfo[$CNF['FIELD_PRICE_RECURRING']] == 0)
  54. break;
  55. $aJs = $oPayment->getSubscribeJs($this->_aContentInfo['author'], '', $this->MODULE, $this->_aContentInfo['id'], 1);
  56. if(empty($aJs) || !is_array($aJs))
  57. break;
  58. list($sJsCode, $sJsMethod) = $aJs;
  59. $aCurrency = $this->_oModule->_oConfig->getCurrency();
  60. $bResult = true;
  61. $this->addMarkers(array(
  62. 'subscribe_title' => _t('_bx_market_menu_item_title_subscribe', $aCurrency['sign'], $this->_aContentInfo[$CNF['FIELD_PRICE_RECURRING']], _t('_bx_market_txt_per_' . $this->_aContentInfo[$CNF['FIELD_DURATION_RECURRING']])),
  63. 'subscribe_onclick' => $sJsMethod
  64. ));
  65. break;
  66. default:
  67. $bResult = true;
  68. }
  69. return $bResult;
  70. }
  71. }
  72. /** @} */