HOME


Mini Shell 1.0
DIR: /home/islapiiu/sites/magnoliya/post-and-get/ajax/
Upload File :
Current File : /home/islapiiu/sites/magnoliya/post-and-get/ajax/fetch_cart.php
<?php

include_once(dirname(__FILE__) . '/../../class/include.php');
//featch_cart
session_start();
$delivery_charge = DefaultData::getDeliveryCharges();
$product = 0;
$quantity = 0;
$total_item = 0;
$total_price = 0;
$output = '';
$cart = '';
// dd($_SESSION["shopping_cart"]);
$output .= '<table class="shop_table shop_table_responsive cart lynessa-cart-form__contents">'
        . '<thead>'
        . '<tr>'
        . '<th class="product-remove">&nbsp;</th>'
        . '<th class="product-thumbnail">&nbsp;</th>'
        . '<th class="product-name">Product</th>'
        . '<th class="product-price">Price</th>'
        . '<th class="product-quantity">Quantity</th>'
        . '<th>Size</th>'
        . '<th class="product-subtotal">Total</th>'
        . '</tr>'
        . '</thead>'
        . '<tbody>';

if (!empty($_SESSION["shopping_cart"])) {

    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;
        }
        $output .= '<tr class="lynessa-cart-form__cart-item cart_item">'
                . '<td class="product-remove"> <span class="delete remove" id="' . $PRODUCT->id . '">x</span></td>'
                . '<td class="product-thumbnail">'
                . '<a class="attachment-lynessa_thumbnail size-lynessa_thumbnail" href="view-product.php?id=' . $p_id . '">'
                . '<img src="upload/product-categories/sub-category/product/photos/' . $image_name . '" width="600"/>'
                . '</a>'
                . '</td>'
                . '<td class="product-name"><a href="view-product.php?id=' . $p_id . '">' . $name . '</a></td>'
                . '<td class="product-price">'
                . '<span class="lynessa-Price-amount amount"><span class="lynessa-Price-currencySymbol">Rs. </span>' . number_format($value["product_price"], 2) . '</span>'
                . '</td>'
                . '<td class="product-quantity">'
                . '<div class="quant-input">'
                . ' <input type="number" name="quantity" id="quantity' . $PRODUCT->id . '" min="' . $min_qty . '" max="' . $max_qty . '" step="' . $min_qty . '"  class="quty-size form-control  text-center quantity qty-input"  product_id=' . $value["product_id"] . ' value="' . $value["product_quantity"] . '"/>
                     </div> '
                . '<td class="product-name text-center"><a type="text" class="text-center"  value="' . $value["product_size"] . '">' . $value["product_size"] . '</a></td>'
//     . '<div class="quantity">
                //     <span class="qty-label">Quantiy:</span>
                //     <div class="control">
                //         <a class="btn-number qtyminus quantity-minus" href="#">-</a>
                //         <input type="text" value="1" title="Qty" class="input-qty input-text qty text quantity qty-input" number="quantity" id="quantity' . $PRODUCT->id . '" min="' . $min_qty . '" max="' . $max_qty . '" step="' . $min_qty . '" product_id=' . $value["product_id"] . ' value="' . $value["product_quantity"] . '">
                //         <a class="btn-number qtyplus quantity-plus" href="#">+</a>
                //     </div>
                // </div>'
                . '</td>'
                . '<td class="product-subtotal"><span class="lynessa-Price-amount amount"><span class="lynessa-Price-currencySymbol">Rs. </span>' . number_format($value["product_quantity"] * $value["product_price"], 2) . '</span></td>'
                //hidden values in form 
                . ' <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;
    }
} else {
    $output .= '<tr>'
            . '<td colspan="6" align="center" class="product-remove">'
            . 'Your Cart is Empty!.'
            . '</td>'
            . '</tr>';
}
$output .= '<input type="hidden" class="form-control" id="total_price"   value="' . $total_price . '"/>';
$output .= '</tbody>';
$output .= '</table>';

$tot1 = 0;
$items = 0;
$more_items = '';
if (!empty($_SESSION["shopping_cart"])) {
    foreach ($_SESSION["shopping_cart"] as $key1 => $product1) {

        if ($key1 < 3) {
            $PRODUCT1 = new Product($product1["product_id"]);
            if ($PRODUCT1->parent != 0) {
                $PARANT1 = new Product($PRODUCT1->parent);
                $name = $PARANT1->name . ' - ' . $product1["product_name"];
                $image_name = $PARANT1->image_name;
                $p_id = $PARANT1->id;
                $min_qty = $PARANT1->min_qty;
                $max_qty = $PARANT1->max_qty;
                $unit = $PARANT1->unit;
            } else {

                $name = $product1["product_name"];
                $image_name = $PRODUCT1->image_name;
                $p_id = $PRODUCT1->id;
                $min_qty = $PRODUCT1->min_qty;
                $max_qty = $PRODUCT1->max_qty;
                $unit = $PRODUCT1->unit;
            }
            $price1 = $product1['product_quantity'] * $product1['product_price'];
            $tot1 += $price1;
            $items += 1;

            $cart .= '<li class="lynessa-mini-cart-item mini_cart_item">'
                    . '<a href="view-product.php?id=' . $p_id . '">'
                    . '<img src="upload/product-categories/sub-category/product/photos/' . $image_name . '" class="attachment-lynessa_thumbnail size-lynessa_thumbnail" alt="img" width="600">' . wordwrap($name, 40, "<br>\n") . '&nbsp;'
                    . '</a>'
                    . '<span class="quantity">' . $product1['product_quantity'] . ' × <span class="lynessa-Price-amount amount"><span class="lynessa-Price-currencySymbol">Rs. </span>' . number_format($product1['product_price'], 2) . '</span></span>'
                    . '</li>';
        }
    }
} else {
    $cart .= '<li class="lynessa-mini-cart-item mini_cart_item">Your cart is empty.</li>';
}
//if ($items > 3) {
//    $more_items .= $items - 3 . ' more items.';
//}
$final = $tot1 + $delivery_charge;
$data = array(
    'cart_details' => $output,
    'cart_box' => $cart,
    'total_item' => $total_item,
    'total_price' => number_format($total_price, 2),
        // 'delivery_charge' => number_format($delivery_charge, 2),
        // 'final' => number_format($final, 2)
        //    'more_items' => $more_items
);
echo json_encode($data);