Skip to content

Instantly share code, notes, and snippets.

@St0iK
Created November 5, 2015 12:01
Show Gist options
  • Save St0iK/f9389a5fc72c69f560a4 to your computer and use it in GitHub Desktop.
Save St0iK/f9389a5fc72c69f560a4 to your computer and use it in GitHub Desktop.
<?php
/**
* @file
* Custom views handler definition.
*
* Place this code in
* /sites/all/[custom_module_name]/includes/views_handler_total_discounted_field.inc
*/
/**
* Custom handler class.
*
* @ingroup views_field_handlers
*/
class views_handler_payable_to_designer_field extends views_handler_field {
/**
* {@inheritdoc}
*
* Perform any database or cache data retrieval here. In this example there is
* none.
*/
function query() {}
/**
* {@inheritdoc}
*
* Modify any end user views settings here. Debug $options to view the field
* settings you can change.
*/
function option_definition() {
$options = parent::option_definition();
return $options;
}
/**
* {@inheritdoc}
*
* Make changes to the field settings form seen by the end user when adding
* your field.
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
}
/**
* Render callback handler.
*
* Return the markup that will appear in the rendered field.
*/
function render($values) {
// get the price compoment
$price_compoments =
$values->_field_data['commerce_line_item_field_data_commerce_line_items_line_item_']['entity']->commerce_total['und'][0]['data']['components'];
// get the currency used
$currency = _calculate_final_currency($price_compoments);
// get the discount type used
$discount_type = _calculate_discount_type($price_compoments);
// get line item total price
$item_total = _item_total(
$values->_field_data['commerce_product_field_data_commerce_product_product_id']['entity']->commerce_price[und][0][amount],
$values->commerce_line_item_field_data_commerce_line_items_quantity
);
// get designer's country term id
$designer_country_term_id = $values->_field_data['node_users_nid']['entity']->field_designer_country[und][0]['tid'];
// get designer's vat number
$designer_vat_number = $values->_field_data['node_users_nid']['entity']->field_designer_company_vat[und][0]['value'];
// calculate the percentage that needs to be applied to this line item
$percentage = _get_percentage_applied_to_line_item($designer_country_term_id,$designer_vat_number);
if ($item_total)
{
// calculate and return the final amount payable to designer
return _calculate_payable_to_designer($item_total, $percentage, $line_item_id, $order_id,$currency);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment