]> _ Git - pmi.git/commitdiff
wip #5788 @0:30
authorsoufiane <soufiane@cubedesigners.com>
Tue, 20 Jun 2023 09:23:44 +0000 (11:23 +0200)
committersoufiane <soufiane@cubedesigners.com>
Tue, 20 Jun 2023 09:23:44 +0000 (11:23 +0200)
app/Http/Controllers/Admin/SelectionCrudController.php
app/Http/Controllers/AjaxController.php
app/Http/Controllers/Client/ClientController.php [new file with mode: 0644]
app/Models/Cart.php [new file with mode: 0644]
app/Models/CommandPanierSchema.php [deleted file]
app/Models/ECommerceCommon.php [new file with mode: 0644]
app/Models/Order.php
app/Models/Panier.php [deleted file]
app/Templates/PaniersEnregistres.php
resources/views/partials/nav-account.blade.php
resources/views/vendor/notifications/email.blade.php

index 12b23ca5d65b0f882095103326dd02bc2016a864..6ba5621f59674bfcb1a058d6d0284f3f480a7f46 100644 (file)
@@ -4,9 +4,9 @@ namespace App\Http\Controllers\Admin;
 
 class SelectionCrudController extends \Cubist\Backpack\app\Magic\Controllers\CubistMagicController
 {
-    protected $_modelNamespace = 'App\Models\Panier';
+    protected $_modelNamespace = 'App\Models\Cart';
     protected $_routeURL = 'selection';
-    protected $_singular = 'Panier';
+    protected $_singular = 'Cart';
     protected $_plural = 'PaniersEnregistres';
     protected $_clonable = true;
     protected $_bulk = true;
index 510aa0225d7d03af2574187f24b51877d41abab7..4bcc69f27ba06196d4e286a66a56a184742f52a3 100644 (file)
@@ -3,7 +3,7 @@
 namespace App\Http\Controllers;
 
 use App\Models\Order;
-use App\Models\Panier;
+use App\Models\Cart;
 use Cubist\Backpack\Facades\App;
 use App\Models\Page;
 use App\Models\Product;
@@ -598,31 +598,31 @@ class AjaxController extends CubistFrontController
         $lastCartId = $request->session()->get('last_selection');
 
         //
-        $lastCartRefs = $lastCartId ? Panier::find($lastCartId)->getReferences() : [];
-        $currentCartRef = Panier::getRefs($data['products']);
+        $lastCartRefs = $lastCartId ? Cart::find($lastCartId)->getReferences() : [];
+        $currentCartRef = Cart::getRefs($data['products']);
         $intersect = $lastCartRefs ? array_intersect($currentCartRef,$lastCartRefs) : [];
 
         $data['products'] = json_encode($data['products']);
         $ids = Product::getProductIds($data);
         $productsInfosBase = Product::getProductsByIds($ids);
-        $currentCartRef = Panier::getRefs(json_decode($data['products'],true));
+        $currentCartRef = Cart::getRefs(json_decode($data['products'],true));
         $data['products'] = json_decode($data['products'], true);
 
         /**
          *
          */
-        $data = Panier::fillData($currentCartRef, $data, $productsInfosBase,false);
+        $data = Cart::fillData($currentCartRef, $data, $productsInfosBase,false);
 
         if(sizeof($lastCartRefs) !== sizeof($intersect) ||
             (sizeof($lastCartRefs) === sizeof($intersect) && sizeof($currentCartRef) != sizeof($lastCartRefs)) ) {
-            $panier = Panier::firstOrCreate($data);
+            $panier = Cart::firstOrCreate($data);
             $panier->save();
             // Save back to the session with the latest cart id
             $id = $panier->getOriginal('id');
             $request->session()->put('last_selection', $id);
         } else {
 
-            Panier::where('id', $lastCartId)->update($data);
+            Cart::where('id', $lastCartId)->update($data);
         }
 
         return __('Le panier a été enregistré avec succès !');
@@ -634,7 +634,7 @@ class AjaxController extends CubistFrontController
         ]);
         $id = $request->input('id');
 
-        $cart = Panier::find($id);
+        $cart = Cart::find($id);
 
         $cart->delete();
     }
