plugin install
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_Forms\Orders\Summaries;
|
||||
|
||||
use \Gravity_Forms\Gravity_Forms\Orders\GF_Order;
|
||||
use \Gravity_Forms\Gravity_Forms\Orders\Factories\GF_Order_Factory;
|
||||
use \Gravity_Forms\Gravity_Forms\Orders\Exporters\GF_Entry_Details_Order_Exporter;
|
||||
|
||||
final class GF_Order_Summary {
|
||||
|
||||
/**
|
||||
* Contains any specific configurations for rendering the summary, for example showing only a receipt.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $configurations;
|
||||
|
||||
/**
|
||||
* Renders the summary markup using the provided data and view.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @param array $form The form object.
|
||||
* @param array $entry The entry object.
|
||||
* @param string $view The view to be used for rendering the order.
|
||||
* @param bool $use_choice_text If the product field has choices, this decided if the choice text should be retrieved along with the product name or not.
|
||||
* @param bool $use_admin_labels Whether to use the product admin label or the front end label.
|
||||
* @param bool $receipt Whether to show only the line items paid for in the order or all products in the form.
|
||||
*
|
||||
* @return string The summary markup.
|
||||
*/
|
||||
public static function render( $form, $entry, $view = 'order-summary', $use_choice_text = false, $use_admin_labels = false, $receipt = false ) {
|
||||
GF_Order_Factory::load_dependencies();
|
||||
|
||||
$order = GF_Order_Factory::create_from_entry( $form, $entry, $use_choice_text, $use_admin_labels, rgar( self::$configurations, 'receipt' ) );
|
||||
$order_summary = ( new GF_Entry_Details_Order_Exporter( $order ) )->export();
|
||||
if ( empty( $order_summary['rows'] ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$order_summary['labels'] = self::get_labels( $form );
|
||||
ob_start();
|
||||
include 'views/view-' . $view . '.php';
|
||||
return ob_get_clean();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the labels used in the summary view.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @param array form The form object.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_labels( $form ) {
|
||||
return array(
|
||||
'order_label' => gf_apply_filters( array( 'gform_order_label', $form['id'] ), __( 'Order', 'gravityforms' ), $form['id'] ),
|
||||
'product' => gf_apply_filters( array( 'gform_product', $form['id'] ), __( 'Product', 'gravityforms' ), $form['id'] ),
|
||||
'product_qty' => gf_apply_filters( array( 'gform_product_qty', $form['id'] ), __( 'Qty', 'gravityforms' ), $form['id'] ),
|
||||
'product_unitprice' => gf_apply_filters( array( 'gform_product_unitprice', $form['id'] ), __( 'Unit Price', 'gravityforms' ), $form['id'] ),
|
||||
'product_price' => gf_apply_filters( array( 'gform_product_price', $form['id'] ), __( 'Price', 'gravityforms' ), $form['id'] ),
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<tr>
|
||||
<td colspan="2" class="entry-view-field-name"><?php echo esc_html( $order_summary['labels']['order_label'] ); ?></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 esc_html( $order_summary['labels']['product'] ); ?></th>
|
||||
<th scope="col" class="textcenter"><?php echo esc_html( $order_summary['labels']['product_qty'] ); ?></th>
|
||||
<th scope="col"><?php echo esc_html( $order_summary['labels']['product_unitprice'] ); ?></th>
|
||||
<th scope="col"><?php echo esc_html( $order_summary['labels']['product_price'] ); ?></th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ( rgars( $order_summary, 'rows/body', array() ) as $row ) {
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="product_name"><?php echo esc_html( rgar( $row, 'name' ) ); ?></div>
|
||||
<ul class="product_options">
|
||||
<?php
|
||||
if ( is_array( rgar( $row, 'options' ) ) ) {
|
||||
$count = sizeof( $row['options'] );
|
||||
for ( $i = 0; $i < $count; $i++ ) {
|
||||
?>
|
||||
<li <?php echo ( $i === ( $count - 1 ) ? "class='lastitem'" : '' ); ?>><?php echo rgar( $row['options'][ $i ], 'option_label' );?></li>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
</td>
|
||||
<td class="textcenter"><?php echo esc_html( rgar( $row, 'quantity' ) ); ?></td>
|
||||
<td><?php echo rgar( $row, 'price_money' ); ?></td>
|
||||
<td><?php echo rgar( $row, 'sub_total_money' ); ?></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="2" class="emptycell"> </td>
|
||||
<td class="subtotal"><?php esc_html_e( 'Sub Total', 'gravityforms' ); ?></td>
|
||||
<td class="subtotal_amount"><?php echo $order_summary['totals']['sub_total_money']; ?></td>
|
||||
</tr>
|
||||
<?php foreach ( rgars( $order_summary, 'rows/footer', array() ) as $row ) { ?>
|
||||
<tr>
|
||||
<td colspan="2" class="emptycell"> </td>
|
||||
<td class="footer_row"><?php echo esc_html( rgar( $row, 'name' ) ); ?></td>
|
||||
<td class="footer_row_amount"><?php echo rgar( $row, 'price_money' ); ?> </td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<tr>
|
||||
<td colspan="2" class="emptycell"> </td>
|
||||
<td class="grandtotal"><?php esc_html_e( 'Total', 'gravityforms' ); ?></td>
|
||||
<td class="grandtotal_amount"><?php echo $order_summary['totals']['total_money']; ?></td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
<tr stayle="background-color:#EAF2FA">
|
||||
<td colspan="2">
|
||||
<strong style="font-family: sans-serif; font-size:12px;"><?php echo esc_html( $order_summary['labels']['order_label'] ); ?></strong>
|
||||
</td>
|
||||
</tr>
|
||||
<tr style="background-color: #FFFFFF">
|
||||
<td style="width: 20px"> </td>
|
||||
<td>
|
||||
<table cellspacing="0" style="border-left:1px solid #DFDFDF; border-top:1px solid #DFDFDF; width: 97%">
|
||||
<thead>
|
||||
<tr>
|
||||
<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"><?php echo esc_html( $order_summary['labels']['product'] ); ?></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"><?php echo esc_html( $order_summary['labels']['product_qty'] ); ?></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"><?php echo esc_html( $order_summary['labels']['product_unitprice'] ); ?></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"><?php echo esc_html( $order_summary['labels']['product_price'] ); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ( rgars( $order_summary, 'rows/body', array() ) as $row ) { ?>
|
||||
<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"><?php echo \GFCommon::maybe_wp_kses( rgar( $row, 'name' ) ); ?></strong>
|
||||
<ul style="margin:0">
|
||||
<?php if ( is_array( rgar( $row, 'options' ) ) ) { ?>
|
||||
<?php
|
||||
$count = sizeof( $row['options'] );
|
||||
for ( $i = 0; $i < $count; $i ++ ) {
|
||||
?>
|
||||
<li style="padding:4px 0 4px 0"><?php echo esc_html( rgar( $row['options'][ $i ], 'option_label' ) );?></li>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</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;"><?php echo esc_html( rgar( $row, 'quantity', 1 ) ); ?></td>
|
||||
<td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family: sans-serif; font-size:11px;"><?php echo rgar( $row, 'price_money' ); ?></td>
|
||||
<td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family: sans-serif; font-size:11px;"><?php echo rgar( $row, 'sub_total_money' ); ?></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="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;"><?php esc_html_e( 'Sub 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;"><?php echo $order_summary['totals']['sub_total_money']; ?></strong>
|
||||
</td>
|
||||
</tr>
|
||||
<?php foreach ( rgars( $order_summary, 'rows/footer', array() ) as $row ) { ?>
|
||||
<tr>
|
||||
<td colspan="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; width:155px; font-family: sans-serif;font-size:12px;text-align:right;"><?php echo \GFCommon::maybe_wp_kses( rgar( $row, 'name' ) ); ?></td>
|
||||
<td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family: sans-serif; font-size:11px;">
|
||||
<?php echo rgar( $row, 'sub_total_money' ); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<tr>
|
||||
<td colspan="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;"><?php esc_html_e( '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;"><?php echo $order_summary['totals']['total_money']; ?></strong></td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php echo "--------------------------------\n";
|
||||
echo esc_html( $order_summary['labels']['order_label'] ) . "\n\n";
|
||||
foreach ( rgars( $order_summary, 'rows/body', array() ) as $row ) {
|
||||
|
||||
if ( ! empty( $row['options'] ) ) {
|
||||
$row['name'] .= ' (' . implode(
|
||||
', ',
|
||||
array_map(
|
||||
function( $option ) {
|
||||
return rgar( $option, 'option_name', '' );
|
||||
},
|
||||
rgar( $row, 'options', array() )
|
||||
)
|
||||
) . ')';
|
||||
}
|
||||
echo rgar( $row, 'quantity' ) . ' ' . rgar( $row, 'name' ) . ': ' . rgar( $row, 'sub_total_money', 0 ) . "\n\n";
|
||||
}
|
||||
|
||||
foreach ( rgars( $order_summary, 'rows/footer', array() ) as $row ) {
|
||||
echo rgar( $row, 'name' ) . ': ' . rgar( $row, 'sub_total_money', 0 ) . "\n\n";
|
||||
}
|
||||
|
||||
echo esc_html__( 'Sub Total', 'gravityforms' ) . ': ' . $order_summary['totals']['sub_total_money'] . "\n\n";
|
||||
|
||||
echo esc_html__( 'Total', 'gravityforms' ) . ': ' . $order_summary['totals']['total_money'] . "\n\n";
|
||||
Reference in New Issue
Block a user