在prestashop webservice的rest api中添加新表 [英] Adding new table in rest api of prestashop webservice

查看:43
本文介绍了在prestashop webservice的rest api中添加新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功地通过 rest api of webserviceprestashop products 表中创建了一个额外的表,但是 api 链接 强> 当我打开此链接时.显示了关联的条目,但未显示数据**参考下图**

突出显示的区域显示了通过 webservice 的 rest api 与产品表关联的 wb3d 表.我无法将 wb3d 故事数据与产品表数据相关联.所以我可以通过webservice在其他设备上使用它

这是我迄今为止尝试过的

 'wb3d','主要' =>'id_wb3d','字段' =>大批('id_wb3d' =>array('type' => self::TYPE_INT, 'required' => true),'product_id' =>array('type' => self::TYPE_INT, 'required' => true),'目录名称' =>array('type' => self::TYPE_STRING, 'required' =>false, 'size' => 64),),);受保护的 $webserviceParameters = array();}?>

productmerge.php 负责在产品表中创建关联表条目.

 webserviceParameters['associations']['wb3d'] = array('resource' => 'wb3d','fields' => array('directory_name' => array('required' =>; 真的)));parent::__construct($id_product, $full, $id_lang, $id_shop, $context);}}?>

在这个 product.php 中,它用于覆盖 product 类,以便通过 webserviceparameters() 传递额外参数strong> 然后调用产品类

的父构造函数

  'images path', 'class' => 'ProductMerge');ksort($resources);返回 $resources;}}?>

WebserviceRequest.php 类是 WebserviceRequest 类的覆盖类,用于显示 Web 服务中表条目的描述

这些是完成工作所需的文件.我想要实现的是关联表 (wb3d) 数据应该通过 webservice rest api 调用在 products 表中可用.

解决方案

如果您想将其他 webservice 表作为关联添加到您的产品中,您可以在 category.php<中查看关联是如何完成的/strong> 位于 prestashop/classes.

'associations' =>大批('类别' =>数组('getter' => 'getChildrenWs', 'resource' => 'category', ))

如你所见,有一个名为 getter 的参数,它从getChildrenWs 这是 category.php 中的一个方法,用于从数据库中获取数据.

所以在你的情况下:在 Product.php

$this->webserviceParameters['associations']['wb3d'] = array('resource' => 'wb3d','吸气剂' =>'你的方法名','字段' =>array('directory_name' => array('required' => true));

并在 Product.php 中创建一个名为yourMethodName"的方法

公共函数 yourMethodName(){//复制Category.php中的getChildrenWs方法并将其更改为您的需要}

I've been successful in creating an extra table in the prestashop products table throught rest api of webservice , however the api link http://127.0.0.1/prestashop/api/wb3d/1 wb3d is the new table which I have created in webservice . Which holds a path to an images directory somewhere on the web . This link when opened shows the data which has been saved in the database as seen in the following image below

model is directory name on the web, so this api(wb3d) has been associated with the product table in the webservice the link:http://127.0.0.1/prestashop/api/products/1 when I open this link . The entry of the association is shown but the data is not shown **refer the below image **

The highlighted area shows the wb3d table associated with the product table throught rest api of webservice . I'm unable to associate the wb3d tale data with product table data. So I can use it in other devices through webservice

This is what I have tried so far

    <?php
class ProductMergeCore extends ObjectModel

{  
    public $product_id;
    public $id_wb3d;
    public $directory_name;
    public static $definition = array(
    'table' => 'wb3d',
    'primary' => 'id_wb3d',
    'fields' => array(
    'id_wb3d' => array('type' => self::TYPE_INT,  'required' => true),
    'product_id' => array('type' => self::TYPE_INT, 'required' => true),
    'directory_name' => array('type' => self::TYPE_STRING,  'required' =>false, 'size' => 64),
     ),
     );
    protected $webserviceParameters = array();
    }
    ?>

productmerge.php is responsible for creating an associate table entry in product table.

 <?php 

  Class Product extends ProductCore

  {

   public $extrafield;



public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)

 {


    $this->webserviceParameters['associations']['wb3d'] = array('resource'    => 'wb3d','fields' => array('directory_name' => array('required' => true)));

    parent::__construct($id_product, $full, $id_lang, $id_shop, $context);

 }

}
?>

In this product.php which is for overriding the product class for passing the extra parameters through webserviceparameters() and then calling the parent constructor of the product class

    <?php
    class WebserviceRequest extends WebserviceRequestCore
    {
    public static function getResources()
    {
    $resources=parent::getResources();
    $resources['wb3d'] = array('description' => 'images path', 'class' =>   'ProductMerge');
    ksort($resources);
    return $resources;
    }
    }
    ?>

WebserviceRequest.php class is a override class for the WebserviceRequest class which shows the description of the table entry in the webservice

These are the files which are required to get the things done. What I'm trying to achieve is the associated table (wb3d) data should be available within the products table through webservice rest api call.

解决方案

if u want to add other webservice table as your association to your product , you can take a look at how associations is done in category.php located in prestashop/classes.

'associations' => array(
     'categories' => array('getter' => 'getChildrenWs', 'resource' => 'category', )         
)

as you can see there is a parameter named getter which gets the value from getChildrenWs which is a method in category.php which fetches the data from database.

so in your case: in Product.php

$this->webserviceParameters['associations']['wb3d'] = array('resource' => 'wb3d',
                                                            'getter' => 'yourMethodName',
                                                            'fields' => array('directory_name' => array('required' => true));

and create a method named 'yourMethodName' in Product.php

public function yourMethodName()
{
  //copy the getChildrenWs method which is in Category.php  and alter it to ur needs
}

这篇关于在prestashop webservice的rest api中添加新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