@fleetbase/storefront-engine 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/addon/controllers/products/index/category/new.js +5 -9
  2. package/addon/models/product-addon-category.js +10 -1
  3. package/addon/models/product-variant.js +0 -2
  4. package/addon/models/product.js +35 -2
  5. package/addon/serializers/product.js +16 -0
  6. package/addon/templates/products/index/category/new.hbs +2 -2
  7. package/composer.json +3 -3
  8. package/extension.json +1 -1
  9. package/package.json +1 -1
  10. package/server/src/Auth/Schemas/Storefront.php +31 -39
  11. package/server/src/Console/Commands/NotifyStorefrontOrderNearby.php +9 -11
  12. package/server/src/Expansions/ContactFilterExpansion.php +1 -1
  13. package/server/src/Expansions/EntityExpansion.php +12 -12
  14. package/server/src/Expansions/OrderFilterExpansion.php +1 -1
  15. package/server/src/Expansions/VendorFilterExpansion.php +1 -1
  16. package/server/src/Http/Controllers/ActionController.php +9 -11
  17. package/server/src/Http/Controllers/AddonCategoryController.php +1 -1
  18. package/server/src/Http/Controllers/CustomerController.php +1 -1
  19. package/server/src/Http/Controllers/GatewayController.php +1 -1
  20. package/server/src/Http/Controllers/MetricsController.php +17 -17
  21. package/server/src/Http/Controllers/NetworkController.php +16 -26
  22. package/server/src/Http/Controllers/NotificationChannelController.php +1 -1
  23. package/server/src/Http/Controllers/OrderController.php +18 -22
  24. package/server/src/Http/Controllers/ProductAddonCategoryController.php +1 -2
  25. package/server/src/Http/Controllers/ProductAddonController.php +1 -2
  26. package/server/src/Http/Controllers/ProductController.php +89 -44
  27. package/server/src/Http/Controllers/ProductHourController.php +1 -1
  28. package/server/src/Http/Controllers/ProductVariantController.php +1 -1
  29. package/server/src/Http/Controllers/ProductVariantOptionController.php +1 -1
  30. package/server/src/Http/Controllers/ReviewController.php +1 -1
  31. package/server/src/Http/Controllers/StoreController.php +1 -2
  32. package/server/src/Http/Controllers/StoreHourController.php +1 -1
  33. package/server/src/Http/Controllers/StoreLocationController.php +1 -1
  34. package/server/src/Http/Controllers/StorefrontController.php +0 -2
  35. package/server/src/Http/Controllers/VoteController.php +1 -1
  36. package/server/src/Http/Controllers/v1/CartController.php +16 -26
  37. package/server/src/Http/Controllers/v1/CategoryController.php +3 -4
  38. package/server/src/Http/Controllers/v1/CheckoutController.php +283 -286
  39. package/server/src/Http/Controllers/v1/CustomerController.php +54 -67
  40. package/server/src/Http/Controllers/v1/GatewayControllerController.php +0 -2
  41. package/server/src/Http/Controllers/v1/NetworkController.php +26 -23
  42. package/server/src/Http/Controllers/v1/PaymentMethodController.php +0 -2
  43. package/server/src/Http/Controllers/v1/ProductController.php +1 -4
  44. package/server/src/Http/Controllers/v1/ReviewController.php +31 -35
  45. package/server/src/Http/Controllers/v1/ServiceQuoteController.php +57 -53
  46. package/server/src/Http/Controllers/v1/StoreController.php +8 -16
  47. package/server/src/Http/Filter/AddonCategoryFilter.php +1 -1
  48. package/server/src/Http/Filter/OrderFilter.php +2 -2
  49. package/server/src/Http/Middleware/SetStorefrontSession.php +9 -20
  50. package/server/src/Http/Requests/AddStoreToNetworkCategory.php +3 -3
  51. package/server/src/Http/Requests/CreateCustomerRequest.php +5 -7
  52. package/server/src/Http/Requests/CreateReviewRequest.php +4 -5
  53. package/server/src/Http/Requests/GetServiceQuoteFromCart.php +2 -2
  54. package/server/src/Http/Requests/InitializeCheckoutRequest.php +5 -5
  55. package/server/src/Http/Requests/NetworkActionRequest.php +2 -2
  56. package/server/src/Http/Requests/VerifyCreateCustomerRequest.php +2 -2
  57. package/server/src/Http/Resources/Cart.php +19 -18
  58. package/server/src/Http/Resources/Category.php +12 -11
  59. package/server/src/Http/Resources/Customer.php +15 -14
  60. package/server/src/Http/Resources/Gateway.php +12 -11
  61. package/server/src/Http/Resources/Media.php +9 -8
  62. package/server/src/Http/Resources/Network.php +32 -31
  63. package/server/src/Http/Resources/Product.php +88 -85
  64. package/server/src/Http/Resources/Review.php +14 -13
  65. package/server/src/Http/Resources/ReviewCustomer.php +12 -11
  66. package/server/src/Http/Resources/Store.php +38 -36
  67. package/server/src/Http/Resources/StoreHour.php +9 -8
  68. package/server/src/Http/Resources/StoreLocation.php +9 -8
  69. package/server/src/Imports/ProductsImport.php +0 -2
  70. package/server/src/Jobs/DownloadProductImageUrl.php +7 -4
  71. package/server/src/Listeners/HandleOrderCompleted.php +2 -1
  72. package/server/src/Listeners/HandleOrderDispatched.php +2 -1
  73. package/server/src/Listeners/HandleOrderDriverAssigned.php +2 -1
  74. package/server/src/Listeners/HandleOrderStarted.php +4 -3
  75. package/server/src/Mail/StorefrontNetworkInvite.php +7 -6
  76. package/server/src/Models/AddonCategory.php +2 -4
  77. package/server/src/Models/Cart.php +117 -124
  78. package/server/src/Models/Checkout.php +14 -12
  79. package/server/src/Models/Customer.php +9 -9
  80. package/server/src/Models/Gateway.php +22 -22
  81. package/server/src/Models/Network.php +41 -52
  82. package/server/src/Models/NetworkStore.php +6 -5
  83. package/server/src/Models/NotificationChannel.php +11 -9
  84. package/server/src/Models/PaymentMethod.php +9 -7
  85. package/server/src/Models/Product.php +152 -30
  86. package/server/src/Models/ProductAddon.php +14 -11
  87. package/server/src/Models/ProductAddonCategory.php +9 -8
  88. package/server/src/Models/ProductHour.php +6 -5
  89. package/server/src/Models/ProductStoreLocation.php +7 -5
  90. package/server/src/Models/ProductVariant.php +15 -11
  91. package/server/src/Models/ProductVariantOption.php +12 -9
  92. package/server/src/Models/Review.php +9 -7
  93. package/server/src/Models/Store.php +68 -84
  94. package/server/src/Models/StoreHour.php +6 -5
  95. package/server/src/Models/StoreLocation.php +12 -8
  96. package/server/src/Models/StorefrontModel.php +1 -1
  97. package/server/src/Models/Vote.php +8 -6
  98. package/server/src/Notifications/StorefrontOrderCanceled.php +15 -19
  99. package/server/src/Notifications/StorefrontOrderCompleted.php +15 -19
  100. package/server/src/Notifications/StorefrontOrderCreated.php +31 -36
  101. package/server/src/Notifications/StorefrontOrderDriverAssigned.php +15 -20
  102. package/server/src/Notifications/StorefrontOrderEnroute.php +14 -19
  103. package/server/src/Notifications/StorefrontOrderNearby.php +16 -21
  104. package/server/src/Notifications/StorefrontOrderPreparing.php +15 -18
  105. package/server/src/Notifications/StorefrontOrderReadyForPickup.php +15 -18
  106. package/server/src/Observers/NetworkObserver.php +2 -3
  107. package/server/src/Observers/ProductObserver.php +17 -33
  108. package/server/src/Providers/EventServiceProvider.php +15 -4
  109. package/server/src/Providers/StorefrontServiceProvider.php +8 -10
  110. package/server/src/Support/Metrics.php +12 -12
  111. package/server/src/Support/OrderConfig.php +3 -2
  112. package/server/src/Support/QPay.php +22 -20
  113. package/server/src/Support/Storefront.php +18 -17
  114. package/server/src/routes.php +1 -1
