GravityView  2.1.1
The best, easiest way to display Gravity Forms entries on your website.
class-gravityview-field-product.php
Go to the documentation of this file.
1 <?php
2 /**
3  * @file class-gravityview-field-product.php
4  * @package GravityView
5  * @subpackage includes\fields
6  * @since 1.20
7  */
8 
9 /**
10  * @since 1.20
11  */
13 
14  var $name = 'product';
15 
16  var $is_searchable = true;
17 
18  var $is_numeric = false;
19 
20  var $search_operators = array( 'is', 'isnot', 'contains' );
21 
22  var $group = 'product';
23 
24  /** @see GF_Field_Product */
25  var $_gf_field_class_name = 'GF_Field_Product';
26 
27  /**
28  * @since 1.20
29  */
30  public function __construct() {
31 
32  add_filter( 'gravityview/edit_entry/field_blacklist', array( $this, 'edit_entry_field_blacklist' ), 10, 2 );
33 
34  add_filter( 'gravityview/edit_entry/after_update', array( $this, 'clear_product_info_cache' ), 10, 3 );
35 
36  parent::__construct();
37  }
38 
39  /**
40  * If the edited entry has a product field and the fields are shown, remove entry purchase cache
41  *
42  * @since 1.20
43  *
44  * @param array $form Gravity Forms array
45  * @param int $entry_id Gravity Forms entry ID
46  * @param GravityView_Edit_Entry_Render $Edit_Entry_Render
47  *
48  * @return void
49  */
50  function clear_product_info_cache( $form = array(), $entry_id = 0, $Edit_Entry_Render = null ) {
51 
52  if( $this->should_hide_product_fields( $Edit_Entry_Render->entry ) ) {
53  return;
54  }
55 
56  // Clear the purchase details so we can re-calculate them
58  gform_delete_meta( $entry_id, 'gform_product_info__' );
59  gform_delete_meta( $entry_id, 'gform_product_info__1' );
60  gform_delete_meta( $entry_id, 'gform_product_info_1_' );
61  gform_delete_meta( $entry_id, 'gform_product_info_1_1' );
62  }
63 
64  }
65 
66  /**
67  * Maybe add Product fields to the Edit Entry blacklist
68  *
69  * @since 1.20
70  *
71  * @param array $blacklist Array of field types not to be shown in the Edit Entry form
72  * @param array $entry Gravity Forms entry array
73  *
74  * @return array Blacklist with product field types added, if should not be shown
75  */
76  public function edit_entry_field_blacklist( $blacklist = array(), $entry = array() ) {
77 
78  if ( $this->should_hide_product_fields( $entry ) ) {
79  $blacklist = array_merge( $blacklist, GVCommon::get_product_field_types() );
80  }
81 
82  return $blacklist;
83  }
84 
85  /**
86  * In Edit Entry, should Product fields be hidden? If entry has transaction data, they should be. Otherwise, no.
87  *
88  * @since 1.20
89  *
90  * @param array $entry Current Gravity Forms entry being edited
91  *
92  * @return bool True: hide product fields; False: show product fields
93  */
94  public function should_hide_product_fields( $entry = array() ) {
95 
96  $has_transaction_data = GVCommon::entry_has_transaction_data( $entry );
97 
98  /**
99  * @filter `gravityview/edit_entry/hide-product-fields` Hide product fields from being editable
100  * @since 1.9.1
101  * @since 1.20 Changed default from false to whether or not entry has transaction data
102  * @see GVCommon::entry_has_transaction_data()
103  * @param boolean $hide_product_fields Whether to hide product fields in the editor. Uses $entry data to determine.
104  */
105  $hide_product_fields = (bool) apply_filters( 'gravityview/edit_entry/hide-product-fields', $has_transaction_data );
106 
107  return $hide_product_fields;
108  }
109 }
110 
Modify field settings by extending this class.
static has_product_field( $form=array())
Check whether a form has product fields.
clear_product_info_cache( $form=array(), $entry_id=0, $Edit_Entry_Render=null)
If the edited entry has a product field and the fields are shown, remove entry purchase cache...
static entry_has_transaction_data( $entry=array())
Check if an entry has transaction data.
should_hide_product_fields( $entry=array())
In Edit Entry, should Product fields be hidden? If entry has transaction data, they should be...
edit_entry_field_blacklist( $blacklist=array(), $entry=array())
Maybe add Product fields to the Edit Entry blacklist.
static get_product_field_types()
Return array of product field types.
$entry
Definition: notes.php:27