[WIP] Order process
This commit is contained in:
@@ -173,14 +173,15 @@ class Articles
|
||||
$articles = self::getArticlesWithOffers($options);
|
||||
foreach ($articles as $article) {
|
||||
$price_lists = $article->offers[0]->tariff->price_lists->toArray();
|
||||
if (count($price_lists)) {
|
||||
if (!is_array($data[$article->name] ?? false)) {
|
||||
$data[$article->name] = self::getDataForSale($article);
|
||||
}
|
||||
$prices = $price_lists[0]['price_list_values'][0];
|
||||
$article_nature_name = strtolower($article->article_nature->name);
|
||||
$data[$article->name][$article_nature_name] = self::getDataPriceForSale($article, $prices);
|
||||
if (!count($price_lists)) {
|
||||
continue;
|
||||
}
|
||||
if (!is_array($data[$article->name] ?? false)) {
|
||||
$data[$article->name] = self::getDataForSale($article);
|
||||
}
|
||||
$prices = $price_lists[0]['price_list_values'][0];
|
||||
$article_nature_name = strtolower($article->article_nature->name);
|
||||
$data[$article->name][$article_nature_name] = self::getDataPriceForSale($article, $prices);
|
||||
}
|
||||
if ($data ?? false) {
|
||||
ksort($data);
|
||||
@@ -511,25 +512,26 @@ class Articles
|
||||
public static function getFullImageByArticle($article)
|
||||
{
|
||||
$image = $article->image;
|
||||
if (!$image) {
|
||||
switch ($article->product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$variety = $article->product;
|
||||
$image = $variety->image ?? false;
|
||||
if (!$image) {
|
||||
$specie = $variety->specie;
|
||||
$image = $specie->image ?? false;
|
||||
}
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$specie = $article->product;
|
||||
if ($image) {
|
||||
return $image;
|
||||
}
|
||||
switch ($article->product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$variety = $article->product;
|
||||
$image = $variety->image ?? false;
|
||||
if (!$image) {
|
||||
$specie = $variety->specie;
|
||||
$image = $specie->image ?? false;
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$merchandise = $article->product;
|
||||
$image = $merchandise->image ?? false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$specie = $article->product;
|
||||
$image = $specie->image ?? false;
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$merchandise = $article->product;
|
||||
$image = $merchandise->image ?? false;
|
||||
break;
|
||||
}
|
||||
return $image;
|
||||
}
|
||||
@@ -581,16 +583,15 @@ class Articles
|
||||
|
||||
public static function storeCategories($article, $categories)
|
||||
{
|
||||
if ($categories) {
|
||||
$categories = collect($categories)->transform(
|
||||
function ($item, $key) {
|
||||
return (int) $item;
|
||||
}
|
||||
)->toArray();
|
||||
return $article->syncCategories($categories, true);
|
||||
} else {
|
||||
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)
|
||||
|
||||
@@ -116,15 +116,14 @@ class Categories
|
||||
public static function getImages($id)
|
||||
{
|
||||
$category = self::get($id);
|
||||
if ($category) {
|
||||
$category->getMedia();
|
||||
foreach ($category->media as $key => $media) {
|
||||
$category->media[$key]['url'] = $media->getUrl();
|
||||
}
|
||||
return $category->media;
|
||||
} else {
|
||||
if (!$category) {
|
||||
return false;
|
||||
}
|
||||
$category->getMedia();
|
||||
foreach ($category->media as $key => $media) {
|
||||
$category->media[$key]['url'] = $media->getUrl();
|
||||
}
|
||||
return $category->media;
|
||||
}
|
||||
|
||||
public static function deleteImage($id, $index)
|
||||
|
||||
@@ -3,18 +3,56 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
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 getAvatar()
|
||||
public static function getAvatar($id = false)
|
||||
{
|
||||
|
||||
$customer = $id ? self::get($id) : self::getAuth();
|
||||
$file = self::makeAvatarFilename($customer);
|
||||
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;
|
||||
$avatar = new Avatar();
|
||||
$ret = $avatar->create($name)
|
||||
->setBackground($bgColor)
|
||||
->setBorder(1, '#29292e')
|
||||
->setFontFamily('Roboto Condensed')
|
||||
->setDimension(40)
|
||||
->setFontSize(16)
|
||||
->save($filename);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public static function makeAvatarFilename($customer)
|
||||
{
|
||||
$path = storage_path(self::getStorage());
|
||||
if (File::checkDirOrCreate($path)) {
|
||||
$filename = $path . 'user-' . $customer->uuid . '.png';
|
||||
}
|
||||
return $filename ?? false;
|
||||
}
|
||||
|
||||
public static function getAvatarFilename($customer)
|
||||
{
|
||||
return 'user-' . $customer->uuid . '.png';
|
||||
}
|
||||
|
||||
|
||||
public static function getName()
|
||||
{
|
||||
$user = self::getAuth();
|
||||
@@ -85,16 +123,15 @@ class Customers
|
||||
|
||||
public static function storeDeliveries($customer, $deliveries)
|
||||
{
|
||||
if ($deliveries) {
|
||||
$deliveries = collect($deliveries)->transform(
|
||||
function ($item, $key) {
|
||||
return (int) $item;
|
||||
}
|
||||
)->toArray();
|
||||
return $customer->deliveries()->sync($deliveries);
|
||||
} else {
|
||||
if (!$deliveries) {
|
||||
return false;
|
||||
}
|
||||
$deliveries = collect($deliveries)->transform(
|
||||
function ($item, $key) {
|
||||
return (int) $item;
|
||||
}
|
||||
)->toArray();
|
||||
return $customer->deliveries()->sync($deliveries);
|
||||
}
|
||||
|
||||
public static function storeAddresses($customer, $addresses)
|
||||
@@ -107,6 +144,7 @@ class Customers
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
$data['uuid'] = Str::uuid()->toString();
|
||||
return Customer::create($data);
|
||||
}
|
||||
|
||||
@@ -122,4 +160,16 @@ class Customers
|
||||
{
|
||||
return Customer::destroy($id);
|
||||
}
|
||||
|
||||
public static function getStorage($filename = false)
|
||||
{
|
||||
$path = '/app/public/Customers/';
|
||||
return $filename ? $path . $filename : $path;
|
||||
}
|
||||
|
||||
public static function getPublic($filename = false)
|
||||
{
|
||||
$path = '/storage/Customers/';
|
||||
return $filename ? $path . $filename : $path;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,11 @@ class Deliveries
|
||||
return Delivery::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getAllWithSaleChannel()
|
||||
{
|
||||
return Delivery::orderBy('name', 'asc')->active()->public()->with('sale_channel')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Delivery::find($id);
|
||||
|
||||
@@ -21,13 +21,14 @@ 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']) {
|
||||
$data[$tag['tag_group_id']]['tags'][] = [
|
||||
'id' => $tag['id'],
|
||||
'name' => $tag['name'],
|
||||
'count' => $tag['articles_count'],
|
||||
];
|
||||
}
|
||||
if (!$tag['articles_count']) {
|
||||
continue;
|
||||
}
|
||||
$data[$tag['tag_group_id']]['tags'][] = [
|
||||
'id' => $tag['id'],
|
||||
'name' => $tag['name'],
|
||||
'count' => $tag['articles_count'],
|
||||
];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user