dkum
dkum

Reputation: 125

Saving cart details in a database using simplecart.js

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.

Upvotes: 0

Views: 582

Answers (0)

Related Questions