Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. Controller
  2. ------------------->
  3. try {
  4. // See whether this product can be shown on PDP
  5. ProductHelper.canDisplayProductPDP(httpParameterMap, productModel);
  6. } catch (e) {
  7. // If redirectUrl is set by canDisplayProductPDP()
  8. if (!empty(ProductHelper.getRedirectUrl())) {
  9. response.redirect(ProductHelper.getRedirectUrl());
  10. return;
  11. }
  12.  
  13. // In case a pipeline is called by canDisplayProductPDP() and it renders a template or redirects execution to
  14. // another pipeline that will render a template then just return
  15. if (ProductHelper.getIsRenderedByPipeline()) {
  16. return;
  17. }
  18.  
  19. // Throw and error because something unhandled happened
  20. throw e;
  21. }
  22. ---------------->
  23.  
  24. Helper
  25. ---------------->
  26. ProductHelper.canDisplayProductPDP = function (httpParameterMap, productModel) {
  27. if (!SitePreference.get('v3_pdp_redesign_enabled')) {
  28. this.callBundlesQuickviewHook();
  29. }
  30. // Please note that handleOfflineProduct and handlePDPForbiddenProduct methods cover the ProductHelper-CheckGWP pipeline functionality
  31. this.handleOfflineProduct(productModel);
  32. this.handlePDPForbiddenProduct(httpParameterMap, productModel);
  33. this.handlePermanentOutOfStockProduct(productModel);
  34. this.handleOfflineProductSet(productModel);
  35. };
  36.  
  37. ProductHelper.handleOfflineProduct = function(productModel) {
  38. if (!productModel.exec('isOnline')) {
  39. this.redirectUrl = URLUtils.url('Home-Show');
  40.  
  41. var catalogCategory = productModel.exec('getDerivedOnlineCategoryId');
  42. if (!empty(catalogCategory)) {
  43. this.redirectUrl = URLUtils.url('Search-Show', 'cgid', catalogCategory);
  44. }
  45.  
  46. throw new Exception('Offline product redirect to URL ' + this.redirectUrl, true , '', Exception.ERROR_CODE_OFFLINE_PRODUCT_REDIRECT, false);
  47. }
  48. };
  49.  
  50. ProductHelper.handlePDPForbiddenProduct = function(httpParameterMap, productModel) {
  51. var isSourceBundle = (httpParameterMap.isParameterSubmitted('source') && httpParameterMap.source.stringValue === 'bundle');
  52. var isAjax = (httpParameterMap.isParameterSubmitted('format') && httpParameterMap.format.stringValue === 'ajax');
  53. var isQuickViewAndTrial = isSourceBundle && isAjax && productModel.exec('isTrial');
  54.  
  55. var dontShowBundlePage = (!SitePreference.get('v3_pdp_bundle_page_enabled') && productModel.exec('isBundle')) || productModel.exec('isSamplesRoutineBundle');
  56.  
  57. var incompatible = productModel.exec('isSample') || productModel.exec('isTrial')
  58. || productModel.exec('getCustom', 'isFree') || productModel.exec('isGiftWrap')
  59. || productModel.exec('isHidden') || dontShowBundlePage || isQuickViewAndTrial;
  60.  
  61. if (incompatible) {
  62. this.redirectUrl = URLUtils.url('Error-Start');
  63. throw new Exception("PDP not available for this product id " + productModel.exec('getId'), true, '', Exception.ERROR_PRODUCT_SHOW_NOT_AVAILABLE, false);
  64. }
  65. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement