Prestashop AJAX Call Module

10,262

1) first of all check for exists quicklook-ajax.php file.

2) check possibility of get access via url: {$base_dir}modules/quicklook/quicklook-ajax.php or you also get 404 error.

3) the best way is create your own controller for this purpose (how to do that: http://blog.belvg.com/how-to-implement-a-controller.html) and uses Link::getModuleLink() for getting url.

Regards

Share:
10,262

Related videos on Youtube

Admin
Author by

Admin

Updated on July 04, 2022

Comments

  • Admin
    Admin almost 2 years

    So I can't quite get this prestashop module working for a quick look I am trying to add on click for each product.

    I have the module in the base directory under /modules/quicklook.

    The files are as follows

    /modules/quicklook.php

    class QuickLook extends Module {
    
    private $_html= '';
    
    function __construct() {
        $this->name = 'quicklook';
        $this->tab = 'other';
        $this->version = '0.2.0';
        $this->author = 'Carl';
        parent::__construct();
        $this->displayName = $this->l('Quick Look');
        $this->description = $this->l('AJAX Quick Look');
    }
    
    public function install() {
        parent::install();
        if(!$this->registerHook('header')) return false;
        return true;
    }
    
    public function getContent()
                            {
                                    $this->_displayForm();
                                    return $this->_html;
                            }
    
    
    
    public function ajaxCall() {
    
                    $this->smartyOutputContent($this->getTemplatePath() . 'quicklook.tpl');
            }
    
    } 
    

    /modules/quicklook.tpl

    Includes everything from product.tpl.

    /modules/quicklook-ajax.tpl includes:

    include(dirname(__FILE__).'/../../config/config.inc.php');
    include(dirname(__FILE__).'/../../init.php');
    include(dirname(__FILE__).'/quicklook.php');
    
    $quicklook = new QuickLook();
    echo $quicklook->ajaxCall();
    

    Then to call the module I added this in product-list.tpl:

    <script type="text/javascript">
    function QuickLook() {
            $.ajax({
                                            url: '{$base_dir}modules/quicklook/quicklook-ajax.php',
                                            type: 'get',
                                            data: 'ajax=true',
                                            success: function(data) {
                                                    console.log('success');
                                                    $('#ajax').text(data);
                                            }
                                    });
        return false;
        }
    </script>
    

    Then to the link for each product I add

    onclick="QuickLook();"
    

    I'm getting

    Failed to load resource: the server responded with a status of 404 (Not Found) 
    

    For undefined.. And the product isn't loading.

    So basically I'm trying to have the a href link for each product execute the javascript which calls the ajax bridge file which then calls quicklook.php which then calls quicklook.tpl which shows the product, hopefully my train of thought is right (this is my first attempt at a module!).

    Would really appreciate some guidance in the right direction. At this point I'm not sure what is going wrong. :(