Posted by hkvega01 on February 27, 2013 at 2:21am
i want to alter a object(a content type) e.g product, there is a custom function in a custom module will be run before whatever pages its appear. How can i access the object?
i want to alter a object(a content type) e.g product, there is a custom function in a custom module will be run before whatever pages its appear. How can i access the object?
Comments
Some more detail about what
Some more detail about what you are trying to achieve would be useful. Under what conditions do you want to modify the content type (the type of object makes a difference) and how (to what purpose) do you want to alter it.
i want to alter all selling
i want to alter all selling price of a product, if display price > selling price, then add css to the display price. This should be applied to all products whatever they appear. And more operation will be added, for example operate with uc discount alternative.
If "all" you want to do is
If "all" you want to do is add css you might look at implementing a price formatter. Here is part of an example
function hook_field_formatter_info() {return array(
'commerce_price_starting_at' => array(
'label' => t('Price starting at'),
'field types' => array('commerce_price'),
'settings' => array(
'prefix' => '',
'separator' => '',
'calculation' => TRUE,
'whole_numbers_only' => FALSE,
'alternative_text_for_zero_price' => '',
),
);
}
You would also need the hooks hook_field_formatter_prepare_view(), hook_field_formatter_settings_form(), hook_field_formatter_settings_summary() (the last two are only needed if the formatter has settings) and hook__field_formatter_view().
Since it is a field you should be also able to alter the render of the field (don't know that hook off the top of my head).
If you want to actually modify the price you will want to implement a rule.
thanks for you reply, but it
thanks for you reply, but it difficult for me to understand. And it seems there is a module called "custom formatter" doing like your solution. But finally, i used hook_node_view to alter the content for my product page.
thanks