Load cart total price.

@param CartInterface $cart Cart
506478
public function loadCartTotalAmount(CartInterface $cart)
    {
        $currency = $this
            ->currencyWrapper
            ->get();

        $finalAmount = clone $cart->getPurchasableAmount();

        /**
         * Calculates the shipping amount.
         */
        $shippingAmount = $cart->getShippingAmount();
        if ($shippingAmount instanceof MoneyInterface) {
            $convertedShippingAmount = $this
                ->currencyConverter
                ->convertMoney(
                    $shippingAmount,
                    $currency
                );
            $finalAmount = $finalAmount->add($convertedShippingAmount);
        }

        /**
         * Calculates the coupon amount.
         */
        $couponAmount = $cart->getCouponAmount();
        if ($couponAmount instanceof MoneyInterface) {
            $convertedCouponAmount = $this
                ->currencyConverter
                ->convertMoney(
                    $couponAmount,
                    $currency
                );
            $finalAmount = $finalAmount->subtract($convertedCouponAmount);
        }

        $cart->setAmount($finalAmount);
    }
78108
protected function loadCartFromSession()
    {
        $cartIdInSession = $this
            ->cartSessionManager
            ->get();

        if (!$cartIdInSession) {
            return null;
        }

        $cart = $this
            ->cartRepository
            ->findOneBy([
                'id' => $cartIdInSession,
                'ordered' => false,
            ]);

        return ($cart instanceof CartInterface)
            ? $cart
            : null;
    }
889998
public function execute(DataSetInterface $dataSet): void
    {
        $priceTypeEntity = SpyPriceTypeQuery::create()
            ->filterByName($dataSet[PriceProductMerchantRelationshipDataSetInterface::PRICE_TYPE])
            ->findOneOrCreate();

        if ($priceTypeEntity->isNew() || $priceTypeEntity->isModified()) {
            $priceTypeEntity->setPriceModeConfiguration(SpyPriceTypeTableMap::COL_PRICE_MODE_CONFIGURATION_BOTH);
            $priceTypeEntity->save();
        }

        $priceProductQuery = SpyPriceProductQuery::create();
        $priceProductQuery->filterByFkPriceType($priceTypeEntity->getIdPriceType());

        if (!empty($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRODUCT_CONCRETE])) {
            $priceProductQuery->filterByFkProduct($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRODUCT_CONCRETE]);
        } else {
            $priceProductQuery->filterByFkProductAbstract($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRODUCT_ABSTRACT]);
        }
        $productPriceEntity = $priceProductQuery->findOneOrCreate();
        $productPriceEntity->save();

        $dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRICE_PRODUCT] = $productPriceEntity->getIdPriceProduct();
    }
446276
public function total()
    {
        return (float) array_sum(
            array_map(function (CartItem $item) {
                return $item->getTotalPrice();
            }, $this->items)
        );
    }
831951
protected function updateTotalPrice(): void
    {
        if (is_int($this->price) && is_int($this->quantity)) {
            $this->totalPrice = BigInteger::of($this->price)->multipliedBy(abs($this->quantity))->toInt();

            $this->updateDiscount();
        }
    }
528401
public function addPrice(PriceInterface $price): ProductInterface
    {
        if (!$this->prices->contains($price)) {
            $this->prices->add($price);
            $price->setProduct($this);
        }

        return $this;
    }
975299
public function handle(AddToCart $command)
    {
        $product = $this->products->getBySku(new SKU($command->sku()));

        $cart = $this->carts->getById(new CartId($command->cartId()));
        $cart->add($product, $command->quantity());
    }
689149
public function dispatchShippingCollectionEvent(CartInterface $cart)
    {
        $event = new ShippingCollectionEvent($cart);

        $this
            ->eventDispatcher
            ->dispatch(
                ElcodiShippingEvents::SHIPPING_COLLECT,
                $event
            );

        return $event->getShippingMethods();
    }
439676
public function add(Product $product, int $quantity)
    {
        if (!$product->isAvailable()) {
            throw new ProductNotAvailableException($product);
        }

        if (!$product->price()->hasCurrency($this->currency)) {
            throw new InvalidCurrencyException($this->currency, $product->price()->currency());
        }

        if (array_key_exists((string) $product->sku(), $this->items)) {
            $quantity += $this->items[(string) $product->sku()]->quantity();
        }

        $this->items[(string) $product->sku()] = new CartItem($product->sku(), $quantity);
    }
