i am facing this issue where everything is displaying but product thumbnail does not show in cart drop down menu and when i visit the http://127.0.0.1:8000/product/mini/cart page i get “image”: null as shown below
{"carts":{"814a8a82665ce9e1fdf8db97d1546227":{"rowId":"814a8a82665ce9e1fdf8db97d1546227","id":"15","name":"Angised 0.5mg Tablet 10 'S","qty":4,"price":12,"weight":1,"options":{"image":null,"size":"0.5mg"},"discount":0,"tax":1.2,"subtotal":48},"c2452c3ec12fa191ac42161be14935a0":{"rowId":"c2452c3ec12fa191ac42161be14935a0","id":"17","name":"Cardace 5mg Tablet 10 'S","qty":3,"price":25,"weight":1,"options":{"image":null,"size":"Small"},"discount":0,"tax":2.5,"subtotal":75},"8ca52c69734d690cc1261de455a4ee3e":{"rowId":"8ca52c69734d690cc1261de455a4ee3e","id":"10","name":"Pinix 0.25mg Tablet 10 'S","qty":"1","price":30,"weight":1,"options":{"image":null,"size":"Pack"},"discount":0,"tax":3,"subtotal":30},"e8441eb85c22e56677ba4f2d9c5ecdf1":{"rowId":"e8441eb85c22e56677ba4f2d9c5ecdf1","id":"9","name":"Transamin (5ml) 500mg Injection 1 'S","qty":"1","price":110,"weight":1,"options":{"image":null,"size":"Medium"},"discount":0,"tax":11,"subtotal":110}},"cartQty":9,"cartTotal":289}
here is CartController
public function AddToCart(Request $request, $id){
$product = Product::findOrFail($id);
if ($product->discount_price == NULL) {
Cart::add([
'id' => $id,
'name' => $request->product_name,
'qty' => $request->quantity,
'price' => $product->selling_price,
'weight' => 1,
'options' => [
'image' => $product->product_thumbnail,
'size' => $request->size,
],
]);
return response()->json(['success' => 'Successfully Added on Your Cart']);
}else{
Cart::add([
'id' => $id,
'name' => $request->product_name,
'qty' => $request->quantity,
'price' => $product->discount_price,
'weight' => 1,
'options' => [
'image' => $product->product_thumbnail,
'size' => $request->size,
],
]);
return response()->json(['success' => 'Successfully Added on Your Cart']);
}
}
// Mini Cart Section
public function AddMiniCart(){
$carts = Cart::content();
$cartQty = Cart::count();
$cartTotal = Cart::total();
return response()->json(array(
'carts' => $carts,
'cartQty' => $cartQty,
'cartTotal' => round($cartTotal),
));
}
and here is my main_master.blade.php file
function productView(id) {
//alert(id)
$.ajax({
type: ‘GET’,
url: ‘/product/view/modal/’+id,
dataType: ‘json’,
success: function(data){
//console.log(data)
$(‘#pname’).text(data.product.product_name_en);
$(‘#price’).text(data.product.selling_price);
$(‘#pcode’).text(data.product.product_code);
$(‘#pcategory’).text(data.product.category.category_name_en);
$(‘#pbrand’).text(data.product.brand.brand_name_en);
$(‘#pimage’).attr(‘src’,’/’+data.product.product_thumbnail);
$(‘#product_id’).val(id);
$(‘#qty’).val(1);
//product price
if (data.product.discount_price == null) {
$('#pprice').text('');
$('#oldprice').text('');
$('#pprice').text(data.product.selling_price);
} else {
$('#pprice').text(data.product.discount_price);
$('#oldprice').text(data.product.selling_price);
}
// Start Stock opiton
if (data.product.product_qty > 0) {
$('#available').text('');
$('#stockout').text('');
$('#available').text('Available');
}else{
$('#available').text('');
$('#stockout').text('');
$('#stockout').text('Out of stock');
} // end Stock Option
//size
$('select[name="size"]').empty();
$.each(data.size,function(key,value){
$('select[name="size"]').append('<option value=" '+value+' ">'+value+' </option>')
if (data.size == "") {
$('#sizeArea').hide();
}else{
$('#sizeArea').show();
}
})
}
})
}
here is the preview