我正在购买和销售应用程序。 在那我有多个送货地址。当我通过检查并提供结帐选择送货地址时,我需要将这些变量存储在购物车表中。
单击结帐时如何获取已检查div的数据。 这是我的代码:
@extends('layouts.master')
@section('content')
<!--Product -->
<div class="container">
@if(Session::has('success'))
<div class="alert alert-success" data-dismiss="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
{{ Session::get('success') }}
</div>
@elseif(Session::has('danger'))
<div class="alert alert-danger" data-dismiss="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
{{ Session::get('danger') }}
</div>
@endif
<div class="row">
<div>
<div class="bc-buy-item">
<div class="bc-buy-accord">
<div class="selected_address">
<div class="form-group col-md-1"><input type="radio" checked="checked" name="address" id="radio-center"/></div>
<div class="col-md-11">
<span class="bc-prod-name">{{$user->name}} {{$user->mobile}}</span>
<span class="bc-number"> {{$user->address}}, {{$user->city}} - {{$user->pin}}, {{$user->state}}, {{$user->country}}.</span>
<a href="/my-profile" class="btn btn-default pull-right"><i class="fa fa-pencil" aria-hidden="true"></i> Edit</a>
</div>
</div>
@foreach($shippingAddress as $ship)
<div class="selected_address">
<div class="col-md-1 form-group"><input type="radio" name="address" id="radio-center"/></div>
<div class="col-md-11">
<span class="bc-prod-name">{{$ship->name}} {{$ship->mobile}}</span>
<span class="bc-number"> {{$ship->shipping_address}}, {{$ship->shipping_city}} - {{$ship->shipping_pincode}}, {{$ship->shipping_state}}, {{$ship->shipping_country}}.</span>
<a href="#editaddress" id="editaddr"
data-id="{{$ship->id}}" data-name="{{$ship->name}}"
data-address="{{$ship->shipping_address}}" data-city="{{$ship->shipping_city}}"
data-pincode="{{$ship->shipping_pincode}}" data-state="{{$ship->shipping_state}}"
data-country="{{$ship->shipping_country}}" data-mobile="{{$ship->mobile}}"
class="btn btn-default pull-right editadress" data-toggle="modal"><i class="fa fa-pencil" aria-hidden="true"></i> Edit</a>
</div>
</div>
@endforeach
</div>
<div class="text-center"><a href="#address" data-toggle="modal"><span class="glyphicon glyphicon-plus"></span> Add New Shipping Address</a></div>
<div class="bc-buy-accord">
<table class="table table-hover">
<thead>
<tr>
<th>Product</th>
<th>Shipping</th>
<th class="text-center">Price</th>
<th class="text-center">Total</th>
</tr>
</thead>
<tbody>
<tr>
<td class="col-md-6">
<div class="media">
<a class="thumbnail pull-left" href="#"> <img class="media-object" width="100px" src="{{ asset($image) }}"> </a>
<div class="media-body product-cart-details">
<span class="bc-prod-name">{{$getProduct->name}} </span>
<div class="bc-custom-prod">
<span class="bc-number"> Seller Name : </span>
<span class="bc-size-type">{{$seller->name}}</span>
</div>
<div class="bc-custom-prod">
<span class="bc-number"> Status : </span>
<span class="bc-size-type">Leaves warehouse in {{$getProduct->shipping_within}} days</span>
</div>
<div><a id="promocode" href="javascript:void(0)">Click here to apply for Promocode discount</a></div>
<div id="promocode_value" style="display:none;">
<form method="post" action="/promocode">
<input type="hidden" name="product_id" value="{{$getProduct->id}}"/>
<div class="form-group col-md-7">
<input required data-error="Please enter the promocode" placeholder="Enter the promocode" class="form-control" name="promocode" type="text">
<div class="help-block with-errors"></div>
<button class="pull-right">Submit</button>
</div>
</form>
</div>
</div>
</div>
</td>
<td class="col-md-1 text-center shipping"><strong>${{$getProduct->shipping_fee}}</strong></td>
<td class="col-md-1 text-center price"><strong>${{$getProduct->price_per_unit}}</strong></td>
<td class="col-md-1 text-center"><strong>${{$total_price}}</strong></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><h3>Total</h3></td>
<td class="text-right"><h3><strong>${{$total_price}}</strong></h3></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>
<button type="button" class="bc-btn bc-btn-save" onclick="location.href='/'">
<span class="glyphicon glyphicon-shopping-cart"></span> Continue Shopping
</button></td>
<td>
<button type="button" class="bc-btn bc-btn-remove" onclick="location.href='/payment'">
Checkout <span class="glyphicon glyphicon-play"></span>
</button></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="address" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Enter new shipping address</h4>
</div>
<div class="modal-body">
<form method="post" action="{{ route('shippingaddress.store') }}" name="shippingaddress" id="shippingaddress" novalidate="novalidate">
<input type="hidden" id="user_id" name="user_id" value="{{Auth::user()->id}}"/>
<div class="form-group">
<label for="shipping-name" class="control-label">Name:</label>
<input type="text" class="form-control" name="name" id="shipping-name"/>
</div>
<div class="form-group">
<label for="shipping-mobile" class="control-label">Mobile:</label>
<input type="text" class="form-control" name="mobile" id="shipping-mobile"/>
</div>
<div class="form-group">
<label for="shipping-address" class="control-label">Address:</label>
<textarea class="form-control" name="shipping_address" id="shipping-address"></textarea>
</div>
<div class="form-group">
<label for="shipping-city" class="control-label">City:</label>
<input type="text" class="form-control" name="shipping_city" id="shipping-city">
</div>
<div class="form-group">
<label for="shpping-state" class="control-label">State:</label>
<input type="text" class="form-control" name="shipping_state" id="shpping-state">
</div>
<div class="form-group">
<label for="shipping-country" class="control-label">Country:</label>
<input type="text" class="form-control" name="shipping_country" id="shipping-country">
</div>
<div class="form-group">
<label for="shipping-pincode" class="control-label">Pin Code:</label>
<input type="text" class="form-control" name="shipping_pincode" id="shipping-pincode">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<input type="submit" class="btn btn-primary"/>
</div>
</form>
</div>
</div>
</div>
</div>
<!--Edit Modal -->
<div class="modal" id="editaddress" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Edit shipping address</h4>
</div>
<form method="put" class="form-horizontal" id="editshippingaddress" novalidate="novalidate" name="editpromocode">
<div class="modal-body editAddressModal">
<input type="hidden" id="id" name="id"/>
<input type="hidden" id="user_id" name="user_id" value="{{Auth::user()->id}}"/>
<div class="form-group">
<label for="shipping-name" class="control-label">Name:</label>
<input type="text" class="form-control" name="name" id="shipping-name"/>
</div>
<div class="form-group">
<label for="shipping-mobile" class="control-label">Mobile:</label>
<input type="text" class="form-control" name="mobile" id="shipping-mobile"/>
</div>
<div class="form-group">
<label for="shipping-address" class="control-label">Address:</label>
<textarea class="form-control" name="shipping_address" id="shipping-address"></textarea>
</div>
<div class="form-group">
<label for="shipping-city" class="control-label">City:</label>
<input type="text" class="form-control" name="shipping_city" id="shipping-city">
</div>
<div class="form-group">
<label for="shpping-state" class="control-label">State:</label>
<input type="text" class="form-control" name="shipping_state" id="shpping-state">
</div>
<div class="form-group">
<label for="shipping-country" class="control-label">Country:</label>
<input type="text" class="form-control" name="shipping_country" id="shipping-country">
</div>
<div class="form-group">
<label for="shipping-pincode" class="control-label">Pin Code:</label>
<input type="text" class="form-control" name="shipping_pincode" id="shipping-pincode">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<input type="submit" class="btn btn-primary"/>
</div>
</div>
</form>
</div>
</div>
</div>
<script>
$("#shippingaddress").on('submit', function(e){
e.preventDefault(e);
var url = $(this).attr('action');
var method = $(this).attr('method');
var myData = {
user_id:$(this).find("[name='user_id']").val(),
name:$(this).find("[name='name']").val(),
mobile:$(this).find("[name='mobile']").val(),
shipping_address:$(this).find("[name='shipping_address']").val(),
shipping_city:$(this).find("[name='shipping_city']").val(),
shipping_state:$(this).find("[name='shipping_state']").val(),
shipping_country:$(this).find("[name='shipping_country']").val(),
shipping_pincode:$(this).find("[name='shipping_pincode']").val(),
}
// console.log(myData);
$.ajax({
type: method,
url: url,
dataType: 'JSON',
data: myData,
success: function(data) {
alert("Shipping address added successfully");
history.go(0);
},
});
});
$('#promocode').click(function(){
$('#promocode_value').slideToggle('slow');
});
$(document).on("click", ".editaddress", function () {
var shippingId = $(this).data('id');
$(".editAddressModal #shippingAddressId").val( shippingId );
});
$("body").on("click","#editaddr",function(){
var id = $(this).data('id');
var name = $(this).data('name');
var mobile = $(this).data('mobile');
var address = $(this).data('address');
var city = $(this).data('city');
var state = $(this).data('state');
var country = $(this).data('country');
var pincode = $(this).data('pincode');
$(".editAddressModal").find("input[name='id']").val(id);
$(".editAddressModal").find("input[name='name']").val(name);
$(".editAddressModal").find("input[name='mobile']").val(mobile);
$(".editAddressModal").find("textarea[name='shipping_address']").val(address);
$(".editAddressModal").find("input[name='shipping_city']").val(city);
$(".editAddressModal").find("input[name='shipping_state']").val(state);
$(".editAddressModal").find("input[name='shipping_country']").val(country);
$(".editAddressModal").find("input[name='shipping_pincode']").val(pincode);
});
$("#editshippingaddress").on('submit', function(e){
e.preventDefault(e);
var id = $(this).find("[name='id']").val();
var url = 'http://192.168.10.10/api/v1/shippingaddress/'+id;
var method = $(this).attr('method');
var myData = {
user_id:$(this).find("[name='user_id']").val(),
name:$(this).find("[name='name']").val(),
mobile:$(this).find("[name='mobile']").val(),
shipping_address:$(this).find("[name='shipping_address']").val(),
shipping_city:$(this).find("[name='shipping_city']").val(),
shipping_state:$(this).find("[name='shipping_state']").val(),
shipping_country:$(this).find("[name='shipping_country']").val(),
shipping_pincode:$(this).find("[name='shipping_pincode']").val(),
}
console.log("data", myData);
$.ajax({
type: method,
url: url,
dataType: 'JSON',
data: myData,
success: function(data) {
console.log(data);
alert("Shipping Address Updated Succesfully");
history.go(0);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(JSON.stringify(jqXHR));
}
});
});
$("input[name='address']").change(function(){
});
</script>
@endsection