add offers count, & minor fixes code standards
This commit is contained in:
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Shop\ArticleComponent;
|
||||
|
||||
class ArticleComponents
|
||||
{
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = ArticleComponent::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return ArticleComponent::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return ArticleComponent::find($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return ArticleComponent::create($data);
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
{
|
||||
return ArticleComponent::find($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return ArticleComponent::destroy($id);
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Shop\ArticlePrice;
|
||||
|
||||
class ArticlePrices
|
||||
{
|
||||
public static function getByArticle($id)
|
||||
{
|
||||
return ArticlePrice::byArticle($id)->get();
|
||||
}
|
||||
|
||||
public static function getByArticleWithAttribute($id)
|
||||
{
|
||||
return ArticlePrice::with('article_attribute.attribute_value')->byArticle($id)->get();
|
||||
}
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = ArticlePrice::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return ArticlePrice::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return ArticlePrice::find($id);
|
||||
}
|
||||
|
||||
public static function storePrices($article_id, $prices)
|
||||
{
|
||||
// dump($article_id);
|
||||
// dump($prices);
|
||||
// exit;
|
||||
if ($prices) {
|
||||
foreach ($prices as $key => $price) {
|
||||
$price['article_attribute']['article_attribute_value_id'] = $price['attribute']['attribute_value_id'];
|
||||
$prices[$key]['article_attribute_id'] = ArticleAttributes::storeAttribute($article_id, $price['article_attribute']);
|
||||
|
||||
unset($prices[$key]['article_attribute']);
|
||||
unset($prices[$key]['attribute']);
|
||||
self::store($prices[$key]);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$attributes = isset($data['attributes']) ? $data['attributes'] : false;
|
||||
unset($data['attributes']);
|
||||
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$price = $id ? self::update($data) : self::create($data);
|
||||
|
||||
$ret = $attributes ? self::storeAttributes($price->id, $attributes) : false;
|
||||
|
||||
return $price->id;
|
||||
}
|
||||
|
||||
public static function storeAttributes($article_price_id, $attributes)
|
||||
{
|
||||
return ArticleAttributes::storeAttribute($article_price_id, $attributes);
|
||||
}
|
||||
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return ArticlePrice::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$article = ArticlePrice::find($id);
|
||||
$article->update($data);
|
||||
return $article;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return ArticlePrice::destroy($id);
|
||||
}
|
||||
}
|
||||
@@ -172,7 +172,7 @@ class Articles
|
||||
|
||||
public static function getByCategory($category_id)
|
||||
{
|
||||
return Article::byCategory($category_id)->with(['prices','product','image'])->get();
|
||||
return Article::byCategory($category_id)->with(['prices', 'product', 'image'])->get();
|
||||
}
|
||||
|
||||
public static function getCategoriesByArticle($article)
|
||||
@@ -223,7 +223,6 @@ class Articles
|
||||
self::storeImages($article, $images);
|
||||
self::storeCategories($article, $categories);
|
||||
self::storeTags($article, $tags);
|
||||
self::storePrices($article, $prices);
|
||||
return $article->id;
|
||||
}
|
||||
|
||||
@@ -270,11 +269,6 @@ class Articles
|
||||
return Tag::storeTags($article, $tags);
|
||||
}
|
||||
|
||||
public static function storePrices($article, $prices)
|
||||
{
|
||||
return ArticlePrices::storePrices($article->id, $prices);
|
||||
}
|
||||
|
||||
public static function storeImages($article, $files)
|
||||
{
|
||||
return Medias::storeImages($article, $files);
|
||||
|
||||
@@ -118,7 +118,7 @@ class Categories
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$category = Category::find($id);
|
||||
$category = self::get($id);
|
||||
$ret = $category->update($data);
|
||||
CategoryTrees::update($data, $category->category_id);
|
||||
return $category;
|
||||
@@ -127,7 +127,7 @@ class Categories
|
||||
public static function destroy($id)
|
||||
{
|
||||
$category = self::get($id);
|
||||
self::deleteNode($category->category_id);
|
||||
CategoryTrees::destroy($category->category_id);
|
||||
return Category::destroy($id);
|
||||
}
|
||||
|
||||
|
||||
73
app/Repositories/Shop/Merchandises.php
Normal file
73
app/Repositories/Shop/Merchandises.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Merchandise;
|
||||
|
||||
class Merchandises
|
||||
{
|
||||
public static function autocomplete($str)
|
||||
{
|
||||
$data = Merchandise::byAutocomplete($str)->orderBy('name')->limit(30)->get()->pluck('name', 'id');
|
||||
$export = [];
|
||||
foreach ($data as $key => $name) {
|
||||
$export[] = ['value' => $key, 'text' => $name];
|
||||
}
|
||||
return $export;
|
||||
}
|
||||
|
||||
public static function getPrices($id)
|
||||
{
|
||||
return Merchandise::with(['price_lists.price_list_values', 'price_lists.sale_channel'])->find($id);
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Merchandise::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getStatus($status_id)
|
||||
{
|
||||
return self::getStatuses()[$status_id];
|
||||
}
|
||||
|
||||
public static function getStatuses()
|
||||
{
|
||||
return ['Actif','Suspendu','Invisible','Obsolete'];
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Merchandise::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Merchandise::find($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Merchandise::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$item = self::get($id);
|
||||
$item->update($data);
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Merchandise::destroy($id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user