Example #1
0
 function getSubTotalFromCartContents()
 {
     $cart2 = new cart2();
     $cart = $cart2->readCart();
     $sub = 0;
     foreach ($cart as $cartproduct) {
         $sub += $cartproduct->quantity * $cartproduct->finalprice;
     }
     return $sub;
 }
Example #2
0
 function ShowConfirmCart($cart, $pretext = null, $posttext = null, $ship = null)
 {
     global $mainframe;
     $debug = 0;
     //todo: add the full server path here instead of the relative local one
     $mainframe->addCustomHeadTag('<link rel="stylesheet" href="components/com_caddy/css/simplecaddy.css" type="text/css" />');
     $mainframe->addCustomHeadTag("<script type='text/javascript' src='components/com_caddy/js/ajax.js'></script>");
     $showhidden = "hidden";
     if ($debug == 1) {
         $showhidden = "text";
     }
     $line = __LINE__;
     $cfg = new sc_configuration();
     $tsep = $cfg->get('thousand_sep');
     $dsep = $cfg->get('decimal_sep');
     $decs = $cfg->get('decimals');
     $currency = $cfg->get('currency');
     $curralign = $cfg->get('curralign');
     $showremove = $cfg->get('remove_button');
     $show_emptycart = $cfg->get('show_emptycart');
     $currency = $cfg->get('currency');
     $currleftalign = $cfg->get('curralign');
     $stdprodcode = $cfg->get("cart_fee_product");
     $shipping = $cfg->get("shippingenabled");
     $cfp = $cfg->get("taxrate");
     $cfp = str_replace("%", "", $cfp);
     if ($cfp > 1) {
         $cfp = $cfp / 100;
     }
     $taxrate = $cfp;
     $gtotal = 0;
     $html = @$pretext->introtext;
     // the text preceding the confirm page
     //		$html .= "<table><tr><td>";
     $html .= "\n<div class='sc_cart'>";
     //error message regarding no shipping selected
     $error = JRequest::getVar("error", null);
     if ($error != null) {
         $html .= "<div class='errormsg'>{$error}</div>";
     }
     $html .= "\n<div class='cartheading'>\n<div class='code_col'>" . JText::_('SC_CODE') . "</div>\n<div class='desc_col'>" . JText::_('SC_DESCRIPTION') . "</div>\n<div class='price_col'>" . JText::_('SC_PRICE_PER_UNIT') . "</div>\n<div class='qty_col'>" . JText::_('SC_QUANTITY') . "</div>\n<div class='total_col'>" . JText::_('SC_TOTAL') . "</div>\n<div class='actions_col'>&nbsp;</div></div>";
     $emptycart = true;
     if (!is_array($cart)) {
         $cart = array();
     }
     foreach ($cart as $key => $cartproduct) {
         $formname = uniqid("Z");
         $html2 = "<form name='{$formname}' method='post'>";
         $html2 .= "\n<div class='code_col'>{$cartproduct->prodcode}</div>";
         $html2 .= "\n<div class='desc_col'>" . urldecode($cartproduct->prodname) . " - " . urldecode($cartproduct->option) . "</div>";
         $pu = number_format($cartproduct->finalprice, $decs, $dsep, $tsep);
         if ($currleftalign == 1) {
             $html2 .= "\n<div class='price_col'>{$currency}&nbsp;" . $pu . "</div>";
         } else {
             $html2 .= "\n<div class='price_col'>{$pu}&nbsp;{$currency}</div>";
         }
         $html2 .= "\n<div class='qty_col'>";
         $html2 .= $cartproduct->quantity;
         $html2 .= "</div>";
         $html2 .= "\n<div class='total_col'>";
         $total = $cartproduct->quantity * $cartproduct->finalprice;
         $nombre_format = number_format($total, $decs, $dsep, $tsep);
         $gtotal = $gtotal + $total;
         if ($currleftalign == 1) {
             $html2 .= "{$currency}&nbsp;" . $nombre_format;
         } else {
             $html2 .= $nombre_format . "&nbsp;{$currency}";
         }
         $html2 .= "\n<input type='{$showhidden}' name='id' value='{$cartproduct->id}'>";
         $html2 .= "</div>\n<div class='actions_col'>";
         $html2 .= "\n<input type='hidden' name='option' value='com_caddy'>";
         $html2 .= "\n<input type='hidden' name='action' value='changeqty'>";
         $html2 .= "\n<input type='hidden' name='edtprodcode' value='" . $cartproduct->prodcode . "'>";
         $html2 .= "\n<input type='hidden' name='edtunitprice' value='" . $cartproduct->unitprice . "'>";
         $html2 .= "\n<input type='hidden' name='edtshorttext' value='" . $cartproduct->prodname . "'>";
         $html2 .= "\n<input type='hidden' name='edtoption' value='" . $cartproduct->option . "'>";
         $html2 .= "</form>";
         $html2 .= "</div>";
         if ($cartproduct->quantity) {
             $html .= $html2;
             // only add to display when qty != zero !
             $emptycart = false;
         }
     }
     //start checkout form
     $html .= "<form name='checkout' method='post'>";
     //shipping things go the enabler (Switch)
     //as shipping is purely for display purposes at the moment it interfers with nothing except increasing the totals
     if ($ship['enabled']) {
         //start shipping region select row
         $html .= "\n<div class='fill_col'>";
         $html .= "<div class='text_left'>" . JText::_('SC_SHIPPING_SELECT') . "</div>";
         $html .= "\n<div class='text_right'>" . $ship['list'] . "</div>";
         $html .= "</div>";
         //start shipping cost row
         $html .= "\n<div class='fill_col'>";
         $html .= "<div class='text_left'>" . JText::_('SC_SHIPPING_COST') . "</div>";
         $html .= "\n<div class='text_right'>";
         $html .= "<div id='shipCost'></div>";
         $html .= "<div id='ajaxloader' style='display:none'><img src='components/com_caddy/images/loader.gif' /></div>";
         $html .= "</div>";
         $html .= "</div>";
     }
     //end shipping additions
     $ccart = new cart2();
     if ($cfg->get("usevouchers") == 1) {
         if (!$ccart->isInCart("voucher")) {
             // only show if no voucher in cart
             //start voucher row
             $html .= "\n<div class='fill_col'>";
             $html .= "<div class='text_left'>" . JText::_('SC_VOUCHER') . "</div>";
             $html .= "\n<div class='text_right'>";
             $html .= "<div id='voucherdiv'><input type='text' size='5' name='voucher' id='voucher' value=''>";
             //  onblur='javascript:getVoucherInfo(this.value);'
             $html .= "<input type='button' name='btnrefresh' value='" . JText::_('SC_CHECK_VOUCHER') . "' class='btnemptycart' onclick='javascript:document.checkout.action.value=\"refresh\";document.checkout.submit(); '>";
             //javascript:getVoucherInfo()
             $html .= "<div id='voucherinfo' class='voucherinfo'>&nbsp;</div></div>";
             $html .= "</div>";
             $html .= "</div>";
         }
     }
     //start tax row
     if ($taxrate > 0) {
         $html .= "\n<div class='fill_col'>";
         $html .= "<div class='text_left'>" . JText::_('SC_SUBTOTAL') . "</div>";
     } else {
         //if no tax is being used, still need somewhere to dump the values that the shipping ajax call drags u, or else the ajax call fails half way through with unexpected resulats usually causing javascript to be disabled on the page.
         $html .= "\r\n\t\t\t<div style='display:none'>\r\n\t\t\t<div id='scTax'></div><div id='scSub'></div>\r\n\t\t\t</div>";
     }
     if ($taxrate > 0) {
         if ($currleftalign == 1) {
             $html .= "\n<div class='text_right'><div id='scSub'>{$currency}&nbsp;" . number_format($gtotal, $decs, $dsep, $tsep) . "</div></div>";
         } else {
             $html .= "\n<div class='text_right'><div id='scSub'>" . number_format($gtotal, $decs, $dsep, $tsep) . "&nbsp;{$currency}</div></div>";
         }
         $html .= "</div>";
         $html .= "\n<div class='fill_col'>";
         $html .= "<div class='text_left'>" . JText::_('SC_TAX') . "</div>";
         if ($currleftalign == 1) {
             $html .= "\n<div class='text_right'><div id='scTax'>{$currency}&nbsp;" . number_format($gtotal * $taxrate, $decs, $dsep, $tsep) . "</div></div>";
         } else {
             $html .= "\n<div class='text_right'><div id='scTax'>" . number_format($gtotal * $taxrate, $decs, $dsep, $tsep) . "&nbsp;{$currency}</div></div>";
         }
         $html .= "</div>";
     }
     $html .= "<div class='fill_col_total'>";
     $html .= "<div class='text_left'>" . JText::_('SC_TOTAL') . "</div>";
     if ($currleftalign == 1) {
         $html .= "\n<div class='text_right'><div id='scgTotal'>{$currency}&nbsp;" . number_format($gtotal + $gtotal * $taxrate, $decs, $dsep, $tsep) . "</div></div>";
     } else {
         $html .= "\n<div class='text_right'><div id='scgTotal'>" . number_format($gtotal + $gtotal * $taxrate, $decs, $dsep, $tsep) . "&nbsp;{$currency}</div></div>";
     }
     $html .= "</div>";
     $html .= "\n<div class='cartactions'>";
     if ($show_emptycart == 1) {
         $html .= "\n<input type='button' name='btnemptycart' value='" . JText::_('SC_EMPTY_CART') . "' class='btnemptycart' onclick='javascript:document.checkout.action.value=\"emptycart\";javascript:document.checkout.submit()'>";
     }
     $html .= "\n<input type='hidden' name='option' value='com_caddy'>";
     $html .= "\n<input type='hidden' name='action' value='confirm'>";
     $html .= "\n<input name='scodrbtn' class='btnconfirm' type='submit' value='" . JText::_('SC_CONFIRM') . "' onclick='javascript:document.checkout.submit()'>";
     $html .= "</div>";
     $html .= "</form>";
     if ($emptycart) {
         $html = "<div>";
         $html .= JText::_('SC_CART_EMPTY');
     }
     $html .= "</div><div id='debug'></div>";
     //		$html .= "</td></tr></table>";
     $html .= @$posttext->introtext;
     // the text below the checkout page
     echo $html;
     if ($debug == 1) {
         echo $line;
     }
 }
