96 lines
2.3 KiB
PHP
96 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Shop;
|
|
|
|
use App\Models\Shop\Offer;
|
|
|
|
class Offers
|
|
{
|
|
|
|
public static function getOffersByArticles($articles_id)
|
|
{
|
|
return Offer::active()->with(['article_nature', 'tariff.price_lists.price_list_values', 'variation'])->byArticles($articles_id)->get();
|
|
}
|
|
|
|
public static function getOffersByArticle($article_id)
|
|
{
|
|
return Offer::active()->with('variation')->byArticle($article_id)->get();
|
|
}
|
|
|
|
public static function getThumbSrcById($id)
|
|
{
|
|
return self::getThumbSrc(self::get($id));
|
|
}
|
|
|
|
public static function getThumbSrc(Offer $offer)
|
|
{
|
|
return $offer->article ? Articles::getThumbSrc($offer->article->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);
|
|
}
|
|
|
|
}
|