I am trying to get Full product link
, so can use it in share in mobile application.
I already used API
:
GET https://domain.com/index.php/rest/V1/products/:sku
and have a response, but can't get a full link. How this?
You might need to extend ProductInterface and add the getters and setters there for the full product link, then you need to extend the actual product model to implement that interface and prepare those methods.
namespace Company\Module\Api\Data;
interface ProductInterface extends \Magento\Catalog\Api\Data\ProductInterface{
public function getFullProductLink();
public function setFullProductLink($productLink);
}
namespace Company\Module\Model;
class Product extends \Magento\Catalog\Model\Product implements \Company\Module\Api\Data\ProductInterface
{
public function setStoreCredit($customerBalanceAmount)
{
// logic to set the full product link
}
public function getFullProductLink() {
// logic to return the full product link
}
}
Hope this helps :)
edit: Used the wrong model
Magento\Catalog\Api\Data\ProductInterface
, you will notice it contains all the returned data from the API. If you take a look at the catalog webapi.xml, under V1/products/:sku, it uses the method get from the ProductRepository, which return instances of ProductInterface
. I had to do something similar for the Order and it worked just by adding the new attribute to the Interface and Model :)
Commented
Mar 21, 2017 at 18:48