19 Commits

Author SHA1 Message Date
Valentin Lab
cc8dfa29b4 fix: display only delivery types that have a price and auto-select first 2025-10-05 10:09:03 +02:00
Valentin Lab
62bce92d6d fix: make delivery option on checkout stick to the current sale channel 2025-10-05 09:56:33 +02:00
Valentin Lab
8d130b9741 new: add channel management 2025-10-05 09:39:27 +02:00
Valentin Lab
2d7436a12b fix: make sale channel description field editable 2025-10-05 05:26:20 +02:00
Valentin Lab
f25a62ed26 new: make admin delivery edition can toggle off public and active states 2025-10-05 03:32:08 +02:00
Valentin Lab
36764f2647 fix: make save button avoid error 500 in delivery method admin page 2025-10-05 03:28:03 +02:00
Valentin Lab
e37cad6699 new: make the eye icon work to see an invoice in admin customer view 2025-10-04 15:37:28 +02:00
Valentin Lab
ae7f8ed2c9 fix: remove 404 about javascript file in admin console 2025-10-04 14:39:07 +02:00
Valentin Lab
a3a86f4b2f new: keep cart when login in 2025-10-04 14:13:48 +02:00
Valentin Lab
9c081574c8 new: make click in choices of search box load the page of the product 2025-10-04 13:54:21 +02:00
Valentin Lab
11edccad02 fix: make invoices creation resistant to missing address if this still happens 2025-10-04 12:55:11 +02:00
Valentin Lab
7c796802be new: make invoice still keep the old addresses when their address gets deleted in profile 2025-10-04 12:39:13 +02:00
Valentin Lab
5cc43bc889 fix: make the button to add an address unusable when the address form is open 2025-10-04 12:19:24 +02:00
Valentin Lab
f094411f10 new: add persistence of default address selection 2025-10-04 11:59:57 +02:00
Valentin Lab
ccc477f291 new: display the default address checkbox on profile load 2025-10-04 11:59:57 +02:00
Valentin Lab
7217d945a3 fix: make the address appear when added 2025-10-04 11:59:57 +02:00
Valentin Lab
9185269874 fix: prevent deleting last address for each kind 2025-10-04 11:59:57 +02:00
Valentin Lab
e42e3b4c0d fix: prevent 404 when deleting an adress 2025-10-04 11:06:43 +02:00
Valentin Lab
a7ae946797 fix: prevent error 500 on profile edition 2025-10-04 10:51:41 +02:00
45 changed files with 1190 additions and 152 deletions

View File

@@ -55,6 +55,7 @@ RUN chmod +x artisan
RUN ./artisan vendor:publish --tag=public --force ## creates public/vendor/jsvalidation
RUN ./artisan vendor:publish --tag=boilerplate-public --force --ansi ## creates public/vendor/boilerplate
RUN ./artisan vendor:publish --tag=datatables-buttons --force --ansi ## creates public/vendor/datatables/buttons
## XXXvlab: 2025-09-25 these migration files are breaking first
## install, but we had to resolve to not install from scratch and use

View File

