← All changes
|
app/Http/Controllers/ProductVariationController.php
+16
-14
1.6.1
→
1.6.6
View file →
| @@ -289,24 +289,26 @@ | ||
| 289 | 289 | |
| 290 | 290 | $row = ['id' => $id]; |
| 291 | 291 | |
| 292 | 292 | if (array_key_exists('item_price', $update)) { |
| 293 | - $itemPriceDollar = floatval($update['item_price']); | |
| 293 | + // Submitted in CENTS. roundCent() normalizes float artifacts | |
| 294 | + // without scaling; it does not multiply by 100. | |
| 295 | + $itemPriceCentsIn = floatval($update['item_price']); | |
| 294 | 296 | // Reject negative prices outright rather than coerce to 0 — |
| 295 | 297 | // a caller submitting -50 has either bad client logic or |
| 296 | 298 | // hostile intent; either way we should not silently |
| 297 | 299 | // substitute a price they didn't choose. |
| 298 | - if ($itemPriceDollar >= 0) { | |
| 299 | - $row['item_price'] = Helper::toCent($itemPriceDollar); | |
| 300 | + if ($itemPriceCentsIn >= 0) { | |
| 301 | + $row['item_price'] = Helper::roundCent($itemPriceCentsIn); | |
| 300 | 302 | } |
| 301 | 303 | } |
| 302 | 304 | |
| 303 | 305 | if (array_key_exists('compare_price', $update)) { |
| 304 | - $comparePriceDollar = floatval($update['compare_price']); | |
| 306 | + $comparePriceCentsIn = floatval($update['compare_price']); | |
| 305 | 307 | // Mirror of the item_price negative guard. compare_price=0 |
| 306 | 308 | // is a valid "no discount" sentinel; negative is not. |
| 307 | - if ($comparePriceDollar >= 0) { | |
| 308 | - $comparePriceCents = Helper::toCent($comparePriceDollar); | |
| 309 | + if ($comparePriceCentsIn >= 0) { | |
| 310 | + $comparePriceCents = Helper::roundCent($comparePriceCentsIn); | |
| 309 | 311 | // Effective item_price (in cents) for the comparison: |
| 310 | 312 | // the new value if this update sets it (and is valid), |
| 311 | 313 | // otherwise the already-persisted value from the DB. |
| 312 | 314 | // Falling back to 0 would re-introduce the bypass |
| @@ -417,9 +419,9 @@ | ||
| 417 | 419 | $itemPrice = Arr::get($raw, 'item_price'); |
| 418 | 420 | if ($itemPrice !== null && $itemPrice !== '') { |
| 419 | 421 | $price = floatval($itemPrice); |
| 420 | 422 | if ($price >= 0) { |
| 421 | - $topLevelDelta['item_price'] = Helper::toCent($price); | |
| 423 | + $topLevelDelta['item_price'] = Helper::roundCent($price); | |
| 422 | 424 | } |
| 423 | 425 | } |
| 424 | 426 | |
| 425 | 427 | $comparePrice = Arr::get($raw, 'compare_price'); |
| @@ -425,9 +427,9 @@ | ||
| 425 | 427 | $comparePrice = Arr::get($raw, 'compare_price'); |
| 426 | 428 | if ($comparePrice !== null && $comparePrice !== '') { |
| 427 | 429 | $compare = floatval($comparePrice); |
| 428 | 430 | if ($compare >= 0) { |
| 429 | - $topLevelDelta['_compare_price_dollars'] = $compare; | |
| 431 | + $topLevelDelta['_compare_price_cents'] = $compare; | |
| 430 | 432 | } |
| 431 | 433 | } |
| 432 | 434 | |
| 433 | 435 | // SKU uniqueness — only apply to a single variant to avoid duplicates. |
| @@ -466,9 +468,9 @@ | ||
| 466 | 468 | $itemCost = Arr::get($raw, 'item_cost'); |
| 467 | 469 | if ($itemCost !== null && $itemCost !== '') { |
| 468 | 470 | $cost = floatval($itemCost); |
| 469 | 471 | if ($cost >= 0) { |
| 470 | - $topLevelDelta['item_cost'] = Helper::toCent($cost); | |
| 472 | + $topLevelDelta['item_cost'] = Helper::roundCent($cost); | |
| 471 | 473 | } |
| 472 | 474 | } |
| 473 | 475 | |
| 474 | 476 | $rawOtherInfo = Arr::get($raw, 'other_info'); |
| @@ -527,10 +529,10 @@ | ||
| 527 | 529 | if (isset($topLevelDelta['item_price'])) { |
| 528 | 530 | $rowUpdate['item_price'] = $topLevelDelta['item_price']; |
| 529 | 531 | } |
| 530 | 532 | |
| 531 | - if (isset($topLevelDelta['_compare_price_dollars'])) { | |
| 532 | - $compareCents = Helper::toCent($topLevelDelta['_compare_price_dollars']); | |
| 533 | + if (isset($topLevelDelta['_compare_price_cents'])) { | |
| 534 | + $compareCents = Helper::roundCent($topLevelDelta['_compare_price_cents']); | |
| 533 | 535 | $itemPriceCents = isset($rowUpdate['item_price']) |
| 534 | 536 | ? (int) $rowUpdate['item_price'] |
| 535 | 537 | : (int) $existingVariant->item_price; |
| 536 | 538 | $rowUpdate['compare_price'] = ($compareCents > 0 && $compareCents >= $itemPriceCents) |
| @@ -573,9 +575,9 @@ | ||
| 573 | 575 | } |
| 574 | 576 | } |
| 575 | 577 | |
| 576 | 578 | if ($paymentType === 'subscription' && array_key_exists('signup_fee', $otherInfoDelta)) { |
| 577 | - $merged['signup_fee'] = Helper::toCent(floatval($otherInfoDelta['signup_fee'])); | |
| 579 | + $merged['signup_fee'] = Helper::roundCent($otherInfoDelta['signup_fee']); | |
| 578 | 580 | } |
| 579 | 581 | |
| 580 | 582 | // `installment` is not an accepted delta key (see sanitizeOtherInfoDelta), |
| 581 | 583 | // so the stored flag on the row decides whether this is an installment |
| @@ -754,10 +756,10 @@ | ||
| 754 | 756 | } |
| 755 | 757 | $delta[$key] = floatval($value); |
| 756 | 758 | } |
| 757 | 759 | |
| 758 | - // signup_fee is stored in dollars here; groupBulkUpdate() converts to cents | |
| 759 | - // via Helper::toCent() when payment_type is subscription. | |
| 760 | + // signup_fee arrives in cents; groupBulkUpdate() normalizes it with | |
| 761 | + // Helper::roundCent() when payment_type is subscription. | |
| 760 | 762 | $signupFee = Arr::get($raw, 'signup_fee'); |
| 761 | 763 | if ($signupFee !== null && $signupFee !== '') { |
| 762 | 764 | $delta['signup_fee'] = floatval($signupFee); |
| 763 | 765 | } |