Optional shopping cart

Asked

Viewed 184 times

-1

Positive added / Negative removed

([1] => 3 [6] => -2 ) 

Next customer can change all snack settings contains a default amount (recipe)

It can pull out 2x and can add 1x 2x 3x lettuce

in case he add 3x and withdrew 2x

then the system has to make a sub-stitution 1 steak per 1 lettuce and additional 1 lettuce, then the system has to have additional/withdrawal/replacement... in my view will always happen or replaces and adds or replaces and removes /// or just subistitui

remembering that everything dynamic can happen these possibilities several times

-+ Bacon por Alfance = R1,00
 + Alfance = R$ 0,50
-+ 2x Bacon por Alfance = R2,00
 + Alfance = R$ 0,50

here is a demonstration http://jsfiddle.net/qtx8jrLy how the client’s part of what he can do...

the ones already marked and the standard recipe of the product... that tbm can be changed...

I even managed to do

**o problema esta aki como interpretar esse array**    
(
    [1] => 3  // [id_produto] => quantidade
    [6] => -2 // [id_produto] => quantidade
    )
fazer-lo virar 
    -+ 2x Bacon por Alfance = R2,00
     + Alfance = R$ 0,50


**as os possivel acontecimentos para esse array** 

    -+ 2x Bacon por Alfance = R2,00
     + Alfance = R$ 0,50

    -+ Bacon por Alfance = R1,00
     - Alfance = R$ 0,50

    -+ 2x Bacon por Alfance = R1,00

http://www.amburgueria.com.br/carrinhoOO/ put the system online

  • I don’t understand what the problem is.

  • how to read this array... I was unable to interpret it

  • 1

    Maybe you should include a field Hidden with the total value of the products, then when adding or removing an item from the snack, you will make the management according to the "balance" of the customer. E in Array bring more information like [id] = {[quantidade] = 3, [valor] = [2.00], [qtd_padrao] = 2}

2 answers

1

Your problem starts with the client and is transported to the server. To begin solving, switch the checkbox to select and create an order form

<form name="pedido">
<label >Bife (adicione ou retire quantidade)</label>
<select name="bife">
<option value="-3">retirar 3 porções</option>
<option value="-2">retirar 2 porções</option>
<option value="-1">retirar 1 porções</option>
<option value="0">Não quero este ingrediente</option>
<option value="1">acrescentar 1 porções</option>
<option value="2">acrescentar 2 porções</option>
<option value="3">acrescentar 3 porções</option>
</select>

<label >Alface (adicione ou retire quantidade)</label>
<select name="alface">
<option value="-3">retirar 3 porções</option>
<option value="-2">retirar 2 porções</option>
<option value="-1">retirar 1 porções</option>
<option value="0">Não quero este ingrediente</option>
<option value="1">acrescentar 3 porções</option>
<option value="2">acrescentar 3 porções</option>
<option value="3">acrescentar 3 porções</option>
</select>

<label >Bacon (adicione ou retire quantidade)</label>
<select name="bacon">
<option value="-3">retirar 3 porções</option>
<option value="-2">retirar 2 porções</option>
<option value="-1">retirar 1 porções</option>
<option value="0">Não quero este ingrediente</option>
<option value="1">acrescentar 3 porções</option>
<option value="2">acrescentar 3 porções</option>
<option value="3">acrescentar 3 porções</option>
</select>
</form>

to receive on the server something like this:

$_POST["bife"] = 1;
$_POST["bacon"] = -2;
$_POST["alface"] = 0;


$receita["bife"] = 1;
$receita["bacon"] = 3;
$receita["alface"] = 5;

$preço["bife"] = 10;
$preço["bacon"] = 2;
$preço["alface"] = 1;




$pedido["bife"] = ($_POST["bife"]) ? ($receita["bife"]+$_POST["bife"]) * $preço["bife"]   : 0;
$pedido["bacon"] = ($_POST["bacon"]) ? ($receita["bacon"]+$_POST["bacon"]) * $preço["bacon"] : 0 ;
$pedido["alface"] = ($_POST["alface"]) ? ($receita["alface"]+$_POST["alface"]) * $preço["alface"] : 0;

$valor-do-pedido = $pedido["bife"] + $pedido["bacon"] + $pedido["alface"];

I think this makes the request less confusing for the user since it clearly informs him what he expects him to do, and makes the request easier to process.

