/** * Add pending referral * * @access public * @uses GFFormsModel::get_lead() * @uses GFCommon::get_product_fields() * @uses GFCommon::to_number() * * @param array $entry * @param array $form */ public function add_pending_referral($entry, $form) { if ($this->was_referred()) { // Do some craziness to determine the price (this should be easy but is not) $desc = ''; $entry = GFFormsModel::get_lead($entry['id']); $products = GFCommon::get_product_fields($form, $entry); $total = 0; foreach ($products['products'] as $key => $product) { $desc .= $product['name']; if ($key + 1 < count($products)) { $description .= ', '; } $price = GFCommon::to_number($product['price']); if (is_array(rgar($product, 'options'))) { $count = sizeof($product['options']); $index = 1; foreach ($product['options'] as $option) { $price += GFCommon::to_number($option['price']); } } $subtotal = floatval($product['quantity']) * $price; $total += $subtotal; } $total += floatval($products['shipping']['price']); $referral_total = $this->calculate_referral_amount($total, $entry['id']); $this->insert_pending_referral($referral_total, $entry['id'], $desc); } }
/** * Add pending referral * * @access public * @uses GFFormsModel::get_lead() * @uses GFCommon::get_product_fields() * @uses GFCommon::to_number() * * @param array $entry * @param array $form */ public function add_pending_referral($entry, $form) { if (!$this->was_referred() || !rgar($form, 'affwp_allow_referrals')) { return; } // Do some craziness to determine the price (this should be easy but is not) $desc = isset($form['title']) ? $form['title'] : ''; $entry = GFFormsModel::get_lead($entry['id']); $products = GFCommon::get_product_fields($form, $entry); $total = 0; foreach ($products['products'] as $key => $product) { $price = GFCommon::to_number($product['price']); if (is_array(rgar($product, 'options'))) { $count = sizeof($product['options']); $index = 1; foreach ($product['options'] as $option) { $price += GFCommon::to_number($option['price']); } } $subtotal = floatval($product['quantity']) * $price; $total += $subtotal; } // replace description if there are products if (!empty($products['products'])) { $product_names = wp_list_pluck($products['products'], 'name'); $desc = implode(', ', $product_names); } $total += floatval($products['shipping']['price']); $referral_total = $this->calculate_referral_amount($total, $entry['id']); $this->insert_pending_referral($referral_total, $entry['id'], $desc); if (empty($total)) { $this->mark_referral_complete($entry, array()); } }
/** * @param $form * @param $entry * @param bool|false $allow_display_empty_fields * @param array $editable_fields * @param Gravity_Flow_Step|null $current_step */ public static function entry_detail_grid($form, $entry, $allow_display_empty_fields = false, $editable_fields = array(), $current_step = null) { $form_id = absint($form['id']); $display_empty_fields = false; if ($allow_display_empty_fields) { $display_empty_fields = rgget('gf_display_empty_fields', $_COOKIE); } $display_empty_fields = (bool) apply_filters('gravityflow_entry_detail_grid_display_empty_fields', $display_empty_fields, $form, $entry); $condtional_logic_enabled = $current_step && $current_step->conditional_logic_editable_fields_enabled; self::register_form_init_scripts($form, array(), $condtional_logic_enabled); if (apply_filters('gform_init_scripts_footer', false)) { add_action('wp_footer', create_function('', 'GFFormDisplay::footer_init_scripts(' . $form['id'] . ');'), 20); add_action('gform_preview_footer', create_function('', 'GFFormDisplay::footer_init_scripts(' . $form['id'] . ');')); } else { echo GFFormDisplay::get_form_init_scripts($form); $current_page = 1; $scripts = "<script type='text/javascript'>" . apply_filters('gform_cdata_open', '') . " jQuery(document).ready(function(){jQuery(document).trigger('gform_post_render', [{$form_id}, {$current_page}]) } ); " . apply_filters('gform_cdata_close', '') . '</script>'; echo $scripts; } ?> <input type="hidden" name="action" id="action" value="" /> <input type="hidden" name="save" id="action" value="Update" /> <input type="hidden" name="screen_mode" id="screen_mode" value="<?php echo esc_attr(rgpost('screen_mode')); ?> " /> <table cellspacing="0" class="widefat fixed entry-detail-view"> <thead> <tr> <th id="details"> <?php $title = sprintf('%s : %s %s', esc_html($form['title']), __('Entry # ', 'gravityflow'), absint($entry['id'])); echo apply_filters('gravityflow_title_entry_detail', $title, $form, $entry); ?> </th> <th style="width:140px; font-size:10px; text-align: right;"> <?php if ($allow_display_empty_fields) { ?> <input type="checkbox" id="gentry_display_empty_fields" <?php echo $display_empty_fields ? "checked='checked'" : ''; ?> onclick="ToggleShowEmptyFields();" /> <label for="gentry_display_empty_fields"><?php _e('show empty fields', 'gravityflow'); ?> </label> <?php } ?> </th> </tr> </thead> <tbody class="<?php echo GFCommon::get_ul_classes($form); ?> "> <?php $count = 0; $field_count = sizeof($form['fields']); $has_product_fields = false; $display_fields_mode = $current_step ? $current_step->display_fields_mode : 'all_fields'; $display_fields_selected = $current_step && is_array($current_step->display_fields_selected) ? $current_step->display_fields_selected : array(); foreach ($form['fields'] as &$field) { /* @var GF_Field $field */ $display_field = true; if ($display_fields_mode == 'selected_fields') { if (!in_array($field->id, $display_fields_selected)) { $display_field = false; } } else { if (GFFormsModel::is_field_hidden($form, $field, array(), $entry)) { $display_field = false; } } $display_field = (bool) apply_filters('gravityflow_workflow_detail_display_field', $display_field, $field, $form, $entry, $current_step); switch (RGFormsModel::get_input_type($field)) { case 'section': if (!GFCommon::is_section_empty($field, $form, $entry) || $display_empty_fields) { $count++; $is_last = $count >= $field_count ? true : false; ?> <tr> <td colspan="2" class="entry-view-section-break<?php echo $is_last ? ' lastrow' : ''; ?> "><?php echo esc_html(rgar($field, 'label')); ?> </td> </tr> <?php } break; case 'captcha': case 'password': case 'page': //ignore captcha, password, page field break; case 'html': if ($display_field) { ?> <tr> <td colspan="2" class="entry-view-field-value"><?php echo $field->content; ?> </td> </tr> <?php } break; default: $field_id = $field->id; if (in_array($field_id, $editable_fields)) { if ($current_step->conditional_logic_editable_fields_enabled) { $field->conditionalLogicFields = GFFormDisplay::get_conditional_logic_fields($form, $field->id); } if (GFCommon::is_product_field($field->type)) { $has_product_fields = true; } $posted_step_id = rgpost('step_id'); if ($posted_step_id == $current_step->get_id()) { $value = GFFormsModel::get_field_value($field); } else { $value = GFFormsModel::get_lead_field_value($entry, $field); if ($field->get_input_type() == 'email' && $field->emailConfirmEnabled) { $_POST['input_' . $field->id . '_2'] = $value; } } if ($field->get_input_type() == 'fileupload') { $field->_is_entry_detail = true; } $content = self::get_field_content($field, $value, $form, $entry); $content = apply_filters('gform_field_content', $content, $field, $value, $entry['id'], $form['id']); $content = apply_filters('gravityflow_field_content', $content, $field, $value, $entry['id'], $form['id']); echo $content; } else { //$field->conditionalLogic = null; if (!$display_field) { continue; } if (GFCommon::is_product_field($field->type)) { $has_product_fields = true; } $value = RGFormsModel::get_lead_field_value($entry, $field); $conditional_logic_fields = GFFormDisplay::get_conditional_logic_fields($form, $field->id); if (!empty($conditional_logic_fields)) { $field->conditionalLogicFields = $conditional_logic_fields; $field_input = self::get_field_input($field, $value, $entry['id'], $form_id, $form); echo '<div style="display:none;"">' . $field_input . '</div>'; } if ($field->type == 'product') { if ($field->has_calculation()) { $product_name = trim($value[$field->id . '.1']); $price = trim($value[$field->id . '.2']); $quantity = trim($value[$field->id . '.3']); if (empty($product_name)) { $value[$field->id . '.1'] = $field->get_field_label(false, $value); } if (empty($price)) { $value[$field->id . '.2'] = '0'; } if (empty($quantity)) { $value[$field->id . '.3'] = '0'; } } } $input_type = $field->get_input_type(); if ($input_type == 'hiddenproduct') { $display_value = $value[$field->id . '.2']; } else { $display_value = GFCommon::get_lead_field_display($field, $value, $entry['currency']); } $display_value = apply_filters('gform_entry_field_value', $display_value, $field, $entry, $form); if ($display_empty_fields || !empty($display_value) || $display_value === '0') { $count++; $is_last = $count >= $field_count && !$has_product_fields ? true : false; $last_row = $is_last ? ' lastrow' : ''; $display_value = empty($display_value) && $display_value !== '0' ? ' ' : $display_value; $content = ' <tr> <td colspan="2" class="entry-view-field-name">' . esc_html(rgar($field, 'label')) . '</td> </tr> <tr> <td colspan="2" class="entry-view-field-value' . $last_row . '">' . $display_value . '</td> </tr>'; $content = apply_filters('gform_field_content', $content, $field, $value, $entry['id'], $form['id']); $content = apply_filters('gravityflow_field_content', $content, $field, $value, $entry['id'], $form['id']); echo $content; } } break; } } $products = array(); if ($has_product_fields) { $products = GFCommon::get_product_fields($form, $entry); if (!empty($products['products'])) { ?> <tr> <td colspan="2" class="entry-view-field-name"><?php echo apply_filters("gform_order_label_{$form_id}", apply_filters('gform_order_label', __('Order', 'gravityflow'), $form_id), $form_id); ?> </td> </tr> <tr> <td colspan="2" class="entry-view-field-value lastrow"> <table class="entry-products" cellspacing="0" width="97%"> <colgroup> <col class="entry-products-col1" /> <col class="entry-products-col2" /> <col class="entry-products-col3" /> <col class="entry-products-col4" /> </colgroup> <thead> <th scope="col"><?php echo apply_filters("gform_product_{$form_id}", apply_filters('gform_product', __('Product', 'gravityflow'), $form_id), $form_id); ?> </th> <th scope="col" class="textcenter"><?php echo esc_html(apply_filters("gform_product_qty_{$form_id}", apply_filters('gform_product_qty', __('Qty', 'gravityflow'), $form_id), $form_id)); ?> </th> <th scope="col"><?php echo esc_html(apply_filters("gform_product_unitprice_{$form_id}", apply_filters('gform_product_unitprice', __('Unit Price', 'gravityflow'), $form_id), $form_id)); ?> </th> <th scope="col"><?php echo esc_html(apply_filters("gform_product_price_{$form_id}", apply_filters('gform_product_price', __('Price', 'gravityflow'), $form_id), $form_id)); ?> </th> </thead> <tbody> <?php $total = 0; foreach ($products['products'] as $product) { ?> <tr> <td> <div class="product_name"><?php echo esc_html($product['name']); ?> </div> <ul class="product_options"> <?php $price = GFCommon::to_number($product['price']); if (is_array(rgar($product, 'options'))) { $count = sizeof($product['options']); $index = 1; foreach ($product['options'] as $option) { $price += GFCommon::to_number($option['price']); $class = $index == $count ? " class='lastitem'" : ''; $index++; ?> <li<?php echo $class; ?> ><?php echo $option['option_label']; ?> </li> <?php } } $subtotal = floatval($product['quantity']) * $price; $total += $subtotal; ?> </ul> </td> <td class="textcenter"><?php echo esc_html($product['quantity']); ?> </td> <td><?php echo GFCommon::to_money($price, $entry['currency']); ?> </td> <td><?php echo GFCommon::to_money($subtotal, $entry['currency']); ?> </td> </tr> <?php } $total += floatval($products['shipping']['price']); ?> </tbody> <tfoot> <?php if (!empty($products['shipping']['name'])) { ?> <tr> <td colspan="2" rowspan="2" class="emptycell"> </td> <td class="textright shipping"><?php echo esc_html($products['shipping']['name']); ?> </td> <td class="shipping_amount"><?php echo GFCommon::to_money($products['shipping']['price'], $entry['currency']); ?> </td> </tr> <?php } ?> <tr> <?php if (empty($products['shipping']['name'])) { ?> <td colspan="2" class="emptycell"> </td> <?php } ?> <td class="textright grandtotal"><?php _e('Total', 'gravityflow'); ?> </td> <td class="grandtotal_amount"><?php echo GFCommon::to_money($total, $entry['currency']); ?> </td> </tr> </tfoot> </table> </td> </tr> <?php } } ?> </tbody> </table> <div class="gform_footer"> <input type="hidden" name="gform_unique_id" value="" /> <input type="hidden" name="is_submit_<?php echo $form_id; ?> " value="1" /> <input type="hidden" name="step_id" value="<?php echo $current_step ? $current_step->get_id() : ''; ?> " /> <?php if (GFCommon::has_multifile_fileupload_field($form) || !empty(GFFormsModel::$uploaded_files[$form_id])) { $files = !empty(GFFormsModel::$uploaded_files[$form_id]) ? GFCommon::json_encode(GFFormsModel::$uploaded_files[$form_id]) : ''; $files_input = "<input type='hidden' name='gform_uploaded_files' id='gform_uploaded_files_{$form_id}' value='" . str_replace("'", ''', $files) . "' />"; echo $files_input; } //GFFormDisplay::print_form_scripts( $form, false ); ?> </div> <?php }
public static function refresh_product_cache($form, $lead, $use_choice_text = false, $use_admin_label = false) { $cache_options = array(array(false, false), array(false, true), array(true, false), array(true, true)); foreach ($form['fields'] as $field) { /* @var $field GF_Field */ if ($field->has_calculation()) { //deleting field value cache for calculated fields $cache_key = 'GFFormsModel::get_lead_field_value_' . $lead['id'] . '_' . $field->id; GFCache::delete($cache_key); } } foreach ($cache_options as $cache_option) { list($use_choice_text, $use_admin_label) = $cache_option; if (gform_get_meta(rgar($lead, 'id'), "gform_product_info_{$use_choice_text}_{$use_admin_label}")) { gform_delete_meta(rgar($lead, 'id'), "gform_product_info_{$use_choice_text}_{$use_admin_label}"); GFCommon::get_product_fields($form, $lead, $use_choice_text, $use_admin_label); } } }
public static function lead_detail_grid($form, $lead, $allow_display_empty_fields = false) { $form_id = $form["id"]; $display_empty_fields = false; if ($allow_display_empty_fields) { $display_empty_fields = rgget("gf_display_empty_fields", $_COOKIE); } ?> <table cellspacing="0" class="widefat fixed entry-detail-view"> <thead> <tr> <th id="details"> <?php echo $form["title"]; ?> : <?php _e("Entry # ", "gravityforms"); ?> <?php echo $lead["id"]; ?> </th> <th style="width:140px; font-size:10px; text-align: right;"> <?php if ($allow_display_empty_fields) { ?> <input type="checkbox" id="gentry_display_empty_fields" <?php echo $display_empty_fields ? "checked='checked'" : ""; ?> onclick="ToggleShowEmptyFields();"/> <label for="gentry_display_empty_fields"><?php _e("show empty fields", "gravityforms"); ?> </label> <?php } ?> </th> </tr> </thead> <tbody> <?php $count = 0; $field_count = sizeof($form["fields"]); $has_product_fields = false; foreach ($form["fields"] as $field) { switch (RGFormsModel::get_input_type($field)) { case "section": if (!GFCommon::is_section_empty($field, $form, $lead) || $display_empty_fields) { $count++; $is_last = $count >= $field_count ? true : false; ?> <tr> <td colspan="2" class="entry-view-section-break<?php echo $is_last ? " lastrow" : ""; ?> "><?php echo esc_html(GFCommon::get_label($field)); ?> </td> </tr> <?php } break; case "captcha": case "html": case "password": case "page": //ignore captcha, html, password, page field break; default: //ignore product fields as they will be grouped together at the end of the grid if (GFCommon::is_product_field($field["type"])) { $has_product_fields = true; continue; } $value = RGFormsModel::get_lead_field_value($lead, $field); $display_value = GFCommon::get_lead_field_display($field, $value, $lead["currency"]); $display_value = apply_filters("gform_entry_field_value", $display_value, $field, $lead, $form); if ($display_empty_fields || !empty($display_value) || $display_value === "0") { $count++; $is_last = $count >= $field_count && !$has_product_fields ? true : false; $last_row = $is_last ? " lastrow" : ""; $display_value = empty($display_value) && $display_value !== "0" ? " " : $display_value; $content = ' <tr> <td colspan="2" class="entry-view-field-name">' . esc_html(GFCommon::get_label($field)) . '</td> </tr> <tr> <td colspan="2" class="entry-view-field-value' . $last_row . '">' . $display_value . '</td> </tr>'; $content = apply_filters("gform_field_content", $content, $field, $value, $lead["id"], $form["id"]); echo $content; } break; } } $products = array(); if ($has_product_fields) { $products = GFCommon::get_product_fields($form, $lead); if (!empty($products["products"])) { ?> <tr> <td colspan="2" class="entry-view-field-name"><?php echo apply_filters("gform_order_label_{$form["id"]}", apply_filters("gform_order_label", __("Order", "gravityforms"), $form["id"]), $form["id"]); ?> </td> </tr> <tr> <td colspan="2" class="entry-view-field-value lastrow"> <table class="entry-products" cellspacing="0" width="97%"> <colgroup> <col class="entry-products-col1"> <col class="entry-products-col2"> <col class="entry-products-col3"> <col class="entry-products-col4"> </colgroup> <thead> <th scope="col"><?php echo apply_filters("gform_product_{$form_id}", apply_filters("gform_product", __("Product", "gravityforms"), $form_id), $form_id); ?> </th> <th scope="col" class="textcenter"><?php echo apply_filters("gform_product_qty_{$form_id}", apply_filters("gform_product_qty", __("Qty", "gravityforms"), $form_id), $form_id); ?> </th> <th scope="col"><?php echo apply_filters("gform_product_unitprice_{$form_id}", apply_filters("gform_product_unitprice", __("Unit Price", "gravityforms"), $form_id), $form_id); ?> </th> <th scope="col"><?php echo apply_filters("gform_product_price_{$form_id}", apply_filters("gform_product_price", __("Price", "gravityforms"), $form_id), $form_id); ?> </th> </thead> <tbody> <?php $total = 0; foreach ($products["products"] as $product) { ?> <tr> <td> <div class="product_name"><?php echo $product["name"]; ?> </div> <ul class="product_options"> <?php $price = GFCommon::to_number($product["price"]); if (is_array(rgar($product, "options"))) { $count = sizeof($product["options"]); $index = 1; foreach ($product["options"] as $option) { $price += GFCommon::to_number($option["price"]); $class = $index == $count ? " class='lastitem'" : ""; $index++; ?> <li<?php echo $class; ?> ><?php echo $option["option_label"]; ?> </li> <?php } } $subtotal = floatval($product["quantity"]) * $price; $total += $subtotal; ?> </ul> </td> <td class="textcenter"><?php echo $product["quantity"]; ?> </td> <td><?php echo GFCommon::to_money($price, $lead["currency"]); ?> </td> <td><?php echo GFCommon::to_money($subtotal, $lead["currency"]); ?> </td> </tr> <?php } $total += floatval($products["shipping"]["price"]); ?> </tbody> <tfoot> <?php if (!empty($products["shipping"]["name"])) { ?> <tr> <td colspan="2" rowspan="2" class="emptycell"> </td> <td class="textright shipping"><?php echo $products["shipping"]["name"]; ?> </td> <td class="shipping_amount"><?php echo GFCommon::to_money($products["shipping"]["price"], $lead["currency"]); ?> </td> </tr> <?php } ?> <tr> <?php if (empty($products["shipping"]["name"])) { ?> <td colspan="2" class="emptycell"> </td> <?php } ?> <td class="textright grandtotal"><?php _e("Total", "gravityforms"); ?> </td> <td class="grandtotal_amount"><?php echo GFCommon::to_money($total, $lead["currency"]); ?> </td> </tr> </tfoot> </table> </td> </tr> <?php } } ?> </tbody> </table> <?php }
public static function refresh_product_cache($form, $lead, $use_choice_text = false, $use_admin_label = false) { $cache_options = array(array(false, false), array(false, true), array(true, false), array(true, true)); foreach ($cache_options as $cache_option) { list($use_choice_text, $use_admin_label) = $cache_option; if (gform_get_meta(rgar($lead, 'id'), "gform_product_info_{$use_choice_text}_{$use_admin_label}")) { gform_delete_meta(rgar($lead, 'id'), "gform_product_info_{$use_choice_text}_{$use_admin_label}"); GFCommon::get_product_fields($form, $lead, $use_choice_text, $use_admin_label); } } }
public static function get_submitted_pricing_fields($form, $lead, $format, $use_text = true, $use_admin_label = false) { $form_id = $form["id"]; $order_label = apply_filters("gform_order_label_{$form["id"]}", apply_filters("gform_order_label", __("Order", "gravityforms"), $form["id"]), $form["id"]); $products = GFCommon::get_product_fields($form, $lead, $use_text, $use_admin_label); $total = 0; $field_data = ""; switch ($format) { case "text": if (!empty($products["products"])) { $field_data = "--------------------------------\n" . $order_label . "\n\n"; foreach ($products["products"] as $product) { $product_name = $product["quantity"] . " " . $product["name"]; $price = self::to_number($product["price"]); if (!empty($product["options"])) { $product_name .= " ("; $options = array(); foreach ($product["options"] as $option) { $price += self::to_number($option["price"]); $options[] = $option["option_name"]; } $product_name .= implode(", ", $options) . ")"; } $subtotal = floatval($product["quantity"]) * $price; $total += $subtotal; $field_data .= "{$product_name}: " . self::to_money($subtotal, $lead["currency"]) . "\n\n"; } $total += floatval($products["shipping"]["price"]); if (!empty($products["shipping"]["name"])) { $field_data .= $products["shipping"]["name"] . ": " . self::to_money($products["shipping"]["price"], $lead["currency"]) . "\n\n"; } $field_data .= __("Total", "gravityforms") . ": " . self::to_money($total, $lead["currency"]) . "\n\n"; } break; default: if (!empty($products["products"])) { $field_data = '<tr bgcolor="#EAF2FA"> <td colspan="2"> <font style="font-family: sans-serif; font-size:12px;"><strong>' . $order_label . '</strong></font> </td> </tr> <tr bgcolor="#FFFFFF"> <td width="20"> </td> <td> <table cellspacing="0" width="97%" style="border-left:1px solid #DFDFDF; border-top:1px solid #DFDFDF"> <thead> <th style="background-color:#F4F4F4; border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; font-family: sans-serif; font-size:12px; text-align:left">' . apply_filters("gform_product_{$form_id}", apply_filters("gform_product", __("Product", "gravityforms"), $form_id), $form_id) . '</th> <th style="background-color:#F4F4F4; border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:50px; font-family: sans-serif; font-size:12px; text-align:center">' . apply_filters("gform_product_qty_{$form_id}", apply_filters("gform_product_qty", __("Qty", "gravityforms"), $form_id), $form_id) . '</th> <th style="background-color:#F4F4F4; border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family: sans-serif; font-size:12px; text-align:left">' . apply_filters("gform_product_unitprice_{$form_id}", apply_filters("gform_product_unitprice", __("Unit Price", "gravityforms"), $form_id), $form_id) . '</th> <th style="background-color:#F4F4F4; border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family: sans-serif; font-size:12px; text-align:left">' . apply_filters("gform_product_price_{$form_id}", apply_filters("gform_product_price", __("Price", "gravityforms"), $form_id), $form_id) . '</th> </thead> <tbody>'; foreach ($products["products"] as $product) { $field_data .= '<tr> <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; font-family: sans-serif; font-size:11px;" > <strong style="color:#BF461E; font-size:12px; margin-bottom:5px">' . esc_html($product["name"]) . '</strong> <ul style="margin:0">'; $price = self::to_number($product["price"]); if (is_array(rgar($product, "options"))) { foreach ($product["options"] as $option) { $price += self::to_number($option["price"]); $field_data .= '<li style="padding:4px 0 4px 0">' . $option["option_label"] . '</li>'; } } $subtotal = floatval($product["quantity"]) * $price; $total += $subtotal; $field_data .= '</ul> </td> <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; text-align:center; width:50px; font-family: sans-serif; font-size:11px;" >' . $product["quantity"] . '</td> <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family: sans-serif; font-size:11px;" >' . self::to_money($price, $lead["currency"]) . '</td> <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family: sans-serif; font-size:11px;" >' . self::to_money($subtotal, $lead["currency"]) . '</td> </tr>'; } $total += floatval($products["shipping"]["price"]); $field_data .= '</tbody> <tfoot>'; if (!empty($products["shipping"]["name"])) { $field_data .= ' <tr> <td colspan="2" rowspan="2" style="background-color:#F4F4F4; border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; font-size:11px;"> </td> <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; text-align:right; width:155px; font-family: sans-serif;"><strong style="font-size:12px;">' . $products["shipping"]["name"] . '</strong></td> <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family: sans-serif;"><strong style="font-size:12px;">' . self::to_money($products["shipping"]["price"], $lead["currency"]) . '</strong></td> </tr> '; } $field_data .= ' <tr>'; if (empty($products["shipping"]["name"])) { $field_data .= ' <td colspan="2" style="background-color:#F4F4F4; border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; font-size:11px;"> </td>'; } $field_data .= ' <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; text-align:right; width:155px; font-family: sans-serif;"><strong style="font-size:12px;">' . __("Total:", "gravityforms") . '</strong></td> <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family: sans-serif;"><strong style="font-size:12px;">' . self::to_money($total, $lead["currency"]) . '</strong></td> </tr> </tfoot> </table> </td> </tr>'; } break; } return $field_data; }
private function get_order_data($feed, $form, $entry) { $products = GFCommon::get_product_fields($form, $entry); $payment_field = $feed["meta"]["transactionType"] == "product" ? $feed["meta"]["paymentAmount"] : $feed["meta"]["recurringAmount"]; $setup_fee_field = rgar($feed["meta"], "setupFee_enabled") ? $feed["meta"]["setupFee_product"] : false; $trial_field = rgar($feed["meta"], "trial_enabled") ? rgars($feed, 'meta/trial_product') : false; $amount = 0; $line_items = array(); $fee_amount = 0; $trial_amount = 0; foreach ($products["products"] as $field_id => $product) { $quantity = $product["quantity"] ? $product["quantity"] : 1; $product_price = GFCommon::to_number($product['price']); $options = array(); if (is_array(rgar($product, "options"))) { foreach ($product["options"] as $option) { $options[] = $option["option_name"]; $product_price += $option["price"]; } } if (!empty($trial_field) && $trial_field == $field_id) { $trial_amount = $product_price * $quantity; } else { if (!empty($setup_fee_field) && $setup_fee_field == $field_id) { $fee_amount = $product_price * $quantity; } else { if (is_numeric($payment_field) && $payment_field != $field_id) { continue; } $amount += $product_price * $quantity; $description = ""; if (!empty($options)) { $description = __("options: ", "gravityforms") . " " . implode(", ", $options); } if ($product_price >= 0) { $line_items[] = array("id" => $field_id, "name" => $product["name"], "description" => $description, "quantity" => $quantity, "unit_price" => GFCommon::to_number($product_price)); } } } } if (!empty($products["shipping"]["name"]) && !is_numeric($payment_field)) { $line_items[] = array("id" => "", "name" => $products["shipping"]["name"], "description" => "", "quantity" => 1, "unit_price" => GFCommon::to_number($products["shipping"]["price"])); $amount += $products["shipping"]["price"]; } return array("payment_amount" => $amount, "setup_fee" => $fee_amount, "trial" => $trial_amount, "line_items" => $line_items); }
public static function export_feed($entry, $form, $settings) { $name_fields = array(); foreach ($form["fields"] as $field) { if (RGFormsModel::get_input_type($field) == "name") { $name_fields[] = $field; } } //Creating client self::log_debug("Checking to see if client exists or a new client needs to be created."); $client = self::get_client($form, $entry, $settings, $name_fields); //if client could not be created, ignore invoice and estimate if (!$client) { self::log_debug("Unable to create client, not creating invoice/estimate."); return; } if ($settings["meta"]["alsocreate"] == "invoice") { $invoice_estimate = new FreshBooks_Invoice(); } else { if ($settings["meta"]["alsocreate"] == "estimate") { $invoice_estimate = new FreshBooks_Estimate(); } else { return; } } //don't create invoice or estimate if (!empty($settings["meta"]["ponumber"])) { $invoice_estimate->poNumber = esc_html(self::get_entry_value($settings["meta"]["ponumber"], $entry, $name_fields)); } $invoice_estimate->discount = $settings["meta"]["discount"]; $invoice_estimate->notes = esc_html($settings["meta"]["notes2"]); $invoice_estimate->terms = esc_html($settings["meta"]["terms"]); $total = 0; $lines = array(); if ($settings["meta"]["is_fixed_cost"] == "2") { //creating line items based on pricing fields $products = GFCommon::get_product_fields($form, $entry, true, false); foreach ($products["products"] as $product) { $product_name = $product["name"]; $price = GFCommon::to_number($product["price"]); if (!empty($product["options"])) { $product_name .= " ("; $options = array(); foreach ($product["options"] as $option) { $price += GFCommon::to_number($option["price"]); $options[] = $option["option_name"]; } $product_name .= implode(", ", $options) . ")"; } $subtotal = floatval($product["quantity"]) * $price; $total += $subtotal; $lines[] = array("name" => esc_html($product["name"]), "description" => esc_html($product_name), "unitCost" => $price, "quantity" => $product["quantity"], "amount" => $subtotal); } //adding shipping if form has shipping if (!empty($products["shipping"]["name"])) { $total += floatval($products["shipping"]["price"]); $lines[] = array("name" => esc_html($products["shipping"]["name"]), "description" => esc_html($products["shipping"]["name"]), "unitCost" => $products["shipping"]["price"], "quantity" => 1, "amount" => $products["shipping"]["price"]); } } else { //creating line items based on fixed cost or mapped fields foreach ($settings["meta"]["items"] as $item) { $cost = $settings["meta"]["is_fixed_cost"] ? $item["cost"] : self::get_entry_value($item["cost"], $entry, $name_fields); $cost = self::get_number($cost); $quantity = $settings["meta"]["is_fixed_cost"] ? $item["quantity"] : self::get_entry_value($item["quantity"], $entry, $name_fields); $amount = $quantity * $cost; $total += $amount; $lines[] = array("name" => $item["item_id"], "description" => esc_html($item["description"]), "unitCost" => $cost, "quantity" => $quantity, "amount" => $amount); } } $invoice_estimate->amount = $total; $invoice_estimate->clientId = $client->clientId; $invoice_estimate->firstName = $client->firstName; $invoice_estimate->lastName = $client->lastName; $invoice_estimate->lines = $lines; $invoice_estimate->organization = $client->organization; $invoice_estimate->pStreet1 = $client->pStreet1; $invoice_estimate->pStreet2 = $client->pStreet2; $invoice_estimate->pCity = $client->pCity; $invoice_estimate->pState = $client->pState; $invoice_estimate->pCode = $client->pCode; $invoice_estimate->pCountry = $client->pCountry; self::log_debug("Creating invoice/estimate."); $invoice_estimate->create(); $lastError = $invoice_estimate->lastError; if (empty($lastError)) { self::log_debug("Invoice/estimate created."); } else { self::log_error("The following error occurred when trying to create an invoice/estimate: {$lastError}"); } }
public static function lead_detail($Form, $lead, $allow_display_empty_fields = false, $inline = true, $options = array()) { if (!class_exists('GFEntryList')) { require_once GFCommon::get_base_path() . "/entry_list.php"; } global $current_user, $_gform_directory_approvedcolumn; get_currentuserinfo(); $display_empty_fields = ''; $allow_display_empty_fields = true; if ($allow_display_empty_fields) { $display_empty_fields = @rgget("gf_display_empty_fields", $_COOKIE); } if (empty($options)) { $options = self::directory_defaults(); } // There is no edit link if (isset($_GET['edit']) || RGForms::post("action") === "update") { // Process editing leads $lead = self::edit_lead_detail($Form, $lead, $options); if (RGForms::post("action") !== "update") { return; } } extract($options); ?> <table cellspacing="0" class="widefat fixed entry-detail-view"> <?php $title = str_replace('%%formtitle%%', $Form["title"], str_replace('%%leadid%%', $lead['id'], $entrydetailtitle)); if (!empty($title) && $inline) { ?> <thead> <tr> <th id="details" colspan="2" scope="col"> <?php $title = apply_filters('kws_gf_directory_detail_title', apply_filters('kws_gf_directory_detail_title_' . (int) $lead['id'], array($title, $lead), true), true); if (is_array($title)) { echo $title[0]; } else { echo $title; } ?> </th> </tr> </thead> <?php } ?> <tbody> <?php $count = 0; $has_product_fields = false; $field_count = sizeof($Form["fields"]); $display_value = ''; foreach ($Form["fields"] as $field) { // Don't show fields defined as hide in single. if (!empty($field['hideInSingle'])) { if (self::has_access("gravityforms_directory")) { echo "\n\t\t\t\t\t\t\t\t\t" . '<!-- ' . sprintf(esc_html__('(Admin-only notice) Field #%d not shown: "Hide This Field in Single Entry View" was selected.', 'gravity-forms-addons'), $field['id']) . ' -->' . "\n\n"; } continue; } $count++; $is_last = $count >= $field_count ? true : false; switch (RGFormsModel::get_input_type($field)) { case "section": if (!GFCommon::is_section_empty($field, $Form, $lead) || $display_empty_fields) { $count++; $is_last = $count >= $field_count ? true : false; ?> <tr> <td colspan="2" class="entry-view-section-break<?php echo $is_last ? " lastrow" : ""; ?> "><?php echo esc_html(GFCommon::get_label($field)); ?> </td> </tr> <?php } break; case "captcha": case "html": case "password": case "page": //ignore captcha, html, password, page field break; case "post_image": $value = RGFormsModel::get_lead_field_value($lead, $field); $valueArray = explode("|:|", $value); @(list($url, $title, $caption, $description) = $valueArray); if (!empty($url)) { $value = $display_value = self::render_image_link($url, $lead, $options, $title, $caption, $description); } break; default: //ignore product fields as they will be grouped together at the end of the grid if (GFCommon::is_product_field($field["type"])) { $has_product_fields = true; continue; } $value = RGFormsModel::get_lead_field_value($lead, $field); $display_value = GFCommon::get_lead_field_display($field, $value, $lead["currency"]); break; } // end switch $display_value = apply_filters("gform_entry_field_value", $display_value, $field, $lead, $Form); if ($display_empty_fields || !empty($display_value) || $display_value === "0") { $count++; $is_last = $count >= $field_count && !$has_product_fields ? true : false; $last_row = $is_last ? " lastrow" : ""; $display_value = empty($display_value) && $display_value !== "0" ? " " : $display_value; $content = ' <tr> <th colspan="2" class="entry-view-field-name">' . esc_html(GFCommon::get_label($field)) . '</th> </tr> <tr> <td colspan="2" class="entry-view-field-value' . $last_row . '">' . $display_value . '</td> </tr>'; $content = apply_filters("gform_field_content", $content, $field, $value, $lead["id"], $Form["id"]); echo $content; } } // End foreach $products = array(); if ($has_product_fields) { $products = GFCommon::get_product_fields($Form, $lead); if (!empty($products["products"])) { ?> <tr> <td colspan="2" class="entry-view-field-name"><?php echo apply_filters("gform_order_label_{$Form["id"]}", apply_filters("gform_order_label", __("Order", "gravityforms"), $Form["id"]), $Form["id"]); ?> </td> </tr> <tr> <td colspan="2" class="entry-view-field-value lastrow"> <table class="entry-products" cellspacing="0" width="97%"> <colgroup> <col class="entry-products-col1"> <col class="entry-products-col2"> <col class="entry-products-col3"> <col class="entry-products-col4"> </colgroup> <thead> <th scope="col"><?php echo apply_filters("gform_product_{$Form['id']}", apply_filters("gform_product", __("Product", "gravityforms"), $Form['id']), $Form['id']); ?> </th> <th scope="col" class="textcenter"><?php echo apply_filters("gform_product_qty_{$Form['id']}", apply_filters("gform_product_qty", __("Qty", "gravityforms"), $Form['id']), $Form['id']); ?> </th> <th scope="col"><?php echo apply_filters("gform_product_unitprice_{$Form['id']}", apply_filters("gform_product_unitprice", __("Unit Price", "gravityforms"), $Form['id']), $Form['id']); ?> </th> <th scope="col"><?php echo apply_filters("gform_product_price_{$Form['id']}", apply_filters("gform_product_price", __("Price", "gravityforms"), $Form['id']), $Form['id']); ?> </th> </thead> <tbody> <?php $total = 0; foreach ($products["products"] as $product) { ?> <tr> <td> <div class="product_name"><?php echo esc_html($product["name"]); ?> </div> <ul class="product_options"> <?php $price = GFCommon::to_number($product["price"]); if (is_array(rgar($product, "options"))) { $count = sizeof($product["options"]); $index = 1; foreach ($product["options"] as $option) { $price += GFCommon::to_number($option["price"]); $class = $index == $count ? " class='lastitem'" : ""; $index++; ?> <li<?php echo $class; ?> ><?php echo $option["option_label"]; ?> </li> <?php } } $subtotal = floatval($product["quantity"]) * $price; $total += $subtotal; ?> </ul> </td> <td class="textcenter"><?php echo $product["quantity"]; ?> </td> <td><?php echo GFCommon::to_money($price, $lead["currency"]); ?> </td> <td><?php echo GFCommon::to_money($subtotal, $lead["currency"]); ?> </td> </tr> <?php } $total += floatval($products["shipping"]["price"]); ?> </tbody> <tfoot> <?php if (!empty($products["shipping"]["name"])) { ?> <tr> <td colspan="2" rowspan="2" class="emptycell"> </td> <td class="textright shipping"><?php echo $products["shipping"]["name"]; ?> </td> <td class="shipping_amount"><?php echo GFCommon::to_money($products["shipping"]["price"], $lead["currency"]); ?> </td> </tr> <?php } ?> <tr> <?php if (empty($products["shipping"]["name"])) { ?> <td colspan="2" class="emptycell"> </td> <?php } ?> <td class="textright grandtotal"><?php esc_html_e("Total", "gravityforms"); ?> </td> <td class="grandtotal_amount"><?php echo GFCommon::to_money($total, $lead["currency"]); ?> </td> </tr> </tfoot> </table> </td> </tr> <?php } } // Edit link if (!empty($options['useredit']) && is_user_logged_in() && intval($current_user->ID) === intval($lead['created_by']) || !empty($options['adminedit']) && self::has_access("gravityforms_directory")) { if (!empty($options['adminedit']) && self::has_access("gravityforms_directory")) { $editbuttontext = apply_filters('kws_gf_directory_edit_entry_text_admin', __("Edit Entry", 'gravity-forms-addons')); } else { $editbuttontext = apply_filters('kws_gf_directory_edit_entry_text_user', __("Edit Your Entry", 'gravity-forms-addons')); } ?> <tr> <th scope="row" class="entry-view-field-name"><?php echo esc_html(apply_filters('kws_gf_directory_edit_entry_th', __("Edit", "gravity-forms-addons"))); ?> </th> <td class="entry-view-field-value useredit"><a href="<?php echo add_query_arg(array('edit' => wp_create_nonce('edit' . $lead['id'] . $Form["id"]))); ?> "><?php echo $editbuttontext; ?> </a></td> </tr> <?php } ?> </tbody> </table> <?php }
/** * Get form data * * @since * * @uses RGFormsModel::create_lead() * @uses GFCommon::get_product_fields() * @uses rgpost() * @uses apply_filters() * @uses GFP_Stripe::get_order_info() * * @param $form * @param $feed * * @return mixed|void */ public static function get_form_data($form, $feed) { // get products $tmp_lead = RGFormsModel::create_lead($form); $products = GFCommon::get_product_fields($form, $tmp_lead); $form_data = array(); // getting billing information $form_data['form_title'] = $form['title']; $form_data['name'] = rgpost('input_' . str_replace('.', '_', $feed['meta']['customer_fields']['first_name'])) . ' ' . rgpost('input_' . str_replace('.', '_', $feed['meta']['customer_fields']['last_name'])); $form_data['email'] = rgpost('input_' . str_replace('.', '_', $feed['meta']['customer_fields']['email'])); $form_data['address1'] = rgpost('input_' . str_replace('.', '_', $feed['meta']['customer_fields']['address1'])); $form_data['address2'] = rgpost('input_' . str_replace('.', '_', $feed['meta']['customer_fields']['address2'])); $form_data['city'] = rgpost('input_' . str_replace('.', '_', $feed['meta']['customer_fields']['city'])); $form_data['state'] = rgpost('input_' . str_replace('.', '_', $feed['meta']['customer_fields']['state'])); $form_data['zip'] = rgpost('input_' . str_replace('.', '_', $feed['meta']['customer_fields']['zip'])); $form_data['country'] = rgpost('input_' . str_replace('.', '_', $feed['meta']['customer_fields']['country'])); $form_data["credit_card"] = rgpost('stripeToken'); $form_data = apply_filters('gfp_stripe_get_form_data', $form_data, $feed, $products); $order_info_args = ''; $order_info = self::$_this->get_order_info($products, apply_filters('gfp_stripe_get_form_data_order_info', $order_info_args, $feed)); $form_data["line_items"] = $order_info["line_items"]; $form_data["amount"] = $order_info["amount"]; return $form_data; }
public static function get_product_billing_data($form, $lead, $config) { // get products $products = GFCommon::get_product_fields($form, $lead); $data = array(); $data["billing"] = array('DESC' => ''); $data["products"] = $products; $data["amount"] = 0; $item = 0; //------------------------------------------------------ //creating line items and recurring description $recurring_amount_field = $config["meta"]["recurring_amount_field"]; foreach ($products["products"] as $product_id => $product) { if (!self::include_in_total($product_id, $config)) { continue; } $product_amount = GFCommon::to_number($product["price"]); if (is_array(rgar($product, "options"))) { foreach ($product["options"] as $option) { $product_amount += $option["price"]; } } $data["amount"] += $product_amount * $product["quantity"]; //adding line items if ($config["meta"]["type"] == "product") { $data["billing"]['L_NAME' . $item] = $product["name"]; $data["billing"]['L_DESC' . $item] = $product["name"]; $data["billing"]['L_AMT' . $item] = $product_amount; $data["billing"]['L_NUMBER' . $item] = $item + 1; $data["billing"]['L_QTY' . $item] = $product["quantity"]; } else { //adding recurring description $data["billing"]['DESC'] .= $item > 1 ? ", " . $product["name"] : $product["name"]; } $item++; } //adding shipping information if feed is configured for products and services or a subscription based on the form total if (!empty($products["shipping"]["name"]) && ($config["meta"]["type"] == "product" || $recurring_amount_field == "all")) { if ($config["meta"]["type"] == "product") { $data["billing"]['L_NAME' . $item] = $products["shipping"]["name"]; $data["billing"]['L_AMT' . $item] = $products["shipping"]["price"]; $data["billing"]['L_NUMBER' . $item] = $item + 1; $data["billing"]['L_QTY' . $item] = 1; } $data["amount"] += $products["shipping"]["price"]; } $data["line_items"] = $item; return $data; }
private static function get_donation_query_string($form, $entry) { $fields = ""; //getting all donation fields $donations = GFCommon::get_fields_by_type($form, array("donation")); $total = 0; $purpose = ""; foreach ($donations as $donation) { $value = RGFormsModel::get_lead_field_value($entry, $donation); list($name, $price) = explode("|", $value); if (empty($price)) { $price = $name; $name = $donation["label"]; } $purpose .= $name . ", "; $price = GFCommon::to_number($price); $total += $price; } //using product fields for donation if there aren't any legacy donation fields in the form if ($total == 0) { //getting all product fields $products = GFCommon::get_product_fields($form, $entry, true); foreach ($products["products"] as $product) { $options = ""; if (is_array($product["options"]) && !empty($product["options"])) { $options = " ("; foreach ($product["options"] as $option) { $options .= $option["option_name"] . ", "; } $options = substr($options, 0, strlen($options) - 2) . ")"; } $quantity = GFCommon::to_number($product["quantity"]); $quantity_label = $quantity > 1 ? $quantity . " " : ""; $purpose .= $quantity_label . $product["name"] . $options . ", "; } $total = GFCommon::get_order_total($form, $entry); } if (!empty($purpose)) { $purpose = substr($purpose, 0, strlen($purpose) - 2); } $purpose = urlencode($purpose); //truncating to maximum length allowed by Paytm Form if (strlen($purpose) > 127) { $purpose = substr($purpose, 0, 124) . "..."; } $fields = "&amount={$total}&desc={$purpose}"; return $total > 0 ? $fields : false; }
public function export_feed($entry, $form, $feed) { $name_fields = array(); foreach ($form['fields'] as $field) { if (RGFormsModel::get_input_type($field) == 'name') { $name_fields[] = $field; } } //Creating client $this->log_debug(__METHOD__ . '(): Checking to see if client exists or a new client needs to be created.'); $client = $this->get_client($form, $entry, $feed, $name_fields); //if client could not be created, ignore invoice and estimate if (!$client) { $this->log_debug(__METHOD__ . '(): Unable to create client, not creating invoice/estimate.'); return; } $type = rgars($feed, 'meta/alsoCreate'); if ($type == 'invoice') { $invoice_estimate = new FreshBooks_Invoice(); } elseif ($type == 'estimate') { $invoice_estimate = new FreshBooks_Estimate(); } else { return; } //don't create invoice or estimate if (!empty($feed['meta']['poNumber'])) { $po_number = esc_html($this->get_entry_value($feed['meta']['poNumber'], $entry, $name_fields)); //trim po_number to 25 characters because FreshBooks only allows 25 and more will cause invoice/estimate to not be created $invoice_estimate->poNumber = substr($po_number, 0, 25); } $invoice_estimate->discount = $feed['meta']['discount']; $invoice_estimate->notes = esc_html(GFCommon::replace_variables($feed['meta']['notes2'], $form, $entry, false, false, false, 'text')); $invoice_estimate->terms = esc_html($feed['meta']['terms']); $total = 0; $lines = array(); if ($feed['meta']['lineItems'] == 'pricing') { $this->log_debug(__METHOD__ . '(): Creating line items based on pricing fields.'); //creating line items based on pricing fields $products = GFCommon::get_product_fields($form, $entry, true, false); foreach ($products['products'] as $product) { $product_name = $product['name']; $price = GFCommon::to_number($product['price']); if (!empty($product['options'])) { $product_name .= ' ('; $options = array(); foreach ($product['options'] as $option) { $price += GFCommon::to_number($option['price']); $options[] = $option['option_name']; } $product_name .= implode(', ', $options) . ')'; } $subtotal = floatval($product['quantity']) * $price; $total += $subtotal; $lines[] = array('name' => esc_html($product['name']), 'description' => esc_html($product_name), 'unitCost' => $price, 'quantity' => $product['quantity'], 'amount' => $subtotal); } //adding shipping if form has shipping if (!empty($products['shipping']['name'])) { $total += floatval($products['shipping']['price']); $lines[] = array('name' => esc_html($products['shipping']['name']), 'description' => esc_html($products['shipping']['name']), 'unitCost' => $products['shipping']['price'], 'quantity' => 1, 'amount' => $products['shipping']['price']); } } else { $i = 0; $this->log_debug(__METHOD__ . '(): Creating line items based on fixed costs and quantities.'); //creating line items based on fixed cost or mapped fields /** * Determines if the item ID should be used instead of the item name. * * @since 2.0 * * @param bool false Defaults to false. Set to the item ID to use it. */ $send_item_id = apply_filters('gform_freshbooks_send_item_id_for_fixed_dynamic', false); foreach ($feed['meta']['item'] as $item) { $cost = $feed['meta']['lineItems'] == 'fixed' ? $feed['meta']['cost'][$i] : $this->get_entry_value($feed['meta']['cost'][$i], $entry, $name_fields); $cost = $this->get_number($cost); $quantity = $feed['meta']['lineItems'] == 'fixed' ? $feed['meta']['quantity'][$i] : $this->get_entry_value($feed['meta']['quantity'][$i], $entry, $name_fields); $amount = $quantity * $cost; $total += $amount; if ($send_item_id) { //item id is what is saved in the database, use it $item_name = $item; } else { //get item name using saved item id $item_name = $this->get_item_name($item); if (empty($item_name)) { //default to item id if no name found $item_name = $item; } } $lines[] = array('name' => $item_name, 'description' => esc_html($feed['meta']['description'][$i]), 'unitCost' => $cost, 'quantity' => $quantity, 'amount' => $amount); $i++; } } $invoice_estimate->amount = $total; $invoice_estimate->clientId = $client->clientId; $invoice_estimate->firstName = $client->firstName; $invoice_estimate->lastName = $client->lastName; $invoice_estimate->lines = $lines; $invoice_estimate->organization = $client->organization; $invoice_estimate->pStreet1 = $client->pStreet1; $invoice_estimate->pStreet2 = $client->pStreet2; $invoice_estimate->pCity = $client->pCity; $invoice_estimate->pState = $client->pState; $invoice_estimate->pCode = $client->pCode; $invoice_estimate->pCountry = $client->pCountry; /** * Filters the invoice estimate data before it is created. * * @since 2.2.3 Added the $feed parameter * @since 2.1 Initial * * @param object $invoice_estimate The invoice estimate object * @param array $form The Form object * @param array $entry The Entry object * @param array $feed The Feed object */ $invoice_estimate = apply_filters('gform_freshbooks_args_pre_create', $invoice_estimate, $form, $entry, $feed); $this->log_debug(__METHOD__ . '(): Creating invoice/estimate => ' . print_r($invoice_estimate, 1)); $invoice_estimate->create(); $lastError = $invoice_estimate->lastError; if (empty($lastError)) { $this->log_debug(__METHOD__ . '(): Invoice/estimate created.'); $id = $type == 'invoice' ? $invoice_estimate->invoiceId : $invoice_estimate->estimateId; $createPayment = rgar($feed['meta'], 'createPayment'); if (!$this->has_product_feed($form, $entry) || !$createPayment) { $this->handle_note_and_send_by_email(rgar($feed['meta'], 'sendByEmail'), $type, $id, $entry); } elseif ($createPayment) { gform_update_meta($entry['id'], 'freshbooks_invoice_id', $id); } } else { $this->log_error(__METHOD__ . "(): The following error occurred when trying to create an invoice/estimate: {$lastError}"); } }
public static function get_submitted_pricing_fields($form, $lead) { $field_data .= '<tr bgcolor="#EAF2FA"> <td colspan="2"> <font style="font-family:verdana,sans-serif; font-size:12px;"><strong>' . apply_filters("gform_order_label_{$form["id"]}", apply_filters("gform_order_label", __("Order", "gravityforms"), $form["id"]), $form["id"]) . '</strong></font> </td> </tr> <tr bgcolor="#FFFFFF"> <td width="20"> </td> <td> <table cellspacing="0" width="97%" style="border-left:1px solid #DFDFDF; border-top:1px solid #DFDFDF"> <thead> <th style="background-color:#F4F4F4; border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; font-family:verdana,sans-serif; font-size:12px; text-align:left">' . __("Product", "gravityforms") . '</th> <th style="background-color:#F4F4F4; border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:50px; font-family:verdana,sans-serif; font-size:12px; text-align:center">' . __("Qty", "gravityforms") . '</th> <th style="background-color:#F4F4F4; border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family:verdana,sans-serif; font-size:12px; text-align:left">' . __("Unit Price", "gravityforms") . '</th> <th style="background-color:#F4F4F4; border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family:verdana,sans-serif; font-size:12px; text-align:left">' . __("Price", "gravityforms") . '</th> </thead> <tbody>'; $products = GFCommon::get_product_fields($form, $lead); $total = 0; foreach ($products["products"] as $product) { $field_data .= '<tr> <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; font-family:verdana,sans-serif; font-size:11px;" > <strong style="color:#BF461E; font-size:12px; margin-bottom:5px">' . esc_html($product["name"]) . '</strong> <ul style="margin:0">'; $price = self::to_number($product["price"]); if (is_array($product["options"])) { foreach ($product["options"] as $option) { $price += self::to_number($option["price"]); $field_data .= '<li style="padding:4px 0 4px 0">' . $option["option_label"] . '</li>'; } } $subtotal = floatval($product["quantity"]) * $price; $total += $subtotal; $field_data .= '</ul> </td> <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; text-align:center; width:50px; font-family:verdana,sans-serif; font-size:11px;" >' . $product["quantity"] . '</td> <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family:verdana,sans-serif; font-size:11px;" >' . self::to_money($price, $lead["currency"]) . '</td> <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family:verdana,sans-serif; font-size:11px;" >' . self::to_money($subtotal, $lead["currency"]) . '</td> </tr>'; } $total += floatval($products["shipping"]["price"]); $field_data .= '</tbody> <tfoot>'; if (!empty($products["shipping"]["name"])) { $field_data .= ' <tr> <td colspan="2" rowspan="2" style="background-color:#F4F4F4; border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; font-size:11px;"> </td> <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; text-align:right; width:155px; font-family:verdana,sans-serif;"><strong style="font-size:12px;">' . $products["shipping"]["name"] . '</strong></td> <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family:verdana,sans-serif;"><strong style="font-size:12px;">' . self::to_money($products["shipping"]["price"], $lead["currency"]) . '</strong></td> </tr> '; } $field_data .= ' <tr>'; if (empty($products["shipping"]["name"])) { $field_data .= ' <td colspan="2" style="background-color:#F4F4F4; border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; font-size:11px;"> </td>'; } $field_data .= ' <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; text-align:right; width:155px; font-family:verdana,sans-serif;"><strong style="font-size:12px;">' . __("Total:", "gravityforms") . '</strong></td> <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family:verdana,sans-serif;"><strong style="font-size:12px;">' . self::to_money($total, $lead["currency"]) . '</strong></td> </tr> </tfoot> </table> </td> </tr>'; return $field_data; }
/** * Get items * * @see Pronamic_Pay_PaymentDataInterface::get_items() * @return Pronamic_IDeal_Items */ public function get_items() { $items = new Pronamic_IDeal_Items(); $number = 0; // Products $products = GFCommon::get_product_fields($this->form, $this->lead); foreach ($products['products'] as $product) { $description = $product['name']; $price = GFCommon::to_number($product['price']); $quantity = $product['quantity']; $item = new Pronamic_IDeal_Item(); $item->setNumber($number++); $item->setDescription($description); $item->setPrice($price); $item->setQuantity($quantity); $items->addItem($item); if (isset($product['options']) && is_array($product['options'])) { foreach ($product['options'] as $option) { $description = $option['option_label']; $price = GFCommon::to_number($option['price']); $item = new Pronamic_IDeal_Item(); $item->setNumber($number++); $item->setDescription($description); $item->setPrice($price); $item->setQuantity($quantity); // Product quantity $items->addItem($item); } } } // Shipping if (isset($products['shipping'])) { $shipping = $products['shipping']; if (isset($shipping['price']) && !empty($shipping['price'])) { $description = $shipping['name']; $price = GFCommon::to_number($shipping['price']); $quantity = 1; $item = new Pronamic_IDeal_Item(); $item->setNumber($number++); $item->setDescription($description); $item->setPrice($price); $item->setQuantity($quantity); $items->addItem($item); } } // Donations $donation_fields = GFCommon::get_fields_by_type($this->form, array('donation')); foreach ($donation_fields as $i => $field) { $value = RGFormsModel::get_lead_field_value($this->lead, $field); if (!empty($value)) { $description = ''; if (isset($field['adminLabel']) && !empty($field['adminLabel'])) { $description = $field['adminLabel']; } elseif (isset($field['label'])) { $description = $field['label']; } $separator_position = strpos($value, '|'); if (false !== $separator_position) { $label = substr($value, 0, $separator_position); $value = substr($value, $separator_position + 1); $description .= ' - ' . $label; } $price = GFCommon::to_number($value); $quantity = 1; $item = new Pronamic_IDeal_Item(); $item->setNumber($i); $item->setDescription($description); $item->setQuantity($quantity); $item->setPrice($price); $items->addItem($item); } } return $items; }
protected function get_order_data($feed, $form, $entry) { $products = GFCommon::get_product_fields($form, $entry); $payment_field = $feed["meta"]["transactionType"] == "product" ? $feed["meta"]["paymentAmount"] : $feed["meta"]["recurringAmount"]; $setup_fee_field = rgar($feed["meta"], "setupFee_enabled") ? $feed["meta"]["setupFee_product"] : false; $trial_field = rgar($feed["meta"], "trial_enabled") ? rgars($feed, 'meta/trial_product') : false; $amount = 0; $line_items = array(); $discounts = array(); $fee_amount = 0; $trial_amount = 0; foreach ($products["products"] as $field_id => $product) { $quantity = $product["quantity"] ? $product["quantity"] : 1; $product_price = GFCommon::to_number($product['price']); $options = array(); if (is_array(rgar($product, "options"))) { foreach ($product["options"] as $option) { if (isset($option['option_name'])) { $options[] = $option["option_name"]; $product_price += $option["price"]; } } } $is_trial_or_setup_fee = false; if (!empty($trial_field) && $trial_field == $field_id) { $trial_amount = $product_price * $quantity; $is_trial_or_setup_fee = true; } else { if (!empty($setup_fee_field) && $setup_fee_field == $field_id) { $fee_amount = $product_price * $quantity; $is_trial_or_setup_fee = true; } } //Do not add to line items if the payment field selected in the feed is not the current field. if (is_numeric($payment_field) && $payment_field != $field_id) { continue; } //Do not add to line items if the payment field is set to "Form Total" and the current field was used for trial or setup fee. if ($is_trial_or_setup_fee && !is_numeric($payment_field)) { continue; } $amount += $product_price * $quantity; $description = ""; if (!empty($options)) { $description = __("options: ", "gravityforms") . " " . implode(", ", $options); } if ($product_price >= 0) { $line_items[] = array("id" => $field_id, "name" => $product["name"], "description" => $description, "quantity" => $quantity, "unit_price" => GFCommon::to_number($product_price), "options" => rgar($product, "options")); } else { $discounts[] = array("id" => $field_id, "name" => $product["name"], "description" => $description, "quantity" => $quantity, "unit_price" => GFCommon::to_number($product_price), "options" => rgar($product, "options")); } } if ($trial_field == "enter_amount") { $trial_amount = rgar($feed["meta"], "trial_amount") ? rgar($feed["meta"], "trial_amount") : 0; } if (!empty($products["shipping"]["name"]) && !is_numeric($payment_field)) { $line_items[] = array("id" => "", "name" => $products["shipping"]["name"], "description" => "", "quantity" => 1, "unit_price" => GFCommon::to_number($products["shipping"]["price"]), "is_shipping" => 1); $amount += $products["shipping"]["price"]; } return array("payment_amount" => $amount, "setup_fee" => $fee_amount, "trial" => $trial_amount, "line_items" => $line_items, "discounts" => $discounts); }
private static function get_product_array($form, $lead, $has_product_fields, $form_array) { $currency_type = method_exists('GFCommon', 'is_currency_decimal_dot') ? GFCommon::is_currency_decimal_dot() : PDF_Common::is_currency_decimal_dot(); $currency_format = $currency_type ? 'decimal_dot' : 'decimal_comma'; if ($has_product_fields) { $products = GFCommon::get_product_fields($form, $lead, true); /* check that there are actual product fields */ if (sizeof($products['products']) > 0) { /* * Set up our variables */ $total = 0; $subtotal = 0; foreach ($products['products'] as $id => $product) { $price = GFCommon::to_number($product['price']); /* add all options to total price */ if (is_array(rgar($product, 'options'))) { foreach ($product['options'] as $option) { $price += GFCommon::to_number($option['price']); } } /* calculate subtotal */ $subtotal = floatval($product['quantity']) * $price; $total += $subtotal; /* * Check if we should include options */ $options = isset($product['options']) ? $product['options'] : array(); /* * Add formated price for each product option */ foreach ($options as &$o) { if (is_numeric($o['price'])) { $o['price_formatted'] = GFCommon::format_number($o['price'], 'currency'); } } /* * Store product in $form_array array */ $form_array['products'][$id] = array('name' => esc_html($product['name']), 'price' => esc_html($product['price']), 'price_unformatted' => GFCommon::clean_number($product['price'], $currency_format), 'options' => $options, 'quantity' => $product['quantity'], 'subtotal' => $subtotal, 'subtotal_formatted' => GFCommon::format_number($subtotal, 'currency')); } /* Increment total */ $total += floatval($products['shipping']['price']); $subtotal = $total - floatval($products['shipping']['price']); /* add totals to form data */ $form_array['products_totals'] = array('subtotal' => $subtotal, 'shipping' => $products['shipping']['price'], 'total' => $total, 'shipping_formatted' => GFCommon::format_number($products['shipping']['price'], 'currency'), 'subtotal_formatted' => GFCommon::format_number($subtotal, 'currency'), 'total_formatted' => GFCommon::format_number($total, 'currency')); } } return $form_array; }
public static function refresh_product_cache($form, $lead, $use_choice_text = false, $use_admin_label = false) { $cache_options = array(array(false, false), array(false, true), array(true, false), array(true, true)); foreach ($form["fields"] as $field) { if (GFCommon::has_field_calculation($field)) { //deleting field value cache for calculated fields $cache_key = "GFFormsModel::get_lead_field_value_" . $lead["id"] . "_" . $field["id"]; GFCache::delete($cache_key); } } foreach ($cache_options as $cache_option) { list($use_choice_text, $use_admin_label) = $cache_option; if (gform_get_meta(rgar($lead, 'id'), "gform_product_info_{$use_choice_text}_{$use_admin_label}")) { gform_delete_meta(rgar($lead, 'id'), "gform_product_info_{$use_choice_text}_{$use_admin_label}"); GFCommon::get_product_fields($form, $lead, $use_choice_text, $use_admin_label); } } }
private static function get_form_data($form, $config) { // get products $tmp_lead = RGFormsModel::create_lead($form); $products = GFCommon::get_product_fields($form, $tmp_lead); $form_data = array(); // getting billing information $form_data["form_title"] = $form["title"]; $form_data["email"] = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["email"])); $form_data["address1"] = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["address1"])); $form_data["address2"] = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["address2"])); $form_data["city"] = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["city"])); $form_data["state"] = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["state"])); $form_data["zip"] = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["zip"])); $form_data["country"] = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["country"])); $card_field = self::get_creditcard_field($form); $form_data["card_number"] = rgpost("input_{$card_field["id"]}_1"); $form_data["expiration_date"] = rgpost("input_{$card_field["id"]}_2"); $form_data["security_code"] = rgpost("input_{$card_field["id"]}_3"); $form_data["card_name"] = rgpost("input_{$card_field["id"]}_5"); $names = explode(" ", $form_data["card_name"]); $form_data["first_name"] = rgar($names, 0); $form_data["last_name"] = ""; if (count($names) > 0) { unset($names[0]); $form_data["last_name"] = implode(" ", $names); } if (!empty($config["meta"]["setup_fee_enabled"])) { $order_info = self::get_order_info($products, rgar($config["meta"], "recurring_amount_field"), rgar($config["meta"], "setup_fee_amount_field")); } else { $order_info = self::get_order_info($products, rgar($config["meta"], "recurring_amount_field"), ""); } $form_data["line_items"] = $order_info["line_items"]; $form_data["amount"] = $order_info["amount"]; $form_data["fee_amount"] = $order_info["fee_amount"]; // need an easy way to filter the the order info as it is not modifiable once it is added to the transaction object $form_data = apply_filters("gform_authorizenet_form_data_{$form['id']}", apply_filters('gform_authorizenet_form_data', $form_data, $form, $config), $form, $config); return $form_data; }
protected function get_order_data($feed, $form, $entry) { $products = GFCommon::get_product_fields($form, $entry); $payment_field = $feed['meta']['transactionType'] == 'product' ? rgars($feed, 'meta/paymentAmount') : rgars($feed, 'meta/recurringAmount'); $setup_fee_field = rgar($feed['meta'], 'setupFee_enabled') ? $feed['meta']['setupFee_product'] : false; $trial_field = rgar($feed['meta'], 'trial_enabled') ? rgars($feed, 'meta/trial_product') : false; $amount = 0; $line_items = array(); $discounts = array(); $fee_amount = 0; $trial_amount = 0; foreach ($products['products'] as $field_id => $product) { $quantity = $product['quantity'] ? $product['quantity'] : 1; $product_price = GFCommon::to_number($product['price'], $entry['currency']); $options = array(); if (is_array(rgar($product, 'options'))) { foreach ($product['options'] as $option) { $options[] = $option['option_name']; $product_price += $option['price']; } } $is_trial_or_setup_fee = false; if (!empty($trial_field) && $trial_field == $field_id) { $trial_amount = $product_price * $quantity; $is_trial_or_setup_fee = true; } elseif (!empty($setup_fee_field) && $setup_fee_field == $field_id) { $fee_amount = $product_price * $quantity; $is_trial_or_setup_fee = true; } //Do not add to line items if the payment field selected in the feed is not the current field. if (is_numeric($payment_field) && $payment_field != $field_id) { continue; } //Do not add to line items if the payment field is set to "Form Total" and the current field was used for trial or setup fee. if ($is_trial_or_setup_fee && !is_numeric($payment_field)) { continue; } $amount += $product_price * $quantity; $description = ''; if (!empty($options)) { $description = esc_html__('options: ', 'gravityforms') . ' ' . implode(', ', $options); } if ($product_price >= 0) { $line_items[] = array('id' => $field_id, 'name' => $product['name'], 'description' => $description, 'quantity' => $quantity, 'unit_price' => GFCommon::to_number($product_price, $entry['currency']), 'options' => rgar($product, 'options')); } else { $discounts[] = array('id' => $field_id, 'name' => $product['name'], 'description' => $description, 'quantity' => $quantity, 'unit_price' => GFCommon::to_number($product_price, $entry['currency']), 'options' => rgar($product, 'options')); } } if ($trial_field == 'enter_amount') { $trial_amount = rgar($feed['meta'], 'trial_amount') ? GFCommon::to_number(rgar($feed['meta'], 'trial_amount'), $entry['currency']) : 0; } if (!empty($products['shipping']['name']) && !is_numeric($payment_field)) { $line_items[] = array('id' => $products['shipping']['id'], 'name' => $products['shipping']['name'], 'description' => '', 'quantity' => 1, 'unit_price' => GFCommon::to_number($products['shipping']['price'], $entry['currency']), 'is_shipping' => 1); $amount += $products['shipping']['price']; } return array('payment_amount' => $amount, 'setup_fee' => $fee_amount, 'trial' => $trial_amount, 'line_items' => $line_items, 'discounts' => $discounts); }
public function has_paypal_payment($feed, $form, $entry) { $products = GFCommon::get_product_fields($form, $entry); $payment_field = $feed['meta']['transactionType'] == 'product' ? $feed['meta']['paymentAmount'] : $feed['meta']['recurringAmount']; $setup_fee_field = rgar($feed['meta'], 'setupFee_enabled') ? $feed['meta']['setupFee_product'] : false; $trial_field = rgar($feed['meta'], 'trial_enabled') ? rgars($feed, 'meta/trial_product') : false; $amount = 0; $line_items = array(); $discounts = array(); $fee_amount = 0; $trial_amount = 0; foreach ($products['products'] as $field_id => $product) { $quantity = $product['quantity'] ? $product['quantity'] : 1; $product_price = GFCommon::to_number($product['price']); $options = array(); if (is_array(rgar($product, 'options'))) { foreach ($product['options'] as $option) { $options[] = $option['option_name']; $product_price += $option['price']; } } $is_trial_or_setup_fee = false; if (!empty($trial_field) && $trial_field == $field_id) { $trial_amount = $product_price * $quantity; $is_trial_or_setup_fee = true; } else { if (!empty($setup_fee_field) && $setup_fee_field == $field_id) { $fee_amount = $product_price * $quantity; $is_trial_or_setup_fee = true; } } //Do not add to line items if the payment field selected in the feed is not the current field. if (is_numeric($payment_field) && $payment_field != $field_id) { continue; } //Do not add to line items if the payment field is set to "Form Total" and the current field was used for trial or setup fee. if ($is_trial_or_setup_fee && !is_numeric($payment_field)) { continue; } $amount += $product_price * $quantity; } if (!empty($products['shipping']['name']) && !is_numeric($payment_field)) { $line_items[] = array('id' => '', 'name' => $products['shipping']['name'], 'description' => '', 'quantity' => 1, 'unit_price' => GFCommon::to_number($products['shipping']['price']), 'is_shipping' => 1); $amount += $products['shipping']['price']; } return $amount > 0; }
public static function get_paypal_payment_amount($form, $entry, $paypal_config) { //TODO: need to support old "paypal_config" format as well as new format when delayed payment suported feed addons are released $products = GFCommon::get_product_fields($form, $entry, true); $recurring_field = rgar($paypal_config['meta'], 'recurring_amount_field'); $total = 0; foreach ($products['products'] as $id => $product) { if ($paypal_config['meta']['type'] != 'subscription' || $recurring_field == $id || $recurring_field == 'all') { $price = GFCommon::to_number($product['price']); if (is_array(rgar($product, 'options'))) { foreach ($product['options'] as $option) { $price += GFCommon::to_number($option['price']); } } $total += $price * $product['quantity']; } } if ($recurring_field == 'all' && !empty($products['shipping']['price'])) { $total += floatval($products['shipping']['price']); } return $total; }
public static function get_submitted_pricing_fields($form, $lead, $format, $use_text = true, $use_admin_label = false) { $form_id = $form['id']; $order_label = gf_apply_filters('gform_order_label', $form_id, esc_html__('Order', 'gravityforms'), $form['id']); $products = GFCommon::get_product_fields($form, $lead, $use_text, $use_admin_label); $total = 0; $field_data = ''; switch ($format) { case 'text': if (!empty($products['products'])) { $field_data = "--------------------------------\n" . $order_label . "\n\n"; foreach ($products['products'] as $product) { $product_name = $product['quantity'] . ' ' . $product['name']; $price = self::to_number($product['price']); if (!empty($product['options'])) { $product_name .= ' ('; $options = array(); foreach ($product['options'] as $option) { $price += self::to_number($option['price']); $options[] = $option['option_name']; } $product_name .= implode(', ', $options) . ')'; } $subtotal = floatval($product['quantity']) * $price; $total += $subtotal; $field_data .= "{$product_name}: " . self::to_money($subtotal, $lead['currency']) . "\n\n"; } $total += floatval($products['shipping']['price']); if (!empty($products['shipping']['name'])) { $field_data .= $products['shipping']['name'] . ': ' . self::to_money($products['shipping']['price'], $lead['currency']) . "\n\n"; } $field_data .= esc_html__('Total', 'gravityforms') . ': ' . self::to_money($total, $lead['currency']) . "\n\n"; } break; default: if (!empty($products['products'])) { $field_data = '<tr bgcolor="#EAF2FA"> <td colspan="2"> <font style="font-family: sans-serif; font-size:12px;"><strong>' . $order_label . '</strong></font> </td> </tr> <tr bgcolor="#FFFFFF"> <td width="20"> </td> <td> <table cellspacing="0" width="97%" style="border-left:1px solid #DFDFDF; border-top:1px solid #DFDFDF"> <thead> <th style="background-color:#F4F4F4; border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; font-family: sans-serif; font-size:12px; text-align:left">' . gf_apply_filters('gform_product', $form_id, esc_html__('Product', 'gravityforms'), $form_id) . '</th> <th style="background-color:#F4F4F4; border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:50px; font-family: sans-serif; font-size:12px; text-align:center">' . gf_apply_filters('gform_product_qty', $form_id, esc_html__('Qty', 'gravityforms'), $form_id) . '</th> <th style="background-color:#F4F4F4; border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family: sans-serif; font-size:12px; text-align:left">' . gf_apply_filters('gform_product_unitprice', $form_id, esc_html__('Unit Price', 'gravityforms'), $form_id) . '</th> <th style="background-color:#F4F4F4; border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family: sans-serif; font-size:12px; text-align:left">' . gf_apply_filters('gform_product_price', $form_id, esc_html__('Price', 'gravityforms'), $form_id) . '</th> </thead> <tbody>'; foreach ($products['products'] as $product) { $field_data .= '<tr> <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; font-family: sans-serif; font-size:11px;" > <strong style="color:#BF461E; font-size:12px; margin-bottom:5px">' . $product['name'] . '</strong> <ul style="margin:0">'; $price = self::to_number($product['price']); if (is_array(rgar($product, 'options'))) { foreach ($product['options'] as $option) { $price += self::to_number($option['price']); $field_data .= '<li style="padding:4px 0 4px 0">' . $option['option_label'] . '</li>'; } } $subtotal = floatval($product['quantity']) * $price; $total += $subtotal; $field_data .= '</ul> </td> <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; text-align:center; width:50px; font-family: sans-serif; font-size:11px;" >' . $product['quantity'] . '</td> <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family: sans-serif; font-size:11px;" >' . self::to_money($price, $lead['currency']) . '</td> <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family: sans-serif; font-size:11px;" >' . self::to_money($subtotal, $lead['currency']) . '</td> </tr>'; } $total += floatval($products['shipping']['price']); $field_data .= '</tbody> <tfoot>'; if (!empty($products['shipping']['name'])) { $field_data .= ' <tr> <td colspan="2" rowspan="2" style="background-color:#F4F4F4; border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; font-size:11px;"> </td> <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; text-align:right; width:155px; font-family: sans-serif;"><strong style="font-size:12px;">' . $products['shipping']['name'] . '</strong></td> <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family: sans-serif;"><strong style="font-size:12px;">' . self::to_money($products['shipping']['price'], $lead['currency']) . '</strong></td> </tr> '; } $field_data .= ' <tr>'; if (empty($products['shipping']['name'])) { $field_data .= ' <td colspan="2" style="background-color:#F4F4F4; border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; font-size:11px;"> </td>'; } $field_data .= ' <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; text-align:right; width:155px; font-family: sans-serif;"><strong style="font-size:12px;">' . esc_html__('Total:', 'gravityforms') . '</strong></td> <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family: sans-serif;"><strong style="font-size:12px;">' . self::to_money($total, $lead['currency']) . '</strong></td> </tr> </tfoot> </table> </td> </tr>'; } break; } return $field_data; }
private static function get_subscription_query_string($config, $form, $entry) { //getting all product fields $products = GFCommon::get_product_fields($form, $entry, true); $item_name = ""; $name_without_options = ""; $amount = 0; foreach ($products["products"] as $id => $product) { if ($id == $config["meta"]["recurring_amount_field"] || $config["meta"]["recurring_amount_field"] == "all") { $options = ""; $price = GFCommon::to_number($product["price"]); if (isset($product["options"]) && is_array($product["options"]) && !empty($product["options"])) { $options = " ("; foreach ($product["options"] as $option) { $options .= $option["option_name"] . ", "; $price += GFCommon::to_number($option["price"]); } $options = substr($options, 0, strlen($options) - 2) . ")"; } $quantity = GFCommon::to_number($product["quantity"]); $quantity_label = $quantity > 1 ? $quantity . " " : ""; $item_name .= $quantity_label . $product["name"] . $options . ", "; $name_without_options .= $product["name"] . ", "; $amount += $price * $quantity; } } //adding shipping if feed was configured with "Form Total" if ($config["meta"]["recurring_amount_field"] == "all" && !empty($products["shipping"]["price"])) { $amount += floatval($products["shipping"]["price"]); } if (!empty($item_name)) { $item_name = substr($item_name, 0, strlen($item_name) - 2); } //if name is larger than max, remove options from it. if (strlen($item_name) > 127) { $item_name = substr($name_without_options, 0, strlen($name_without_options) - 2); //truncating name to maximum allowed size if (strlen($item_name) > 127) { $item_name = substr($item_name, 0, 124) . "..."; } } $item_name = urlencode($item_name); $trial = ""; if ($config["meta"]["trial_period_enabled"]) { $trial_amount = GFCommon::to_number($config["meta"]["trial_amount"]); if (empty($trial_amount)) { $trial_amount = 0; } $trial = "&a1={$trial_amount}&p1={$config["meta"]["trial_period_number"]}&t1={$config["meta"]["trial_period_type"]}"; } $recurring_times = !empty($config["meta"]["recurring_times"]) ? "&srt={$config["meta"]["recurring_times"]}" : ""; $recurring_retry = $config["meta"]["recurring_retry"] ? "1" : "0"; $query_string = "&cmd=_xclick-subscriptions&item_name={$item_name}{$trial}&a3={$amount}&p3={$config["meta"]["billing_cycle_number"]}&t3={$config["meta"]["billing_cycle_type"]}&src=1&sra={$recurring_retry}{$recurring_times}"; return $amount > 0 ? $query_string : false; }
public static function get_payment_amount($form, $entry, $paypal_config) { $products = GFCommon::get_product_fields($form, $entry, true); $recurring_field = rgar($paypal_config["meta"], "recurring_amount_field"); $total = 0; foreach ($products["products"] as $id => $product) { if ($paypal_config["meta"]["type"] != "subscription" || $recurring_field == $id || $recurring_field == "all") { $price = GFCommon::to_number($product["price"]); if (is_array(rgar($product, "options"))) { foreach ($product["options"] as $option) { $price += GFCommon::to_number($option["price"]); } } $total += $price * $product['quantity']; } } if ($recurring_field == "all" && !empty($products["shipping"]["price"])) { $total += floatval($products["shipping"]["price"]); } return $total; }
public static function lead_detail_grid($form, $lead, $allow_display_empty_fields = false) { $form_id = absint($form['id']); $display_empty_fields = false; if ($allow_display_empty_fields) { $display_empty_fields = rgget('gf_display_empty_fields', $_COOKIE); } $display_empty_fields = apply_filters('gform_entry_detail_grid_display_empty_fields', $display_empty_fields, $form, $lead); ?> <table cellspacing="0" class="widefat fixed entry-detail-view"> <thead> <tr> <th id="details"> <?php $title = sprintf('%s : %s %s', esc_html($form['title']), esc_html__('Entry # ', 'gravityforms'), absint($lead['id'])); echo apply_filters('gravityflow_title_entry_detail', $title, $form, $lead); ?> </th> <th style="width:140px; font-size:10px; text-align: right;"> <?php if ($allow_display_empty_fields) { ?> <input type="checkbox" id="gentry_display_empty_fields" <?php echo $display_empty_fields ? "checked='checked'" : ''; ?> onclick="ToggleShowEmptyFields();" /> <label for="gentry_display_empty_fields"><?php esc_html_e('show empty fields', 'gravityforms'); ?> </label> <?php } ?> </th> </tr> </thead> <tbody> <?php $count = 0; $field_count = sizeof($form['fields']); $has_product_fields = false; foreach ($form['fields'] as $field) { switch (RGFormsModel::get_input_type($field)) { case 'section': if (!GFCommon::is_section_empty($field, $form, $lead) || $display_empty_fields) { $count++; $is_last = $count >= $field_count ? true : false; ?> <tr> <td colspan="2" class="entry-view-section-break<?php echo $is_last ? ' lastrow' : ''; ?> "><?php echo esc_html(GFCommon::get_label($field)); ?> </td> </tr> <?php } break; case 'captcha': case 'html': case 'password': case 'page': //ignore captcha, html, password, page field break; default: //ignore product fields as they will be grouped together at the end of the grid if (GFCommon::is_product_field($field->type)) { $has_product_fields = true; continue; } $value = RGFormsModel::get_lead_field_value($lead, $field); $display_value = GFCommon::get_lead_field_display($field, $value, $lead['currency']); $display_value = apply_filters('gform_entry_field_value', $display_value, $field, $lead, $form); if ($display_empty_fields || !empty($display_value) || $display_value === '0') { $count++; $is_last = $count >= $field_count && !$has_product_fields ? true : false; $last_row = $is_last ? ' lastrow' : ''; $display_value = empty($display_value) && $display_value !== '0' ? ' ' : $display_value; $content = ' <tr> <td colspan="2" class="entry-view-field-name">' . esc_html(GFCommon::get_label($field)) . '</td> </tr> <tr> <td colspan="2" class="entry-view-field-value' . $last_row . '">' . $display_value . '</td> </tr>'; $content = apply_filters('gform_field_content', $content, $field, $value, $lead['id'], $form['id']); echo $content; } break; } } $products = array(); if ($has_product_fields) { $products = GFCommon::get_product_fields($form, $lead); if (!empty($products['products'])) { ?> <tr> <td colspan="2" class="entry-view-field-name"><?php echo esc_html(apply_filters("gform_order_label_{$form_id}", apply_filters('gform_order_label', __('Order', 'gravityforms'), $form_id), $form_id)); ?> </td> </tr> <tr> <td colspan="2" class="entry-view-field-value lastrow"> <table class="entry-products" cellspacing="0" width="97%"> <colgroup> <col class="entry-products-col1" /> <col class="entry-products-col2" /> <col class="entry-products-col3" /> <col class="entry-products-col4" /> </colgroup> <thead> <th scope="col"><?php echo apply_filters("gform_product_{$form_id}", apply_filters('gform_product', __('Product', 'gravityforms'), $form_id), $form_id); ?> </th> <th scope="col" class="textcenter"><?php echo esc_html(apply_filters("gform_product_qty_{$form_id}", apply_filters('gform_product_qty', __('Qty', 'gravityforms'), $form_id), $form_id)); ?> </th> <th scope="col"><?php echo esc_html(apply_filters("gform_product_unitprice_{$form_id}", apply_filters('gform_product_unitprice', __('Unit Price', 'gravityforms'), $form_id), $form_id)); ?> </th> <th scope="col"><?php echo esc_html(apply_filters("gform_product_price_{$form_id}", apply_filters('gform_product_price', __('Price', 'gravityforms'), $form_id), $form_id)); ?> </th> </thead> <tbody> <?php $total = 0; foreach ($products['products'] as $product) { ?> <tr> <td> <div class="product_name"><?php echo esc_html($product['name']); ?> </div> <ul class="product_options"> <?php $price = GFCommon::to_number($product['price']); if (is_array(rgar($product, 'options'))) { $count = sizeof($product['options']); $index = 1; foreach ($product['options'] as $option) { $price += GFCommon::to_number($option['price']); $class = $index == $count ? " class='lastitem'" : ''; $index++; ?> <li<?php echo $class; ?> ><?php echo $option['option_label']; ?> </li> <?php } } $subtotal = floatval($product['quantity']) * $price; $total += $subtotal; ?> </ul> </td> <td class="textcenter"><?php echo esc_html($product['quantity']); ?> </td> <td><?php echo GFCommon::to_money($price, $lead['currency']); ?> </td> <td><?php echo GFCommon::to_money($subtotal, $lead['currency']); ?> </td> </tr> <?php } $total += floatval($products['shipping']['price']); ?> </tbody> <tfoot> <?php if (!empty($products['shipping']['name'])) { ?> <tr> <td colspan="2" rowspan="2" class="emptycell"> </td> <td class="textright shipping"><?php echo esc_html($products['shipping']['name']); ?> </td> <td class="shipping_amount"><?php echo GFCommon::to_money($products['shipping']['price'], $lead['currency']); ?> </td> </tr> <?php } ?> <tr> <?php if (empty($products['shipping']['name'])) { ?> <td colspan="2" class="emptycell"> </td> <?php } ?> <td class="textright grandtotal"><?php esc_html_e('Total', 'gravityforms'); ?> </td> <td class="grandtotal_amount"><?php echo GFCommon::to_money($total, $lead['currency']); ?> </td> </tr> </tfoot> </table> </td> </tr> <?php } } ?> </tbody> </table> <?php }
/** * Return the formatted entry value. * * @param array $entry The entry currently being processed. * @param string $input_id The field or input ID. * @param bool|false $use_text * @param bool|false $is_csv * * @return string */ public function get_value_export($entry, $input_id = '', $use_text = false, $is_csv = false) { if (empty($input_id)) { $input_id = $this->id; } $value = rgar($entry, $input_id); if (!empty($value)) { $form = GFAPI::get_form($entry['form_id']); $product_info = GFCommon::get_product_fields($form, $entry); $coupon_codes = array_map('trim', explode(',', $value)); $coupons = array(); foreach ($coupon_codes as $code) { $price = GFCommon::to_money($product_info['products'][$code]['price'], rgar($entry, 'currency')); $coupons[] = sprintf('%s (%s: %s)', $product_info['products'][$code]['name'], $code, $price); } $value = implode(', ', $coupons); } return $value; }