$currentItem = false;
if($product) {
$categoryProduct = $product->category;
- $discount = \App\Models\Client::discountArray($categoryProduct);
+ $discount = \App\Models\Client::getDiscount($categoryProduct);
$currentItem = array_filter($cart_items, function ($n) use ($ref) {
return $n['ref'] === $ref;
});
$clientIdInRequest = intval($cart['user_id']);
$clientId = Client::getClientConnected()->id;
-
- $categoryClient = Client::getClientConnected()->discount ?? 'A';
$currentCartRef = Panier::getRefs(json_decode($cart['products'],true));
$cart['products'] = json_decode($cart['products'], true);
- $data = Panier::test($currentCartRef,$categoryClient,$cart,$productsInfosBase);
+ $data = Panier::updateCartData($currentCartRef,$cart,$productsInfosBase);
if($clientIdInRequest === $clientId) {
$cartData = $data['products'];
$request->session()->put('last_selection', intval($cartId));
return "success";
}
+
+ return false;
}
public function order(Request $request) {
$data['products'] = json_encode($data['products']);
$ids = Product::getProductIds($data);
+ $data['products'] = json_decode($data['products'], true);
+
$productsInfosBase = Product::getProductsByIds($ids);
$currentCartRef = Panier::getRefs(json_decode($data['products'],true));
- $data['products'] = json_decode($data['products'], true);
- $data = Command::fillData($currentCartRef, $data,$productsInfosBase);
-// dd($data);
+ $data = Command::fillData($currentCartRef,$data,$productsInfosBase);
if($data) {
$order = Command::create($data);
$order->save();
}else{
- abort('422', 'Data are empty');
+ abort('422', 'Datas are empty');
}
// Clear cart session
}
public function updateCart($request) {
- $id = $request->id;
-
$cart = Product::getCartData();
+
$data['products'] = json_encode($cart);
$ids = Product::getProductIds($data);
$productsInfosBase = Product::getProductsByIds($ids);
return Auth::guard('web-clients')->user();
}
- public static function discountArray($categoryProduct, $categoryClient = false) {
+ public static function getCategory() {
+ return self::getClientConnected()->discount ?? 'A';
+ }
+
+ public static function getDiscount($categoryProduct, $categoryClient = false) {
if(!$categoryClient)
- $categoryClient = self::getClientConnected()->discount ?? 'A';
- //dd(self::getClientConnected());
+ $categoryClient = self::getCategory();
+
$category_array = [
'A' => 0,
'B' => 5,
return self::all()->where('user_id', $userID)->toArray();
}
- public static function test($currentCartRef,$categoryClient,$data = [], $productsInfosBase = []){
+ 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) {
- if($productsInfosBase[$data['products'][$keyRefs]['id']][0]['json']) {
- $options = json_decode($productsInfosBase[$data['products'][$keyRefs]['id']][0]['json'], true);
+ $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) {
}
}
- $cat = $productsInfosBase[$data['products'][$keyRefs]['id']][0]['category'];
- $discount = Client::discountArray($cat,$categoryClient);
- $data['products'][$keyRefs]['discount'] = $discount;
-
+ $categoryProduct = $productsInfosBase[$index][0]['category'];
+ $discount = intval(Client::getDiscount($categoryProduct));
$quantity = intval($data['products'][$keyRefs]["quantity"]);
- $basicSellingPrice = $data['products'][$keyRefs]["basic_selling_price"];
+ $basicSellingPrice = $productsInfosBase[$index][0]['basic_selling_price'] ?? 0;
- $totalOptionsPrice = $basicSellingPrice ? array_reduce($opt[$refs], function ($carry, $item) {
+ $totalOptionPrices = $basicSellingPrice ? array_reduce($opt[$refs], function ($carry, $item) {
return $carry + $item;
}) : 0;
- $basicSellingPrice = $productsInfosBase[$data['products'][$keyRefs]['id']][0]['basic_selling_price'] ?? 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;
- $discount = floatval($data['products'][$keyRefs]["discount"]) ?? 0;
- $price = floatval($basicSellingPrice + $totalOptionsPrice);
- $priceDiscount = ($price - (($price * $discount) / 100));
- $total[] = str_replace(',','.',$priceDiscount * $quantity);
$data['products'][$keyRefs]["price"] = $price;
}
- $checkUnavailableEcommerceProduct = array_filter($data['products'], function($n) {
- return !$n['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'] = !$checkUnavailableEcommerceProduct ? number_format($ttc,2) : null;
+ $data['total'] = !$unavailableEcommerceProduct ? number_format($ttc,2) : null;
return $data;
}
public static function fillData($currentCartRef, $data, $productsInfosBase, $haveStatus = true) {
- /**
- *
- */
- $categoryClient = Client::getClientConnected()->discount ?? 'A';
+ $data = self::updateCartData($currentCartRef,$data,$productsInfosBase);
- $data = self::test($currentCartRef,$categoryClient,$data,$productsInfosBase);
-
- //
if(isset($data['addresses']))
$data['addresses'] = json_encode($data['addresses']);
- $data['products'] = json_encode($data['products']);
-
if($haveStatus)
$data['status'] = 'new';
+ $data['products'] = json_encode($data['products']);
+
return $data;
}
}
$allProducts = array_map(function($n){ return json_decode($n['products'], true); }, $items);
$idsProducts = Product::getProductIds($items);
- $categoryClient = Client::getClientConnected()->discount ?? 'A';
$productsInfosBase = Product::getProductsByIds($idsProducts);
foreach ($allProducts as $key => $products){
$data['products'] = $products;
- $currentCartRef = Panier::getRefs($data['products']);
- $data = self::test($currentCartRef,$categoryClient,$data,$productsInfosBase);
+ $currentCartRef = self::getRefs($data['products']);
+ $data = self::updateCartData($currentCartRef,$data,$productsInfosBase);
$items[$key]['products'] = json_encode($data['products']);
$items[$key]['total'] = $data['total'];
}
}
public static function getProductIds($data) {
- if(isset($data['products'])){
+ if(isset($data['products'])){ //way to check if is multidimensional array
$allProducts = json_decode($data['products'], true);
$ids = array_column($allProducts, 'id');
}else{
namespace App\Templates;
use App\Models\Command;
-use App\Models\Panier;
-use Cubist\Backpack\app\Magic\Menu\PageItem;
class MyOrder extends Base
{
min-width: 281px !important
right: 0
+ &-nav-container
+ overflow-x: auto
+ -ms-overflow-style: none
+ scrollbar-width: none
+ &::-webkit-scrollbar
+ display: none
+
&-nav
+ width max-content
li
position: relative
padding-bottom: 21px
background-color: currentColor
&-container-content
- padding: 46px 96px
+ padding: 2.5rem
+ +above($breakpoint-columns)
+ padding: 46px 96px
&-address,
&-password
padding-top: 0 !important
&-address-header
- padding-bottom: 46px
+ +above($breakpoint-columns)
+ padding-bottom 46px
form
label
@section('breadcrumbs')
<full-width padding="pt-1v pb-1v">
<content>
- {!! CubistMenu::breadcrumbs() !!}
+ <div class="xs:hidden">
+ {!! CubistMenu::breadcrumbs() !!}
+ </div>
</content>
</full-width>
@show
<content>
<div class="account">
<text-block :title="$page->title" title-tag="h1" />
-
- <ul class="account-nav flex items-center pl-2v">
- <li @click="tab = 'infos'; activeTab('infos')" class="text-lg cursor-pointer" :class="{ active: tab === 'infos' }">{{ __('Mes coordonnées') }}</li>
- <li @click="tab = 'address'; activeTab('address')" class="text-lg cursor-pointer" :class="{ active: tab === 'address' }">{{ __('Mes adresses') }}</li>
- <li @click="tab = 'pw'; activeTab('pw')" class="text-lg cursor-pointer" :class="{ active: tab === 'pw' }">{{ __('Modifier mon mot de passe') }}</li>
- </ul>
+ <div class="account-nav-container">
+ <ul class="account-nav flex items-center pl-2v">
+ <li @click="tab = 'infos'; activeTab('infos')" class="text-lg cursor-pointer" :class="{ active: tab === 'infos' }">{{ __('Mes coordonnées') }}</li>
+ <li @click="tab = 'address'; activeTab('address')" class="text-lg cursor-pointer" :class="{ active: tab === 'address' }">{{ __('Mes adresses') }}</li>
+ <li @click="tab = 'pw'; activeTab('pw')" class="text-lg cursor-pointer" :class="{ active: tab === 'pw' }">{{ __('Modifier mon mot de passe') }}</li>
+ </ul>
+ </div>
<div class="account-container-content bg-grey-200">
<div id="account-infos" v-cloak v-if="tab === 'infos'">
</div>
<div id="account-address" class="account-address" v-cloak v-if="tab === 'address'">
- <div class="account-address-header flex items-center justify-between border-b border-b-light-b relative">
- <h2 class="text-2xl m-0">{{ __('Mes adresses') }}</h2>
- <button class="btn btn-custom xs:w-full flex items-center absolute right-0" @click.prevent="addAddressToForm">
+ <div class="account-address-header sm:flex-wrap flex items-center justify-between border-b border-b-light-b relative">
+ <h2 class="text-2xl m-0 sm:mb-6">{{ __('Mes adresses') }}</h2>
+ <button class="btn btn-custom xs:w-full flex items-center absolute right-0 sm:relative" @click.prevent="addAddressToForm">
<span class="pr-2">{{ __('Ajouter une adresse') }}</span>
@svg('icon-white-add')
</button>
$options = true;
}
- $discount = \App\Models\Client::discountArray($categoryProduct);
+ $discount = \App\Models\Client::getDiscount($categoryProduct);
@endphp
@extends('layouts/app')
$options = false;
$categoryProduct = $product->category;
- $discount = \App\Models\Client::discountArray($categoryProduct);
+ $discount = \App\Models\Client::getDiscount($categoryProduct);
$price = floatval(number_format($product->basic_selling_price - (($product->basic_selling_price * $discount) / 100), 2));
if($price < 1)