Tags/topics: 
1
Answers
Vote up!
0
Vote down!

Location of field

I am having an issue with moving different fields around.

I currently have for the product view a grid setup, 3 across, 3 down, with the image, the product name, the price, the wishlist, and the add to cart button, as well as a special field that I have added in that says if the product comes in pairs or if there are multiple items that are different colors, that it is EA, not all the ones in the picture. I have created this field fine, however I am having an issue placing it where I want it. Currently it is at the bottom of each item, below everything else, centered, and I would like it to be next to the price. Any way to make that happen?

Here is the website

http://robertasherdesigns.com/catelog/bracelets

Asked by: daniel
on June 26, 2013

1 Answer

Vote up!
0
Vote down!

If you are using the "Rendered Entity/Rendered Node" field in your views (the default in commerce_kickstart), you could add a custom view mode formatter, for example:


/**
* Implements hook_field_formatter_info().
*/
function MYMODULE_field_formatter_info() {
return array(
'mymodule_special_field_format' => array(
'label' => t('Special Field Format X'),
'description' => t('Description'),
'field types' => array('commerce_price'),
),
);
}

/**
* Implements hook_field_formatter_view().
*/
function MYMODULE_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {

if ($display['type'] == 'mymodule_special_field_format') {
$node_wrapper = entity_metadata_wrapper('node', $entity->display_context['entity']);
$element = array();
foreach ($items as $delta => $item) {
if (is_null($item['amount'])) {
continue;
}

$element[$delta] = array(
'#markup' => commerce_currency_format($item['amount'], $item['currency_code'], $entity) . $node_wrapper->field_each->value()
);
}

return $element;
}
}

If you are using a view of fields, you could just "Rewrite the Output" of the price field to include the value of your special field.

Answer by: Favio Manriquez
Posted: Jun 27, 2013