Add variations, slider, fix cart ...
This commit is contained in:
50
app/Console/Commands/untranslateShelves.php
Normal file
50
app/Console/Commands/untranslateShelves.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\Shop\Category;
|
||||
|
||||
class untranslateShelves extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'untranslateShelves';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Migrations of shelves';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$categories = Category::all();
|
||||
foreach ($categories as $category) {
|
||||
$trans = json_decode($category->name, true);
|
||||
$name = $trans['fr'];
|
||||
$trans = $category->description ? json_decode($category->description, true) : false;
|
||||
$description = $trans ? $trans['fr'] : '';
|
||||
$category->update(['name' => $name, 'description' => $description]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ class CategoriesDataTable extends DataTable
|
||||
|
||||
public function query(Category $model)
|
||||
{
|
||||
$model = $model::with(['tags.articles'])->withCount(['articles', 'tags']);
|
||||
$model = $model::notRoot()->with(['tags.articles'])->withCount(['articles', 'tags']);
|
||||
return $this->buildQuery($model);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,11 +59,11 @@ class OffersDataTable extends DataTable
|
||||
{
|
||||
return [
|
||||
Column::make('status_id')->title('')->width(40),
|
||||
Column::make('article.article_nature.name')->title('Nature'),
|
||||
Column::make('thumb')->title('')->width(40)->searchable(false),
|
||||
Column::make('article.name')->title('Article'),
|
||||
Column::make('variation.name')->title('Déclinaison'),
|
||||
Column::make('tariff.name')->title('Tarif'),
|
||||
Column::make('article.article_nature.name')->title('Nature')->defaultContent(''),
|
||||
Column::make('thumb')->title('')->width(40)->searchable(false)->order(false),
|
||||
Column::make('article.name')->title('Article')->defaultContent(''),
|
||||
Column::make('variation.name')->title('Déclinaison')->defaultContent(''),
|
||||
Column::make('tariff.name')->title('Tarif')->defaultContent(''),
|
||||
Column::make('stock_current')->title('Appro im')->searchable(false),
|
||||
Column::make('stock_delayed')->title('Appro délai')->searchable(false),
|
||||
Column::make('stock_ondemand')->title('Dmde')->searchable(false),
|
||||
|
||||
@@ -14,6 +14,8 @@ class ArticleController extends Controller
|
||||
{
|
||||
$data = self::init();
|
||||
$data['article'] = Articles::getArticleToSell($id);
|
||||
// dump($data);
|
||||
// exit;
|
||||
return view('Shop.Articles.show', $data);
|
||||
}
|
||||
}
|
||||
|
||||
70
app/Http/Controllers/Shop/BasketController.php
Normal file
70
app/Http/Controllers/Shop/BasketController.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Shop;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
use App\Repositories\Core\User\ShopCart;
|
||||
use App\Repositories\Shop\Offers;
|
||||
|
||||
class BasketController extends Controller
|
||||
{
|
||||
|
||||
public function getPrice(Request $request)
|
||||
{
|
||||
$offer_id = $request->input('offer_id');
|
||||
$quantity = $request->input('quantity');
|
||||
$price = Offers::getPrice($offer_id, $quantity)->price_taxed;
|
||||
return $quantity * $price;
|
||||
}
|
||||
|
||||
public function addBasket(Request $request)
|
||||
{
|
||||
$offer_id = $request->input('offer_id');
|
||||
$quantity = $request->input('quantity');
|
||||
|
||||
if (ShopCart::has($offer_id)) {
|
||||
$ret = ShopCart::remove($offer_id);
|
||||
}
|
||||
$data = Offers::getBasketData($offer_id, $quantity);
|
||||
$ret = ShopCart::add($data);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function basket()
|
||||
{
|
||||
$data['basket'] = Offers::getBasket();
|
||||
dump($data['basket']->toArray());
|
||||
exit;
|
||||
return view('Shop.Baskets.basket', $data);
|
||||
}
|
||||
|
||||
public function getBasket()
|
||||
{
|
||||
$data = ShopCart::getContent();
|
||||
return response()->json(['data' => $data, 'code' => '200']);
|
||||
}
|
||||
|
||||
public function countBasket()
|
||||
{
|
||||
return ShopCart::count();
|
||||
}
|
||||
|
||||
public function order(Request $request)
|
||||
{
|
||||
ShopCart::clear();
|
||||
$data = $request->all();
|
||||
unset($data['_token']);
|
||||
$data['user_id'] = Users::getId();
|
||||
Orders::newOrder($data);
|
||||
return response()->json(['code' => '200']);
|
||||
|
||||
// return redirect()->route('ThirdParty.select');
|
||||
}
|
||||
|
||||
public function clearBasket()
|
||||
{
|
||||
return ShopCart::clear();
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,9 @@ class HomeController extends Controller
|
||||
$input = $request->input();
|
||||
$data = self::init();
|
||||
$data['display_by_rows'] = $input['by_rows'] ?? false;
|
||||
$data['articles'] = Articles::getArticlesToSell();
|
||||
$data['shelves'] = Articles::getArticlesByHomepage();
|
||||
// dump($data['shelves']);
|
||||
// exit;
|
||||
$data['tags'] = TagGroups::getWithTagsAndCountOffers();
|
||||
return view('Shop.home', $data);
|
||||
}
|
||||
|
||||
@@ -24,12 +24,13 @@ class Category extends parentCategory
|
||||
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'categories';
|
||||
public $translatable = ['name', 'description'];
|
||||
public $translatable = [];
|
||||
protected $cascadeDeleteMorph = ['Articles'];
|
||||
protected $fillable = [
|
||||
'visible',
|
||||
'homepage',
|
||||
'slug',
|
||||
'name',
|
||||
'visible',
|
||||
'description',
|
||||
NestedSet::LFT,
|
||||
NestedSet::RGT,
|
||||
@@ -61,4 +62,14 @@ class Category extends parentCategory
|
||||
{
|
||||
return $query->where('visible', 1);
|
||||
}
|
||||
|
||||
public function scopeHomepage($query)
|
||||
{
|
||||
return $query->where('homepage', 1);
|
||||
}
|
||||
|
||||
public function scopeNotRoot($query)
|
||||
{
|
||||
return $query->where('id', '<>', 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,4 +150,35 @@ class Offer extends Model
|
||||
$query->active()->bySaleChannel($sale_channel_id);
|
||||
});
|
||||
}
|
||||
|
||||
public function scopeWithPriceListsBySaleChannel($query, $sale_channel_id)
|
||||
{
|
||||
return $query->with([
|
||||
'price_lists' => function($query) use ($sale_channel_id) {
|
||||
$query->bySaleChannel($sale_channel_id);
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
public function scopeWithPriceListValuesBySaleChannel($query, $sale_channel_id)
|
||||
{
|
||||
return $query->with([
|
||||
'price_lists' => function($query) use ($sale_channel_id) {
|
||||
$query->bySaleChannel($sale_channel_id);
|
||||
},
|
||||
'price_lists.price_list_values',
|
||||
]);
|
||||
}
|
||||
|
||||
public function scopeWithPriceBySaleChannelByQuantity($query, $sale_channel_id, $quantity = 1)
|
||||
{
|
||||
return $query->with([
|
||||
'price_lists' => function($query) use ($sale_channel_id) {
|
||||
$query->bySaleChannel($sale_channel_id);
|
||||
},
|
||||
'price_lists.price_list_values' => function($query) use ($quantity) {
|
||||
$query->byQuantity($quantity);
|
||||
},
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ class Categories
|
||||
{
|
||||
$categories = self::getCategoryTreeVisibles()->toArray();
|
||||
return $categories ? self::getChildren($categories[0]['children'], $withFolder) : [];
|
||||
return $categories ? self::getChildren($categories[0]['children'], $withFolder) : [];
|
||||
}
|
||||
|
||||
public static function getTree($withFolder = false)
|
||||
@@ -111,7 +110,7 @@ class Categories
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
// return Category::class;
|
||||
return app('rinvex.categories.category');
|
||||
return app(Category::class);
|
||||
// return app('rinvex.categories.category');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Repositories\Core\User;
|
||||
|
||||
use App\Repositories\Core\Auth\Users;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use \Cart;
|
||||
|
||||
class ShopCart
|
||||
@@ -19,9 +20,8 @@ class ShopCart
|
||||
|
||||
public static function clear()
|
||||
{
|
||||
Cart::session(1)->clear();
|
||||
return Cart::clear();
|
||||
// return self::get()->clear();
|
||||
Cart::clear();
|
||||
return Cart::session(Auth::id())->clear();
|
||||
}
|
||||
|
||||
public static function has($id)
|
||||
|
||||
@@ -16,11 +16,11 @@ class ShopCartStorage
|
||||
|
||||
public function get($key)
|
||||
{
|
||||
if ($this->has($key)) {
|
||||
return new CartCollection(CartStorage::find($key)->cart_data);
|
||||
} else {
|
||||
if (!$this->has($key)) {
|
||||
return [];
|
||||
}
|
||||
return new CartCollection(CartStorage::find($key)->cart_data);
|
||||
|
||||
}
|
||||
|
||||
public function put($key, $value)
|
||||
|
||||
@@ -32,7 +32,8 @@ class Articles
|
||||
$article_ids = self::getSiblingsIds($id);
|
||||
$offers = Offers::getOffersByArticles($article_ids, $sale_channel_id);
|
||||
foreach ($offers as $offer) {
|
||||
$data[strtolower($offer->article_nature->name)] = [
|
||||
$data[strtolower($offer->article_nature->name)][] = [
|
||||
'id' => $offer->id,
|
||||
'name' => $offer->variation->name,
|
||||
'prices' => $offer->tariff->price_lists->first()->price_list_values->toArray(),
|
||||
];
|
||||
@@ -77,7 +78,6 @@ class Articles
|
||||
|
||||
public static function getArticleToSell($id, $sale_channel_id = false)
|
||||
{
|
||||
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
|
||||
$article = self::get($id);
|
||||
$data = $article->toArray();
|
||||
$parents = self::getInheritedByProduct($article->product_id, $article->product_type);
|
||||
@@ -126,6 +126,19 @@ class Articles
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getArticlesByHomepage()
|
||||
{
|
||||
$shelves = Categories::getByHomepage();
|
||||
foreach ($shelves as $shelve) {
|
||||
$data[] = [
|
||||
'id' => $shelve->id,
|
||||
'name' => $shelve->name,
|
||||
'articles' => self::getArticlesToSell($shelve->id),
|
||||
];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getArticlesToSell($category_id = false, $tags = false)
|
||||
{
|
||||
$articles = self::getArticlesWithOffers($category_id, $tags);
|
||||
@@ -135,6 +148,7 @@ class Articles
|
||||
if (count($price_lists)) {
|
||||
if (!is_array($data[$article->name] ?? false)) {
|
||||
$data[$article->name] = [
|
||||
'id' => $article->id,
|
||||
'description' => (!empty($article->description)) ? $article->description : $article->product->description,
|
||||
'image' => self::getFullImageByArticle($article),
|
||||
'product_type' => $article->product_type,
|
||||
|
||||
@@ -8,6 +8,12 @@ use App\Repositories\Core\Categories as CategoryTrees;
|
||||
|
||||
class Categories
|
||||
{
|
||||
|
||||
public static function getByHomepage()
|
||||
{
|
||||
return Category::homepage()->orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Category::orderBy('name', 'asc')->get();
|
||||
|
||||
@@ -3,9 +3,40 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Offer;
|
||||
use App\Repositories\Core\User\ShopCart;
|
||||
|
||||
class Offers
|
||||
{
|
||||
|
||||
public static function getPrice($id, $quantity = 1, $sale_channel_id = false)
|
||||
{
|
||||
$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();
|
||||
}
|
||||
|
||||
public static function getBasket()
|
||||
{
|
||||
$basket = ShopCart::getContent();
|
||||
$offers = Offer::with(['variation', 'article.article_nature'])->whereIn('id', ShopCart::keys())->get();
|
||||
dump($basket->toArray());
|
||||
dump($offers->toArray());
|
||||
exit;
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getBasketData($id, $quantity = 1)
|
||||
{
|
||||
$offer = Offer::with(['article'])->findOrFail($id);
|
||||
return [
|
||||
'id' => $id,
|
||||
'name' => $offer->article->name,
|
||||
'price' => self::getPrice($id, $quantity)->price_taxed,
|
||||
'quantity' => $quantity,
|
||||
'attributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public static function getOffersByArticles($articles_ids, $sale_channel_id = false)
|
||||
{
|
||||
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
|
||||
@@ -13,7 +44,7 @@ class Offers
|
||||
->with([
|
||||
'article_nature',
|
||||
'variation',
|
||||
'tariff.price_lists' => function($query) use ($sale_channel_id) {
|
||||
'tariff.price_lists' => function ($query) use ($sale_channel_id) {
|
||||
$query->bySaleChannel($sale_channel_id);
|
||||
},
|
||||
'tariff.price_lists.price_list_values',
|
||||
@@ -30,7 +61,7 @@ class Offers
|
||||
->with([
|
||||
'article_nature',
|
||||
'variation',
|
||||
'tariff.price_lists' => function($query) use ($sale_channel_id) {
|
||||
'tariff.price_lists' => function ($query) use ($sale_channel_id) {
|
||||
$query->bySaleChannel($sale_channel_id);
|
||||
},
|
||||
'tariff.price_lists.price_list_values',
|
||||
|
||||
Reference in New Issue
Block a user