php - Getting tax value to calculate once state is selected -


i'm attempting add sales tax logic site , have pretty start except running couple of issues.

  1. the largest issue tax value isn't being recognized. have of other values price, shipping cost, etc in database , i'm storing values session. so, pull that. when select state, value isn't being added calculations, i'm not sure how that.

  2. i'm not sure how make equation not calculate tax price if there not any. i'm calculating tax 1 state like:

    $base_price += $products[$product_id]['price'] * $product['quantity']; $tax_price += $base_price * $taxvalue[''];  $tax_price - $base_price; 

    for example:

    base_cost = $10

    tax_value = $1.065

    so $10 * $1.065 -$10 = tax

so if customer chooses other state other tax state subtract price cost in tax spot.

i haven't included of states, need see can tax value added in once state selected.

<?php                            $base_price = 0;             foreach($_session['shopping_cart'] $id => $product) {                 $product_id = $product['product_id'];                 $base_price += $products[$product_id]['price'] * $product['quantity'];                 $shipping_price += $products[$product_id]['shippingprice'] * $product['quantity'];               }             $tax_price += $base_price * $taxvalue[''];             $total_price += $base_price + $shipping_price + $tax_price; } $taxvalue['ohio'] = 1.065; $taxvalue['virginia'] = 1; ?> 

the form part:

<label for="state">state</label> <select type="text" class="mediuminputbar preview" id="shiptostate" data-copy="#confirmstate" name="shiptostate" value="<?php echo escape($user->data()->state); ?>" required>     <option value=''>select state</option> <?php foreach($taxvalue $key => $val) {     echo "<option value='$val'>$key</option>/n"; }    ?> </select> 

with code posted, name of state doesn't carry forward, value does. there way can change state's name goes through in instances , value goes through in others?

for instance when send order need states name shipping info etc. need tax value in other cases.

its because html select input sends 1 value. here if want send name of state, create separate input select state or join both values.

this line causes problem

echo "<option value='$val'>$key</option>/n"; 

change carries both values. use special character join both name of state , value. explode value php exlode() function. name of state , value easily.

example

echo "<option value='$val^$key'>$key</option>/n"; 

see above example, joined $val , $key special character "^".now both state , value in php. explode special character "^".


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -