Function to calculate the total price of products in the cart
351535
public function totalPrice()
	{
		$total = 0;
		$products = $this->content();
		foreach ($products as $product) {
			$total += ($product->qty * $product->price);
		}
		$total = ($total + ($total * ($this->taxRate/100)));
		$total += $this->deliveryCharges;
		return $total;
	}
782301
def calculate_fee(self, input_values):
        '''
        
        '''
        total_in = sum(input_values)
        total_out = sum([utils.le2i(tx_out.value) for tx_out in self.tx_outs])
        for js in self.tx_joinsplits:
            total_in += utils.le2i(js.vpub_new)
            total_out += utils.le2i(js.vpub_old)
        return total_in - total_out
604584
public void addAllToCart()
    {
        for (Product item : searchResults) {
            Boolean selected = searchSelections.get(item);
            if (selected != null && selected) {
                searchSelections.put(item, false);
                cart.addProduct(item, 1);
            }
        }
    }
634714
function calculatePriceWithOptions( $currency = false )
    {
        $optionList = eZProductCollectionItemOption::fetchList( $this->attribute( 'id' ) );
        $contentObject = $this->contentObject();
        $contentObjectVersion = $contentObject->attribute( 'current_version' );
        $optionsPrice = 0.0;
        if ( count( $optionList ) > 0 )
        {
            $db = eZDB::instance();
            $db->begin();
            foreach( $optionList as $option )
            {
                $objectAttribute = eZContentObjectAttribute::fetch( $option->attribute( 'object_attribute_id' ), $contentObjectVersion );
                if ( $objectAttribute == null )
                {
                    $optionsPrice += 0.0;
                    continue;
                }

                $dataType = $objectAttribute->dataType();
                $optionData = $dataType->productOptionInformation( $objectAttribute, $option->attribute( 'option_item_id' ), $this );

                if ( $optionData )
                {
                    $optionData['additional_price'] = eZShopFunctions::convertAdditionalPrice( $currency, $optionData['additional_price'] );
                    $option->setAttribute( 'price', $optionData['additional_price'] );
                    $option->store();

                    $optionsPrice += $optionData['additional_price'];
                }

            }
            $db->commit();
        }
        return $optionsPrice;
    }
799146
public function getTotal()
    {
        $content = $this->getContent();

        $total = $content->reduce(function (Money $total, CartItem $cartItem) {
            return $total->add($cartItem->getTotal());
        }, new Money(0, Config::get('shoppingcart.currency')));

        return $total;
    }
1306149
def update(self):
        

        subtotal = float(0)
        total = float(0)
        for product in self.items:
            subtotal += float(product["price"])
        if subtotal > 0:
            total = subtotal + self.extra_amount
        self.subtotal = subtotal
        self.total = total
270399
public function process($orderData, $cartProducts, $request)
    {
        $subTotal = 0;
        $taxTotal = 0;

        foreach ($cartProducts as $product) {
            $subTotal += $product->price() * $product->qty();
            $taxTotal += $product->tax() * $product->qty();
        }

        $total = (round($subTotal, 2) + round($taxTotal, 2)) * 100;

        $totalCents = (int) $total;
        $apiKey = Configuration::getConfiguration(self::CONFIG_SECRET_KEY);

        Stripe::setApiKey($apiKey);
        $currencyCode = Configuration::getConfiguration('general_site_currency');
        $response = Charge::create([
            'amount' => $totalCents,
            'currency' => $currencyCode,
            'source' => $request->get('stripeToken'), // obtained with Stripe.js
            'description' => 'AvoRed E commerce Payment',
        ]);

        return $response;
    }
438356
public function priceCalculator()
    {
        $return_price = 0;

        $price      = \floatval($this->getRequest()->query->get('price', 0));
        $product_id = \intval($this->getRequest()->query->get('product_id', 0));
        $action     = $this->getRequest()->query->get('action', ''); // With ot without tax
        $convert    = \intval($this->getRequest()->query->get('convert_from_default_currency', 0));

        if (null !== $product = ProductQuery::create()->findPk($product_id)) {
            if ($action == 'to_tax') {
                $return_price = $this->computePrice($price, 'without_tax', $product);
            } elseif ($action == 'from_tax') {
                $return_price = $this->computePrice($price, 'with_tax', $product);
            } else {
                $return_price = $price;
            }

            if ($convert != 0) {
                $return_price = $price * Currency::getDefaultCurrency()->getRate();
            }
        }

        return new JsonResponse(array('result' => $this->formatPrice($return_price)));
    }