1079524
private function getNonAppliedAutomaticCoupons(CartInterface $cart)
    {
        $automaticCoupons = $this
            ->couponRepository
            ->findBy([
                'enforcement' => ElcodiCouponTypes::ENFORCEMENT_AUTOMATIC,
            ]);

        $loadedAutomaticCoupons = $this
            ->cartCouponManager
            ->getCoupons($cart);

        return array_udiff(
            $automaticCoupons,
            $loadedAutomaticCoupons,
            function (CouponInterface $a, CouponInterface $b) {
                return $a->getId() != $b->getId();
            }
        );
    }
1316772
public function loadOrderShippingMethod(
        CartInterface $cart,
        OrderInterface $order
    ) {
        $shippingMethodId = $cart->getShippingMethod();

        if (empty($shippingMethodId)) {
            return $this;
        }

        $shippingMethod = $this
            ->shippingWrapper
            ->getOneById($cart, $shippingMethodId);

        if ($shippingMethod instanceof ShippingMethod) {
            $order->setShippingAmount($shippingMethod->getPrice());
            $order->setShippingMethod($shippingMethod);
        }
    }
53604
public function total($decimals = null, $decimalPoint = null, $thousandSeperator = null)
    {
        $content = $this->getContent();

        $total = $content->reduce(function ($total, CartItem $cartItem) {
            return $total + ($cartItem->qty * $cartItem->priceTax);
        }, 0);

        return $this->numberFormat($total, $decimals, $decimalPoint, $thousandSeperator);
    }
1297705
public function addItem(CartEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        $cart = $event->getCart();
        $newness = $event->getNewness();
        $append = $event->getAppend();
        $quantity = $event->getQuantity();
        $currency = $cart->getCurrency();
        $customer = $cart->getCustomer();
        $discount = 0;

        if ($cart->isNew()) {
            $persistEvent = new CartPersistEvent($cart);
            $dispatcher->dispatch(TheliaEvents::CART_PERSIST, $persistEvent);
        }

        if (null !== $customer && $customer->getDiscount() > 0) {
            $discount = $customer->getDiscount();
        }

        $productSaleElementsId = $event->getProductSaleElementsId();
        $productId = $event->getProduct();

        // Search for an identical item in the cart
        $findItemEvent = clone $event;

        $dispatcher->dispatch(TheliaEvents::CART_FINDITEM, $findItemEvent);

        $cartItem = $findItemEvent->getCartItem();

        if ($cartItem === null || $newness) {
            $productSaleElements = ProductSaleElementsQuery::create()->findPk($productSaleElementsId);

            if (null !== $productSaleElements) {
                $productPrices = $productSaleElements->getPricesByCurrency($currency, $discount);

                $cartItem = $this->doAddItem($dispatcher, $cart, $productId, $productSaleElements, $quantity, $productPrices);
            }
        } elseif ($append && $cartItem !== null) {
            $cartItem->addQuantity($quantity)->save();
        }

        $event->setCartItem($cartItem);
    }
1225070
public function addToCart($productid, $price, $quantity)
	{
		// check if the product already exists in the cart.
		// if it does, add the quantities together
		$productAlreadyExists = 0;
		$olderProduct = ShoppingCartItem::where('product_id', '=', $productid)->where('user_id', '=', Auth::user()->id)->first();
		if($olderProduct != null) {
			$productAlreadyExists = $olderProduct->qty;
			$olderProduct->qty += $quantity;
			$olderProduct->save(); 
		} else {
			$item = new ShoppingCartItem;
			$item->user_id = Auth::user()->id;
			$item->product_id = $productid;
			$item->price = $price;
			$item->qty = $quantity;
			$item->save();
		}
	}
47121
public static function load(string $path): void
    {
        $filePath = \absolute_path($path, static::FILE);
        if (!\is_readable($filePath) || !\is_file($filePath)) {
            return;
        }

        $array = self::optimizeGet($path, $filePath);

        if ($array === false) {
            $array = \parse_ini_file($filePath, false, INI_SCANNER_RAW);
        }

        foreach ($array as $name => $value) {
            static::set($name, $value);
        }

        self::optimizeSet($path, $array, $filePath);
    }
579125
public function dispatchCartCouponOnRejectedEvent(
        CartInterface $cart,
        CouponInterface $coupon
    ) {
        $event = new CartCouponOnRejectedEvent($cart, $coupon);
        $this->eventDispatcher->dispatch(
            ElcodiCartCouponEvents::CART_COUPON_ONREJECTED,
            $event
        );
    }
422286
public function totalExcludingTax()
    {
        return (float) array_sum(
            array_map(function (CartItem $item) {
                return $item->getTotalPriceExcludingTax();
            }, $this->items)
        );
    }