fixed discount bug on problem

fixed shopping card step bugs
pull/36/head
A1Gard 1 year ago
parent bd9fb9f5e8
commit 369b69f7fc

@ -4,7 +4,7 @@
/** /**
* A helper file for Laravel, to provide autocomplete information to your IDE * A helper file for Laravel, to provide autocomplete information to your IDE
* Generated for Laravel 9.52.8. * Generated for Laravel 9.52.14.
* *
* This file should not be included in your code, only analyzed by your IDE! * This file should not be included in your code, only analyzed by your IDE!
* *
@ -1252,7 +1252,7 @@
* Call the given Closure / class@method and inject its dependencies. * Call the given Closure / class@method and inject its dependencies.
* *
* @param callable|string $callback * @param callable|string $callback
* @param \Illuminate\Container\array<string, mixed> $parameters * @param array<string, mixed> $parameters
* @param string|null $defaultMethod * @param string|null $defaultMethod
* @return mixed * @return mixed
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
@ -11684,6 +11684,7 @@
/** /**
* Gets the decoded form or json request body. * Gets the decoded form or json request body.
* *
* @throws JsonException When the body cannot be decoded to an array
* @static * @static
*/ */
public static function getPayload() public static function getPayload()
@ -19129,6 +19130,27 @@
{ {
/** @var \Spatie\FlareClient\Flare $instance */ /** @var \Spatie\FlareClient\Flare $instance */
return $instance->filterReportsUsing($filterReportsCallable); return $instance->filterReportsUsing($filterReportsCallable);
}
/**
*
*
* @param array<class-string<ArgumentReducer>|ArgumentReducer>|\Spatie\Backtrace\Arguments\ArgumentReducers|null $argumentReducers
* @static
*/
public static function argumentReducers($argumentReducers)
{
/** @var \Spatie\FlareClient\Flare $instance */
return $instance->argumentReducers($argumentReducers);
}
/**
*
*
* @static
*/
public static function withStackFrameArguments($withStackFrameArguments = true)
{
/** @var \Spatie\FlareClient\Flare $instance */
return $instance->withStackFrameArguments($withStackFrameArguments);
} }
/** /**
* *
@ -19229,7 +19251,7 @@
* *
* @param string $name * @param string $name
* @param string $messageLevel * @param string $messageLevel
* @param \Spatie\FlareClient\array<int, mixed> $metaData * @param array<int, mixed> $metaData
* @return \Spatie\FlareClient\Flare * @return \Spatie\FlareClient\Flare
* @static * @static
*/ */
@ -19322,7 +19344,7 @@
/** /**
* *
* *
* @param \Spatie\FlareClient\array<int, string> $fieldNames * @param array<int, string> $fieldNames
* @return \Spatie\FlareClient\Flare * @return \Spatie\FlareClient\Flare
* @static * @static
*/ */
@ -19398,7 +19420,7 @@
* *
* *
* @param string $groupName * @param string $groupName
* @param \Spatie\FlareClient\array<string, mixed> $properties * @param array<string, mixed> $properties
* @return \Spatie\FlareClient\Flare * @return \Spatie\FlareClient\Flare
* @static * @static
*/ */
@ -23099,8 +23121,8 @@ namespace {
/** /**
* Increment the given column's values by the given amounts. * Increment the given column's values by the given amounts.
* *
* @param \Illuminate\Database\Query\array<string, float|int|numeric-string> $columns * @param array<string, float|int|numeric-string> $columns
* @param \Illuminate\Database\Query\array<string, mixed> $extra * @param array<string, mixed> $extra
* @return int * @return int
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @static * @static
@ -23114,8 +23136,8 @@ namespace {
/** /**
* Decrement the given column's values by the given amounts. * Decrement the given column's values by the given amounts.
* *
* @param \Illuminate\Database\Query\array<string, float|int|numeric-string> $columns * @param array<string, float|int|numeric-string> $columns
* @param \Illuminate\Database\Query\array<string, mixed> $extra * @param array<string, mixed> $extra
* @return int * @return int
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @static * @static

@ -603,6 +603,9 @@ function showMeta($key, $value)
*/ */
function time2persian($date, $format = 'Y/m/d') function time2persian($date, $format = 'Y/m/d')
{ {
if ($date == null){
return '-';
}
$dt = new TDate(); $dt = new TDate();
return $dt->PDate($format, $date); return $dt->PDate($format, $date);
} }

@ -112,6 +112,9 @@ class ProductController extends Controller
$discount->amount = $request->discount['amount']; $discount->amount = $request->discount['amount'];
$discount->expire = date('Y-m-d',floor($request->discount['expire']/1000)); $discount->expire = date('Y-m-d',floor($request->discount['expire']/1000));
// $discount->code = $request->discount['code']; // $discount->code = $request->discount['code'];
if ($discount->expire == '1970-01-01 00:00:00'){
$discount->expire = null;
}
$discount->type = $request->discount['type']; $discount->type = $request->discount['type'];
$discount->save(); $discount->save();
} }

