简体   繁体   中英

Magento - retrieve the details of a specific product using custom attribute

I'm a beginner in Magento. I have this kind of requirement.

When some user enters a " item code " ( this is a custom attribute of every product in the store ) in a separate web page , the relevant information of that item should be retrieved from my magento store. Basically, I want the shop that item belongs, (shop - custom product attribute, drop down menu. ) & the image url of that item.

*item_code - custom attribute (varchar)

*shop - drop down menu ( options - abc , def , ghi, jkl )

I used soap v1 to do this.

Following cord is working fine .

But I don't know this is the best method to do it .

& When I get the product details , using " catalog_product.info " itwill give shop value as a number ( 126 ) But I want to get the actually name of it.

Is there any way to retrieve custom drop down menu values directly ? ?

This is my cord.

<?php


 $client = new SoapClient('http://myhost/index.php/api/soap/?wsdl');
 $session = $client->login('test', 'test1234');

 //get the specific product id using item_code
 $filters = array (
  'item_code' => array('like'=>'Mo-20105%')
 );

 $products = $client->call($session, 'product.list', array($filters) );

 //print_r($products);

 // using product id get all the attribute details of the product
 $result = $client->call($session, 'catalog_product.info', $products[0]['product_id'] );
 //var_dump($result);

 // using product id get the image url
 $img = $client->call($session, 'catalog_product_attribute_media.list', $products[0]   ['product_id'] );
 //var_dump($img);


// match the product 's shop value ( get from the web service ) with option values & get the correct shop name.
if( $result['shop'] == 129 ){ $shop = "abc" ; }
else if ( $result['shop'] == 126 ){ $shop = " def" ; }
else if ( $result['shop'] == 128 ){ $shop = " ghi" ; }
else if ( $result['shop'] == 126 ){ $shop = " jkl " ; }

echo $shop;
echo '</br>';
echo '<img src = '.$img[0]['url'].'  />'; 

Thank you

The value of shop drop down which you are getting in result of api call, that is an option value of select box for that specific product. For getting the name of specific option first you need to find out the attribute id of drop down attribute. So you need to use following api which will revert all the attribute list of product with name and id.

http://www.magentocommerce.com/api/soap/catalog/catalogProductAttribute/product_attribute.list.html

Then you can use following api to get all the option of that attribute with id and name of option.

http://www.magentocommerce.com/api/soap/catalog/catalogProductAttribute/product_attribute.options.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM