Refactor the order and shipment lifecycle across WordPress and Laravel,
improving multi-package handling, payment automation, and frontend
reliability.
- Laravel:
- Rename `package_number` to `package_no` and `description` to
`content_description` in `ShipmentPackage` model and controller.
- Update `PaymentController` to automatically transition approved
shipments to `Processed` status upon successful payment.
- Adjust `OrderPaymentService` to validate against `Approved` status
instead of `PendingPayment`.
- Expose `/countries` endpoint as a public route (unauthenticated).
- Remove obsolete `read_excel.php` utility.
- WordPress (Bridge Plugin & Theme):
- Implement AJAX handler for wallet-based order payments.
- Update `ifnex-order-form.js` to support multi-package input names
and auto-select Iran based on shipment direction.
- Improve error handling and feedback in the order form and country
loading logic.
- Add automatic tracking submission when an `awb` parameter is
present in the URL.
- Update CSS with `!important` flags to ensure correct visibility
of form steps and dashboard elements.
- Implement cache-busting for plugin assets and prevent OPcache
stale files via header controls.
- Optimize theme logo loading with eager loading and explicit
dimensions.
64 lines
1.7 KiB
PHP
64 lines
1.7 KiB
PHP
<?php
|
||
|
||
namespace App\Models;
|
||
|
||
use Illuminate\Database\Eloquent\Model;
|
||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||
|
||
class ShipmentPackage extends Model
|
||
{
|
||
protected $fillable = [
|
||
'shipment_id',
|
||
'package_no',
|
||
'weight',
|
||
'volumetric_weight',
|
||
'chargeable_weight',
|
||
'dimensions',
|
||
'content_description',
|
||
];
|
||
|
||
protected $casts = [
|
||
'weight' => 'decimal:3',
|
||
'volumetric_weight' => 'decimal:3',
|
||
'chargeable_weight' => 'decimal:3',
|
||
];
|
||
|
||
/**
|
||
* رابطه با Shipment
|
||
*/
|
||
public function shipment(): BelongsTo
|
||
{
|
||
return $this->belongsTo(Shipment::class);
|
||
}
|
||
|
||
/**
|
||
* محاسبه وزن قابل محاسبه (ماکزیمم وزن واقعی و حجمی)
|
||
*/
|
||
public function calculateChargeableWeight(): float
|
||
{
|
||
return max((float) $this->weight, (float) $this->volumetric_weight);
|
||
}
|
||
|
||
/**
|
||
* محاسبه وزن حجمی از ابعاد
|
||
* فرمول: (طول × عرض × ارتفاع) / 5000
|
||
*/
|
||
public static function calculateVolumetricWeight(?string $dimensions): float
|
||
{
|
||
if (!$dimensions) return 0;
|
||
|
||
// پارس کردن ابعاد - فرمتهای ممکن: "25*15*3" یا "25x15x3" یا "25,15,3"
|
||
$parts = preg_split('/[\*xX,]/', trim($dimensions));
|
||
if (count($parts) !== 3) return 0;
|
||
|
||
$length = (float) trim($parts[0]);
|
||
$width = (float) trim($parts[1]);
|
||
$height = (float) trim($parts[2]);
|
||
|
||
if ($length <= 0 || $width <= 0 || $height <= 0) return 0;
|
||
|
||
// فرمول استاندارد IATA: (L × W × H) / 5000
|
||
return round(($length * $width * $height) / 5000, 3);
|
||
}
|
||
}
|