0

The array I am looking at is this:

Array
(
[0] => Array
    (
        [0] => Bigcommerce\Api\Resources\ProductCustomField Object
            (
                [ignoreOnCreate:protected] => Array
                    (
                        [0] => id
                        [1] => product_id
                    )

                [ignoreOnUpdate:protected] => Array
                    (
                        [0] => id
                        [1] => product_id
                    )

                [fields:protected] => stdClass Object
                    (
                        [id] => 17
                        [product_id] => 3232
                        [name] => Artist
                        [text] => Test
                    )

                [id:protected] => 17
                [ignoreIfZero:protected] => Array
                    (
                    )

            )

    )

)

I want to check to see if 'Artist' exists in a php conditional statement. But I don't know how to turn 'Artist' into a string.

UPDATED: I did not find understand how to extract that value into a string, but I got what I was looking for using the method related to the bigcommerce api:

$customs = Bigcommerce::getProductCustomFields($product->id);
foreach($customs as $custom) {
if($custom->name == 'Artist'): // do something 
endif;
}
4
  • Is there a way to access the ProductCustomField protected $fields property, like via a getter (eg $obj->getFields())? Commented Mar 27, 2014 at 2:58
  • I'm not sure. I was not able to find clear documentation, but I think this should look up the customfields... Bigcommerce::getProductCustomFields($product->id); But I still don't know how to access it from that. Commented Mar 27, 2014 at 3:01
  • Would you pls add var_export($yourArray) so it will be easier for us to use it and run for testing? Commented Mar 27, 2014 at 3:03
  • array ( 0 => array ( 0 => Bigcommerce\Api\Resources\ProductCustomField::__set_state(array( 'ignoreOnCreate' => array ( 0 => 'id', 1 => 'product_id', ), 'ignoreOnUpdate' => array ( 0 => 'id', 1 => 'product_id', ), 'fields' => stdClass::__set_state(array( 'id' => 17, 'product_id' => 3232, 'name' => 'Artist', 'text' => 'Test', )), 'id' => 17, 'ignoreIfZero' => array ( ), )), ), ) Commented Mar 27, 2014 at 3:08

2 Answers 2

2

Ok, looking at the source, it seems you should be able to use the magic __get method. Try

$array[0][0]->name == 'Artist'
Sign up to request clarification or add additional context in comments.

1 Comment

I hadn't looked at that. It's probably easier to do with those functions. But I'm still confused as to what the $field would be for the custom value I created for the product (which is the artist name.)
0

The value of the custom field would be stored in the "text" resource for that custom field.

See the following link where you can see the 4 properties of a custom field. https://developer.bigcommerce.com/api/stores/v2/products/custom_fields

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.