Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

my shopping cart does not capture the products on the first attempt #64

Open
BlackKwazi opened this issue May 31, 2020 · 1 comment
Open

Comments

@BlackKwazi
Copy link

if(isset($_POST["add_to_cart"])){

    if(isset($_SESSION["shopping_cart"])) {
        $item_array_id = array_column($_SESSION["shopping_cart"],"item_id");
        if(!in_array($_GET["ItemID"],$item_array_id)){

            $count = count($_SESSION["shopping_cart"]);
            $item_array = array(
                'item_id' => $_GET["ItemID"],
                'item_name' => $_POST["hidden_ProductName"],
                'item_price' => $_POST["hidden_ProductPrice"],
                'item_quantity' => $_POST["quantity"]
            );
            $_SESSION["shopping_cart"][$count] = $item_array;
        }
        else{
                echo '<script>alert("item already added, pick a different item")</script>';
                echo '<script> window.location ="productPage.php" </script>';
        }
    }
    else{
            $item_array = array(
                'item_id' => $_GET["ItemID"],
                'item_name' => $_POST["hidden_ProductName"],
                'item_price' => $_POST["hidden_ProdcutPrice"],
                'item_quantity' => $_POST["qunatity"]
            );
            $_SESSION["shopping_cart"][0] = $item_array;
    }
@BlackKwazi
Copy link
Author

$values){ ?>
                    <tr>
                        <td><?php echo $values["item_name"]; ?></td>
                        <td><?php echo $values["item_quantity"]; ?></td>
                        <td>R <?php echo $values["item_price"]; ?></td>
                        <td>R <?php echo number_format($values["item_quantity"] * $values["item_price"], 2); ?></td>
                        <td><a href="productPage.php?action=delete&ItemID=<?php echo $values["item_id"]; ?>"><span class="text-danger"> Remove </span></a></td>
                    </tr>
                    <?php 
                            $total = $total + ($values["item_quantity"] * $values["item_price"]);     
                        }
                    ?>
                    <tr>
                        <td colspan="3" align="right">Total</td>
                        <td align="rigt">R<?php echo number_format($total,2); ?> </td>
                        <td></td>
                    </tr>
                   <?php
                        }
                    ?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant