0

我正在使用 simplecart.js。购物车正确显示。我现在要做的是检索购物车中的详细信息并插入数据库。这是我的代码。

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;
});

和 PHP 文件

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 */            
}

问题是当我尝试回显任何变量时,不显示购物车中的内容。请问如何让变量包含实际内容,将它们插入数据库不会有问题。

4

0 回答 0