第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Opencart 的 REST API 生成

Opencart 的 REST API 生成

PHP
幕布斯7119047 2022-07-22 16:04:47
我試圖為我的客戶、類別、產(chǎn)品、優(yōu)惠券、制造商和所有其他人生成一個(gè) REST API,以便在我的 Android 應(yīng)用程序中使用它,但我無(wú)法獲得任何解決方案。誰(shuí)能告訴我如何在 opencart 3.0.2.0 中創(chuàng)建 API?
查看完整描述

1 回答

?
瀟瀟雨雨

TA貢獻(xiàn)1833條經(jīng)驗(yàn) 獲得超4個(gè)贊

在目錄 > 控制器 > api文件夾中制作自定義控制器


創(chuàng)建控制器文件名:allproducts.php


您可以復(fù)制以下代碼并粘貼allproducts.php


<?php

class ControllerApiAllproducts extends Controller {

    private $error = array();


    // All Products

    public function index(){

        $products = array();

        $this->load->language('catalog/product');

        $this->load->model('catalog/product');

        $this->load->model('tool/image');


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


        $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_catalog_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));

        }  

    }


    // Product info Page

    public function productInfo(){


        $this->load->language('catalog/product');

        $this->load->model('catalog/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));

        }

    }


    // Category Listing Page

    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));

        }

    }


    // Product Listing By Category

    public function categoryList(){ 


        $this->load->model('catalog/category');

        $this->load->model('catalog/product');

        $this->load->model('tool/image');

        $error['fail'] = 'Failed';


        if (isset($this->request->get['path'])) {

            $url = '';

            $path = '';

            $parts = explode('_', (string)$this->request->get['path']);


            $category_id = (int)array_pop($parts);


            foreach ($parts as $path_id) {

                if (!$path) {

                    $path = (int)$path_id;

                } else {

                    $path .= '_' . (int)$path_id;

                }


                $category_info = $this->model_catalog_category->getCategory($path_id);

            }

        } else {

            $category_id = 0;

        }


        $category_info = $this->model_catalog_category->getCategory($category_id);


        if ($category_info) {


            $url = '';

            //$data['categories'] = array();

            $results = $this->model_catalog_category->getCategories($category_id);


            foreach ($results as $result) {

                $filter_data = array(

                    'filter_category_id'  => $result['category_id'],

                    'filter_sub_category' => true

                );


            }


            $products = array();


            $filter_data = array(

                'filter_category_id' => $category_id

            );


            $product_total = $this->model_catalog_product->getTotalProducts($filter_data);

            $products = $this->model_catalog_product->getProducts($filter_data);

            echo json_encode($products); die;


        } else {

            $this->response->setOutput(json_encode($error));

        }


    }


    // All Manufacturers Listing

    public function manufactureList() {


        $this->load->model('catalog/manufacturer');

        $this->load->model('tool/image');

        $error['fail'] = 'Failed';


        $manufactureList = array();


        if (isset($this->request->get['json'])) {

            $manufactureList = $this->model_catalog_manufacturer->getManufacturers();

            echo json_encode($manufactureList);die;

        } else {

            $this->response->setOutput(json_encode($error));

        }

    }


    // Manufactur info Page

    public function manufactureInfo() {


        $this->load->model('catalog/manufacturer');

        $this->load->model('catalog/product');

        $this->load->model('tool/image');

        $error['fail'] = 'Failed';


        if (isset($this->request->get['manufacturer_id'])) {

            $manufactureInfo = $this->model_catalog_manufacturer->getManufacturer($manufacturer_id);

            echo json_encode($product_details);die;

        } else {

            $this->response->setOutput(json_encode($error));

        }

    }



    // Category Listing Page

    public function specialProduct(){ 


        $specialProduct = array();

        $this->load->model('catalog/product');

        $this->load->model('tool/image');

        $error['fail'] = 'Failed';


        if (isset($this->request->get['json'])) {

            $specialProduct = $this->model_catalog_product->getProductSpecials();

            echo json_encode($specialProduct);die;

        } else {

            $this->response->setOutput(json_encode($error));

        }

    }

}

我制作了以下 API 及其路徑(請(qǐng)參閱 Postman 應(yīng)用程序):

  1. 所有產(chǎn)品:http ://examples.com/index.php?route=api/allproducts&json

  2. 產(chǎn)品編號(hào):http ://examples.com/index.php?route=api/allproducts/productInfo&json&product_id=30

  3. 所有類別:http ://examples.com/index.php?route=api/allproducts/categories&json

  4. 分類明智的產(chǎn)品:http ://examples.com/index.php?route=api/allproducts/categoryList&json&path=25_28

  5. 所有制造商:http ://examples.com/index.php?route=api/allproducts/manufactureList&json

  6. 制造商 ID:http ://examples.com/index.php?route=api/allproducts/manufactureInfo&manufacturer_id=11

  7. 特殊產(chǎn)品:http ://examples.com/index.php?route=api/allproducts/specialProduct&json


查看完整回答
反對(duì) 回復(fù) 2022-07-22
  • 1 回答
  • 0 關(guān)注
  • 193 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)