PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.6
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.6
1.6.6 1.6.5 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 All 49 releases
← All changes | app/Services/Async/ImageAttachService.php +14 -6 1.4.0 → 1.6.6 View file →
@@ -15,9 +15,9 @@
15 15 {
16 16 $this->requireFiles();
17 17 }
18 18
19 - public static function attachImageToProduct(array $product, array $images)
19 + public static function attachImageToProduct(array $product, array $images, bool $cdnMode = false)
20 20 {
21 21
22 22 if (empty($images)) {
23 23 return;
@@ -26,9 +26,9 @@
26 26 $gallery = [];
27 27 $instance = new ImageAttachService();
28 28
29 29 foreach ($images as $image) {
30 - $value = $instance->addImageFromUrl($image, $product['post_title']);
30 + $value = $instance->addImageFromUrl($image, $product['post_title'], $cdnMode);
31 31 if (!empty($value)) {
32 32 $gallery[] = $value;
33 33 }
34 34 }
@@ -38,15 +38,15 @@
38 38 }
39 39
40 40 }
41 41
42 - public static function attachImageToVariant($variantId, array $images)
42 + public static function attachImageToVariant($variantId, array $images, bool $cdnMode = false)
43 43 {
44 44 $variant = ProductVariation::query()->find($variantId);
45 45 if (empty($variant)) {
46 46 return;
47 47 }
48 -
48 +
49 49 if (empty($images)) {
50 50 return;
51 51 }
52 52
@@ -53,9 +53,9 @@
53 53 $instance = new ImageAttachService();
54 54
55 55 $metaValue = [];
56 56 foreach ($images as $image) {
57 - $value = $instance->addImageFromUrl($image, $variant['variation_title']);
57 + $value = $instance->addImageFromUrl($image, $variant['variation_title'], $cdnMode);
58 58 if (!empty($value)) {
59 59 $metaValue[] = $value;
60 60 }
61 61
@@ -74,10 +74,18 @@
74 74 }
75 75
76 76 }
77 77
78 - protected function addImageFromUrl($url, $title): array
78 + protected function addImageFromUrl($url, $title, bool $cdnMode = false): array
79 79 {
80 + if ($cdnMode) {
81 + return [
82 + 'id' => null,
83 + 'title' => $title ?: basename($url),
84 + 'url' => $url,
85 + ];
86 + }
87 +
80 88 $uploadUrl = wp_upload_dir()['baseurl'];
81 89 $uploadUrl = Str::of($uploadUrl)->replace('http://', '')->replace('https://', '')->toString();
82 90 $tmpUrl = Str::of($url)->replace('http://', '')->replace('https://', '')->toString();
83 91