[WIP] Order process
This commit is contained in:
@@ -44,7 +44,9 @@ class Cities
|
||||
// dump($adresse);
|
||||
$geocode = app('geocoder')->geocode($adresse)->get();
|
||||
// dump($geocode);
|
||||
if (count($geocode)) {
|
||||
if (!count($geocode)) {
|
||||
return false;
|
||||
}
|
||||
// dump($geocode);
|
||||
$res = $geocode[0]->getCoordinates()->toArray();
|
||||
// dump($res);
|
||||
@@ -53,9 +55,7 @@ class Cities
|
||||
// dump($latitude);
|
||||
// dump($longitude);
|
||||
return ['latitude' => $latitude, 'longitude' => $longitude];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function getCoordsByCity($id)
|
||||
|
||||
@@ -133,7 +133,8 @@ class Debug
|
||||
dump($msg);
|
||||
}
|
||||
|
||||
if (self::isDebug()) {
|
||||
if (!self::isDebug()){
|
||||
return;}
|
||||
if (static::isCLI()) {
|
||||
self::dumpCli($msg, $cat);
|
||||
}
|
||||
@@ -143,7 +144,7 @@ class Debug
|
||||
if (static::isClockwork()) {
|
||||
self::dumpClockwork($msg, $cat);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function dumpDebugbar($msg, $cat = '', $force = false)
|
||||
|
||||
@@ -75,12 +75,16 @@ class Export
|
||||
if (isset($options[$key])) {
|
||||
$txt = $options[$key][$txt];
|
||||
}
|
||||
if (isset($multioptions[$key])) {
|
||||
if (!isset($multioptions[$key])){
|
||||
$this->writeCell($this->lig, $col, $txt);
|
||||
$this->nb++;
|
||||
$col++;
|
||||
continue;}
|
||||
$tabs = self::getReverseMultiOptions($txt);
|
||||
foreach ($tabs as $key2 => $value) {
|
||||
$txt .= $multioptions[$key][$key2] . '\n';
|
||||
}
|
||||
}
|
||||
|
||||
$this->writeCell($this->lig, $col, $txt);
|
||||
$this->nb++;
|
||||
$col++;
|
||||
@@ -114,7 +118,8 @@ class Export
|
||||
|
||||
public function close()
|
||||
{
|
||||
if (!$this->debug) {
|
||||
if ($this->debug){
|
||||
return;}
|
||||
// Debug::message($this->xls);
|
||||
$objWriter = PHPExcel_IOFactory::createWriter($this->xls, 'Excel2007');
|
||||
// Debug::message($objWriter);
|
||||
@@ -126,7 +131,7 @@ class Export
|
||||
// $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
|
||||
$objWriter->save('text.xlsx');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function conv($lig, $col)
|
||||
|
||||
@@ -16,7 +16,6 @@ class File
|
||||
|
||||
public static function checkDir($dir)
|
||||
{
|
||||
// File::isDirectory($path)
|
||||
return is_dir($dir);
|
||||
}
|
||||
|
||||
@@ -27,8 +26,7 @@ class File
|
||||
|
||||
public static function createDir($dir)
|
||||
{
|
||||
Storage::makeDirectory($dir);
|
||||
return true;
|
||||
return mkdir($dir, '0777', true);
|
||||
}
|
||||
|
||||
public static function deleteDir($dir)
|
||||
|
||||
@@ -6,12 +6,15 @@ class Geolocation
|
||||
{
|
||||
public static function getCoords($address, $zipcode, $city)
|
||||
{
|
||||
if (!empty($address) && !empty($zipcode) && !empty($city)) {
|
||||
if (!(!empty($address) && !empty($zipcode) && !empty($city))){
|
||||
return;}
|
||||
$address = $address . ' , ' . $city . ' ' . $zipcode . ' , ' . 'France';
|
||||
|
||||
$geocode = app('geocoder')->geocode($address)->get();
|
||||
|
||||
if (count($geocode)) {
|
||||
if (!count($geocode)) {
|
||||
return false;
|
||||
}
|
||||
$res = $geocode[0]->getCoordinates()->toArray();
|
||||
// dump($res);
|
||||
$longitude = $res[0];
|
||||
@@ -20,11 +23,8 @@ class Geolocation
|
||||
// dump($longitude);
|
||||
// exit;
|
||||
return ['latitude' => $latitude, 'longitude' => $longitude];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static function autocomplete($query)
|
||||
{
|
||||
|
||||
@@ -50,7 +50,8 @@ class Item extends LavaryMenuItem
|
||||
|
||||
foreach ($routes as $pattern) {
|
||||
$arr = [$pattern];
|
||||
if (if_route_pattern($arr)) {
|
||||
if (!if_route_pattern($arr)){
|
||||
continue;}
|
||||
$this->activate();
|
||||
|
||||
if (strstr($this->title, 'circle-o')) {
|
||||
@@ -59,7 +60,6 @@ class Item extends LavaryMenuItem
|
||||
// dump($this);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ class Menu extends LavaryMenu
|
||||
{
|
||||
public function make($name, $callback)
|
||||
{
|
||||
if (is_callable($callback)) {
|
||||
if (!is_callable($callback)){
|
||||
return;}
|
||||
if (!array_key_exists($name, $this->menu)) {
|
||||
$this->menu[$name] = new Builder($name, $this->loadConf($name));
|
||||
}
|
||||
@@ -25,5 +26,4 @@ class Menu extends LavaryMenu
|
||||
|
||||
return $this->menu[$name];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,15 +13,12 @@ class ShopCart
|
||||
if (self::has($item['id'])) {
|
||||
if ($update) {
|
||||
self::remove($item['id']);
|
||||
$ret = self::get()->add($item);
|
||||
// $ret = self::get()->update($item['id'], ['quantity' => $item['quantity']]);
|
||||
self::get()->add($item);
|
||||
} else {
|
||||
$ret = self::get()->update($item['id'], ['quantity' => $item['quantity']]);
|
||||
// self::remove($item['id']);
|
||||
// $ret = self::get()->add($item);
|
||||
self::get()->update($item['id'], ['quantity' => $item['quantity']]);
|
||||
}
|
||||
} else {
|
||||
$ret = self::get()->add($item);
|
||||
self::get()->add($item);
|
||||
}
|
||||
return [
|
||||
'count' => self::count(),
|
||||
@@ -73,7 +70,12 @@ class ShopCart
|
||||
|
||||
public static function getTotal()
|
||||
{
|
||||
return number_format(round(self::get()->getTotal(),2),2);
|
||||
return self::fixDecimal(self::get()->getTotal());
|
||||
}
|
||||
|
||||
public static function fixDecimal($number)
|
||||
{
|
||||
return number_format(round($number, 2), 2);
|
||||
}
|
||||
|
||||
public static function getItemQuantity($id)
|
||||
|
||||
@@ -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