PreviousProductDataField.php
3 years ago
PreviousProductIDDataField.php
3 years ago
PreviousProductNameField.php
3 years ago
ProductDataField.php
3 years ago
ProductIDDataField.php
2 years ago
ProductNameDataField.php
2 years ago
ProductDataField.php
121 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Integrations\ThriveAutomator\DataFields; |
| 4 | |
| 5 | if ( ! defined( 'ABSPATH' ) ) { |
| 6 | exit; // Silence is golden! |
| 7 | } |
| 8 | |
| 9 | use SureCart\Models\Product; |
| 10 | use Thrive\Automator\Items\Data_Field; |
| 11 | |
| 12 | /** |
| 13 | * Class ProductDataField |
| 14 | */ |
| 15 | class ProductDataField extends Data_Field { |
| 16 | /** |
| 17 | * Get the data field identifier |
| 18 | * |
| 19 | * @return string |
| 20 | */ |
| 21 | public static function get_id() { |
| 22 | return 'surecart_product_data_field'; |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Get the data field name |
| 27 | * |
| 28 | * @return string |
| 29 | */ |
| 30 | public static function get_name() { |
| 31 | return 'Product'; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Get the data field description |
| 36 | * |
| 37 | * @return string |
| 38 | */ |
| 39 | public static function get_description() { |
| 40 | return 'Show all SureCart Products'; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Get the data field input placeholder |
| 45 | * |
| 46 | * @return string |
| 47 | */ |
| 48 | public static function get_placeholder() { |
| 49 | return 'Select Product'; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Get the data field supported filter |
| 54 | * |
| 55 | * @return array |
| 56 | */ |
| 57 | public static function get_supported_filters() { |
| 58 | return [ 'dropdown' ]; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * For multiple option inputs, name of the callback function called through ajax to get the options |
| 63 | * |
| 64 | * @return array |
| 65 | */ |
| 66 | public static function get_options_callback() { |
| 67 | $options = []; |
| 68 | |
| 69 | $products = Product::where( |
| 70 | [ |
| 71 | 'archived' => false, |
| 72 | ] |
| 73 | )->get(); |
| 74 | |
| 75 | foreach ( $products as $product ) { |
| 76 | $options[ $product->id ] = [ |
| 77 | 'label' => $product->name, |
| 78 | 'id' => $product->id, |
| 79 | ]; |
| 80 | } |
| 81 | |
| 82 | return $options; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Determine if the values are direct or an ajax request |
| 87 | * |
| 88 | * @return boolean |
| 89 | */ |
| 90 | public static function is_ajax_field() { |
| 91 | return true; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Get data field value type |
| 96 | * |
| 97 | * @return string |
| 98 | */ |
| 99 | public static function get_field_value_type() { |
| 100 | return static::TYPE_ARRAY; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Get dummy value |
| 105 | * |
| 106 | * @return string |
| 107 | */ |
| 108 | public static function get_dummy_value() { |
| 109 | return __( 'Product', 'surecart' ); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Get validators |
| 114 | * |
| 115 | * @return array |
| 116 | */ |
| 117 | public static function get_validators() { |
| 118 | return [ 'required' ]; |
| 119 | } |
| 120 | } |
| 121 |