0

I'm trying to make a function that return all related product of a product, using the productId

So I make this in /var/www/website/api/catalog/get_collection.php :

require_once dirname(__FILE__).'/../app/Init.php';

$task = new Init(__FILE__);
        > try {
        > 
        >         $client = $task->getSOAPClient();
        >         $session = $task->getSOAPSession($client);
        > 
        >         $productId = $_GET['productId'];
        >         $productId = (string)$productId;
        >         $result = $client->call($session, 'catalog_product_link.list', array('type' => 'related', 'product' => $productId));  
        >         var_dump ($result);
              } 
        catch(Exception $e) {
        >     $task->errorResponse($e->getMessage()); 
              }

I call this "get_collection.php" file from my google chrome with this line :

http://magento.dev.website.com/api/catalog/get_collection.php?productId=557

And this is the result I get :

{ error: "Product not exists." }

I try to replace $productId in the array of argument by the value of the productId, but still the same error.

Please, help me >.< Oh, it's on Magento 1.8.0, if this can help someone helping me ^^

  • are you trying to extend Magento's API? – kbariotis Sep 1 '14 at 17:36
  • I just make this php file, if it's your question =) – Malerick Sep 2 '14 at 7:24
  • No idea what you are trying to do. Normally, there is no file app/Init.php. Seems you want to use SOAP in order to get related products. This is described here. – Simon Sep 2 '14 at 7:26
  • I have seen it yesterday, and try 'var_dump($proxy->call($sessionId, 'product_link.list', array('related', 'Sku')));', but it doesn't work, and like it doesn't use the productId, I don't know how to use it. And I'm trying to make a function that return all related product of a product, using the productId (update my question to explain it) – Malerick Sep 2 '14 at 7:56
1

I assume you use SOAP v2. As written in the comments, there is no file App/Init.php, so I have no idea what you are trying to do. The documentation of the SOAP API is rather good. This page explains how to get the related products. Something like this should work:

$proxy = new SoapClient('http://magentohost/api/v2_soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');
$result = $proxy->catalogProductLinkList($sessionId, 'related', $productId);
var_dump($result);

Make sure that you configure Magento correctly. You can have a look at this Inchoo article for a reference.

  • I try SOAP v2, but doesn't config', and don't have access to make it. But I also try again the '$result = $client->call($session, 'catalog_product_link.list', array('type' => 'related', 'product' => '1'));', and I have a new error "product not exists.". How can I had $productId in this line, which I have (using GET) ? – Malerick Sep 2 '14 at 8:36
  • I edit my question, new start of solution =P – Malerick Sep 2 '14 at 9:03
  • I am pretty sure you need to login in order to be able to use the SOAP API. You need the API credentials. – Simon Sep 2 '14 at 9:10
  • This is made by the Init.php file, correctly working for the get_product.php like that : require_once dirname(__FILE__).'/../app/Init.php'; $task = new Init(__FILE__); try { $client = $task->getSOAPClient(); $session = $task->getSOAPSession($client); – Malerick Sep 2 '14 at 9:28
  • Okay. Then the product with the ID just does not exist in the store. – Simon Sep 2 '14 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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