add shipping rules

This commit is contained in:
Ludovic CANDELLIER
2023-07-16 14:45:42 +02:00
parent 297dcc62d2
commit 39c80ce6d1
459 changed files with 6219 additions and 5416 deletions

View File

@@ -2,10 +2,10 @@
namespace App\Repositories\Shop;
use App\Models\Shop\ArticleNature;
use App\Models\Shop\Article;
use App\Models\Botanic\Specie;
use App\Models\Botanic\Variety;
use App\Models\Shop\Article;
use App\Models\Shop\ArticleNature;
use App\Models\Shop\Merchandise;
class ArticleNatures
@@ -18,6 +18,7 @@ class ArticleNatures
public static function getProductType($id)
{
$type = self::get($id)->product_type ?? false;
return $type ? self::getProductTypes()[$type] : false;
}
@@ -40,6 +41,7 @@ class ArticleNatures
case Merchandise::class:
return 2;
}
return false;
}
@@ -61,6 +63,7 @@ class ArticleNatures
public static function getOptionsByProductTypeModel($model)
{
$type = self::getProductTypeByModel($model);
return self::getOptionsByProductType($type);
}
@@ -87,6 +90,7 @@ class ArticleNatures
public static function getNamesByIds($ids)
{
$names = ArticleNature::byIds($ids)->pluck('name')->toArray();
return array_map('strtolower', $names);
}
@@ -98,6 +102,7 @@ class ArticleNatures
public static function store($data)
{
$item = ($data['id'] ?? false) ? self::update($data) : self::create($data);
return $item->id;
}
@@ -111,6 +116,7 @@ class ArticleNatures
$id = $id ? $id : $data['id'];
$item = self::get($id);
$ret = $item->update($data);
return $item;
}

View File

@@ -2,17 +2,14 @@
namespace App\Repositories\Shop;
use Illuminate\Support\Str;
use App\Repositories\Core\Tag;
use App\Repositories\Core\Medias;
use App\Repositories\Core\Comments;
use App\Repositories\Botanic\Species;
use App\Repositories\Botanic\Varieties;
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\Repository\Imageable;
use Illuminate\Support\Str;
class Articles
{
@@ -25,6 +22,7 @@ class Articles
foreach ($data as $key => $name) {
$export[] = ['value' => $key, 'text' => $name];
}
return $export;
}
@@ -40,6 +38,7 @@ class Articles
'prices' => $offer->tariff->price_lists->first()->price_list_values->toArray(),
];
}
return $data ?? false;
}
@@ -56,6 +55,7 @@ class Articles
$data[strtolower($sibling->article_nature->name)] = $sibling->description;
}
}
return $data ?? false;
}
@@ -82,9 +82,10 @@ class Articles
{
$articles = Article::with(['article_nature'])->get();
foreach ($articles as $article) {
$data[$article->id] = ($article->article_nature->name ?? null) . ' - ' . $article->name;
$data[$article->id] = ($article->article_nature->name ?? null).' - '.$article->name;
}
asort($data, SORT_NATURAL);
return $data;
}
@@ -97,6 +98,7 @@ class Articles
{
$data = self::getArticle($id);
$data['offers'] = self::getOffersGroupedByNature($id, $sale_channel_id);
return $data;
}
@@ -113,6 +115,7 @@ class Articles
$data['categories'] = self::getCategoriesNameByArticle($article);
$data['tags'] = self::getFullTagsSlugByArticle($article);
$data['comments'] = Comments::getByModel($article);
return $data;
}
@@ -150,6 +153,7 @@ class Articles
($data['plus'] ?? null);
*/
$data['description'] = $article->description;
return $data;
}
@@ -166,6 +170,7 @@ class Articles
]),
];
}
return $data ?? [];
}
@@ -174,10 +179,10 @@ class Articles
$articles = self::getArticlesWithOffers($options);
foreach ($articles as $article) {
$price_lists = $article->offers[0]->tariff->price_lists->toArray();
if (!count($price_lists)) {
if (! count($price_lists)) {
continue;
}
if (!is_array($data[$article->name] ?? false)) {
if (! is_array($data[$article->name] ?? false)) {
$data[$article->name] = self::getDataForSale($article);
}
$prices = $price_lists[0]['price_list_values'][0];
@@ -187,6 +192,7 @@ class Articles
if ($data ?? false) {
ksort($data);
}
return $data ?? false;
}
@@ -236,6 +242,7 @@ class Articles
'offers.tariff.price_lists.price_list_values',
'offers.variation.package',
])->get();
return $data;
}
@@ -249,6 +256,7 @@ class Articles
$sale_channel_id = $options['sale_channel_id'] ?? SaleChannels::getDefaultID();
$model = self::getModelByOptions($options);
$data = $model->withAvailableOffers($sale_channel_id)->get()->pluck('article_nature_id')->unique();
return array_values($data->toArray());
}
@@ -260,6 +268,7 @@ class Articles
$type = ArticleNatures::getProductTypeNameByClass($class);
$data[$type] = true;
}
return array_keys($data);
}
@@ -268,6 +277,7 @@ class Articles
$sale_channel_id = $options['sale_channel_id'] ?? SaleChannels::getDefaultID();
$model = self::getModelByOptions($options);
$data = $model->withAvailableOffers($sale_channel_id)->get()->pluck('product_type')->unique();
return $data->toArray();
}
@@ -294,6 +304,7 @@ class Articles
$model = $model->merchandise();
break;
}
return $model;
}
@@ -301,6 +312,7 @@ class Articles
{
$data['article'] = self::getArticleEdit($id);
self::getMeta($data);
return $data;
}
@@ -312,12 +324,14 @@ class Articles
$data['categories'] = self::getCategoriesByArticle($article);
$data['tags'] = self::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);
}
@@ -350,10 +364,11 @@ class Articles
$data[] = [
'name' => 'Marchandise',
'description' => $product->description,
'tags' => $product->tags->toArray()
'tags' => $product->tags->toArray(),
];
break;
}
return $data ?? false;
}
@@ -370,6 +385,7 @@ class Articles
$data['images'] = Merchandises::getImages($product_id);
break;
}
return $data ?? false;
}
@@ -398,6 +414,7 @@ class Articles
'App\Models\Botanic\Variety' => 'Variétés',
'App\Models\Shop\Merchandise' => 'Marchandise',
];
return $data;
}
@@ -414,6 +431,7 @@ class Articles
public static function getProductTypeByCategory($category_id)
{
$models = self::getProductTypesModelsByCategory($category_id);
return (($models[0] ?? false) == Merchandise::class) ? 'merchandise' : 'botanic';
}
@@ -470,10 +488,11 @@ class Articles
$data += $article->tags->toArray();
foreach ($data as $tag) {
if (!isset($tags[$tag['group']][$tag['name']])) {
if (! isset($tags[$tag['group']][$tag['name']])) {
$tags[$tag['group']][] = $tag['name'];
}
}
return $tags ?? null;
}
@@ -490,12 +509,14 @@ class Articles
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;
}
@@ -523,6 +544,7 @@ class Articles
$images = count($merchandise->images ?? []) ? $merchandise->images : $images;
break;
}
return $images;
}
@@ -548,6 +570,7 @@ class Articles
$image = $article->product->image ?? false;
break;
}
return $image;
}
@@ -555,26 +578,28 @@ class Articles
{
$images = $data['images'] ?? false;
unset($data['images']);
$categories = $data['categories'] ?? false;
unset($data['categories']);
$tags = $data['tags'] ?? false;
unset($data['tags']);
$prices = $data['prices'] ?? false;
unset($data['prices']);
$article = self::store($data);
self::storeImages($article, $images);
self::storeCategories($article, $categories);
self::storeTags($article, $tags);
return $article->id;
}
public static function store($data)
{
$data['visible'] = $data['visible'] ?? false;
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
}
@@ -588,6 +613,7 @@ class Articles
$id = $id ? $id : $data['id'];
$article = self::get($id);
$ret = $article->update($data);
return $article;
}
@@ -598,7 +624,7 @@ class Articles
public static function storeCategories($article, $categories)
{
if (!$categories) {
if (! $categories) {
return false;
}
$categories = collect($categories)->transform(
@@ -606,6 +632,7 @@ class Articles
return (int) $item;
}
)->toArray();
return $article->syncCategories($categories, true);
}
@@ -632,6 +659,7 @@ class Articles
public static function getHash($id)
{
$name = self::get($id)->name ?? false;
return $name ? hash('crc32c', Str::slug($name)) : false;
}
}

