GravityView  2.17
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  var $icon = 'dashicons-cart';
25 
26  /** @see GF_Field_Product */
27  var $_gf_field_class_name = 'GF_Field_Product';
28 
29  /**
30  * @since 1.20
31  */
32  public function __construct() {
33 
34  add_filter( 'gravityview/edit_entry/field_blocklist', array( $this, 'edit_entry_field_blocklist' ), 10, 2 );
35 
36  add_action( 'gravityview/edit_entry/after_update', array( $this, 'clear_product_info_cache' ), 10, 3 );
37 
38  parent::__construct();
39  }
40 
41  /**
42  * If the edited entry has a product field and the fields are shown, remove entry purchase cache
43  *
44  * @since 1.20
45  *
46  * @param array $form Gravity Forms array
47  * @param int $entry_id Gravity Forms entry ID
48  * @param GravityView_Edit_Entry_Render $Edit_Entry_Render
49  *
50  * @return void
51  */
52  function clear_product_info_cache( $form = array(), $entry_id = 0, $Edit_Entry_Render = null ) {
53 
54  if( $this->should_hide_product_fields( $Edit_Entry_Render->entry ) ) {
55  return;
56  }
57 
58  // Clear the purchase details so we can re-calculate them
60  gform_delete_meta( $entry_id, 'gform_product_info__' );
61  gform_delete_meta( $entry_id, 'gform_product_info__1' );
62  gform_delete_meta( $entry_id, 'gform_product_info_1_' );
63  gform_delete_meta( $entry_id, 'gform_product_info_1_1' );
64  }
65 
66  }
67 
68  /**
69  * @depecated 2.14
70  */
71  public function edit_entry_field_blacklist( $blocklist = array(), $entry = array() ) {
72  _deprecated_function( __METHOD__, '2.14', 'GravityView_Field_Product::edit_entry_field_blocklist' );
73  return $this->edit_entry_field_blocklist( $blocklist, $entry );
74  }
75 
76  /**
77  * Maybe add Product fields to the Edit Entry blocklist
78  *
79  * @since 1.20
80  *
81  * @param array $blocklist Array of field types not to be shown in the Edit Entry form
82  * @param array $entry Gravity Forms entry array
83  *
84  * @return array Blocklist with product field types added, if should not be shown
85  */
86  public function edit_entry_field_blocklist( $blocklist = array(), $entry = array() ) {
87 
88  if ( $this->should_hide_product_fields( $entry ) ) {
89  $blocklist = array_merge( $blocklist, GVCommon::get_product_field_types() );
90  }
91 
92  return $blocklist;
93  }
94 
95  /**
96  * In Edit Entry, should Product fields be hidden? If entry has transaction data, they should be. Otherwise, no.
97  *
98  * @since 1.20
99  *
100  * @param array $entry Current Gravity Forms entry being edited
101  *
102  * @return bool True: hide product fields; False: show product fields
103  */
104  public function should_hide_product_fields( $entry = array() ) {
105 
106  $has_transaction_data = GVCommon::entry_has_transaction_data( $entry );
107 
108  /**
109  * @filter `gravityview/edit_entry/hide-product-fields` Hide product fields from being editable
110  * @since 1.9.1
111  * @since 1.20 Changed default from false to whether or not entry has transaction data
112  * @see GVCommon::entry_has_transaction_data()
113  * @param boolean $hide_product_fields Whether to hide product fields in the editor. Uses $entry data to determine.
114  */
115  $hide_product_fields = (bool) apply_filters( 'gravityview/edit_entry/hide-product-fields', $has_transaction_data );
116 
117  return $hide_product_fields;
118  }
119 }
120 
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( $blocklist=array(), $entry=array())
2.14
if(gravityview() ->plugin->is_GF_25()) $form
static get_product_field_types()
Return array of product field types.
$entry
Definition: notes.php:27
edit_entry_field_blocklist( $blocklist=array(), $entry=array())
Maybe add Product fields to the Edit Entry blocklist.