Commit 0c5685ff by Angel MAS

descuentos de promcion descontados en todos los metodos de pago

parent ffb67b46
......@@ -288,18 +288,32 @@ public function shipping()
$detail = '';
$status = '';
$user = \App\User::first();
$descuento = 0;
$cupon = '';
foreach ($sale->items as $item) {
foreach ($sale->products as $item) {
$detail = $detail." ".$item->quantity." ".$item->product->name.", ";
$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 ($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;
$cupon = ' - Descuento '.$request->coupon.' '.$data['amount'];
}
}
$detail = $detail.''.$cupon;
$mp = new MP(env('AC_MERCADO_PAGO'));
$payment_data = array(
"transaction_amount" => $this->total() + $addres->shipping_price->cost,
"transaction_amount" => ($this->total() + $addres->shipping_price->cost) - $descuento,
"token" => $request->card_token_id,
"description" => $detail,
"installments" => 1,
......@@ -390,23 +404,41 @@ public function shipping()
$addres = $client->shipping;
$products = $sale->products;
$detail = '';
$descuento = 0;
$cupon = '';
foreach ($sale->items as $item) {
foreach ($sale->products as $item) {
$detail = $detail." ".$item->quantity." ".$item->product->name.", ";
$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";
$detail = $detail." Envio ". $addres->shipping_price->name." ".money_format('%(#10n',$addres->shipping_price->cost);
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;
$cupon = ' - Descuento '.$request->coupon.' '.$data['amount'];
}
$mp = new MP('TEST-7957752184054483-101318-9bbc7ef53f975318d2521f05257cb66a__LB_LC__-60150825');
}
$detail = $detail.''.$cupon;
$mp = new MP(env('AC_MERCADO_PAGO'));
$payment_data = array(
"transaction_amount" => 100,
"description" => "Title of what you are paying for",
"payment_method_id" => "oxxo",
"transaction_amount" => ($this->total() + $addres->shipping_price->cost)-$descuento,
"description" => $detail,
"payment_method_id" => $request->payment_id,
"payer" => array (
"email" => "[email protected]"
"email" => $client->email,
"first_name"=>$client->name,
"last_name"=>$client->lastname
)
);
......
......@@ -3,6 +3,7 @@
namespace Onestartup\Shop\Libs;
use Onestartup\Shop\Model\ProductShop as Product;
use Onestartup\Shop\Model\DiscountCoupon as Coupon;
use Onestartup\Shop\Notifications\StockNotify;
use App\User;
......@@ -54,4 +55,66 @@ class Util
}
public function getDiscount($sale,$code)
{
$client = $sale->client;
$addres = $client->shipping;
$cost_shipping = $addres->shipping_price->cost;
$coupon = Coupon::where('code', $code)->first();
$today = date("Y-m-d");
$descuento = 0;
$total = 0;
$msg = 'Codigo de promoción no valido';
$valid = false;
$data = [];
foreach ($sale->products as $product) {
$aux = $product->pivot->quantity * $product->infoSale->sale_price;
$total += $aux;
}
if ($coupon != null) {
if ($today <= $coupon->expiration) {
if ($total >= $coupon->min_sale) {
if ($coupon->type == 'Efectivo') {
$descuento = $coupon->value;
$msg = 'Tienes un descuento de: '.money_format('%(#10n',$descuento);
$valid = true;
}
if ($coupon->type == 'Porcentaje') {
$descuento = ($coupon->value/100) * $total;
$msg = 'Tienes un descuento de: '.money_format('%(#10n',$descuento);
$valid = true;
}
} else {
$msg = 'Para aplicar este código de descuento tu compra minima debe ser de: '
.money_format('%(#10n',$coupon->min_sale);
}
} else{
$msg = 'Lo sentimos este código de descuento ya expiró :(';
}
}
$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,7 +10,7 @@ use Onestartup\Shop\Model\SaleShop as Order;
use Onestartup\Shop\Model\ClientShop as Client;
use Onestartup\Shop\Model\ShippingAddres as Shipping;
use Onestartup\Shop\Libs\Util;
class ResumenOrder extends Notification
{
......@@ -20,6 +20,7 @@ class ResumenOrder extends Notification
protected $products;
protected $client;
protected $shipping;
protected $promo = null;
......@@ -34,6 +35,11 @@ class ResumenOrder extends Notification
$this->products = $products;
$this->shipping = $shipping;
$this->client = $client;
if ($this->order->coupon != null) {
$util = new Util();
$this->promo = $util->getDiscount($order, $order->coupon);
}
}
/**
......@@ -58,10 +64,11 @@ class ResumenOrder extends Notification
return (new MailMessage)
->subject('Resumen de compra')
->markdown('shop::mail.resumen.order', [
'order'=>$this->order,
'products'=>$this->products,
'client'=>$this->client,
'shipping'=>$this->shipping
'order' => $this->order,
'products' => $this->products,
'client' => $this->client,
'shipping' => $this->shipping,
'promo' => $this->promo
]);
}
......
......@@ -22,6 +22,9 @@ setlocale(LC_MONETARY, 'en_US');
| {{$p->pivot->quantity}} | {{$p->name}} | {{money_format('%(#10n', $p->infoSale->sale_price)}} | {{money_format('%(#10n', $p->infoSale->sale_price * $p->pivot->quantity)}} |
@endforeach
| 1 | {{$shipping->shipping_price->name}} | {{money_format('%(#10n',$shipping->shipping_price->cost)}} | {{money_format('%(#10n',$shipping->shipping_price->cost)}} |
@if($promo != null)
| 1 | Descuento *** {{$order->coupon}} *** | {{" - ".$promo['amount']}} | {{" - ".$promo['amount']}}|
@endif
| - | - | Total: | {{money_format('%(#10n',$order->total)}}|
@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