PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / app / Models / CustomerMeta.php

CustomerMeta.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at app/Models/CustomerMeta.php

49 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Models;
4
5 /**
6 * Meta Model - DB Model for Meta table
7 *
8 * Database Model
9 *
10 * @package FluentCart\App\Models
11 *
12 * @version 1.0.0
13 */
14 class CustomerMeta extends Model
15 {
16 protected $table = 'fct_customer_meta';
17
18 protected $primaryKey = 'id';
19
20 protected $guarded = [ 'id' ];
21
22 protected $fillable = [
23 'customer_id',
24 'meta_key',
25 'meta_value',
26 ];
27
28 public function setMetaValueAttribute( $value ) {
29 //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
30 if (is_array( $value ) || is_object( $value ) ) {
31 $value = json_encode( $value , JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES );
32 }
33 //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
34 $this->attributes['meta_value'] = $value;
35 }
36
37 public function getMetaValueAttribute( $value ) {
38 if (is_string( $value )) {
39 $decoded = json_decode($value, true);
40 return $decoded ?: $value;
41 }
42 return $value;
43 }
44
45 public function customer() {
46 return $this->belongsTo( Customer::class, 'customer_id', 'id' );
47 }
48 }
49