View File

@@ -9,10 +9,11 @@ class Baskets
{
public static function addBasket($offer_id, $quantity = 1, $update = false)
{
if (ShopCart::has($offer_id) && !$quantity) {
if (ShopCart::has($offer_id) && ! $quantity) {
$ret = ShopCart::remove($offer_id);
}
$data = $quantity ? self::getBasketData($offer_id, $quantity) : false;
return $data ? ShopCart::add($data, $update) : false;
}
@@ -28,7 +29,7 @@ class Baskets
$prices = Offers::getPrice($item->id, $item->quantity, $sale_channel_id);
$detail[] = [
'offer_id' => (int) $item->id,
'name' => $offer->article->name . ' (' . $offer->variation->name . ')',
'name' => $offer->article->name.' ('.$offer->variation->name.')',
'quantity' => (int) $item->quantity,
'price' => (float) $prices->price,
'tax' => $prices->price_taxed - $prices->price,
@@ -48,6 +49,7 @@ class Baskets
'shipping' => $shipping,
'total_shipped' => $total_taxed + $shipping,
];
return $data ?? false;
}
@@ -68,7 +70,7 @@ class Baskets
'article.image',
'price_lists.price_list_values',
])->withPriceListsBySaleChannel($sale_channel_id)
->whereIn('id', ShopCart::keys())->get();
->whereIn('id', ShopCart::keys())->get();
foreach ($basket as $item) {
$offer = $offers->where('id', $item->id)->first();
$article_nature = strtolower($offer->article->article_nature->name);
@@ -82,12 +84,14 @@ class Baskets
'latin' => $offer->article->product->specie->latin ?? false,
];
}
return $data ?? false;
}
public static function getBasketData($id, $quantity = 1)
{
$offer = Offers::get($id, ['article', 'variation']);
return [
'id' => $id,
'name' => self::getArticleName($offer),

View File

@@ -3,8 +3,8 @@
namespace App\Repositories\Shop;
use App\Models\Shop\Category;
use App\Repositories\Core\Tag;
use App\Repositories\Core\Categories as CategoryTrees;
use App\Repositories\Core\Tag;
class Categories
{
@@ -13,6 +13,7 @@ class Categories
$category = Articles::get($id)->categories()->first();
$ancestors = self::getAncestorsByCategory($category->id);
$ancestors[] = $category->toArray();
return $ancestors;
}
@@ -21,6 +22,7 @@ class Categories
$category = self::get($id);
$ancestors = $category->getAncestors()->toArray();
unset($ancestors[0]);
return $ancestors;
}
@@ -46,6 +48,7 @@ class Categories
$data['name'] = $category->name;
$data['description'] = $category->description;
$data['tags'] = self::getTagsByCategory($category);
return $data;
}
@@ -81,16 +84,18 @@ class Categories
$tags = $data['tags'] ?? false;
unset($data['tags']);
$category = self::store($data);
self::storeImages($category, $images);
self::storeTags($category, $tags);
return $category;
}
public static function store($data)
{
$id = isset($data['id']) ? $data['id'] : false;
return $id ? self::update($data, $id) : self::create($data);
}
@@ -116,13 +121,14 @@ class Categories
public static function getImages($id)
{
$category = self::get($id);
if (!$category) {
if (! $category) {
return false;
}
$category->getMedia();
foreach ($category->media as $key => $media) {
$category->media[$key]['url'] = $media->getUrl();
}
return $category->media;
}
@@ -131,7 +137,8 @@ class Categories
$category = self::get($id);
$category->getMedia();
$ret = $category->media[$index]->delete();
return "1";
return '1';
}
public static function moveTree($node_id, $target_id, $type)
@@ -149,6 +156,7 @@ class Categories
$id = $id ? (int) $id : $data['id'];
$category = self::get($id);
$ret = $category->update($data);
return $category;
}

