refactoring on Articles, minor fixes
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Datatables\Admin\Shop\ArticlesDataTable;
|
||||
use App\Http\Requests\Admin\Shop\StoreArticlePost;
|
||||
use App\Repositories\Shop\ArticleNatures;
|
||||
use App\Repositories\Shop\Articles;
|
||||
use App\Repositories\Shop\ArticleInherited;
|
||||
use App\Repositories\Shop\Categories;
|
||||
use App\Repositories\Shop\Tags;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -71,7 +72,7 @@ class ArticleController extends Controller
|
||||
{
|
||||
$data = [
|
||||
'article' => [
|
||||
'inherited' => Articles::getInheritedByProduct($productId, base64_decode($model)),
|
||||
'inherited' => ArticleInherited::getInheritedByProduct($productId, base64_decode($model)),
|
||||
],
|
||||
];
|
||||
|
||||
@@ -80,7 +81,7 @@ class ArticleController extends Controller
|
||||
|
||||
public function getProductTags($productId, $model)
|
||||
{
|
||||
$data = Articles::getInheritedByProduct($productId, base64_decode($model));
|
||||
$data = ArticleInherited::getInheritedByProduct($productId, base64_decode($model));
|
||||
|
||||
return view('Admin.Shop.Articles.partials.product.tags', $data);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class ContentController extends Controller
|
||||
public function edit($id)
|
||||
{
|
||||
$data = [
|
||||
'homepage' => Contents::get($id),
|
||||
'content' => Contents::get($id),
|
||||
];
|
||||
|
||||
return view('Admin.Shop.Contents.edit', $data);
|
||||
|
||||
@@ -10,19 +10,17 @@ class CustomerAddressController extends Controller
|
||||
{
|
||||
public function index(CustomerAddressesDataTable $dataTable)
|
||||
{
|
||||
$data = [];
|
||||
|
||||
return $dataTable->render('Admin.Shop.Customers.list', $data);
|
||||
return $dataTable->render('Admin.Shop.Customers.list');
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('Admin.Shop.CustomerAddresses.create', $data);
|
||||
return view('Admin.Shop.CustomerAddresses.create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$ret = CustomerAddresses::storeFull($request->all());
|
||||
$ret = CustomerAddresses::store($request->all());
|
||||
|
||||
return redirect()->route('Admin.Shop.CustomerAddresses.index');
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Shop;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Repositories\Shop\Articles;
|
||||
use App\Repositories\Shop\ArticleSiblings;
|
||||
|
||||
class ArticleController extends Controller
|
||||
{
|
||||
@@ -11,7 +12,7 @@ class ArticleController extends Controller
|
||||
{
|
||||
$data = [
|
||||
'article' => Articles::getArticleToSell($id),
|
||||
'offers2' => Articles::getSiblings($id)->toArray(),
|
||||
'offers2' => ArticleSiblings::getSiblings($id)->toArray(),
|
||||
];
|
||||
|
||||
return view('Shop.Articles.show', $data);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace App\Http\Controllers\Shop;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Repositories\Core\PDF;
|
||||
use App\Repositories\Shop\InvoicePDF;
|
||||
use App\Repositories\Shop\Invoices;
|
||||
|
||||
class InvoiceController extends Controller
|
||||
@@ -24,11 +24,6 @@ class InvoiceController extends Controller
|
||||
{
|
||||
\Debugbar::disable();
|
||||
|
||||
$data = [
|
||||
'invoice' => Invoices::getByUUID($uuid),
|
||||
];
|
||||
$filename = 'invoice-'.$uuid.'.pdf';
|
||||
|
||||
return PDF::view('Shop.Invoices.pdf', $data, $filename);
|
||||
return InvoicePDF::getByUUID($uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,6 @@ class Tax extends Model
|
||||
|
||||
public function price()
|
||||
{
|
||||
return $this->hasMany(ArticlePrice::class, 'id', 'tax_id');
|
||||
return $this->hasMany(PriceListValue::class, 'id', 'tax_id');
|
||||
}
|
||||
}
|
||||
|
||||
62
app/Repositories/Shop/ArticleCategories.php
Normal file
62
app/Repositories/Shop/ArticleCategories.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Article;
|
||||
use App\Models\Shop\Merchandise;
|
||||
use App\Repositories\Botanic\Species;
|
||||
use App\Repositories\Botanic\Varieties;
|
||||
use App\Repositories\Core\Comments;
|
||||
use App\Repositories\Core\Tag;
|
||||
use App\Traits\Model\Basic;
|
||||
use App\Traits\Repository\Imageable;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ArticleCategories
|
||||
{
|
||||
public static function getProductTypeByCategory($category_id)
|
||||
{
|
||||
$models = self::getProductTypesModelsByCategory($category_id);
|
||||
|
||||
return ($models[0] ?? false) === Merchandise::class ? 'merchandise' : 'botanic';
|
||||
}
|
||||
|
||||
public static function getProductTypesModelsByCategory($category_id)
|
||||
{
|
||||
return Article::byCategory($category_id)->select('product_type')->distinct()->get();
|
||||
}
|
||||
|
||||
public static function countProductTypesByCategory($category_id)
|
||||
{
|
||||
return Article::byCategory($category_id)->select('product_type')->distinct()->count();
|
||||
}
|
||||
|
||||
public static function getByCategory($category_id)
|
||||
{
|
||||
return Article::byCategory($category_id)->with(['prices', 'product', 'image'])->get();
|
||||
}
|
||||
|
||||
public static function getCategoriesByArticle($article)
|
||||
{
|
||||
return $article->categories->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
public static function getCategoriesNameByArticle($article)
|
||||
{
|
||||
return $article->categories->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function storeCategories($article, $categories)
|
||||
{
|
||||
if (! $categories) {
|
||||
return false;
|
||||
}
|
||||
$categories = collect($categories)->transform(
|
||||
function ($item, $key) {
|
||||
return (int) $item;
|
||||
}
|
||||
)->toArray();
|
||||
|
||||
return $article->syncCategories($categories, true);
|
||||
}
|
||||
}
|
||||
110
app/Repositories/Shop/ArticleImages.php
Normal file
110
app/Repositories/Shop/ArticleImages.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Article;
|
||||
use App\Models\Shop\Merchandise;
|
||||
use App\Repositories\Botanic\Species;
|
||||
use App\Repositories\Botanic\Varieties;
|
||||
use App\Repositories\Core\Comments;
|
||||
use App\Repositories\Core\Tag;
|
||||
use App\Traits\Model\Basic;
|
||||
use App\Traits\Repository\Imageable;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ArticleImages
|
||||
{
|
||||
use Basic, Imageable;
|
||||
|
||||
public static function getFullImagesByArticleId($id)
|
||||
{
|
||||
$article = self::get($id);
|
||||
|
||||
return $article ? self::getFullImagesByArticle($article) : false;
|
||||
}
|
||||
|
||||
public static function countFullImagesByArticleId($id)
|
||||
{
|
||||
$article = self::get($id);
|
||||
|
||||
return $article ? self::countFullImagesByArticle($article) : 0;
|
||||
}
|
||||
|
||||
public static function countFullImagesByArticle($article)
|
||||
{
|
||||
return count(self::getFullImagesByArticle($article));
|
||||
}
|
||||
|
||||
public static function getFullImagesByArticle($article)
|
||||
{
|
||||
$images = count($article->images) ? $article->images : collect([]);
|
||||
switch ($article->product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$variety = $article->product ?? false;
|
||||
$specie = $variety->specie ?? false;
|
||||
if ($variety) {
|
||||
$images = count($variety->images ?? []) ? $images->merge($variety->images) : $images;
|
||||
}
|
||||
if ($specie) {
|
||||
$images = count($specie->images ?? []) ? $images->merge($specie->images) : $images;
|
||||
}
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$specie = $article->product ?? false;
|
||||
$images = count($specie->images ?? []) ? $specie->images : $images;
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$merchandise = $article->product ?? false;
|
||||
$images = count($merchandise->images ?? []) ? $merchandise->images : $images;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
return $images;
|
||||
}
|
||||
|
||||
public static function getFullImageById($id)
|
||||
{
|
||||
return self::getFullImageByArticle(self::get($id));
|
||||
}
|
||||
|
||||
public static function getFullImageByArticle($article)
|
||||
{
|
||||
$image = $article->image;
|
||||
if ($image) {
|
||||
return $image;
|
||||
}
|
||||
switch ($article->product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$image = $article->product->image ?? ($article->product->specie->image ?? false);
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$image = $article->product->image ?? false;
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$image = $article->product->image ?? false;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
public static function getInheritedImagesByProduct($product_id, $product_type)
|
||||
{
|
||||
switch ($product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$images = Varieties::getImages($product_id);
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$images = Species::getImages($product_id);
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$images = Merchandises::getImages($product_id);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
return $images ?? false ? ['images' => $images] : false;
|
||||
}
|
||||
}
|
||||
65
app/Repositories/Shop/ArticleInherited.php
Normal file
65
app/Repositories/Shop/ArticleInherited.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Article;
|
||||
use App\Repositories\Botanic\Species;
|
||||
use App\Repositories\Botanic\Varieties;
|
||||
|
||||
class ArticleInherited
|
||||
{
|
||||
public static function getInherited($id)
|
||||
{
|
||||
$article = Article::with('product.tags.tag_group')->findOrFail($id);
|
||||
|
||||
return self::getInheritedByProduct($article->product_id, $article->product_type);
|
||||
}
|
||||
|
||||
public static function getInheritedByProduct($product_id, $product_type)
|
||||
{
|
||||
$data = [];
|
||||
switch ($product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$product = Varieties::get($product_id);
|
||||
if (! $product) {
|
||||
break;
|
||||
}
|
||||
$data[] = [
|
||||
'name' => 'Espèces',
|
||||
'description' => Species::getDescription($product->specie_id),
|
||||
'tags' => Species::getTags($product->specie_id),
|
||||
];
|
||||
$data[] = [
|
||||
'name' => 'Variétés',
|
||||
'description' => $product->description,
|
||||
'tags' => $product->tags->toArray(),
|
||||
];
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$product = Species::get($product_id);
|
||||
if (! $product) {
|
||||
break;
|
||||
}
|
||||
$data[] = [
|
||||
'name' => 'Espèces',
|
||||
'description' => $product->description,
|
||||
'tags' => $product->tags->toArray(),
|
||||
];
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$product = Merchandises::get($product_id);
|
||||
if (! $product) {
|
||||
break;
|
||||
}
|
||||
$data[] = [
|
||||
'name' => 'Marchandise',
|
||||
'description' => $product->description,
|
||||
'tags' => $product->tags->toArray(),
|
||||
];
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
return $data ?? false;
|
||||
}
|
||||
}
|
||||
43
app/Repositories/Shop/ArticleSiblings.php
Normal file
43
app/Repositories/Shop/ArticleSiblings.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Article;
|
||||
use App\Models\Shop\Merchandise;
|
||||
use App\Repositories\Botanic\Species;
|
||||
use App\Repositories\Botanic\Varieties;
|
||||
use App\Repositories\Core\Comments;
|
||||
use App\Repositories\Core\Tag;
|
||||
use App\Traits\Model\Basic;
|
||||
use App\Traits\Repository\Imageable;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ArticleSiblings
|
||||
{
|
||||
public static function getSiblingsIDs($id)
|
||||
{
|
||||
return self::getSiblings($id)->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
public static function getSiblingsDescriptions($id)
|
||||
{
|
||||
$data = [];
|
||||
$siblings = self::getSiblings($id);
|
||||
foreach ($siblings as $sibling) {
|
||||
if ($sibling->description && ($sibling->article_nature->name ?? false)) {
|
||||
$data[strtolower($sibling->article_nature->name)] = $sibling->description;
|
||||
}
|
||||
}
|
||||
|
||||
return $data ?? false;
|
||||
}
|
||||
|
||||
public static function getSiblings($id)
|
||||
{
|
||||
return Article::with([
|
||||
'siblings' => function ($query) use ($id) {
|
||||
$query->where('id', '!=', $id);
|
||||
},
|
||||
])->find($id)->siblings;
|
||||
}
|
||||
}
|
||||
67
app/Repositories/Shop/ArticleTags.php
Normal file
67
app/Repositories/Shop/ArticleTags.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Article;
|
||||
use App\Models\Shop\Merchandise;
|
||||
use App\Repositories\Botanic\Species;
|
||||
use App\Repositories\Botanic\Varieties;
|
||||
use App\Repositories\Core\Comments;
|
||||
use App\Repositories\Core\Tag;
|
||||
use App\Traits\Model\Basic;
|
||||
use App\Traits\Repository\Imageable;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ArticleTags
|
||||
{
|
||||
public static function getTagsByArticle($article)
|
||||
{
|
||||
return $article->tags->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
public static function getTagsNameByArticle($article)
|
||||
{
|
||||
return $article->tags->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getTagsSlugByArticle($article)
|
||||
{
|
||||
return $article->tags->pluck('slug', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getFullTagsSlugByArticle($article)
|
||||
{
|
||||
$data = [];
|
||||
|
||||
switch ($article->product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$data += $article->product->tags->toArray();
|
||||
if ($article->product->specie ?? false) {
|
||||
$data += $article->product->specie->tags->toArray();
|
||||
}
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$data += $article->product->tags->toArray();
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$data += $article->product->tags->toArray();
|
||||
$data += $article->product->producer->tags->toArray();
|
||||
break;
|
||||
default:
|
||||
}
|
||||
$data += $article->tags->toArray();
|
||||
|
||||
foreach ($data as $tag) {
|
||||
if (! isset($tags[$tag['group']][$tag['name']])) {
|
||||
$tags[$tag['group']][] = $tag['name'];
|
||||
}
|
||||
}
|
||||
|
||||
return $tags ?? null;
|
||||
}
|
||||
|
||||
public static function storeTags($article, $tags)
|
||||
{
|
||||
return Tag::storeTags($article, $tags);
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ class Articles
|
||||
|
||||
public static function getOffersGroupedByNature($id, $saleChannelId = false)
|
||||
{
|
||||
$articleIds = self::getSiblingsIds($id);
|
||||
$articleIds = ArticleSiblings::getSiblingsIds($id);
|
||||
$articleIds[] = $id;
|
||||
$offers = Offers::getOffersByArticles($articleIds, $saleChannelId);
|
||||
foreach ($offers as $offer) {
|
||||
@@ -43,33 +43,6 @@ class Articles
|
||||
return $data ?? false;
|
||||
}
|
||||
|
||||
public static function getSiblingsIDs($id)
|
||||
{
|
||||
return self::getSiblings($id)->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
public static function getSiblingsDescriptions($id)
|
||||
{
|
||||
$data = [];
|
||||
$siblings = self::getSiblings($id);
|
||||
foreach ($siblings as $sibling) {
|
||||
if ($sibling->description && ($sibling->article_nature->name ?? false)) {
|
||||
$data[strtolower($sibling->article_nature->name)] = $sibling->description;
|
||||
}
|
||||
}
|
||||
|
||||
return $data ?? false;
|
||||
}
|
||||
|
||||
public static function getSiblings($id)
|
||||
{
|
||||
return Article::with([
|
||||
'siblings' => function ($query) use ($id) {
|
||||
$query->where('id', '!=', $id);
|
||||
},
|
||||
])->find($id)->siblings;
|
||||
}
|
||||
|
||||
public static function getOffersById($id)
|
||||
{
|
||||
return Offers::getOffersByArticle($id);
|
||||
@@ -105,13 +78,13 @@ class Articles
|
||||
$article = self::get($id);
|
||||
$data = $article->toArray();
|
||||
$data['description'] = self::getFullDescriptionByArticle($article);
|
||||
$images = self::getFullImagesByArticle($article);
|
||||
$images = ArticleImages::getFullImagesByArticle($article);
|
||||
$data['image'] = self::getPreviewSrc($images[0] ?? false);
|
||||
$data['images'] = count($images) ? $images : false;
|
||||
$data['image_big'] = self::getImageSrc($images[0] ?? false);
|
||||
$data['inherited'] = self::getInherited($id);
|
||||
$data['categories'] = self::getCategoriesNameByArticle($article);
|
||||
$data['tags'] = self::getFullTagsSlugByArticle($article);
|
||||
$data['inherited'] = ArticleInherited::getInherited($id);
|
||||
$data['categories'] = ArticleCategories::getCategoriesNameByArticle($article);
|
||||
$data['tags'] = ArticleTags::getFullTagsSlugByArticle($article);
|
||||
$data['comments'] = Comments::getByModel($article);
|
||||
|
||||
return $data;
|
||||
@@ -140,7 +113,7 @@ class Articles
|
||||
if ($article->description) {
|
||||
$data[strtolower($article->article_nature->name ?? '')] = $article->description;
|
||||
}
|
||||
$siblings = self::getSiblingsDescriptions($article->id);
|
||||
$siblings = ArticleSiblings::getSiblingsDescriptions($article->id);
|
||||
if ($siblings) {
|
||||
array_push($data, $siblings);
|
||||
}
|
||||
@@ -195,7 +168,7 @@ class Articles
|
||||
'id' => $article->id,
|
||||
'article_nature_id' => $article->article_nature_id,
|
||||
'description' => $article->description ? $article->description : $article->product->description,
|
||||
'image' => self::getFullImageByArticle($article),
|
||||
'image' => ArticleImages::getFullImageByArticle($article),
|
||||
'product_type' => $article->product_type,
|
||||
'product_id' => $article->product_id,
|
||||
'product_name' => $article->product->name,
|
||||
@@ -315,87 +288,14 @@ class Articles
|
||||
{
|
||||
$article = self::get($id);
|
||||
$data = $article->toArray();
|
||||
$data['inherited'] = self::getInherited($id);
|
||||
$data['categories'] = self::getCategoriesByArticle($article);
|
||||
$data['tags'] = self::getTagsByArticle($article);
|
||||
$data['inherited'] = ArticleInherited::getInherited($id);
|
||||
$data['categories'] = ArticleCategories::getCategoriesByArticle($article);
|
||||
$data['tags'] = ArticleTags::getTagsByArticle($article);
|
||||
$data['comments'] = Comments::getByModel($article);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getInherited($id)
|
||||
{
|
||||
$article = Article::with('product.tags.tag_group')->findOrFail($id);
|
||||
|
||||
return self::getInheritedByProduct($article->product_id, $article->product_type);
|
||||
}
|
||||
|
||||
public static function getInheritedByProduct($product_id, $product_type)
|
||||
{
|
||||
$data = [];
|
||||
switch ($product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$product = Varieties::get($product_id);
|
||||
if (! $product) {
|
||||
break;
|
||||
}
|
||||
$data[] = [
|
||||
'name' => 'Espèces',
|
||||
'description' => Species::getDescription($product->specie_id),
|
||||
'tags' => Species::getTags($product->specie_id),
|
||||
];
|
||||
$data[] = [
|
||||
'name' => 'Variétés',
|
||||
'description' => $product->description,
|
||||
'tags' => $product->tags->toArray(),
|
||||
];
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$product = Species::get($product_id);
|
||||
if (! $product) {
|
||||
break;
|
||||
}
|
||||
$data[] = [
|
||||
'name' => 'Espèces',
|
||||
'description' => $product->description,
|
||||
'tags' => $product->tags->toArray(),
|
||||
];
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$product = Merchandises::get($product_id);
|
||||
if (! $product) {
|
||||
break;
|
||||
}
|
||||
$data[] = [
|
||||
'name' => 'Marchandise',
|
||||
'description' => $product->description,
|
||||
'tags' => $product->tags->toArray(),
|
||||
];
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
return $data ?? false;
|
||||
}
|
||||
|
||||
public static function getInheritedImagesByProduct($product_id, $product_type)
|
||||
{
|
||||
switch ($product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$images = Varieties::getImages($product_id);
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$images = Species::getImages($product_id);
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$images = Merchandises::getImages($product_id);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
return $images ?? false ? ['images' => $images] : false;
|
||||
}
|
||||
|
||||
public static function getMeta(&$data = [])
|
||||
{
|
||||
switch ($data['article']['product_type'] ?? false) {
|
||||
@@ -424,163 +324,11 @@ class Articles
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getByCategory($category_id)
|
||||
{
|
||||
return Article::byCategory($category_id)->with(['prices', 'product', 'image'])->get();
|
||||
}
|
||||
|
||||
public static function getCategoriesByArticle($article)
|
||||
{
|
||||
return $article->categories->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
public static function getProductTypeByCategory($category_id)
|
||||
{
|
||||
$models = self::getProductTypesModelsByCategory($category_id);
|
||||
|
||||
return ($models[0] ?? false) === Merchandise::class ? 'merchandise' : 'botanic';
|
||||
}
|
||||
|
||||
public static function getProductTypesModelsByCategory($category_id)
|
||||
{
|
||||
return Article::byCategory($category_id)->select('product_type')->distinct()->get();
|
||||
}
|
||||
|
||||
public static function countProductTypesByCategory($category_id)
|
||||
{
|
||||
return Article::byCategory($category_id)->select('product_type')->distinct()->count();
|
||||
}
|
||||
|
||||
public static function getCategoriesNameByArticle($article)
|
||||
{
|
||||
return $article->categories->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getTagsByArticle($article)
|
||||
{
|
||||
return $article->tags->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
public static function getTagsNameByArticle($article)
|
||||
{
|
||||
return $article->tags->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getTagsSlugByArticle($article)
|
||||
{
|
||||
return $article->tags->pluck('slug', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getFullTagsSlugByArticle($article)
|
||||
{
|
||||
$data = [];
|
||||
|
||||
switch ($article->product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$data += $article->product->tags->toArray();
|
||||
if ($article->product->specie ?? false) {
|
||||
$data += $article->product->specie->tags->toArray();
|
||||
}
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$data += $article->product->tags->toArray();
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$data += $article->product->tags->toArray();
|
||||
$data += $article->product->producer->tags->toArray();
|
||||
break;
|
||||
default:
|
||||
}
|
||||
$data += $article->tags->toArray();
|
||||
|
||||
foreach ($data as $tag) {
|
||||
if (! isset($tags[$tag['group']][$tag['name']])) {
|
||||
$tags[$tag['group']][] = $tag['name'];
|
||||
}
|
||||
}
|
||||
|
||||
return $tags ?? null;
|
||||
}
|
||||
|
||||
public static function getPricesByArticle($article)
|
||||
{
|
||||
return Prices::getByArticle($article->id);
|
||||
}
|
||||
|
||||
public static function getFullImagesByArticleId($id)
|
||||
{
|
||||
$article = self::get($id);
|
||||
|
||||
return $article ? self::getFullImagesByArticle($article) : false;
|
||||
}
|
||||
|
||||
public static function countFullImagesByArticleId($id)
|
||||
{
|
||||
$article = self::get($id);
|
||||
|
||||
return $article ? self::countFullImagesByArticle($article) : 0;
|
||||
}
|
||||
|
||||
public static function countFullImagesByArticle($article)
|
||||
{
|
||||
return count(self::getFullImagesByArticle($article));
|
||||
}
|
||||
|
||||
public static function getFullImagesByArticle($article)
|
||||
{
|
||||
$images = count($article->images) ? $article->images : collect([]);
|
||||
switch ($article->product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$variety = $article->product ?? false;
|
||||
$specie = $variety->specie ?? false;
|
||||
if ($variety) {
|
||||
$images = count($variety->images ?? []) ? $images->merge($variety->images) : $images;
|
||||
}
|
||||
if ($specie) {
|
||||
$images = count($specie->images ?? []) ? $images->merge($specie->images) : $images;
|
||||
}
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$specie = $article->product ?? false;
|
||||
$images = count($specie->images ?? []) ? $specie->images : $images;
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$merchandise = $article->product ?? false;
|
||||
$images = count($merchandise->images ?? []) ? $merchandise->images : $images;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
return $images;
|
||||
}
|
||||
|
||||
public static function getFullImageById($id)
|
||||
{
|
||||
return self::getFullImageByArticle(self::get($id));
|
||||
}
|
||||
|
||||
public static function getFullImageByArticle($article)
|
||||
{
|
||||
$image = $article->image;
|
||||
if ($image) {
|
||||
return $image;
|
||||
}
|
||||
switch ($article->product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$image = $article->product->image ?? ($article->product->specie->image ?? false);
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$image = $article->product->image ?? false;
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$image = $article->product->image ?? false;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
public static function storeFull($data)
|
||||
{
|
||||
$images = $data['images'] ?? false;
|
||||
@@ -594,31 +342,12 @@ class Articles
|
||||
|
||||
$article = self::store($data);
|
||||
self::storeImages($article, $images);
|
||||
self::storeCategories($article, $categories);
|
||||
self::storeTags($article, $tags);
|
||||
ArticleCategories::storeCategories($article, $categories);
|
||||
ArticleTags::storeTags($article, $tags);
|
||||
|
||||
return $article->id;
|
||||
}
|
||||
|
||||
public static function storeCategories($article, $categories)
|
||||
{
|
||||
if (! $categories) {
|
||||
return false;
|
||||
}
|
||||
$categories = collect($categories)->transform(
|
||||
function ($item, $key) {
|
||||
return (int) $item;
|
||||
}
|
||||
)->toArray();
|
||||
|
||||
return $article->syncCategories($categories, true);
|
||||
}
|
||||
|
||||
public static function storeTags($article, $tags)
|
||||
{
|
||||
return Tag::storeTags($article, $tags);
|
||||
}
|
||||
|
||||
public static function toggleVisible($id, $visible)
|
||||
{
|
||||
return self::update(['visible' => $visible], $id);
|
||||
|
||||
@@ -107,7 +107,7 @@ class Baskets
|
||||
'quantity' => (int) $item->quantity,
|
||||
'price' => $item->price,
|
||||
'variation' => $offer->variation->name,
|
||||
'image' => Articles::getPreviewSrc(Articles::getFullImageByArticle($offer->article)),
|
||||
'image' => Articles::getPreviewSrc(ArticleImages::getFullImageByArticle($offer->article)),
|
||||
'latin' => $offer->article->product->specie->latin ?? false,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -2,66 +2,41 @@
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Invoice;
|
||||
use Carbon\Carbon;
|
||||
use LaravelDaily\Invoices\Invoice;
|
||||
use LaravelDaily\Invoices\Classes\Party;
|
||||
use LaravelDaily\Invoices\Classes\InvoiceItem;
|
||||
|
||||
class InvoicePDF
|
||||
{
|
||||
public static function getByUUID($uuid)
|
||||
{
|
||||
return self::get(Invoices::getIdByUUID($uuid));
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
$invoice = Invoices::getFull($id);
|
||||
|
||||
$client = new Party([
|
||||
'name' => 'Roosevelt Lloyd',
|
||||
'phone' => '(520) 318-9486',
|
||||
'custom_fields' => [
|
||||
'note' => 'IDDQD',
|
||||
'business id' => '365#GG',
|
||||
],
|
||||
]);
|
||||
|
||||
$customer = new Party([
|
||||
'name' => 'Ashley Medina',
|
||||
'address' => 'The Green Street 12',
|
||||
'code' => '#22663214',
|
||||
'name' => $invoice->customer->name,
|
||||
'address' => self::makeAddress($invoice->address),
|
||||
'custom_fields' => [
|
||||
'order number' => '> 654321 <',
|
||||
'order number' => $invoice->order->ref,
|
||||
],
|
||||
]);
|
||||
|
||||
$items = self::makeItems($order->details);
|
||||
$items = self::makeItems($invoice->order->detail);
|
||||
|
||||
$notes = [
|
||||
'your multiline',
|
||||
'additional notes',
|
||||
'in regards of delivery or something else',
|
||||
];
|
||||
$notes = implode("<br>", $notes);
|
||||
|
||||
$invoice = Invoice::make('receipt')
|
||||
->series('BIG')
|
||||
// ability to include translated invoice status
|
||||
// in case it was paid
|
||||
->status(__('invoices::invoice.paid'))
|
||||
->sequence(667)
|
||||
->serialNumberFormat('{SEQUENCE}/{SERIES}')
|
||||
->seller($client)
|
||||
$invoice = Invoice::make(__('invoices::invoice.invoice') . ' ' .$invoice->ref)
|
||||
->status(Invoices::getStatus($invoice->status))
|
||||
->buyer($customer)
|
||||
->date(now()->subWeeks(3))
|
||||
->dateFormat('m/d/Y')
|
||||
->shipping($invoice->shipping)
|
||||
->date(Carbon::parse($invoice->date_invoice))
|
||||
->payUntilDays(14)
|
||||
->currencySymbol('$')
|
||||
->currencyCode('USD')
|
||||
->currencyFormat('{SYMBOL}{VALUE}')
|
||||
->currencyThousandsSeparator('.')
|
||||
->currencyDecimalPoint(',')
|
||||
->filename($client->name . ' ' . $customer->name)
|
||||
->filename('invoice-' . $invoice->ref . '-' . $invoice->uuid)
|
||||
->addItems($items)
|
||||
->notes($notes)
|
||||
->logo(public_path('vendor/invoices/sample-logo.png'))
|
||||
// You can additionally save generated invoice to configured disk
|
||||
->notes($invoice->comment ?? '')
|
||||
->logo(public_path('img/logo.png'))
|
||||
->save('public');
|
||||
|
||||
$link = $invoice->url();
|
||||
@@ -71,12 +46,20 @@ class InvoicePDF
|
||||
return $invoice->stream();
|
||||
}
|
||||
|
||||
public static function makeAddress($address)
|
||||
{
|
||||
return $address->address . '<br>' . $address->zipcode . ' ' . $address->city;
|
||||
}
|
||||
|
||||
public static function makeItems($details)
|
||||
{
|
||||
$items = [];
|
||||
|
||||
foreach ($details as $detail) {
|
||||
$items[] = InvoiceItem::make($detail->name)->pricePerUnit($detail->price)->quantity($detail->quantity);
|
||||
$items[] = InvoiceItem::make($detail->name)
|
||||
->pricePerUnit($detail->price)
|
||||
->taxByPercent($detail->vat)
|
||||
->quantity($detail->quantity);
|
||||
}
|
||||
|
||||
return $items;
|
||||
|
||||
25
app/Repositories/Shop/OfferStocks.php
Normal file
25
app/Repositories/Shop/OfferStocks.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Offer;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class OfferStocks
|
||||
{
|
||||
public static function decreaseStock($item)
|
||||
{
|
||||
$offer = Offers::get($item['offer_id']);
|
||||
$offer->stock_current = $offer->stock_current - $item['quantity'];
|
||||
if ($offer->stock_current <= 0) {
|
||||
$offer->stock_current = 0;
|
||||
}
|
||||
|
||||
return $offer->save();
|
||||
}
|
||||
|
||||
public static function getStockCurrent($id)
|
||||
{
|
||||
return Offers::getField($id, 'stock_current');
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,22 @@ class Offers
|
||||
];
|
||||
}
|
||||
|
||||
public static function decreaseStock($item)
|
||||
{
|
||||
$offer = self::get($item['offer_id']);
|
||||
$offer->stock_current = $offer->stock_current - $item['quantity'];
|
||||
if ($offer->stock_current <= 0) {
|
||||
$offer->stock_current = 0;
|
||||
}
|
||||
|
||||
return $offer->save();
|
||||
}
|
||||
|
||||
public static function getStockCurrent($id)
|
||||
{
|
||||
return self::getField($id, 'stock_current');
|
||||
}
|
||||
|
||||
public static function getWeight($id, $quantity = 1)
|
||||
{
|
||||
$offer = self::get($id);
|
||||
@@ -58,7 +74,7 @@ class Offers
|
||||
'tariff.price_lists.price_list_values',
|
||||
'variation',
|
||||
])->find($id);
|
||||
$images = Articles::getFullImagesByArticle($offer->article);
|
||||
$images = ArticleImages::getFullImagesByArticle($offer->article);
|
||||
$offer->article->image = Articles::getPreviewSrc($images[0] ?? false);
|
||||
|
||||
return $offer;
|
||||
@@ -111,7 +127,7 @@ class Offers
|
||||
|
||||
public static function getThumbSrc(Offer $offer)
|
||||
{
|
||||
$image = $offer->article ? Articles::getFullImageByArticle($offer->article) : false;
|
||||
$image = $offer->article ? ArticleImages::getFullImageByArticle($offer->article) : false;
|
||||
|
||||
return $image ? Articles::getThumbSrc($image) : false;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,9 @@ class OrderDetails
|
||||
foreach ($data as $item) {
|
||||
$item['order_id'] = $order_id;
|
||||
$detail = self::store($item);
|
||||
if ($detail) {
|
||||
OfferStocks::decreaseStock($item);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user