如何使用ajax与prestashop数据交互?

时间:2016-05-20 12:31:48

标签: ajax prestashop prestashop-1.6

我有一个prestashop商店,我希望在商店中添加一些交互性,但为此我需要从数据库中获取有关产品的一些数据。我试图搜索prestashop文档,但没有找到任何有用的东西。

如何使用ajax与prestashop的产品数据进行交互?

2 个答案:

答案 0 :(得分:0)

你可以在你想要的地方创建一个php文件(根文件夹没问题)并启动"环境"像这样

require_once(dirname(__FILE__).'../../../config/config.inc.php');
require_once(dirname(__FILE__).'../../../init.php');

echo("<br />a log string " . date("H:i:s d/m/Y"));

error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT);

// here you have all prestashop class
$myCategory = new Category($id)
之后你会在你的ajax电话中找到你的php

答案 1 :(得分:0)

1-转到:https://validator.prestashop.com/auth/login

2-创建一个通用模块(更快)

3-创建文件夹控制器/ front / ajaxmain.php(示例)

添加:

    <?php

        class YOURMODULENAMEAjaxmainModuleFrontController extends ModuleFrontController
        {


            public function __construct()
            {
                parent::__construct();

                $this->context = Context::getContext();
            }

            public function initContent()
            {
                parent::initContent();

                if (Tools::isSubmit('anysubmitname'))
                {
                        $this->getproduct();
                }

               //or Tools::getvalue("anyvalue")....

            }
     private function getproduct(){

// do your magic

            die(json_encode(array(
                "response"=> "response"
            ) ));
        }

然后,调用它 - &gt;的index.php FC =模块&安培;模块=试验&安培;控制器= ajaxmain

我认为这更干净,然后你可以用这个

获得更多东西