From 7c637da9ea0701b4b6f99eab54f863d22b879116 Mon Sep 17 00:00:00 2001
From: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com>
Date: Sun, 4 Feb 2024 01:09:43 +0000
Subject: [PATCH] Merge branch 'master' into v4
Signed-off-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com>
---
phpstan-baseline.neon | 2 +-
resources/js/cartitem.js | 7 ++---
resources/lang/en/default.php | 5 +++-
resources/models/order.php | 10 +++++++
.../Conditions/OrderAttribute.php | 27 +++++++++++++++++++
src/Models/Order.php | 4 +--
src/Requests/MenuRequest.php | 2 +-
tests/Requests/MenuTest.php | 7 ++---
8 files changed, 53 insertions(+), 11 deletions(-)
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index 3b62dd7..aa750a9 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -357,7 +357,7 @@ parameters:
-
message: "#^Call to an undefined static method Igniter\\\\Cart\\\\Models\\\\CartSettings\\:\\:get\\(\\)\\.$#"
- count: 3
+ count: 4
path: src/Extension.php
-
diff --git a/resources/js/cartitem.js b/resources/js/cartitem.js
index c59f908..1f59826 100644
--- a/resources/js/cartitem.js
+++ b/resources/js/cartitem.js
@@ -50,12 +50,13 @@
var $button = $(event.currentTarget),
$container = $button.closest('[data-toggle="quantity"]'),
$input = $container.find('input'),
- oldValue = parseFloat($input.val())
+ oldValue = parseFloat($input.val()),
+ minQuantity = parseFloat(this.options.minQuantity)
if ($button.data('operator') === 'plus') {
- $input.val(oldValue+this.options.minQuantity)
+ $input.val(oldValue+minQuantity)
} else {
- $input.val((oldValue > 0) ? oldValue-this.options.minQuantity : 0)
+ $input.val((oldValue > 0) ? oldValue-minQuantity : 0)
}
$input.trigger('input');
diff --git a/resources/lang/en/default.php b/resources/lang/en/default.php
index 2941079..0b02a0e 100644
--- a/resources/lang/en/default.php
+++ b/resources/lang/en/default.php
@@ -129,6 +129,7 @@
'alert_no_search_query' => 'Please type in a postcode/address to check if we can deliver to you.',
'alert_location_closed' => 'Sorry, you can\'t place an order now, we are currently closed,
please come back later during our opening times.',
'alert_min_delivery_order_total' => 'Order total is below the %s minimum order total.
You need to spend more to order.',
+ 'alert_min_order_total' => 'Order total is below the %s minimum order total.
You need to spend more to order.',
'alert_coupon_removed' => 'Your coupon has been removed successfully.',
'alert_coupon_applied' => 'Your coupon has been applied successfully.',
'alert_coupon_invalid' => 'Please enter a valid coupon.',
@@ -240,6 +241,7 @@
'text_leave_review' => 'Leave review',
'text_no_payment' => 'No Payment',
'text_login_to_view_more' => 'For more information about your order, please create an account or login.',
+ 'text_title_cancel' => 'Cancel Order',
'column_id' => 'Order no.',
'column_status' => 'Status',
@@ -257,7 +259,7 @@
'button_order' => 'Place New Order',
'button_reorder' => 'Reorder',
- 'button_cancel' => 'Cancel',
+ 'button_cancel' => 'Cancel order',
'button_view_order' => 'View/Reorder',
'button_back' => 'Back',
@@ -328,6 +330,7 @@
'label_restaurant_address' => 'Address',
'label_payment_method' => 'Payment Method',
'label_total_items' => 'Total Items',
+ 'label_cancel_reason' => 'Reason for cancellation',
'notify_status_updated_title' => 'Order status updated',
'notify_assigned_title' => 'Order assigned',
diff --git a/resources/models/order.php b/resources/models/order.php
index 8ce3230..06c37da 100644
--- a/resources/models/order.php
+++ b/resources/models/order.php
@@ -140,6 +140,16 @@
'label' => 'lang:igniter.cart::default.orders.column_total',
'type' => 'currency',
],
+ 'telephone' => [
+ 'label' => 'lang:igniter.cart::default.orders.label_telephone',
+ 'invisible' => true,
+ 'searchable' => true,
+ ],
+ 'email' => [
+ 'label' => 'lang:igniter::admin.label_email',
+ 'invisible' => true,
+ 'searchable' => true,
+ ],
'updated_at' => [
'label' => 'lang:igniter::admin.column_date_updated',
'type' => 'datesince',
diff --git a/src/AutomationRules/Conditions/OrderAttribute.php b/src/AutomationRules/Conditions/OrderAttribute.php
index 450f9e1..806d7cd 100644
--- a/src/AutomationRules/Conditions/OrderAttribute.php
+++ b/src/AutomationRules/Conditions/OrderAttribute.php
@@ -34,6 +34,9 @@ public function defineModelAttributes()
'location_id' => [
'label' => 'Location ID',
],
+ 'status_id' => [
+ 'label' => 'Last order status ID',
+ ],
'total_items' => [
'label' => 'Cart total items',
],
@@ -49,6 +52,12 @@ public function defineModelAttributes()
'hours_until' => [
'label' => 'Hours until order delivery/collection time',
],
+ 'days_since' => [
+ 'label' => 'Days since order delivery/collection time',
+ ],
+ 'days_until' => [
+ 'label' => 'Days until order delivery/collection time',
+ ],
'history_status_id' => [
'label' => 'Recent order status IDs (eg. 1,2,3)',
],
@@ -73,6 +82,24 @@ public function getHoursUntilAttribute($value, $order)
: 0;
}
+ public function getDaysSinceAttribute($value, $order)
+ {
+ $currentDateTime = now();
+
+ return $currentDateTime->isAfter($order->order_datetime)
+ ? $order->order_datetime->diffInDays($currentDateTime)
+ : 0;
+ }
+
+ public function getDaysUntilAttribute($value, $order)
+ {
+ $currentDateTime = now();
+
+ return $currentDateTime->isBefore($order->order_datetime)
+ ? $currentDateTime->diffInDays($order->order_datetime)
+ : 0;
+ }
+
public function getHistoryStatusIdAttribute($value, $order)
{
return $order->status_history()->pluck('status_id')->implode(',');
diff --git a/src/Models/Order.php b/src/Models/Order.php
index 1a90b10..d24e594 100644
--- a/src/Models/Order.php
+++ b/src/Models/Order.php
@@ -225,10 +225,10 @@ public function getOrderDates()
return $this->pluckDates('created_at');
}
- public function markAsCanceled()
+ public function markAsCanceled(array $statusData = [])
{
$canceled = false;
- if ($this->addStatusHistory(setting('canceled_order_status'))) {
+ if ($this->addStatusHistory(setting('canceled_order_status'), $statusData)) {
$canceled = true;
OrderCanceledEvent::dispatch($this);
}
diff --git a/src/Requests/MenuRequest.php b/src/Requests/MenuRequest.php
index 3222a54..6bd2ee6 100644
--- a/src/Requests/MenuRequest.php
+++ b/src/Requests/MenuRequest.php
@@ -39,7 +39,7 @@ public function rules()
'order_restriction.*' => ['nullable', 'string'],
'menu_status' => ['boolean'],
'mealtime_id' => ['nullable', 'integer'],
- 'menu_priority' => ['nullable', 'integer'],
+ 'menu_priority' => ['min:0', 'integer'],
];
}
}
diff --git a/tests/Requests/MenuTest.php b/tests/Requests/MenuTest.php
index 29c922b..ce59f86 100644
--- a/tests/Requests/MenuTest.php
+++ b/tests/Requests/MenuTest.php
@@ -54,10 +54,11 @@ function () {
expect('numeric')->toBeIn(array_get($rules, 'menu_price'));
});
-it('has min:0 rule for menu_price input', function () {
+it('has min:0 rule for menu_price, menu_priority input', function () {
$rules = (new MenuRequest)->rules();
- expect('min:0')->toBeIn(array_get($rules, 'menu_price'));
+ expect('min:0')->toBeIn(array_get($rules, 'menu_price'))
+ ->and('min:0')->toBeIn(array_get($rules, 'menu_priority'));
});
it('has min:1 rule for minimum_qty input', function () {
@@ -108,7 +109,7 @@ function () {
order_restriction.*, mealtime_id, menu_priority',
function () {
$rules = (new MenuRequest)->rules();
- $inputNames = ['order_restriction.*', 'mealtime_id', 'menu_priority'];
+ $inputNames = ['order_restriction.*', 'mealtime_id'];
$testExpectation = null;
foreach ($inputNames as $key => $inputName) {