Compare commits
16 Commits
1.0.0-rc.1
...
1.0.0-rc.4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae7f8ed2c9 | ||
|
|
a3a86f4b2f | ||
|
|
9c081574c8 | ||
|
|
11edccad02 | ||
|
|
7c796802be | ||
|
|
5cc43bc889 | ||
|
|
f094411f10 | ||
|
|
ccc477f291 | ||
|
|
7217d945a3 | ||
|
|
9185269874 | ||
|
|
e42e3b4c0d | ||
|
|
a7ae946797 | ||
|
|
7a189abf0b | ||
|
|
34fc1c33bf | ||
|
|
61e34b4f4e | ||
|
|
7fe2770d45 |
@@ -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
|
||||
@@ -93,7 +94,8 @@ RUN mkdir -p /out \
|
||||
--exclude=.editorconfig --exclude=phpunit.xml \
|
||||
--exclude=.travis.yml --exclude=composer.lock --exclude=.styleci.yml \
|
||||
--exclude=Makefile --exclude=.gitkeep --exclude=test \
|
||||
artisan app build config database vendor public resources routes stubs bootstrap storage composer.json \
|
||||
--exclude=resources/shop \
|
||||
artisan app config database vendor public resources routes stubs bootstrap storage composer.json \
|
||||
&& xz -T0 -9e /out/app.tar \
|
||||
&& mv /out/app.tar.xz /out/opensem-prod.tar.xz
|
||||
|
||||
|
||||
48
Gruntfile.js
@@ -19,8 +19,8 @@ var jsSite = [
|
||||
jsBootstrap,
|
||||
'node_modules/jquery-serializejson/jquery.serializejson.min.js',
|
||||
'node_modules/currency.js/dist/currency.min.js',
|
||||
'build/js/plugins/smooth_products/js/smoothproducts.min.js',
|
||||
'build/js/site.js',
|
||||
'resources/shop/js/plugins/smooth_products/js/smoothproducts.min.js',
|
||||
'resources/shop/js/site.js',
|
||||
]
|
||||
|
||||
var cssSite = [
|
||||
@@ -28,8 +28,8 @@ var cssSite = [
|
||||
'node_modules/@fortawesome/fontawesome-free/css/all.min.css',
|
||||
'node_modules/animate.css/animate.min.css',
|
||||
'node_modules/icheck-bootstrap/icheck-bootstrap.min.css',
|
||||
'build/js/plugins/smooth_products/css/smoothproducts.css',
|
||||
'build/css/site.css',
|
||||
'resources/shop/js/plugins/smooth_products/css/smoothproducts.css',
|
||||
'resources/shop/css/site.css',
|
||||
]
|
||||
|
||||
var jsAdminLTE = [
|
||||
@@ -41,15 +41,15 @@ var jsAdminLTE = [
|
||||
]
|
||||
|
||||
var jsCoreInclude = [
|
||||
'build/js/include/core/objectLength.js',
|
||||
'build/js/include/core/url.js',
|
||||
'build/js/include/core/user.js',
|
||||
'build/js/include/form/radio.js',
|
||||
'build/js/include/form/upload.js',
|
||||
'build/js/include/form/validator.js',
|
||||
'build/js/include/layout/animate.js',
|
||||
'build/js/include/layout/scroll.js',
|
||||
'build/js/include/layout/tooltip.js',
|
||||
'resources/shop/js/include/core/objectLength.js',
|
||||
'resources/shop/js/include/core/url.js',
|
||||
'resources/shop/js/include/core/user.js',
|
||||
'resources/shop/js/include/form/radio.js',
|
||||
'resources/shop/js/include/form/upload.js',
|
||||
'resources/shop/js/include/form/validator.js',
|
||||
'resources/shop/js/include/layout/animate.js',
|
||||
'resources/shop/js/include/layout/scroll.js',
|
||||
'resources/shop/js/include/layout/tooltip.js',
|
||||
]
|
||||
|
||||
var jsBundle = [
|
||||
@@ -84,7 +84,7 @@ var jsMain = [
|
||||
var cssPrint = [
|
||||
// 'node_modules/bootstrap/dist/css/bootstrap.min.css',
|
||||
'cssIcons',
|
||||
'build/print.css'
|
||||
'resources/shop/print.css'
|
||||
]
|
||||
|
||||
var cssBundle = [
|
||||
@@ -109,7 +109,7 @@ var cssIcons = [
|
||||
var cssMain = [
|
||||
cssBundle,
|
||||
cssIcons,
|
||||
'build/css/main.css',
|
||||
'resources/shop/css/main.css',
|
||||
]
|
||||
|
||||
var jsDataTables = [
|
||||
@@ -251,31 +251,31 @@ module.exports = function(grunt) {
|
||||
},
|
||||
{
|
||||
expand: true,
|
||||
cwd: 'build/fonts',
|
||||
cwd: 'resources/shop/fonts',
|
||||
src: ['**'],
|
||||
dest: 'public/fonts/'
|
||||
},
|
||||
{
|
||||
expand: true,
|
||||
cwd: 'build/img',
|
||||
cwd: 'resources/shop/img',
|
||||
src: ['**'],
|
||||
dest: 'public/img/'
|
||||
},
|
||||
{
|
||||
expand: true,
|
||||
cwd: 'build/lang',
|
||||
cwd: 'resources/shop/lang',
|
||||
src: ['**'],
|
||||
dest: 'public/assets/lang/'
|
||||
},
|
||||
{
|
||||
expand: true,
|
||||
cwd: 'build/plugins',
|
||||
cwd: 'resources/shop/plugins',
|
||||
src: ['**'],
|
||||
dest: 'public/assets/plugins/'
|
||||
},
|
||||
{
|
||||
expand: true,
|
||||
cwd: 'build/assets/tpl',
|
||||
cwd: 'resources/shop/assets/tpl',
|
||||
src: ['**'],
|
||||
dest: 'public/assets/tpl/'
|
||||
},
|
||||
@@ -395,7 +395,7 @@ module.exports = function(grunt) {
|
||||
},
|
||||
{
|
||||
expand: true,
|
||||
cwd: 'build/plugins/pdfjs/',
|
||||
cwd: 'resources/shop/plugins/pdfjs/',
|
||||
src: ['**'],
|
||||
dest: 'public/assets/plugins/pdfjs',
|
||||
},
|
||||
@@ -461,7 +461,7 @@ module.exports = function(grunt) {
|
||||
},
|
||||
{
|
||||
expand: true,
|
||||
cwd: 'build/js/include/plugins/datatables_lang/',
|
||||
cwd: 'resources/shop/js/include/plugins/datatables_lang/',
|
||||
src: ['*.json'],
|
||||
dest: 'public/assets/plugins/datatables_lang',
|
||||
},
|
||||
@@ -539,7 +539,7 @@ module.exports = function(grunt) {
|
||||
},
|
||||
{
|
||||
expand: true,
|
||||
cwd: 'build/js/include/',
|
||||
cwd: 'resources/shop/js/include/',
|
||||
src: ['boilerplate.js'],
|
||||
dest: 'public/assets/plugins',
|
||||
},
|
||||
@@ -548,7 +548,7 @@ module.exports = function(grunt) {
|
||||
},
|
||||
watch: {
|
||||
dist: {
|
||||
files: ['build/js/*', 'build/css/*'],
|
||||
files: ['resources/shop/js/*', 'resources/shop/css/*'],
|
||||
// tasks: ['concat', 'copy']
|
||||
tasks: ['concat']
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Shop;
|
||||
use App\Repositories\Shop\CustomerAddresses;
|
||||
use App\Repositories\Shop\Customers;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
@@ -56,10 +57,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']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,9 @@ class InvoiceController extends Controller
|
||||
|
||||
public function pdf($uuid)
|
||||
{
|
||||
\Debugbar::disable();
|
||||
if (app()->bound('debugbar')) {
|
||||
app('debugbar')->disable();
|
||||
}
|
||||
|
||||
return InvoicePDF::getByUUID($uuid);
|
||||
}
|
||||
|
||||
@@ -3,13 +3,19 @@
|
||||
namespace App\Http\Controllers\Shop;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Repositories\Core\User\ShopCart;
|
||||
use App\Repositories\Shop\Paybox as PayboxGateway;
|
||||
use App\Repositories\Shop\Contents;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
|
||||
class PayboxController extends Controller
|
||||
{
|
||||
public function accepted()
|
||||
{
|
||||
ShopCart::clear();
|
||||
|
||||
return view('paybox.paybox', ['content' => Contents::getPayboxConfirmedContent()]);
|
||||
}
|
||||
|
||||
@@ -30,8 +36,20 @@ class PayboxController extends Controller
|
||||
|
||||
public function process(Request $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
$invoiceId = $request->input('order_number');
|
||||
|
||||
return view('paybox.send', $data);
|
||||
if (! $invoiceId) {
|
||||
Log::warning('Paybox callback missing order_number', ['payload' => $request->all()]);
|
||||
|
||||
return response('Missing order_number', 400);
|
||||
}
|
||||
|
||||
$success = PayboxGateway::verifyPayment($invoiceId);
|
||||
|
||||
if (! $success) {
|
||||
return response('KO', 400);
|
||||
}
|
||||
|
||||
return response('OK');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -95,6 +96,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 +113,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 +124,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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Invoice;
|
||||
use App\Models\Shop\InvoicePayment;
|
||||
use App\Repositories\Core\DateTime;
|
||||
use Bnb\PayboxGateway\Requests\Paybox\AuthorizationWithCapture;
|
||||
use Bnb\PayboxGateway\Requests\PayboxDirect\Capture;
|
||||
use Bnb\PayboxGateway\Responses\Exceptions\InvalidSignature;
|
||||
use Bnb\PayboxGateway\Responses\Paybox\Verify;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class Paybox
|
||||
@@ -23,17 +26,141 @@ class Paybox
|
||||
|
||||
public static function verifyPayment($invoiceId)
|
||||
{
|
||||
$invoice = Invoices::get($invoiceId);
|
||||
$payboxVerify = App::make(Verify::class);
|
||||
try {
|
||||
$success = $payboxVerify->isSuccess($invoice->total_shipped);
|
||||
if ($success) {
|
||||
// process order here after making sure it was real payment
|
||||
}
|
||||
echo 'OK';
|
||||
} catch (InvalidSignature $e) {
|
||||
Log::alert('Invalid payment signature detected');
|
||||
$invoice = Invoices::get($invoiceId, ['order']);
|
||||
|
||||
if (! $invoice) {
|
||||
Log::warning('Paybox callback received for unknown invoice', [
|
||||
'invoice_id' => $invoiceId,
|
||||
'payload' => request()->all(),
|
||||
]);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$payboxVerify = App::make(Verify::class);
|
||||
|
||||
try {
|
||||
$isSuccessful = $payboxVerify->isSuccess($invoice->total_shipped);
|
||||
} catch (InvalidSignature $e) {
|
||||
Log::alert('Invalid payment signature detected', [
|
||||
'invoice_id' => $invoiceId,
|
||||
'payload' => request()->except('signature'),
|
||||
]);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $isSuccessful) {
|
||||
Log::warning('Paybox payment verification failed', [
|
||||
'invoice_id' => $invoiceId,
|
||||
'response_code' => $payboxVerify->getResponseCode(),
|
||||
'payload' => request()->except('signature'),
|
||||
]);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return self::finalizeInvoicePayment($invoice);
|
||||
}
|
||||
|
||||
protected static function finalizeInvoicePayment(Invoice $invoice)
|
||||
{
|
||||
$order = $invoice->order;
|
||||
|
||||
if (! $order) {
|
||||
Log::error('Paybox payment cannot be finalized: missing related order', [
|
||||
'invoice_id' => $invoice->id,
|
||||
]);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$request = request();
|
||||
$referenceParts = array_filter([
|
||||
$request->input('call_number'),
|
||||
$request->input('transaction_number'),
|
||||
]);
|
||||
$reference = $referenceParts ? implode('-', $referenceParts) : $request->input('authorization_number');
|
||||
if (! $reference) {
|
||||
$reference = 'paybox-'.$invoice->id;
|
||||
}
|
||||
|
||||
$payload = $request->except('signature');
|
||||
$existingPayment = InvoicePayment::where('invoice_id', $invoice->id)
|
||||
->where('reference', $reference)
|
||||
->first();
|
||||
$shouldNotify = false;
|
||||
$validatedTotal = InvoicePayment::where('invoice_id', $invoice->id)
|
||||
->validated()
|
||||
->sum('amount');
|
||||
|
||||
if (! $existingPayment && (float) $validatedTotal >= (float) $invoice->total_shipped) {
|
||||
Log::info('Paybox payment ignored: invoice already fully settled', [
|
||||
'invoice_id' => $invoice->id,
|
||||
'order_id' => $order->id,
|
||||
'reference' => $reference,
|
||||
]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($invoice, $order, $reference, $payload, $existingPayment, &$shouldNotify) {
|
||||
$attributes = [
|
||||
'payment_type' => 1,
|
||||
'amount' => $invoice->total_shipped,
|
||||
'date' => DateTime::getDate(),
|
||||
'data' => json_encode($payload, JSON_UNESCAPED_UNICODE),
|
||||
'validated' => 1,
|
||||
];
|
||||
|
||||
if ($existingPayment) {
|
||||
$previousValidationState = (int) ($existingPayment->validated ?? 0);
|
||||
$existingPayment->fill($attributes);
|
||||
|
||||
if ($existingPayment->isDirty()) {
|
||||
$existingPayment->save();
|
||||
}
|
||||
|
||||
if ($previousValidationState !== 1 && (int) $existingPayment->validated === 1) {
|
||||
$shouldNotify = true;
|
||||
}
|
||||
} else {
|
||||
InvoicePayment::create($attributes + [
|
||||
'invoice_id' => $invoice->id,
|
||||
'reference' => $reference,
|
||||
]);
|
||||
$shouldNotify = true;
|
||||
}
|
||||
|
||||
Invoices::checkPayments($invoice->id);
|
||||
|
||||
$paidStatus = Orders::getStatusByName('Préparation');
|
||||
if ($paidStatus !== '' && (int) $order->status !== (int) $paidStatus) {
|
||||
$order->status = $paidStatus;
|
||||
$order->save();
|
||||
}
|
||||
});
|
||||
|
||||
if ($shouldNotify) {
|
||||
try {
|
||||
OrderMails::sendOrderConfirmed($order->id);
|
||||
} catch (\Throwable $exception) {
|
||||
Log::error('Unable to send order confirmation email after Paybox payment', [
|
||||
'order_id' => $order->id,
|
||||
'invoice_id' => $invoice->id,
|
||||
'exception' => $exception->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Log::info('Paybox payment finalized successfully', [
|
||||
'invoice_id' => $invoice->id,
|
||||
'order_id' => $order->id,
|
||||
'reference' => $reference,
|
||||
'notified' => $shouldNotify,
|
||||
]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getPreviousAuthorizedRequest($request)
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
// 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) {
|
||||
e.preventDefault();
|
||||
if ($(this).next('.submenu').length) {
|
||||
$(this).next('.submenu').toggle();
|
||||
}
|
||||
$('.dropdown').on('hide.bs.dropdown', function () {
|
||||
$(this).find('.submenu').hide();
|
||||
});
|
||||
});
|
||||
}
|
||||
0
resources/shop/assets/tpl/.gitkeep
Normal file
|
Before Width: | Height: | Size: 71 KiB After Width: | Height: | Size: 71 KiB |
|
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 70 KiB |
|
Before Width: | Height: | Size: 82 KiB After Width: | Height: | Size: 82 KiB |
|
Before Width: | Height: | Size: 69 KiB After Width: | Height: | Size: 69 KiB |
|
Before Width: | Height: | Size: 75 KiB After Width: | Height: | Size: 75 KiB |
BIN
resources/shop/img/favicon.ico
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 5.0 KiB After Width: | Height: | Size: 5.0 KiB |
|
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 43 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 48 KiB |
|
Before Width: | Height: | Size: 8.8 KiB After Width: | Height: | Size: 8.8 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 61 KiB |