HEX
Server: nginx/1.18.0
System: Linux iZj6c1ieg2jrpk1z5tzi19Z 6.3.9-1.el7.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 21 22:18:40 EDT 2023 x86_64
User: www (1001)
PHP: 8.2.4
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/www.cytocare.cn/wp-content/plugins/shopmagic-abandoned-carts/src/Cart/ActiveCart.php
<?php
declare( strict_types=1 );

namespace WPDesk\ShopMagicCart\Cart;

use WPDesk\ShopMagic\Customer\Customer;
use WPDesk\ShopMagic\Helper\WordPressFormatHelper;

/**
 * Currently active cart. Can manipulate its data. May become submitted or abandoned.
 */
class ActiveCart extends BaseCart {

	public function __construct(
		?int $id,
		string $status,
		Customer $customer,
		\DateTimeInterface $last_modified,
		\DateTimeInterface $created,
		array $items,
		array $coupons,
		array $fees,
		float $shipping_tax_total,
		float $shipping_total,
		float $total,
		string $token,
		string $currency
	) {
		parent::__construct(
			$id,
			$status,
			$customer,
			$last_modified,
			$created,
			$items,
			$coupons,
			$fees,
			$shipping_tax_total,
			$shipping_total,
			$total,
			$token,
			$currency
		);
	}

	/**
	 * Updates the stored cart with the current time and cart items
	 *
	 * @param string $token Deprecated.
	 * @return void
	 */
	public function sync( \WC_Cart $wc_cart, Customer $customer, string $token = '' ) {
		$this->last_modified = new \DateTimeImmutable();

		$this->items = $this->map_array_items( $wc_cart->get_cart_for_session() );

		$coupon_data = [];
		foreach ( $wc_cart->get_applied_coupons() as $coupon_code ) {
			$coupon_data[ $coupon_code ] = [
				'discount_incl_tax' => $wc_cart->get_coupon_discount_amount( $coupon_code, false ),
				'discount_excl_tax' => $wc_cart->get_coupon_discount_amount( $coupon_code ),
				'discount_tax'      => $wc_cart->get_coupon_discount_tax_amount( $coupon_code ),
			];
		}

		$this->coupons            = $coupon_data;
		$this->fees               = $wc_cart->get_fees();
		$this->currency           = get_woocommerce_currency();
		$this->customer           = $customer;
		$this->shipping_tax_total = $wc_cart->shipping_tax_total;
		$this->shipping_total     = $wc_cart->shipping_total;

		$this->calculate_totals();

		if ( $this->status === Cart::FRESH ) {
			$this->status = Cart::ACTIVE;
		}
	}

	/** @return void */
	private function calculate_totals() {
		$this->calculated_subtotal  = 0;
		$this->calculated_tax_total = 0;
		$this->total                = 0;

		$tax_display = get_option( 'woocommerce_tax_display_cart' );

		foreach ( $this->items as $item ) {
			$this->calculated_tax_total += $item->get_line_subtotal_tax();
			$this->total                += $item->get_line_subtotal() + $item->get_line_subtotal_tax();
			$this->calculated_subtotal  += $tax_display === 'excl' ? $item->get_line_subtotal() : $item->get_line_subtotal() + $item->get_line_subtotal_tax();
		}

		foreach ( $this->coupons as $coupon ) {
			$this->total                -= $coupon['discount_incl_tax'];
			$this->calculated_tax_total -= $coupon['discount_tax'];
		}

		foreach ( $this->fees as $fee ) {
			$this->total                += ( $fee->amount + $fee->tax );
			$this->calculated_tax_total += $fee->tax;
		}

		$this->calculated_tax_total += $this->shipping_tax_total;
		$this->total                += $this->shipping_total;
		$this->total                += $this->shipping_tax_total;
	}
}