mirror of
https://github.com/openclassify/openclassify.git
synced 2026-01-11 18:01:10 -06:00
added bestseller twig function
This commit is contained in:
parent
4f55c622e9
commit
fd12783ec0
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Anomaly\Streams\Platform\Database\Migration\Migration;
|
||||
|
||||
class VisiosoftModuleAdvsAddTotalSalesField extends Migration
|
||||
{
|
||||
protected $delete = false;
|
||||
|
||||
protected $stream = [
|
||||
'slug' => 'advs',
|
||||
];
|
||||
|
||||
protected $fields = [
|
||||
'total_sales' => [
|
||||
'type' => 'anomaly.field_type.integer',
|
||||
'config' => [
|
||||
'min' => 0,
|
||||
'default_value' => 0,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
protected $assignments = [
|
||||
'total_sales'
|
||||
];
|
||||
}
|
||||
@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Visiosoft\AdvsModule\Adv\Contract\AdvInterface;
|
||||
use Anomaly\Streams\Platform\Model\Advs\AdvsAdvsEntryModel;
|
||||
use Visiosoft\AdvsModule\Support\Command\Currency;
|
||||
use Visiosoft\LocationModule\City\CityModel;
|
||||
use Visiosoft\LocationModule\Country\CountryModel;
|
||||
use Visiosoft\CartsModule\Cart\Command\GetCart;
|
||||
@ -17,6 +18,51 @@ use Visiosoft\LocationModule\Village\Contract\VillageRepositoryInterface;
|
||||
|
||||
class AdvModel extends AdvsAdvsEntryModel implements AdvInterface
|
||||
{
|
||||
protected $appends = [
|
||||
'detail_url',
|
||||
'currency_price',
|
||||
'currency_standard_price',
|
||||
'category1',
|
||||
'category2',
|
||||
'thumbnail',
|
||||
];
|
||||
|
||||
public function getDetailUrlAttribute()
|
||||
{
|
||||
return $this->getAdvDetailLinkByModel($this, 'list');
|
||||
}
|
||||
|
||||
public function getCurrencyPriceAttribute()
|
||||
{
|
||||
return app(Currency::class)->format($this->price, $this->currency);
|
||||
}
|
||||
|
||||
public function getCurrencyStandardPriceAttribute()
|
||||
{
|
||||
return app(Currency::class)->format($this->standard_price, $this->currency);
|
||||
}
|
||||
|
||||
public function getCategory1Attribute()
|
||||
{
|
||||
return $this->hasMany('Visiosoft\CatsModule\Category\CategoryModel', 'id', 'cat1')->first();
|
||||
|
||||
}
|
||||
|
||||
public function getCategory2Attribute()
|
||||
{
|
||||
return $this->hasMany('Visiosoft\CatsModule\Category\CategoryModel', 'id', 'cat1')->first();
|
||||
|
||||
}
|
||||
|
||||
public function getThumbnailAttribute()
|
||||
{
|
||||
if ($this->cover_photo == null) {
|
||||
return $this->dispatch(new MakeImageInstance('visiosoft.theme.base::images/no-image.png', 'img'))->url();
|
||||
} else {
|
||||
return url($this->cover_photo);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTransNameAttribute()
|
||||
{
|
||||
if (is_null($this->name)) {
|
||||
@ -278,12 +324,10 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface
|
||||
|
||||
public function stockControl($id, $quantity)
|
||||
{
|
||||
if($adv = $this->getAdv($id))
|
||||
{
|
||||
if ($adv = $this->getAdv($id)) {
|
||||
$stock = $adv->stock;
|
||||
|
||||
if($stock and $stock >= $quantity)
|
||||
{
|
||||
if ($stock and $stock >= $quantity) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,6 +49,19 @@ class AdvsModulePlugin extends Plugin
|
||||
return $latestAds;
|
||||
}
|
||||
),
|
||||
new \Twig_SimpleFunction(
|
||||
'bestsellerAds',
|
||||
function ($catId = null) {
|
||||
return AdvModel::query()
|
||||
->orderBy('total_sales', 'desc')
|
||||
->where(function ($query) use ($catId) {
|
||||
if ($catId) {
|
||||
$query->where('cat1', $catId);
|
||||
}
|
||||
})
|
||||
->limit(10)->get();
|
||||
}
|
||||
),
|
||||
new \Twig_SimpleFunction(
|
||||
'appendRequestURL',
|
||||
function ($request, $url, $new_parameters, $removeParams = []) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user