Skip to content

Commit

Permalink
fix: minor
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Poyigi <[email protected]>
  • Loading branch information
sampoyigi committed Jan 4, 2025
1 parent ed80200 commit 2735769
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 100 deletions.
50 changes: 0 additions & 50 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,6 @@ parameters:
count: 1
path: src/CartConditions/PaymentFee.php

-
message: "#^Result of static method Igniter\\\\Local\\\\Facades\\\\Location\\:\\:orderTypeIsDelivery\\(\\) \\(void\\) is used\\.$#"
count: 1
path: src/CartConditions/Tax.php

-
message: "#^Undefined variable\\: \\$deliveryCharge$#"
count: 1
path: src/CartConditions/Tax.php

-
message: "#^Call to an undefined static method Igniter\\\\Cart\\\\Models\\\\CartSettings\\:\\:get\\(\\)\\.$#"
count: 2
Expand Down Expand Up @@ -175,16 +165,6 @@ parameters:
count: 1
path: src/Classes/OrderManager.php

-
message: "#^Access to an undefined property Igniter\\\\User\\\\Models\\\\Customer\\:\\:\\$address_id\\.$#"
count: 2
path: src/Classes/OrderManager.php

-
message: "#^Access to an undefined property Igniter\\\\User\\\\Models\\\\Customer\\:\\:\\$email\\.$#"
count: 1
path: src/Classes/OrderManager.php

-
message: "#^Call to an undefined method Igniter\\\\Local\\\\Contracts\\\\LocationInterface\\:\\:allowGuestOrder\\(\\)\\.$#"
count: 1
Expand Down Expand Up @@ -230,11 +210,6 @@ parameters:
count: 1
path: src/Classes/OrderManager.php

-
message: "#^Result of static method Igniter\\\\User\\\\Facades\\\\Auth\\:\\:customer\\(\\) \\(void\\) is used\\.$#"
count: 1
path: src/Classes/OrderManager.php

-
message: "#^PHPDoc tag @param references unknown parameter\\: \\$options$#"
count: 3
Expand All @@ -245,16 +220,6 @@ parameters:
count: 4
path: src/Extension.php

-
message: "#^Call to an undefined static method Igniter\\\\User\\\\Http\\\\Controllers\\\\Customers\\:\\:extendFormFields\\(\\)\\.$#"
count: 1
path: src/Extension.php

-
message: "#^Method Igniter\\\\Admin\\\\Widgets\\\\Form\\:\\:addTabFields\\(\\) invoked with 2 parameters, 1 required\\.$#"
count: 1
path: src/Extension.php

-
message: "#^Result of static method Igniter\\\\User\\\\Facades\\\\Auth\\:\\:getId\\(\\) \\(void\\) is used\\.$#"
count: 1
Expand Down Expand Up @@ -600,11 +565,6 @@ parameters:
count: 1
path: src/Models/Observers/MenuOptionValueObserver.php

-
message: "#^Access to an undefined property Igniter\\\\Admin\\\\Models\\\\StatusHistory\\:\\:\\$status\\.$#"
count: 1
path: src/Models/Order.php

-
message: "#^Access to an undefined property Igniter\\\\Cart\\\\Models\\\\Order\\:\\:\\$address\\.$#"
count: 2
Expand Down Expand Up @@ -760,17 +720,7 @@ parameters:
count: 1
path: src/OrderTypes/Collection.php

-
message: "#^Result of static method Igniter\\\\Local\\\\Facades\\\\Location\\:\\:orderType\\(\\) \\(void\\) is used\\.$#"
count: 1
path: src/OrderTypes/Collection.php

-
message: "#^Call to an undefined method Igniter\\\\Local\\\\Models\\\\Location\\:\\:hasDelivery\\(\\)\\.$#"
count: 1
path: src/OrderTypes/Delivery.php

-
message: "#^Result of static method Igniter\\\\Local\\\\Facades\\\\Location\\:\\:orderType\\(\\) \\(void\\) is used\\.$#"
count: 1
path: src/OrderTypes/Delivery.php
42 changes: 2 additions & 40 deletions src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Igniter\Admin\DashboardWidgets\Charts;
use Igniter\Admin\DashboardWidgets\Statistics;
use Igniter\Admin\Widgets\Form;
use Igniter\Cart\Classes\CheckoutForm;
use Igniter\Cart\Listeners\AddsCustomerOrdersTabFields;
use Igniter\Cart\Listeners\RegistersDashboardCards;
use Igniter\Cart\Models\Category;
use Igniter\Cart\Models\Concerns\LocationAction;
Expand All @@ -28,7 +28,6 @@
use Igniter\System\Models\Settings;
use Igniter\User\Facades\Auth;
use Igniter\User\Http\Controllers\Customers;
use Igniter\User\Models\Customer;
use Illuminate\Foundation\AliasLoader;
use Illuminate\Support\Facades\Event;

Expand Down Expand Up @@ -95,44 +94,7 @@ public function boot()

LocationModel::implement(LocationAction::class);

Customers::extendFormFields(function(Form $form) {
if (!$form->model instanceof Customer) {
return;
}

$form->addTabFields([
'orders' => [
'tab' => 'lang:igniter.cart::default.text_tab_orders',
'type' => 'datatable',
'context' => ['edit', 'preview'],
'useAjax' => true,
'defaultSort' => ['order_id', 'desc'],
'columns' => [
'order_id' => [
'title' => 'lang:igniter::admin.column_id',
],
'customer_name' => [
'title' => 'lang:igniter.cart::default.orders.column_customer_name',
],
'status_name' => [
'title' => 'lang:igniter::admin.label_status',
],
'order_type_name' => [
'title' => 'lang:igniter::admin.label_type',
],
'order_total' => [
'title' => 'lang:igniter.cart::default.orders.column_total',
],
'order_time' => [
'title' => 'lang:igniter.cart::default.orders.column_time',
],
'order_date' => [
'title' => 'lang:igniter.cart::default.orders.column_date',
],
],
],
], 'primary');
});
Customers::extendFormFields(new AddsCustomerOrdersTabFields());

Statistics::registerCards(function() {
return (new RegistersDashboardCards)();
Expand Down
49 changes: 49 additions & 0 deletions src/Listeners/AddsCustomerOrdersTabFields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Igniter\Cart\Listeners;

use Igniter\Admin\Widgets\Form;
use Igniter\User\Models\Customer;

class AddsCustomerOrdersTabFields
{
public function __invoke(Form $form)
{
if (!$form->model instanceof Customer) {
return;
}

$form->addTabFields([
'orders' => [
'tab' => 'lang:igniter.cart::default.text_tab_orders',
'type' => 'datatable',
'context' => ['edit', 'preview'],
'useAjax' => true,
'defaultSort' => ['order_id', 'desc'],
'columns' => [
'order_id' => [
'title' => 'lang:igniter::admin.column_id',
],
'customer_name' => [
'title' => 'lang:igniter.cart::default.orders.column_customer_name',
],
'status_name' => [
'title' => 'lang:igniter::admin.label_status',
],
'order_type_name' => [
'title' => 'lang:igniter::admin.label_type',
],
'order_total' => [
'title' => 'lang:igniter.cart::default.orders.column_total',
],
'order_time' => [
'title' => 'lang:igniter.cart::default.orders.column_time',
],
'order_date' => [
'title' => 'lang:igniter.cart::default.orders.column_date',
],
],
],
]);
}
}
2 changes: 1 addition & 1 deletion src/Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public function isCancelable()
return false;
}

if (!$this->order_datetime->isFuture()) {
if ($this->order_datetime->isPast()) {
return false;
}

Expand Down
23 changes: 18 additions & 5 deletions tests/ExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Igniter\Admin\DashboardWidgets\Charts;
use Igniter\Admin\DashboardWidgets\Statistics;
use Igniter\Admin\Http\Controllers\Dashboard;
use Igniter\Admin\Models\StatusHistory;
use Igniter\Admin\Widgets\Form;
use Igniter\Cart\AutomationRules\Conditions\OrderAttribute;
Expand All @@ -14,7 +15,6 @@
use Igniter\Cart\Extension;
use Igniter\Cart\Facades\Cart;
use Igniter\Cart\FormWidgets\StockEditor;
use Igniter\Cart\Http\Controllers\Menus;
use Igniter\Cart\Http\Middleware\CartMiddleware;
use Igniter\Cart\Models\CartSettings;
use Igniter\Cart\Models\MenuExport;
Expand Down Expand Up @@ -255,7 +255,7 @@
});

it('returns registered dashboard charts', function() {
$charts = new class(resolve(Menus::class)) extends Charts
$charts = new class(resolve(Dashboard::class)) extends Charts
{
public function testDatasets()
{
Expand All @@ -268,7 +268,7 @@ public function testDatasets()
});

it('returns registered dashboard statistic widgets', function() {
$statistics = new class(resolve(Menus::class)) extends Statistics
$statistics = new class(resolve(Dashboard::class)) extends Statistics
{
public function testCards()
{
Expand All @@ -277,14 +277,27 @@ public function testCards()
};
$cards = $statistics->testCards();

expect($cards)->not->toBeEmpty();
expect(array_keys($cards))->toContain(
'sale',
'lost_sale',
'cash_payment',
'order',
'delivery_order',
'collection_order',
'completed_order',
);
});

it('adds orders tab to customer edit form', function() {
it('does not add orders tab to customer edit form when model is invalid', function() {
$model = mock(Model::class)->makePartial();
$form = new Form(resolve(Customers::class), ['model' => $model, 'context' => 'edit']);
$form->bindToController();
$fields = $form->getFields();

expect($fields)->not->toHaveKey('orders');
});

it('adds orders tab to customer edit form', function() {
$customer = mock(Customer::class)->makePartial();
$form = new Form(resolve(Customers::class), ['model' => $customer, 'context' => 'edit']);
$form->bindToController();
Expand Down
8 changes: 4 additions & 4 deletions tests/Http/Controllers/OrdersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@
->assertOk();
});

it('deletes order from edit page', function() {
it('deletes order from list page', function() {
$order = Order::factory()->create();

actingAsSuperUser()
->post(route('igniter.cart.orders', ['slug' => 'edit/'.$order->getKey()]), [], [
->post(route('igniter.cart.orders'), ['checked' => [$order->getKey()]], [
'X-Requested-With' => 'XMLHttpRequest',
'X-IGNITER-REQUEST-HANDLER' => 'onDelete',
]);

expect(Order::find($order->getKey()))->toBeNull();
});

it('deletes order from list page', function() {
it('deletes order from edit page', function() {
$order = Order::factory()->create();

actingAsSuperUser()
->post(route('igniter.cart.orders'), ['checked' => [$order->getKey()]], [
->post(route('igniter.cart.orders', ['slug' => 'edit/'.$order->getKey()]), [], [
'X-Requested-With' => 'XMLHttpRequest',
'X-IGNITER-REQUEST-HANDLER' => 'onDelete',
]);
Expand Down

0 comments on commit 2735769

Please sign in to comment.