fix bug
This commit is contained in:
@@ -219,6 +219,8 @@ class SingleOrderController extends Controller
|
||||
$data['total_price'] = $data['amount'] * $data['price'];
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
|
||||
$this->enforceProductOrderLimits($data, (float) $data['total_price']);
|
||||
|
||||
if (!empty($data['first_buy']) && ($minFirstBuy = Setting::where('is_active', 1)->where('key', 'min_first_buy')->value('value'))) {
|
||||
if ($data['total_price'] < (int) $minFirstBuy) {
|
||||
throw new UnprocessableEntityHttpException('حداقل سفارش اول ' . number_format((int) $minFirstBuy) . ' ریال میباشد.');
|
||||
@@ -256,6 +258,8 @@ class SingleOrderController extends Controller
|
||||
$data['total_price'] = $data['total_amount'] * $data['price'];
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
|
||||
$this->enforceProductOrderLimits($data, (float) $data['total_price']);
|
||||
|
||||
if (!empty($data['first_buy']) && ($minFirstBuy = Setting::where('is_active', 1)->where('key', 'min_first_buy')->value('value'))) {
|
||||
if ($data['total_price'] < (int) $minFirstBuy) {
|
||||
throw new UnprocessableEntityHttpException('حداقل سفارش اول ' . number_format((int) $minFirstBuy) . ' ریال میباشد.');
|
||||
@@ -306,6 +310,7 @@ class SingleOrderController extends Controller
|
||||
$data['total_amount'] = $data['amount'] + ($data['product']['percent_fee_buy'] * $data['amount']);
|
||||
$data['total_price'] = $data['total_amount'] * $data['price'];
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
$this->enforceProductOrderLimits($data, (float) $data['total_price']);
|
||||
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_buy'] * $data['amount']);
|
||||
$data['total_fee'] = 0;
|
||||
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
|
||||
@@ -345,6 +350,8 @@ class SingleOrderController extends Controller
|
||||
{
|
||||
$response = [];
|
||||
$data['price'] -= $data['difference'];
|
||||
$grossTotal = $data['amount'] * $data['price'];
|
||||
$this->enforceProductOrderLimits($data, (float) $grossTotal);
|
||||
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : $data['service_charge_percentage'] * $data['amount'];
|
||||
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
|
||||
$data['total_price'] = $data['amount'] * $data['price'] - $data['service_charge_price'];
|
||||
@@ -376,6 +383,8 @@ class SingleOrderController extends Controller
|
||||
$data['total_amount'] = $data['amount'] - ($data['product']['percent_fee_sell'] * $data['amount']);
|
||||
$data['total_price'] = $data['total_amount'] * $data['price'];
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
$grossTotal = (float) ($data['amount'] * $data['price']);
|
||||
$this->enforceProductOrderLimits($data, $grossTotal);
|
||||
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_sell'] * $data['amount']);
|
||||
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
|
||||
$wallet_interface_product = new WalletInterface(auth('customer')->id(), auth('customer')->user()->type, null, $data["product_id"]);
|
||||
@@ -417,6 +426,8 @@ class SingleOrderController extends Controller
|
||||
$data['total_amount'] = $data['amount'] - ($data['product']['percent_fee_sell'] * $data['amount']);
|
||||
$data['total_price'] = $data['total_amount'] * $data['price'];
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
$grossTotal = (float) ($data['amount'] * $data['price']);
|
||||
$this->enforceProductOrderLimits($data, $grossTotal);
|
||||
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_sell'] * $data['amount']);
|
||||
$data['total_fee'] = 0;
|
||||
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
|
||||
@@ -843,4 +854,28 @@ class SingleOrderController extends Controller
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function enforceProductOrderLimits(array &$data, float $totalPriceRial): void
|
||||
{
|
||||
$product = $data['product'] ?? null;
|
||||
|
||||
if (!$product instanceof Product) {
|
||||
$productId = (int) ($data['abshode_id'] ?? $data['product_id'] ?? 0);
|
||||
if ($productId) {
|
||||
$product = Product::find($productId);
|
||||
if ($product) {
|
||||
$data['product'] = $product;
|
||||
}
|
||||
}
|
||||
} elseif (is_array($product)) {
|
||||
$product = Product::find($product['id'] ?? $data['product_id'] ?? 0);
|
||||
if ($product) {
|
||||
$data['product'] = $product;
|
||||
}
|
||||
}
|
||||
|
||||
if ($product instanceof Product) {
|
||||
$product->validateOrderCashLimit($totalPriceRial);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user