sessioncheck(); $addedvalue = false; if(!empty($_GET)) { $messages->message('Checkout page cannot be accessed this way.'); $messages->showmessage(); exit; } if(isset($_SESSION['token'])) { $token = $_SESSION['token']; if($token != $_POST['token']) { $messages->message('Token is incorrect.'); $messages->showmessage(); exit; } } else { $messages->message('Token is incorrect or not set.'); $messages->showmessage(); exit; } if(!isset($_POST['checkout-post'])) { $messages->message('Checkout page could not be loaded from resource and cannot be accessed this way.'); $messages->showmessage(); exit; } /* Get the currency of site.json * To change the default currency, edit site.json which has a numeric value that corresponds to the values inside currencies.json. * DO NOT edit currencies.json, unless adding a new currency, as this file is used throughout OpenShop and might break functionality. */ $sitecurrency = $shop->getsitecurrency('../server/config/site.conf.json','../server/config/currencies.conf.json'); // echo $shop->debug($_POST); if(isset($_POST['payment_gateway'])) { $payment_gateway = $sanitizer->sanitize($_POST['payment_gateway'],'encode'); } else { $payment_gateway = 'PayPal'; $messages->message('Payment Gateway not selected, assuming and defaulting to PayPal'); $messages->showmessage(); } if(isset($_POST['shipping_country'])) { $shippingcountry = $sanitizer->sanitize($_POST['shipping_country'],'encode'); } else { $messages->message('Country not selected, cannot continue to checkout!'); $messages->showmessage(); exit; } if(isset($_POST['cooffset'])) { $addedvalue = true; $carbonvalue = (float)$_POST['cooffset']; $_SESSION['carbonoffset'] = $carbonvalue; } $gateway = $sanitizer->sanitize($payment_gateway,'alphanum'); ?> getmeta(); ?>

Checkout