View File

@@ -23,7 +23,7 @@ class CustomerAddresses
public static function add($user_id, $data)
{
$name = $data['company'] ? $data['company'] : $data['first_name'] . ' ' . $data['last_name'];
$name = $data['company'] ? $data['company'] : $data['first_name'].' '.$data['last_name'];
if ($data['use_for_delivery'] ?? false) {
return self::store([
'customer_id' => $user_id,
@@ -49,6 +49,7 @@ class CustomerAddresses
{
$id = $data['id'] ?? false;
$item = $id ? self::update($data, $id) : self::create($data);
return $item->id;
}
@@ -62,6 +63,7 @@ class CustomerAddresses
$id = $id ? $id : $data['id'];
$delivery = self::get($id);
$delivery->update($data);
return $delivery;
}

View File

@@ -6,7 +6,7 @@ use Spatie\Stats\BaseStats;
class CustomerStats extends BaseStats
{
public function getName() : string
public function getName(): string
{
return 'customers';
}

View File

@@ -3,14 +3,12 @@
namespace App\Repositories\Shop;
use App\Datatables\Shop\CustomerOrdersDataTable;
use App\Models\Shop\Customer;
use App\Repositories\Core\File;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
use Laravolt\Avatar\Avatar;
use App\Repositories\Core\File;
use App\Models\Shop\Customer;
class Customers
{
public static function count()
@@ -32,6 +30,7 @@ class Customers
'deliveries' => Deliveries::getAll('sale_channel')->toArray(),
'orders' => $orders_datatable->html(),
];
return $data;
}
@@ -39,16 +38,17 @@ class Customers
{
$customer = $id ? self::get($id) : self::getAuth();
$file = self::makeAvatarFilename($customer);
if (!File::checkFile($file)) {
if (! File::checkFile($file)) {
self::createAvatar($customer);
}
return self::getPublic(self::getAvatarFilename($customer));
}
public static function createAvatar($customer)
{
$filename = self::makeAvatarFilename($customer);
$name = $customer->first_name . ' ' . $customer->last_name;
$name = $customer->first_name.' '.$customer->last_name;
$avatar = new Avatar();
$ret = $avatar->create($name)
->setBackground('#F2B90F')
@@ -58,6 +58,7 @@ class Customers
->setDimension(36)
->setFontSize(16)
->save($filename);
return $ret;
}
@@ -65,19 +66,21 @@ class Customers
{
$path = storage_path(self::getStorage());
if (File::checkDirOrCreate($path)) {
$filename = $path . self::getAvatarFilename($customer);
$filename = $path.self::getAvatarFilename($customer);
}
return $filename ?? false;
}
public static function getAvatarFilename($customer)
{
return 'user-' . $customer->uuid . '.png';
return 'user-'.$customer->uuid.'.png';
}
public static function getAddresses($id = false)
{
$customer = self::getWithAddresses($id);
return $customer ? $customer->addresses : false;
}
@@ -89,7 +92,8 @@ class Customers
public static function getName($id = false)
{
$user = $id ? self::get($id) : self::getAuth();
return $user ? $user->first_name . ' ' . $user->last_name : '';
return $user ? $user->first_name.' '.$user->last_name : '';
}
public static function getAuth()
@@ -110,6 +114,7 @@ class Customers
public static function get($id = false, $relations = false)
{
$id = $id ? $id : self::getId();
return $id ? ($relations ? Customer::with($relations)->findOrFail($id) : Customer::findOrFail($id)) : false;
}
@@ -118,6 +123,7 @@ class Customers
$customer = self::get($id, 'addresses');
$data = $customer->toArray();
$data['deliveries'] = $customer->deliveries->pluck('id')->toArray();
return $data;
}
@@ -130,6 +136,7 @@ class Customers
$customer = self::store($data);
self::storeDeliveries($customer, $deliveries);
self::storeAddresses($customer, $addresses);
return $customer->id;
}
@@ -140,7 +147,7 @@ class Customers
public static function storeDeliveries($customer, $deliveries)
{
if (!$deliveries) {
if (! $deliveries) {
return false;
}
$deliveries = collect($deliveries)->transform(
@@ -148,6 +155,7 @@ class Customers
return (int) $item;
}
)->toArray();
return $customer->deliveries()->sync($deliveries);
}
@@ -176,6 +184,7 @@ class Customers
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
return $user;
}
@@ -184,6 +193,7 @@ class Customers
$id = $id ? $id : $data['id'];
$customer = self::get($id);
$customer->update($data);
return $customer;
}
@@ -195,13 +205,15 @@ class Customers
public static function getStorage($filename = false)
{
$path = '/app/public/Customers/';
return $filename ? $path . $filename : $path;
return $filename ? $path.$filename : $path;
}
public static function getPublic($filename = false)
{
$path = '/storage/Customers/';
return $filename ? $path . $filename : $path;
return $filename ? $path.$filename : $path;
}
public static function guard()

