Cart_Mapper::map()

Summary

No summary available.

Return

(array)


Source

File: src/BigCommerce/Cart/Cart_Mapper.php

	public function map() {
		$this->identify_channel();
		$cart = [
			'cart_id'         => $this->cart->getId(),
			'base_amount'     => [
				'raw'       => $this->cart->getBaseAmount(),
				'formatted' => $this->format_currency( $this->cart->getBaseAmount() ),
			],
			'discount_amount' => [
				'raw'       => $this->cart->getDiscountAmount(),
				'formatted' => $this->format_currency( $this->cart->getDiscountAmount() ),
			],
			'cart_amount'     => [
				'raw'       => $this->cart->getCartAmount(),
				'formatted' => $this->format_currency( $this->cart->getCartAmount() ),
			],
			'tax_included'    => (bool) $this->cart->getTaxIncluded(),
			'coupons'         => $this->map_coupon_data( $this->cart->getCoupons() ),
			'items'           => $this->cart_items(),
		];

		$coupons_discount_amount = $this->get_coupons_discount_amount( $this->cart->getCoupons() );

		$cart[ 'coupons_discount_amount' ] = [
			'raw'       => $coupons_discount_amount,
			'formatted' => $this->format_currency( $coupons_discount_amount ),
		];

		$tax_amount = $this->calculate_total_tax(
			$cart[ 'cart_amount' ][ 'raw' ],
			$cart[ 'discount_amount' ][ 'raw' ],
			$coupons_discount_amount,
			$cart[ 'items' ]
		);

		$cart[ 'tax_amount' ] = [
			'raw'       => $tax_amount,
			'formatted' => $this->format_currency( $tax_amount ),
		];

		/**
		 * If tax is not already included in item prices
		 * then we need to deduct the calulated tax from the subtotal
		 * as we are displaying the tax separately
		 */
		if ( $cart[ 'tax_included' ] ) {
			$subtotal = $cart[ 'cart_amount' ][ 'raw' ];
		} else {
			$subtotal = $cart[ 'cart_amount' ][ 'raw' ] - $tax_amount;
		}

		$cart[ 'subtotal' ] = [
			'raw'       => $subtotal,
			'formatted' => $this->format_currency( $subtotal ),
		];

		/**
		 * Filter mapped cart
		 *
		 * @param array $cart Cart data.
		 */
		return apply_filters( 'bigcommerce/cart_mapper/map', $cart );
	}


User Contributed Notes

You must log in before being able to contribute a note or feedback.