@@ -647,7 +647,7 @@ class AjaxController extends CubistFrontController
         $id = $request->input('id');
         $newName = $request->input('text');
 
-        $cart = Panier::find($id);
+        $cart = Cart::find($id);
         $cart->name = $newName;
         $cart->save();
     }
@@ -659,16 +659,16 @@ class AjaxController extends CubistFrontController
 
         $cartId = $request->input('id');
 
-        $cart = Panier::find($cartId)->toArray();
+        $cart = Cart::find($cartId)->toArray();
         $ids = Product::getProductIds($cart);
         $productsInfosBase = Product::getProductsByIds($ids);
 
         $clientIdInRequest = intval($cart['user_id']);
         $clientId = Client::getClientConnected()->id;
-        $currentCartRef = Panier::getRefs(json_decode($cart['products'],true));
+        $currentCartRef = Cart::getRefs(json_decode($cart['products'],true));
 
         $cart['products'] = json_decode($cart['products'], true);
-        $data = Panier::updateCartData($currentCartRef,$cart,$productsInfosBase);
+        $data = Cart::updateCartData($currentCartRef,$cart,$productsInfosBase);
 
         if($clientIdInRequest === $clientId) {
             $cartData = $data['products'];
@@ -698,7 +698,7 @@ class AjaxController extends CubistFrontController
         $data['products'] = json_decode($data['products'], true);
 
         $productsInfosBase = Product::getProductsByIds($ids);
-        $currentCartRef = Panier::getRefs($data['products']);
+        $currentCartRef = Cart::getRefs($data['products']);
 
         $data = Order::fillData($currentCartRef,$data,$productsInfosBase);
 
@@ -721,9 +721,9 @@ class AjaxController extends CubistFrontController
         $data['products'] = json_encode($cart);
         $ids = Product::getProductIds($data);
         $productsInfosBase = Product::getProductsByIds($ids);
-        $currentCartRef = Panier::getRefs(json_decode($data['products'],true));
+        $currentCartRef = Cart::getRefs(json_decode($data['products'],true));
         $data['products'] = json_decode($data['products'], true);
-        $data = Panier::fillData($currentCartRef, $data, $productsInfosBase,false);
+        $data = Cart::fillData($currentCartRef, $data, $productsInfosBase,false);
         $update = json_decode($data['products'],true);
 
         $request->session()->forget('cart_items');
diff --git a/app/Http/Controllers/Client/ClientController.php b/app/Http/Controllers/Client/ClientController.php
new file mode 100644 (file)
index 0000000..905be08
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+namespace App\Http\Controllers\Client;
+
+use App\Models\Client;
+use Illuminate\Http\Request;
+use Illuminate\Http\RedirectResponse;
+use Illuminate\Support\Facades\Auth;
+use Cubist\Backpack\app\Http\Controllers\CubistPageController;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Hash;
+use Illuminate\Support\Facades\Password;
+
+class ClientController extends CubistPageController
+{
+    public function logout(Request $request): RedirectResponse
+    {
+        Auth::guard('web-clients')->logout();
+        $request->session()->invalidate();
+        $request->session()->regenerateToken();
+        return redirect('/se-connecter');
+    }
+}
diff --git a/app/Models/Cart.php b/app/Models/Cart.php
new file mode 100644 (file)
index 0000000..0e5fc37
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+
+namespace App\Models;
+
+class Cart extends ECommerceCommon
+{
+    protected $table = 'cart';
+
+    protected $_options = ['name' => 'cart',
+        'singular' => 'Cart',
+        'plural' => 'Carts'];
+
+    public function setFields()
+    {
+        parent::setFields();
+
+        foreach ($this->fields as $fields) {
+            $fields['tab'] = 'Informations';
+            $this->addField($fields);
+        }
+
+        $this->addField(['name' => 'name',
+            'type' => 'Text',
+            'label' => 'Nom',
+            'column' => true
+        ]);
+    }
+
+    protected function getAllByUserId()
+    {
+        $items = parent::getAllByUserId();
+        $allProducts = array_map(function($n){ return json_decode($n['products'], true); }, $items);
+
+        $idsProducts = Product::getProductIds($items);
+        $productsInfosBase = Product::getProductsByIds($idsProducts);
+
+        foreach ($allProducts as $key => $products){
+            $data['products'] = $products;
+            $currentCartRef = self::getRefs($data['products']);
+            $data = self::updateCartData($currentCartRef,$data,$productsInfosBase);
+            $items[$key]['products'] = json_encode($data['products']);
+            $items[$key]['total'] = $data['total'];
+        }
+        return $items;
+    }
+
+    public static function getRefs($products) {
+        $refs = array_map(function ($n) {
+            return $n["ref"] ?? $n["reference"];
+        }, $products);
+
+        return $refs;
+    }
+
+    public function getReferences(){
+        $panier = $this->toArray();
+        $products = json_decode($panier['products'], true);
+
+        $refs = self::getRefs($products);
+
+        return $refs;
+    }
+}
diff --git a/app/Models/CommandPanierSchema.php b/app/Models/CommandPanierSchema.php
deleted file mode 100644 (file)
index e9455a4..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-<?php
-
-namespace App\Models;
-
-use Cubist\Backpack\app\Magic\Models\CubistMagicAbstractModel;
-
-class CommandPanierSchema extends CubistMagicAbstractModel
-{
-    protected $fields = [
-        [
-            'name' => 'user_id',
-            'label' => 'user_id',
-            'type' => 'Text',
-            'column' => true
-        ],
-        [
-            'name' => 'addresses',
-            'label' => 'Adresses',
-            'type' => 'Text',
-            'column' => true
-        ],
-        [
-            'name' => 'products',
-            'label' => 'Produits',
-            'type' => 'Text',
-            'column' => true
-        ],
-        [
-            'name' => 'total',
-            'type' => 'Text'
-        ]
-    ];
-
-
-    protected function getAllByUserId() {
-        $userID = Client::getClientConnected()->id;
-        return self::all()->where('user_id', $userID)->toArray();
-    }
-
-    public static function updateCartData($currentCartRef,$data = [], $productsInfosBase = []) {
-        $opt = [];
-        $total = [];
-
-        /*
-         *
-         * Recalculate option prices
-         * and store the result in an array like
-         * ["first_ref" => [5,30,45,...], "second_ref" => [...], ... ]
-         *
-         */
-        foreach ($currentCartRef as $keyRefs => $refs) {
-            $index = $data['products'][$keyRefs]['id'];
-            if($productsInfosBase[$index][0]['json']) {
-                $options = json_decode($productsInfosBase[$index][0]['json'], true);
-                foreach (explode("/", $refs) as $key => $ref) {
-                    $key -= 1;
-                    if ($key > -1) {
-                        $options_ = $options[$key]['options'];
-                        foreach ($options_ as $opt_) {
-                            if ($opt_["ref"] === $ref) {
-                                $opt[$refs][] = $opt_["sale_price"] ?? 0;
-                            }
-                        }
-                    }
-                }
-            }
-
-            $categoryProduct = $productsInfosBase[$index][0]['category'];
-            $discount = intval(Client::getDiscount($categoryProduct));
-            $quantity = intval($data['products'][$keyRefs]["quantity"]);
-            $basicSellingPrice = $productsInfosBase[$index][0]['basic_selling_price'] ?? 0;
-
-            $totalOptionPrices = $basicSellingPrice ? array_reduce($opt[$refs], function ($carry, $item) {
-                return $carry + $item;
-            }) : 0;
-
-            $price = floatval($basicSellingPrice + $totalOptionPrices);
-            $priceWithDiscount = ($price - (($price * $discount) / 100));
-            $total[] = str_replace(',','.',$priceWithDiscount * $quantity);
-
-            $data['products'][$keyRefs]['discount'] = $discount;
-            $data['products'][$keyRefs]["basic_selling_price"] = $basicSellingPrice;
-            $data['products'][$keyRefs]["price"] = $price;
-        }
-
-        $unavailableEcommerceProduct = array_filter($data['products'], function($n) {
-            return !$n['price'] || $n['price'] <= 0;
-        });
-
-        $ht = array_reduce($total, function($carry, $item) { return $carry + $item; });
-        $ht += ($ht > 1000) ? 20 : 0;
-        $tva = $ht * 0.2;
-        $ttc = $ht + $tva;
-        $data['total'] = !$unavailableEcommerceProduct ? number_format($ttc,2) : null;
-
-        return $data;
-    }
-
-    public static function fillData($currentCartRef, $data, $productsInfosBase, $haveStatus = true) {
-        $data = self::updateCartData($currentCartRef,$data,$productsInfosBase);
-
-        if(isset($data['addresses']))
-            $data['addresses'] = json_encode($data['addresses']);
-
-        if($haveStatus)
-            $data['status'] = 'new';
-
-        $data['products'] = json_encode($data['products']);
-
-        return $data;
-    }
-}
diff --git a/app/Models/ECommerceCommon.php b/app/Models/ECommerceCommon.php
new file mode 100644 (file)
index 0000000..a3c5fb8
--- /dev/null
@@ -0,0 +1,112 @@
+<?php
+
+namespace App\Models;
+
+use Cubist\Backpack\app\Magic\Models\CubistMagicAbstractModel;
+
+class ECommerceCommon extends CubistMagicAbstractModel
+{
+    protected $fields = [
+        [
+            'name' => 'user_id',
+            'label' => 'user_id',
+            'type' => 'Text',
+            'column' => true
+        ],
+        [
+            'name' => 'addresses',
+            'label' => 'Adresses',
+            'type' => 'Text',
+            'column' => true
+        ],
+        [
+            'name' => 'products',
+            'label' => 'Produits',
+            'type' => 'Text',
+            'column' => true
+        ],
+        [
+            'name' => 'total',
+            'type' => 'Text'
+        ]
+    ];
+
+
+    protected function getAllByUserId() {
+        $userID = Client::getClientConnected()->id;
+        return self::all()->where('user_id', $userID)->toArray();
+    }
+
+    public static function updateCartData($currentCartRef,$data = [], $productsInfosBase = []) {
+        $opt = [];
+        $total = [];
+
+        /*
+         *
+         * Recalculate option prices
+         * and store the result in an array like
+         * ["first_ref" => [5,30,45,...], "second_ref" => [...], ... ]
+         *
+         */
+        foreach ($currentCartRef as $keyRefs => $refs) {
+            $index = $data['products'][$keyRefs]['id'];
+            if($productsInfosBase[$index][0]['json']) {
+                $options = json_decode($productsInfosBase[$index][0]['json'], true);
+                foreach (explode("/", $refs) as $key => $ref) {
+                    $key -= 1;
+                    if ($key > -1) {
+                        $options_ = $options[$key]['options'];
+                        foreach ($options_ as $opt_) {
+                            if ($opt_["ref"] === $ref) {
+                                $opt[$refs][] = $opt_["sale_price"] ?? 0;
+                            }
+                        }
+                    }
+                }
+            }
+
+            $categoryProduct = $productsInfosBase[$index][0]['category'];
+            $discount = intval(Client::getDiscount($categoryProduct));
+            $quantity = intval($data['products'][$keyRefs]["quantity"]);
+            $basicSellingPrice = $productsInfosBase[$index][0]['basic_selling_price'] ?? 0;
+
+            $totalOptionPrices = $basicSellingPrice ? array_reduce($opt[$refs], function ($carry, $item) {
+                return $carry + $item;
+            }) : 0;
+
+            $price = floatval($basicSellingPrice + $totalOptionPrices);
+            $priceWithDiscount = ($price - (($price * $discount) / 100));
+            $total[] = str_replace(',','.',$priceWithDiscount * $quantity);
+
+            $data['products'][$keyRefs]['discount'] = $discount;
+            $data['products'][$keyRefs]["basic_selling_price"] = $basicSellingPrice;
+            $data['products'][$keyRefs]["price"] = $price;
+        }
+
+        $unavailableEcommerceProduct = array_filter($data['products'], function($n) {
+            return !$n['price'] || $n['price'] <= 0;
+        });
+
+        $ht = array_reduce($total, function($carry, $item) { return $carry + $item; });
+        $ht += ($ht > 1000) ? 20 : 0;
+        $tva = $ht * 0.2;
+        $ttc = $ht + $tva;
+        $data['total'] = !$unavailableEcommerceProduct ? number_format($ttc,2) : null;
+
+        return $data;
+    }
+
+    public static function fillData($currentCartRef, $data, $productsInfosBase, $haveStatus = true) {
+        $data = self::updateCartData($currentCartRef,$data,$productsInfosBase);
+
+        if(isset($data['addresses']))
+            $data['addresses'] = json_encode($data['addresses']);
+
+        if($haveStatus)
+            $data['status'] = 'new';
+
+        $data['products'] = json_encode($data['products']);
+
+        return $data;
+    }
+}
index 7f9afb243cac2ad08a4be12c4f4b43a46977a838..e13d09f0091b4a0bd7938bf07e8974610c647a8d 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 namespace App\Models;
 
-class Order extends CommandPanierSchema
+class Order extends ECommerceCommon
 {
     protected $table = 'order';
 
diff --git a/app/Models/Panier.php b/app/Models/Panier.php
deleted file mode 100644 (file)
index abe060e..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-<?php
-
-namespace App\Models;
-
-class Panier extends CommandPanierSchema
-{
-    protected $table = 'selection';
-
-    protected $_options = ['name' => 'selection',
-        'singular' => 'Panier',
-        'plural' => 'PaniersEnregistres'];
-
-    public function setFields()
-    {
-        parent::setFields();
-
-        foreach ($this->fields as $fields) {
-            $fields['tab'] = 'Informations';
-            $this->addField($fields);
-        }
-
-        $this->addField(['name' => 'name',
-            'type' => 'Text',
-            'label' => 'Nom',
-            'column' => true
-        ]);
-    }
-
-    protected function getAllByUserId()
-    {
-        $items = parent::getAllByUserId();
-        $allProducts = array_map(function($n){ return json_decode($n['products'], true); }, $items);
-
-        $idsProducts = Product::getProductIds($items);
-        $productsInfosBase = Product::getProductsByIds($idsProducts);
-
-        foreach ($allProducts as $key => $products){
-            $data['products'] = $products;
-            $currentCartRef = self::getRefs($data['products']);
-            $data = self::updateCartData($currentCartRef,$data,$productsInfosBase);
-            $items[$key]['products'] = json_encode($data['products']);
-            $items[$key]['total'] = $data['total'];
-        }
-        return $items;
-    }
-
-    public static function getRefs($products) {
-        $refs = array_map(function ($n) {
-            return $n["ref"] ?? $n["reference"];
-        }, $products);
-
-        return $refs;
-    }
-
-    public function getReferences(){
-        $panier = $this->toArray();
-        $products = json_decode($panier['products'], true);
-
-        $refs = self::getRefs($products);
-
-        return $refs;
-    }
-}
index 2687c084a3e7fcfc3528929a85b95f2d47470960..b5927192911ec6215fde615a98de94e339fdbed3 100644 (file)
@@ -4,7 +4,7 @@
 namespace App\Templates;
 
 
-use App\Models\Panier;
+use App\Models\Cart;
 
 class PaniersEnregistres extends Base
 {
@@ -15,7 +15,7 @@ class PaniersEnregistres extends Base
 
     public function setData(&$data)
     {
-        $data["items"] = Panier::getAllByUserId();
+        $data["items"] = Cart::getAllByUserId();
     }
 
     public function init()
index 074871ebf284e6806c770b8f9738abc1f443bb41..15bee739358496b50e4f076688be101e6928a276 100644 (file)
@@ -19,7 +19,7 @@
         </li>
         <li class="{{ Request::is('paniers-enregistres') ? "active" : '' }}">
             <a href="/paniers-enregistres">
-                <span>{{ __('Panier enregistrés') }}</span>
+                <span>{{ __('Paniers enregistrés') }}</span>
             </a>
         </li>
         <li>
index 05be6cd95e1a7c2122a6bde7f69b5da87850dd15..01671dab39a0f7b3ceddd280960e36c252cbe877 100644 (file)
@@ -53,8 +53,8 @@
 @slot('subcopy')
 
 @lang(
-    ":text1 \":actionText\" :text2".
-    ':text3 [:actionURL](:actionURL)',
+    ":text1 \":actionText\" :text2 ".
+    ":text3 [:actionURL](:actionURL)",
     [
         'text1' => trans('mail.footer_part1'),
         'text2' => trans('mail.footer_part2'),