]> _ Git - pmi.git/commitdiff
wip #5850 @7:30
authorsoufiane <soufiane@cubedesigners.com>
Wed, 5 Apr 2023 17:07:15 +0000 (19:07 +0200)
committersoufiane <soufiane@cubedesigners.com>
Wed, 5 Apr 2023 17:07:15 +0000 (19:07 +0200)
app/Http/Controllers/Admin/ProductBaseController.php
app/Http/Controllers/ProductController.php
app/Models/Product.php
resources/js/app.js
resources/js/components/Configurator.vue [new file with mode: 0644]
resources/styles/components/product-details.styl
resources/views/components/cart-add.blade.php
resources/views/pages/category.blade.php
resources/views/pages/product-detail.blade.php
resources/views/pages/products.blade.php
tailwind.config.js

index 31c547c1bdd0bcba75d5f31d92bed9e37d4467c3..c557d65b2f472b42aa78ff4258802aafa675dc29 100644 (file)
@@ -208,7 +208,7 @@ class ProductBaseController extends CubistMagicController {
         $contents = $datas['resume']. "\n";
         $contents .= "Details : \r\n\n";
         foreach ($datas['details'] as $filename => $values ) {
-            $contents .= $filename."\r\n";
+            $contents .= "Fichier $filename \r\n";
             foreach ($values as $product => $value) {
                 $contents .= "> $product : $value \r\n";
             }
index dc8481c8278fb7fca69a3846168d5ef4a1489712..3527e3a55f2912e575adc6ad1654191e0baa39a1 100644 (file)
@@ -59,9 +59,4 @@ class ProductController extends CubistFrontController
         }
         return view('pages.product-detail', $this->data);
     }
-
-
-    public function excelToJson($file){
-
-    }
 }
index 3cd479b0df773807c8c7791a7fa78a88ebae1d84..8c8bf97b6297ae5e9a00f6de8c36a16c484bb094 100644 (file)
@@ -548,7 +548,6 @@ class Product extends CubistMagicPageModel
                 $values = [];
 
                 foreach ($products as $product) {
-
                     $pv = $product->get($spec_name);
 
                     if (is_array($pv) && $data->type === 'list') {
@@ -598,17 +597,21 @@ class Product extends CubistMagicPageModel
                 }
                 $f['options'] = $options;
             } else if ($data->type === 'numeric' || $data->type === 'range' || $data->type === 'numeric_list') {
-                $f['min'] = INF;
-                $f['max'] = -INF;
-                $f['unit'] = $data->unit;
-                $f['type'] = 'range';
-                $f['scale'] = $data->logarithmic_scale ? 'log' : 'linear';
-
-                if ($data->type === 'numeric' || $data->type === 'numeric_list') {
-                    $f['prefix'] = $data['prefix'];
-                } else {
-                    $f['prefix'] = '';
-                }
+                //$checkV = array_filter($products, function($n) use($spec_name) { return $n->get($spec_name) !== null; });
+
+                //if($checkV) {
+                    $f['min'] = INF;
+                    $f['max'] = -INF;
+                    $f['unit'] = $data->unit;
+                    $f['type'] = 'range';
+                    $f['scale'] = $data->logarithmic_scale ? 'log' : 'linear';
+
+                    if ($data->type === 'numeric' || $data->type === 'numeric_list') {
+                        $f['prefix'] = $data['prefix'];
+                    } else {
+                        $f['prefix'] = '';
+                    }
+                //}
 
                 foreach ($products as $product) {
                     $v = $product->get($spec_name);
@@ -618,7 +621,6 @@ class Product extends CubistMagicPageModel
                         continue;
                     }
 
-
                     if (null !== $filter_value) {
                         $fvmax = $filter_value[1];
                         $fvmin = $filter_value[0];
index 472fa798a5addb9715da1704e6ba0ce87d39574f..ac305c0f804b094e3b565df174d267080c4037a6 100644 (file)
@@ -76,7 +76,12 @@ const app = new Vue({
         errorsForm: {},
         user: '',
         default_billing_address: null,
-        default_delivery_address: null
+        default_delivery_address: null,
+        //
+        price: '',
+        ref: '',
+        statusConfig: false,
+        statusText: ''
     },
 
     beforeMount() {
@@ -102,6 +107,9 @@ const app = new Vue({
                 id: id
             });
         });
+
+        this.price = this.$refs.optprice ?.dataset.default
+        this.statusText = this.$refs.statusConfig ?.dataset.incomplete
     },
 
     watch: {
@@ -402,6 +410,30 @@ const app = new Vue({
                 .catch(function (error) {
                 }
             )
+        },
+        /**
+         *
+         */
+        changePrice() {
+            let options = [];
+            const selectOptions = document.querySelectorAll(".opt-select")
+
+            selectOptions.forEach(function(e, i) {
+                options.push(e.selectedOptions[0])
+            })
+
+            let prices = options.map(opt => parseFloat(opt.dataset.price)).filter(n => !isNaN(n)),
+                refs = options.map(opt => opt.dataset.ref).filter(n => n !== undefined).join("/")
+
+            if(prices.length === selectOptions.length) {
+                this.statusConfig = true
+                this.statusText = this.$refs.statusConfig.dataset.completed
+            }
+
+            let total = prices.reduce((init, current) => init + current)
+
+            this.ref = refs
+            this.price = total + parseFloat(this.$refs.optprice.dataset.default)
         }
     },
     /**
diff --git a/resources/js/components/Configurator.vue b/resources/js/components/Configurator.vue
new file mode 100644 (file)
index 0000000..fa35921
--- /dev/null
@@ -0,0 +1,13 @@
+<script>
+    export default {
+        data() {
+            return {
+                price: ''
+            }
+        },
+
+        methods: {
+
+        }
+    }
+</script>
index 5b2ef4c4fc630b2f20657caa323f40da4a040f46..8a27bec095b709bd84e442d8f55a448953bf0209 100644 (file)
@@ -1,5 +1,9 @@
 .product-detail
 
+  .text-block-body
+    max-width: 570px
+    width: 100%
+
   &-specifications
     display: block
     width: 100%
       dd
         width: 40%
         max-width: 400px
+
+.opt
+  &-group:not(:last-of-type)
+    margin-bottom: 12px
+
+  &-select
+    display: block
+    width: 100%
+    outline: 2px solid transparent
+    outline-offset: 2px
+    border-width: 1px
+    border-color: rgba(247, 248, 252, 1)
+    color: theme('colors.grey.dark')
+    border-radius: 0.25rem
+    padding: 15px 20px
+    appearance: none
+    background: url(/images/icon-angle-down.svg) no-repeat right #fff
+    background-position-x: calc(100% - 20px)
index dc5aa01aa93da9fcb44c7faa7363914381bcf8c9..61591be7b5acc52ed77e9f04f23d6e16c48f5ae0 100644 (file)
@@ -1,7 +1,11 @@
-<button data-product-id="{{ $id }}" class="btn cart-add">
+<button data-product-id="{{ $id }}" class="btn cart-add" :class="{ 'pointer-events-none bg-grey-disabled' : price && !statusConfig }">
         <span class="btn-text relative">
             <span class="add">
-               {{ __('Ajouter à ma sélection') }}
+                @if(isset($price))
+                    {{ __('Ajouter au panier') }}
+                @else
+                    {{ __('Ajouter à ma sélection') }}
+                @endif
             </span>
             <span class="added absolute top-0 left-0 w-full h-full flex items-center justify-ce hidden" style="top:-2px">
                 @svg('tick', 'w-4 mr-3 mt-1 inline absolute left-0') <span>{{ __('Produit ajouté') }}</span>
index aee44625b5eb330af76e4fcdabeddc9249d57456..98585beaa537f17a61e07ca7f62585771f3463cf 100644 (file)
@@ -1,5 +1,9 @@
 @extends('layouts/app')
 
+@php
+//    dd(json_encode($filters, JSON_THROW_ON_ERROR),json_encode($filter_results));
+@endphp
+
 @section('content')
 
     @intro(['padding' => 'pb-1v'])
index d16ff2f9652486b3e5a49c3668a8fe1808d803ae..d2d475292358a68bc2fdd7d39ea4a8320d43ab63 100644 (file)
@@ -1,5 +1,6 @@
 @php
     $technical_sheet = $product->getMediaUrl('technical_sheet', false);
+    $specs = $product->json;
 @endphp
 
 @extends('layouts/app')
@@ -26,7 +27,7 @@
             @include('partials.product-gallery')
 
             {{-- Product text --}}
-            <text-block class="product-detail-text sm:mt-6">
+            <text-block class="product-detail-text sm:mt-6 flex-auto">
                 <div class="mb-6">
                     @markdown($product->highlights)
                 </div>
                     </p>
                 @endif
 
+                @guest('web-clients')
+                    @if($product->basic_selling_price)
+                        <div class="mb-8">
+                            <div>{{ __('Connectez-vous à votre compte pour afficher les prix') }}</div>
+                            <a href="/se-connecter">{{ __('Se connecter') }}</a>
+                        </div>
+                    @endif
+                @endguest
+
+                @auth('web-clients')
+                    @if($product->basic_selling_price)
+                        <div class="opt-configurator bg-grey-200 p-12 mb-8">
+                            <div class="opt-group">
+                                @foreach($specs as $spec)
+                                    <div class="opt-group">
+                                        <label class="opt-name mb-2 inline-block">
+                                            {{  \Illuminate\Support\Str::ucfirst( $spec['name_fr']) }}
+                                        </label>
+                                        <div>
+                                            <select class="opt-select" v-on:change="changePrice">
+                                                <option selected disabled value="">Sélectionner</option>
+                                                @foreach($spec['options'] as $option)
+                                                    <option data-price="{{ $option['sale_price'] }}" data-ref="{{ $option['ref'] }}">
+                                                        {{ $option['name_fr'] }}
+                                                    </option>
+                                                @endforeach
+                                            </select>
+                                        </div>
+                                    </div>
+                                @endforeach
+                            </div>
+                        </div>
+                        <div class="opt-infos mb-8">
+                            <div class="opt-ref" v-cloak v-if="ref">{{ __('Référence') }} : <span id="opt-ref">@{{ ref }}</span></div>
+                            <div class="opt-price">
+                                {{ __('Prix unitaire') }} :
+                                <span id="opt-price" ref="optprice" v-cloak data-default="{{ $product->basic_selling_price }}">@{{ price }}</span>{{ "€ ".__('HT') }}
+                            </div>
+                            <div class="opt-statut">{{ __('Statut') }} :
+                                <span id="opt-statut" v-cloak :class="{ 'text-green' : statusConfig }" ref="statusConfig" data-incomplete="{{ __('La configuration est incomplète') }}" data-completed="{{ __('La configuration est complète') }}">
+                                    @{{ statusText }}
+                                </span>
+                            </div>
+                        </div>
+                    @endif
+                @endauth
 
                 @if(config('features.quote'))
-                    <cart-add :id="$product->id"></cart-add>
+                    <cart-add :id="$product->id" :price="$product->basic_selling_price"></cart-add>
                     <span
                         data-tooltip="{{__('Ajoutez un ou plusieurs produits à votre sélection, ajustez les quantités et obtenez un devis.')}}"
                         class="font-display text-lg inline-block align-middle rounded-full border-grey-dark border-2 h-8 w-8 text-center ml-6">?</span>
index 362b051e234261eae583e8081f76e3040247e445..ec53d151efa4374600830db664ca114f9d384fcd 100644 (file)
@@ -10,7 +10,7 @@
             @if ($filters && $filter_results)
                 <products-filters v-cloak
                                   :product-type="{{ $product_type->id }}"
-                                  :filter-data='@json($filters)'
+                                  :filter-data='JSON.parse($filters)'
                                   :result-data='@json($filter_results)'
                                   :translations='@json([
                                     'result' => __('résultat'),
index d435ecb3e003b0f18e72c48e4f19d469fad45ccb..14a84232dfa2e9a4a30102148dffd20216b5eb3e 100644 (file)
@@ -22,7 +22,9 @@ module.exports = {
                 'navy-dark': '#0C213A',
                 'red': '#F81E60',
                 'light-b': '#D5D7DF',
+                'green': '#369841',
                 'grey': {
+                    'disabled': '#B0B4C1',
                     '100': '#F7F8FC',
                     '200': '#EEF1F8',
                     '250': '#E7E9F3',