PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / trunk
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler vtrunk
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 1.2.1 All 46 releases
fluent-cart / api / Meta.php

Meta.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler trunk, at api/Meta.php

126 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\Api;
4
5 use FluentCart\App\Models\ProductMeta;
6
7 class Meta
8 {
9
10 /**
11 *
12 * @param $productId
13 * @return array
14 */
15 public static function getProductGallery($productId)
16 {
17
18 $meta = ProductMeta::query()->where('object_id', $productId)->where('meta_key', 'product_gallery')->first();
19
20 return empty($meta) ? [] : $meta->meta_value;
21 }
22
23 /**
24 * @param $productId
25 * @param $data
26 * @return mixed
27 */
28 public static function updateProductGallery($productId, $data)
29 {
30 $meta = ProductMeta::query()->where('object_id', $productId)->where('meta_key', 'product_gallery')->first();
31
32 if (empty($meta)) {
33 ProductMeta::create([
34 'object_id' => $productId,
35 'object_type' => 'product_variant_info',
36 //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
37 'meta_value' => $data,
38 //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
39 'meta_key' => 'product_gallery',
40 ]);
41 } else {
42 $meta->update([
43 //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
44 'meta_value' => $data,
45 ]);
46 }
47
48 return $meta;
49 }
50
51
52 /**
53 *
54 * @param $productId
55 * @param $pic
56 * @return mixed
57 */
58 public static function setProductThumbnail($productId, $pic)
59 {
60 $meta = ProductMeta::query()->where('object_id', $productId)->where('meta_key', 'product_thumbnail')->first();
61
62 if (empty($meta)) {
63 ProductMeta::create([
64 'object_id' => $productId,
65 'object_type' => 'product_variant_info',
66 //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
67 'meta_key' => 'product_thumbnail',
68 //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
69 'meta_value' => $pic,
70 ]);
71 } else {
72 $meta->update([
73 //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
74 'meta_value' => $pic,
75 ]);
76 }
77
78 return $meta;
79 }
80
81
82 /**
83 *
84 * @param $productId
85 * @return string
86 */
87 public static function getProductThumbnail($productId)
88 {
89
90 $meta = ProductMeta::query()->where('object_id', $productId)->where('meta_key', 'product_thumbnail')->first();
91
92 return empty($meta) ? '' : $meta->meta_value;
93 }
94
95
96 public static function getProductVariationMedia($varId)
97 {
98
99 $obType = 'product_variant_info';
100
101 return ProductMeta::where('object_id', $varId)->where('object_type', $obType)->where('meta_key', 'product_thumbnail')->first();
102 }
103
104 public static function saveVariationMedia($varId, $val)
105 {
106
107 $obType = 'product_variant_info';
108
109 return ProductMeta::create([
110 'object_id' => $varId,
111 'object_type' => $obType,
112 //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
113 'meta_key' => 'product_thumbnail',
114 //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
115 'meta_value' => $val,
116 ]);
117 }
118
119 public static function deleteVariationMedia($varId) {
120
121 $obType = 'product_variant_info';
122
123 return ProductMeta::query()->where('object_id', $varId)->where('object_type', $obType)->delete();
124 }
125 }
126