function _commerce_price_field_serialize_data in Commerce Core 7
Converts price field data to a serialized array.
Parameters
$entity_type: The entity type variable passed through hook_field_storage_pre_*().
$entity: The entity variable passed through hook_field_storage_pre_*().
2 calls to _commerce_price_field_serialize_data()
- commerce_price_field_storage_pre_insert in modules/
price/ commerce_price.module - Implements hook_field_storage_pre_insert().
- commerce_price_field_storage_pre_update in modules/
price/ commerce_price.module - Implements hook_field_storage_pre_update().
File
- modules/
price/ commerce_price.module, line 142 - Defines the Price field with widgets and formatters used to add prices with currency codes to various Commerce entities.
Code
function _commerce_price_field_serialize_data($entity_type, $entity) {
// Loop over all the price fields attached to this entity.
foreach (_commerce_price_get_price_fields($entity_type, $entity) as $field_name) {
// Iterate over the items arrays for each language.
foreach (array_keys($entity->{$field_name}) as $langcode) {
$items = isset($entity->{$field_name}[$langcode]) ? $entity->{$field_name}[$langcode] : array();
// Serialize data arrays before saving.
foreach ($items as $delta => $item) {
// Serialize an existing data array.
if (isset($item['data']) && is_array($item['data'])) {
$entity->{$field_name}[$langcode][$delta]['data'] = serialize($item['data']);
}
}
}
}
}