Example #3
0
 function redeemvoucher($voucher)
 {
     global $mainframe;
     $cfg = new sc_configuration();
     $cfp = $cfg->get("taxrate");
     $cfp = str_replace("%", "", $cfp);
     if ($cfp > 1) {
         $cfp = $cfp / 100;
     }
     $taxrate = $cfp;
     $cartProd = new CartProduct();
     $cartProd->prodcode = "voucher";
     $cartProd->option = "";
     $cartProd->prodname = $voucher->name;
     $cartProd->unitprice = 0;
     $cartProd->quantity = 1;
     $cartProd->finalprice = 0;
     // matheval("$cartProd->unitprice $cartProd->formula");
     $cart = new cart2();
     $cart->removeCartProduct($cartProd);
     // remove any vouchers from the cart
     /**
     		$acart=$cart->readCart(); // returns array of cart products
     		$gtotal=0;
     		foreach ($acart as $key=>$cartproduct) {
     			$total=$cartproduct->quantity*$cartproduct->finalprice;
     			$gtotal= $gtotal + $total;
     		}
     */
     $gtotal = $cart->getCartTotal();
     $korting = $gtotal - matheval("{$gtotal} {$voucher->formula}");
     $cartProd->finalprice = $korting * -1;
     // just to get the amount back in the cart
     $cartProd->unitprice = $cartProd->finalprice;
     $cartProd->id = "voucher";
     $cart->addCartProduct($cartProd);
     // now return the values for immediate display
     $gtotal = $korting;
     $tax = $gtotal * $taxrate;
     $res['korting'] = $korting;
     $res['subtotal'] = $gtotal;
     $res['tax'] = $tax;
     $res['carttotal'] = $gtotal + $tax;
     return $res;
 }
Example #4
0
function AddStandard()
{
    $cfg = new sc_configuration();
    $stdprod = $cfg->get("cart_fee_product");
    if ($stdprod != "") {
        $tmp = new products();
        $sp = $tmp->getproductByProdCode($stdprod);
        $cartProd = new CartProduct();
        $cartProd->option = "";
        $cartProd->prodcode = $stdprod;
        $cartProd->prodname = $sp->shorttext;
        $cartProd->unitprice = $sp->unitprice;
        $cartProd->quantity = 1;
        $cartProd->finalprice = $sp->unitprice;
        $cartProd->id = uniqid("S");
        $cart2 = new cart2();
        $cart2->removecartProduct($cartProd);
        $c = $cart2->readcart();
        if (count($c) > 0) {
            $cart2->addCartProduct($cartProd);
        }
    }
}