0

I below mention Quick view controllers. I don't know how to set redirection.

Can anyone please tell me how to set redirect after Add to cart?

public function viewAction()
{
    $html = $this->_loadCache();
    if ($html === false) {
        // Get initial data from request
        $categoryId = (int) $this->getRequest()->getParam('category', false);
        $productId  = (int) $this->getRequest()->getParam('id');

        $path  = (string) $this->getRequest()->getParam('path');
        $path   =   str_replace("_!_","/",$path);
        $path[0] == "\/" ? $path = substr($path, 1, strlen($path)) : $path;     
        $tableName = Mage::getSingleton('core/resource')->getTableName('core_url_rewrite'); 
        $write = Mage::getSingleton('core/resource')->getConnection('core_write');

        $query = "select MAIN_TABLE.`product_id` from `{$tableName}` as MAIN_TABLE where MAIN_TABLE.`request_path` in('{$path}')";
        $readresult=$write->query($query);
        if ($row = $readresult->fetch() ) {
            $productId=$row['product_id'];
        }       
        $this->_cacheTags[] = Mage_Catalog_Model_Product::CACHE_TAG.'_'.$productId;
        //print_r($this->getCacheTags());
        $specifyOptions = $this->getRequest()->getParam('options');

        // Prepare helper and params
        $viewHelper = Mage::helper('quickshop/product_view');


        $params = new Varien_Object();
        $params->setCategoryId($categoryId);
        $params->setSpecifyOptions($specifyOptions);

        // Render page
        try {
            $viewHelper->prepareAndRender($productId, $this, $params);
            $html = $this->getLayout()->getBlock('root')->toHtml();
            $this->_saveCache($html);
            $this->getResponse()->setBody($html);
        } catch (Exception $e) {
            if ($e->getCode() == $viewHelper->ERR_NO_PRODUCT_LOADED) {
                if (isset($_GET['store'])  && !$this->getResponse()->isRedirect()) {
                    $this->_redirect('');
                } elseif (!$this->getResponse()->isRedirect()) {
                    $this->_forward('noRoute');
                }
            } else {
                Mage::logException($e);
                $this->_forward('noRoute');
            }
        }
    } else {
        $this->_redirect('');
        $this->getResponse()->setBody($html);
    }
}

My js file