View File

@@ -2,11 +2,8 @@
namespace App\Repositories\Shop;
use App\Models\Shop\Homepage;
class Dashboards
{
public static function getStats($start, $end)
{
return [

View File

@@ -14,6 +14,7 @@ class Deliveries
public static function getAll($relations = false)
{
$model = $relations ? Delivery::with($relations) : Delivery::query();
return $model->orderBy('name', 'asc')->get();
}
@@ -31,6 +32,7 @@ class Deliveries
{
$id = $data['id'] ?? false;
$item = $id ? self::update($data, $id) : self::create($data);
return $item->id;
}
@@ -44,6 +46,7 @@ class Deliveries
$id = $id ? $id : $data['id'];
$delivery = self::get($id);
$delivery->update($data);
return $delivery;
}

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Repositories\Shop;
use App\Models\Shop\DeliveryPackage;
class DeliveryPackages
{
public static function getOptions()
{
return DeliveryPackage::pluck('name', 'id');
}
public static function get($id)
{
return DeliveryPackage::find($id);
}
public static function store($data)
{
$item = ($data['id'] ?? false) ? self::update($data) : self::create($data);
return $item->id;
}
public static function create($data)
{
return DeliveryPackage::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 DeliveryPackage::destroy($id);
}
}

View File

@@ -6,13 +6,49 @@ use App\Models\Shop\DeliveryTypeCalculation;
class DeliveryTypeCalculations
{
public static function getByDeliveryType($type_id)
public static function getByDeliveryType($typeId)
{
return DeliveryTypeCalculation::byDeliveryTpe($type_id)->get();
return DeliveryTypeCalculation::byDeliveryTpe($typeId)->get();
}
public static function getPrice($type_id, $weight)
public static function getPrice($typeId, $weight)
{
return DeliveryTypeCalculation::byDeliveryType($type_id)->byWeight($weight)->get();
return DeliveryTypeCalculation::byDeliveryType($typeId)->byWeight($weight)->get();
}
public static function getOptions()
{
return DeliveryTypeCalculation::pluck('name', 'id');
}
public static function get($id)
{
return DeliveryTypeCalculation::find($id);
}
public static function store($data)
{
$item = ($data['id'] ?? false) ? self::update($data) : self::create($data);
return $item->id;
}
public static function create($data)
{
return DeliveryTypeCalculation::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 DeliveryTypeCalculation::destroy($id);
}
}

View File

@@ -10,4 +10,35 @@ class DeliveryTypes
{
return DeliveryType::pluck('name', 'id');
}
public static function get($id)
{
return DeliveryType::find($id);
}
public static function store($data)
{
$item = ($data['id'] ?? false) ? self::update($data) : self::create($data);
return $item->id;
}
public static function create($data)
{
return DeliveryType::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 DeliveryType::destroy($id);
}
}

View File

@@ -6,10 +6,10 @@ use App\Models\Shop\Homepage;
class Homepages
{
public static function getLast()
{
$model = Homepage::latest('id')->first();
return $model ? $model->text : '';
}
@@ -36,6 +36,7 @@ class Homepages
public static function store($data)
{
$item = ($data['id'] ?? false) ? self::update($data) : self::create($data);
return $item->id;
}
@@ -49,6 +50,7 @@ class Homepages
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -2,13 +2,10 @@
namespace App\Repositories\Shop;
use Illuminate\Support\Str;
use App\Models\Shop\InvoicePayment;
class InvoicePayments
{
public static function get($id, $relations = false)
{
return $relations ? InvoicePayment::with($relations)->findOrFail($id) : InvoicePayment::findOrFail($id);
@@ -29,6 +26,7 @@ class InvoicePayments
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -6,7 +6,7 @@ use Spatie\Stats\BaseStats;
class InvoiceStats extends BaseStats
{
public function getName() : string
public function getName(): string
{
return 'invoices';
}

View File

@@ -2,9 +2,9 @@
namespace App\Repositories\Shop;
use Illuminate\Support\Str;
use Carbon\Carbon;
use App\Models\Shop\Invoice;
use Carbon\Carbon;
use Illuminate\Support\Str;
class Invoices
{
@@ -19,6 +19,7 @@ class Invoices
'order' => $order->toArray(),
'customer' => $customer->toArray(),
];
return view('Shop.Invoices.mail', $data)->render();
}
@@ -30,6 +31,7 @@ class Invoices
public static function saveInvoice($order_id, $data)
{
$data['order_id'] = $order_id;
return self::store($data);
}
@@ -46,6 +48,7 @@ class Invoices
public static function countByMonth()
{
$start = Carbon::now()->beginOfMonth();
return Invoice::where('created_at', '>', $start);
}
@@ -59,6 +62,7 @@ class Invoices
InvoiceStats::increase($data['total_taxed']);
$data['uuid'] = Str::uuid()->toString();
$data['ref'] = self::getNewRef();
return Invoice::create($data);
}
@@ -67,6 +71,7 @@ class Invoices
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}
@@ -74,13 +79,15 @@ class Invoices
{
$invoice = self::get($id);
InvoiceStats::decrease($invoice->total_priced);
return Invoice::destroy($id);
}
public static function getNewRef()
{
$ref = date('ym') . '00000';
$ref = date('ym').'00000';
$last_ref = Invoice::orderBy('id', 'desc')->first();
return $last_ref ? $last_ref->ref + 1 : $ref + 1;
}

View File

@@ -2,8 +2,8 @@
namespace App\Repositories\Shop;
use App\Repositories\Core\Tag;
use App\Models\Shop\Merchandise;
use App\Repositories\Core\Tag;
use App\Traits\Repository\Imageable;
class Merchandises
@@ -17,6 +17,7 @@ class Merchandises
foreach ($data as $key => $name) {
$export[] = ['value' => $key, 'text' => $name];
}
return $export;
}
@@ -37,7 +38,7 @@ class Merchandises
public static function getStatuses()
{
return ['Actif','Suspendu','Invisible','Obsolete'];
return ['Actif', 'Suspendu', 'Invisible', 'Obsolete'];
}
public static function getAll()
@@ -53,6 +54,7 @@ class Merchandises
public static function getFull($id)
{
$data = self::get($id)->toArray();
return $data;
}
@@ -65,6 +67,7 @@ class Merchandises
{
$id = isset($data['id']) ? $data['id'] : false;
$item = $id ? self::update($data, $id) : self::create($data);
return $item;
}
@@ -77,6 +80,7 @@ class Merchandises
$merchandise = self::store($data);
self::storeImages($merchandise, $images);
self::storeTags($merchandise, $tags);
return $merchandise;
}
@@ -95,6 +99,7 @@ class Merchandises
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -3,7 +3,6 @@
namespace App\Repositories\Shop;
use App\Models\Shop\Offer;
use App\Repositories\Core\User\ShopCart;
class Offers
{
@@ -29,6 +28,7 @@ class Offers
])->find($id);
$images = Articles::getFullImagesByArticle($offer->article);
$offer->article->image = Articles::getPreviewSrc($images[0] ?? false);
return $offer;
}
@@ -36,6 +36,7 @@ class Offers
{
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
$offer = Offer::withPriceBySaleChannelByQuantity($sale_channel_id, $quantity)->find($id);
return $offer->price_lists->first()->price_list_values->first();
}
@@ -57,6 +58,7 @@ class Offers
public static function getOffersBySaleChannelRaw($sale_channel_id = false)
{
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
return Offer::active()->byStockAvailable()
->with([
'article_nature',
@@ -77,9 +79,10 @@ class Offers
public static function getThumbSrc(Offer $offer)
{
$image = $offer->article ? Articles::getFullImageByArticle($offer->article) : false;
return $image ? Articles::getThumbSrc($image) : false;
}
public static function getLast()
{
return Offer::with(['article.image'])->active()->orderByDesc('updated_at')->get();
@@ -92,6 +95,7 @@ class Offers
$offers1 = self::getByCategory($category_id)->toArray();
$offers2 = self::getByTags($tags)->toArray();
$data = array_merge($offers1, $offers2);
return $data;
}
@@ -130,6 +134,7 @@ class Offers
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -12,6 +12,7 @@ class OrderDetails
$item['order_id'] = $order_id;
$detail = self::store($item);
}
return true;
}
@@ -35,6 +36,7 @@ class OrderDetails
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -6,7 +6,7 @@ use Spatie\Stats\BaseStats;
class OrderStats extends BaseStats
{
public function getName() : string
public function getName(): string
{
return 'orders';
}

View File

@@ -2,15 +2,14 @@
namespace App\Repositories\Shop;
use Carbon\Carbon;
use App\Mail\Acheminement;
use App\Mail\ConfirmationCommande;
use App\Mail\Preparation;
use App\Models\Shop\Order;
use App\Repositories\Core\DateStats;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Carbon\Carbon;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Str;
class Orders
{
@@ -35,6 +34,7 @@ class Orders
unset($data['detail']);
unset($data['payment_type']);
unset($data['sale_channel_id']);
return ($order && $detail) ? Invoices::saveInvoice($order->id, $data) : false;
}
@@ -47,6 +47,7 @@ class Orders
{
$order = self::get($order_id, ['customer', 'address']);
$mail = new ConfirmationCommande($order);
return Mail::to($order->customer->email)->send($mail);
}
@@ -54,6 +55,7 @@ class Orders
{
$order = self::get($order_id, ['customer', 'address']);
$mail = new Preparation($order);
return Mail::to($order->customer->email)->send($mail);
}
@@ -61,6 +63,7 @@ class Orders
{
$order = self::get($order_id, ['customer', 'address']);
$mail = new Acheminement($order);
return Mail::to($order->customer->email)->send($mail);
}
@@ -73,6 +76,7 @@ class Orders
{
$start = Carbon::now()->subHours(24);
$end = Carbon::now();
return Order::preparation()->byPeriod($start, $end, 'updated_at')->count();
}
@@ -80,12 +84,14 @@ class Orders
{
$start = Carbon::now()->subHours(48);
$end = Carbon::now();
return Order::preparation()->byPeriod($start, $end, 'updated_at')->count();
}
public static function countInPreparationMore48H()
{
$start = Carbon::now()->subHours(48);
return Order::preparation()->where('updated_at', '>', $start)->count();
}
@@ -120,6 +126,7 @@ class Orders
OrderStats::increase();
$data['uuid'] = Str::uuid()->toString();
$data['ref'] = self::getNewRef();
return Order::create($data);
}
@@ -128,6 +135,7 @@ class Orders
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}
@@ -150,6 +158,7 @@ class Orders
public static function getStatusByName($name)
{
$data = array_flip(self::statuses());
return $data[$name] ?? '';
}
@@ -170,8 +179,9 @@ class Orders
public static function getNewRef()
{
$ref = date('ym') . '00000';
$ref = date('ym').'00000';
$last_ref = Order::orderBy('id', 'desc')->first();
return $last_ref ? $last_ref->ref + 1 : $ref + 1;
}

