<?php
include_once(dirname(__FILE__) . '/../../class/include.php');
//featch_cart
session_start();
$product = 0;
$quantity = 0;
$total_item = 0;
$total_price = 0;
$output = '';
$cart = '';
$output .= '<table class="table">'
. '<thead class="text-uppercase wow fadeInUp" data-wow-delay=".1s">'
. '<tr>'
. '<th></th>'
. '<th>Product</th>'
. '<th>Price</th>'
. '<th>Quantity</th>'
. '<th>subtotal</th>'
. '</tr>'
. '</thead>';
// unset($_SESSION["shopping_cart"]);
if (!empty($_SESSION["shopping_cart"])) {
$output .= '<tbody>';
foreach ($_SESSION["shopping_cart"] as $key => $value) {
$PRODUCT = new Product($value["product_id"]);
if($PRODUCT->parent != 0) {
$PARANT = new Product($PRODUCT->parent);
$name = $PARANT->name . ' - ' . $value["product_name"];
$image_name = $PARANT->image_name;
$p_id = $PARANT->id;
$min_qty = $PARANT->min_qty;
$max_qty = $PARANT->max_qty;
$unit = $PARANT->unit;
} else {
$name = $value["product_name"];
$image_name = $PRODUCT->image_name;
$p_id = $PRODUCT->id;
$min_qty = $PRODUCT->min_qty;
$max_qty = $PRODUCT->max_qty;
$unit = $PRODUCT->unit;
}
// dd($value["product_price"]);
$output .= '<tr class="wow fadeInUp" data-wow-delay=".1s">'
. '<td>'
. '<button type="button" class="remove_btn delete" name="delete" id="' . $value["product_id"] . '"><i class="fa fa-times"></i></button>'
. '</td>'
. '<td>'
. '<div class="carttable_product_item">'
. '<h3 class="item_title">' . $name . '</h3>'
. '<div class="item_image">'
. '<img src="upload/product/' . $image_name . '" alt="' . $PRODUCT->name . '" title="' . $PRODUCT->name . '" width="14%"/>'
. '</div>'
. '</div>'
. '</td>'
. '<td><span class="price_text1">US $' . number_format($value["product_price"], 2) . '</span></td>'
. '<td><div class="quantity_input quantity">'
. '<input type="number" name="quantity" size="1" class="form-control quantity qty-input" id="quantity' . $PRODUCT->id . '" min="' . $min_qty . '" max="' . $max_qty . '" step="' . $min_qty . '" product_id=' . $value["product_id"] . ' value="' . $value["product_quantity"] . '" />'
. '</div>'
. '</td>'
. '<td class="text-right">US $' . number_format($value["product_quantity"] * $value["product_price"], 2) . '</td>'
. ' <input type="hidden" class="form-control " product_id="' . $value["product_id"] . '" /> '
. '<input type="hidden" class="form-control" id="price" name="price" value="' . $value["product_price"] . '"/>'
. '<input type="hidden" class="form-control max" value="' . $unit . '"/>'
. '</tr>';
$total_price = $total_price + ($value["product_quantity"] * $value["product_price"]);
$total_item = $total_item + 1;
}
$output .= '</tbody><tfooter>'
. '<tr>'
. '<th colspan="4">Total</th>'
. '<th class="text-right">US $' . number_format($total_price, 2) . '</th>'
. '</tr>'
. '</tfooter>';
} else {
$output .= '<tbody><tr>'
. '<td colspan="5" align="center" class="product-remove">'
. 'Your Cart is Empty!.'
. '</td>'
. '</tr></tbody>';
}
$output .= '<input type="hidden" class="form-control" id="total_price" value="' . $total_price . '"/>';
$output .= '</table>';
$tot1 = 0;
$items = 0;
$more_items = '';
if (!empty($_SESSION["shopping_cart"])) {
foreach ($_SESSION["shopping_cart"] as $key1 => $product1) {
$PRODUCT1 = new Product($product1['product_id']);
$price1 = $product1['product_quantity'] * $product1['product_price'];
$tot1 += $price1;
$items += 1;
if ($key1 < 3) {
$cart .= '<tr>'
. '<td class="text-center" style="width:70px">'
. '<a href="#"> <img src="upload/product-categories/sub-category/product/photos/' . $PRODUCT1->image_name . '" style="width:70px" alt="' . $PRODUCT1->name . '" title="' . $PRODUCT1->name . '" class="preview"> </a>'
. '</td>'
. '<td class="text-left"> <a class="cart_product_name" href="product.php?id=' . $PRODUCT1->id . '">' . $PRODUCT1->name . '</a> </td>'
. '<td class="text-center"> x' . $product1["product_quantity"] . ' </td>'
. '<td class="text-center">US $' . number_format($price1, 2) . '</td>'
. '</tr>';
}
}
}
//if ($items > 3) {
// $more_items .= $items - 3 . ' more items.';
//}
$data = array(
'cart_details' => $output,
'cart_box' => $cart,
'total_item' => $total_item,
'total_price' => number_format($tot1, 2)
// 'more_items' => $more_items
);
// dd($data);
echo json_encode($data);
|