1

I'm using commercial modules AJAX Cart Pro by aheadWorks and Quick View Pro by BelVG but I'm having an issues getting the two to work together.

When the quick view modal opens up, clicking the add to cart button doesn't trigger the ajax. Instead, it submits the form normally and redirects the customer to the cart page.

How can I get the ajax cart to work in the quick view window?

closed as off-topic by Raphael at Digital Pianism, Fabian Schmengler, Qaisar Satti, Amit Bera, Rajeev K Tomy Apr 18 '16 at 9:15

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about third-party modules are generally off-topic because the scope of functionality and code are not available. For more information, see this meta post/answer." – Raphael at Digital Pianism, Fabian Schmengler, Qaisar Satti, Amit Bera, Rajeev K Tomy
If this question can be reworded to fit the rules in the help center, please edit the question.

3

Ajax Cart Pro uses their own version of javascript observers to detect events and fire their custom action instead. You can find these observers in js/aw_ajaxcartpro/observers/. Because your HTML is being loaded after page load, the observers aren't tracking the form submission.

This can most easily be solved by adding your own observer when the quick view window template is loaded. Copy base/default/template/belvg/quickviewpro/popup.phtml to your package/theme. You'll need to add your observer object to AW_AjaxCartPro by using AW_AjaxCartPro.registerObserver() (we can pretty much copy the observer in js/aw_ajaxcartpro/observers/clickOnAddToCartInProductPage.js).

Quickview uses a variable called q_productAddToCartForm which can be used in the observer method _getTargetObj(), and another variable quickview which can be used to close the modal once the form is submitted (after validation).

Long story short, add the following to your popup.phtml template:

<script type="text/javascript">
//<![CDATA[
var AW_AjaxCartProObserverObject = new AW_AjaxCartProObserver('clickOnAddToCartInQuickview');
Object.extend(AW_AjaxCartProObserverObject, {

    uiBlocks: ['progress', 'options', 'add_confirmation'],

    _oldSubmitFn: null,

    /**
     * This method will be called when the observer is registered.
     * Here's where we'll inject our submit instead
     */
    run: function() {
        var targetObj = this._getTargetObj();
        if (!targetObj) {
            return null;
        }
        // Save the old submit
        this._oldSubmitFn = targetObj.form.submit;
        // Do ours instead
        targetObj.form.submit = this._observeFn.bind(this);
        //HACK for EE
        targetObj.form.select('button').each(function(btn){
            btn.removeAttribute('disabled')
        });
        return null;
    },

    stop: function() {
        var targetObj = this._getTargetObj();
        if (!targetObj) {
            return;
        }
        targetObj.form.submit = this._oldSubmitFn;
    },

    fireOriginal: function(url, parameters) {
        var targetObj = this._getTargetObj();
        if (!targetObj) {
            return;
        }
        this.stop();
        targetObj.submit();
    },

    _observeFn: function() {
        var targetObj = this._getTargetObj();
        if (!targetObj) {
            return;
        }
        var action = targetObj.form.readAttribute('action') || '';
        var params = targetObj.form.serialize(true);
        quickview.close();
        this.fireCustom(action, params);
    },

    _getTargetObj: function() {
        return q_productAddToCartForm;
    }
});
AW_AjaxCartPro.registerObserver(AW_AjaxCartProObserverObject);
delete AW_AjaxCartProObserverObject;
// Restart observers
AW_AjaxCartPro.stopObservers();
AW_AjaxCartPro.startObservers();
//]]>
</script>

Or, Quick View Pro was kind enough to leave you a method if you wanted to include/extend it there instead

# js/belvg/quickviewpro/quickView.js
Quickview.prototype   = {
    [...]
    /* Your code after quickview display */
    showAfterYourCode: function(pro_id) {

    },
    [...]
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.