cancel
Showing results for 
Search instead for 
Did you mean: 

Custom link type doesn't work in REST API

SOLVED
   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Custom link type doesn't work in REST API

I need not only cross-sell, up-sell, related but also additional link types so I created a module for it.

 

I have tried put the plugin definition in /etc/di.xml or /etc/adminhtml/di.xml and /etc/webapi_rest/di.xml.  It always works for adminhtml page but not work for api call.  What I added plugin definition is

<type name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Related">

        <plugin name="change_modifyMeta_after" type="Company\LinkedProducts\Plugin\Related"/>
</type>
<type name="Company\LinkedProducts\Model\ProductLink\CollectionProvider\LinkedProduct">
        <plugin name="change_link_before" type="Company\LinkedProducts\Plugin\Related"/>
</type>
 
 
The error I got when I have pulgin definition in etc/di.xml
 
"messages": {
        "error": [
            {
                "code"500,
                "message""Fatal Error: 'Uncaught Error: Cannot instantiate interface Magento\\Catalog\\Model\\Locator\\LocatorInterface in C:\\laragon\\www\\thibault\\vendor\\magento\\framework\\ObjectManager\\Factory\\Dynamic\\Developer.php:50\nStack trace:\n#0 C:\\laragon\\www\\thibault\\vendor\\magento\\framework\\ObjectManager\\ObjectManager.php(70): Magento\\Framework\\ObjectManager\\Factory\\Dynamic\\Developer->create('Magento\\\\Catalog...')\n#1 C:\\laragon\\www\\thibault\\vendor\\magento\\framework\\ObjectManager\\Factory\\AbstractFactory.php(160): Magento\\Framework\\ObjectManager\\ObjectManager->get('Magento\\\\Catalog...')\n#2 C:\\laragon\\www\\thibault\\vendor\\magento\\framework\\ObjectManager\\Factory\\AbstractFactory.php(246): Magento\\Framework\\ObjectManager\\Factory\\AbstractFactory->resolveArgument(Array, 'Magento\\\\Catalog...', NULL, 'locator', 'Shooga\\\\LinkedPr...')\n#3 C:\\laragon\\www\\thibault\\vendor\\magento\\framework\\ObjectManager\\Factory\\Dynamic\\Developer.php(34): Magento\\Framework\\ObjectManager\\Factory\\AbstractFactory->resolveArgumentsInRuntime('Shooga\\\\LinkedPr...', Array, Array)\n#4 C' in 'C:\\laragon\\www\\thibault\\vendor\\magento\\framework\\ObjectManager\\Factory\\Dynamic\\Developer.php' on line 50",
                "trace""Trace is not available."
            }
        ]
 
The error I got when I have pulgin definition in etc/adminhtml/di.xml and etc/webapi_rest/di.xml
 
{
    "message""Warning: Invalid argument supplied for foreach() in C:\\laragon\\www\\thibault\\vendor\\magento\\module-catalog\\Model\\ProductLink\\CollectionProvider.php on line 54",
    "trace""#0 C:\\laragon\\www\\thibault\\vendor\\magento\\module-catalog\\Model\\ProductLink\\CollectionProvider.php(54): Magento\\Framework\\App\\ErrorHandler->handler(2, 'Invalid argumen...', 'C:\\\\laragon\\\\www\\\\...', 54, Array)\n#1 C:\\laragon\\www\\thibault\\vendor\\magento\\module-catalog\\Model\\ProductLink\\Repository.php(157): Magento\\Catalog\\Model\\ProductLink\\CollectionProvider->getCollection(Object(Magento\\Catalog\\Model\\Product\\Interceptor), 'linked_accessor...')\n#2 C:\\laragon\\www\\thibault\\vendor\\magento\\module-catalog\\Model\\Product.php(1455): Magento\\Catalog\\Model\\ProductLink\\Repository->getList(Object(Magento\\Catalog\\Model\\Product\\Interceptor))\n#3 C:\\laragon\\www\\thibault\\generated\\code\\Magento\\Catalog\\Model\\Product\\Interceptor.php(817): Magento\\Catalog\\Model\\Product->getProductLinks()\n#4 C:\\laragon\\www\\thibault\\vendor\\magento\\framework\\Reflection\\DataObjectProcessor.php(91): Magento\\Catalog\\Model\\Product\\Interceptor->getProductLinks()\n#5 C:\\laragon\\www\\thibault\\vendor\\magento\\framework\\Webapi\\ServiceOutputProcessor.php(126): Magento\\Framework\\Reflection\\DataObjectProcessor->buildOutputDataArray(Object(Magento\\Catalog\\Model\\Product\\Interceptor), '\\\\Magento\\\\Catalo...')\n#6 C:\\laragon\\www\\thibault\\vendor\\magento\\framework\\Webapi\\ServiceOutputProcessor.php(78): Magento\\Framework\\Webapi\\ServiceOutputProcessor->convertValue(Object(Magento\\Catalog\\Model\\Product\\Interceptor), '\\\\Magento\\\\Catalo...')\n#7 C:\\laragon\\www\\thibault\\vendor\\magento\\module-webapi\\Controller\\Rest\\SynchronousRequestProcessor.php(97): Magento\\Framework\\Webapi\\ServiceOutputProcessor->process(Object(Magento\\Catalog\\Model\\Product\\Interceptor), 'Magento\\\\Catalog...', 'get')\n#8 C:\\laragon\\www\\thibault\\vendor\\magento\\module-webapi\\Controller\\Rest.php(188): Magento\\Webapi\\Controller\\Rest\\SynchronousRequestProcessor->process(Object(Magento\\Framework\\Webapi\\Rest\\Request\\Proxy))\n#9 C:\\laragon\\www\\thibault\\vendor\\magento\\framework\\Interception\\Interceptor.php(58): Magento\\Webapi\\Controller\\Rest->dispatch(Object(Magento\\Framework\\App\\Request\\Http))\n#10 C:\\laragon\\www\\thibault\\vendor\\magento\\framework\\Interception\\Interceptor.php(138): Magento\\Webapi\\Controller\\Rest\\Interceptor->___callParent('dispatch', Array)\n#11 C:\\laragon\\www\\thibault\\vendor\\magento\\framework\\Interception\\Interceptor.php(153): Magento\\Webapi\\Controller\\Rest\\Interceptor->Magento\\Framework\\Interception\\{closure}(Object(Magento\\Framework\\App\\Request\\Http))\n#12 C:\\laragon\\www\\thibault\\generated\\code\\Magento\\Webapi\\Controller\\Rest\\Interceptor.php(26): Magento\\Webapi\\Controller\\Rest\\Interceptor->___callPlugins('dispatch', Array, Array)\n#13 C:\\laragon\\www\\thibault\\vendor\\magento\\framework\\App\\Http.php(136): Magento\\Webapi\\Controller\\Rest\\Interceptor->dispatch(Object(Magento\\Framework\\App\\Request\\Http))\n#14 C:\\laragon\\www\\thibault\\generated\\code\\Magento\\Framework\\App\\Http\\Interceptor.php(24): Magento\\Framework\\App\\Http->launch()\n#15 C:\\laragon\\www\\thibault\\vendor\\magento\\framework\\App\\Bootstrap.php(258): Magento\\Framework\\App\\Http\\Interceptor->launch()\n#16 C:\\laragon\\www\\thibault\\index.php(39): Magento\\Framework\\App\\Bootstrap->run(Object(Magento\\Framework\\App\\Http\\Interceptor))\n#17 {main}"
}
 
Help me.
 
Thank you.
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Custom link type doesn't work in REST API

I solved this problem.

I added 

<preference for="Magento\Catalog\Model\Product" type="Company\LinkedProducts\Model\Product" /> in etc/di.xml

View solution in original post

1 REPLY 1

Re: Custom link type doesn't work in REST API

I solved this problem.

I added 

<preference for="Magento\Catalog\Model\Product" type="Company\LinkedProducts\Model\Product" /> in etc/di.xml