Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
onestartup-shop
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Angel Martin
onestartup-shop
Commits
0a524135
Commit
0a524135
authored
Jun 04, 2018
by
Angel MAS
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ajax promo payments
parent
d78a2461
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
158 additions
and
15 deletions
+158
-15
CartController.php
src/controllers/CartController.php
+76
-2
routes.php
src/routes.php
+2
-0
finish.blade.php
src/views/public/cart/finish.blade.php
+35
-6
fields-payment-cash.blade.php
src/views/public/forms/fields-payment-cash.blade.php
+11
-2
fields-payment.blade.php
src/views/public/forms/fields-payment.blade.php
+11
-2
form-acordar.blade.php
src/views/public/forms/form-acordar.blade.php
+13
-2
form-paypal.blade.php
src/views/public/forms/form-paypal.blade.php
+10
-1
No files found.
src/controllers/CartController.php
View file @
0a524135
...
...
@@ -13,6 +13,7 @@ use Onestartup\Shop\Model\ClientShop as Client;
use
Onestartup\Shop\Model\ShippingAddres
as
Addres
;
use
Onestartup\Shop\Model\SaleShop
as
Sale
;
use
Onestartup\Shop\Model\DetailShop
as
Item
;
use
Onestartup\Shop\Model\DiscountCoupon
as
Coupon
;
use
Onestartup\Shop\Payment\MP
;
use
Onestartup\Shop\Notifications\PaymentClient
;
...
...
@@ -45,6 +46,7 @@ class CartController extends Controller
if
(
!
\Session
::
has
(
'cart'
))
{
\Session
::
put
(
'cart'
,
array
());
}
setlocale
(
LC_MONETARY
,
'en_US'
);
$this
->
util
=
new
Util
();
}
...
...
@@ -681,7 +683,11 @@ public function shipping()
public
function
testmail
()
{
$sale
=
Sale
::
find
(
5
);
/*$sale = Sale::find(10);
$data = $this->getDiscount($sale, 'test1');
return $data['amount'];
$products = $sale->products;
//return $products;
...
...
@@ -699,7 +705,7 @@ public function shipping()
}
$sale->status = 3;
$sale
->
save
();
$sale->save();
*/
return
"yei"
;
...
...
@@ -723,4 +729,72 @@ public function shipping()
}
public
function
discount
(
Request
$request
)
{
$sale
=
Sale
::
find
(
$request
->
total
);
$data
=
$this
->
getDiscount
(
$sale
,
$request
->
coupon
);
return
response
()
->
json
(
$data
);
}
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
(
$this
->
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
),
'total'
=>
money_format
(
'%(#10n'
,
((
$total
+
$cost_shipping
)
-
$descuento
))
];
return
$data
;
}
}
src/routes.php
View file @
0a524135
...
...
@@ -108,4 +108,6 @@ Route::group(['middleware' => ['web']], function(){
Route
::
get
(
'cart/cancelPaypal'
,
'Onestartup\Shop\Controller\CartController@cancelPaypal'
)
->
name
(
'cart.cancelPaypal'
);
Route
::
get
(
'cart/testmail'
,
'Onestartup\Shop\Controller\CartController@testmail'
)
->
name
(
'cart.testmail'
);
Route
::
get
(
'get/coupon'
,
'Onestartup\Shop\Controller\CartController@discount'
)
->
name
(
'cart.discount'
);
});
src/views/public/cart/finish.blade.php
View file @
0a524135
...
...
@@ -72,14 +72,15 @@ setlocale(LC_MONETARY, 'en_US');
<br>
</section>
@endsection
@section('scripts_extra')
<script type="
text
/
javascript
">
<script type="
text
/
javascript
">
Mercadopago.setPublishableKey(
{
{env('PK_MERCADO_PAGO')}
}
);
Mercadopago.setPublishableKey('key_test'
);
...
...
@@ -166,7 +167,7 @@ setlocale(LC_MONETARY, 'en_US');
};
function
setPaymentMethodInfo
(
status
,
response
)
{
console
.
log
(
"holiholi"
);
if
(
status
==
200
)
{
// do somethings ex: show logo of the payment method
var
form
=
document
.
querySelector
(
'#form-pagar-mp'
);
...
...
@@ -187,5 +188,34 @@ setlocale(LC_MONETARY, 'en_US');
addEvent
(
document
.
querySelector
(
'input[data-checkout="cardNumber"]'
),
'keyup'
,
guessingPaymentMethod
);
addEvent
(
document
.
querySelector
(
'input[data-checkout="cardNumber"]'
),
'change'
,
guessingPaymentMethod
);
</
script
>
@
endsection
\ No newline at end of file
</
script
>
<
script
type
=
"text/javascript"
>
$
(
".coupon"
)
.
keyup
(
function
(){
var
text
=
this
.
value
;
if
(
text
.
length
>
3
)
{
$
.
get
(
"/get/coupon"
,
{
total
:
$
(
this
)
.
data
(
'total'
),
coupon
:
text
}
)
.
done
(
function
(
data
)
{
$
(
".reponse_coupon"
)
.
text
(
data
.
msg
);
if
(
data
.
valid
)
{
$
(
".amount_discount"
)
.
html
(
' - descuento de'
+
data
.
amount
+
'<br> = '
+
data
.
total
);
$
(
'.coupon'
)
.
val
(
text
);
}
else
{
$
(
".amount_discount"
)
.
text
(
''
);
}
});
}
});
</
script
>
@
endsection
src/views/public/forms/fields-payment-cash.blade.php
View file @
0a524135
...
...
@@ -4,17 +4,25 @@
<div
class=
"group"
>
<label>
Selecciona la opcion deseada
</label>
</label>
<br>
<select
name=
"payment_id"
>
<option
value=
"oxxo"
>
Oxxo
</option>
<option
value=
"bancomer"
>
Bancomer
</option>
<option
value=
"serfin"
>
Santander
</option>
<option
value=
"banamex"
>
Banamex
</option>
</select>
</select>
<br>
</div>
<div>
<label>
Si cuentas con un código de promocion introducelo aquí
</label><br>
<input
type=
"text"
name=
"coupon"
class=
"coupon"
placeholder=
"Codigo de promoción"
data-total=
"{{$sale->id}}"
>
<span
class=
"reponse_coupon"
></span>
<br>
</div>
<br>
<button>
Pagar {{ money_format('%(#10n', ($total + $addres->shipping_price->cost)) }}
<span
class=
"amount_discount"
></span>
</button>
</form>
\ No newline at end of file
src/views/public/forms/fields-payment.blade.php
View file @
0a524135
...
...
@@ -18,9 +18,17 @@
<input
class=
"form-white"
type=
"text"
size=
"4"
name=
"cvc"
data-checkout=
"securityCode"
placeholder=
"Ej. 543"
required=
"required"
class=
"form-control"
/>
<input
name=
"paymentMethodId"
type=
"hidden"
>
<button
type=
"submit"
>
<br>
<div>
<label>
Si cuentas con un código de promocion introducelo aquí
</label><br>
<input
type=
"text"
name=
"coupon"
class=
"coupon"
placeholder=
"Codigo de promoción"
data-total=
"{{$sale->id}}"
>
<span
class=
"reponse_coupon"
></span>
<br>
</div>
<br>
<button>
Pagar {{ money_format('%(#10n', ($total + $addres->shipping_price->cost)) }}
<span
class=
"amount_discount"
></span>
</button>
</form>
\ No newline at end of file
src/views/public/forms/form-acordar.blade.php
View file @
0a524135
<form
action=
"{{route('cart.acordar')}}"
method=
"POST"
>
{{ csrf_field() }}
<button
type=
"submit"
>
Acordar con el vendedor: {{ money_format('%(#10n', ($total + $addres->shipping_price->cost)) }}
<div>
<label>
Si cuentas con un código de promocion introducelo aquí
</label><br>
<input
type=
"text"
name=
"coupon"
class=
"coupon"
placeholder=
"Codigo de promoción"
data-total=
"{{$sale->id}}"
>
<span
class=
"reponse_coupon"
></span>
<br>
</div>
<br>
<button>
Acordar con el vendedor {{ money_format('%(#10n', ($total + $addres->shipping_price->cost)) }}
<br>
<span
class=
"amount_discount"
></span>
</button>
</form>
\ No newline at end of file
src/views/public/forms/form-paypal.blade.php
View file @
0a524135
<form
action=
"{{route('cart.paymentPaypal')}}"
method=
"POST"
>
{{ csrf_field() }}
<button>
<div>
<label>
Si cuentas con un código de promocion introducelo aquí
</label><br>
<input
type=
"text"
name=
"coupon"
class=
"coupon"
placeholder=
"Codigo de promoción"
data-total=
"{{$sale->id}}"
>
<span
class=
"reponse_coupon"
></span>
<br>
</div>
<br>
<button
type=
"submit"
>
Pagar con paypal {{ money_format('%(#10n', ($total + $addres->shipping_price->cost)) }}
<span
class=
"amount_discount"
></span>
</button>
</form>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment