leifnel Posted July 6, 2016 Share Posted July 6, 2016 Is it possible to search via the webservice for the id of a feature value. Say I want to assign the feature "Colour => Red" to a product. Currently I do this; function find_feature_value_id($feature_name, $feature_value) { $webService = new \Presta\api(); $opt['resource'] = 'product_features'; $features = $webService->get($opt); //var_dump($features); foreach ($features->product_features->product_feature as $feature) { //var_dump($feature); $f_id = (int)$feature[0]['id']; $opt['resource'] = 'product_features/' . $f_id; $feat = $webService->get($opt); $f_name= (string )$feat->product_feature->name->language[0]; // echo $f_id.": ".$f_name."<br />"; if ($f_name == $feature_name) { $opt['resource'] = 'product_feature_values'; $opt['filter']['id_feature'] = $f_id; $values = $webService->get($opt); foreach ($values->product_feature_values->product_feature_value as $v) { $id_product_feature_value = ((int)$v[0]['id']); $opt['resource'] = 'product_feature_values/' . $id_product_feature_value; $value = $webService->get($opt); $text = (string )$value->children()->children()->value->language[0]; // echo $id_product_feature_value . ": " . $text . "<br />"; if ($text==$feature_value) { return(array('feature'=>$f_id,'val'=>$id_product_feature_value)); } } } } } It takes several webservice-calls to get that id, a more efficient approach would probably to just extract all product_feature_values and put into an array in php $product_value_id['Compositions']['wool']=22; At least I should cache the results. I could easily do it with a couple of joins in mysql, but I want to keep the interface as clean as possible, Am I missing something obvious? Link to comment Share on other sites More sharing options...
aguilloteau Posted August 26, 2021 Share Posted August 26, 2021 Hello, did you find an answer to your question? or is your solution the only one that works? thanks! Link to comment Share on other sites More sharing options...
Radziasss Posted May 18, 2022 Share Posted May 18, 2022 +1 Is it really the only way to get the proper product_feature_value? Why can't we just filter it by value? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now