@@ -11,7 +11,7 @@ use Yajra\DataTables\Html\Column;
class CustomerInvoicesDataTable extends DataTable
{
public $model_name = 'invoices';
public $model_name = 'customer_invoices';
public $sortedColumn = 1;

View File

@@ -12,15 +12,6 @@ class CustomerInvoiceController extends Controller
return $dataTable->render('Admin.Shop.CustomerInvoices.list');
}
public function show($id)
{
$data = [
'invoice' => Invoices::get($id),
];
return view('Admin.Shop.CustomerInvoices.view', $data);
}
public function destroy($id)
{
return Invoices::destroy($id);

View File

@@ -3,6 +3,7 @@
namespace App\Http\Controllers\Shop\Auth;
use App\Http\Controllers\Controller;
use App\Repositories\Core\User\ShopCart;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
@@ -31,6 +32,7 @@ class LoginController extends Controller
]);
if ($this->guard()->attempt($credentials, $request->get('remember'))) {
ShopCart::migrateGuestCartToUser();
$request->session()->regenerate();
if (back()->getTargetUrl() === route('Shop.Orders.store')) {
$route = 'Shop.Orders.order';

View File

@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Shop\Auth;
use App\Http\Controllers\Controller;
use App\Http\Requests\Shop\RegisterCustomer;
use App\Repositories\Core\User\ShopCart;
use App\Repositories\Shop\CustomerSaleChannels;
use App\Repositories\Shop\CustomerAddresses;
use App\Repositories\Shop\Customers;
@@ -33,6 +34,7 @@ class RegisterController extends Controller
$user = $this->create($request->all());
$this->guard()->login($user);
ShopCart::migrateGuestCartToUser();
return $request->wantsJson()
? new JsonResponse([], 201)

View File

@@ -2,9 +2,13 @@
namespace App\Http\Controllers\Shop;
use App\Repositories\Core\User\ShopCart;
use App\Repositories\Shop\Baskets;
use App\Repositories\Shop\CustomerAddresses;
use App\Repositories\Shop\Customers;
use App\Repositories\Shop\Offers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
class CustomerController extends Controller
{
@@ -43,8 +47,50 @@ class CustomerController extends Controller
public function storeProfileAjax(Request $request)
{
$data = $request->all();
if (array_key_exists('default_sale_channel_id', $data)) {
$customer = Customers::get(Customers::getId());
$newSaleChannelId = (int) $data['default_sale_channel_id'];
$currentSaleChannelId = (int) ($customer->default_sale_channel_id ?? 0);
if ($newSaleChannelId && $newSaleChannelId !== $currentSaleChannelId && ShopCart::count() > 0) {
$cartItems = ShopCart::getContent();
$unavailable = [];
foreach ($cartItems as $item) {
$offerId = (int) $item->id;
if (! Offers::getPrice($offerId, 1, $newSaleChannelId)) {
$offer = Offers::get($offerId, ['article']);
$unavailable[] = $offer->article->name ?? $item->name;
if (count($unavailable) >= 3) {
break;
}
}
}
if (! empty($unavailable)) {
$list = implode(', ', $unavailable);
return response()->json([
'error' => 1,
'message' => __('Certains articles de votre panier ne sont pas disponibles dans ce canal : :products. Merci de finaliser votre commande ou de retirer ces articles avant de changer de canal.', ['products' => $list]),
], 422);
}
}
}
$customer = Customers::store($data);
if ($customer) {
Customers::guard()->setUser($customer->fresh(['sale_channels']));
if (array_key_exists('default_sale_channel_id', $data)) {
session(['shop.default_sale_channel_id' => $data['default_sale_channel_id']]);
Baskets::refreshPrices((int) $data['default_sale_channel_id']);
}
}
return response()->json(['error' => 0]);
}
@@ -56,10 +102,89 @@ class CustomerController extends Controller
return redirect()->route('Shop.Customers.edit');
}
public function storeAddress(Request $request)
{
if (Customers::isNotConnected()) {
return response()->json(['message' => __('Authentification requise.')], 403);
}
$prefix = $request->input('prefix');
$types = ['deliveries' => 1, 'invoices' => 2];
if (! array_key_exists($prefix, $types)) {
return response()->json(['message' => __('Type d\'adresse inconnu.')], 422);
}
$addressData = $request->input($prefix, []);
$validator = Validator::make($addressData, [
'name' => ['nullable', 'string', 'max:150'],
'address' => ['required', 'string', 'max:255'],
'address2' => ['nullable', 'string', 'max:255'],
'zipcode' => ['required', 'string', 'max:30'],
'city' => ['required', 'string', 'max:255'],
], [
'address.required' => __('Merci de renseigner l\'adresse.'),
'zipcode.required' => __('Merci de renseigner le code postal.'),
'city.required' => __('Merci de renseigner la ville.'),
]);
if ($validator->fails()) {
return response()->json([
'message' => __('Merci de vérifier les informations saisies.'),
'errors' => $validator->errors(),
], 422);
}
$data = $validator->validated();
$customerId = Customers::getId();
$data['customer_id'] = $customerId;
$data['type'] = $types[$prefix];
if (empty($data['name'])) {
$data['name'] = Customers::getName($customerId);
}
$address = CustomerAddresses::store($data);
CustomerAddresses::setDefault($customerId, $address->id, $types[$prefix]);
$html = view('Shop.Customers.partials.address_item', [
'address' => $address->toArray(),
'prefix' => $prefix,
'with_name' => true,
'selected' => $address->id,
])->render();
return response()->json([
'success' => true,
'html' => $html,
'message' => __('Adresse enregistrée.'),
'id' => $address->id,
]);
}
public function delete_address($id)
{
$ret = CustomerAddresses::destroy($id);
$address = CustomerAddresses::get($id);
return redirect()->route('Shop.Customers.edit');
if (! $address || (int) $address->customer_id !== (int) Customers::getId()) {
abort(404);
}
$remaining = CustomerAddresses::getModel()
->byCustomer($address->customer_id)
->byType($address->type)
->count();
if ($remaining <= 1) {
return redirect()->route('Shop.Customers.edit')
->with('growl', [__('Vous devez conserver au moins une adresse par type.'), 'warning']);
}
CustomerAddresses::destroy($id);
CustomerAddresses::ensureDefault($address->customer_id, $address->type);
return redirect()->route('Shop.Customers.edit')
->with('growl', [__('Adresse supprimée.'), 'success']);
}
}

View File

@@ -15,8 +15,14 @@ class InvoiceController extends Controller
public function view($uuid)
{
$invoice = Invoices::view($uuid);
if (! $invoice) {
abort(404);
}
$data = [
'invoice' => Invoices::view($uuid),
'invoice' => $invoice,
];
return view('Shop.Invoices.view', $data);

View File

@@ -49,12 +49,22 @@ class OrderController extends Controller
{
if (ShopCart::count()) {
$customer = Customers::getWithAddresses();
$deliveries = Deliveries::getByCustomer();
$customerId = $customer ? $customer->id : false;
$defaultSaleChannelId = SaleChannels::getDefaultID($customerId);
$deliveries = $defaultSaleChannelId
? Deliveries::getBySaleChannels([$defaultSaleChannelId])
: Deliveries::getByCustomer($customerId);
$deliveries = $deliveries ? $deliveries->values() : collect();
$customerData = $customer ? $customer->toArray() : false;
if ($customerData && $defaultSaleChannelId) {
$customerData['default_sale_channel_id'] = $defaultSaleChannelId;
}
$data = [
'customer' => $customer ? $customer->toArray() : false,
'customer' => $customerData,
'basket' => Baskets::getBasketTotal(),
'deliveries' => $deliveries ? $deliveries->toArray() : [],
'deliveries' => $deliveries->toArray(),
'delivery_types' => DeliveryTypes::getWithPrice(Baskets::getWeight()),
];

View File

@@ -3,9 +3,11 @@
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class CustomerAddress extends Model
{
use SoftDeletes;
protected $guarded = ['id'];
protected $table = 'shop_customer_addresses';

View File

@@ -39,7 +39,7 @@ class Invoice extends Model
public function address(): BelongsTo
{
return $this->belongsTo(CustomerAddress::class, 'invoice_address_id');
return $this->belongsTo(CustomerAddress::class, 'invoice_address_id')->withTrashed();
}
public function scopeByCustomer($query, $customerId)

View File

@@ -29,7 +29,7 @@ class Order extends Model
public function delivery_address(): BelongsTo
{
return $this->belongsTo(CustomerAddress::class, 'delivery_address_id');
return $this->belongsTo(CustomerAddress::class, 'delivery_address_id')->withTrashed();
}
public function delivery(): BelongsTo

View File

@@ -94,11 +94,106 @@ class ShopCart
return self::get()->getContent();
}
public static function get()
public static function migrateGuestCartToUser($userId = null)
{
$userId = Auth::guard('customer')->id();
$sessionKey = 'cart_'.sha1(static::class . ($userId ?? 'guest'));
$userId = self::resolveUserId($userId);
return Cart::session($sessionKey);
if ($userId === null) {
return;
}
$guestSessionKey = self::sessionKey();
$guestItems = Cart::session($guestSessionKey)->getContent();
if ($guestItems->count() === 0) {
return;
}
$userSessionKey = self::sessionKey($userId);
foreach ($guestItems as $item) {
$existing = Cart::session($userSessionKey)->get($item->id);
if ($existing) {
Cart::session($userSessionKey)->update($item->id, [
'quantity' => [
'relative' => false,
'value' => $existing->quantity + $item->quantity,
],
]);
continue;
}
$itemData = [
'id' => $item->id,
'name' => $item->name,
'price' => $item->price,
'quantity' => $item->quantity,
'attributes' => self::extractAttributes($item),
];
if (isset($item->associatedModel)) {
$itemData['associatedModel'] = $item->associatedModel;
}
$conditions = self::extractConditions($item);
if (! empty($conditions)) {
$itemData['conditions'] = $conditions;
}
Cart::session($userSessionKey)->add($itemData);
}
Cart::session($guestSessionKey)->clear();
Cart::session($userSessionKey);
}
protected static function extractAttributes($item)
{
if (! isset($item->attributes)) {
return [];
}
if (is_object($item->attributes) && method_exists($item->attributes, 'toArray')) {
return $item->attributes->toArray();
}
return (array) $item->attributes;
}
protected static function extractConditions($item)
{
if (! isset($item->conditions)) {
return [];
}
if (is_object($item->conditions) && method_exists($item->conditions, 'toArray')) {
return $item->conditions->toArray();
}
return (array) $item->conditions;
}
protected static function resolveUserId($userId = null)
{
return $userId ?? Auth::guard('customer')->id();
}
protected static function sessionKey($userId = null)
{
$key = $userId ?? 'guest';
return 'cart_'.sha1(static::class.$key);
}
protected static function session($userId = null)
{
return Cart::session(self::sessionKey($userId));
}
public static function get($userId = null)
{
return self::session(self::resolveUserId($userId));
}
}

View File

@@ -5,6 +5,7 @@ namespace App\Repositories\Shop;
use App\Models\Shop\Article;
use App\Repositories\Botanic\Species;
use App\Repositories\Botanic\Varieties;
use App\Repositories\Shop\SaleChannels;
use App\Repositories\Core\Comments;
use App\Traits\Model\Basic;
use App\Traits\Repository\Imageable;
@@ -70,9 +71,14 @@ class Articles
public static function getArticleToSell($id, $saleChannelId = false)
{
$saleChannelId = $saleChannelId ?: SaleChannels::getDefaultID();
$data = self::getArticle($id);
$data['offers'] = self::getOffersGroupedByNature($id, $saleChannelId);
$currentSaleChannel = $saleChannelId ? SaleChannels::get($saleChannelId) : null;
$data['current_sale_channel'] = $currentSaleChannel ? $currentSaleChannel->toArray() : null;
$data['available_sale_channels'] = Offers::getSaleChannelsForArticle($id);
return $data;
}

View File

@@ -100,12 +100,19 @@ class Baskets
$offers = Offers::getWithPricesByIds(self::getIds(), $saleChannelId);
foreach ($basket as $item) {
$offer = $offers->where('id', $item->id)->first();
if (! $offer) {
continue;
}
$priceValue = Offers::getPrice($item->id, $item->quantity, $saleChannelId);
$unitPrice = $priceValue ? (float) $priceValue->price_taxed : (float) $item->price;
$article_nature = strtolower($offer->article->article_nature->name);
$data[$article_nature][] = [
'id' => (int) $item->id,
'name' => $item->name,
'quantity' => (int) $item->quantity,
'price' => $item->price,
'price' => $unitPrice,
'variation' => $offer->variation->name,
'image' => Articles::getPreviewSrc(ArticleImages::getFullImageByArticle($offer->article)),
'latin' => $offer->article->product->specie->latin ?? false,
@@ -115,6 +122,24 @@ class Baskets
return $data ?? false;
}
public static function refreshPrices($saleChannelId = false)
{
$saleChannelId = $saleChannelId ? $saleChannelId : SaleChannels::getDefaultID();
$basket = ShopCart::getContent();
foreach ($basket as $item) {
$priceValue = Offers::getPrice($item->id, $item->quantity, $saleChannelId);
if (! $priceValue) {
continue;
}
ShopCart::get()->update($item->id, [
'price' => $priceValue->price_taxed,
]);
}
}
public static function getBasketData($id, $quantity = 1)
{
$offer = Offers::get($id, ['article', 'variation']);

View File

@@ -12,17 +12,35 @@ class CustomerAddresses
public static function storeByCustomer($customer, $data)
{
$deliveries = $data['deliveries'] ?? false;
if ($deliveries && $deliveries['zipcode'] && $deliveries['city']) {
$deliveries['customer_id'] = $customer->id;
$deliveries['type'] = 1;
self::store($deliveries);
if ($deliveries) {
if (! empty($deliveries['address_id'])) {
self::setDefault($customer->id, (int) $deliveries['address_id'], 1);
}
if (! empty($deliveries['zipcode']) && ! empty($deliveries['city'])) {
$payload = $deliveries;
unset($payload['address_id']);
$payload['customer_id'] = $customer->id;
$payload['type'] = 1;
$newAddress = self::store($payload);
self::setDefault($customer->id, $newAddress->id, 1);
}
}
$invoices = $data['invoices'] ?? false;
if ($invoices && $invoices['zipcode'] && $invoices['city']) {
$invoices['customer_id'] = $customer->id;
$invoices['type'] = 2;
self::store($invoices);
if ($invoices) {
if (! empty($invoices['address_id'])) {
self::setDefault($customer->id, (int) $invoices['address_id'], 2);
}
if (! empty($invoices['zipcode']) && ! empty($invoices['city'])) {
$payload = $invoices;
unset($payload['address_id']);
$payload['customer_id'] = $customer->id;
$payload['type'] = 2;
$newAddress = self::store($payload);
self::setDefault($customer->id, $newAddress->id, 2);
}
}
}
@@ -70,14 +88,24 @@ class CustomerAddresses
public static function getInvoiceAddress($customerId)
{
$addresses = CustomerAddress::byCustomer($customerId)->byInvoicing()->get();
return count($addresses) ? $addresses->first() : self::getByCustomer($customerId);
$address = CustomerAddress::byCustomer($customerId)
->byInvoicing()
->orderByDesc('priority')
->orderBy('id')
->first();
return $address ?? self::getByCustomer($customerId);
}
public static function getDeliveryAddress($customerId)
{
$addresses = CustomerAddress::byCustomer($customerId)->byDelivery()->get();
return count($addresses) ? $addresses->first() : self::getByCustomer($customerId);
$address = CustomerAddress::byCustomer($customerId)
->byDelivery()
->orderByDesc('priority')
->orderBy('id')
->first();
return $address ?? self::getByCustomer($customerId);
}
public static function getByCustomer($customerId = false)
@@ -92,6 +120,40 @@ class CustomerAddresses
return ((int) $type === 1) ? '<i class="fa fa-fw fa-truck"></i>' : '<i class="fa fa-fw fa-file-invoice"></i>';
}
public static function setDefault($customerId, $addressId, $type)
{
if (! $addressId) {
return;
}
$address = self::get($addressId);
if (! $address || (int) $address->customer_id !== (int) $customerId || (int) $address->type !== (int) $type) {
return;
}
self::getModel()->byCustomer($customerId)->byType($type)->update(['priority' => null]);
$address->priority = 1;
$address->save();
}
public static function ensureDefault($customerId, $type)
{
$hasDefault = self::getModel()->byCustomer($customerId)->byType($type)->where('priority', 1)->exists();
if ($hasDefault) {
return;
}
$address = self::getModel()->byCustomer($customerId)->byType($type)->orderBy('id')->first();
if ($address) {
$address->priority = 1;
$address->save();
}
}
public static function toggleActive($id, $active)
{
return self::update(['active' => $active], $id);

View File

@@ -6,6 +6,7 @@ use App\Datatables\Shop\CustomerInvoicesDataTable;
use App\Datatables\Shop\CustomerOrdersDataTable;
use App\Models\Shop\Customer;
use App\Traits\Model\Basic;
use App\Repositories\Shop\CustomerAddresses;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
@@ -30,16 +31,31 @@ class Customers
public static function getSaleChannels($customerId = false)
{
$customer = $customerId ? self::get($customerId) : self::getAuth();
$saleChannels = $customer ? $customer->sale_channels : false;
$saleChannels = collect();
return $saleChannels ? $saleChannels : SaleChannels::getDefault();
if ($customer) {
$customer->loadMissing('sale_channels');
$saleChannels = $customer->sale_channels ?? collect();
if ($saleChannels instanceof \Illuminate\Support\Collection && $saleChannels->isNotEmpty()) {
return $saleChannels;
}
}
$default = SaleChannels::getDefault($customerId);
return $default ? collect([$default]) : collect();
}
public static function getSaleChannel($customerId = false)
{
$saleChannels = self::getSaleChannels($customerId);
return $saleChannels->first();
if ($saleChannels instanceof \Illuminate\Support\Collection) {
return $saleChannels->first();
}
return $saleChannels;
}
public static function getDeliveries()
@@ -57,12 +73,22 @@ class Customers
public static function editProfile($id = false)
{
return $id ? [
'customer' => self::get($id, ['addresses', 'deliveries'])->toArray(),
'deliveries' => Deliveries::getAllWithSaleChannel()->toArray(),
if (! $id) {
abort('403');
}
$customer = self::get($id, ['addresses', 'deliveries', 'sale_channels']);
$saleChannels = self::getSaleChannels($id);
return [
'customer' => $customer->toArray(),
'sale_channels' => $saleChannels->toArray(),
'deliveries' => Deliveries::getByCustomer($id)->toArray(),
'sale_channel_checks' => Shop::getSaleChannelAvailabilitySummary($saleChannels->pluck('id')->toArray()),
'orders' => (new CustomerOrdersDataTable())->html(),
'invoices' => (new CustomerInvoicesDataTable())->html(),
] : abort('403');
];
}
public static function getAddresses($id = false)
@@ -95,6 +121,16 @@ class Customers
$data = $customer->toArray();
$data['sale_channels'] = $customer->sale_channels->pluck('id')->toArray();
$data['deliveries'] = Deliveries::getBySaleChannels($data['sale_channels'])->toArray();
$data['delivery_address_id'] = optional(CustomerAddresses::getDeliveryAddress($id))->id;
$data['invoice_address_id'] = optional(CustomerAddresses::getInvoiceAddress($id))->id;
if (! $data['delivery_address_id'] && ! empty($data['delivery_addresses'])) {
$data['delivery_address_id'] = $data['delivery_addresses'][0]['id'] ?? null;
}
if (! $data['invoice_address_id'] && ! empty($data['invoice_addresses'])) {
$data['invoice_address_id'] = $data['invoice_addresses'][0]['id'] ?? null;
}
return $data;
}
@@ -102,8 +138,8 @@ class Customers
public static function storeFull($data)
{
$data2 = $data;
if ($data['sale_channels'] ?? false) {
$saleChannels = $data['sale_channels'] ?? false;
$saleChannels = array_key_exists('sale_channels', $data) ? $data['sale_channels'] : null;
if ($saleChannels !== null) {
unset($data['sale_channels']);
}
if ($data['deliveries'] ?? false) {
@@ -113,7 +149,9 @@ class Customers
unset($data['invoices']);
}
$customer = self::store($data);
$customer->sale_channels()->sync($saleChannels);
if ($saleChannels !== null) {
$customer->sale_channels()->sync($saleChannels);
}
CustomerAddresses::storeByCustomer($customer, $data2);
return $customer->id;

View File

@@ -21,12 +21,12 @@ class Deliveries
$customer = $customerId ? Customers::get($customerId) : Customers::getAuth();
$saleChannels = $customer ? $customer->sale_channels->pluck('id')->toArray() : [SaleChannels::getDefaultID()];
return $saleChannels ? self::getBySaleChannels($saleChannels) : false;
return $saleChannels ? self::getBySaleChannels($saleChannels) : collect();
}
public static function getBySaleChannels($saleChannels)
{
return Delivery::bySaleChannels($saleChannels)->with('sale_channel')->get();
return Delivery::bySaleChannels($saleChannels)->active()->with('sale_channel')->get();
}
public static function getSaleChannelId($deliveryId)
@@ -41,7 +41,7 @@ class Deliveries
public static function getAllWithSaleChannel()
{
return Delivery::orderBy('name', 'asc')->active()->public()->with('sale_channel')->get();
return Delivery::orderBy('name', 'asc')->active()->with('sale_channel')->get();
}
public static function toggleActive($id, $active)

View File

@@ -15,9 +15,15 @@ class DeliveryTypes
$types = self::getAll();
foreach ($types as $type) {
$price = self::getPrice($type->id, $weight);
if ($price === false) {
continue;
}
$data[$type->id] = [
'name' => $type->name,
'price' => self::getPrice($type->id, $weight),
'price' => $price,
];
}

View File

@@ -17,12 +17,15 @@ class InvoicePDF
public static function get($id)
{
$invoice = Invoices::getFull($id);
$customFields = [];
if ($orderRef = optional($invoice->order)->ref) {
$customFields['order number'] = $orderRef;
}
$customer = new Party([
'name' => $invoice->customer->name,
'name' => optional($invoice->customer)->name ?? __('Client inconnu'),
'address' => self::makeAddress($invoice->address),
'custom_fields' => [
'order number' => $invoice->order->ref,
],
'custom_fields' => $customFields,
]);
$items = self::makeItems($invoice->order->detail);
@@ -48,7 +51,17 @@ class InvoicePDF
public static function makeAddress($address)
{
return $address->address.'<br>'.$address->zipcode.' '.$address->city;
if (! $address) {
return '';
}
$lines = array_filter([
$address->address ?? '',
$address->address2 ?? '',
trim(($address->zipcode ?? '').' '.($address->city ?? '')),
]);
return implode('<br>', $lines);
}
public static function makeItems($details)

View File

@@ -36,7 +36,13 @@ class Invoices
public static function view($uuid)
{
$data = self::getFullByUUID($uuid)->toArray();
$invoice = self::getFullByUUID($uuid);
if (! $invoice) {
return false;
}
$data = $invoice->toArray();
$data['payment_type'] = InvoicePayments::getPaymentType($data['payment_type']);
$data['status'] = self::getStatus($data['status']);

View File

@@ -3,6 +3,8 @@
namespace App\Repositories\Shop;
use App\Models\Shop\Offer;
use App\Models\Shop\PriceListValue;
use App\Models\Shop\SaleChannel;
use App\Traits\Model\Basic;
class Offers
@@ -166,4 +168,42 @@ class Offers
{
return Offer::query();
}
public static function getSaleChannelsForArticle($articleId)
{
$channels = SaleChannel::query()
->whereHas('price_lists', function ($query) use ($articleId) {
$query->whereHas('tariff.offers', function ($subQuery) use ($articleId) {
$subQuery->byArticle($articleId);
})->whereHas('price_list_values');
})
->orderBy('name')
->get();
$offers = Offer::query()
->byArticle($articleId)
->with('article')
->get();
return $channels->map(function ($channel) use ($offers) {
$priceValue = null;
foreach ($offers as $offer) {
$priceCandidate = self::getPrice($offer->id, 1, $channel->id);
if ($priceCandidate && (float) $priceCandidate->price_taxed > 0) {
$priceValue = $priceCandidate;
break;
}
}
return [
'id' => $channel->id,
'name' => $channel->name,
'code' => $channel->code,
'price_taxed' => $priceValue ? (float) $priceValue->price_taxed : null,
'quantity' => $priceValue ? (int) $priceValue->quantity : null,
];
})->toArray();
}
}

View File

@@ -3,21 +3,52 @@
namespace App\Repositories\Shop;
use App\Models\Shop\SaleChannel;
use App\Repositories\Shop\Customers;
use App\Traits\Model\Basic;
class SaleChannels
{
use Basic;
public static function getDefaultID()
public static function getDefaultID($customerId = false)
{
$default = self::getDefault();
$default = self::getDefault($customerId);
return $default ? self::getDefault()->id : false;
return $default ? $default->id : false;
}
public static function getDefault()
public static function getDefault($customerId = false)
{
$sessionChannelId = session('shop.default_sale_channel_id');
if ($sessionChannelId) {
$sessionChannel = SaleChannel::find($sessionChannelId);
if ($sessionChannel) {
return $sessionChannel;
}
}
$customer = $customerId ? Customers::get($customerId) : Customers::getAuth();
if ($customer) {
$customer->loadMissing('sale_channels');
if ($customer->default_sale_channel_id) {
$preferred = $customer->sale_channels->firstWhere('id', $customer->default_sale_channel_id);
if (! $preferred) {
$preferred = SaleChannel::find($customer->default_sale_channel_id);
}
if ($preferred) {
session(['shop.default_sale_channel_id' => $preferred->id]);
return $preferred;
}
}
if ($customer->sale_channels->isNotEmpty()) {
session(['shop.default_sale_channel_id' => $customer->sale_channels->first()->id]);
return $customer->sale_channels->first();
}
}
return self::getByCode('EXP');
}

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Repositories\Shop;
use App\Repositories\Core\User\ShopCart;
class Shop
{
public static function getSaleChannelAvailabilitySummary(array $saleChannelIds): array
{
if (empty($saleChannelIds) || ShopCart::count() === 0) {
return [];
}
$cartItems = ShopCart::getContent();
$summary = [];
foreach ($saleChannelIds as $saleChannelId) {
$saleChannelId = (int) $saleChannelId;
$issues = [];
$issueCount = 0;
foreach ($cartItems as $item) {
$offerId = (int) $item->id;
if (! Offers::getPrice($offerId, 1, $saleChannelId)) {
$offer = Offers::get($offerId, ['article']);
$issues[] = $offer->article->name ?? $item->name;
$issueCount++;
if (count($issues) >= 3) {
continue;
}
}
}
if (! empty($issues)) {
$summary[$saleChannelId] = [
'full_count' => $issueCount,
'names' => array_slice($issues, 0, 3),
];
}
}
return $summary;
}
}

View File

@@ -0,0 +1,47 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
if (! Schema::hasTable('shop_deliveries')) {
return;
}
$columns = ['created_by', 'updated_by', 'deleted_by'];
$columnsToDrop = [];
foreach ($columns as $column) {
if (Schema::hasColumn('shop_deliveries', $column)) {
$columnsToDrop[] = $column;
}
}
if ($columnsToDrop) {
Schema::table('shop_deliveries', function (Blueprint $table) use ($columnsToDrop) {
$table->dropColumn($columnsToDrop);
});
}
Schema::table('shop_deliveries', function (Blueprint $table) {
$table->unsignedBigInteger('created_by')->nullable()->after('event_date_end');
$table->unsignedBigInteger('updated_by')->nullable()->after('created_by');
$table->unsignedBigInteger('deleted_by')->nullable()->after('updated_by');
});
}
public function down(): void
{
if (! Schema::hasTable('shop_deliveries')) {
return;
}
Schema::table('shop_deliveries', function (Blueprint $table) {
$table->dropColumn(['created_by', 'updated_by', 'deleted_by']);
});
}
};

View File

@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::table('shop_customers', function (Blueprint $table) {
if (! Schema::hasColumn('shop_customers', 'default_sale_channel_id')) {
$table->unsignedInteger('default_sale_channel_id')->nullable()->after('settings');
$table->index('default_sale_channel_id', 'shop_customers_default_sale_channel_id_index');
}
});
}
public function down()
{
Schema::table('shop_customers', function (Blueprint $table) {
if (Schema::hasColumn('shop_customers', 'default_sale_channel_id')) {
$table->dropIndex('shop_customers_default_sale_channel_id_index');
$table->dropColumn('default_sale_channel_id');
}
});
}
};

View File

@@ -223,6 +223,9 @@ return [
'successmod' => 'Le canal de vente a été correctement modifié',
'successdel' => 'Le canal de vente a été correctement effacé',
'confirmdelete' => 'Confirmez-vous la suppression du canal de vente ?',
'missing_offers' => '{1} Ce canal de vente n\'a pas d\'offre pour :count produit.|[2,*] Ce canal de vente n\'a pas d\'offre pour :count produits.',
'missing_offers_all' => 'Ce canal de vente n\'a aucune offre pour tous les produits de votre panier.',
'cannot_select_with_cart' => 'Vous ne pouvez pas sélectionner ce mode d\'achat tant que votre panier contient des produits non disponibles dans ce mode.',
],
'shelves' => [
'title' => 'Rayons',

View File

@@ -1,8 +1,34 @@
// Simple notification helper used by blade templates (fallback to Bootstrap alerts)
window.growl = function(message, type) {
var alertTypes = {
success: 'alert-success',
error: 'alert-danger',
warning: 'alert-warning',
info: 'alert-info'
};
var cssClass = alertTypes[type] || alertTypes.info;
var $container = $('#growl-container');
if (!$container.length) {
$container = $('<div id="growl-container" class="growl-container position-fixed w-100" style="top: 1rem; left: 0; z-index: 1080; pointer-events: none;"></div>');
$('body').append($container);
}
var $alert = $('<div class="alert ' + cssClass + ' alert-dismissible fade show mx-auto shadow" role="alert" style="max-width: 420px; pointer-events: all;"></div>');
$alert.append($('<span></span>').text(message));
$alert.append('<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>');
$container.append($alert);
setTimeout(function() {
$alert.alert('close');
}, 4000);
};
// Prevent closing from click inside dropdown
$(document).on('click', '.dropdown-menu', function (e) {
e.stopPropagation();
});
// make it as accordion for smaller screens
if ($(window).width() < 992) {
$('.dropdown-menu a').click(function(e) {

View File

@@ -4,8 +4,28 @@
'model' => 'customer_invoices',
'with_print' => false,
'with_filters' => false,
'show_callback' => 'AdminCustomerInvoiceView(id);',
])
<x-layout.modal title="Filtres" id="modal-customer_invoices-filters">
@include('Admin.Shop.CustomerInvoices.partials.filters', ['model' => 'customer_invoices'])
</x-layout.modal>
</x-card>
@include('load.layout.modal')
@push('js')
<script>
(function() {
const customerInvoiceShowTemplate = "{{ route('Shop.Invoices.view', ['uuid' => '__UUID__']) }}";
window.AdminCustomerInvoiceView = function(id) {
if (!id) {
return;
}
const url = customerInvoiceShowTemplate.replace('__UUID__', id);
openModal('Voir une facture', '#invoice-form', url, false, false, 'xl', true);
};
})();
</script>
@endpush

View File

@@ -15,6 +15,7 @@
<div class="row">
<div class="col-5">
{{ Form::label('active', __('Actif')) }}<br/>
<input type="hidden" name="active" value="0">
@include("components.form.toggle", [
'name' => 'active',
'value' => $delivery['active'] ?? false,
@@ -24,6 +25,7 @@
</div>
<div class="col-3">
{{ Form::label('is_public', __('Type')) }}
<input type="hidden" name="is_public" value="0">
@include('components.form.toggle', [
'name' => 'is_public',
'value' => $delivery['is_public'] ?? false,

View File

@@ -48,6 +48,37 @@
</div>
<div class="col-lg-3 col-xs-12">
@if (config('app.debug') && ($article['current_sale_channel'] ?? false))
<div class="alert alert-info p-2 mb-3">
<strong>Canal actif :</strong>
{{ $article['current_sale_channel']['name'] ?? 'N/A' }}
<span class="d-block small text-muted">
ID {{ $article['current_sale_channel']['id'] ?? '' }} · Code {{ $article['current_sale_channel']['code'] ?? '' }}
</span>
@if (!empty($article['available_sale_channels']))
<hr class="my-2">
<strong class="d-block">Offres disponibles dans :</strong>
<ul class="list-unstyled mb-0 small">
@foreach ($article['available_sale_channels'] as $channel)
<li class="d-flex justify-content-between align-items-start">
<span>
{{ $channel['name'] }}
<span class="d-block text-muted" style="font-size: 0.85em; padding-left: 0.9em;">code {{ $channel['code'] }}</span>
</span>
@if (isset($channel['price_taxed']))
<span class="ml-2 text-nowrap text-right">
{{ number_format($channel['price_taxed'], 2, ',', ' ') }} TTC
@if (! empty($channel['quantity']))
<span class="d-block text-muted" style="font-size: 0.85em;">Qté min. {{ $channel['quantity'] }}</span>
@endif
</span>
@endif
</li>
@endforeach
</ul>
@endif
</div>
@endif
@include('Shop.Articles.partials.ArticleAddBasket')
</div>
</div>

View File

@@ -58,7 +58,7 @@
updateBasket(offer_id, quantity, function() {
calculatePrice($row);
calculateTotal();
});
}, $row);
});
$('.basket-delete').click(function() {
@@ -70,13 +70,20 @@
});
}
function updateBasket(offer_id, quantity, callback) {
function updateBasket(offer_id, quantity, callback, $row) {
var data = {
offer_id: offer_id,
quantity: quantity,
update: true
};
$.post("{{ route('Shop.Basket.addBasket') }}", data, callback);
$.post("{{ route('Shop.Basket.addBasket') }}", data, function(response) {
if ($row && response && response.added && typeof response.added.price !== 'undefined') {
$row.find('.basket-price').text(fixNumber(response.added.price));
$row.find('.basket-total-row').text(fixNumber(response.added.price * $row.find('.basket-quantity').val()));
}
callback(response);
refreshBasketTop();
});
}
function calculatePrice($that) {

View File

@@ -24,6 +24,7 @@
'prefix' => 'deliveries',
'addresses' => $customer['delivery_addresses'],
'with_name' => true,
'selected' => $customer['delivery_address_id'] ?? null,
])
</x-card>
@@ -32,6 +33,7 @@
'prefix' => 'invoices',
'addresses' => $customer['invoice_addresses'],
'with_name' => true,
'selected' => $customer['invoice_address_id'] ?? null,
])
</x-card>

View File

@@ -0,0 +1,25 @@
<div class="row mt-3 address-row" data-address-id="{{ $address['id'] }}">
<div class="col-1">
@php
$inputName = isset($prefix) && $prefix ? $prefix.'[address_id]' : 'address_id';
$currentValue = $selected ?? null;
@endphp
<x-form.radios.icheck name="{{ $inputName }}" val="{{ $address['id'] }}"
:value="$currentValue" id="address_{{ $address['id'] }}" />
</div>
<div class="col-10">
@if ($with_name ?? false)
{{ $address['name'] ?? '' }}<br />
@endif
{{ $address['address'] }}<br />
@if (! empty($address['address2']))
{{ $address['address2'] }}<br />
@endif
{{ $address['zipcode'] }} {{ $address['city'] }}
</div>
<div class="col-1 text-right">
<a class="text-danger" href="{{ route('Shop.Customers.delete_address', ['id' => $address['id']]) }}">
<i class="fa fa-trash" data-id="{{ $address['id'] }}"></i>
</a>
</div>
</div>

View File

@@ -1,26 +1,13 @@
@foreach ($addresses ?? [] as $address)
<div class="row mt-3">
<div class="col-1">
<x-form.radios.icheck name="@if ($prefix ?? false) {{ $prefix }} . '[]' @endif address_id"
val="{{ $address['id'] }}" id="address_{{ $address['id'] }}" />
</div>
<div class="col-10">
@if ($with_name ?? false)
{{ $address['name'] }}<br />
@endif
{{ $address['address'] }}<br />
@if ($address['address2'])
{{ $address['address2'] }}<br />
@endif
{{ $address['zipcode'] }} {{ $address['city'] }}
</div>
<div class="col-1">
<a href="{{ route('Shop.Customers.delete_address') }}/{{ $address['id'] }}">
<i class="fa fa-trash" class="delete" data-id="{{ $address['id'] }}"></i>
</a>
</div>
</div>
@endforeach
<div id="addresses_list_{{ $prefix }}" class="addresses-list">
@foreach ($addresses ?? [] as $address)
@include('Shop.Customers.partials.address_item', [
'address' => $address,
'prefix' => $prefix ?? null,
'with_name' => $with_name ?? false,
'selected' => $selected ?? null,
])
@endforeach
</div>
<div id="add_address_container_{{ $prefix }}" class="green-dark d-none mb-3 mt-3">
<x-card classBody="bg-green-dark yellow" title="Nouvelle adresse" classTitle="h4">
@@ -31,6 +18,18 @@
'label' => 'Adresse',
'customer' => [],
])
<div class="row mt-3">
<div class="col-md-6 mb-2">
<x-form.button id="save_address_{{ $prefix }}" class="btn-success btn-sm btn-block"
icon="fa-save" txt="Enregistrer cette adresse"
:metadata="'data-prefix='.$prefix" />
</div>
<div class="col-md-6 mb-2">
<x-form.button id="cancel_address_{{ $prefix }}" class="btn-outline-light btn-sm btn-block"
icon="fa-times" txt="Annuler"
:metadata="'data-prefix='.$prefix" />
</div>
</div>
</x-card>
</div>
@@ -43,8 +42,71 @@
@push('js')
<script>
$('#add_address_{{ $prefix }}').click(function() {
$('#add_address_container_{{ $prefix }}').toggleClass('d-none');
})
(function() {
var prefix = '{{ $prefix }}';
var $formContainer = $('#add_address_container_{{ $prefix }}');
var $list = $('#addresses_list_{{ $prefix }}');
var storeUrl = '{{ route('Shop.Customers.address.store') }}';
var $toggleBtn = $('#add_address_{{ $prefix }}');
$toggleBtn.on('click', function() {
var isHidden = $formContainer.hasClass('d-none');
if (isHidden) {
$formContainer.removeClass('d-none');
$toggleBtn.prop('disabled', true);
}
});
$('#cancel_address_{{ $prefix }}').on('click', function() {
$formContainer.addClass('d-none');
$formContainer.find('input[type="text"]').val('');
$toggleBtn.prop('disabled', false);
});
$('#save_address_{{ $prefix }}').on('click', function() {
const data = $formContainer.find(':input').serialize();
$.ajax({
url: storeUrl,
method: 'POST',
data: data + '&prefix=' + prefix,
success: function(response) {
if (response.html) {
$list.append(response.html);
}
$formContainer.addClass('d-none');
$formContainer.find('input[type="text"]').val('');
$toggleBtn.prop('disabled', false);
if (response.id) {
const $newRadio = $list.find('#address_' + response.id);
$list.find('input[type="radio"]').not($newRadio).prop('checked', false);
$newRadio.prop('checked', true);
}
if (typeof $.fn.iCheck === 'function') {
$list.find('input[type="radio"]').iCheck('destroy');
if (typeof initIcheck === 'function') {
initIcheck('#addresses_list_{{ $prefix }} input[type="radio"]');
if (response.id) {
$list.find('#address_' + response.id).iCheck('check');
}
}
}
const message = response.message || '{{ __('Adresse enregistrée.') }}';
if (typeof growl === 'function') {
growl(message, 'success');
}
},
error: function(xhr) {
let message = '{{ __('Une erreur est survenue lors de l\'enregistrement de l\'adresse.') }}';
if (xhr.responseJSON && xhr.responseJSON.message) {
message = xhr.responseJSON.message;
}
if (typeof growl === 'function') {
growl(message, 'error');
}
}
});
});
})();
</script>
@endpush