= 1) { $c = count($_SESSION['cart']); if(($c > 0) && ($c < 9999) ) { ?>

  • 🛒
  • Product Name
  • Description
  • Variants
  • Price
  • Qty
  • Tax
  • Total
  • getproductlist('../inventory/shop.json'); $productsum_total = 0; $productsum = 0; $fixedpriceshipping = 0; $totaltax = 0; $totaltax_country = 0; $total_products_price = 0; $product_tax_calc = 0; $productshipping = 0; /* $productprice = 0; $productdesc = ''; $producttitle = ''; $producttax = 0; $taxitem = 'n/a'; */ for($i=0; $i < $c; $i++) { if($_SESSION['cart'][$i]) { $product = (int) $_SESSION['cart'][$i]['product.id']; if($_SESSION['cart'][$i]['product.qty'] == 0) { $_SESSION['cart'][$i]['product.qty'] = 1; } $productqty = $_SESSION['cart'][$i]['product.qty']; } $j = 0; if(isset($product)) { foreach($products as $key => $value) { if($products[$j][0][1] == $product) { for($k=0;$k=0) { if($value[$k][0] == 'variant.price1') { if(stristr($value[$k][1],',')) { $values = explode(',',$value[$k][1]); $productprice = trim($values[$key]); } } } if($value[$k][0] == 'product.description') { $productdesc = $value[$k][1]; } if($value[$k][0] == 'product.title') { $producttitle = $value[$k][1]; } if($value[$k][0] == 'product.tax') { $producttax = $value[$k][1]; } } if($productprice == null || $productprice == 0 ) { $productprice = 1; } if($productqty == null || $productqty == 0 ) { $productqty = 1; } if($producttax == null || $producttax == 0 ) { $producttax = 0; $totaltax_country = 1; // get tax for country in total, because there is no tax for a product. } else { } if((int)$productprice >=1) { $tax_price = ($productprice / 100); $product_tax_calc = round(($tax_price * $producttax),2); $total_products_price = round(($productprice + $product_tax_calc),2); $taxitem = $product_tax_calc; } else { $producttax = 0; $taxitem = 'n/a'; } if($productshipping != null || $productshipping != 0 ) { $fixedpriceshipping += ($productshipping * (int)$productqty); } $productsum = round(($total_products_price * (int)$productqty),2); $productsum_total += $productsum; $qtyid = 'tscart-'.$j.$product; ?>
  • 🛒
  • '; if($vc >=1) { for($j=0;$j<$vc;$j++) { echo $variants[$j]; if($j < ($vc-1)) { echo ', '; } } } else { echo 'n/a'; } echo ''; } ?>
  • json->load_json("../server/config/shipping.conf.json"); $countryprice = $shop->getcountryprice($siteconf,$shippingcountry); if($countryprice != false) { $country_price = (int)$countryprice; } else { $country_price = 10; // default shipping fee. } // free shipping logic. $free = false; $siteconf = $shop->json->load_json("../server/config/site.conf.json"); $freeshipping = $shop->getasetting($siteconf,'site.freeshipping'); $freeshipping = $freeshipping; if($freeshipping != '' || $freeshipping != null) { if((int)$freeshipping >= 1) { if(round((int)$productsum_total) >= round((int)$freeshipping)) { // shipping is free. $free = true; $totalshipping = 'free'; $total = $productsum_total; } } } if($free != true) { if($fixedpriceshipping > $country_price) { // fixed flatfee shipping, if individual items exceeds flat fee. $totalshipping = $country_price; $total = ($country_price + $productsum_total); } elseif($fixedpriceshipping > 0 && ($fixedpriceshipping < $country_price)) { // TODO: Calculate if there is an item without fixed shipping price. // If so, we default to flat fee again. $totalshipping = round($fixedpriceshipping,2); $total = ($totalshipping + $productsum_total); } else { // no item fixed price shipping, proceed with default country price. $totalshipping = $sitecurrency .' '. $country_price; $total = ($country_price + $productsum_total); } } if($totaltax_country >=1) { // there was a product without tax, get country tax. $country_tx = str_replace('shipping.','',$shippingcountry); $shippingcountry = 'tax.' . strtolower($country_tx); $json = $shop->json->load_json("../server/config/tax.conf.json"); if($json !== null) { if(isset($json[0][$shippingcountry])) { if( $json[0][$shippingcountry] != null && $json[0][$shippingcountry] != '') { $totaltax = str_replace(['%',' '],['',''],$json[0][$shippingcountry]); } } } if($totaltax >=1) { $pre_tax = ($productsum_total / 100); $productsum_total += round(($pre_tax * $totaltax),2); $total += round(($pre_tax * $totaltax),2); } } else { //$productsum_total = $total_products_price; //$total = $productsum_total; $country_tx = str_replace('shipping.','',$shippingcountry); } if($totaltax <= 0) { $totaltax = 'payable per unit.'; $totaltax_session = 'payable per unit.'; } else { $totaltax = $totaltax .'%'; $totaltax_session = $totaltax; } if($addedvalue == true) { $total = ($total + $carbonvalue); } ?>

  • Country
  • Tax
  • Subtotal
  • Shipping & handling
  • Carbon offset
  • Total
  • '; } else { ?>
  • uniqueID(); $_SESSION['cartid'] = $sanitizer->sanitize($uniqueid,'alphanum'); $_SESSION['tax'] = str_replace('percnt','',$sanitizer->sanitize($totaltax_session,'alphanum')); $_SESSION['subtotal'] = (int) $productsum_total; $_SESSION['shipping'] = (int) $totalshipping; $_SESSION['totalprice'] = (int) $total; $_SESSION['shipping_country'] = $country_tx; if(isset($_POST['email'])) { // we use this for pre-payment in paypal gateway. $_SESSION['email'] = $sanitizer->sanitize($_POST['email'],'email'); } } } else { echo "
    Cart is empty.
    "; } ?>