0

how to get all configurable product attribute like color,size,brand,shipping etc in soap api V2, I am totally new in this field. Thanks in advance. Here is my code where i have to fetch all the configurable attribute with label to my android application. I tried to copy the description module same in color module but its return the numeric digit rather than color text.


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

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

    $products= $proxy->catalogCategoryAssignedProducts($sessionId,$categoryId);


    $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";
           }
            $color=$product2->getColor();
           if($color==""){
            $color="blank";
           }

           $baseImageUrl = $productMediaConfig->getMediaUrl($product2->getImage());
           if($baseImageUrl=="http://www.prash.com/media/catalog/product/"){
            $baseImageUrl="http://www.prash.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,
      "color"=>$color,
      "imageurl"=>$baseImageUrl,
      );
    }


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

Use below code instead of getColor() because getColor() will return the id of that color.

$color=$product2->getResource()->getAttribute('color')->getFrontend()->getValue($product2);

to get all attributes of front end try below code

$attributes = $product->getAttributes();

foreach ($attributes as $attribute) { 
echo $label=$attribute->getFrontendLabel();
echo $value = $attribute->getFrontend()->getValue($product);
}
5
  • Thanks for your reply. I got the value now, Could you please show me how can I will be able to get complete additional data like brand,size,color and shipping etc – Prashant Das Dec 3 '16 at 10:05
  • @PrashantDas feel free to raise new question :) – Gopal Patel Dec 3 '16 at 10:07
  • @PrashantDas find your requirement in updated answer and welcome to magento community :) – Gopal Patel Dec 3 '16 at 10:21
  • thanks for your answer...but could you please tell where to place this line of code and in your answer ($product) will be ($product2) – Prashant Das Dec 3 '16 at 10:53
  • @PrashantDas yes $product2. Actually your code is not optimized. Why you are loading product each time? you can load it in one go and play it with in foreach. And yes more important first try on your own, in case you stuck some where then raise question don't expect full code solution. – Gopal Patel Dec 3 '16 at 11:02

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.