Mobile Opencart Rest API生成

Mobile Opencart Rest API生成,mobile,opencart,Mobile,Opencart,我试图生成我所有类别、产品和所有其他产品的RESTAPI,以将其用于我的移动应用程序,但我无法获得任何解决方案。在opencart 3.0.2.0中,有人能告诉我这一点吗?否则,如果opencart不能提供此解决方案,那么请给我其他框架,我可以通过它轻松为数据创建API?这对我来说是可行的 我在OpenCart api文件夹中创建了一个自定义控制器 <?php class ControllerApiAllproducts extends Controller { private $

我试图生成我所有类别、产品和所有其他产品的RESTAPI,以将其用于我的移动应用程序,但我无法获得任何解决方案。在opencart 3.0.2.0中,有人能告诉我这一点吗?否则,如果opencart不能提供此解决方案,那么请给我其他框架,我可以通过它轻松为数据创建API?

这对我来说是可行的

我在OpenCart api文件夹中创建了一个自定义控制器

<?php
class ControllerApiAllproducts extends Controller {
    private $error = array();

   public function index()
   {
        $products = array();
        $this->load->language('catalog/product');
        $this->load->model('catalog/product');
        $this->load->model('api/product');
        $this->load->model('tool/image');

        $error[]['no_json']= "No JSON";

        // preg_match("/[^\/]+$/", $_SERVER['REQUEST_URI'], $matches);
       //    $last_word = $matches[0];
        $product_total = $this->model_catalog_product->getTotalProducts();

        $results = $this->model_catalog_product->getProducts();

        foreach ($results as $result) {
            if (is_file(DIR_IMAGE . $result['image'])) {
                $image = $this->model_tool_image->resize($result['image'], 40, 40);
            } else {
                $image = $this->model_tool_image->resize('no_image.png', 40, 40);
            }

            $special = false;

            $product_specials = $this->model_api_product->getProductSpecials($result['product_id']);

            foreach ($product_specials  as $product_special) {
                if (($product_special['date_start'] == '0000-00-00' || strtotime($product_special['date_start']) < time()) && ($product_special['date_end'] == '0000-00-00' || strtotime($product_special['date_end']) > time())) {
                    $special = $product_special['price'];

                    break;
                }
            }

            $shop_products['shop_products'][] = array(
                'product_id' => $result['product_id'],
                'image'      => $image,
                'name'       => $result['name'],
                'model'      => $result['model'],
                'price'      => $result['price'],
                'special'    => $special,
                'quantity'   => $result['quantity'],
                'status'     => $result['status']
            );
        }


        if (isset($this->request->get['json'])) {
            echo json_encode($shop_products);
            die;
        } else {
            $this->response->setOutput(json_encode($error));
        }  
   }

   public function product()
   {

    $this->load->language('catalog/product');
    $this->load->model('catalog/product');
    $this->load->model('api/product');
    $this->load->model('tool/image');

     $product_details = array();
     $error['fail'] = 'Failed';
    if (isset($this->request->get['product_id'])) {
         //$product_details['product_id'] = $this->request->get['product_id'];
         $product_details = $this->model_catalog_product->getProduct($this->request->get['product_id']);

            echo json_encode($product_details);
            die;
        } else {
            $this->response->setOutput(json_encode($error));
        }
   }

   public function categories()
   { 
      $shop_categories = array();
      $this->load->model('catalog/category');


       $error['fail'] = 'Failed';
    if (isset($this->request->get['json'])) {
         $shop_categories =$this->model_catalog_category->getCategories();
            echo json_encode($shop_categories);
            die;
        } else {
            $this->response->setOutput(json_encode($error));
        }
   }
}

有谁能指导我如何开始与Opencart与自定义系统的集成?给出错误通知:未定义索引:第8行的api_token in/opt/lampp/htdocs/Opencart/upload/catalog/controller/startup/session.php有任何解决方案吗?@NeerajPrajapati请确保您在提出请求时提供了
api_token
参数。谢谢@这对我很有帮助。现在我正在使用“API_令牌”的管理实例中的“API密钥”,请确认它是否正确,或者是否需要更改?是否有其他API的参考,如用户登录、优惠券、购物车等?不工作仅类别工作