@ -85,7 +85,7 @@ class GatewayRedirectController
$proData = [ $proData = [
'count' => $buyCount, 'count' => $buyCount,
'quantity_id' => $id, 'quantity_id' => $id,
'price_total' => ($q->price * ($buyCount)), 'price_total' => ($product->getPurePriceDef($q->price) * ($buyCount)),
'data'=>json_encode($q), 'data'=>json_encode($q),
]; ];
$invoice->total_price += $proData['price_total']; $invoice->total_price += $proData['price_total'];
@ -107,16 +107,16 @@ class GatewayRedirectController
$product->save(); $product->save();
$proData = [ $proData = [
'count' => \request('count')[$item], 'count' => \request('count')[$item],
'price_total' => ($product->price * (\request('count')[$item])) 'price_total' => ($product->getPurePrice() * (\request('count')[$item]))
]; ];
if (isset(\request('data')[$item])){ if (isset(\request('data')[$item])){
$temp = json_decode(\request('data')[$item]); $temp = json_decode(\request('data')[$item]);
$qd = Quantity::find($temp->id); $qd = Quantity::find($temp->id);
$qd->count -= \request('count')[$item]; $qd->count -= \request('count')[$item];
$proData['data'] = \request('data')[$item]; $proData['data'] = \request('data')[$item];
$proData['price_total'] = $qd->price * \request('count')[$item]; $proData['price_total'] = $product->getPurePriceDef($qd->price) * \request('count')[$item];
$proData['quantity_id'] = $qd->id; $proData['quantity_id'] = $qd->id;
$product->price = $qd->price; $product->price = $product->getPurePriceDef($qd->price);
$qd->save(); $qd->save();
} }
$invoice->save(); $invoice->save();

@ -6,6 +6,7 @@ use Conner\Tagging\Taggable;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use phpDocumentor\Reflection\Types\Never_;
use Plank\Metable\Metable; use Plank\Metable\Metable;
use Spatie\Image\Manipulations; use Spatie\Image\Manipulations;
use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\HasMedia;
@ -116,6 +117,8 @@ use function App\Helpers\getSetting;
* @method static \Illuminate\Database\Eloquent\Builder|Product whereImageIndex($value) * @method static \Illuminate\Database\Eloquent\Builder|Product whereImageIndex($value)
* @property int $carat * @property int $carat
* @method static \Illuminate\Database\Eloquent\Builder|Product whereCarat($value) * @method static \Illuminate\Database\Eloquent\Builder|Product whereCarat($value)
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Discount> $activeDiscounts
* @property-read int|null $active_discounts_count
* @mixin \Eloquent * @mixin \Eloquent
*/ */
class Product extends Model implements HasMedia class Product extends Model implements HasMedia
@ -239,11 +242,34 @@ class Product extends Model implements HasMedia
return $this->hasMany(Discount::class, 'product_id', 'id'); return $this->hasMany(Discount::class, 'product_id', 'id');
} }
public function activeDiscounts()
{
return $this->hasMany(Discount::class, 'product_id', 'id')->where(function ($query) {
$query->where('expire', '>=', date('Y-m-d'))
->orWhereNull('expire');
});
}
public function discountWithSign()
{
if ($this->activeDiscounts()->count() > 0) {
$discount = $this->activeDiscounts()->first();
if ($discount->type == 'price') {
return ' - ' . $discount->amount;
} else {
return ' * ' . (( 100 - $discount->amount ) / 100);
}
} else {
return null;
}
}
public function getPurePrice() public function getPurePrice()
{ {
if ($this->discounts()->whereNull('code')->count() > 0) { if ($this->activeDiscounts()->whereNull('code')->count() > 0) {
$d = $this->discounts()->whereNull('code')->orderBy('id', 'desc')->first(); $d = $this->activeDiscounts()->whereNull('code')->orderBy('id', 'desc')->first();
if ($d->type == 'percent') { if ($d->type == 'percent') {
$price = $this->price - ($this->price * ($d->amount / 100)); $price = $this->price - ($this->price * ($d->amount / 100));
return $price; return $price;
@ -261,8 +287,8 @@ class Product extends Model implements HasMedia
*/ */
public function getPurePriceDef($def) public function getPurePriceDef($def)
{ {
if ($this->discounts()->whereNull('code')->count() > 0) { if ($this->activeDiscounts()->whereNull('code')->count() > 0) {
$d = $this->discounts()->whereNull('code')->orderBy('id', 'desc')->first(); $d = $this->activeDiscounts()->whereNull('code')->orderBy('id', 'desc')->first();
if ($d->type == 'percent') { if ($d->type == 'percent') {
$price = $def - ($def * ($d->amount / 100)); $price = $def - ($def * ($d->amount / 100));
return $price; return $price;
@ -280,6 +306,7 @@ class Product extends Model implements HasMedia
} }
return number_format($this->price) . ' ' . config('app.currency_type'); return number_format($this->price) . ' ' . config('app.currency_type');
} }
public function getPrice() public function getPrice()
{ {
if ($this->getPurePrice() == 0) { if ($this->getPurePrice() == 0) {

@ -11137,7 +11137,7 @@ h3.textt{
#card-steps .step { #card-steps .step {
display: none; display: none;
} }
#card-steps .step.active { #card-steps .step.active-step {
display: block; display: block;
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -268,5 +268,28 @@ jQuery(function ($) {
}); });
} }
}, 500); }, 500);
$(".next-step").bind('click', function () {
step++;
$(".step" + step).click();
}); });
$(".progress-step .step").click(function () {
$(".progress-step .step").removeClass('done');
$($(this).data('done')).addClass('done');
$("#card-steps .active-step").slideUp(300).removeClass('active-step');
$('#' + $(this).data('id')).slideDown(500).addClass('active-step');
step = parseInt($(this).data('id').substr(4, 1));
if ($(this).data('id') == 'step3') {
$(".last-step").slideDown(300);
$(".next-step").slideUp(300);
} else {
$(".last-step").slideUp(300);
$(".next-step").slideDown(300);
}
});
});

@ -47,7 +47,7 @@
#card-steps { #card-steps {
.step{ .step{
display: none; display: none;
&.active{ &.active-step{
display: block; display: block;
} }
} }

