This commit is contained in:
2026-07-02 15:54:39 -06:00
commit 9883323161
17470 changed files with 4470592 additions and 0 deletions
@@ -0,0 +1,45 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Orders\Exporters;
use \Gravity_Forms\Gravity_Forms\Orders\GF_Order;
use \Gravity_Forms\Gravity_Forms\Orders\Exporters\GF_Order_Exporter;
use \GFCommon;
class GF_Entry_Details_Order_Exporter extends GF_Order_Exporter {
/**
* GF_Entry_Details_Order_Formatter constructor.
*
* @param GF_Order $order The order to be formatted.
* @param array $config Any specific configurations required while formatting the order.
*/
public function __construct( $order, $config = array() ) {
parent::__construct( $order, $config );
$this->data['rows'] = array();
}
/**
* Extracts a set of raw data from the order.
*
* @since 2.6
*/
protected function format() {
foreach ( $this->order->get_items() as $item ) {
$this->data['rows'][ $item->belongs_to ][] = $this->filter_item_data(
$item,
array(),
array(
'price_money' => GFCommon::to_money( $item->get_base_price(), $this->order->currency ),
'sub_total_money' => GFCommon::to_money( $item->sub_total, $this->order->currency ),
)
);
}
foreach ( $this->data['totals'] as $label => $total ) {
$this->data['totals'][ $label . '_money' ] = GFCommon::to_money( $total, $this->order->currency );
}
}
}
@@ -0,0 +1,110 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Orders\Exporters;
use \Gravity_Forms\Gravity_Forms\Orders\GF_Order;
use \Gravity_Forms\Gravity_Forms\Orders\Items\GF_Order_Item;
use \GFCommon;
class GF_Order_Exporter {
/**
* The order to be formatted.
*
* @since 2.6
*
* @var GF_Order
*/
protected $order;
/**
* Any specific configurations required while formatting the order.
*
* @since 2.6
*
* @var array
*/
protected $config;
/**
* An array containing the extracted order data.
*
* @since 2.6
*
* @var array[]
*/
protected $data = array(
'totals' => array(),
);
/**
* GF_Order_Formatter constructor.
*
* @param GF_Order $order The order to be formatted.
* @param array $config Any specific configurations required while formatting the order.
*/
public function __construct( $order, $config = array() ) {
$this->order = $order;
$this->data['totals'] = $this->order->get_totals();
}
/**
* Extracts a set of raw data from the order.
*
* @since 2.6
*/
protected function format() {
}
/**
* Filters the item data and keeps only the required values.
*
* @since 2.6
*
* @param GF_Order_Item $item The order item.
* @param array $exclude A set of properties to exclude from the item.
* @param array $add More rows to be added to the item data.
*
* @return array The filtered data.
*/
protected function filter_item_data( $item, $exclude = array(), $add = array() ) {
$data = $item->to_array();
if ( is_array( $exclude ) && ! empty( $exclude ) ) {
$data = array_diff_key( $data, array_flip( $exclude ) );
}
if ( is_array( $add ) && ! empty( $add ) ) {
$data = array_merge( $data, $add );
}
return array_filter( $data );
}
/**
* Returns the extracted data.
*
* @since 2.6
*
* @param string|callable $output What format to use when exporting the data, or a function to execute on the formatted data.
*
* @return mixed|array[]
*/
public function export( $output = 'ARRAY' ) {
try {
$this->format();
} catch ( \Exception $ex ) {
$this->data['errors'] = array( $ex->getMessage(), $ex->getCode() );
}
if ( is_callable( $output ) ) {
return $output( $this->data );
}
return $output === 'json' ? json_encode( $this->data ) : $this->data;
}
}
@@ -0,0 +1,50 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Orders\Exporters;
use \Gravity_Forms\Gravity_Forms\Orders\GF_Order;
use \Gravity_Forms\Gravity_Forms\Orders\Items\GF_Order_Item;
use \Gravity_Forms\Gravity_Forms\Orders\Items\GF_Form_Product_Item;
use \GFCommon;
class GF_Save_Entry_Order_Exporter extends GF_Order_Exporter {
/**
* GF_Default_Order_Formatter constructor.
*
* @param GF_Order $order The order to be formatted.
* @param array $config Any specific configurations required while formatting the order.
*/
public function __construct( $order, $config = array() ) {
parent::__construct( $order, $config );
}
/**
* Extracts a set of raw data from the order.
*
* @since 2.6
*/
protected function format() {
foreach ( $this->order->get_items() as $item ) {
if ( ! isset( $this->data['rows'][ $item->belongs_to ] ) ) {
$this->data['rows'][ $item->belongs_to ] = array();
}
if ( $item->is_line_item ) {
// If form product item, we don't need to store pricing info, name and options as they are already stored.
$exclude_properties = is_a( $item, GF_Form_Product_Item::class ) ? array( 'name', 'price', 'quantity', 'sub_total', 'options' ) : array();
$this->data['rows'][ $item->belongs_to ][] = $this->filter_item_data( $item, $exclude_properties );
}
}
// No need to save totals now as they will be calculated later.
// In the future when we have dynamically calculated totals we may save them.
unset( $this->data['totals'] );
// Versioning will help identify this when it changes later, which is very likely.
$this->data['v'] = '0.1';
}
}