@@ -17,6 +17,7 @@ export default class ProductsIndexCategoryNewController extends BaseController {
17
17
  @service fetch;
18
18
  @service loader;
19
19
  @service crud;
20
+ @service hostRouter;
20
21
  @alias('storefront.activeStore') activeStore;
21
22
  @tracked product = this.store.createRecord('product', { store_uuid: this.activeStore.id, currency: this.activeStore.currency, tags: [], meta_array: [] });
22
23
  @tracked uploadQueue = [];
@@ -58,15 +59,13 @@ export default class ProductsIndexCategoryNewController extends BaseController {
58
59
  this.product
59
60
  .serializeMeta()
60
61
  .save()
61
- .then((product) => {
62
+ .then(() => {
62
63
  this.loader.removeLoader(loader);
63
64
  this.isSaving = false;
64
65
  this.notifications.success('New product created successfully!');
65
66
 
66
67
  return this.transitionToRoute('products.index.category').then(() => {
67
- console.log(this.productsIndexCategoryController);
68
- console.log(this.productsIndexCategoryController.products);
69
- this.productsIndexCategoryController?.products?.pushObject(product);
68
+ return this.hostRouter.refresh();
70
69
  });
71
70
  })
72
71
  .catch((error) => {
@@ -81,8 +80,7 @@ export default class ProductsIndexCategoryNewController extends BaseController {
81
80
  this.product.tags = [];
82
81
  }
83
82
 
84
- this.product.tags?.pushObject(tag);
85
- console.log('this.product.tags', this.product.tags);
83
+ this.product.tags.pushObject(tag);
86
84
  }
87
85
 
88
86
  @action removeTag(index) {
@@ -191,7 +189,7 @@ export default class ProductsIndexCategoryNewController extends BaseController {
191
189
  });
192
190
  });
193
191
 
194
- product.addon_categories = productAddonCategories;
192
+ product.addon_categories.pushObjects(productAddonCategories);
195
193
  },
196
194
  });
