PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 2.4.5
Fluent Support – Helpdesk & Customer Support Ticket System v2.4.5
2.4.5 2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 All 69 releases
← All changes | app/Models/Product.php +76 -1 1.5.3 → 2.4.5 View file →
@@ -23,9 +23,8 @@
23 23
24 24 protected $searchable = ['title', 'description'];
25 25
26 26 /**
27 - * Local scope to filter products by search/query string
28 27 * @param ModelQueryBuilder $query
29 28 * @param string $search
30 29 * @return ModelQueryBuilder
31 30 */
@@ -45,6 +44,82 @@
45 44
46 45 return $query;
47 46 }
48 47
48 + /**
49 + * @param $query
50 + * @return mixed
51 + */
52 + public function scopeOrderedByTitle($query)
53 + {
54 + return $query->orderBy('title', 'ASC');
55 + }
56 +
57 + /**
58 + * @param string $search
59 + * @return array
60 + */
61 + public function getProducts ( $search )
62 + {
63 + return [
64 + 'products' => $this->orderedByTitle()->searchBy($search)->paginate()
65 + ];
66 + }
67 +
68 + /**
69 + * @param int $productId
70 + * @return array
71 + */
72 + public function getProduct ( $productId )
73 + {
74 + return [
75 + 'product' => $this->findOrFail($productId)
76 + ];
77 + }
78 +
79 + /**
80 + * @param array $data
81 + * @return array
82 + */
83 + public function createProduct ( $data )
84 + {
85 + $data = wp_unslash($data);
86 + $product = $this->create($data);
87 +
88 + return [
89 + 'message' => __('Product has been successfully created', 'fluent-support'),
90 + 'product' => $product
91 + ];
92 + }
93 +
94 + /**
95 + * @param int $productId
96 + * @param array $data
97 + * @return array
98 + */
99 + public function updateProduct ( $productId, $data )
100 + {
101 + $data = wp_unslash($data);
102 + $product = $this->findOrFail($productId);
103 + $product->fill($data);
104 + $product->save();
105 +
106 + return [
107 + 'message' => __('Product has been updated', 'fluent-support'),
108 + 'product' => $product
109 + ];
110 + }
111 +
112 + /**
113 + * @param int $productId
114 + * @return array
115 + */
116 + public function deleteProduct ( $productId )
117 + {
118 + $this->where('id', $productId)->delete();
119 +
120 + return [
121 + 'message' => __('Product has been deleted', 'fluent-support')
122 + ];
123 + }
49 124
50 125 }