0

I have written soap API for related product but this script is not working ,here is my code,i am totally new to this. please help me someone.Thanks


<?php 
// Get related products in productId
require_once('../app/Mage.php');//Path to Magento umask(0);

if(isset($_GET["productId"])){
  $categoryId=$_GET["productId"];
    $proxy = new SoapClient('http:/www.prashant.com/index.php/api/v2_soap/?wsdl'); // TODO : change url
    $sessionId = $proxy->login('pras', 'prashant123@'); // TODO : change login and pwd if necessary

    $products= $proxy->catalogProductLinkList($sessionId,$productId);


    $itemDetails=array();
    Mage::app(); 

  foreach ($products as $item) { 

    $product2 = Mage::getModel('catalog/product')->load($item->product_id);
    $productMediaConfig = Mage::getModel('catalog/product_media_config');
    $baseImageUrl = $productMediaConfig->getMediaUrl($product2->getImage());
    $price2=0;
    $price2=$product2->getFinalPrice();
    if($price2==0){
    $price2=$product2->getPrice();
    }



    $desc=$product2->getDescription();
           if($desc==""){
            $desc="blank";
           }


           $baseImageUrl = $productMediaConfig->getMediaUrl($product2->getImage());
           if($baseImageUrl=="http://www.prashant.com/media/catalog/product/"){
            $baseImageUrl="http://www.prashant.com/customApi/icon.png";
           }

           //"desc"=>$desc,

           $statusp=$product2->getStatus();
    $statusen= Mage_Catalog_Model_Product_Status::STATUS_ENABLED;


    if($statusp==$statusen){
         $itemDetails[]=array(
      "productId"=>$item->product_id,
      "name"=>$product2->getName(),
      "price"=>$product2->getPrice(),
      "spprice"=>$price2,
      "desc"=>$desc,
      "imageurl"=>$baseImageUrl,
      );
    }


  }
  //return array of products
  //echo "<pre>";
  //print_r($itemDetails);
  //echo "</pre>";
  echo json_encode($itemDetails);
  exit();
}else{
  echo "error";
  exit();
}
?>
0

Your server does not working, because this I can't test your code.

I made a simple try to get related products for product that ID is '45' and the code can be viewed below

    <?php

    $proxy = new SoapClient('http://www.uaiaquitem.com.br/api/v2_soap?wsdl=1'); // TODO : change url
    $sessionId = $proxy->login('xxxxxx', 'xxxxxx'); // TODO : change login and pwd

    //$products= $proxy->catalogProductLinkList($sessionId,$productId);

    $result = $proxy->catalogProductLinkList($sessionId,  'related', '45', '1');

    var_dump($result);
?>
| improve this answer | |
0

you can not get related products directly though SOAP api, you need to create custom code for getting related product collection, here my ref.

<?php
    $productColection = Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect('*');
    $productColection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds())
                ->addAttributeToFilter('status', 1) // enabled
                ->addAttributeToFilter('entity_id', array('eq' => $_REQUEST['product_id']));

    foreach ($productColection as $product)
    {
        $relatedIds = $product->getRelatedProductIds();
    }
    $relatedProductCollection = Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect('*');
    $relatedProductCollection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds())
            ->addAttributeToFilter('entity_id', array('in' => $relatedIds))
            ->addAttributeToFilter('status', 1) // enabled
    foreach($relatedProductCollection as $related){
        echo $related->getName();
        -------------------
    }

?>
| improve this answer | |

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.