197
195
  });
@@ -265,8 +263,6 @@ export default class ProductsIndexCategoryNewController extends BaseController {
265
263
  } else {
266
264
  productAddonCategory.excluded_addons.pushObject(id);
267
265
  }
268
-
269
- console.log(productAddonCategory);
270
266
  }
271
267
 
272
268
  @action addMetaField() {
@@ -1,5 +1,6 @@
1
1
  import Model, { attr, belongsTo } from '@ember-data/model';
2
2
  import { format, formatDistanceToNow } from 'date-fns';
3
+ import getWithDefault from '@fleetbase/ember-core/utils/get-with-default';
3
4
 
4
5
  export default class ProductAddonCategoryModel extends Model {
5
6
  /** @ids */
@@ -19,7 +20,15 @@ export default class ProductAddonCategoryModel extends Model {
19
20
 
20
21
  /** @methods */
21
22
  toJSON() {
22
- return this.serialize();
23
+ return {
24
+ uuid: this.id,
25
+ category_uuid: this.category_uuid,
26
+ product_uuid: this.product_uuid,
27
+ name: this.name,
28
+ excluded_addons: getWithDefault(this, 'excluded_addons', []),
29
+ updated_at: this.updated_at,
30
+ created_at: this.created_at,
31
+ };
23
32
  }
24
33
 
25
34
  /** @computed */
@@ -4,8 +4,6 @@ import { format, formatDistanceToNow } from 'date-fns';
4
4
  export default class ProductVariantModel extends Model {
5
5
  /** @ids */
6
6
  @attr('string') product_uuid;
7
- @attr('string') created_by_uuid;
8
- @attr('string') company_uuid;
9
7
 
10
8
  /** @relationships */
11
9
  @hasMany('product-variant-option') options;
@@ -20,7 +20,7 @@ export default class ProductModel extends Model {
20
20
  @belongsTo('file') primary_image;
21
21
  @hasMany('file') files;
22
22
  @hasMany('product-variant', { async: false }) variants;
23
- @hasMany('product-addon-category') addon_categories;
23
+ @hasMany('product-addon-category', { async: false }) addon_categories;
24
24
  @hasMany('product-hour') hours;
25
25
 
26
26
  /** @attributes */
@@ -56,7 +56,40 @@ export default class ProductModel extends Model {
56
56
 
57
57
  /** @methods */
58
58
  toJSON() {
59
- return this.serialize();
59
+ return {
60
+ uuid: this.id,
61
+ created_by_uuid: this.created_by_uuid,
62
+ company_uuid: this.company_uuid,
63
+ store_uuid: this.store_uuid,
64
+ category_uuid: this.category_uuid,
65
+ primary_image_uuid: this.primary_image_uuid,
66
+ public_id: this.public_id,
67
+ name: this.name,
68
+ category: this.category,
69
+ primary_image: this.primary_image,
70
+ files: this.files,
71
+ variants: this.variants,
72
+ addon_categories: this.addon_categories,
73
+ hours: this.hours,
74
+ description: this.description,
75
+ primary_image_url: this.primary_image_url,
76
+ sku: this.sku,
77
+ currency: this.currency,
78
+ price: this.price,
79
+ sale_price: this.sale_price,
80
+ tags: this.tags,
81
+ youtube_urls: this.youtube_urls,
82
+ translations: this.translations,
83
+ is_on_sale: this.is_on_sale,
84
+ is_recommended: this.is_recommended,
85
+ is_service: this.is_service,
86
+ is_available: this.is_available,
87
+ is_bookable: this.is_bookable,
88
+ status: this.status,
89
+ slug: this.slug,
90
+ created_at: this.created_at,
91
+ updated_at: this.updated_at,
92
+ };
60
93
  }
61
94
 
62
95
  /** @computed */
@@ -1,5 +1,6 @@
1
1
  import ApplicationSerializer from '@fleetbase/ember-core/serializers/application';
2
2
  import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';
3
+ import { isArray } from '@ember/array';
3
4
 
4
5
  export default class ProductSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
5
6
  /**
@@ -17,4 +18,19 @@ export default class ProductSerializer extends ApplicationSerializer.extend(Embe
17
18
  category: { embedded: 'always' },
18
19
  };
19
20
  }
21
+
22
+ serializeHasMany(snapshot, json, relationship) {
23
+ let key = relationship.key;
24
+
25
+ if (key === 'addon_categories') {
26
+ const addonCategories = snapshot.record.get('addon_categories');
27
+
28
+ if (isArray(addonCategories)) {
29
+ json.addon_categories = addonCategories;
30
+ }
31
+ return;
32
+ }
33
+
34
+ return super.serializeHasMany(...arguments);
35
+ }
20
36
  }
@@ -117,7 +117,7 @@
117
117
  </ContentPanel>
118
118
 
119
119
  <ContentPanel @title="Add-Ons" @open={{this.product.addon_categories.length}} @pad={{false}} @panelBodyWrapperClass="px-0 py-4" @panelBodyClass="bg-white dark:bg-gray-800">
120
- <div class="px-4 py-3">
120
+ <div class="px-4">
121
121
  <div class="flex items-center justify-end mb-3">
122
122
  <Button @text="Select Addon Categories" @icon="plus" @iconPrefix="fas" @onClick={{this.selectAddonCategory}} />
123
123
  </div>
@@ -139,7 +139,7 @@
139
139
  {{#each addonCategory.category.addons as |addon|}}
140
140
  <div class="grid grid-cols-10 gap-1 px-3 py-2 rounded-md border border-gray-200 dark:border-gray-900 dark:text-gray-100 dark:bg-gray-800 bg-gray-200">
141
141
  <div class="flex items-center">
142
- <Checkbox @value={{not-in-array addon.id addonCategory.excluded_addons}} @onToggle={{fn this.excludeAddon index addon}} />
142
+ <Checkbox @value={{not (in-array addon.id addonCategory.excluded_addons)}} @onToggle={{fn this.excludeAddon index addon}} />
143
143
  </div>
144
144
  <div class="col-span-3 flex items-center">
145
145
  {{addon.name}}
package/composer.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetbase/storefront-api",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "Headless Commerce & Marketplace Extension for Fleetbase",
5
5
  "keywords": [
6
6
  "fleetbase-extension",
@@ -22,8 +22,8 @@
22
22
  ],
23
23
  "require": {
24
24
  "php": "^7.4|^8.0",
25
- "fleetbase/core-api": "^1.3.2",
26
- "fleetbase/fleetops-api": "^0.3.5",
25
+ "fleetbase/core-api": "^1.3.6",
26
+ "fleetbase/fleetops-api": "^0.3.8",
27
27
  "geocoder-php/google-maps-places-provider": "^1.4",
28
28
  "laravel-notification-channels/apn": "^3.8",
29
29
  "laravel-notification-channels/fcm": "^2.7",
package/extension.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "Storefront",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "Headless Commerce & Marketplace Extension for Fleetbase",
5
5
  "repository": "https://github.com/fleetbase/storefront",
6
6
  "license": "MIT",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fleetbase/storefront-engine",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "Headless Commerce & Marketplace Extension for Fleetbase",
5
5
  "fleetbase": {
6
6
  "route": "storefront",
@@ -6,90 +6,82 @@ class Storefront
6
6
  {
7
7
  /**
8
8
  * The permission schema Name.
9
- *
10
- * @var string
11
9
  */
12
10
  public string $name = 'storefront';
13
11
 
14
12
  /**
15
13
  * The permission schema Polict Name.
16
- *
17
- * @var string
18
14
  */
19
15
  public string $policyName = 'Storefront';
20
16
 
21
17
  /**
22
18
  * Guards these permissions should apply to.
23
- *
24
- * @var array
25
19
  */
26
20
  public array $guards = ['web', 'api'];
27
21
 
28
22
  /**
29
23
  * The permission schema resources.
30
- *
31
- * @var array
32
24
  */
33
25
  public array $resources = [
34
26
  [
35
- 'name' => 'order',
36
- 'actions' => ['accept', 'mark-as-ready', 'mark-as-completed', 'reject']
27
+ 'name' => 'order',
28
+ 'actions' => ['accept', 'mark-as-ready', 'mark-as-completed', 'reject'],
37
29
  ],
38
30
  [
39
- 'name' => 'product',
40
- 'actions' => ['import']
31
+ 'name' => 'product',
32
+ 'actions' => ['import'],
41
33
  ],
42
34
  [
43
- 'name' => 'product-addon',
44
- 'actions' => []
35
+ 'name' => 'product-addon',
36
+ 'actions' => [],
45
37
  ],
46
38
  [
47
- 'name' => 'product-addon-category',
48
- 'actions' => []
39
+ 'name' => 'product-addon-category',
40
+ 'actions' => [],
49
41
  ],
50
42
  [
51
- 'name' => 'product-hour',
52
- 'actions' => []
43
+ 'name' => 'product-hour',
44
+ 'actions' => [],
53
45
  ],
54
46
  [
55
- 'name' => 'product-store-location',
56
- 'actions' => []
47
+ 'name' => 'product-store-location',
48
+ 'actions' => [],
57
49
  ],
58
50
  [
59
- 'name' => 'product-variant',
60
- 'actions' => []
51
+ 'name' => 'product-variant',
52
+ 'actions' => [],
61
53
  ],
62
54
  [
63
- 'name' => 'product-variant-option',
64
- 'actions' => []
55
+ 'name' => 'product-variant-option',
56
+ 'actions' => [],
65
57
  ],
66
58
  [
67
- 'name' => 'gateway',
68
- 'actions' => []
59
+ 'name' => 'gateway',
60
+ 'actions' => [],
69
61
  ],
70
62
  [
71
- 'name' => 'notification-channel',
72
- 'actions' => []
63
+ 'name' => 'notification-channel',
64
+ 'actions' => [],
73
65
  ],
74
66
  [
75
- 'name' => 'network',
76
- 'actions' => []
67
+ 'name' => 'network',
68
+ 'actions' => [],
77
69
  ],
78
70
  [
79
- 'name' => 'network-store',
80
- 'actions' => []
71
+ 'name' => 'network-store',
72
+ 'actions' => [],
81
73
  ],
82
74
  [
83
- 'name' => 'store',
84
- 'actions' => []
75
+ 'name' => 'store',
76
+ 'actions' => [],
85
77
  ],
86
78
  [
87
- 'name' => 'store-location',
88
- 'actions' => []
79
+ 'name' => 'store-location',
80
+ 'actions' => [],
89
81
  ],
90
82
  [
91
- 'name' => 'store-hour',
92
- 'actions' => []
93
- ]
83
+ 'name' => 'store-hour',
84
+ 'actions' => [],
85
+ ],
94
86
  ];
95
87
  }
@@ -33,17 +33,17 @@ class NotifyStorefrontOrderNearby extends Command
33
33
  // Get storefront orders that are enroute
34
34
  $orders = $this->getActiveStorefrontOrders();
35
35
 
36
- // Notify and update
36
+ // Notify and update
37
37
  $this->alert('Found (' . $orders->count() . ') Storefront Orders which are Enroute.');
38
38
 
39
39
  // Iterate each order
40
40
  $orders->each(
41
41
  function ($order) {
42
- $origin = $order->payload->getPickupOrFirstWaypoint();
42
+ $origin = $order->payload->getPickupOrFirstWaypoint();
43
43
  $destination = $order->payload->getDropoffOrLastWaypoint();
44
- $matrix = Utils::getDrivingDistanceAndTime($origin, $destination);
45
- $distance = $matrix->distance;
46
- $time = $matrix->time;
44
+ $matrix = Utils::getDrivingDistanceAndTime($origin, $destination);
45
+ $distance = $matrix->distance;
46
+ $time = $matrix->time;
47
47
 
48
48
  if (!$distance || !$time) {
49
49
  return;
@@ -63,21 +63,19 @@ class NotifyStorefrontOrderNearby extends Command
63
63
 
64
64
  /**
65
65
  * Fetches active storefront orders based on certain criteria.
66
- *
67
- * @return \Illuminate\Database\Eloquent\Collection
68
66
  */
69
67
  public function getActiveStorefrontOrders(): \Illuminate\Database\Eloquent\Collection
70
68
  {
71
69
  return Order::where(
72
70
  [
73
- 'status' => 'driver_enroute',
74
- 'type' => 'storefront',
75
- 'dispatched' => true
71
+ 'status' => 'driver_enroute',
72
+ 'type' => 'storefront',
73
+ 'dispatched' => true,
76
74
  ]
77
75
  )->with(
78
76
  [
79
77
  'payload',
80
- 'customer'
78
+ 'customer',
81
79
  ]
82
80
  )
83
81
  ->withoutGlobalScopes()
@@ -24,7 +24,7 @@ class ContactFilterExpansion implements Expansion
24
24
  public function storefront()
25
25
  {
26
26
  return function (?string $storefront) {
27
- /** @var \Fleetbase\FleetOps\Http\Filter\ContactFilter $this */
27
+ /* @var \Fleetbase\FleetOps\Http\Filter\ContactFilter $this */
28
28
  $this->builder->whereHas(
29
29
  'customerOrders',
30
30
  function ($query) use ($storefront) {
@@ -17,7 +17,7 @@ class EntityExpansion implements Expansion
17
17
  }
18
18
 
19
19
  /**
20
- * Create a new Entity from a Storefront Product
20
+ * Create a new Entity from a Storefront Product.
21
21
  *
22
22
  * @return \Fleetbase\FleetOps\Models\Entity
23
23
  */
@@ -26,18 +26,18 @@ class EntityExpansion implements Expansion
26
26
  return static function (\Fleetbase\Storefront\Models\Product $product) {
27
27
  return new static([
28
28
  'company_uuid' => session('company'),
29
- 'photo_uuid' => $product->primary_image_uuid,
30
- 'internal_id' => $product->public_id,
31
- 'name' => $product->name,
32
- 'description' => $product->description,
33
- 'currency' => $product->currency,
34
- 'sku' => $product->sku,
35
- 'price' => $product->price,
36
- 'sale_price' => $product->sale_price,
37
- 'meta' => [
29
+ 'photo_uuid' => $product->primary_image_uuid,
30
+ 'internal_id' => $product->public_id,
31
+ 'name' => $product->name,
32
+ 'description' => $product->description,
33
+ 'currency' => $product->currency,
34
+ 'sku' => $product->sku,
35
+ 'price' => $product->price,
36
+ 'sale_price' => $product->sale_price,
37
+ 'meta' => [
38
38
  'product_id' => $product->public_id,
39
- 'image_url' => $product->primary_image_url,
40
- ]
39
+ 'image_url' => $product->primary_image_url,
40
+ ],
41
41
  ]);
42
42
  };
43
43
  }
@@ -24,7 +24,7 @@ class OrderFilterExpansion implements Expansion
24
24
  public function storefront()
25
25
  {
26
26
  return function (?string $storefront) {
27
- /** @var \Fleetbase\FleetOps\Http\Filter\OrderFilter $this */
27
+ /* @var \Fleetbase\FleetOps\Http\Filter\OrderFilter $this */
28
28
  $this->builder->where('meta->storefront_id', $storefront);
29
29
  };
30
30
  }
@@ -24,7 +24,7 @@ class VendorFilterExpansion implements Expansion
24
24
  public function storefront()
25
25
  {
26
26
  return function (?string $storefront) {
27
- /** @var \Fleetbase\FleetOps\Http\Filter\VendorFilter $this */
27
+ /* @var \Fleetbase\FleetOps\Http\Filter\VendorFilter $this */
28
28
  $this->builder->whereHas(
29
29
  'customerOrders',
30
30
  function ($query) use ($storefront) {
@@ -2,9 +2,9 @@
2
2
 
3
3
  namespace Fleetbase\Storefront\Http\Controllers;
4
4
 
5
- use Fleetbase\Http\Controllers\Controller;
6
5
  use Fleetbase\FleetOps\Models\Contact;
7
6
  use Fleetbase\FleetOps\Models\Order;
7
+ use Fleetbase\Http\Controllers\Controller;
8
8
  use Fleetbase\Storefront\Models\Store;
9
9
  use Illuminate\Http\Request;
10
10
  use Illuminate\Support\Carbon;
@@ -19,7 +19,6 @@ class ActionController extends Controller
19
19
  /**
20
20
  * Get the number of storefronts created.
21
21
  *
22
- * @param \Illuminate\Http\Request $request
23
22
  * @return \Illuminate\Http\Response
24
23
  */
25
24
  public function getStoreCount(Request $request)
@@ -32,21 +31,20 @@ class ActionController extends Controller
32
31
  /**
33
32
  * Get key metrics for storefront.
34
33
  *
35
- * @param \Illuminate\Http\Request $request
36
34
  * @return \Illuminate\Http\Response
37
35
  */
38
36
  public function getMetrics(Request $request)
39
37
  {
40
38
  $store = $request->input('store');
41
39
  $start = $request->has('start') ? Carbon::fromString($request->input('start'))->toDateTimeString() : Carbon::now()->startOfMonth()->toDateTimeString();
42
- $end = $request->has('end') ? Carbon::fromString($request->input('end'))->toDateTimeString() : Carbon::now()->toDateTimeString();
40
+ $end = $request->has('end') ? Carbon::fromString($request->input('end'))->toDateTimeString() : Carbon::now()->toDateTimeString();
43
41
 
44
42
  // default metrics
45
43
  $metrics = [
46
- 'orders_count' => 0,
44
+ 'orders_count' => 0,
47
45
  'customers_count' => 0,
48
- 'stores_count' => 0,
49
- 'earnings_sum' => 0
46
+ 'stores_count' => 0,
47
+ 'earnings_sum' => 0,
50
48
  ];
51
49
 
52
50
  // get the current active store
@@ -60,7 +58,7 @@ class ActionController extends Controller
60
58
  return response()->json($metrics);
61
59
  }
62
60
 
63
- /**
61
+ /*
64
62
  * Query metrics between given time period
65
63
  */
66
64
 
@@ -70,7 +68,7 @@ class ActionController extends Controller
70
68
  // - orders count
71
69
  $metrics['orders_count'] = Order::where([
72
70
  'company_uuid' => session('company'),
73
- 'type' => 'storefront'
71
+ 'type' => 'storefront',
74
72
  ])
75
73
  ->where('meta->storefront_id', $store->public_id)
76
74
  ->whereNotIn('status', ['canceled'])
@@ -79,7 +77,7 @@ class ActionController extends Controller
79
77
  // - customers count -- change to where has orders where meta->storefront_id === store
80
78
  $metrics['customers_count'] = Contact::where([
81
79
  'company_uuid' => session('company'),
82
- 'type' => 'customer'
80
+ 'type' => 'customer',
83
81
  ])->whereHas('customerOrders', function ($q) use ($start, $end, $store) {
84
82
  $q->whereBetween('created_at', [$start, $end]);
85
83
  $q->where('meta->storefront_id', $store->public_id);
@@ -93,7 +91,7 @@ class ActionController extends Controller
93
91
  // $metrics['earnings_sum'] = Transaction::where(['company_uuid' => session('company'), 'type' => 'storefront', 'meta->storefront_id' => $store->public_id])->whereBetween('created_at', [$start, $end])->sum('amount');
94
92
  $metrics['earnings_sum'] = Order::where([
95
93
  'company_uuid' => session('company'),
96
- 'type' => 'storefront'
94
+ 'type' => 'storefront',
97
95
  ])
98
96
  ->whereBetween('created_at', [$start, $end])
99
97
  ->where('meta->storefront_id', $store->public_id)
@@ -5,7 +5,7 @@ namespace Fleetbase\Storefront\Http\Controllers;
5
5
  class AddonCategoryController extends StorefrontController
6
6
  {
7
7
  /**
8
- * The resource to query
8
+ * The resource to query.
9
9
  *
10
10
  * @var string
11
11
  */
@@ -5,7 +5,7 @@ namespace Fleetbase\Storefront\Http\Controllers;
5
5
  class CustomerController extends StorefrontController
6
6
  {
7
7
  /**
8
- * The resource to query
8
+ * The resource to query.
9
9
  *
10
10
  * @var string
11
11
  */
@@ -5,7 +5,7 @@ namespace Fleetbase\Storefront\Http\Controllers;
5
5
  class GatewayController extends StorefrontController
6
6
  {
7
7
  /**
8
- * The resource to query
8
+ * The resource to query.
9
9
  *
10
10
  * @var string
11
11
  */
@@ -2,16 +2,16 @@
2
2
 
3
3
  namespace Fleetbase\Storefront\Http\Controllers;
4
4
 
5
- use Fleetbase\Storefront\Support\Metrics;
6
5
  use Fleetbase\Http\Controllers\Controller;
6
+ use Fleetbase\Storefront\Support\Metrics;
7
7
  use Illuminate\Http\Request;
8
8
 
9
9
  class MetricsController extends Controller
10
10
  {
11
11
  public function all(Request $request)
12
12
  {
13
- $start = $request->date('start');
14
- $end = $request->date('end');
13
+ $start = $request->date('start');
14
+ $end = $request->date('end');
15
15
  $discover = $request->array('discover', []);
16
16
 
17
17
  try {
@@ -25,10 +25,10 @@ class MetricsController extends Controller
25
25
 
26
26
  public function dashboard(Request $request)
27
27
  {
28
- $start = $request->date('start');
29
- $end = $request->date('end');
28
+ $start = $request->date('start');
29
+ $end = $request->date('end');
30
30
  $discover = $request->array('discover', []);
31
- $metrics = [];
31
+ $metrics = [];
32
32
 
33
33
  try {
34
34
  $metrics = Metrics::forCompany($request->user()->company, $start, $end)->with($discover)->get();
@@ -42,28 +42,28 @@ class MetricsController extends Controller
42
42
  // dashboard config
43
43
  $dashboardConfig = [
44
44
  [
45
- 'size' => 12,
46
- 'title' => 'Storefront Metrics',
47
- 'classList' => [],
48
- 'component' => null,
45
+ 'size' => 12,
46
+ 'title' => 'Storefront Metrics',
47
+ 'classList' => [],
48
+ 'component' => null,
49
49
  'queryParams' => [
50
50
  'start' => ['component' => 'date-picker'],
51
- 'end' => ['component' => 'date-picker'],
51
+ 'end' => ['component' => 'date-picker'],
52
52
  ],
53
53
  'widgets' => collect($metrics)
54
54
  ->map(function ($value, $key) use ($metricsFormats) {
55
55
  return [
56
56
  'component' => 'count',
57
- 'options' => [
57
+ 'options' => [
58
58
  'format' => $metricsFormats[$key] ?? null,
59
- 'title' => str_replace('_', ' ', \Illuminate\Support\Str::title($key)),
60
- 'value' => $value
61
- ]
59
+ 'title' => str_replace('_', ' ', \Illuminate\Support\Str::title($key)),
60
+ 'value' => $value,
61
+ ],
62
62
  ];
63
63
  })
64
64
  ->values()
65
- ->toArray()
66
- ]
65
+ ->toArray(),
66
+ ],
67
67
  ];
68
68
 
69
69
  return response()->json(array_values($dashboardConfig));