128050
def getTotalDiscountedPrice(self):
        
        price = self.getDiscountedPrice()
        vat = self.getVAT()
        price = price and price or 0
        vat = vat and vat or 0
        return float(price) + (float(price) * float(vat)) / 100
244190
public function getTotalPrice()
    {
        $totalPrice = 0;

        if ($this->count()) {
            foreach ($this->storage as $id => $item) {
                if (isset($item[ 'subTotal' ][ 'price' ])) {
                    $totalPrice += (int)$item[ 'price' ];
                }
            }
        }

        return $totalPrice;
    }
1198433
function doProductPage(product) {
	let res = http.get(product.url);
	check(res, {
		"title is correct": (res) => res.html("title").text() == product.title,
	});
	if (Math.random() <= product.chance) {
		let formBuildID = res.body.match('name="form_build_id" value="(.*)"')[1];
		let formID = res.body.match('name="form_id" value="(.*)"')[1];
		let formToken = res.body.match('name="form_token" value="(.*)"')[1];
		let productID = res.body.match('name="product_id" value="(.*)"')[1];
		group("add to cart", function() { 
			addProductToCart(product.url, productID, formID, formBuildID, formToken)
		});
	}
}
277482
def subtotals
      x = {}
      charges.each do |r|
        x[r.product_code] ||= 0.to_f
        x[r.product_code]  += r.total_cost.to_f
      end
      return x
    end
873672
public function calculatePriceTax()
    {
        $money = new Money(0, new Currency($this->currency));

        $this->items->map(function ($item) use (&$money) {
            $money = $money->add($item->calculatePriceTax());
        });

        return $money;
    }
532115
public function actionGetProductCombination($values, $productId, $currencyFormatting = false) {
        /** @var CartComponent $cart */
        $cart = \Yii::$app->cart;

        $values = Json::decode($values);
        $combination = $cart->getCombination($values, $productId);
        if (!empty($combination)) {
            $oldPrice = $combination->price->oldPrice ?? '';
            $newPrice = $combination->price->discountPrice ?? '';
            if ($currencyFormatting) {
                $oldPrice = Yii::$app->formatter->asCurrency($oldPrice);
                $newPrice = Yii::$app->formatter->asCurrency($newPrice);
            }

            $availability = $combination->combinationAvailability->translation->title
                ?? $combination->product->productAvailability->translation->title ?? '';
            $description = (!empty($combination->translation->description))
                ? $combination->translation->description
                : $combination->product->translation->full_text ?? '';

            $array = [
                'image' => $combination->images[0]->productImage->thumb ?? '',
                'images' => $combination->getImagesArray() ?? '',
                'oldPrice' => $oldPrice,
                'newPrice' => $newPrice,
                'sku' => $combination->sku ?? '',
                'availability' => $availability,
                'description' => $description,
                'prices' => $combination->combinationPrices
            ];
        }
        else return 0;

        return Json::encode($array);
    }
450014
public function getCartTotalPrice($withItemsInPromo = true)
    {
        $total = 0;

        $cartItems = $this->getRequest()->getSession()->getSessionCart($this->getDispatcher())->getCartItems();

        foreach ($cartItems as $cartItem) {
            if ($withItemsInPromo || ! $cartItem->getPromo()) {
                $total += $cartItem->getRealPrice() * $cartItem->getQuantity();
            }
        }

        return $total;
    }
