Commit 831d0198 by Angel MAS

shipping no required and placeholder select

parent 50a7bc5f
......@@ -281,13 +281,19 @@ class AdminProductController extends Controller
{
$sale = Sale::find($id);
$promo = null;
$shipping = null;
$shipping_price = null;
if ($sale->coupon != null) {
$promo = $this->util->getDiscount($sale, $sale->coupon);
}
$client = $sale->client;
$orden = $sale->items;
if ($client->shipping != null) {
$shipping = $client->shipping;
$shipping_price = $shipping->shipping_price;
}
if ($sale->status == 0) {
$estado = "Cancelado";
......
......@@ -47,18 +47,21 @@ class CartController extends Controller
if (!\Session::has('cart')) {
\Session::put('cart', array());
}
setlocale(LC_MONETARY, 'en_US');
$this->util = new Util();
}
public function show()
{
$total = $this->total();
$cart = \Session::get('cart');
return view('shop-public::cart.show-cart')
->with('cart', $cart)
->with('total', $total);
}
public function add(Product $product)
......@@ -183,10 +186,17 @@ public function shipping()
$client = new Client();
$addres = new Addres();
$cart = \Session::get('cart');
$costoEnvio = 0;
if(\Session::has('client')) {
$client = \Session::get('client');
if ($client->shipping != null) {
$addres = $client->shipping;
}
if (\Session::get('client')->email != $request->email) {
$client = new Client();
$addres = new Addres();
......@@ -198,6 +208,8 @@ public function shipping()
$client->fill($request->all());
$client->save();
if ($request->home_delivery) {
/** Crea forma de envio ····· */
$addres->fill($request->all());
......@@ -210,9 +222,12 @@ public function shipping()
/** Guarda productos en tabla ······ */
$costoEnvio = $addres->shipping_price->cost;
}
if (!\Session::has('sale')) {
$sale = $client->sales()->save(new Sale(['status' => 1, 'total'=>($this->total() + $costoEnvio)]));
$sale = $client->sales()->save(new Sale(['home_delivery'=>$request->home_delivery,'status' => 1, 'total'=>($this->total() + $costoEnvio)]));
foreach ($cart as $product) {
$item = Item::create([
......@@ -284,20 +299,25 @@ public function shipping()
$sale = Sale::find(\Session::get('sale')->id);
$client = $sale->client;
$items = $sale->items;
$addres = $client->shipping;
$addres = $client->shipping != null ? $client->shipping : null;
$products = $sale->products;
$detail = '';
$status = '';
$user = \App\User::first();
$descuento = 0;
$cupon = '';
$costo_envio = 0;
foreach ($sale->products as $item) {
$detail = $detail." ".$item->pivot->quantity." ".$item->name." Sub. ".money_format('%(#10n', ($item->infoSale->sale_price*$item->pivot->quantity)).", ";
}
$detail = $detail." Envio ". $addres->shipping_price->name ." $". $addres->shipping_price->cost .".00";
if ($addres != null) {
$detail = $detail." Envio ". $addres->shipping_price->name." ".money_format('%(#10n',$addres->shipping_price->cost);
$costo_envio = $addres->shipping_price->cost;
}
if ($request->coupon != null) {
$data = $this->getDiscount($sale, $request->coupon);
......@@ -314,7 +334,7 @@ public function shipping()
$mp = new MP(env('AC_MERCADO_PAGO'));
$payment_data = array(
"transaction_amount" => ($this->total() + $addres->shipping_price->cost) - $descuento,
"transaction_amount" => ($this->total() + $costo_envio) - $descuento,
"token" => $request->card_token_id,
"description" => $detail,
"installments" => 1,
......@@ -402,18 +422,24 @@ public function shipping()
$sale = Sale::find(\Session::get('sale')->id);
$client = $sale->client;
$items = $sale->items;
$addres = $client->shipping;
$addres = $client->shipping != null ? $client->shipping : null;
$products = $sale->products;
$detail = '';
$descuento = 0;
$cupon = '';
$costo_envio = 0;
foreach ($sale->products as $item) {
$detail = $detail." ".$item->pivot->quantity." ".$item->name." Sub. ".money_format('%(#10n', ($item->infoSale->sale_price*$item->pivot->quantity)).", ";
}
if ($addres != null) {
$detail = $detail." Envio ". $addres->shipping_price->name." ".money_format('%(#10n',$addres->shipping_price->cost);
$costo_envio = $addres->shipping_price->cost;
}
if ($request->coupon != null) {
$data = $this->getDiscount($sale, $request->coupon);
......@@ -431,7 +457,7 @@ public function shipping()
$mp = new MP(env('AC_MERCADO_PAGO'));
$payment_data = array(
"transaction_amount" => ($this->total() + $addres->shipping_price->cost)-$descuento,
"transaction_amount" => ($this->total() + $costo_envio)-$descuento,
"description" => $detail,
......@@ -522,7 +548,8 @@ public function shipping()
$sale = Sale::find(\Session::get('sale')->id);
$client = $sale->client;
$items = $sale->items;
$addres = $client->shipping;
$addres = $client->shipping != null ? $client->shipping : null;
$costo_envio = 0;
$products = $sale->products;
$old = $sale->status;
$sale->status = 2;
......@@ -579,7 +606,8 @@ public function shipping()
$client = $sale->client;
$items = $sale->items;
$products = $sale->products;
$addres = $client->shipping;
$addres = $client->shipping != null ? $client->shipping : null;
$costo_envio = 0;
$detail = '';
$descuento = 0;
......@@ -619,6 +647,10 @@ public function shipping()
$items[]=$item1;
}
if ($addres != null) {
$costo_envio = $addres->shipping_price->cost;
$item2 = new PaypalItem();
$item2->setName($addres->shipping_price->name)
->setDescription($addres->shipping_price->name)
......@@ -628,6 +660,8 @@ public function shipping()
array_push($items, $item2);
}
if ($request->coupon != null) {
$data = $this->getDiscount($sale, $request->coupon);
if ($data['valid']) {
......@@ -654,12 +688,12 @@ public function shipping()
$itemList->setItems($items);
$details = new Details();
$details->setSubtotal(($this->total() + $addres->shipping_price->cost) - $descuento);
$details->setSubtotal(($this->total() + $costo_envio) - $descuento);
$amount = new \PayPal\Api\Amount();
$amount->setCurrency("MXN")
->setTotal(($this->total() + $addres->shipping_price->cost)-$descuento)
->setTotal(($this->total() + $costo_envio)-$descuento)
->setDetails($details);
......@@ -709,7 +743,8 @@ public function shipping()
$client = $sale->client;
$products = $sale->products;
$items = $sale->items;
$addres = $client->shipping;
$addres = $client->shipping != null ? $client->shipping : null;
$costo_envio = 0;
$detail = '';
$sale->status = 3;
......@@ -802,9 +837,13 @@ public function shipping()
{
$client = $sale->client;
$addres = null;
$cost_shipping = 0;
if ($sale->home_delivery) {
$addres = $client->shipping;
$cost_shipping = $addres->shipping_price->cost;
}
$coupon = Coupon::where('code', $code)->first();
$today = date("Y-m-d");
......@@ -864,8 +903,13 @@ public function getDiscount2($sale)
{
$client = $sale->client;
$addres = null;
$cost_shipping = 0;
if ($sale->home_delivery) {
$addres = $client->shipping;
$cost_shipping = $addres->shipping_price->cost;
}
$coupon = Coupon::where('code', $sale->coupon)->first();
......
......@@ -39,7 +39,12 @@ class OrderDataTable extends DataTable
if ($sale->status == 3) {
$estado = "<span class='label primary'>En proceso</span>";
}
if ($sale->client->shipping != null) {
$html = "Estado: <b>$estado</b><br>Tipo: <b>$sale->payment_type</b> <br>Transaccion:<br><b>$sale->transaction_id</b><br>Envio: <b>".$sale->client->shipping->shipping_price->name."</b>";
} else {
$html = "Estado: <b>$estado</b><br>Tipo: <b>$sale->payment_type</b> <br>Transaccion:<br><b>$sale->transaction_id</b><br>Envio: <b>Recojer en la tienda</b>";
}
return $html;
})
->addColumn('action', function (Sale $sale){
......
......@@ -60,9 +60,13 @@ class Util
{
$client = $sale->client;
$addres = null;
$cost_shipping = 0;
if ($sale->home_delivery) {
$addres = $client->shipping;
$cost_shipping = $addres->shipping_price->cost;
}
$coupon = Coupon::where('code', $code)->first();
$today = date("Y-m-d");
......
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddShippmentOptionToClientShopsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('sale_shops', function (Blueprint $table) {
$table->boolean('home_delivery')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('sale_shops', function (Blueprint $table) {
$table->dropColumn('home_delivery');
});
}
}
......@@ -7,7 +7,16 @@ use Illuminate\Database\Eloquent\Model;
class SaleShop extends Model
{
protected $table = 'sale_shops';
protected $fillable = ['status', 'total', 'client_id', 'transaction_id', 'payment_type', 'shipping_status', 'coupon'];
protected $fillable = [
'status',
'total',
'client_id',
'transaction_id',
'payment_type',
'shipping_status',
'coupon',
'home_delivery'
];
public function client()
......
......@@ -29,7 +29,7 @@ class ResumenOrder extends Notification
*
* @return void
*/
public function __construct(Order $order, $products, Client $client, Shipping $shipping)
public function __construct(Order $order, $products, Client $client, $shipping)
{
$this->order = $order;
$this->products = $products;
......
......@@ -45,8 +45,9 @@ setlocale(LC_MONETARY, 'en_US');
<p>Teléfono: <b>{{$client->phone}}</b></p>
<p>Correo: <b>{{$client->email}}</b></p>
<p>Fecha de registro: <b>{{$client->created_at}}</b></p>
@if($shipping != null)
<p>Requiere factura: <b>{{$shipping->facturacion}}</b></p>
@endif
</div>
<div class="col-md-6">
......@@ -151,12 +152,14 @@ setlocale(LC_MONETARY, 'en_US');
<td> - {{$promo['amount']}}</td>
</tr>
@endif
@if($shipping_price != null)
<tr>
<td>1</td>
<td>{{$shipping_price->name}}</td>
<td>{{money_format('%(#10n', $shipping_price->cost)}}</td>
<td>{{money_format('%(#10n', $shipping_price->cost)}}</td>
</tr>
@endif
<tfoot>
<tr>
<td></td>
......@@ -184,6 +187,7 @@ setlocale(LC_MONETARY, 'en_US');
<div class="box-body">
<div class="row">
<div class="col-md-6">
@if($shipping != null)
Direccion de entrega:<br>
<b>{{$shipping->calle}}, # {{$shipping->numero}}, col. {{$shipping->colonia}}</b><br>
......@@ -195,6 +199,11 @@ setlocale(LC_MONETARY, 'en_US');
Estatus del envio: <a href="javascript::void()" data-target="#m-a-a" data-toggle="modal" href="#" ui-target="#animate" ui-toggle-class="zoom"><i class="fa fa-edit"></i></a><br>
<span class="label warning">{{$sale->shipping_status}}</span>
@else
<h6>
No hay datos de envio, el cliente pasara a la tienda a recoger el producto
</h6>
@endif
</div>
......
......@@ -21,7 +21,9 @@ setlocale(LC_MONETARY, 'en_US');
@foreach($products as $p)
| {{$p->pivot->quantity}} | {{$p->name}} | {{money_format('%(#10n', $p->infoSale->sale_price)}} | {{money_format('%(#10n', $p->infoSale->sale_price * $p->pivot->quantity)}} |
@endforeach
@if($shipping != null)
| 1 | {{$shipping->shipping_price->name}} | {{money_format('%(#10n',$shipping->shipping_price->cost)}} | {{money_format('%(#10n',$shipping->shipping_price->cost)}} |
@endif
@if($promo != null)
| 1 | Descuento *** {{$order->coupon}} *** | {{" - ".$promo['amount']}} | {{" - ".$promo['amount']}}|
@endif
......@@ -37,6 +39,7 @@ Datos del comprador:
- Correo: *** {{$client->email}} ***
@endcomponent
@if($shipping != null)
@component('mail::panel')
Datos de envio:
......@@ -50,6 +53,7 @@ Datos de envio:
@endif
@endcomponent
@endif
Gracias por tu compra,<br>
{{ config('app.name') }}
......
......@@ -64,7 +64,7 @@
<div class="col-md-4">
<div class="form-group">
{!! Form::label($extra->variable, $extra->alias, ['class'=>'control-label'])!!}
{!! Form::select($extra->variable, array_combine( explode(",", $extra->values), explode(",", $extra->values)), null, ["class"=>"form-control"]) !!}
{!! Form::select($extra->variable, array_combine( explode(",", $extra->values), explode(",", $extra->values)), null, ["class"=>"form-control", "placeholder"=>"Elije una opción"]) !!}
</div>
</div>
@endif
......
......@@ -47,8 +47,10 @@ setlocale(LC_MONETARY, 'en_US');
</td>
<td align="center">
{{ money_format('%(#10n', ($total)) }} +
{{ money_format('%(#10n', $addres->shipping_price->cost) }} =
{{ money_format('%(#10n', ($total + $addres->shipping_price->cost)) }}
{{ $sale->home_delivery ? money_format('%(#10n', $addres->shipping_price->cost) : '0' }} =
{{ $sale->home_delivery ? money_format('%(#10n', ($total + $addres->shipping_price->cost)) : money_format('%(#10n', ($total))}}
</td>
</tr>
</table>
......
......@@ -54,21 +54,32 @@ setlocale(LC_MONETARY, 'en_US');
@include('shop-public::forms.fields-client')
</section>
<section>
<section id="delivery" style="display: none;">
<h4>Datos de envio</h4>
@include('shop-public::forms.fields-shipping')
<br>
{!! Form::submit('Enviar información', ['class'=>'']) !!}
{!! Form::close() !!}
</section>
{!! Form::submit('Enviar información', ['class'=>'']) !!}
{!! Form::close() !!}
@endsection
@section('scripts_extra')
<script type="text/javascript">
$('#home_delivery').change(function () {
if ($(this).val() == 1) {
$('#delivery').show();
$("#delivery :input").prop('required','required');
}
if ($(this).val() == 0)
{
$('#delivery').hide();
$("#delivery :input").prop('required',null);
}
})
</script>
@endsection
\ No newline at end of file
......@@ -17,3 +17,8 @@
{!! Form::label('phone', 'Teléfono', ['class'=>'']) !!}
{!! Form::text('phone', null, ['class'=>'form-control', 'required'=>'required', 'id'=>'phone']) !!}
</div>
<div class="form-group">
{!! Form::label('home_delivery', '¿Requieres envio a domicilio?', ['class'=>'']) !!}
{!! Form::select('home_delivery',[false=>'No, pasare por el paquete a la tienda', true=>'SI'], null, ['class'=>'form-control', 'required'=>'required', 'id'=>'home_delivery']) !!}
</div>
\ No newline at end of file
......@@ -21,7 +21,7 @@
</div>
<br>
<button>
Pagar {{ money_format('%(#10n', ($total + $addres->shipping_price->cost)) }}
Pagar {{ $sale->home_delivery ? money_format('%(#10n', ($total + $addres->shipping_price->cost)) : money_format('%(#10n', $total)}}
<span class="amount_discount"></span>
</button>
......
......@@ -27,7 +27,7 @@
</div>
<br>
<button>
Pagar {{ money_format('%(#10n', ($total + $addres->shipping_price->cost)) }}
Pagar {{ $sale->home_delivery ? money_format('%(#10n', ($total + $addres->shipping_price->cost)) : money_format('%(#10n', $total ) }}
<span class="amount_discount"></span>
</button>
......
<div class="form-group">
{!! Form::label('cp', 'Codigo postal', ['class'=>'']) !!}
{!! Form::text('cp', $addres->cp, ['class'=>'form-control','required'=>'required']) !!}
{!! Form::text('cp', isset($address) ? $addres->cp : null, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('calle', 'Calle', ['class'=>'']) !!}
{!! Form::text('calle', $addres->calle, ['class'=>'form-control','required'=>'required']) !!}
{!! Form::text('calle', isset($address) ? $addres->calle : null, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('numero', 'Numero', ['class'=>'']) !!}
{!! Form::text('numero', $addres->numero, ['class'=>'form-control','required'=>'required']) !!}
{!! Form::text('numero', isset($address) ? $addres->numero : null, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('colonia', 'Colonia', ['class'=>'']) !!}
{!! Form::text('colonia', $addres->colonia, ['class'=>'form-control','required'=>'required']) !!}
{!! Form::text('colonia', isset($address) ? $addres->colonia : null, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('ciudad', 'Ciudad o delegación', ['class'=>'']) !!}
{!! Form::text('ciudad', $addres->ciudad, ['class'=>'form-control','required'=>'required']) !!}
{!! Form::text('ciudad', isset($address) ? $addres->ciudad : null, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('estado', 'Estado', ['class'=>'']) !!}
{!! Form::text('estado', $addres->estado, ['class'=>'form-control','required'=>'required']) !!}
{!! Form::text('estado', isset($address) ? $addres->estado : null, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('referencias', 'Referencias', ['class'=>'']) !!}
{!! Form::text('referencias', $addres->referencias, ['class'=>'form-control','required'=>'required']) !!}
{!! Form::text('referencias', isset($address) ? $addres->referencias : null, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('facturacion', '¿Necesitaras factura?', ['class'=>'']) !!}
{!! Form::select('facturacion',['No'=>'No', 'Si'=>'Si'], $addres->facturacion, ['class'=>'form-control','required'=>'required']) !!}
{!! Form::select('facturacion',['No'=>'No', 'Si'=>'Si'], isset($address) ? $addres->facturacion : null, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('shipping_price_id', 'Tipo de envio', ['class'=>'']) !!}
{!! Form::select('shipping_price_id', $shipping, $addres->shipping_price_id != null ? $addres->shipping_price_id : null,['class'=>'form-control','required'=>'required']) !!}
{!! Form::select('shipping_price_id', $shipping, isset($address) && $addres->shipping_price_id != null ? $addres->shipping_price_id : null,['class'=>'form-control']) !!}
</div>
\ No newline at end of file
......@@ -10,7 +10,7 @@
</div>
<br>
<button>
Acordar con el vendedor {{ money_format('%(#10n', ($total + $addres->shipping_price->cost)) }}
Acordar con el vendedor {{ $sale->home_delivery ? money_format('%(#10n', ($total + $addres->shipping_price->cost)) : money_format('%(#10n', $total ) }}
<br>
<span class="amount_discount"></span>
</button>
......
......@@ -9,7 +9,7 @@
</div>
<br>
<button type="submit">
Pagar con paypal {{ money_format('%(#10n', ($total + $addres->shipping_price->cost)) }}
Pagar con paypal {{ $sale->home_delivery ? money_format('%(#10n', ($total + $addres->shipping_price->cost)): money_format('%(#10n', $total)}}
<span class="amount_discount"></span>
</button>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment