0

I wish to update values in commerce_payment_transaction entity. I am using such code:

<?php
$transaction = commerce_payment_transaction_load(58);
 $digests = array(
'DIGEST' => '456',
'DIGEST2' => '478'
);

$transaction_wrapper = entity_metadata_wrapper('commerce_payment_transaction', $transaction);
$transaction_wrapper->payload->set($digests);
$transaction_wrapper->field_my_custom_field->set(1458);
$transaction_wrapper->save();

The problem is, that such code throws me error, that payload is not property of commerce_payment_transaction entity. Although "payload" is column in database table of this entity type. But it is not set as property.

When I don't use entity_metadata_wrapper, this code works for me:

<?php
$transaction = commerce_payment_transaction_load(58);
$digests = array(
'DIGEST' => '456',
'DIGEST2' => '478'
);
$transaction->payload = $digests;
commerce_payment_transaction_save($transaction);
?>

But is it possible to use also entity_metadata_wrapper to update data of entity, that are neither properties nor fields, like payload in commerce_payment_transaction?

1 Answer 1

0

The payload column is a property of the commerce payment transaction type already (property is a Drupal core term for any base fields on an entity), but for whatever reason the authors of the module have chosen not to expose it to the Entity API module through commerce_payment_entity_property_info().

Fortunately you can just use hook_entity_property_info_alter() in a custom module to provide the metadata on its behalf. See hook_entity_property_info() for details of the options available.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.