• User Attivo

    Problemi con una modifica ad una carta

    Salve a tutti, ho un theme e-commerce ed avrei bisogno di modificare un file, ma non ne riesco a venire a capo.

    Il file da modificare e quello della carta che calcola il totale, praticamente al momento il theme mi calcola le spedizioni in base alla quantità (es. per ogni oggetto 10€ di spedizioni), io avrei bisogno di calcolare il tutto in base ad un altro dato che sarebbe la dimensione, quindi calcolare il totale del peso e a seconda della fascia di appartenenza assegnare un valore alla spedizione.

    Se solamente mi aiutereste a dire come richiamare all'interno del file la dimensione stessa, potrei provvedere al resto, il punto è che io non la riesco proprio a prelevare.
    Grazie mille a chiunque mi aiuterà

    Questo è il codice del file:

    [PHP]<?php
    session_start();

    error_reporting (E_ALL ^ E_NOTICE);

    // Get Session variable data
    $LANGUAGE = $_SESSION["LANGUAGE"];
    $CURRENCY_SYMBOL = $_SESSION["CURRENCY_SYMBOL"];
    $CURRENCY_CODE = $_SESSION["CURRENCY_CODE"];
    $PPEmail = $_SESSION["PPEmail"];
    $CARTDIR = $_SESSION["CARTDIR"];
    $CARTURL = $CARTDIR . "cart.php";
    $CHECKOUT_RETURNURL = $_SESSION["POSTSALE_URL"];

    require("../language/" . $LANGUAGE . ".php");

    // Load WordPress
    $load = '../../../../wp-load.php';
    if (file_exists($load)){
    require($load);
    } else {
    wp_die('Error: wp-load file not found');
    }

    // Payment Processing Post URL -- (Enable only one)
    $ACTION_URL = "https:// - www - paypal.com/cgi-bin/webscr"; //Paypal
    //$ACTION_URL = "https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/YOURMERCHANTIDHERE"; //Google Checkout (change merch ID)

    //TODO: Create Cart Object
    $crtQuantity = array();
    $crtStockQuantity = array();
    $crtAmount = array();
    $crtShipping = array();
    $crtShipping2 = array();
    $crtHandling = array();
    $crtHandlingCart = array();
    $crtOptions = array();
    $PPOptions = array();

    //retrieve session Variables
    if($_SESSION["Quantity"]){
    $crtName = $_SESSION["Name"];
    $crtNotes = $_SESSION["Notes"];
    $crtPostID = $_SESSION["PostID"];
    $crtQuantity = $_SESSION["Quantity"];
    $crtStockQuantity = $_SESSION["StockQuantity"];
    $crtAmount = $_SESSION["Amount"];
    $crtShipping = $_SESSION["Shipping"];
    $crtShipping2 = $_SESSION["Shipping2"];
    $crtHandling = $_SESSION["Handling"];
    $crtHandlingCart = $_SESSION["HandlingCart"];
    $crtOptions = $_SESSION["Options"];
    $PPOptions = $_SESSION["PPOptions"];
    }

    //convert strings to integers
    function str2int($string, $concat = true) {
    $length = strlen($string);
    for ($i = 0, $int = '', $concat_flag = true; $i < $length; $i++) {
    if (is_numeric($string*) && $concat_flag) {
    $int .= $string*;
    } elseif(!$concat && $concat_flag && strlen($int) > 0) {
    $concat_flag = false;
    }
    }

    return (int) $int;
    

    }

    //Save Session Variables
    function SaveSession($crtName,$crtNotes,$crtPostID,$crtAmount,$crtQuantity,$crtStockQuantity,$crtShipping,$crtShipping2,$crtHandling,$crtHandlingCart,$crtOptions,$PPOptions=' '){
    $_SESSION["Name"] = $crtName;
    $_SESSION["Notes"] = $crtNotes;
    $_SESSION["PostID"] = $crtPostID;
    $_SESSION["Quantity"] = $crtQuantity;
    $_SESSION["StockQuantity"] = $crtStockQuantity;
    $_SESSION["Amount"] = $crtAmount;
    $_SESSION["Shipping"] = $crtShipping;
    $_SESSION["Shipping2"] = $crtShipping2;
    $_SESSION["Handling"] = $crtHandling;
    $_SESSION["HandlingCart"] = $crtHandlingCart;
    $_SESSION["Options"] = $crtOptions;
    $_SESSION["PPOptions"] = $PPOptions;

    }

    //Monolithic display cart function
    function ShowCart($crtName,$crtNotes,$crtPostID,$crtAmount,$crtQuantity,$crtStockQuantity,$crtShipping,$crtShipping2,$crtHandling,$crtHandlingCart,$crtOptions,$PPOptions){
    include("cart_top.php");

    global $CARTURL,$CURRENCY_SYMBOL,$ACTION_URL,$CHECKOUT_RETURNURL,$CARTDIR;
    
    $checkout = '';
    $prods = '';
    $i = 1;
    $ShippingTotal = 0;
    $GrandTotal = 0;
        // Calculation of $ShippingTotal - starts
        if(!empty($crtPostID))
        {
            $s_values = array();
            foreach( $crtPostID as $item =>$postid )
            {
                $r = array_key_exists($postid,$s_values);
                if(!$r)
                {
                    $s_values[$postid]['postID'] = $crtPostID[$item];
                    $s_values[$postid]['quantity'] = $crtQuantity[$item];
                    $s_values[$postid]['shipping'] = $crtShipping[$item];
                    $s_values[$postid]['shipping2'] = $crtShipping2[$item];                                                
                }
                else
                {
                    $s_values[$postid]['quantity'] = $s_values[$postid]['quantity'] + $crtQuantity[$item];
                }
            }
            $ShippingTotal = 0;
            foreach( $s_values as $postid =>$v )
            {
                if ($v['quantity'] > 1)
                {
                    $ShippingTotal = $ShippingTotal + $v['shipping'];
                    $ShippingTotal = $ShippingTotal + (($v['quantity'] - 1) * $v['shipping2']);
                }
                else
                {
                    $ShippingTotal = $ShippingTotal + $v['shipping'];
                }
            }
        }    // End -- if(!empty($crtPostID))
        // Calculation of $ShippingTotal - ends
        
        foreach( $crtAmount as $item =>$amount )
        {
            $GrandTotal = $GrandTotal + ($crtAmount[$item] * $crtQuantity[$item]);            
            
            // Check if Special Comments Box is allowed for this post or not.
            $mkt_special_comment_box = get_post_meta($crtPostID[$item], 'mkt_special_comment_box', $single = true);
            $sp_comments = '';
            if(($mkt_special_comment_box == "1") AND (!empty($crtNotes[$item])))
            {
                $sp_comments = '<br><div style="margin-left: 10px;"><small><a title="'.$crtNotes[$item].'">'.mkt_SHOPCART_ITEM_SPECIAL_INSTRUCTIONS.'</a></small></div>';
            }
            
            $mkt_pk_item_amount = $CURRENCY_SYMBOL.number_format((float)($crtAmount[$item] * $crtQuantity[$item]), 2, '.', ',');
            
            $Shipping = 'Shipping: '.$CURRENCY_SYMBOL.$Shipping;
            $content .= '<tr id="'.$item.'"><td>'.$crtName[$item].$sp_comments.'</td><td style="text-align:left;">'.$crtOptions[$item].'</td><td style="text-align:center;"><input class="quantity" name="'.$item.'" type="text" value="'.$crtQuantity[$item].'" /></td><td style="text-align:center;"><a href="'.$GLOBALS["CARTURL"].'?remove='.$item.'" class="crtRemove">'.mkt_SHOPCART_ITEM_REMOVE.'</a></td><td style="text-align:right;">'.$mkt_pk_item_amount.'</td></tr>';
    
            
                if ($crtHandling[$item]){
                    $Handling = $crtHandling[$item];
                        if($crtQuantity[$item] > 1){ 
                            $Handling += $crtHandlingCart[$item] * ($crtQuantity[$item] - 1);
                        }
                    $checkout .='<input type="hidden" name="handling_'.$i.'" value="'.$Handling.'" />';
                }
            
            $checkout .='<input type="hidden" name="item_name_'.$i.'" value="'.$crtName[$item].'" />
                <input type="hidden" name="amount_'.$i.'" value="'.$crtAmount[$item].'" />
                <input type="hidden" name="quantity_'.$i.'" value="'.$crtQuantity[$item].'" />';
    
            // The following 4 inputs are for Google Checkout purposes
            $checkout .='<input type="hidden" name="item_description_'.$i.'" value="'.$crtOptions[$item].'" />
                        <input type="hidden" name="item_quantity_'.$i.'" value="'.$crtQuantity[$item].'" />
                        <input type="hidden" name="item_price_'.$i.'" value="'.$crtAmount[$item].'" />
                        <input type="hidden" name="item_currency_'.$i.'" value="'.$GLOBALS["CURRENCY_CODE"].'" />';
                        
              $tmp = explode("<br />",$crtOptions[$item]);
    
    
             $itr=0;
              foreach ($tmp as $chk){
                if($chk!=""){
                    list($opt,$val)=explode(":",$chk);
                    $checkout.='<input type="hidden" name="on'.$itr.'_'.$i.'" value="'.$opt.'" /><input type="hidden" name="os'.$itr.'_'.$i.'" value="'.$val.'" />';
                }
               ++$itr;
              }
              
            // Create value for inventory control              
            // $prods = $prods . $crtPostID[$item] . "-" . $crtQuantity[$item];
                $mkt_pk_item_amount = (float)($crtAmount[$item] * $crtQuantity[$item]);
                $prods = $prods . $crtPostID[$item] . "+:#" . $crtName[$item]. "+:#". $crtOptions[$item]. "+:#" . $crtQuantity[$item]. "+:#" . $mkt_pk_item_amount. "+:#" . $crtNotes[$item] . "+:#" .$item_shipping_pk;
                if ($i < count($crtPostID)) {
                //    $prods = $prods . ",";
                    $prods = $prods . "^:*";
                }
                
            ++$i;            
        }
        
        // If no item value, then display message
        if ($item == null){
            $content .= '<tr><td colspan=5>'.mkt_SHOPCART_NOITEMS.'</td></tr>';
        }
    
    $ItemSubTotal = $GrandTotal;
    $GrandTotal = $GrandTotal + $ShippingTotal;
    

    session_register("grand_total");
    $_SESSION["grand_total"] = $GrandTotal;
    session_register("item_subtotal");
    $_SESSION["item_subtotal"] = $ItemSubTotal;
    session_register("shipping_cost");
    $_SESSION["shipping_cost"] = $ShippingTotal;

    $mkt_pk_ItemSubTotal = $CURRENCY_SYMBOL.number_format($ItemSubTotal, 2, '.', ',');
    $mkt_pk_ShippingTotal = $CURRENCY_SYMBOL.number_format($ShippingTotal, 2, '.', ',');
    $mkt_pk_GrandTotal = $CURRENCY_SYMBOL.number_format($GrandTotal, 2, '.', ',');
    
    $content .= '<tr><td colspan=4 align=right>'.mkt_SHOPCART_SUBTOTAL.'<br/>'.mkt_SHOPCART_SHIPPING.'<br/><b>'.mkt_SHOPCART_TOTAL.'</b></td><td style="text-align:right;">'.$mkt_pk_ItemSubTotal.'<br/>'.$mkt_pk_ShippingTotal.'<br/><b>'.$mkt_pk_GrandTotal.'</b></td></tr>';
    
    // Create product summary session variable for inventory control postsale page
        $_SESSION["prods"] = $prods;
        $_SESSION["mkt_pk_ItemSubTotal"] = $mkt_pk_ItemSubTotal;
        $_SESSION["mkt_pk_ShippingTotal"] = $mkt_pk_ShippingTotal;
        $_SESSION["mkt_pk_GrandTotal"] = $mkt_pk_GrandTotal;
    
    // The following 4 inputs are Google Checkout variables
        $checkout .='<input type="hidden" name="ship_method_name_1" value="Ship Method"/>';
        $checkout .='<input type="hidden" name="ship_method_price_1" value="'.$ShippingTotal.'" />';
        $checkout .='<input type="hidden" name="ship_method_currency_1" value="'.$GLOBALS["CURRENCY_CODE"].'" />';            
        $checkout .='<input type="hidden" name="checkout-flow-support.merchant-checkout-flow-support.continue-shopping-url" value="' . $CHECKOUT_RETURNURL . '">';
    
    // Send the ADMIN EMAIL address too...
        $checkout .='<input type="hidden" name="mkt_pk_admin_email" value="'.$_SESSION["mkt_pk_admin_email"].'"/>';
    
    include("cart_bottom.php");
    echo $content;
    

    }

    if($_GET['cart']){
    ShowCart($crtName,$crtNotes,$crtPostID,$crtAmount,$crtQuantity,$crtStockQuantity,$crtShipping,$crtShipping2,$crtHandling,$crtHandlingCart,$crtOptions,$PPOptions);
    }

    if($_GET["remove"]){
    $item = removeItem($_GET["remove"]);
    }

    function removeItem($item){
    global $crtName,$crtNotes,$crtPostID,$crtAmount,$crtQuantity,$crtStockQuantity,$crtShipping,$crtShipping2,$crtHandling,$crtHandlingCart,$crtOptions,$PPOptions;
    unset($crtName[$item]);
    unset($crtNotes[$item]);
    unset($crtPostID[$item]);
    unset($crtAmount[$item]);
    unset($crtQuantity[$item]);
    unset($crtStockQuantity[$item]);
    unset($crtShipping[$item]);
    unset($crtShipping2[$item]);
    unset($crtHandling[$item]);
    unset($crtHandlingCart[$item]);
    unset($crtOptions[$item]);
    SaveSession($crtName,$crtNotes,$crtPostID,$crtAmount,$crtQuantity,$crtStockQuantity,$crtShipping,$crtShipping2,$crtHandling,$crtHandlingCart,$crtOptions,$PPOptions);
    return $item;
    }

    if($_GET["update"]){
    foreach ($_GET as $item => $value ){

        if($crtQuantity[$item]){
            if (($crtStockQuantity[$item] != "") && ($value > $crtStockQuantity[$item])) {
                echo "<span style='color:#F00000;'><b>" . mkt_SHOPCART_OVERSTOCK_MESSAGE . " " . $crtStockQuantity[$item] . " -- (" . $crtName[$item]  . ")</b></span><br>";
                $crtQuantity[$item] = $crtStockQuantity[$item];
            } else {
                $crtQuantity[$item] = str2int($value);
            }            
            // If value = 0 then remove item from list
            if($crtQuantity[$item] == 0){
                removeItem($item);
            } 
         }
    }
    SaveSession($crtName,$crtNotes,$crtPostID,$crtAmount,$crtQuantity,$crtStockQuantity,$crtShipping,$crtShipping2,$crtHandling,$crtHandlingCart,$crtOptions,$PPOptions);
    ShowCart($crtName,$crtNotes,$crtPostID,$crtAmount,$crtQuantity,$crtStockQuantity,$crtShipping,$crtShipping2,$crtHandling,$crtHandlingCart,$crtOptions,$PPOptions);
    

    }

    if($_GET["add"]){
    $item ="item".rand();//An Id can be used in lue of store with multiple items with the same name
    $name = $_GET["item_name"];
    $notes = $_GET["notes"];
    $postID = $_GET["postID"];
    $amt = (float)$_GET["amount"];
    $handling = (float)$_GET["handling"];
    $handling_cart = (float)$_GET["handling_cart"];
    $quan = str2int($_GET["quantity"]);
    $stockquantity = str2int($_GET["stockquantity"]);
    $ppoptions = "";
    $optionpricing = 0;

    $options = "";
    $i = 0;
    
    if(strpos($_GET["shipping"],"/")){
        $ar = explode("/",$_GET["shipping"]);
        $ship = (float)$ar[0];
        $ship2= (float)$ar[1];
    }else{
        $ship = (float)$_GET["shipping"];
        $ship2= 0;
    }
    
    foreach ($_GET as $key => $value ){
        $val = substr($key,0,2);
            if($val=="on"){
                $opt = substr($key,2,1);
                $index = "os".$opt;
    
                // Option pricing begin
                $optionval = explode("@",$_GET[$index]);
                $optionpricing = $optionpricing + $optionval[1];
                if ($optionval[1]) {
                    if ($optionval[1]>0) {
                        $optiontext = " (+"; 
                    } else {
                        $optiontext = " (-"; 
                    }
                    $optiontext = $optiontext . $CURRENCY_SYMBOL.number_format(abs($optionval[1]), 2, '.', ','); 
                    $optiontext = $optiontext .")";
                } else {
                    $optiontext = "";
                }
                // Option pricing end            
    
                $options.= $value.': '.$optionval[0].$optiontext.'<br />';
                ++$i;
            }
    }
        
    // Check for duplicate products
        if ($crtPostID == "") {$crtPostID = array();}
        $duplicate_prodIDs = array_keys($crtPostID, $postID);
        for($i=0; $i<count($duplicate_prodIDs); $i++)
        {
            $totalprodquan += $crtQuantity[$duplicate_prodIDs*];
            $s1 = trim($notes);
            $s2 = trim($crtNotes[$duplicate_prodIDs*]);
            $cmp = strcasecmp($s1, $s2);
            if (($postID == $crtPostID[$duplicate_prodIDs*]) && ($options == $crtOptions[$duplicate_prodIDs*]) && ($cmp == 0)) 
            {
                $duplicateitemID = $duplicate_prodIDs*;
            }
        }
    
    
    // Check to see if this puts it over stock quantity
    if (($stockquantity !="") && ($totalprodquan + $quan > $stockquantity)) {
        echo "<span style='color:#F00000;'><b>" . mkt_SHOPCART_OVERSTOCK_MESSAGE . " " . $stockquantity . " -- (" . $name  . ")</b></span><br>";
    } else {
        if ($duplicateitemID) {
                    $crtQuantity[$duplicateitemID] += $quan;
                    $crtNotes[$duplicateitemID] = $notes;    
                //if($crtShipping[$item] < $ship){
                    $crtShipping[$item] = $ship;
                    $crtShipping2[$item] = $ship2;
                    $crtHandling[$item] = $handling;
                    $crtHandlingCart[$item] = $handling_cart;
                //}
        }else{// A new item
            $crtName[$item] = $name;
            $crtNotes[$item] = $notes;            
            $crtPostID[$item] = $postID;
            $crtAmount[$item] = $amt + $optionpricing;
            $crtShipping[$item] = $ship;
            $crtShipping2[$item] = $ship2;
            $crtHandling[$item] = $handling;
            $crtHandlingCart[$item] = $handling_cart;
            $crtQuantity[$item] = $quan;
            $crtStockQuantity[$item] = $stockquantity;
            $crtOptions[$item] = $options;
            $PPOptions[$item] = $ppoptions;
        }
    }
    //Save the Session and Display the cart
    SaveSession($crtName,$crtNotes,$crtPostID,$crtAmount,$crtQuantity,$crtStockQuantity,$crtShipping,$crtShipping2,$crtHandling,$crtHandlingCart,$crtOptions,$PPOptions);
    ShowCart($crtName,$crtNotes,$crtPostID,$crtAmount,$crtQuantity,$crtStockQuantity,$crtShipping,$crtShipping2,$crtHandling,$crtHandlingCart,$crtOptions,$PPOptions);
    

    }

    ?>[/PHP]