120 lines
3.3 KiB
PHP
120 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Shop;
|
|
|
|
use App\Models\Shop\Offer;
|
|
|
|
class Offers
|
|
{
|
|
public static function getOffersByArticles($articles_ids, $sale_channel_id = false)
|
|
{
|
|
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
|
|
return Offer::active()
|
|
->with([
|
|
'article_nature',
|
|
'variation',
|
|
'tariff.price_lists' => function($query) use ($sale_channel_id) {
|
|
$query->bySaleChannel($sale_channel_id);
|
|
},
|
|
'tariff.price_lists.price_list_values',
|
|
])
|
|
->byArticles($articles_ids)
|
|
->bySaleChannel($sale_channel_id)
|
|
->get();
|
|
}
|
|
|
|
public static function getOffersByArticle($article_id, $sale_channel_id = false)
|
|
{
|
|
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
|
|
return Offer::active()
|
|
->with([
|
|
'article_nature',
|
|
'variation',
|
|
'tariff.price_lists' => function($query) use ($sale_channel_id) {
|
|
$query->bySaleChannel($sale_channel_id);
|
|
},
|
|
'tariff.price_lists.price_list_values',
|
|
])
|
|
->byArticle($article_id)
|
|
->bySaleChannel($sale_channel_id)
|
|
->get();
|
|
}
|
|
|
|
public static function getThumbSrcById($id)
|
|
{
|
|
return self::getThumbSrc(self::get($id));
|
|
}
|
|
|
|
public static function getThumbSrc(Offer $offer)
|
|
{
|
|
$image = $offer->article ? Articles::getFullImageByArticle($offer->article) : false;
|
|
return $image ? Articles::getThumbSrc($image) : false;
|
|
}
|
|
|
|
public static function getLast()
|
|
{
|
|
return Offer::with(['article.image'])->active()->orderByDesc('updated_at')->get();
|
|
}
|
|
|
|
public static function getByCategoryWithTags($category_id)
|
|
{
|
|
$category = Categories::get($category_id);
|
|
$tags = Categories::getTagsByCategory($category);
|
|
$offers1 = self::getByCategory($category_id)->toArray();
|
|
$offers2 = self::getByTags($tags)->toArray();
|
|
$data = array_merge($offers1, $offers2);
|
|
return $data;
|
|
}
|
|
|
|
public static function getByCategory($category_id)
|
|
{
|
|
return Offer::with(['article.image'])->byCategory($category_id)->get();
|
|
}
|
|
|
|
public static function getByTags($tags)
|
|
{
|
|
return Offer::with(['article.tags'])->byTags($tags)->get();
|
|
}
|
|
|
|
public static function getAll()
|
|
{
|
|
return Offer::get();
|
|
}
|
|
|
|
public static function get($id)
|
|
{
|
|
return Offer::findOrFail($id);
|
|
}
|
|
|
|
public static function store($data)
|
|
{
|
|
$id = isset($data['id']) ? $data['id'] : false;
|
|
$item = $id ? self::update($data, $id) : self::create($data);
|
|
return $item->id;
|
|
}
|
|
|
|
public static function create($data)
|
|
{
|
|
return Offer::create($data);
|
|
}
|
|
|
|
public static function update($data, $id = false)
|
|
{
|
|
$id = $id ? $id : $data['id'];
|
|
$item = self::get($id);
|
|
$item->update($data);
|
|
return $item;
|
|
}
|
|
|
|
public static function destroy($id)
|
|
{
|
|
return Offer::destroy($id);
|
|
}
|
|
|
|
public static function toggle_active($id, $status_id)
|
|
{
|
|
return self::update(['status_id' => $status_id], $id);
|
|
}
|
|
|
|
}
|