0

I am using simplecart.js. The cart displays properly. What I want to do now is to retrieve the details in the cart and insert into a database. Here is my code.

simpleCart({
    cartColumns: [
        { attr: "name", label: "Name" },
        { attr: "price", label: "Price", view: 'currency' },
        { view: "decrement", label: false },
        { attr: "quantity", label: "Qty" },
        { view: "increment", label: false },
        { attr: "total", label: "SubTotal", view: 'currency' },
        { view: "remove", text: "Remove", label: false }
    ],
    cartStyle: "table",
    checkout: {
        type: "SendForm",
        url: base_url + "Checkout/checkout_function",
        method: "POST",
        success: base_url + "/Checkout/success",
        cancel: base_url + "Checkout/cancel"
    }
});

simpleCart.bind('beforeCheckout', function (data) {
    data.full_name = document.getElementById("full_name").value;
    data.phone = document.getElementById("phone").value;
    data.country = document.getElementById("country").value;
    data.state = document.getElementById("state").value;
    data.city = document.getElementById("city").value;
    data.address1 = document.getElementById("address1").value;
    data.address2 = document.getElementById("address2").value;
    data.zip = document.getElementById("zip").value;
    data.address_type = document.getElementById("address_type").value;
});

And the PHP file

for($i=1; $i < $content['itemCount'] + 1; $i++) 
{
    $prod_name = 'item_name_'.$i; /* product name variable */
    $quantity = 'item_quantity_'.$i; /* product quantity variable */
    $price = 'item_price_'.$i; /* product price variable */
    $shipping = 'simpleCart_shipping_'.$i; /* Shipping cost */
    $total = $content[$quantity]*$content[$price]; /* product total price variable (price*quantity) */
    $grandTotal += $total; /* accumulating the total of all items */            
}

The issue is when I try to echo any of the variables,does not display the content from the cart. Please how do I get the variables to contain the actual content, inserting them into a database will not be a problem.

Waleed Iqbal
  • 1,308
  • 19
  • 35
dkum
  • 105
  • 8
  • How is `$content` defined in your PHP? Have you debugged to see if it actually sends any info? Have you checked the console and the servers error log to see if you get any errors? Does it make the request correctly? – M. Eriksson Dec 20 '17 at 12:00
  • $_POST was assigned to $content, sorry for not including that.Also, II have found a problem. I was doing this: echo $prod_name instead of $content[$prod_name];' – dkum Dec 20 '17 at 12:05

0 Answers0