View File

@@ -6,7 +6,6 @@ use App\Models\Shop\Package;
class Packages
{
public static function getOptions()
{
return Package::orderBy('value', 'asc')->pluck('value', 'id')->toArray();
@@ -31,6 +30,7 @@ class Packages
{
$id = isset($data['id']) ? $data['id'] : false;
$item = $id ? self::update($data) : self::create($data);
return $item->id;
}
@@ -44,6 +44,7 @@ class Packages
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -3,14 +3,12 @@
namespace App\Repositories\Shop;
use App;
use Devpark\PayboxGateway\Requests\AuthorizationWithCapture;
use Devpark\PayboxGateway\Responses\Verify;
use Devpark\PayboxGateway\Requests\Capture;
use Devpark\PayboxGateway\Responses\Verify;
class Paybox
{
public static function makeAuthorizationRequest($amount, $customer_email = 'test@example.com')
{
$authorizationRequest = App::make(AuthorizationWithCapture::class);
@@ -26,11 +24,10 @@ class Paybox
try {
$success = $payboxVerify->isSuccess($invoice->total_shipped);
if ($success) {
// process order here after making sure it was real payment
// process order here after making sure it was real payment
}
echo "OK";
}
catch (InvalidSignature $e) {
echo 'OK';
} catch (InvalidSignature $e) {
Log::alert('Invalid payment signature detected');
}
}
@@ -44,10 +41,9 @@ class Paybox
->setPayboxTransactionNumber($payment->transaction_number)
->setDayRequestNumber(2)
->send();
if ($response->isSuccess()) {
// process order here
// process order here
}
}
}

View File

@@ -2,20 +2,16 @@
namespace App\Repositories\Shop;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use App\Models\Shop\PriceListValue;
use App\Models\Shop\PriceList;
use App\Models\Shop\Offer;
use App\Models\Shop\PriceListValue;
class PriceListValues
{
public static function getPriceByOffer($offer_id, $quantity = 1, $sale_channel_id = false)
{
$prices = self::getPricesByOffer($offer_id, $sale_channel_id);
$price = $prices ? $prices->where('quantity', '<=', $quantity)->sortByDesc('quantity')->first() : false;
return $price ? $price->price_taxed : false;
}
@@ -26,6 +22,7 @@ class PriceListValues
$sale_channel_id ? $query->bySaleChannel($sale_channel_id) : $query;
},
])->find($offer_id)->price_lists->first();
return $price_list ? $price_list->price_list_values : false;
}
@@ -58,6 +55,7 @@ class PriceListValues
{
$id = isset($data['id']) ? $data['id'] : false;
$price = $id ? self::update($data) : self::create($data);
return $price;
}
@@ -71,6 +69,7 @@ class PriceListValues
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -2,15 +2,10 @@
namespace App\Repositories\Shop;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use App\Models\Shop\PriceList;
class PriceLists
{
public static function getByOfferAndSaleChannel($offer_id, $sale_channel_id)
{
return PriceList::bySaleChannel($sale_channel_id)->byOffer($offer_id)->get();
@@ -28,7 +23,7 @@ class PriceLists
public static function getStatuses()
{
return ['Actif','Suspendu','Invisible','Obsolete'];
return ['Actif', 'Suspendu', 'Invisible', 'Obsolete'];
}
public static function getByTariff($id)
@@ -53,6 +48,7 @@ class PriceLists
if ($n <= 3) {
$price_list['price_list_values'] += array_fill($n, 3 - $n, '');
}
return $price_list;
}
@@ -78,6 +74,7 @@ class PriceLists
unset($data['price_list_values']);
$price_list = $id ? self::update($data) : self::create($data);
PriceListValues::storePrices($price_list->id, $price_list_values);
return $price_list;
}
@@ -91,6 +88,7 @@ class PriceLists
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -2,14 +2,8 @@
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\Article;
use App\Models\Shop\Price;
use Yajra\DataTables\DataTables;
class Prices
{
@@ -17,12 +11,14 @@ class Prices
{
$data['prices'] = Price::byArticle($id)->notGeneric()->get()->toArray();
$data['generics'] = Price::byArticle($id)->generic()->with(['generic.prices', 'generic.category'])->get()->toArray();
return $data;
}
public static function getDatatable()
{
$model = Price::orderBy('name');
return Datatables::of($model)->make(true);
}
@@ -40,6 +36,7 @@ class Prices
{
$id = isset($data['id']) ? $data['id'] : false;
$item = $id ? self::update($data) : self::create($data);
return $item->id;
}
@@ -53,6 +50,7 @@ class Prices
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -2,8 +2,8 @@
namespace App\Repositories\Shop;
use App\Repositories\Core\Tag;
use App\Models\Shop\Producer;
use App\Repositories\Core\Tag;
use App\Traits\Repository\Imageable;
class Producers
@@ -17,6 +17,7 @@ class Producers
foreach ($data as $key => $name) {
$export[] = ['value' => $key, 'text' => $name];
}
return $export;
}
@@ -50,6 +51,7 @@ class Producers
$producer = self::get($id);
$data = $producer->toArray();
$data['tags'] = self::getTagsByProducer($producer);
return $data;
}
@@ -67,6 +69,7 @@ class Producers
$producer = self::store($data);
self::storeImages($producer, $images);
self::storeTags($producer, $tags);
return $producer;
}
@@ -85,6 +88,7 @@ class Producers
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -9,6 +9,7 @@ class SaleChannels
public static function getDefaultID()
{
$default = self::getDefault();
return $default ? self::getDefault()->id : false;
}
@@ -41,6 +42,7 @@ class SaleChannels
{
$id = isset($data['id']) ? $data['id'] : false;
$item = $id ? self::update($data) : self::create($data);
return $item->id;
}
@@ -54,6 +56,7 @@ class SaleChannels
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -2,8 +2,6 @@
namespace App\Repositories\Shop;
use App\Models\Shop\Article;
class Searches
{
public static function getResults($options)

View File

@@ -2,14 +2,12 @@
namespace App\Repositories\Shop;
use Illuminate\Support\Str;
use App\Models\Shop\TagGroup;
use App\Models\Shop\Tag;
use App\Models\Shop\TagGroup;
use Illuminate\Support\Str;
class TagGroups
{
public static function getOptions()
{
return TagGroup::get()->SortBy('name')->pluck('name', 'id')->toArray();
@@ -21,7 +19,7 @@ class TagGroups
$tag_groups = TagGroup::pluck('name', 'id')->toArray();
foreach ($tags as $tag) {
$data[$tag['tag_group_id']]['name'] = $tag_groups[$tag['tag_group_id']];
if (!$tag['articles_count']) {
if (! $tag['articles_count']) {
continue;
}
$data[$tag['tag_group_id']]['tags'][] = [
@@ -30,6 +28,7 @@ class TagGroups
'count' => $tag['articles_count'],
];
}
return $data;
}
@@ -40,13 +39,14 @@ class TagGroups
foreach ($items as $group) {
$group_tags = [];
foreach ($group->tags as $tag) {
$group_tags[$tag->id] = $group->name . ' - ' . $tag->name;
$group_tags[$tag->id] = $group->name.' - '.$tag->name;
}
$tags[] = [
'label' => $group->name,
'options' => $group_tags,
'label' => $group->name,
'options' => $group_tags,
];
}
return $tags;
}
@@ -73,12 +73,14 @@ class TagGroups
public static function store($data)
{
$item = ($data['id'] ?? false) ? self::update($data) : self::create($data);
return $item->id;
}
public static function create($data)
{
$data['slug'] = Str::slug($data['name']);
return TagGroup::create($data);
}
@@ -91,6 +93,7 @@ class TagGroups
}
$model->update($data);
Tags::updateGroup($id, $data['name']);
return $model;
}

