Commit 68a2dd63 by Angel MAS

desceunto con paypal

parent 0a524135
......@@ -43,15 +43,15 @@ class CartController extends Controller
public function __construct()
{
if (!\Session::has('cart')) {
\Session::put('cart', array());
}
setlocale(LC_MONETARY, 'en_US');
$this->util = new Util();
}
public function show()
{
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');
......@@ -551,8 +551,7 @@ public function shipping()
$products = $sale->products;
$addres = $client->shipping;
$detail = '';
$descuento = 0;
$apiContext = new ApiContext(
new OAuthTokenCredential(
......@@ -599,17 +598,38 @@ public function shipping()
array_push($items, $item2);
if ($request->coupon != null) {
$data = $this->getDiscount($sale, $request->coupon);
if ($data['valid']) {
$descuento = $data['amount_unformated'];
$sale->total = $data['total_unformated'];
$sale->coupon = $request->coupon;
//Descuento en caso de haber
$item3 = new PaypalItem();
$item3->setName('Código de descuento: '.$request->coupon)
->setDescription('Código de descuento: '.$request->coupon)
->setCurrency('MXN')
->setQuantity(1)
->setPrice(($descuento * -1));
array_push($items, $item3);
}
}
$itemList = new ItemList();
$itemList->setItems($items);
$details = new Details();
$details->setSubtotal($this->total() + $addres->shipping_price->cost);
$details->setSubtotal(($this->total() + $addres->shipping_price->cost) - $descuento);
$amount = new \PayPal\Api\Amount();
$amount->setCurrency("MXN")
->setTotal($this->total() + $addres->shipping_price->cost)
->setTotal(($this->total() + $addres->shipping_price->cost)-$descuento)
->setDetails($details);
......@@ -665,6 +685,16 @@ public function shipping()
$sale->status = 3;
$sale->transaction_id = null;
$sale->payment_type = 'Acordar con vendedor';
if ($request->coupon != null) {
$data = $this->getDiscount($sale, $request->coupon);
if ($data['valid']) {
$sale->total = $data['total_unformated'];
$sale->coupon = $request->coupon;
}
}
$sale->save();
\Session::forget('client');
......@@ -731,7 +761,7 @@ public function shipping()
public function discount(Request $request)
{
$sale = Sale::find($request->total);
$data = $this->getDiscount($sale, $request->coupon);
return response()
......@@ -762,7 +792,7 @@ public function shipping()
if ($coupon != null) {
if ($today <= $coupon->expiration) {
if ($this->total() >= $coupon->min_sale) {
if ($total >= $coupon->min_sale) {
if ($coupon->type == 'Efectivo') {
$descuento = $coupon->value;
......@@ -778,23 +808,25 @@ public function shipping()
} else {
$msg = 'Para aplicar este código de descuento tu compra minima debe ser de: '
.money_format('%(#10n',$coupon->min_sale);
.money_format('%(#10n',$coupon->min_sale);
}
} else{
$msg = 'Lo sentimos este código de descuento ya expiró :(';
}
}
$msg = 'Lo sentimos este código de descuento ya expiró :(';
}
$data = [
'valid'=>$valid,
'msg'=>$msg,
'amount'=>money_format('%(#10n',$descuento),
'total'=>money_format('%(#10n', (($total+$cost_shipping)-$descuento))
];
}
return $data;
}
$data = [
'valid'=>$valid,
'msg'=>$msg,
'amount'=>money_format('%(#10n',$descuento),
'amount_unformated'=>$descuento,
'total'=>money_format('%(#10n', (($total+$cost_shipping)-$descuento)),
'total_unformated'=>($total+$cost_shipping)-$descuento
];
return $data;
}
}
......@@ -10,6 +10,7 @@ setlocale(LC_MONETARY, 'en_US');
- Numero de orden: # {{$order->id}}
- Fecha: {{$order->created_at->format('d/m/Y')}}
- Forma de pago: {{$order->payment_type}}
- Cupon de descuento: {{$order->coupon != null ? $order->coupon : 'N/A'}}
@endcomponent
......
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