function commerce_gc_remove_giftcard_components in Commerce GC 7
Remove giftcard components from a given price and recalculate the total.
Parameters
$price_wrapper: Wrapped commerce price.
1 call to commerce_gc_remove_giftcard_components()
File
- ./
commerce_gc.module, line 273 - Provides Giftcard coupon bundle, Giftcard Transaction entity and basic user interface elements.
Code
function commerce_gc_remove_giftcard_components($price_wrapper) {
$data = $price_wrapper->data
->value();
$component_removed = FALSE;
// Remove price components belonging to giftcards.
foreach ($data['components'] as $key => $component) {
if ($component['name'] == 'giftcard') {
unset($data['components'][$key]);
$component_removed = TRUE;
}
}
// Don't alter the price components if no components were removed.
if (!$component_removed) {
return;
}
// Re-save the price without the giftcards (if existed).
$price_wrapper->data
->set($data);
// Re-set the total price.
$total = commerce_price_component_total($price_wrapper
->value());
$price_wrapper->amount
->set($total['amount']);
}