| @@ -44,15 +44,25 @@ | ||
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | public static function make($disableCoupon = false): ?CartCheckoutHelper |
| 47 | 47 | { |
| 48 | - static $instance = null; | |
| 48 | + if (!self::$instance) { | |
| 49 | + self::$instance = new self($disableCoupon); | |
| 50 | + } | |
| 49 | 51 | |
| 50 | - if (!$instance) { | |
| 51 | - $instance = new self($disableCoupon); | |
| 52 | - } | |
| 52 | + return self::$instance; | |
| 53 | + } | |
| 53 | 54 | |
| 54 | - return $instance; | |
| 55 | + /** | |
| 56 | + * Drop the request-scoped instance so the next make() re-initializes from | |
| 57 | + * the current request's cart. Production runs one request per process and | |
| 58 | + * never needs this; long-lived processes (the test suites) call it before | |
| 59 | + * each dispatched request so a helper bound to an earlier cart cannot leak | |
| 60 | + * into the next checkout. | |
| 61 | + */ | |
| 62 | + public static function resetInstance(): void | |
| 63 | + { | |
| 64 | + self::$instance = false; | |
| 55 | 65 | } |
| 56 | 66 | |
| 57 | 67 | |
| 58 | 68 | public function init() |
| @@ -934,7 +944,22 @@ | ||
| 934 | 944 | if ($this->cart->order) { |
| 935 | 945 | return $this->cart->order->manual_discount_total; |
| 936 | 946 | } |
| 937 | 947 | |
| 938 | - return (int)Arr::get($this->cart->checkout_data, 'manual_discount.amount', 0); | |
| 948 | + return (int)Arr::get($this->cart->checkout_data, 'manual_discount.amount', 0) | |
| 949 | + + (int)Arr::get($this->cart->checkout_data, 'upgrade_discount.amount', 0) | |
| 950 | + + $this->getProrateCreditAmount(); | |
| 951 | + } | |
| 952 | + | |
| 953 | + public function getProrateCreditAmount() | |
| 954 | + { | |
| 955 | + if (empty($this->cart)) { | |
| 956 | + return 0; | |
| 957 | + } | |
| 958 | + | |
| 959 | + if ($this->cart->order) { | |
| 960 | + return (int) Arr::get($this->cart->order->config, 'prorate_credit', 0); | |
| 961 | + } | |
| 962 | + | |
| 963 | + return (int) Arr::get($this->cart->checkout_data, 'prorate_credit.amount', 0); | |
| 939 | 964 | } |
| 940 | 965 | } |