Adding a new table to rest api preashop webservice

I managed to create an additional table in the prestashop product table via the rest api webservice , however the api link http://127.0.0.1/prestashop/api/wb3d/1 wb3d is the new table I created in webservice. Which contains the path to a catalog of images somewhere on the Internet. This link, when opened, shows the data that was saved in the database, as shown in the following figure below

enter image description heremodel is the name of a directory on the Internet, so this api (wb3d) was associated with the product table in the web service : http://127.0.0.1/prestashop/api/products/1 when I open this link. Association record is shown, but data is not displayed ** see below image **        enter image description here

The highlighted area shows the wb3d table associated with the product table through the api webservice point. I cannot associate wb3d history data with product table data. Therefore, 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 the associated table in the 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);

 }

}
?>

product.php, webserviceparameters(),

    <?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 - WebserviceRequest, -

, , . , , - (wb3d) webservice rest api call.

+2
1

webservice , , category.php, preashash/classes.

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

, getter, getChildrenWs, category.php, .

: Product.php

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

" yourMethodName" Product.php

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

All Articles