new: add channel management

This commit is contained in:
Valentin Lab
2025-10-05 09:39:27 +02:00
parent 2d7436a12b
commit 8d130b9741
16 changed files with 541 additions and 65 deletions

View File

@@ -100,12 +100,19 @@ class Baskets
$offers = Offers::getWithPricesByIds(self::getIds(), $saleChannelId);
foreach ($basket as $item) {
$offer = $offers->where('id', $item->id)->first();
if (! $offer) {
continue;
}
$priceValue = Offers::getPrice($item->id, $item->quantity, $saleChannelId);
$unitPrice = $priceValue ? (float) $priceValue->price_taxed : (float) $item->price;
$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,
'price' => $unitPrice,
'variation' => $offer->variation->name,
'image' => Articles::getPreviewSrc(ArticleImages::getFullImageByArticle($offer->article)),
'latin' => $offer->article->product->specie->latin ?? false,
@@ -115,6 +122,24 @@ class Baskets
return $data ?? false;
}
public static function refreshPrices($saleChannelId = false)
{
$saleChannelId = $saleChannelId ? $saleChannelId : SaleChannels::getDefaultID();
$basket = ShopCart::getContent();
foreach ($basket as $item) {
$priceValue = Offers::getPrice($item->id, $item->quantity, $saleChannelId);
if (! $priceValue) {
continue;
}
ShopCart::get()->update($item->id, [
'price' => $priceValue->price_taxed,
]);
}
}
public static function getBasketData($id, $quantity = 1)
{
$offer = Offers::get($id, ['article', 'variation']);