View File

@@ -1,25 +1,168 @@
@foreach ($deliveries as $delivery)
<div class="row">
<div class="col-1 text-right pt-1">
@push('styles')
<style>
.sale-channel-wrapper {
border: none;
background-color: transparent;
}
.sale-channel-wrapper:not(.blocked) .card-body {
border: 1px solid #e5e7eb;
border-radius: .75rem;
background-color: #ffffff;
transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.sale-channel-wrapper:not(.blocked) .card-body:hover {
border-color: #3b82f6;
box-shadow: 0 0.35rem 0.8rem rgba(37, 99, 235, 0.12);
}
.sale-channel-wrapper.blocked .card-body {
border: 1px solid #d1d5db;
border-radius: .75rem;
background-color: #f3f4f6;
}
.sale-channel-wrapper .card-body {
padding: 1.25rem;
}
.sale-channel-toggle {
display: flex;
align-items: flex-start;
justify-content: center;
padding-top: 0.25rem;
}
.sale-channel-content strong {
font-size: 1.05rem;
}
.sale-channel-warning {
font-size: 0.85rem;
}
.sale-channel-wrapper .icheck-success > input:first-child + label::before,
.sale-channel-wrapper .icheck-primary > input:first-child + label::before,
.sale-channel-wrapper .icheck-danger > input:first-child + label::before {
opacity: 1;
border-width: 2px;
border-color: #9ca3af;
}
.sale-channel-wrapper.blocked .icheck-success > input:first-child + label::before,
.sale-channel-wrapper.blocked .icheck-primary > input:first-child + label::before,
.sale-channel-wrapper.blocked .icheck-danger > input:first-child + label::before {
border-color: #cbd5f5;
background-color: #f8fafc;
}
.sale-channel-wrapper .icheck-success > input:first-child + label,
.sale-channel-wrapper .icheck-primary > input:first-child + label,
.sale-channel-wrapper .icheck-danger > input:first-child + label {
opacity: 1;
}
.sale-channel-wrapper [class*="icheck-"] > input:first-child:disabled + label {
opacity: 1;
}
</style>
@endpush
@php
$saleChannelsCollection = collect($sale_channels);
$firstSaleChannel = $saleChannelsCollection->first();
$selectedSaleChannelId = $customer['default_sale_channel_id'] ?? ($firstSaleChannel['id'] ?? null);
$cartCount = app('App\\Repositories\\Core\\User\\ShopCart')::count();
@endphp
@if ($cartCount > 0)
<div class="alert alert-warning">
<strong>Note :</strong> en changeant votre mode d'achat, les articles de votre panier seront transférés sur la liste de prix correspondant au nouveau canal de vente sélectionné.
</div>
@endif
@foreach ($saleChannelsCollection as $saleChannel)
@php
$check = $sale_channel_checks[$saleChannel['id']] ?? null;
$isBlocked = $check && $saleChannel['id'] !== $selectedSaleChannelId;
@endphp
<div class="card sale-channel-wrapper mb-3 @if($isBlocked) blocked @endif">
<div class="card-body py-3">
<div class="row align-items-start">
<div class="col-1 sale-channel-toggle">
@include('components.form.radios.icheck', [
'name' => 'delivery_id',
'id_name' => 'delivery_id_' . $delivery['id'],
'value' => $delivery['id'],
'checked' => $customer['sale_delivery_id'] ?? false,
'class' => 'delivery',
'name' => 'sale_channel_id',
'id_name' => 'sale_channel_id_' . $saleChannel['id'],
'val' => $saleChannel['id'],
'value' => $selectedSaleChannelId,
'class' => 'sale-channel',
'disabled' => $isBlocked,
])
</div>
<div class="col-11 pt-3">
<strong>{{ $delivery['name'] }} - {{ $delivery['sale_channel']['name'] }}</strong><br />
<p>{{ $delivery['description'] }}</p>
</div>
<div class="col-11 sale-channel-content @if($isBlocked) text-muted @endif">
<strong>{{ $saleChannel['name'] }}</strong><br />
<p class="mb-2">{!! $saleChannel['description'] ?? '' !!}</p>
@if ($check)
<div class="text-danger small mb-0 sale-channel-warning">
@php $missingCount = $check['full_count'] ?? count($check['names']); @endphp
@if ($cartCount > 0 && $missingCount >= $cartCount)
{{ __('shop.sale_channels.missing_offers_all') }}
@else
{{ trans_choice('shop.sale_channels.missing_offers', $missingCount, ['count' => $missingCount]) }}
<br>
@if ($missingCount > 3)
<span class="d-block">{{ implode(', ', array_slice($check['names'], 0, 3)) }}, …</span>
@else
<span class="d-block">{{ implode(', ', $check['names']) }}</span>
@endif
@endif
<div class="d-flex align-items-start mt-1">
<span class="mr-1">⚠️</span>
<span>{{ __('shop.sale_channels.cannot_select_with_cart') }}</span>
</div>
</div>
@endif
</div>
</div>
</div>
</div>
@endforeach
@push('js')
<script>
$('.delivery').off().change(function() {
console.log($(this).val());
const $saleChannels = $('.sale-channel');
const updateUrl = '{{ route('Shop.Customers.storeProfileAjax') }}';
const token = '{{ csrf_token() }}';
const customerId = {{ $customer['id'] ?? 'null' }};
let currentSaleChannelId = '{{ $selectedSaleChannelId }}';
$saleChannels.off().change(function() {
if (!customerId) {
return;
}
const selectedSaleChannel = $(this).val();
$.post(updateUrl, {
_token: token,
id: customerId,
default_sale_channel_id: selectedSaleChannel,
}).done(function() {
currentSaleChannelId = selectedSaleChannel;
window.location.reload();
}).fail(function(xhr) {
const message = xhr.responseJSON && xhr.responseJSON.message
? xhr.responseJSON.message
: "{{ __('Une erreur est survenue lors de l\'enregistrement du canal de vente préféré.') }}";
alert(message);
if (currentSaleChannelId) {
$saleChannels.filter('[value="' + currentSaleChannelId + '"]').prop('checked', true);
}
});
});
</script>
@endpush

View File

@@ -1,35 +1,69 @@
<nav>
<div class="nav nav-tabs pl-2">
<a href="#deliveriesTab" data-toggle="tab" class="nav-item nav-link active" role="tab" aria-selected="true">
MON MODE D'ACHAT
</a>
<a href="#ordersTab" data-toggle="tab" class="nav-item nav-link" role="tab" aria-selected="false">
SUIVI DE COMMANDES
</a>
<a href="#invoicesTab" data-toggle="tab" class="nav-item nav-link" role="tab" aria-selected="false">
FACTURES
</a>
</div>
</nav>
@php
$saleChannels = $sale_channels ?? [];
@endphp
<div class="tab-content">
<div class="tab-pane fade show active pt-0 pb-0" id="deliveriesTab">
<x-card classBody="bg-light">
@include('Shop.Customers.partials.deliveries')
</x-card>
@if (count($saleChannels) > 1)
<nav>
<div class="nav nav-tabs pl-2">
<a href="#deliveriesTab" data-toggle="tab" class="nav-item nav-link active" role="tab" aria-selected="true">
MON MODE D'ACHAT
</a>
<a href="#ordersTab" data-toggle="tab" class="nav-item nav-link" role="tab" aria-selected="false">
SUIVI DE COMMANDES
</a>
<a href="#invoicesTab" data-toggle="tab" class="nav-item nav-link" role="tab" aria-selected="false">
FACTURES
</a>
</div>
</nav>
<div class="tab-content">
<div class="tab-pane fade show active pt-0 pb-0" id="deliveriesTab">
<x-card classBody="bg-light">
@include('Shop.Customers.partials.deliveries')
</x-card>
</div>
<div class="tab-pane fade show pt-0 pb-0" id="ordersTab">
<x-card classBody="bg-light">
@include('Shop.Orders.partials.list', [
'dataTable' => $orders,
])
</x-card>
</div>
<div class="tab-pane fade show pt-0 pb-0" id="invoicesTab">
<x-card classBody="bg-light">
@include('Shop.Invoices.partials.list', [
'dataTable' => $invoices,
])
</x-card>
</div>
</div>
<div class="tab-pane fade show pt-0 pb-0" id="ordersTab">
<x-card classBody="bg-light">
@include('Shop.Orders.partials.list', [
'dataTable' => $orders,
])
</x-card>
@else
<nav>
<div class="nav nav-tabs pl-2">
<a href="#ordersTab" data-toggle="tab" class="nav-item nav-link active" role="tab" aria-selected="true">
SUIVI DE COMMANDES
</a>
<a href="#invoicesTab" data-toggle="tab" class="nav-item nav-link" role="tab" aria-selected="false">
FACTURES
</a>
</div>
</nav>
<div class="tab-content">
<div class="tab-pane fade show active pt-0 pb-0" id="ordersTab">
<x-card classBody="bg-light">
@include('Shop.Orders.partials.list', [
'dataTable' => $orders,
])
</x-card>
</div>
<div class="tab-pane fade show pt-0 pb-0" id="invoicesTab">
<x-card classBody="bg-light">
@include('Shop.Invoices.partials.list', [
'dataTable' => $invoices,
])
</x-card>
</div>
</div>
<div class="tab-pane fade show pt-0 pb-0" id="invoicesTab">
<x-card classBody="bg-light">
@include('Shop.Invoices.partials.list', [
'dataTable' => $invoices,
])
</x-card>
</div>
</div>
@endif

View File

@@ -1,13 +1,51 @@
@php
$addresses = collect($addresses ?? []);
$preselectedAddressId = old($name);
if ($preselectedAddressId === null && is_string($name) && str_contains($name, '[')) {
$dotName = preg_replace('/\[(.*?)\]/', '.$1', $name);
$dotName = trim($dotName, '.');
$preselectedAddressId = $dotName ? old($dotName) : null;
}
if (($preselectedAddressId === null || $preselectedAddressId === '') && $addresses->isNotEmpty()) {
$defaultAddress = $addresses->firstWhere('priority', 1);
if (! $defaultAddress) {
$defaultAddress = $addresses
->filter(function ($address) {
return (int) ($address['priority'] ?? 0) > 0;
})
->sortByDesc(function ($address) {
return (int) ($address['priority'] ?? 0);
})
->first();
}
if (! $defaultAddress) {
$defaultAddress = $addresses->firstWhere('is_default', true)
?? $addresses->firstWhere('default', true);
}
if (! $defaultAddress) {
$defaultAddress = $addresses->first();
}
$preselectedAddressId = $defaultAddress['id'] ?? null;
}
$addresses = $addresses->all();
@endphp
@if ($addresses)
@foreach ($addresses ?? [] as $address)
@foreach ($addresses as $address)
<div class="row mb-3">
<div class="col-1">
@include('components.form.radios.icheck', [
'name' => $name,
'val' => $address['id'],
'id' => $prefix . '_address_' . $address['id'],
'value' =>
old($name) ?? $address['priority'] || count($addresses) === 1 ? $address['id'] : false,
'value' => $preselectedAddressId,
])
</div>
<div class="col-11">

View File

@@ -1,10 +1,20 @@
@php
$defaultSaleChannelId = $customer['default_sale_channel_id'] ?? null;
$preselectedDeliveryId = old('delivery_id');
if (! $preselectedDeliveryId && $defaultSaleChannelId) {
$match = collect($deliveries)->firstWhere('sale_channel_id', $defaultSaleChannelId);
$preselectedDeliveryId = $match['id'] ?? null;
}
@endphp
@foreach ($deliveries as $delivery)
<div class="row">
<div class="col-1">
@include('components.form.radios.icheck', [
'name' => 'delivery_id',
'val' => $delivery['id'],
'value' => (int) old('delivery_id') === $delivery['id'] ? $delivery['id'] : null,
'value' => $preselectedDeliveryId,
'id' => 'delivery_' . $delivery['id'],
'class' => 'delivery_mode' . ($delivery['at_house'] ? ' at_house' : ''),
])
@@ -29,16 +39,29 @@ ci-contre
@push('js')
<script>
function handleDeliveries() {
$('#delivery_mode input.delivery_mode').change(function() {
if ($(this).hasClass('at_house')) {
var $deliveryInputs = $('#delivery_mode input.delivery_mode');
$deliveryInputs.change(function() {
var $currentDelivery = $(this);
var deliveryTypeId = $('input[name=delivery_type_id]:checked').val();
if ($currentDelivery.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();
var deliveryId = $currentDelivery.val();
refreshBasketTotal(deliveryId, deliveryTypeId);
});
var $preselected = $deliveryInputs.filter(':checked').first();
if ($preselected.length) {
$preselected.trigger('change');
} else {
$('#delivery_addresses').closest('.card').addClass('d-none');
}
}
handleDeliveries();

View File

@@ -7,7 +7,18 @@
</th>
</tr>
</thead>
@foreach ($delivery_types as $delivery_type_id => $delivery_type)
@php
$deliveryTypes = collect($delivery_types);
$preselectedDeliveryTypeId = old('delivery_type_id');
if ($preselectedDeliveryTypeId === null || $preselectedDeliveryTypeId === '') {
$preselectedDeliveryTypeId = $deliveryTypes->keys()->first();
}
$deliveryTypes = $deliveryTypes->all();
@endphp
@foreach ($deliveryTypes as $delivery_type_id => $delivery_type)
<tr>
<td>
@include('components.form.radios.icheck', [
@@ -15,6 +26,7 @@
'val' => $delivery_type_id,
'id' => 'delivery_type_' . $delivery_type_id,
'class' => 'delivery_type',
'value' => $preselectedDeliveryTypeId,
])
</td>
<td>
@@ -31,11 +43,19 @@
@push('js')
<script>
function handleDeliveryTypes() {
$('input.delivery_type').change(function() {
var $deliveryTypeInputs = $('input.delivery_type');
$deliveryTypeInputs.change(function() {
var deliveryTypeId = $(this).val();
var deliveryId = $('input[name=delivery_id]:checked').val()
refreshBasketTotal(deliveryId, deliveryTypeId);
});
var $preselected = $deliveryTypeInputs.filter(':checked').first();
if ($preselected.length) {
$preselected.trigger('change');
}
}
handleDeliveryTypes();
</script>

View File

@@ -17,6 +17,7 @@
<link rel="shortcut icon" type="image/x-icon" href="{{ asset('img/favicon.ico') }}">
<link rel="stylesheet" href="/css/site.min.css?{{ date('Ymd') }}" type="text/css" media="all">
@stack('styles')
@stack('css')
</head>

View File

@@ -16,11 +16,27 @@
@push('js')
<script>
$(function() {
const articleShowUrlTemplate = "{{ route('Shop.Articles.show', ['id' => '__ARTICLE_ID__']) }}";
$('#search-general .fa-search').click(function() {
$('#search-general').submit();
});
initAutocomplete('#search_name');
function redirectToArticle(item, evt) {
if (!item || typeof item.value === 'undefined' || item.value === null || item.value === '') {
return;
}
if (evt) {
evt.preventDefault();
evt.stopPropagation();
}
const targetUrl = articleShowUrlTemplate.replace('__ARTICLE_ID__', item.value);
window.location.href = targetUrl;
}
initAutocomplete('#search_name', redirectToArticle);
});
</script>
@endpush

View File

@@ -13,9 +13,10 @@
var id = item.value;
$('#' + field).val(id);
if (typeof(callback) != 'undefined') {
var c = callback + '(' + id + ')';
eval(c);
if (typeof callback === 'function') {
callback.call(this, item, evt);
} else if (typeof callback === 'string' && callback.length && typeof window[callback] === 'function') {
window[callback].call(this, item, evt);
}
});
}

View File

@@ -38,7 +38,8 @@
/<(p|a|div|span|strike|strong|i|u)[^>]*?>(\s|&nbsp;|<br\/>|\r|\n)*?<\/(p|a|div|span|strike|strong|i|u)>/gi,
''); // Empty tags
},
skin: "boilerplate",
skin: "oxide",
content_css: 'oxide',
language: '{{ App::getLocale() }}',
file_picker_callback: function(callback, value, meta) {
var x = window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName(

View File

@@ -3,5 +3,4 @@
Route::prefix('CustomerInvoices')->name('CustomerInvoices.')->group(function () {
Route::get('', 'CustomerInvoiceController@index')->name('index');
Route::delete('destroy/{id?}', 'CustomerInvoiceController@destroy')->name('destroy');
Route::get('view/{id?}', 'CustomerInvoiceController@view')->name('view');
});

View File

@@ -7,5 +7,6 @@ Route::prefix('Clients')->name('Customers.')->group(function () {
Route::get('edit', 'CustomerController@edit')->name('edit');
Route::post('storeProfileAjax', 'CustomerController@storeProfileAjax')->name('storeProfileAjax');
Route::post('store', 'CustomerController@store')->name('store');
Route::get('delete_address/{$id?}', 'CustomerController@delete_address')->name('delete_address');
Route::post('address', 'CustomerController@storeAddress')->name('address.store');
Route::get('delete_address/{id}', 'CustomerController@delete_address')->name('delete_address');
});