Creating rule to create time based on delivery rate

0

I have a condition in my form that calculates the delivery time of the orders, follows the rule below:

date_default_timezone_set('America/Sao_Paulo');
$Agora = date('H:i:s');
$HoraServico = date('H:i:s', strtotime('+69 minute', strtotime($Agora)));


if ( $Agora < '11:00:00'){
    $HoraServico = '12:00:00';
}

else if ( $Agora > '11:00:00' ){
    $HoraServico == $HoraServico;

};

Today all orders placed before 11am arrive at 12am on the client, and orders placed after 11am arrive 69 minutes later. That is, current time ($ Now) + 69 minutes.

What I need to do is create a rule where $ HourService is based on the delivery value $ delivery

Example: If the delivery fee is $ 7.00 then the delivery time will be the sum of the current time ($ Now) + 120 minutes.

If the delivery fee is $ 2.00 then the delivery time will be the sum of the current time ($ Now) + 30 minutes. And so on.

The idea is, the more expensive the delivery rate (because it is far) the more time it will cost to deliver.

I do not know if it would be like this:

date_default_timezone_set('America/Sao_Paulo');
$Agora = date('H:i:s');
$HoraServico = date('H:i:s', strtotime('+69 minute', strtotime($Agora)));

if ( $entrega = '5.00'){
    $HoraServico = date('H:i:s', strtotime('+120 minute', strtotime($Agora)));
}

if ( $entrega = '2.00'){
    $HoraServico = date('H:i:s', strtotime('+30 minute', strtotime($Agora)));

}

else if  ( $entrega = '7.00'){
    $HoraServico = date('H:i:s', strtotime('+20 minute', strtotime($Agora)));

};

I tested like this, but it's not going! It is always adding the middle option, where $entrega is equal to $ 2.00 - being in the case 30 minutes to add with current time.

As I understand it, it is not computing the delivery rate correctly ( $entrega = $_POST["taxadeentrega"]; )

In short, $entrega read the form field:

Thecodeforthisfieldintheformis:

<tr><td>TaxadeEntrega:</td><td><spanid="idTaxa"></span></td>
  </tr>
    
asked by anonymous 29.08.2017 / 23:57

2 answers

0

Solved !! Here is the correct code:

var arrayTempoEntrega = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110];
var arrTaxaEntrega = [4.80, 6.50, 6.00, 5.80, 5.30, 4.30, 3.80, 3.30, 2.50, 2.00, 1.50];
var taxadeentrega = total - taxa;

In the part of the CEPs

//aqui eu pego o cep
        var cep = document.getElementById("cep").value;


} if (cep == "20010-090" || cep == "20020-100" || cep == "20021-130" || cep == "20021-315" || cep == "20030-001" || cep == "20031-000" || cep == "20031-003" || cep == "20031-010" || cep == "20031-050" || cep == "20031-141" || cep == "20031-143" || cep == "20031-005" || cep == "20031-001" || cep == "20020-903" || cep == "20031-144" || cep == "20030-080" || cep == "20031-142" || cep == "20031-120" || cep == "20031-007" || cep == "20010-009" || cep == "20031-913" || cep == "20021-370" || cep == "20200-100" || cep == "20030-901" || cep == "20030-021" || cep == "20210-030" || cep == "24220-280") {

            //se for um dos ceps acima, incrementa 1.2 no valor final
            taxa = arrTaxaEntrega[9];
            tempoEntrega = arrayTempoEntrega[9];

        } if (cep == "20020-010" || cep == "20020-040" || cep == "20020-080" || cep == "20021-060" || cep == "20021-120" || cep == "20021-900" || cep == "20021-903" || cep == "20030-002" || cep == "20030-015" || cep == "20030-013" || cep == "20030-020" || cep == "20030-021" || cep == "20030-060" || cep == "20030-070" || cep == "20030-120" || cep == "20002-080" || cep == "20002-008" || cep == "20003-021" || cep == "20030-905" || cep == "24220-031" || cep == "20002-010" || cep == "20030-015") {

            //se for um dos ceps acima, incrementa 0.7 no valor final
            taxa = arrTaxaEntrega[10];
            tempoEntrega = arrayTempoEntrega[10];

        }

        total += taxa;

        if (taxa != 0) {
            //caso a taxa seja diferente de 0, mostra ao usuário
            document.getElementById("idTaxa").innerHTML = "Custo adicional: R$ " + taxa;
        }
        document.getElementById("idTempoEntrega").innerHTML = tempoEntrega + " min.";
        document.getElementById("TempoEntrega").value = tempoEntrega;
        $("div#total").html("Valor total da sua<br>encomenda: R$ " + String(total.toFixed(2)).replace(".", ","));
        $("div#total").css("display", "block");
        $("#total2").html("R$ " + String(total.toFixed(2)).replace(".", ","));
    }) //click
    $("#total2").html("R$ " + String(total.toFixed(2)).replace(".", ","));
    
05.09.2017 / 22:40
1

Hello,

It is "always adding the middle option" because of the fact that within the if, if e else if declarations you are performing an assignment operation and not a comparison of values.

Do the following:

date_default_timezone_set('America/Sao_Paulo');
$Agora = date('H:i:s');
$HoraServico = date('H:i:s', strtotime('+69 minute', strtotime($Agora)));

if ( $entrega == '5.00'){
    $HoraServico = date('H:i:s', strtotime('+120 minute', strtotime($Agora)));
}

if ( $entrega == '2.00'){
    $HoraServico = date('H:i:s', strtotime('+30 minute', strtotime($Agora)));

}

else if  ( $entrega == '7.00'){
    $HoraServico = date('H:i:s', strtotime('+20 minute', strtotime($Agora))); 
}
    
30.08.2017 / 02:31