Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Controller
- ------------------->
- try {
- // See whether this product can be shown on PDP
- ProductHelper.canDisplayProductPDP(httpParameterMap, productModel);
- } catch (e) {
- // If redirectUrl is set by canDisplayProductPDP()
- if (!empty(ProductHelper.getRedirectUrl())) {
- response.redirect(ProductHelper.getRedirectUrl());
- return;
- }
- // In case a pipeline is called by canDisplayProductPDP() and it renders a template or redirects execution to
- // another pipeline that will render a template then just return
- if (ProductHelper.getIsRenderedByPipeline()) {
- return;
- }
- // Throw and error because something unhandled happened
- throw e;
- }
- ---------------->
- Helper
- ---------------->
- ProductHelper.canDisplayProductPDP = function (httpParameterMap, productModel) {
- if (!SitePreference.get('v3_pdp_redesign_enabled')) {
- this.callBundlesQuickviewHook();
- }
- // Please note that handleOfflineProduct and handlePDPForbiddenProduct methods cover the ProductHelper-CheckGWP pipeline functionality
- this.handleOfflineProduct(productModel);
- this.handlePDPForbiddenProduct(httpParameterMap, productModel);
- this.handlePermanentOutOfStockProduct(productModel);
- this.handleOfflineProductSet(productModel);
- };
- ProductHelper.handleOfflineProduct = function(productModel) {
- if (!productModel.exec('isOnline')) {
- this.redirectUrl = URLUtils.url('Home-Show');
- var catalogCategory = productModel.exec('getDerivedOnlineCategoryId');
- if (!empty(catalogCategory)) {
- this.redirectUrl = URLUtils.url('Search-Show', 'cgid', catalogCategory);
- }
- throw new Exception('Offline product redirect to URL ' + this.redirectUrl, true , '', Exception.ERROR_CODE_OFFLINE_PRODUCT_REDIRECT, false);
- }
- };
- ProductHelper.handlePDPForbiddenProduct = function(httpParameterMap, productModel) {
- var isSourceBundle = (httpParameterMap.isParameterSubmitted('source') && httpParameterMap.source.stringValue === 'bundle');
- var isAjax = (httpParameterMap.isParameterSubmitted('format') && httpParameterMap.format.stringValue === 'ajax');
- var isQuickViewAndTrial = isSourceBundle && isAjax && productModel.exec('isTrial');
- var dontShowBundlePage = (!SitePreference.get('v3_pdp_bundle_page_enabled') && productModel.exec('isBundle')) || productModel.exec('isSamplesRoutineBundle');
- var incompatible = productModel.exec('isSample') || productModel.exec('isTrial')
- || productModel.exec('getCustom', 'isFree') || productModel.exec('isGiftWrap')
- || productModel.exec('isHidden') || dontShowBundlePage || isQuickViewAndTrial;
- if (incompatible) {
- this.redirectUrl = URLUtils.url('Error-Start');
- throw new Exception("PDP not available for this product id " + productModel.exec('getId'), true, '', Exception.ERROR_PRODUCT_SHOW_NOT_AVAILABLE, false);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement