Manage homepage by article, modify article template, enhance basket (add selector)

This commit is contained in:
Ludovic CANDELLIER
2022-03-24 00:48:26 +01:00
parent ddc5f2664c
commit c65056531c
13 changed files with 277 additions and 148 deletions

View File

@@ -133,49 +133,64 @@ class Articles
$data[] = [
'id' => $shelve->id,
'name' => $shelve->name,
'articles' => self::getArticlesToSell($shelve->id),
'articles' => self::getArticlesToSell([
'category_id' => $shelve->id,
'homepage' => true,
]),
];
}
return $data;
}
public static function getArticlesToSell($category_id = false, $tags = false)
public static function getArticlesToSell($options)
{
$articles = self::getArticlesWithOffers($category_id, $tags);
$articles = self::getArticlesWithOffers($options);
foreach ($articles as $article) {
$price_lists = $article->offers[0]->tariff->price_lists->toArray();
// dump($price_lists);
if (count($price_lists)) {
if (!is_array($data[$article->name] ?? false)) {
$data[$article->name] = [
'id' => $article->id,
'description' => (!empty($article->description)) ? $article->description : $article->product->description,
'image' => self::getFullImageByArticle($article),
'product_type' => $article->product_type,
'product_id' => $article->product_id,
'product_name' => $article->product->name,
'parent_name' => trim(str_replace($article->product->name, '', $article->name)),
];
$data[$article->name] = self::getDataForSale($article);
}
$prices = $price_lists[0]['price_list_values'][0];
$article_nature_name = strtolower($article->article_nature->name);
// dump($prices);
$data[$article->name][$article_nature_name] = [
'article_id' => $article->id,
'offer_id' => $article->offers[0]->id,
'quantity' => $prices['quantity'],
'price' => $prices['price_taxed'],
'variation' => $article->offers[0]->variation->name,
];
$data[$article->name][$article_nature_name] = self::getDataPriceForSale($article, $prices);
}
}
return $data ?? false;
}
public static function getArticlesWithOffers($category_id = false, $tags = false, $sale_channel_id = false)
public static function getDataForSale($article)
{
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
return Article::byCategory($category_id)->byTags($tags)->visible()->withAvailableOffers($sale_channel_id)->with([
return [
'id' => $article->id,
'description' => (!empty($article->description)) ? $article->description : $article->product->description,
'image' => self::getFullImageByArticle($article),
'product_type' => $article->product_type,
'product_id' => $article->product_id,
'product_name' => $article->product->name,
'parent_name' => trim(str_replace($article->product->name, '', $article->name)),
];
}
public static function getDataPriceForSale($article, $prices)
{
return [
'article_id' => $article->id,
'offer_id' => $article->offers[0]->id,
'quantity' => $prices['quantity'],
'price' => $prices['price_taxed'],
'variation' => $article->offers[0]->variation->name,
];
}
public static function getArticlesWithOffers($options = false)
{
$category_id = $options['category_id'] ?? false;
$sale_channel_id = $options['sale_channel_id'] ?? SaleChannels::getDefaultID();
$tags = $options['tags'] ?? false;
$model = ($options['homepage'] ?? false) ? Article::homepage()->visible() : Article::visible();
return $model->byCategory($category_id)->byTags($tags)->withAvailableOffers($sale_channel_id)->with([
'image',
'product',
'article_nature',
@@ -187,6 +202,7 @@ class Articles
])->get();
}
public static function getFull($id)
{
$data['article'] = self::getArticleEdit($id);
@@ -452,4 +468,15 @@ class Articles
{
return Tag::storeTags($article, $tags);
}
public static function toggleVisible($id, $visible)
{
return self::update(['visible' => $visible], $id);
}
public static function toggleHomepage($id, $homepage)
{
return self::update(['homepage' => $homepage], $id);
}
}

View File

@@ -18,11 +18,22 @@ class Offers
public static function getBasket()
{
$basket = ShopCart::getContent();
$offers = Offer::with(['variation', 'article.article_nature'])->whereIn('id', ShopCart::keys())->get();
dump($basket->toArray());
dump($offers->toArray());
exit;
return $data;
// dump($basket->toArray());
$offers = Offer::with(['variation', 'article.article_nature', 'article.image'])->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($offer->article->image),
];
}
return $data ?? false;
}
public static function getBasketData($id, $quantity = 1)