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
* 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!
*
@ -1252,7 +1252,7 @@
* Call the given Closure / class@method and inject its dependencies.
*
* @param callable|string $callback
* @param \Illuminate\Container\array<string, mixed> $parameters
* @param array<string, mixed> $parameters
* @param string|null $defaultMethod
* @return mixed
* @throws \InvalidArgumentException
@ -11684,6 +11684,7 @@
/**
* Gets the decoded form or json request body.
*
* @throws JsonException When the body cannot be decoded to an array
* @static
*/
public static function getPayload()
@ -19129,6 +19130,27 @@
{
/** @var \Spatie\FlareClient\Flare $instance */
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 $messageLevel
* @param \Spatie\FlareClient\array<int, mixed> $metaData
* @param array<int, mixed> $metaData
* @return \Spatie\FlareClient\Flare
* @static
*/
@ -19322,7 +19344,7 @@
/**
*
*
* @param \Spatie\FlareClient\array<int, string> $fieldNames
* @param array<int, string> $fieldNames
* @return \Spatie\FlareClient\Flare
* @static
*/
@ -19398,7 +19420,7 @@
*
*
* @param string $groupName
* @param \Spatie\FlareClient\array<string, mixed> $properties
* @param array<string, mixed> $properties
* @return \Spatie\FlareClient\Flare
* @static
*/
@ -23099,8 +23121,8 @@ namespace {
/**
* Increment the given column's values by the given amounts.
*
* @param \Illuminate\Database\Query\array<string, float|int|numeric-string> $columns
* @param \Illuminate\Database\Query\array<string, mixed> $extra
* @param array<string, float|int|numeric-string> $columns
* @param array<string, mixed> $extra
* @return int
* @throws \InvalidArgumentException
* @static
@ -23114,8 +23136,8 @@ namespace {
/**
* Decrement the given column's values by the given amounts.
*
* @param \Illuminate\Database\Query\array<string, float|int|numeric-string> $columns
* @param \Illuminate\Database\Query\array<string, mixed> $extra
* @param array<string, float|int|numeric-string> $columns
* @param array<string, mixed> $extra
* @return int
* @throws \InvalidArgumentException
* @static

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

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

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

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

@ -11137,7 +11137,7 @@ h3.textt{
#card-steps .step {
display: none;
}
#card-steps .step.active {
#card-steps .step.active-step {
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);
$(".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 {
.step{
display: none;
&.active{
&.active-step{
display: block;
}
}

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

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

@ -130,6 +130,14 @@
{{$pro->getPrice()}}
</span>
</b>
@if($pro->hasDiscount())
<del class="text-muted">
<span id="real-price">
{{number_format($pro->price)}}
</span>
{{config('app.currency_type')}}
</del>
@endif
</td>
</tr>
@if($pro->hasMeta('color'))
@ -378,5 +386,6 @@
<input type="hidden" id="qn" value="">
<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="discount" value="{{$pro->discountWithSign()}}">
@endsection

Loading…
Cancel
Save