better management of shipping and basket summary display
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Admin\Shop;
|
||||
|
||||
use App\Datatables\Shop\PriceListsDataTable;
|
||||
use App\Datatables\Admin\Shop\PriceListsDataTable;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Repositories\Shop\PriceLists;
|
||||
use App\Repositories\Shop\SaleChannels;
|
||||
@@ -14,45 +14,20 @@ class PriceListController extends Controller
|
||||
{
|
||||
public function index(PriceListsDataTable $dataTable)
|
||||
{
|
||||
$data = [];
|
||||
|
||||
return $dataTable->render('Admin.Shop.PriceLists.list', $data);
|
||||
return $dataTable->render('Admin.Shop.PriceLists.list');
|
||||
}
|
||||
|
||||
public function create()
|
||||
public function modalCreate($tariffId)
|
||||
{
|
||||
$data = [];
|
||||
$data['sale_channels'] = SaleChannels::getOptions();
|
||||
|
||||
return view('Admin.Shop.PriceLists.create', $data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$data['price_list'] = PriceLists::get($id);
|
||||
$data['sale_channels'] = SaleChannels::getOptions();
|
||||
|
||||
return view('Admin.Shop.PriceLists.edit', $data);
|
||||
}
|
||||
|
||||
public function modalCreate($tariff_id)
|
||||
{
|
||||
$data = [];
|
||||
$data['price_list']['tariff_id'] = $tariff_id;
|
||||
$data['price_list']['price_list_values'] = array_fill(0, 3, '');
|
||||
$data['sale_channels'] = SaleChannels::getOptions();
|
||||
$data['statuses'] = Tariffs::getStatuses();
|
||||
$data['taxes'] = Taxes::getOptions();
|
||||
$data = PriceLists::init($tariffId);
|
||||
|
||||
return view('Admin.Shop.PriceLists.modal', $data);
|
||||
}
|
||||
|
||||
public function modalEdit($id)
|
||||
{
|
||||
$data = PriceLists::init();
|
||||
$data['price_list'] = PriceLists::edit($id);
|
||||
$data['sale_channels'] = SaleChannels::getOptions();
|
||||
$data['statuses'] = Tariffs::getStatuses();
|
||||
$data['taxes'] = Taxes::getOptions();
|
||||
|
||||
return view('Admin.Shop.PriceLists.modal', $data);
|
||||
}
|
||||
|
||||
@@ -25,32 +25,22 @@ class TariffController extends Controller
|
||||
|
||||
public function create()
|
||||
{
|
||||
$data['sale_channels'] = SaleChannels::getOptions();
|
||||
$data['statuses'] = Tariffs::getStatuses();
|
||||
$data['tariff_unities'] = TariffUnities::getOptions();
|
||||
|
||||
$model = new PriceListsDataTable();
|
||||
$data['datatables']['price_lists'] = $model->html();
|
||||
$data = Tariffs::init();
|
||||
|
||||
return view('Admin.Shop.Tariffs.create', $data);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$data['tariff'] = Tariffs::getFull($id);
|
||||
$data['tariff'] = Tariffs::getArray($id);
|
||||
|
||||
return view('Admin.Shop.Tariffs.view', $data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$data = Tariffs::init();
|
||||
$data['tariff'] = Tariffs::get($id);
|
||||
$data['sale_channels'] = SaleChannels::getOptions();
|
||||
$data['statuses'] = Tariffs::getStatuses();
|
||||
$data['tariff_unities'] = TariffUnities::getOptions();
|
||||
|
||||
$model = new PriceListsDataTable();
|
||||
$data['datatables']['price_lists'] = $model->html();
|
||||
|
||||
return view('Admin.Shop.Tariffs.edit', $data);
|
||||
}
|
||||
|
||||
@@ -5,8 +5,7 @@ namespace App\Http\Controllers\Shop;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Repositories\Core\User\ShopCart;
|
||||
use App\Repositories\Shop\Baskets;
|
||||
use App\Repositories\Shop\Deliveries;
|
||||
use App\Repositories\Shop\DeliveryTypes;
|
||||
use App\Repositories\Shop\Customers;
|
||||
use App\Repositories\Shop\Offers;
|
||||
use App\Repositories\Shop\Orders;
|
||||
use App\Repositories\Users;
|
||||
|
||||
@@ -69,4 +69,9 @@ class Customer extends Authenticatable
|
||||
{
|
||||
$this->notify(new ResetPassword($token));
|
||||
}
|
||||
|
||||
public function getNameAttribute()
|
||||
{
|
||||
return $this->getAttribute('first_name').' '.$this->getAttribute('last_name');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,19 +6,19 @@ use App\Repositories\Core\User\ShopCart;
|
||||
|
||||
class Baskets
|
||||
{
|
||||
public static function addBasket($offer_id, $quantity = 1, $update = false)
|
||||
public static function addBasket($offerId, $quantity = 1, $update = false)
|
||||
{
|
||||
if (ShopCart::has($offer_id) && ! $quantity) {
|
||||
$ret = ShopCart::remove($offer_id);
|
||||
if (ShopCart::has($offerId) && ! $quantity) {
|
||||
$ret = ShopCart::remove($offerId);
|
||||
}
|
||||
$data = $quantity ? self::getBasketData($offer_id, $quantity) : false;
|
||||
$data = $quantity ? self::getBasketData($offerId, $quantity) : false;
|
||||
|
||||
return $data ? ShopCart::add($data, $update) : false;
|
||||
}
|
||||
|
||||
public static function getBasketTotal($deliveryId = false, $deliveryTypeId = false)
|
||||
{
|
||||
$saleChannelId = $deliveryId ? Deliveries::getField($deliveryId, 'sale_channel_id') : SaleChannels::getDefaultID();
|
||||
$saleChannelId = Deliveries::getSaleChannelId($deliveryId);
|
||||
|
||||
return self::getBasketSummary($saleChannelId, $deliveryTypeId);
|
||||
}
|
||||
@@ -36,8 +36,8 @@ class Baskets
|
||||
$prices = Offers::getPrice($item->id, $item->quantity, $saleChannelId);
|
||||
$weight = $offer->weight * $item->quantity;
|
||||
$detail[] = self::getRowDetail($item, $offer, $prices, $weight);
|
||||
$total += self::getTotal($item->quantity, $prices->price);
|
||||
$totalTaxed += self::getTotal($item->quantity, $prices->price_taxed);
|
||||
$total += $prices ? self::getTotal($item->quantity, $prices->price) : false;
|
||||
$totalTaxed += $prices ? self::getTotal($item->quantity, $prices->price_taxed) : false;
|
||||
$totalWeight += $weight;
|
||||
}
|
||||
$shipping = DeliveryTypeCalculations::getPriceByDeliveryType($deliveryTypeId, $totalWeight);
|
||||
@@ -52,6 +52,7 @@ class Baskets
|
||||
'count' => ShopCart::count(),
|
||||
'quantity' => ShopCart::getTotalQuantity(),
|
||||
'weight' => $totalWeight,
|
||||
'sale_channel' => SaleChannels::getArray($saleChannelId),
|
||||
];
|
||||
|
||||
return $data ?? false;
|
||||
@@ -63,12 +64,12 @@ class Baskets
|
||||
'offer_id' => (int) $item->id,
|
||||
'name' => $offer->article->name.' ('.$offer->variation->name.')',
|
||||
'quantity' => (int) $item->quantity,
|
||||
'price' => (float) $prices->price,
|
||||
'tax' => $prices->price_taxed - $prices->price,
|
||||
'price_taxed' => (float) $prices->price_taxed,
|
||||
'total' => self::getTotal($item->quantity, $prices->price),
|
||||
'total_tax' => self::getTotal($item->quantity, $prices->price_taxed - $prices->price),
|
||||
'total_taxed' => self::getTotal($item->quantity, $prices->price_taxed),
|
||||
'price' => $prices ? (float) $prices->price : false,
|
||||
'tax' => $prices ? $prices->price_taxed - $prices->price : false,
|
||||
'price_taxed' => $prices ? (float) $prices->price_taxed : false,
|
||||
'total' => $prices ? self::getTotal($item->quantity, $prices->price) : false,
|
||||
'total_tax' => $prices ? self::getTotal($item->quantity, $prices->price_taxed - $prices->price) : false,
|
||||
'total_taxed' => $prices ? self::getTotal($item->quantity, $prices->price_taxed) : false,
|
||||
'weight' => $weight,
|
||||
];
|
||||
}
|
||||
@@ -110,6 +111,7 @@ class Baskets
|
||||
'latin' => $offer->article->product->specie->latin ?? false,
|
||||
];
|
||||
}
|
||||
$data['sale_channel'] = Customers::getSaleChannel();
|
||||
|
||||
return $data ?? false;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,18 @@ class Customers
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public static function getSaleChannel()
|
||||
{
|
||||
return SaleChannels::getDefault();
|
||||
}
|
||||
|
||||
public static function getDeliveries()
|
||||
{
|
||||
$customer = self::getAuth();
|
||||
|
||||
return $customer ? $customer->deliveries : Deliveries::getDefault();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Customer::pluck('last_name', 'id');
|
||||
@@ -23,13 +35,13 @@ class Customers
|
||||
{
|
||||
$id = $id ? $id : self::getId();
|
||||
$datatableOrders = new CustomerOrdersDataTable();
|
||||
$data = [
|
||||
|
||||
return [
|
||||
'customer' => self::get($id, ['addresses', 'deliveries'])->toArray(),
|
||||
'deliveries' => Deliveries::getAllWithSaleChannel()->toArray(),
|
||||
'orders' => $datatableOrders->html(),
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getAvatar($id = false)
|
||||
@@ -48,7 +60,8 @@ class Customers
|
||||
$filename = self::makeAvatarFilename($customer);
|
||||
$name = $customer->first_name.' '.$customer->last_name;
|
||||
$avatar = new Avatar();
|
||||
$ret = $avatar->create($name)
|
||||
|
||||
return $avatar->create($name)
|
||||
->setBackground('#F2B90F')
|
||||
->setForeground('#335012')
|
||||
->setBorder(1, '#28a745')
|
||||
@@ -56,8 +69,6 @@ class Customers
|
||||
->setDimension(36)
|
||||
->setFontSize(16)
|
||||
->save($filename);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public static function makeAvatarFilename($customer)
|
||||
@@ -93,7 +104,7 @@ class Customers
|
||||
{
|
||||
$user = $id ? self::get($id) : self::getAuth();
|
||||
|
||||
return $user ? $user->first_name.' '.$user->last_name : '';
|
||||
return $user ? $user->name : '';
|
||||
}
|
||||
|
||||
public static function getAuth()
|
||||
@@ -162,7 +173,7 @@ class Customers
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
$user = Customer::create([
|
||||
return Customer::create([
|
||||
'uuid' => Str::uuid(),
|
||||
'active' => true,
|
||||
'first_name' => $data['first_name'],
|
||||
@@ -177,8 +188,6 @@ class Customers
|
||||
'email' => $data['email'],
|
||||
'password' => bcrypt($data['password']),
|
||||
]);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
public static function getStorage($filename = false)
|
||||
|
||||
@@ -9,6 +9,16 @@ class Deliveries
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public static function getSaleChannelId($deliveryId)
|
||||
{
|
||||
return $deliveryId ? Deliveries::getField($deliveryId, 'sale_channel_id') : SaleChannels::getDefaultID();
|
||||
}
|
||||
|
||||
public static function getDefault()
|
||||
{
|
||||
return Delivery::active()->atHouse()->first();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Delivery::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
|
||||
@@ -3,9 +3,12 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Homepage;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class Homepages
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public static function getLast()
|
||||
{
|
||||
$model = Homepage::latest('id')->first();
|
||||
@@ -28,34 +31,8 @@ class Homepages
|
||||
return self::get(3)->text ?? '';
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
public static function getModel()
|
||||
{
|
||||
return Homepage::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 Homepage::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 Homepage::destroy($id);
|
||||
return Homepage::query();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ class InvoicePayments
|
||||
'CB',
|
||||
'CHEQUE',
|
||||
'VIREMENT',
|
||||
'PRELEVEMENT',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Offer;
|
||||
use App\Models\Shop\PriceList;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class Offers
|
||||
@@ -36,7 +37,7 @@ class Offers
|
||||
return Offer::with([
|
||||
'variation',
|
||||
'article.article_nature',
|
||||
'article.product.Specie',
|
||||
'article.product',
|
||||
'article.image',
|
||||
'price_lists.price_list_values',
|
||||
])->withPriceListsBySaleChannel($saleChannelId)->byIds($ids)->get();
|
||||
@@ -67,8 +68,9 @@ class Offers
|
||||
{
|
||||
$saleChannelId = $saleChannelId ? $saleChannelId : SaleChannels::getDefaultID();
|
||||
$offer = Offer::withPriceBySaleChannelByQuantity($saleChannelId, $quantity)->find($id);
|
||||
$priceList = $offer->price_lists->first();
|
||||
|
||||
return $offer->price_lists->first()->price_list_values->first();
|
||||
return $priceList ? $priceList->price_list_values->first() : false;
|
||||
}
|
||||
|
||||
public static function getOffersByArticles($article_ids, $saleChannelId = false)
|
||||
|
||||
@@ -3,9 +3,12 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\OrderDetail;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class OrderDetails
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public static function saveBasket($order_id, $data)
|
||||
{
|
||||
foreach ($data as $item) {
|
||||
@@ -16,32 +19,8 @@ class OrderDetails
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function get($id, $relations = false)
|
||||
public static function getModel()
|
||||
{
|
||||
return $relations ? OrderDetail::with($relations)->findOrFail($id) : OrderDetail::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return OrderDetail::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 delete($id)
|
||||
{
|
||||
return OrderDetail::destroy($id);
|
||||
return OrderDetail::query();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,12 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Package;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class Packages
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Package::orderBy('value', 'asc')->pluck('value', 'id')->toArray();
|
||||
@@ -21,35 +24,8 @@ class Packages
|
||||
return self::get($id)->value;
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
public static function getModel()
|
||||
{
|
||||
return Package::find($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Package::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 Package::destroy($id);
|
||||
return Package::query();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,12 @@ namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Offer;
|
||||
use App\Models\Shop\PriceListValue;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class PriceListValues
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public static function getPriceByOffer($offer_id, $quantity = 1, $sale_channel_id = false)
|
||||
{
|
||||
$prices = self::getPricesByOffer($offer_id, $sale_channel_id);
|
||||
@@ -31,16 +34,6 @@ class PriceListValues
|
||||
return PriceListValue::byPriceList($id)->get();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return PriceListValue::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return PriceListValue::find($id);
|
||||
}
|
||||
|
||||
public static function storePrices($price_list_id, $values)
|
||||
{
|
||||
foreach ($values as $value) {
|
||||
@@ -51,30 +44,8 @@ class PriceListValues
|
||||
}
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
public static function getModel()
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$price = $id ? self::update($data) : self::create($data);
|
||||
|
||||
return $price;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return PriceListValue::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 PriceListValue::destroy($id);
|
||||
return PriceListValue::query();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,25 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\PriceList;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class PriceLists
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public static function init($tariffId = false)
|
||||
{
|
||||
return [
|
||||
'sale_channels' => SaleChannels::getOptions(),
|
||||
'statuses' => Tariffs::getStatuses(),
|
||||
'taxes' => Taxes::getOptions(),
|
||||
'price_list' => [
|
||||
'tariff_id' => $tariffId,
|
||||
'price_list_values' => array_fill(0, 3, ''),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public static function getByOfferAndSaleChannel($offer_id, $sale_channel_id)
|
||||
{
|
||||
return PriceList::bySaleChannel($sale_channel_id)->byOffer($offer_id)->get();
|
||||
@@ -31,15 +47,6 @@ class PriceLists
|
||||
return PriceList::byTariff($id)->get();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return PriceList::pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return PriceList::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function edit($id)
|
||||
{
|
||||
@@ -52,11 +59,6 @@ class PriceLists
|
||||
return $price_list;
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return PriceList::find($id);
|
||||
}
|
||||
|
||||
public static function getPrices($id)
|
||||
{
|
||||
return PriceList::with('price_list_values')->find($id);
|
||||
@@ -78,22 +80,8 @@ class PriceLists
|
||||
return $price_list;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
public static function getModel()
|
||||
{
|
||||
return PriceList::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 PriceList::destroy($id);
|
||||
return PriceList::query();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,12 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\SaleChannel;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class SaleChannels
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public static function getDefaultID()
|
||||
{
|
||||
$default = self::getDefault();
|
||||
@@ -23,45 +26,8 @@ class SaleChannels
|
||||
return SaleChannel::byCode($code)->first();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
public static function getModel()
|
||||
{
|
||||
return SaleChannel::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return SaleChannel::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return SaleChannel::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return SaleChannel::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 SaleChannel::destroy($id);
|
||||
return SaleChannel::query();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,27 @@
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Datatables\Admin\Shop\PriceListsDataTable;
|
||||
use App\Models\Shop\Tariff;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class Tariffs
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public static function init()
|
||||
{
|
||||
$model = new PriceListsDataTable();
|
||||
|
||||
return [
|
||||
'sale_channels' => SaleChannels::getOptions(),
|
||||
'statuses' => Tariffs::getStatuses(),
|
||||
'tariff_unities' => TariffUnities::getOptions(),
|
||||
'datatables' => [
|
||||
'price_lists' => $model->html(),
|
||||
],
|
||||
];
|
||||
}
|
||||
public static function autocomplete($str)
|
||||
{
|
||||
$data = Tariff::byAutocomplete($str)->orderBy('name')->limit(30)->get()->pluck('name', 'id');
|
||||
@@ -27,11 +44,6 @@ class Tariffs
|
||||
return Tariff::with(['price_lists.price_list_values', 'price_lists.sale_channel'])->find($id);
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Tariff::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getStatus($status_id)
|
||||
{
|
||||
return self::getStatuses()[$status_id];
|
||||
@@ -42,40 +54,8 @@ class Tariffs
|
||||
return ['Actif', 'Suspendu', 'Invisible', 'Obsolete'];
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
public static function getModel()
|
||||
{
|
||||
return Tariff::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Tariff::find($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Tariff::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 Tariff::destroy($id);
|
||||
return Tariff::query();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
@include('components.form.select', [
|
||||
@include('components.form.select', [
|
||||
'label' => 'Règlement',
|
||||
'name' => 'payment_type',
|
||||
'list' => $payment_types ?? [],
|
||||
|
||||
@@ -1,54 +1,54 @@
|
||||
@component('components.card', [
|
||||
'id_card' => $model . '-basket',
|
||||
'id_card' => $model . '-basket',
|
||||
'title' => $title,
|
||||
'class' => 'mb-3 addBasket ' . ($bgClass ?? null),
|
||||
'classTitle' => 'mb-0',
|
||||
'outline' => false,
|
||||
'class' => 'mb-3 addBasket ' . ($bgClass ?? null),
|
||||
'classTitle' => 'mb-0',
|
||||
'outline' => false,
|
||||
])
|
||||
@include('components.form.select', [
|
||||
'name' => 'offer_id',
|
||||
'id_name' => $model . '-offer_id',
|
||||
'list' => collect($data)->pluck('name', 'id')->toArray(),
|
||||
'class' => 'select2 mb-2 offer_id',
|
||||
])
|
||||
|
||||
@include('components.form.select', [
|
||||
'name' => 'offer_id',
|
||||
'id_name' => $model . '-offer_id',
|
||||
'list' => collect($data)->pluck('name', 'id')->toArray(),
|
||||
'class' => 'select2 mb-2 offer_id',
|
||||
])
|
||||
|
||||
<div class="row">
|
||||
<div class="col-5">
|
||||
@include('components.form.inputs.number', [
|
||||
'name' => 'quantity',
|
||||
'class' => 'quantity',
|
||||
'id_name' => $model . '-quantity',
|
||||
'value' => 1,
|
||||
])
|
||||
</div>
|
||||
<div class="col-7 text-right">
|
||||
<span id="{{ $model }}-price" style="font-size:2em; font-weight: 600;">
|
||||
{{ $data[0]['prices'][0]['price_taxed'] }}
|
||||
</span>
|
||||
€ TTC
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
@include('components.form.button', [
|
||||
'metadata' => 'data-type=' . $model,
|
||||
'class' => 'btn-success basket w-100 ' . $model,
|
||||
'txt' => 'Ajouter au panier',
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-5">
|
||||
@include('components.form.inputs.number', [
|
||||
'name' => 'quantity',
|
||||
'class' => 'quantity',
|
||||
'id_name' => $model . '-quantity',
|
||||
'value' => (int) $data[0]['prices'][0]['quantity'],
|
||||
'min' => $data[0]['prices'][0]['quantity'],
|
||||
'step' => 1,
|
||||
])
|
||||
</div>
|
||||
<div class="col-7 text-right">
|
||||
<span id="{{ $model }}-price" style="font-size:2em; font-weight: 600;">
|
||||
{{ $data[0]['prices'][0]['price_taxed'] }}
|
||||
</span>
|
||||
€ TTC
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
@include('components.form.button', [
|
||||
'metadata' => 'data-type=' . $model,
|
||||
'class' => 'btn-success basket w-100 ' . $model,
|
||||
'txt' => 'Ajouter au panier',
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
@endcomponent
|
||||
|
||||
@push('js')
|
||||
<script>
|
||||
$('#{{ $model }}-quantity').change(function() {
|
||||
setPrice('{{ $model }}');
|
||||
});
|
||||
$('#{{ $model }}-offer_id').change(function() {
|
||||
setPrice('{{ $model }}');
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
$('#{{ $model }}-quantity').change(function() {
|
||||
setPrice('{{ $model }}');
|
||||
});
|
||||
$('#{{ $model }}-offer_id').change(function() {
|
||||
setPrice('{{ $model }}');
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
|
||||
@@ -1,121 +1,126 @@
|
||||
@extends('Shop.layout.layout', [
|
||||
'title' => __('Panier'),
|
||||
'title' => __('Panier'),
|
||||
])
|
||||
|
||||
@section('content')
|
||||
@if ($basket)
|
||||
<div class="row">
|
||||
<div class="col-lg-8 col-md-12">
|
||||
<div class="row mb-3">
|
||||
<div class="col-4">
|
||||
<h1>Panier</h1>
|
||||
</div>
|
||||
<div class="col-8">
|
||||
Livraison à domicile ...<br>
|
||||
Commande en ligne et livraison par voie postale. Attention certains produits ne sont pas disponibles en livraison.
|
||||
Les sachets disponibles en lignes sont disponibles à la livraison et uniquement quelques plants.
|
||||
</div>
|
||||
</div>
|
||||
@foreach ($basket as $nature => $items)
|
||||
<div class="row ml-1 mb-3 p-2 bg-green-light border rounded-lg">
|
||||
<div class="col-12">
|
||||
<h2 style="font-size: 1.6em;" class="text-uppercase">{{ $nature }}</h2>
|
||||
@foreach ($items as $item)
|
||||
@include('Shop.Baskets.partials.article')
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<div class="col-lg-4 col-md-12">
|
||||
<x-card class='shadow'>
|
||||
@include('Shop.Baskets.partials.basketTotal')
|
||||
<div class="row m-3">
|
||||
<div class="col-12 text-center">
|
||||
<a href="{{ route('Shop.Orders.order') }}" class="btn btn-green-dark">COMMANDER</a>
|
||||
</div>
|
||||
</div>
|
||||
</x-card>
|
||||
</div>
|
||||
</div>
|
||||
@else
|
||||
<div class="row">
|
||||
<div class="col-8">
|
||||
<h1>Panier</h1>
|
||||
Votre panier est vide
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
@if ($basket)
|
||||
<div class="row">
|
||||
<div class="col-lg-8 col-md-12">
|
||||
<div class="row mb-3">
|
||||
<div class="col-4">
|
||||
<h1>Panier</h1>
|
||||
</div>
|
||||
<div class="col-8">
|
||||
Livraison à domicile ...<br>
|
||||
Commande en ligne et livraison par voie postale. Attention certains produits ne sont pas disponibles
|
||||
en livraison.
|
||||
Les sachets disponibles en lignes sont disponibles à la livraison et uniquement quelques plants.
|
||||
</div>
|
||||
</div>
|
||||
@foreach ($basket as $nature => $items)
|
||||
<div class="row ml-1 mb-3 p-2 bg-green-light border rounded-lg">
|
||||
<div class="col-12">
|
||||
<h2 style="font-size: 1.6em;" class="text-uppercase">{{ $nature }}</h2>
|
||||
@foreach ($items as $item)
|
||||
@include('Shop.Baskets.partials.article')
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<div class="col-lg-4 col-md-12">
|
||||
<x-card class='shadow'>
|
||||
@include('Shop.Baskets.partials.basketTotal')
|
||||
<div class="row m-3">
|
||||
<div class="col-12 text-center">
|
||||
<a href="{{ route('Shop.Orders.order') }}" class="btn btn-green-dark">COMMANDER</a>
|
||||
</div>
|
||||
</div>
|
||||
</x-card>
|
||||
</div>
|
||||
</div>
|
||||
@else
|
||||
<div class="row">
|
||||
<div class="col-8">
|
||||
<h1>Panier</h1>
|
||||
Votre panier est vide
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
@endsection
|
||||
|
||||
@push('js')
|
||||
<script>
|
||||
function handleBasket() {
|
||||
calculateTotal();
|
||||
<script>
|
||||
function handleBasket() {
|
||||
calculateTotal();
|
||||
|
||||
$('.basket-quantity').change(function() {
|
||||
var offer_id = $(this).data('id');
|
||||
var quantity = $(this).val();
|
||||
var $row = $(this).closest('.row');
|
||||
updateBasket(offer_id, quantity, function() {
|
||||
calculatePrice($row);
|
||||
calculateTotal();
|
||||
});
|
||||
});
|
||||
$('.basket-quantity').change(function() {
|
||||
var offer_id = $(this).data('id');
|
||||
var quantity = $(this).val();
|
||||
var $row = $(this).closest('.row');
|
||||
updateBasket(offer_id, quantity, function() {
|
||||
calculatePrice($row);
|
||||
calculateTotal();
|
||||
});
|
||||
});
|
||||
|
||||
$('.basket-delete').click(function() {
|
||||
var offer_id = $(this).data('id');
|
||||
updateBasket(offer_id, 0, function() {
|
||||
$('#basket_offer-' + offer_id).remove();
|
||||
calculateTotal();
|
||||
});
|
||||
});
|
||||
}
|
||||
$('.basket-delete').click(function() {
|
||||
var offer_id = $(this).data('id');
|
||||
updateBasket(offer_id, 0, function() {
|
||||
$('#basket_offer-' + offer_id).remove();
|
||||
calculateTotal();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function updateBasket(offer_id, quantity, callback) {
|
||||
var data = {offer_id: offer_id, quantity: quantity, update: true};
|
||||
$.post("{{ route('Shop.Basket.addBasket') }}", data, callback);
|
||||
}
|
||||
function updateBasket(offer_id, quantity, callback) {
|
||||
var data = {
|
||||
offer_id: offer_id,
|
||||
quantity: quantity,
|
||||
update: true
|
||||
};
|
||||
$.post("{{ route('Shop.Basket.addBasket') }}", data, callback);
|
||||
}
|
||||
|
||||
function calculatePrice($that) {
|
||||
var quantity = $that.find('.basket-quantity').val();
|
||||
var price = $that.find('.basket-price').text();
|
||||
var total_price = fixNumber(quantity * price);
|
||||
$that.find('.basket-total-row').html(total_price);
|
||||
calculateTotal();
|
||||
return total_price;
|
||||
}
|
||||
function calculatePrice($that) {
|
||||
var quantity = $that.find('.basket-quantity').val();
|
||||
var price = $that.find('.basket-price').text();
|
||||
var total_price = fixNumber(quantity * price);
|
||||
$that.find('.basket-total-row').html(total_price);
|
||||
calculateTotal();
|
||||
return total_price;
|
||||
}
|
||||
|
||||
function calculateTotal() {
|
||||
countBasket();
|
||||
var total = 0;
|
||||
$('.basket-total-row').each(function() {
|
||||
total += parseFloat($(this).text());
|
||||
});
|
||||
$('#basket-total').html(fixNumber(total));
|
||||
calculateTotalShipped();
|
||||
refreshBasketTop();
|
||||
return total;
|
||||
}
|
||||
function calculateTotal() {
|
||||
countBasket();
|
||||
var total = 0;
|
||||
$('.basket-total-row').each(function() {
|
||||
total += parseFloat($(this).text());
|
||||
});
|
||||
$('#basket-total').html(fixNumber(total));
|
||||
calculateTotalShipped();
|
||||
refreshBasketTop();
|
||||
return total;
|
||||
}
|
||||
|
||||
function countBasket() {
|
||||
var count = 0;
|
||||
$('.basket-quantity').each(function() {
|
||||
count += parseInt($(this).val());
|
||||
});
|
||||
$('#basket-count').html(count);
|
||||
return count;
|
||||
}
|
||||
function countBasket() {
|
||||
var count = 0;
|
||||
$('.basket-quantity').each(function() {
|
||||
count += parseInt($(this).val());
|
||||
});
|
||||
$('#basket-count').html(count);
|
||||
return count;
|
||||
}
|
||||
|
||||
function calculateTotalShipped() {
|
||||
var total_shipped = parseFloat($('#basket-total').html());
|
||||
$('#basket-total-shipped').html(fixNumber(total_shipped));
|
||||
}
|
||||
function calculateTotalShipped() {
|
||||
var total_shipped = parseFloat($('#basket-total').html());
|
||||
$('#basket-total-shipped').html(fixNumber(total_shipped));
|
||||
}
|
||||
|
||||
function fixNumber(value) {
|
||||
return parseFloat(value).toFixed(2);
|
||||
}
|
||||
function fixNumber(value) {
|
||||
return parseFloat(value).toFixed(2);
|
||||
}
|
||||
|
||||
handleBasket();
|
||||
</script>
|
||||
handleBasket();
|
||||
</script>
|
||||
@endpush
|
||||
@@ -4,7 +4,7 @@
|
||||
</div>
|
||||
<div class="col-6 text-right font-weight-bold">
|
||||
<span id="basket_sale_channel">
|
||||
{{ $sale_channel['name'] ?? null }}
|
||||
{{ $basket['sale_channel']['name'] ?? null }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -18,7 +18,7 @@
|
||||
</span> €
|
||||
</div>
|
||||
</div>
|
||||
@if ($basket['shipping'])
|
||||
@if ($basket['shipping'] ?? false)
|
||||
<div class="row mb-3">
|
||||
<div class="col-6">
|
||||
LIVRAISON
|
||||
|
||||
@@ -54,15 +54,6 @@
|
||||
$('#personal_data').collapse('show');
|
||||
});
|
||||
|
||||
$('#delivery_mode .delivery_mode').click(function() {
|
||||
var test = $(this).hasClass('at_house');
|
||||
if ($(this).hasClass('at_house')) {
|
||||
$('#delivery_addresses').closest('.card').removeClass('d-none');
|
||||
} else {
|
||||
$('#delivery_addresses').closest('.card').addClass('d-none');
|
||||
}
|
||||
});
|
||||
|
||||
function refreshBasketTotal(deliveryId, deliveryTypeId) {
|
||||
options = deliveryId + '/' + deliveryTypeId;
|
||||
$.get("{{ Route('Shop.Basket.getBasketTotal') }}/" + options, function(data) {
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
<div class="row mb-3">
|
||||
<div class="col-1">
|
||||
@include('components.form.radios.icheck', [
|
||||
'name' => 'address_id',
|
||||
'name' => $prefix . '_address_id',
|
||||
'val' => $address['id'],
|
||||
'id' => 'address_' . $address['id'],
|
||||
'value' => count($addresses) === 1 ? $address['id'] : false,
|
||||
'id' => $prefix . '_address_' . $address['id'],
|
||||
'value' => $address['priority'] || count($addresses) === 1 ? $address['id'] : false,
|
||||
])
|
||||
</div>
|
||||
<div class="col-11">
|
||||
|
||||
@@ -24,12 +24,21 @@ ci-contre
|
||||
|
||||
@push('js')
|
||||
<script>
|
||||
$('.delivery_mode').click(function() {
|
||||
var deliveryTypeId = $(this).val();
|
||||
var deliveryId = $('input[name=delivery_id]').val()
|
||||
console.log(deliveryId);
|
||||
console.log(deliveryTypeId);
|
||||
refreshBasketTotal(deliveryId, deliveryTypeId)
|
||||
});
|
||||
function handleDeliveries() {
|
||||
$('#delivery_mode input.delivery_mode').change(function() {
|
||||
if ($(this).hasClass('at_house')) {
|
||||
$('#delivery_addresses').closest('.card').removeClass('d-none');
|
||||
var deliveryTypeId = $('input[name=delivery_type_id]:checked').val()
|
||||
} else {
|
||||
$('#delivery_addresses').closest('.card').addClass('d-none');
|
||||
}
|
||||
var deliveryId = $(this).val();
|
||||
console.log(deliveryId);
|
||||
console.log(deliveryTypeId);
|
||||
refreshBasketTotal(deliveryId, deliveryTypeId);
|
||||
});
|
||||
}
|
||||
|
||||
handleDeliveries();
|
||||
</script>
|
||||
@endpush
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<x-layout.collapse id="invoice_addresses" title="Adresse de facturation" class="rounded-lg mb-3" uncollapsed=true>
|
||||
@include('Shop.Orders.partials.addresses', [
|
||||
'addresses' => $customer['invoice_addresses'] ?? false,
|
||||
'prefix' => 'invoice',
|
||||
])
|
||||
</x-layout.collapse>
|
||||
|
||||
@@ -13,6 +14,7 @@
|
||||
uncollapsed=true>
|
||||
@include('Shop.Orders.partials.addresses', [
|
||||
'addresses' => $customer['delivery_addresses'] ?? false,
|
||||
'prefix' => 'delivery',
|
||||
])
|
||||
@include('Shop.Orders.partials.shipping')
|
||||
</x-layout.collapse>
|
||||
|
||||
@@ -30,12 +30,15 @@
|
||||
|
||||
@push('js')
|
||||
<script>
|
||||
$('.delivery_type').click(function() {
|
||||
var deliveryId = $(this).val();
|
||||
var deliveryTypeId = $('input[name=delivery_type_id]').val()
|
||||
console.log(deliveryId);
|
||||
console.log(deliveryTypeId);
|
||||
refreshBasketTotal(deliveryId, deliveryTypeId);
|
||||
});
|
||||
function handleDeliveryTypes() {
|
||||
$('input.delivery_type').change(function() {
|
||||
var deliveryTypeId = $(this).val();
|
||||
var deliveryId = $('input[name=delivery_id]').val()
|
||||
console.log(deliveryId);
|
||||
console.log(deliveryTypeId);
|
||||
refreshBasketTotal(deliveryId, deliveryTypeId);
|
||||
});
|
||||
}
|
||||
handleDeliveryTypes();
|
||||
</script>
|
||||
@endpush
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<div class="icheck-{{ $color ?? 'success' }} {{ $class ?? '' }}">
|
||||
@include('components.form.radio')
|
||||
<label class="control-label light" for="{{ $id_name ?? $id ?? $name }}">{{ $label ?? '' }}</label>
|
||||
<label class="control-label light" for="{{ $id_name ?? ($id ?? $name) }}">{{ $label ?? '' }}</label>
|
||||
</div>
|
||||
Reference in New Issue
Block a user