[WIP] Working on orders & invoices
This commit is contained in:
@@ -7,15 +7,6 @@ use App\Repositories\Core\User\ShopCart;
|
||||
|
||||
class Offers
|
||||
{
|
||||
public static function addBasket($offer_id, $quantity = 1, $update = false)
|
||||
{
|
||||
if (ShopCart::has($offer_id) && !$quantity) {
|
||||
$ret = ShopCart::remove($offer_id);
|
||||
}
|
||||
$data = $quantity ? Offers::getBasketData($offer_id, $quantity) : false;
|
||||
return $data ? ShopCart::add($data, $update) : false;
|
||||
}
|
||||
|
||||
public static function getFull($id, $sale_channel_id = false)
|
||||
{
|
||||
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
|
||||
@@ -43,47 +34,6 @@ class Offers
|
||||
return $offer->price_lists->first()->price_list_values->first();
|
||||
}
|
||||
|
||||
public static function getBasket($sale_channel_id = false)
|
||||
{
|
||||
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
|
||||
$basket = ShopCart::getContent();
|
||||
// dump($basket->toArray());
|
||||
$offers = Offer::with([
|
||||
'variation',
|
||||
'article.article_nature',
|
||||
'article.product.Specie',
|
||||
'article.image',
|
||||
'price_lists.price_list_values',
|
||||
])->withPriceListsBySaleChannel($sale_channel_id)
|
||||
->whereIn('id', ShopCart::keys())->get();
|
||||
foreach ($basket as $item) {
|
||||
$offer = $offers->where('id', $item->id)->first();
|
||||
$article_nature = strtolower($offer->article->article_nature->name);
|
||||
$data[$article_nature][] = [
|
||||
'id' => (int) $item->id,
|
||||
'name' => $item->name,
|
||||
'quantity' => (int) $item->quantity,
|
||||
'price' => $item->price,
|
||||
'variation' => $offer->variation->name,
|
||||
'image' => Articles::getPreviewSrc(Articles::getFullImageByArticle($offer->article)),
|
||||
'latin' => $offer->article->product->specie->latin ?? false,
|
||||
];
|
||||
}
|
||||
return $data ?? false;
|
||||
}
|
||||
|
||||
public static function getBasketData($id, $quantity = 1)
|
||||
{
|
||||
$offer = Offer::with(['article'])->findOrFail($id);
|
||||
return [
|
||||
'id' => $id,
|
||||
'name' => $offer->article->name,
|
||||
'price' => self::getPrice($id, $quantity)->price_taxed,
|
||||
'quantity' => $quantity,
|
||||
'attributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public static function getOffersByArticles($article_ids, $sale_channel_id = false)
|
||||
{
|
||||
return self::getOffersBySaleChannelRaw($sale_channel_id)->byArticles($article_ids)->get();
|
||||
@@ -155,16 +105,14 @@ class Offers
|
||||
return Offer::get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
public static function get($id, $relations = false)
|
||||
{
|
||||
return Offer::findOrFail($id);
|
||||
return $relations ? Offer::with($relations)->findOrFail($id) : 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;
|
||||
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
|
||||
Reference in New Issue
Block a user