public function updateComplement(){
$ids = $_GET['id'];
$names = $_GET['name'];
$valores = $_GET['valor'];
$quantities = $_GET['quantity'];
$idProdutos = $_GET['idProduto'];
$carrinho = [];
for ($i = 0; $i < count($ids); $i++) {
$id = $ids[$i];
$name = $names[$i];
$valor = $valores[$i];
$quantity = $quantities[$i];
$idProduto = $idProdutos[$i];
$checkC = Complemento::select()->where('id', $ids[$i])->first();
$carrinho = Carrinho::select()->where('product', $idProduto)->where('id_user', $this->loggedUser->id)->first();
$checkCart = Ccarrinho::select()->where('id_carrinho', $carrinho['id'])->first();
foreach ($carrinho as $car) {
}
if($checkC){
Ccarrinho::insert([
'id_user' => $this->loggedUser->id,
'name' => $name,
'subtotal' => $valor,
'quantity' => $quantity,
'id_c' => $id,
'id_carrinho' => $usarIdAlternativo ? $checkCcarinho['id'] : $car['id']
]);
}
}
}
I'm sending the additional data of a product through a fetch, receive them and add with the product that is in the user's shopping cart [CARRINHO], but I can not find a logic to create complement for each product in the cart.
up to 3 additional for each product in the cart, the add-ons are saved in the CCARRINHO table with the cart ID.
source https://stackoverflow.com/questions/76894985/question-about-php-verification-and-database
No comments:
Post a Comment