diff --git a/app/Datatables/Shop/ArticlesDataTable.php b/app/Datatables/Shop/ArticlesDataTable.php
index 1772f6b4..23ef7257 100644
--- a/app/Datatables/Shop/ArticlesDataTable.php
+++ b/app/Datatables/Shop/ArticlesDataTable.php
@@ -43,6 +43,28 @@ class ArticlesDataTable extends DataTable
public function modifier($datatables)
{
$datatables
+ ->editColumn('visible', function (Article $article) {
+ return view("components.form.toggle", [
+ 'name' => 'visible',
+ 'value' => $article->visible,
+ 'on' => __('oui'),
+ 'off' => __('non'),
+ 'meta' => 'data-id=' . $article->id,
+ 'size' => 'sm',
+ 'class' => 'visible',
+ ]);
+ })
+ ->editColumn('homepage', function (Article $article) {
+ return view("components.form.toggle", [
+ 'name' => 'homepage',
+ 'value' => $article->homepage,
+ 'on' => __('oui'),
+ 'off' => __('non'),
+ 'meta' => 'data-id=' . $article->id,
+ 'size' => 'sm',
+ 'class' => 'homepage',
+ ]);
+ })
->editColumn('thumb', function (Article $article) {
$image = Articles::getFullImageByArticle($article);
return '';
@@ -64,6 +86,8 @@ class ArticlesDataTable extends DataTable
protected function getColumns()
{
return [
+ Column::make('visible')->title('Visible')->searchable(false),
+ Column::make('homepage')->title('Accueil')->searchable(false),
Column::make('article_nature.name')->title('Nature'),
Column::make('thumb')->title('')->searchable(false)->orderable(false)->width(40)->class('text-center'),
Column::make('name')->title('Nom'),
diff --git a/app/Http/Controllers/Admin/Shop/ArticleController.php b/app/Http/Controllers/Admin/Shop/ArticleController.php
index 61caef3e..23318eaa 100644
--- a/app/Http/Controllers/Admin/Shop/ArticleController.php
+++ b/app/Http/Controllers/Admin/Shop/ArticleController.php
@@ -89,4 +89,17 @@ class ArticleController extends Controller
$index = $request->input('index');
return Articles::deleteImage($id, $index);
}
+
+ public function toggleVisible(Request $request)
+ {
+ $data = Articles::toggleVisible($request->input('id'), ($request->input('visible') == 'true') ? 1 : 0);
+ return response()->json(['error' => 0]);
+ }
+
+ public function toggleHomepage(Request $request)
+ {
+ $data = Articles::toggleHomepage($request->input('id'), ($request->input('homepage') == 'true') ? 1 : 0);
+ return response()->json(['error' => 0]);
+ }
+
}
diff --git a/app/Http/Controllers/Shop/BasketController.php b/app/Http/Controllers/Shop/BasketController.php
index e9169dfc..29b65297 100644
--- a/app/Http/Controllers/Shop/BasketController.php
+++ b/app/Http/Controllers/Shop/BasketController.php
@@ -27,16 +27,17 @@ class BasketController extends Controller
if (ShopCart::has($offer_id)) {
$ret = ShopCart::remove($offer_id);
}
- $data = Offers::getBasketData($offer_id, $quantity);
- $ret = ShopCart::add($data);
+ $data = $quantity ? Offers::getBasketData($offer_id, $quantity) : false;
+ $ret = $data ? ShopCart::add($data) : false;
return true;
}
public function basket()
{
+ $data = self::init();
$data['basket'] = Offers::getBasket();
- dump($data['basket']->toArray());
- exit;
+ //dump($data['basket']);
+ // exit;
return view('Shop.Baskets.basket', $data);
}
diff --git a/app/Models/Shop/Article.php b/app/Models/Shop/Article.php
index 37d3c294..9c0bde82 100644
--- a/app/Models/Shop/Article.php
+++ b/app/Models/Shop/Article.php
@@ -131,4 +131,9 @@ class Article extends Model implements HasMedia
{
return $query->where($this->table . '.visible', 1);
}
+
+ public function scopeHomepage($query)
+ {
+ return $query->where($this->table . '.homepage', 1);
+ }
}
diff --git a/app/Repositories/Shop/Articles.php b/app/Repositories/Shop/Articles.php
index eb239575..b3293abf 100644
--- a/app/Repositories/Shop/Articles.php
+++ b/app/Repositories/Shop/Articles.php
@@ -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);
+ }
+
}
diff --git a/app/Repositories/Shop/Offers.php b/app/Repositories/Shop/Offers.php
index ce44944c..2f735ad2 100644
--- a/app/Repositories/Shop/Offers.php
+++ b/app/Repositories/Shop/Offers.php
@@ -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)
diff --git a/resources/views/Admin/Shop/Articles/form.blade.php b/resources/views/Admin/Shop/Articles/form.blade.php
index c2cee1b2..28ab643d 100644
--- a/resources/views/Admin/Shop/Articles/form.blade.php
+++ b/resources/views/Admin/Shop/Articles/form.blade.php
@@ -1,79 +1,6 @@