1341891
function updatePriceInfo( $productCollectionID, &$basketInfo )
    {
        $shippingInfo = eZShippingManager::getShippingInfo( $productCollectionID );
        $additionalShippingValues = eZShippingManager::vatPriceInfo( $shippingInfo );
        $returnValue = false;
        foreach ( $additionalShippingValues['shipping_vat_list'] as $vatValue => $additionalShippingValueArray )
        {
            $shippingExVAT = $additionalShippingValueArray['shipping_ex_vat'];
            $shippingIncVAT = $additionalShippingValueArray['shipping_inc_vat'];
            $shippingVat = $additionalShippingValueArray['shipping_vat'];

            if ( !isset( $basketInfo['price_info'][$vatValue]['total_price_ex_vat'] ) )
            {
                $basketInfo['price_info'][$vatValue]['total_price_ex_vat'] = $shippingExVAT;
                $basketInfo['price_info'][$vatValue]['total_price_inc_vat'] = $shippingIncVAT;
                $basketInfo['price_info'][$vatValue]['total_price_vat'] = $shippingVat;

                $basketInfo['total_price_info']['total_price_ex_vat'] = $shippingExVAT;
                $basketInfo['total_price_info']['total_price_inc_vat'] = $shippingIncVAT;
                $basketInfo['total_price_info']['total_price_vat'] = $shippingVat;
            }
            else
            {
                $basketInfo['price_info'][$vatValue]['total_price_ex_vat'] += $shippingExVAT;
                $basketInfo['price_info'][$vatValue]['total_price_inc_vat'] += $shippingIncVAT;
                $basketInfo['price_info'][$vatValue]['total_price_vat'] += $shippingVat;

                $basketInfo['total_price_info']['total_price_ex_vat'] += $shippingExVAT;
                $basketInfo['total_price_info']['total_price_inc_vat'] += $shippingIncVAT;
                $basketInfo['total_price_info']['total_price_vat'] += $shippingVat;
            }

            if ( !isset( $basketInfo['additional_info']['shipping_items'][$vatValue]['total_price_ex_vat'] ) )
            {
                $basketInfo['additional_info']['shipping_items'][$vatValue]['total_price_ex_vat'] = $shippingExVAT;
                $basketInfo['additional_info']['shipping_items'][$vatValue]['total_price_inc_vat'] = $shippingIncVAT;
                $basketInfo['additional_info']['shipping_items'][$vatValue]['total_price_vat'] = ( $shippingIncVAT - $shippingExVAT );
            }
            else
            {
                $basketInfo['additional_info']['shipping_items'][$vatValue]['total_price_ex_vat'] += $shippingExVAT;
                $basketInfo['additional_info']['shipping_items'][$vatValue]['total_price_inc_vat'] += $shippingIncVAT;
                $basketInfo['additional_info']['shipping_items'][$vatValue]['total_price_vat'] += ( $shippingIncVAT - $shippingExVAT );
            }

            if ( !isset( $basketInfo['additional_info']['shipping_total']['total_price_ex_vat'] ) )
            {
                $basketInfo['additional_info']['shipping_total']['total_price_ex_vat'] = $shippingExVAT;
                $basketInfo['additional_info']['shipping_total']['total_price_inc_vat'] = $shippingIncVAT;
                $basketInfo['additional_info']['shipping_total']['total_price_vat'] = ( $shippingIncVAT - $shippingExVAT );
            }
            else
            {
                $basketInfo['additional_info']['shipping_total']['total_price_ex_vat'] += $shippingExVAT;
                $basketInfo['additional_info']['shipping_total']['total_price_inc_vat'] += $shippingIncVAT;
                $basketInfo['additional_info']['shipping_total']['total_price_vat'] += ( $shippingIncVAT - $shippingExVAT );
            }
        }

        if ( count( $additionalShippingValues['shipping_vat_list'] ) > 0 )
        {
            $returnValue = true;
        }

        return $returnValue;
    }
1306757
public function calculate(array &$data)
    {
        $result = array();
        $this->hook->attach('order.calculate.before', $data, $result, $this);

        if (!empty($result)) {
            return (array) $result;
        }

        $components = array();
        $total = $data['cart']['total'];

        $this->calculateComponents($total, $data, $components);
        $this->calculatePriceRules($total, $data, $components);

        $result = array(
            'total' => $total,
            'components' => $components,
            'currency' => $data['cart']['currency'],
            'total_decimal' => $this->price->decimal($total, $data['cart']['currency']),
            'total_formatted' => $this->price->format($total, $data['cart']['currency']),
            'total_formatted_number' => $this->price->format($total, $data['cart']['currency'], true, false),
        );

        $this->hook->attach('order.calculate.after', $data, $result, $this);
        return (array) $result;
    }