cart.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * Copyright (c) UNA, Inc - https://una.io
  3. * MIT License - https://opensource.org/licenses/MIT
  4. *
  5. * @defgroup Payment Payment
  6. * @ingroup UnaModules
  7. *
  8. * @{
  9. */
  10. function BxPaymentCart(oOptions) {
  11. this.init(oOptions);
  12. }
  13. BxPaymentCart.prototype = new BxPaymentMain();
  14. BxPaymentCart.prototype.init = function(oOptions) {
  15. if($.isEmptyObject(oOptions))
  16. return;
  17. this._sActionsUrl = oOptions.sActionUrl;
  18. this._sObjName = oOptions.sObjName == undefined ? 'oPmtCart' : oOptions.sObjName;
  19. this._sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'fade' : oOptions.sAnimationEffect;
  20. this._iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
  21. };
  22. BxPaymentCart.prototype.addToCart = function(iSellerId, iModuleId, iItemId, iItemCount, iRedirect, sCustom) {
  23. var $this = this;
  24. var oDate = new Date();
  25. var sRedirect = '';
  26. if(typeof iRedirect == 'number' && parseInt(iRedirect) > 0)
  27. sRedirect = sUrlRoot + 'cart.php?seller_id=' + iSellerId;
  28. else if(typeof iRedirect == 'string' && iRedirect.length > 0)
  29. sRedirect = iRedirect;
  30. $.post(
  31. this._sActionsUrl + 'add_to_cart/' + iSellerId + '/' + iModuleId + '/' + iItemId + '/' + iItemCount + '/',
  32. {
  33. custom: sCustom ? sCustom : '',
  34. _t: oDate.getTime()
  35. },
  36. function(oData) {
  37. if(oData && oData.code == 0 && sRedirect) {
  38. oData.message = '';
  39. oData.redirect = sRedirect;
  40. }
  41. processJsonData(oData);
  42. },
  43. 'json'
  44. );
  45. };
  46. BxPaymentCart.prototype.onCartContinue = function(oData) {
  47. if (!oData || oData.link == undefined)
  48. return;
  49. location.href = oData.link;
  50. };
  51. BxPaymentCart.prototype.onCartCheckout = function(oData) {
  52. if (!oData || oData.link == undefined)
  53. return;
  54. location.href = oData.link;
  55. };
  56. BxPaymentCart.prototype.subscribe = function(oLink, iSellerId, sSellerProvider, iModuleId, iItemId, iItemCount, sRedirect, sCustom) {
  57. this.subscribeWithAddons(oLink, iSellerId, sSellerProvider, iModuleId, iItemId, iItemCount, '', sRedirect, sCustom);
  58. };
  59. BxPaymentCart.prototype.subscribeWithAddons = function(oLink, iSellerId, sSellerProvider, iModuleId, iItemId, iItemCount, sItemAddons, sRedirect, sCustom) {
  60. var $this = this;
  61. var oDate = new Date();
  62. var oParams = {
  63. seller_id: iSellerId,
  64. seller_provider: sSellerProvider,
  65. module_id: iModuleId,
  66. item_id: iItemId,
  67. item_count: 1,
  68. item_addons: sItemAddons,
  69. redirect: sRedirect ? sRedirect : '',
  70. custom: sCustom ? sCustom : '',
  71. _t: oDate.getTime()
  72. };
  73. if(iItemCount != undefined && iItemCount.length > 0)
  74. oParams.item_count = parseInt(iItemCount);
  75. var oLoading = $(oLink).hasClass('bx-btn') ? oLink : null;
  76. this.loadingInButton(oLoading, true);
  77. $.post(
  78. this._sActionsUrl + 'subscribe_json/',
  79. oParams,
  80. function(oData){
  81. $this.loadingInButton(oLoading, false);
  82. processJsonData(oData);
  83. },
  84. 'json'
  85. );
  86. };
  87. BxPaymentCart.prototype.onSubscribeSubmit = function(oData) {
  88. document.location = oData.redirect;
  89. };
  90. /** @} */