Try to fix price_lists by sale_channel
This commit is contained in:
@@ -38,6 +38,16 @@ class Article extends Model implements HasMedia
|
||||
return $this->hasMany(Offer::class);
|
||||
}
|
||||
|
||||
public function price_lists()
|
||||
{
|
||||
return $this->hasManyDeep(
|
||||
PriceList::class,
|
||||
[Offer::class, Tariff::class],
|
||||
['article_id', 'id'],
|
||||
['id', 'tariff_id'],
|
||||
);
|
||||
}
|
||||
|
||||
public function prices()
|
||||
{
|
||||
return $this->hasManyDeep(
|
||||
|
||||
@@ -163,10 +163,9 @@ class Offer extends Model
|
||||
public function scopeWithPriceListValuesBySaleChannel($query, $sale_channel_id)
|
||||
{
|
||||
return $query->with([
|
||||
'price_lists' => function($query) use ($sale_channel_id) {
|
||||
'price_lists.price_list_values' => function($query) use ($sale_channel_id) {
|
||||
$query->bySaleChannel($sale_channel_id);
|
||||
},
|
||||
'price_lists.price_list_values',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,4 +39,12 @@ class PriceListValue extends Model
|
||||
{
|
||||
return $query->orderBy('quantity', 'desc')->where($this->table . '.quantity', '<=', $quantity)->first();
|
||||
}
|
||||
|
||||
public function scopeBySaleChannel($query, $sale_channel_id) {
|
||||
return $query->with([
|
||||
'price_list' => function ($query) use ($sale_channel_id) {
|
||||
return $query->bySaleChannel($sale_channel_id);
|
||||
},
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class Tariff extends Model
|
||||
->orWhere($this->table . '.code', 'LIKE', "${str}%");
|
||||
}
|
||||
|
||||
public function scopeBySaleChanel($query, $id)
|
||||
public function scopeBySaleChanelDefault($query, $id)
|
||||
{
|
||||
return $query->where($this->table . '.sale_channel_id', $id);
|
||||
}
|
||||
|
||||
@@ -145,9 +145,13 @@ class Articles
|
||||
public static function getArticlesToSell($options)
|
||||
{
|
||||
$articles = self::getArticlesWithOffers($options);
|
||||
// dump($options);
|
||||
// dump($articles->toArray());
|
||||
// exit;
|
||||
/*
|
||||
foreach ($articles as $article) {
|
||||
$price_lists = $article->offers[0]->tariff->price_lists->toArray();
|
||||
// dump($price_lists);
|
||||
dump($price_lists);
|
||||
if (count($price_lists)) {
|
||||
if (!is_array($data[$article->name] ?? false)) {
|
||||
$data[$article->name] = self::getDataForSale($article);
|
||||
@@ -157,6 +161,7 @@ class Articles
|
||||
$data[$article->name][$article_nature_name] = self::getDataPriceForSale($article, $prices);
|
||||
}
|
||||
}
|
||||
*/
|
||||
return $data ?? false;
|
||||
}
|
||||
|
||||
@@ -190,14 +195,24 @@ class Articles
|
||||
$sale_channel_id = $options['sale_channel_id'] ?? SaleChannels::getDefaultID();
|
||||
$tags = $options['tags'] ?? false;
|
||||
$model = ($options['homepage'] ?? false) ? Article::homepage()->visible() : Article::visible();
|
||||
|
||||
dump($model->with([
|
||||
'offers' => function($query) use ($sale_channel_id) {
|
||||
$query->withPriceListValuesBySaleChannel($sale_channel_id);
|
||||
},
|
||||
])
|
||||
->get()->toArray());
|
||||
dump('ici');
|
||||
|
||||
// exit;
|
||||
return $model->byCategory($category_id)->byTags($tags)->withAvailableOffers($sale_channel_id)->with([
|
||||
'image',
|
||||
'product',
|
||||
'article_nature',
|
||||
'offers.variation.package',
|
||||
'offers.tariff.price_lists' => function($query) use ($sale_channel_id) {
|
||||
'offers' => function($query) use ($sale_channel_id) {
|
||||
$query->bySaleChannel($sale_channel_id);
|
||||
},
|
||||
'offers.variation.package',
|
||||
'offers.tariff.price_lists.price_list_values',
|
||||
])->get();
|
||||
}
|
||||
|
||||
@@ -48,27 +48,25 @@ class Offers
|
||||
];
|
||||
}
|
||||
|
||||
public static function getOffersByArticles($articles_ids, $sale_channel_id = false)
|
||||
public static function getOffersByArticles($article_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();
|
||||
return self::getOffersBySaleChannelRaw($sale_channel_id)->byArticles($article_ids)->get();
|
||||
}
|
||||
|
||||
public static function getOffersByArticle($article_id, $sale_channel_id = false)
|
||||
{
|
||||
return self::getOffersBySaleChannelRaw($sale_channel_id)->byArticle($article_id)->get();
|
||||
}
|
||||
|
||||
public static function getOffersBySaleChannel($sale_channel_id = false)
|
||||
{
|
||||
return self::getOffersBySaleChannelRaw($sale_channel_id)->get();
|
||||
}
|
||||
|
||||
public static function getOffersBySaleChannelRaw($sale_channel_id = false)
|
||||
{
|
||||
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
|
||||
return Offer::active()
|
||||
return Offer::active()->byStockAvailable()
|
||||
->with([
|
||||
'article_nature',
|
||||
'variation',
|
||||
@@ -77,9 +75,7 @@ class Offers
|
||||
},
|
||||
'tariff.price_lists.price_list_values',
|
||||
])
|
||||
->byArticle($article_id)
|
||||
->bySaleChannel($sale_channel_id)
|
||||
->get();
|
||||
->bySaleChannel($sale_channel_id);
|
||||
}
|
||||
|
||||
public static function getThumbSrcById($id)
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
"php-console/php-console": "^3.1",
|
||||
"proengsoft/laravel-jsvalidation": "^4.5",
|
||||
"qoraiche/laravel-mail-editor": "^3.2",
|
||||
"rahul900day/laravel-captcha": "^1.0",
|
||||
"respect/validation": "^2.2",
|
||||
"rinvex/laravel-categories": "^6.0",
|
||||
"rinvex/laravel-tags": "^6.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
<ul class="navbar-nav mr-auto" style="width:180px;">
|
||||
@foreach ($categories as $category)
|
||||
@if (isset($category['children']))
|
||||
<li class="nav-item dropdown">
|
||||
|
||||
Reference in New Issue
Block a user