new: add channel management
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Offer;
|
||||
use App\Models\Shop\PriceListValue;
|
||||
use App\Models\Shop\SaleChannel;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class Offers
|
||||
@@ -166,4 +168,42 @@ class Offers
|
||||
{
|
||||
return Offer::query();
|
||||
}
|
||||
|
||||
public static function getSaleChannelsForArticle($articleId)
|
||||
{
|
||||
$channels = SaleChannel::query()
|
||||
->whereHas('price_lists', function ($query) use ($articleId) {
|
||||
$query->whereHas('tariff.offers', function ($subQuery) use ($articleId) {
|
||||
$subQuery->byArticle($articleId);
|
||||
})->whereHas('price_list_values');
|
||||
})
|
||||
->orderBy('name')
|
||||
->get();
|
||||
|
||||
$offers = Offer::query()
|
||||
->byArticle($articleId)
|
||||
->with('article')
|
||||
->get();
|
||||
|
||||
return $channels->map(function ($channel) use ($offers) {
|
||||
$priceValue = null;
|
||||
|
||||
foreach ($offers as $offer) {
|
||||
$priceCandidate = self::getPrice($offer->id, 1, $channel->id);
|
||||
|
||||
if ($priceCandidate && (float) $priceCandidate->price_taxed > 0) {
|
||||
$priceValue = $priceCandidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $channel->id,
|
||||
'name' => $channel->name,
|
||||
'code' => $channel->code,
|
||||
'price_taxed' => $priceValue ? (float) $priceValue->price_taxed : null,
|
||||
'quantity' => $priceValue ? (int) $priceValue->quantity : null,
|
||||
];
|
||||
})->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user