0

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?

1 Answer 1

0

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

1
  • I might not know a deep answer on how magento works with the API, but it seems to use the Interfaces to return the data needed for the APIs. If you look at 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 :)
    – manumotate
    Commented Mar 21, 2017 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.