Of course this code is extremely simple.

  • more arrives so there, msm with the checkboxes ai subitraio the array_client by the array_recipe... ai it returns [1] => 3 / [6] = -2 // that would be 3 lettuce adds and 2 steak removed... ends up not needing to select

  • the bid and interpret this array [1] = 3 / [6] = -2 /// -+ Bacon by Alfance = R1,00 + Alfance = R$ 0,50 -+ 2x Bacon by Alfance = R2,00 + Alfance = R$ 0,50

  • So much so that it cannot solve the problem. This is the second time you have asked the question. The more you complicate a situation, the more you increase the risk of errors. But it’s your choice. If it were a problem of mine, it would solve it like this. Simple and direct. But it’s only a suggestion, it’s your right to accept.

  • manuel notices well, what is different and checkbox to select... this option of yours would give the same thing... [lettuce] => 3 [bacon] = -2 / I arrive at msm way / in msm array I stay at 3 positive and 2 negative of msm way

  • and where is your price list? your table with the cost of each replacement?

  • in a db I will search them with the [$id] => quantity

  • but does it have a fixed price for each ingredient or depends on the replacement that the customer makes? That is, 1 serving of lettuce always costs 0.50 or if it is to replace the bacon costs 0.25 and if it is to replace the steak costs,75?

  • If it’s the last case, then you have to ask the client to say what replacements he wants to make, because being reduce the lettuce and bacon and increase the steak, you don’t know if he wants to replace it with bacon or lettuce.

  • then the value is fixed.. I subtract: bacon 2.00 / lettuce 1.00 = -1.00 these -1.00 set in the total value of the snack

  • I made an edit to calculate the order price.

  • It’s true there... which he wants to withdraw... you see some solution to this?

  • or I’ll have to make a page to add and remove and replace

  • when it wants to remove it becomes zero. You can write "I don’t want this ingredient". See the change

Show 8 more comments

0

I don’t really know how your project is going, nor the reason for using checkbox among other models, I also do not know if it is easy to change or not.

But I took the liberty of making a code that I hosted on Jsfiddle of how you could do this project of yours.

Link to the code

Link to PHP code

Hence an example like you can receive the data sent:

<?php 

   if (isset($_POST['produto'])){
      $pedido = '';

      foreach ($_POST['produto'] as $id => $dados) {
         if ($dados['qtd'] <= 0) continue;
         $pedido .= "ID: {$id} <br>QTD: {$dados['qtd']}<br><br>";
      }
      echo $pedido.'<hr><br>';
   }

?>

Ai just search in the bank for the item ID the value, multiply by the quantity and etc.

  • yes, and almost that @Kaduamaral , more like it will identify whether it is additional withdrawal or replacement? additional are +o-50 option // withdrawal are the standard ingredients // and replacement and if it removes one ingredient and adds another.. the problem that the system can not identify this example: I have added 2x bacon now I want to take out 2x 1x potato straw lettuce 1x egg with which of those 3 via make the replacement? want to take 1x potato and 1x lettuce

  • http://www.amburgueria.com.br/carrinhoOO/ take a look at the online system

  • Because then, in this example that I gave, if the guy wants to remove an item he leaves as 0, or else you can put a button on the side to delete the line, and if he wants to add, there are the additional options and also the option to change the quantity. And the product should be made by the data sent by the form.

  • yes I saw it, and replace it?

  • Do you need to limit the balance so that the value of the snack does not exceed the standard value? And this replacement, is the user going to choose what to replace? If so this is one more hole that you are digging, because if the user can remove one item and add another, joining the two would already replace.

  • so this msm joint remove and add there turns the replace... more the problem and that if he remove 2 items example potato and bacon and add cheese how will you know by which he wants to subistituir? unless it uses artificial intelligence to see which of the remove is more expensive and exchange for it? would be the solution?

  • then Kadu need to read this Aki array o ([1] => 3 [6] => -2 ) [id]=>positive amount and add / negative and remove... and an AI to replace that gives this array the subistituir and the price I look for in sql... ai seta pq the guy pd make a mess in these checkbox you saw http://www.amburgueria.com.br/carrinhoOO/ ? and in this case ai and 2 subistituir and an additional

  • What is the need to know which one to replace? I think you are complicating the situation.

  • because bacon and 2.00 lettuce and 1.00 file Migon 6.00 // 2 bacon = 4 -* 2 lettuce = 2 if it was with the biggest customer would only pay an additional 2 real

  • It is easier to control the price of the product, as in code I gave of example, each item has an individual value, and the total value of the snack is generated according to the amount of each item.

  • more and the same thing... if I decrement there the lettuce and the catupiry and 1x bacon and add +2 steak as it will do?

  • ([1] => 3 [6] => -2 [2] => -2) // [id_product] => quantity &#Xa+ 1x Lettuce -2x Cheddar

  • Man, I’m sorry I didn’t understand the purpose of your application. But in this sales model that you presented, which replaces the snack items, I would do the snack value over the value and quantity of each item. It would show a "standard recipe" for the user and let it modify, then it would send this modification and I would save his request in the database, pedidos(id, usuario); itens_pedidos(pedidoID, itemID, quantidade); itens(id, nome, valor).

Show 8 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.