View File

@@ -2,15 +2,14 @@
namespace App\Repositories\Shop;
use Illuminate\Support\Str;
use App\Models\Shop\Tag;
use Illuminate\Support\Str;
class Tags
{
public static function getTagHtml($tag)
{
return '<span class="btn btn-xs btn-secondary pb-2 mr-2 mb-2">' . self::getFullnameByTag($tag) . '</span>';
return '<span class="btn btn-xs btn-secondary pb-2 mr-2 mb-2">'.self::getFullnameByTag($tag).'</span>';
}
public static function getOptions()
@@ -32,8 +31,9 @@ class Tags
{
$tags = Tag::with('tag_group')->get()->toArray();
foreach ($tags as $tag) {
$data[$tag['id']] = $tag['tag_group']['name'] . '-' . $tag['name'];
$data[$tag['id']] = $tag['tag_group']['name'].'-'.$tag['name'];
}
return $data;
}
@@ -45,12 +45,13 @@ class Tags
public static function getFullname($id)
{
$tag = Tag::with('tag_group')->find($id);
return $tag ? self::getFullnameByTag($tag) : false;
}
public static function getFullnameByTag($tag)
{
return $tag->tag_group->name . '-' . $tag->name;
return $tag->tag_group->name.'-'.$tag->name;
}
public static function get($id)
@@ -61,6 +62,7 @@ class Tags
public static function store($data)
{
$item = ($data['id'] ?? false) ? self::update($data) : self::create($data);
return $item->id;
}
@@ -70,10 +72,10 @@ class Tags
$data['group'] = TagGroups::getName($data['tag_group_id']);
$data['sort_order'] = self::getNewOrder($data['tag_group_id']);
$tag = Tag::create($data);
return $tag;
}
public static function update($data, $id = false)
{
$id = $id ? $id : $data['id'];
@@ -81,6 +83,7 @@ class Tags
$data['slug'] = self::buildSlug($data);
$data['group'] = TagGroups::getName($data['tag_group_id']);
$tag->update($data);
return $tag;
}
@@ -102,6 +105,7 @@ class Tags
public static function getNewOrder($tag_group_id)
{
$tag = Tag::byGroup($tag_group_id)->orderBy('sort_order', 'desc')->first();
return $tag ? (int) $tag->sort_order + 1 : 1;
}
}

