ProductTemplates
4 weeks ago
BlockRegistry.php
4 weeks ago
BlockTemplateUtils.php
4 weeks ago
Init.php
4 weeks ago
ProductFormsController.php
4 weeks ago
ProductTemplate.php
4 weeks ago
RedirectionController.php
4 weeks ago
Tracks.php
4 weeks ago
ProductTemplate.php
231 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WooCommerce Product Block Editor |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Admin\Features\ProductBlockEditor; |
| 7 | |
| 8 | /** |
| 9 | * The Product Template that represents the relation between the Product and |
| 10 | * the LayoutTemplate (ProductFormTemplateInterface) |
| 11 | * |
| 12 | * @see ProductFormTemplateInterface |
| 13 | * @deprecated 10.9.0 Product editor extension APIs will be removed in WooCommerce 11.0. |
| 14 | */ |
| 15 | class ProductTemplate { |
| 16 | /** |
| 17 | * The template id. |
| 18 | * |
| 19 | * @var string |
| 20 | */ |
| 21 | private $id; |
| 22 | |
| 23 | /** |
| 24 | * The template title. |
| 25 | * |
| 26 | * @var string |
| 27 | */ |
| 28 | private $title; |
| 29 | |
| 30 | /** |
| 31 | * The product data. |
| 32 | * |
| 33 | * @var array |
| 34 | */ |
| 35 | private $product_data; |
| 36 | |
| 37 | /** |
| 38 | * The template order. |
| 39 | * |
| 40 | * @var Integer |
| 41 | */ |
| 42 | private $order = 999; |
| 43 | |
| 44 | /** |
| 45 | * The layout template id. |
| 46 | * |
| 47 | * @var string |
| 48 | */ |
| 49 | private $layout_template_id = null; |
| 50 | |
| 51 | /** |
| 52 | * The template description. |
| 53 | * |
| 54 | * @var string |
| 55 | */ |
| 56 | private $description = null; |
| 57 | |
| 58 | /** |
| 59 | * The template icon. |
| 60 | * |
| 61 | * @var string |
| 62 | */ |
| 63 | private $icon = null; |
| 64 | |
| 65 | /** |
| 66 | * If the template is directly selectable through the UI. |
| 67 | * |
| 68 | * @var boolean |
| 69 | */ |
| 70 | private $is_selectable_by_user = true; |
| 71 | |
| 72 | /** |
| 73 | * ProductTemplate constructor |
| 74 | * |
| 75 | * @param array $data The data. |
| 76 | */ |
| 77 | public function __construct( array $data ) { |
| 78 | $this->id = $data['id']; |
| 79 | $this->title = $data['title']; |
| 80 | $this->product_data = $data['product_data']; |
| 81 | |
| 82 | if ( isset( $data['order'] ) ) { |
| 83 | $this->order = $data['order']; |
| 84 | } |
| 85 | |
| 86 | if ( isset( $data['layout_template_id'] ) ) { |
| 87 | $this->layout_template_id = $data['layout_template_id']; |
| 88 | } |
| 89 | |
| 90 | if ( isset( $data['description'] ) ) { |
| 91 | $this->description = $data['description']; |
| 92 | } |
| 93 | |
| 94 | if ( isset( $data['icon'] ) ) { |
| 95 | $this->icon = $data['icon']; |
| 96 | } |
| 97 | |
| 98 | if ( isset( $data['is_selectable_by_user'] ) ) { |
| 99 | $this->is_selectable_by_user = $data['is_selectable_by_user']; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Get the template ID. |
| 105 | * |
| 106 | * @return string The ID. |
| 107 | */ |
| 108 | public function get_id() { |
| 109 | return $this->id; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Get the template title. |
| 114 | * |
| 115 | * @return string The title. |
| 116 | */ |
| 117 | public function get_title() { |
| 118 | return $this->title; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Get the layout template ID. |
| 123 | * |
| 124 | * @return string The layout template ID. |
| 125 | */ |
| 126 | public function get_layout_template_id() { |
| 127 | return $this->layout_template_id; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Set the layout template ID. |
| 132 | * |
| 133 | * @param string $layout_template_id The layout template ID. |
| 134 | */ |
| 135 | public function set_layout_template_id( string $layout_template_id ) { |
| 136 | $this->layout_template_id = $layout_template_id; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Get the product data. |
| 141 | * |
| 142 | * @return array The product data. |
| 143 | */ |
| 144 | public function get_product_data() { |
| 145 | return $this->product_data; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Get the template description. |
| 150 | * |
| 151 | * @return string The description. |
| 152 | */ |
| 153 | public function get_description() { |
| 154 | return $this->description; |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Set the template description. |
| 159 | * |
| 160 | * @param string $description The template description. |
| 161 | */ |
| 162 | public function set_description( string $description ) { |
| 163 | $this->description = $description; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Get the template icon. |
| 168 | * |
| 169 | * @return string The icon. |
| 170 | */ |
| 171 | public function get_icon() { |
| 172 | return $this->icon; |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Set the template icon. |
| 177 | * |
| 178 | * @see https://github.com/WordPress/gutenberg/tree/trunk/packages/icons. |
| 179 | * |
| 180 | * @param string $icon The icon name from the @wordpress/components or a url for an external image resource. |
| 181 | */ |
| 182 | public function set_icon( string $icon ) { |
| 183 | $this->icon = $icon; |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Get the template order. |
| 188 | * |
| 189 | * @return int The order. |
| 190 | */ |
| 191 | public function get_order() { |
| 192 | return $this->order; |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Get the selectable attribute. |
| 197 | * |
| 198 | * @return boolean Selectable. |
| 199 | */ |
| 200 | public function get_is_selectable_by_user() { |
| 201 | return $this->is_selectable_by_user; |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Set the template order. |
| 206 | * |
| 207 | * @param int $order The template order. |
| 208 | */ |
| 209 | public function set_order( int $order ) { |
| 210 | $this->order = $order; |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * Get the product template as JSON like. |
| 215 | * |
| 216 | * @return array The JSON. |
| 217 | */ |
| 218 | public function to_json() { |
| 219 | return array( |
| 220 | 'id' => $this->get_id(), |
| 221 | 'title' => $this->get_title(), |
| 222 | 'description' => $this->get_description(), |
| 223 | 'icon' => $this->get_icon(), |
| 224 | 'order' => $this->get_order(), |
| 225 | 'layoutTemplateId' => $this->get_layout_template_id(), |
| 226 | 'productData' => $this->get_product_data(), |
| 227 | 'isSelectableByUser' => $this->get_is_selectable_by_user(), |
| 228 | ); |
| 229 | } |
| 230 | } |
| 231 |