Good morning, I am developing a module that will make use of the webservices functionality of Prestashop 1.6.
In my case I try to send data from one store to another with a custom web service, that is, I have created a webservice of my own, activated the methods that interest me, but when implementing the CRUD functions, I am a bit lost .
I would like to know how URLs are interpreted by passing parameters to, for example, consult an item by ID, delete an item by ID or create a new one. Yes, using the way to implement as done here: link
Edit: I put here the explanation and the code. The data to recover and record is recovered / saved in a new table that I have registered.
This is the class that extends the webservice request core to implement my own webservice
class WebserviceRequest extends WebserviceRequestCore
{
public function __construct()
{
include_once(_PS_MODULE_DIR_.'directorioModulo'.DIRECTORY_SEPARATOR.'models'.DIRECTORY_SEPARATOR.'ClaseParaImplementarModuloCustom.php');
}
}
This ClassForImplementModuleCustom.php is where all the Webservice logic should be done. (I understand the CRUD functions)
class CentralizedStoreAssociated extends ObjectModel
{
//Campos de la clase
public $id;
public $store_name;
public $store_url;
public $store_api_key;
public $store_contact_email;
//Definición de la clase/objeto
public static $definition = [
'table' => 'centralized_stores',
'primary' => 'id_centralizedstore',
'multilang' => false,
'multilang_shop' => false,
'fields' => array(
'store_id' => ['type' => self::TYPE_INT, 'validate' => 'isInt', 'size' => 256],
),
];
}
//Definición de los parámetros del servicio web. Aquí es donde entiendo que deben definirse las funciones para el CRUD en associations.
protected $webserviceParameters = [
'objectNodeName' => 'store',
'objectsNodeName' =>'centralized_stores',
'associations' => [
'storeDetails' => array('getter' => 'getStoreDetails', 'resource' => 'storeDetails',
'fields' => array(
'store_name' => ['type' => self::TYPE_STRING, 'validate' => 'isString', 'size' => 256],
'store_url' => ['type' => self::TYPE_STRING, 'validate' => 'isUrl', 'size' => 2038],
'store_api_key' => ['type' => self::TYPE_STRING, 'validate' => 'isString', 'size' => 32],
'store_contact_email' => ['type' => self::TYPE_STRING, 'validate' => 'isEmail', 'size' => 254],
),
),
]
];
Finally I have defined a function for the getter = > getStoreDetails that is nothing more than a function to obtain the data of a store from the custom table, by means of the URL link
I hope I have made everything clearer.