I successfully receive product variation object by its id
$variation = \Drupal::entityTypeManager()->getStorage('commerce_product_variation')->load(8);
Then I successfully receive its structure like
(
[variation_id] => Array
(
[x-default] => 8
)
[type] => Array
(
[x-default] => router
)
[uuid] => Array
(
[x-default] => a44c2c31-2131-4c99-82a6-856b566d97cf
)
...
by print_r()
like
echo '<pre>';
print_r($variation);
echo '</pre>';
Now if I try to get SKU with $variation->sku->value
, I get it
But if I try to get variation type machine name with $variation->type->value
I get nothing (and gettype($variation->type->value)
returns NULL).
Still, we see it in the structure with the value router
Why and how to get the machine name?
It's strange: the print_r()
shows the way is $variation->type->value
But I've just successfully got it by
$variation->type[0]->target_id
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.