News:

Looking for documentation? Take a look on our wiki

Main Menu

Getting total profit from order

Started by Master_gray, July 23, 2013, 17:19:47 PM

Previous topic - Next topic

Master_gray

Hi everyone,

i'm making a shipping calculator that need to take the total profit and tell my calculator the amount of profit and subtract 50% of the profit value form the shipping cost,
Now what i would like to know is how can i grab only the total profit in the cart so that i can supply my calculator with the profit amount?

Thanks for reading!!

Milbo

Try

if (!class_exists('VirtueMartCart')) require(JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php');
$cart = VirtueMartCart::getCart();


the use vmdebug('my cart',$cart); use vmdebug('my this',$this) to see if the cart is already available,
Then learn how the prices are stored, set the prices with $cart->setCartPricesMerge
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Master_gray

Hi milbo,

Thanks for the help but i have already found out how to get the result i need below you can see what i did:

<?php

    $array 
unserialize($_SESSION['__vm']['vmcart']); 
    foreach(
$array->products as $product){

        
$price $product->product_price;
$amount $product->quantity;
$length $product->product_length;
$width $product->product_width;
$height $product->product_height;
$weight $product->product_weight;
$zip $product->zip;
$vat 14 100;
$profit_percent 10 100;
$half_profit_percent 50 100;



// $cost takes the cost price and the quantity of the product and multiply it
$cost $price $amount;

// $add_vat show the vat amount of the cost price
$add_vat $cost $vat ;

// $vat_price adds the vat amount and the cost price together
$vat_price $cost $add_vat;

// $add_profit show the profit amount of the $vat_price price
$add_profit $vat_price $profit_percent;

//$half_profit Show you what half of your profit is
$half_profit $add_profit $half_profit_percent;

// $total show you the total amount of the product
$total $vat_price $add_profit;



echo '<strong>Cost price:</strong> '.$cost
.'<strong>  Vat amount:</strong> '.$add_vat
.'<strong>  Cost with vat:</strong> '.$vat_price
.'<strong>  Profit amount:</strong> '.$add_profit
.'<strong>  Shipping discount:</strong> '.$half_profit
.'<strong>  Total amount:</strong>  '.$total
.'<br>'.$length
.'  '.$width
.'  '.$height
.'  '.$weight
.'<br><br>';
echo $zip;

}

?>


But i have one more question how can i get the zip for the cart data array - i tried to use $zip = $product->zip; because i can see the user zip in the array when someone is logged in but it seems to me that i can't grab it - any ideas?

Milbo

$cart->BT['zip'] or so

use vmdebug('my cart',$cart); to see what the cart already provides
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Master_gray

Hi everyone,

I found a way to get the zip from the session if anyone would like to know (See below)

<?php

//This will get the zip out of the cart!!!!!!

$array unserialize($_SESSION['__vm']['vmcart']); 
foreach(
$array->BT as $key => $zip){
 if (
$key == 'zip'){
echo 
$zip;
}
}
?>


if you need details on how this works PM me :) i will be glad to help.

Hope i can help someone with this,
Regards.