jQuery.noConflict();
qs=null;
jQuery(function ($) {
    var isMobile = /iPhone|iPod|iPad|Phone|Mobile|Android|hpwos/i.test(navigator.userAgent);
    //get IE version
    function ieVersion() {
        var rv = -1; // Return value assumes failure.
        if (navigator.appName == 'Microsoft Internet Explorer') {
            var ua = navigator.userAgent;
            var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
            if (re.exec(ua) != null) rv = parseFloat(RegExp.$1);
        }
        return rv;
    }

    //read href attr in a tag

    function readHref() {
        var result = arguments[0].replace(EM.QuickShop.BASE_URL, '');
        var patn = /catalog\/product\/view\/id\/(.*?)\//i;
        if (patn.test(result)) {
        var s = patn.exec(result);
        result = 'catalog/product/view/id/' +  s[1];
        } else {
        result = result.replace(/\//gi,"_!_");
        }
        return result;
    }

    //string trim
    function strTrim() {
        return arguments[0].replace(/^\s+|\s+$/g, "");
    }

    // quickshop init
    function _qsJnit() {
        var selectorObj = arguments[0];
        var listprod = $(selectorObj.itemClass);    // selector chon tat ca cac li chua san pham tren luoi
        var mypath = 'quickshop/index/view/path/';
        var baseUrl = EM.QuickShop.BASE_URL + mypath;

        var _qsHref = "<a id=\"em_quickshop_handler\"  title=\""+EM.QuickShop.QS_TEXT+"\" href=\"#\" style=\"visibility:hidden;position:absolute;top:0;left:0\"><span><span>"+EM.QuickShop.QS_TEXT+"</span></span></a>";
        $(document.body).append(_qsHref);
        var qsHandlerImg = $('#em_quickshop_handler img');

        $.each(listprod, function (index, value) {
            if(($(value).parents(".no_quickshop").length <= 0)&&(isMobile==false)){
                var reloadurl = baseUrl;

                //get reload url
                var prodLinkTag = $(value).find(selectorObj.aClass);
                if (!prodLinkTag || prodLinkTag.length == 0) return;
                var prodHref = readHref(prodLinkTag.attr('href'));
                reloadurl = baseUrl + prodHref;

                if($(value).parents('.top-quickshop').length>0)
                // show quickshop handle when hover product image
                {
                    $(selectorObj.imgClass, this).bind('mouseover', function () {
                        var o = $(this).offset();               
                        $('#em_quickshop_handler').attr('href', reloadurl).show().css({
                                'top': o.top+($(this).height() - EM.QuickShop.QS_BTN_HEIGHT - 80)/2+'px',
                                'left': o.left+($(this).width() - EM.QuickShop.QS_BTN_WIDTH)/2+2+'px',
                                'visibility': 'visible',
                                'z-index':  999
                        });
                    });
                }
                else{
                    $(selectorObj.imgClass, this).bind('mouseover', function () {
                        var o = $(this).offset();
                        $('#em_quickshop_handler').attr('href', reloadurl).show().css({
                                'top': o.top+($(this).height() - EM.QuickShop.QS_BTN_HEIGHT)/2+'px',
                                'left': o.left+($(this).width() - EM.QuickShop.QS_BTN_WIDTH)/2+2+'px',
                                'visibility': 'visible',
                                'z-index':  999
                        });
                    }); 
                }
                $(value).bind('mouseout', function () {
                    $('#em_quickshop_handler').hide();
                });
            }
        });

        //fix bug image disapper when hover
        $('#em_quickshop_handler').bind('mouseover', function () {
            $(this).show();
        }).bind('click', function () {
            $(this).hide();
        });

        //insert quickshop popup
        $('#em_quickshop_handler').fancybox({
            'width': EM.QuickShop.QS_FRM_WIDTH,
            'height': EM.QuickShop.QS_FRM_HEIGHT,
            'autoScale': false,
            'padding': 20,
            'margin': 20,
            //'transitionIn'        : 'none',
            //'transitionOut'       : 'none',
            'type': 'iframe',
            onComplete: function () {
                $.fancybox.showActivity();
                $('#fancybox-frame').unbind('load');
                $('#fancybox-frame').bind('load', function () {
                    $.fancybox.hideActivity();
                });
            }
        });
    }

    if (typeof EM_QUICKSHOP_DISABLED == 'undefined' || !EM_QUICKSHOP_DISABLED)
        _qsJnit({
            itemClass: '.products-grid li.item, .products-list li.item, li.item .cate_product, .product-upsell-slideshow li.item, .mini-products-list li.item, #crosssell-products-list li.item', //selector for each items in catalog product list,use to insert quickshop image
            aClass: 'a.product-image', //selector for each a tag in product items,give us href for one product
            imgClass: '.product-image img' //class for quickshop href
        });
        qs = _qsJnit;
});
2
  • Could you reduce the code to the part/method that is actually relevant?
    – 7ochem
    Commented Sep 23, 2015 at 8:01
  • check my update question\
    – user31402
    Commented Sep 23, 2015 at 8:03

1 Answer 1

0

below code will redirect to cart page.

$this->_redirect('checkout/cart');
14
  • How to add in this quick view controller & where to add
    – user31402
    Commented Sep 23, 2015 at 6:45
  • $this->getResponse()->setBody($html); before this if you want to redirect but i think this code for ajax Commented Sep 23, 2015 at 6:51
  • redirect to same page ??
    – user31402
    Commented Sep 23, 2015 at 6:58
  • add on first line of function viewAction and check it Commented Sep 23, 2015 at 7:05
  • No it's not working
    – user31402
    Commented Sep 23, 2015 at 7:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.