In prestashop > 1.6 you can proceed :
- Override **product** class,
- Redefine the **definition** schema and the **webserviceParameters** schema
- Add both fields "**url**"
- create a function "**getWsUrl()**" that returns the absolute url of your product
And the job is done, here is my code:
<?php
class ProductForWs extends ProductCore
{
protected $webserviceParameters = array(
'objectMethods' => array(
'add' => 'addWs',
'update' => 'updateWs'
),
'objectNodeNames' => 'ProductForWs',
'fields' => array(
'id_default_image' => array(
'getter' => 'getCoverWs',
'setter' => 'setCoverWs',
'xlink_resource' => array(
'resourceName' => 'images',
'subResourceName' => 'products'
)
)
),
'associations' => array(
'url' => array('resource' => 'url',
'fields' => array(
'url' => array('required' => true)
),
'setter' => false
)
),
);
public static $definition = array(
'table' => 'product',
'primary' => 'id_product',
'fields' => array(
'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCatalogName', 'required' => true, 'size' => 128),
'url' => array('type' => self::TYPE_STRING),
'associations' => array(),
),
);
public function getWsUrl(){
$link = new Link();
$product = new Product($this->id);
return array(array("url" => $link->getProductLink($product)));
}
The WebServiceOutputBuilder will call your function and return the url path as an association. Like:
<associations>
<url nodeType="url" api="url">
<url>
<url>
<![CDATA[
[To see links please register here]
]]>
</url>
</url>
</url>
</associations>