@ -380,6 +380,13 @@ jQuery(function ($) {
}); });
try { try {
if ($('#qnt').length != 0) { if ($('#qnt').length != 0) {
let qnt ;
let hasDiscount = false;
if ($("#discount").val() !== ''){
hasDiscount = true;
}
sizes = {}; sizes = {};
qnt = JSON.parse($('#qnt').val()); qnt = JSON.parse($('#qnt').val());
// console.log(qnt); // console.log(qnt);
@ -414,10 +421,13 @@ jQuery(function ($) {
let txt = ''; let txt = '';
let cl = ''; let cl = '';
for( const c of colors) { for( const c of colors) {
cl = colorNames[c.color]; let p = c.price;
// console.log(c.color,colorNames); if (hasDiscount){
p = eval(c.price + $("#discount").val())
}
txt += `<div data-id="${c.id}" txt += `<div data-id="${c.id}"
data-price="${c.price}" data-price="${p}"
data-real-price="${c.price}"
data-count="${c.count}" data-count="${c.count}"
data-image="${c.image}" data-image="${c.image}"
class="color"> class="color">
@ -436,6 +446,7 @@ jQuery(function ($) {
$(this).addClass('active'); $(this).addClass('active');
$("#qn").val($(this).data('id')); $("#qn").val($(this).data('id'));
$("#last-pricex").text(commafy($(this).data('price'))); $("#last-pricex").text(commafy($(this).data('price')));
$("#real-price").text(commafy($(this).data('real-price')));
$("#counting").text($(this).data('count')); $("#counting").text($(this).data('count'));
$(".product-count").attr('max',$(this).data('count')).val(1); $(".product-count").attr('max',$(this).data('count')).val(1);
}); });

@ -13,11 +13,13 @@
<i class="fa fa-shopping-bag"></i> <i class="fa fa-shopping-bag"></i>
سبد خرید سبد خرید
</div> </div>
<div class="step step2" data-id="step2" data-done=".progress-step .step1,.progress-step .step2"> <div class="step step2" data-id="step2"
data-done=".progress-step .step1,.progress-step .step2">
<i class="fa fa-truck-fast"></i> <i class="fa fa-truck-fast"></i>
اطلاعات ارسال اطلاعات ارسال
</div> </div>
<div class="step step3" data-id="step3" data-done=".progress-step .step1,.progress-step .step2, .progress-step .step3"> <div class="step step3" data-id="step3"
data-done=".progress-step .step1,.progress-step .step2, .progress-step .step3">
<i class="fa fa-credit-card"></i> <i class="fa fa-credit-card"></i>
اطلاعات پرداخت اطلاعات پرداخت
</div> </div>
@ -29,7 +31,7 @@
<div class="row"> <div class="row">
<div class="col-md-9"> <div class="col-md-9">
<div id="card-steps"> <div id="card-steps">
<div id="step1" class="step active" > <div id="step1" class="step active-step">
<div class="text-center" id="card"> <div class="text-center" id="card">
<table class="table table-hover table-responsive-lg" <table class="table table-hover table-responsive-lg"
id="card-table"> id="card-table">
@ -63,7 +65,9 @@
</a> </a>
</td> </td>
<td colspan="2"> <td colspan="2">
<a href="{{route('product',$pro->slug)}}">
{{$pro->name}} {{$pro->name}}
</a>
<input type="hidden" name="products[]" value="{{$pro->id}}"> <input type="hidden" name="products[]" value="{{$pro->id}}">
</td> </td>
<td colspan="2"> <td colspan="2">
@ -74,7 +78,8 @@
@endif @endif
@endforeach @endforeach
@else @else
<span class="active" data-count="{{$pro->stock_quantity}}"></span> <span class="active"
data-count="{{$pro->stock_quantity}}"></span>
@foreach(\App\Helpers\getPriceableMeta($pro) as $k => $meta) @foreach(\App\Helpers\getPriceableMeta($pro) as $k => $meta)
<div class="meta"> <div class="meta">
{{\App\Helpers\getPropLabel($k)}} {{\App\Helpers\getPropLabel($k)}}
@ -89,7 +94,8 @@
@endforeach @endforeach
@endif @endif
</td> </td>
<td colspan="2" class="price-td" data-price="{{$pro->getPurePrice()}}"> <td colspan="2" class="price-td"
data-price="{{$pro->getPurePrice()}}">
@if($pro->getPurePrice() == 0) @if($pro->getPurePrice() == 0)
{{__("We call you about price soon.")}} {{__("We call you about price soon.")}}
@else @else
@ -105,8 +111,10 @@
<div class="btn btn-info count-inc"> <div class="btn btn-info count-inc">
<i class="fa fa-plus"></i> <i class="fa fa-plus"></i>
</div> </div>
<input type="number" data-stock="{{$pro->stock_quantity}}" <input type="number"
max="{{$pro->stock_quantity}}" name="count[{{$pro->id}}]" data-stock="{{$pro->stock_quantity}}"
max="{{$pro->stock_quantity}}"
name="count[{{$pro->id}}]"
min="1" min="1"
data-price="{{str_replace(',','',$pro->getPurePrice())}}" data-price="{{str_replace(',','',$pro->getPurePrice())}}"
class="form-control product-count" class="form-control product-count"
@ -117,7 +125,8 @@
</div> </div>
</td> </td>
<td> <td>
<a href="{{route('card.rem',$pro->slug)}}" class="btn btn-outline-danger"> <a href="{{route('card.rem',$pro->slug)}}"
class="btn btn-outline-danger">
<i class="fa fa-times"></i> <i class="fa fa-times"></i>
</a> </a>
</td> </td>
@ -129,15 +138,19 @@
<td> <td>
<a href="{{route('product',$qpro->product->slug)}}"> <a href="{{route('product',$qpro->product->slug)}}">
<img src="{{$qpro->product->thumbUrl()}}" class="img-64" alt=""> <img src="{{$qpro->product->thumbUrl()}}" class="img-64"
alt="">
</a> </a>
</td> </td>
<td colspan="2"> <td colspan="2">
{{$qpro->product->name}} <a href="{{route('product',$qpro->product->slug)}}">
{{$pro->name}}
</a>
</td> </td>
<td colspan="2"> <td colspan="2">
@php($data = json_decode($qpro->data)) @php($data = json_decode($qpro->data))
<span class="badge badge-inverse" style="background: {{$data->color}};"> <span class="badge badge-inverse"
style="background: {{$data->color}};">
<b> <b>
{{\App\Helpers\getColorName($data->color)}} {{\App\Helpers\getColorName($data->color)}}
</b> </b>
@ -146,23 +159,25 @@
{{$data->size}} {{$data->size}}
</span> </span>
</td> </td>
<td colspan="2" class="price-td" data-price="{{$qpro->price}}"> <td colspan="2" class="price-td"
data-price="{{$qpro->product->getPurePriceDef($qpro->price)}}">
@if($qpro->price == 0) @if($qpro->price == 0)
{{__("We call you about price soon.")}} {{__("We call you about price soon.")}}
@else @else
<span class="price"> <span class="price">
{{number_format($qpro->price)}} {{number_format($qpro->product->getPurePriceDef($qpro->price))}}
</span> </span>
{{config('app.currency_type')}} {{config('app.currency_type')}}
@endif @endif
@php($tot = $tot + $qpro->price) @php($tot = $tot + $qpro->product->getPurePriceDef($qpro->price))
</td> </td>
<td colspan="2"> <td colspan="2">
<div class="product-count"> <div class="product-count">
<div class="btn btn-info count-inc"> <div class="btn btn-info count-inc">
<i class="fa fa-plus"></i> <i class="fa fa-plus"></i>
</div> </div>
<input type="number" data-stock="{{$qpro->count}}" max="{{$qpro->count}}" <input type="number" data-stock="{{$qpro->count}}"
max="{{$qpro->count}}"
name="qcount[{{$qpro->id}}]" name="qcount[{{$qpro->id}}]"
min="1" min="1"
data-price="{{$qpro->price}}" data-price="{{$qpro->price}}"
@ -174,7 +189,8 @@
</div> </div>
</td> </td>
<td> <td>
<a href="{{route('card.remq',$qpro->id)}}" class="btn btn-outline-danger"> <a href="{{route('card.remq',$qpro->id)}}"
class="btn btn-outline-danger">
<i class="fa fa-times"></i> <i class="fa fa-times"></i>
</a> </a>
</td> </td>
@ -215,8 +231,13 @@
{{$t->title}} {{$t->title}}
</label> </label>
@if(strlen($t->description) > 1) @if(strlen($t->description) > 1)
<p class="preline alert alert-info mt-1">{{$t->description}} <span <p class="preline alert alert-info mt-1">{{$t->description}}
class="float-end">@if($t->price > 0){{number_format($t->price)}} @else {{__("Free")}} @endif</span> <span
class="float-end">@if($t->price > 0)
{{number_format($t->price)}}
@else
{{__("Free")}}
@endif</span>
</p> </p>
@endif @endif
</li> </li>
@ -251,7 +272,8 @@
</ul> </ul>
<div class="p-5 py-3" id="resv"> <div class="p-5 py-3" id="resv">
<div class="form-check form-switch"> <div class="form-check form-switch">
<input name="reserve" class="form-check-input" type="checkbox" role="switch" <input name="reserve" class="form-check-input" type="checkbox"
role="switch"
id="flexSwitchCheckDefault"> id="flexSwitchCheckDefault">
<label class="form-check-label" <label class="form-check-label"
for="flexSwitchCheckDefault">{{__("Reserve order for :H hours",['H'=>\App\Helpers\getSetting('reserve')])}}</label> for="flexSwitchCheckDefault">{{__("Reserve order for :H hours",['H'=>\App\Helpers\getSetting('reserve')])}}</label>
@ -293,7 +315,8 @@
</label> </label>
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<input type="text" class="form-control" id="discount-code" name="discount" <input type="text" class="form-control" id="discount-code"
name="discount"
placeholder="{{__("Discount code")}}"> placeholder="{{__("Discount code")}}">
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
@ -364,14 +387,16 @@
<i class="far fa-credit-card"></i> <i class="far fa-credit-card"></i>
پرداخت از درگاه های آنلاین پرداخت از درگاه های آنلاین
</button> </button>
<button type="submit" class="btn btn-secondary float-end " name="nopay" value="no-payment"> <button type="submit" class="btn btn-secondary float-end " name="nopay"
value="no-payment">
<i class="far fa-credit-card"></i> <i class="far fa-credit-card"></i>
ثبت سفارش پرداخت اعتباری + آنلاین ثبت سفارش پرداخت اعتباری + آنلاین
</button> </button>
<br> <br>
<br> <br>
@endif @endif
&nbsp;@else &nbsp;
@else
{{-- {{__("Register or login to complete purchase")}}--}} {{-- {{__("Register or login to complete purchase")}}--}}
<hr> <hr>
<br> <br>

@ -130,6 +130,14 @@
{{$pro->getPrice()}} {{$pro->getPrice()}}
</span> </span>
</b> </b>
@if($pro->hasDiscount())
<del class="text-muted">
<span id="real-price">
{{number_format($pro->price)}}
</span>
{{config('app.currency_type')}}
</del>
@endif
</td> </td>
</tr> </tr>
@if($pro->hasMeta('color')) @if($pro->hasMeta('color'))
@ -378,5 +386,6 @@
<input type="hidden" id="qn" value=""> <input type="hidden" id="qn" value="">
<input type="hidden" id="qnt" value='{!! $pro->quantities()->orderBy('price')->get();!!}'> <input type="hidden" id="qnt" value='{!! $pro->quantities()->orderBy('price')->get();!!}'>
<input type="hidden" id="colors" value='{!! json_encode( \App\Helpers\getColors()) !!}'> <input type="hidden" id="colors" value='{!! json_encode( \App\Helpers\getColors()) !!}'>
<input type="hidden" id="discount" value="{{$pro->discountWithSign()}}">
@endsection @endsection

Loading…
Cancel
Save