Integrate `SystemSetting` into core services to enable dynamic configuration of business logic and update the WordPress order form redirection to align with the new order approval workflow. - Update `PaymentController`, `ShipmentObserver`, and `TrackingService` to utilize `SystemSetting` for runtime configuration. - Modify `ifnex-order-form.js` to redirect users to the orders list instead of order details upon successful submission.
47 lines
1.5 KiB
PHP
47 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Observers;
|
|
|
|
use App\Models\Shipment;
|
|
use App\Models\SystemSetting;
|
|
use App\Notifications\ShipmentUpdatedNotification;
|
|
use App\Notifications\ShipmentApprovedSms;
|
|
use App\Notifications\ShipmentRejectedSms;
|
|
use Illuminate\Support\Facades\Config;
|
|
|
|
class ShipmentObserver
|
|
{
|
|
public function updated(Shipment $shipment): void
|
|
{
|
|
$changes = $shipment->getChanges();
|
|
$ignored = ['updated_at'];
|
|
|
|
$changedFields = array_filter(
|
|
array_keys($changes),
|
|
fn ($key) => !in_array($key, $ignored)
|
|
);
|
|
|
|
if (empty($changedFields)) {
|
|
return;
|
|
}
|
|
|
|
ShipmentUpdatedNotification::notify($shipment);
|
|
|
|
$oldStatus = $shipment->getOriginal('status');
|
|
$newStatus = $shipment->status;
|
|
|
|
if ($oldStatus !== $newStatus) {
|
|
$trackingUrl = url("/track/{$shipment->awb_no}");
|
|
$smsEnabled = !empty(SystemSetting::get('kavenegar_api_key'));
|
|
|
|
if ($smsEnabled && $newStatus === \App\Enums\ShipmentStatus::Approved && (bool) SystemSetting::get('kavenegar_send_shipment_approved', true)) {
|
|
$shipment->user->notify(new ShipmentApprovedSms($shipment->awb_no, $trackingUrl));
|
|
}
|
|
|
|
if ($smsEnabled && $newStatus === \App\Enums\ShipmentStatus::Cancelled && (bool) SystemSetting::get('kavenegar_send_shipment_rejected', true)) {
|
|
$shipment->user->notify(new ShipmentRejectedSms($shipment->awb_no, 'سفارش شما رد شد.'));
|
|
}
|
|
}
|
|
}
|
|
}
|