Jump to content

get feature value id by name


Recommended Posts

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);
    foreach ($features->product_features->product_feature as $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) {

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


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

  • 5 years later...
  • 8 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...