View File

@@ -25,6 +25,7 @@ class TariffUnities
{
$id = isset($data['id']) ? $data['id'] : false;
$item = $id ? self::update($data, $id) : self::create($data);
return $item->id;
}
@@ -38,6 +39,7 @@ class TariffUnities
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -13,6 +13,7 @@ class Tariffs
foreach ($data as $key => $name) {
$export[] = ['value' => $key, 'text' => $name];
}
return $export;
}
@@ -55,6 +56,7 @@ class Tariffs
{
$id = isset($data['id']) ? $data['id'] : false;
$item = $id ? self::update($data, $id) : self::create($data);
return $item->id;
}
@@ -68,6 +70,7 @@ class Tariffs
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -2,17 +2,10 @@
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\Tax;
class Taxes
{
public static function getOptions()
{
return Tax::orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
@@ -32,6 +25,7 @@ class Taxes
{
$id = isset($data['id']) ? $data['id'] : false;
$item = $id ? self::update($data) : self::create($data);
return $item->id;
}
@@ -45,6 +39,7 @@ class Taxes
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -2,8 +2,6 @@
namespace App\Repositories\Shop\Traits;
use App\Repositories\Shop\Customers;
use App\Repositories\Core\DateTime;
use Illuminate\Mail\Mailables\Address;
use Illuminate\Mail\Mailables\Envelope;

View File

@@ -35,6 +35,7 @@ class Unities
{
$id = isset($data['id']) ? $data['id'] : false;
$item = $id ? self::update($data, $id) : self::create($data);
return $item->id;
}
@@ -48,6 +49,7 @@ class Unities
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -2,9 +2,8 @@
namespace App\Repositories\Shop;
use Illuminate\Support\Str;
use App\Models\Shop\Variation;
use Illuminate\Support\Str;
class Variations
{
@@ -15,6 +14,7 @@ class Variations
foreach ($data as $key => $name) {
$export[] = ['value' => $key, 'text' => $name];
}
return $export;
}
@@ -25,6 +25,7 @@ class Variations
$data[$variation->id] = self::getName($variation);
}
natsort($data);
return $data;
}
@@ -35,12 +36,12 @@ class Variations
public static function getName($variation)
{
return $variation->package->value . ' ' . $variation->quantity . ' ' . ($variation->unity->value ?? null) . ' ' . Str::limit(strip_tags($variation->description), 15, ' (...)');
return $variation->package->value.' '.$variation->quantity.' '.($variation->unity->value ?? null).' '.Str::limit(strip_tags($variation->description), 15, ' (...)');
}
public static function buildName($data)
{
return Packages::getName($data['package_id']) . ' ' . $data['quantity'] . ' ' . Unities::getName($data['unity_id']);
return Packages::getName($data['package_id']).' '.$data['quantity'].' '.Unities::getName($data['unity_id']);
}
public static function getAll()
@@ -62,12 +63,14 @@ class Variations
{
$id = isset($data['id']) ? $data['id'] : false;
$item = $id ? self::update($data) : self::create($data);
return $item->id;
}
public static function create($data)
{
$data['name'] = self::buildName($data);
return Variation::create($data);
}
@@ -77,6 +80,7 @@ class Variations
$variation = self::get($id);
$data['name'] = self::buildName($data);
$variation->update($data);
return $variation;
}