Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 551 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get product URL using Prestashop API

#1
I have two stores using Prestashop. I would like to import a products URLs list from the first to the second.

I can access to the product list by using `http://example.com/api/products`
I can also access to the product information by using

```http://example.com/api/products/{ProductID}
```

By this way I can access to all products data but I can't find product URL.

Is there a way to retrieve a product URL from Prestashop ?

Reply

#2
<p>You can generate the product URL from the product ID:</p>
$productUrl = 'http://mydomain.com/index.php?controller=product&id_product=' . $productId;
<p>If Friendly URL is turned on then the URL will be rewritten.</p>
Reply

#3
For those who are looking to generate the absolute url inside their store, you can do the following :

$product = new Product(Tools::getValue('id_product'));
$link = new Link();
$url = $link->getProductLink($product);

Will result with something like :

>

[To see links please register here]

Reply

#4
On PrestaShop™ 1.4.5.1
I use

public function getProductLink($id)
{
global $cookie;
$productUrl = "http://".$_SERVER['HTTP_HOST'].'/product.php?id_product=' . $id;
return $productUrl;

}
Reply

#5
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>
Reply

#6
In add to @robin-delaporte you can use this overriding Product class and automatically get for all languages in your prestashop.

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()
),
'setter' => false
),
),
);

public function getWsUrl(){
$languages = Language::getLanguages(true, $this->context->shop->id);
$link = new Link();
$product = new Product($this->id);


if (!count($languages))
return array(array("url" => $link->getProductLink($product)));;

$default_rewrite = array();
$rewrite_infos = Product::getUrlRewriteInformations($this->id);
foreach ($rewrite_infos as $infos)
$default_rewrite[$infos['id_lang']] = $link->getProductLink($this->id, $infos['link_rewrite'], $infos['category_rewrite'], $infos['ean13'], (int)$infos['id_lang']);

return $default_rewrite;
}
Reply

#7
Define $your_product_id in the controller file of the tpl file, then call it from the tpl file as follows

yourcontroller.php

public function hookTheHookYouWant()
{
$set_product = $this->context->smarty->assign(array(
'product_id' => 27,
));
$set_product = $this->context->smarty->fetch($this->local_path.'views/templates/front/yourtplfile.tpl');
return $set_product;
}
}

yourtplfile.tpl

{url entity='product' id=$product_id}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through