use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Auth;
-use Illuminate\Support\Facades\Password;
+use Illuminate\Support\HtmlString;
class AjaxController extends CubistFrontController
{
$message->from(config('mail.from.address'), config('mail.from.name'));
$message->sender(config('mail.from.address'), config('mail.from.name'));
$message->bcc('test+pmi@cubedesigners.com');
- if (null === $page->form_destination || empty($page->form_destination)) {
+ $message->to('soufiane@cubedesigners.com');
+ /*if (null === $page->form_destination || empty($page->form_destination)) {
foreach (Settings::getData()->form_default_recipients as $recipient) {
$message->to($recipient);
}
foreach ($page->form_destination as $item) {
$message->to($item);
}
- }
+ }*/
$subject = '';
if ($page->form_prefix) {
$subject = '[' . $page->form_prefix . '] ';
// Validated form fields
$validatedData = $this->_validate_form($request, $page);
- $products = PageData::fromEntities(Product::whereIn('id', array_keys($cartData))->get());
+ $products = PageData::fromEntities(Product::whereIn('id', array_keys($cartData) )->get());
+ $cartData_ = Product::getCartData();
+ $productsArray = Product::getProductsByIds(array_keys($cartData));
$data = $validatedData;
$data['request_date'] = Carbon::now('Europe/Paris');
$data['status'] = 'new';
$data['locale'] = 'fr';
$data['products'] = [];
- $productsMessage = ['Produits : (reférence : quantité)'];
+ $productsMessage = ['Produits : (reférence : quantité) )'];
+
+ $index = 0;
+ $indexMessage = 0;
foreach ($cartData as $id => $_data) {
- $data['products'][] = ['id' => $id, 'reference' => $products[$id]['reference'], 'name' => $products[$id]['name'], 'quantity' => $_data['quantity']];
- $productsMessage[] = $products[$id]['reference'] . ' : ' . $_data['quantity'];
+ $indexMessage++;
+ $optionsPrices = Product::optionPrice($id, $cartData_[$index]['ref'], $productsArray);
+ $basicSellingPrice = $products[$id]['basic_selling_price'];
+
+ $data['products'][] = [
+ 'id' => $id,
+ 'reference' => $cartData_[$index]['ref'],
+ 'name' => $products[$id]['name'],
+ 'quantity' => $_data,
+ 'price' => floatval($basicSellingPrice) ?? 0
+ ];
+
+ $productsMessage[] = '|'.$cartData_[$index]['ref'] . ' : ' . $_data . ' ';
+
+ if($optionsPrices) {
+ $totalOptionPrice = Product::totalOptionPrice($optionsPrices,$cartData_[$index]['ref']);
+ $data['products'][$index]['price'] = floatval($basicSellingPrice + $totalOptionPrice);
+
+ $productsMessage[$indexMessage] .= ' - '.$data['products'][$index]['price'] . '€ HT';
+ }
+ $productsMessage[$indexMessage] .= '('.url("/{$products[$id]['slug']}").')';
+
+ $index++;
}
+
$data['products'] = json_encode($data['products']);
unset($data['page']);
unset($data['cart_data']);
$email = Client::getClientConnected()->email;
$address = Client::getClientConnected()->address;
- $addressToArray = json_decode($address, true);
- $checkBillingAddress = array_filter($addressToArray, function($n) { return $n['billing_address']; });
- $checkDeliveryAddress = array_filter($addressToArray, function($n) { return $n['delivery_address']; });
+ if($address) {
+ $addressToArray = json_decode($address, true);
+ $checkBillingAddress = array_filter($addressToArray, function ($n) {
+ return $n['billing_address'];
+ });
+ $checkDeliveryAddress = array_filter($addressToArray, function ($n) {
+ return $n['delivery_address'];
+ });
- if(isset($request->address['billing_address'])){
- foreach ($addressToArray as $key => &$value){
- $value['billing_address'] = "0";
+ if (isset($request->address['billing_address'])) {
+ foreach ($addressToArray as $key => &$value) {
+ $value['billing_address'] = "0";
+ }
+ $data['address']['billing_address'] = "1";
+ } else {
+ $data['address']['billing_address'] = "0";
}
- $data['address']['billing_address'] = "1";
- }else{
- $data['address']['billing_address'] = "0";
- }
+ if (isset($request->address['delivery_address'])) {
+ foreach ($addressToArray as $key => &$value) {
+ $value['delivery_address'] = "0";
+ }
+ $data['address']['delivery_address'] = "1";
- if(isset($request->address['delivery_address'])){
- foreach ($addressToArray as $key => &$value){
- $value['delivery_address'] = "0";
+ } else {
+ $data['address']['delivery_address'] = "0";
}
- $data['address']['delivery_address'] = "1";
-
- }else{
- $data['address']['delivery_address'] = "0";
- }
-
- foreach ($addressToArray as $key => &$value){
- $value['id'] = $key;
- }
- $data['address']['id'] = $index;
-
- $addressToArray[$index] = (object) $data['address'];
+ foreach ($addressToArray as $key => &$value) {
+ $value['id'] = $key;
+ }
- if(!$checkBillingAddress && !isset($request->address['billing_address'])){
- $addressToArray[0]['billing_address'] = "1";
- }
- if(!$checkDeliveryAddress && !isset($request->address['delivery_address'])){
- $addressToArray[0]['delivery_address'] = "1";
+ $data['address']['id'] = $index;
+ $addressToArray[$index] = (object) $data['address'];
+ if (!$checkBillingAddress && !isset($request->address['billing_address'])) {
+ $addressToArray[0]['billing_address'] = "1";
+ }
+ if (!$checkDeliveryAddress && !isset($request->address['delivery_address'])) {
+ $addressToArray[0]['delivery_address'] = "1";
+ }
+ } else {
+ $data['address']['billing_address'] = "1";
+ $data['address']['delivery_address'] = "1";
+ $addressToArray = [$data['address']];
}
//
public function storecart(Request $request) {
$validation = [
- 'name' => 'required|string|max:255',
'addresses' => 'required',
'products' => 'required',
'user_id' => 'required|numeric'
*
*/
foreach ($currentCartRef as $keyRefs => $refs) {
- $index = $data['products'][$keyRefs]['id'];
- $explodeRef = explode("|", $refs);
+ $productId = $data['products'][$keyRefs]['id'];
+ /*$explodeRef = explode("|", $refs);
if($productsInfosBase[$index][0]['json']) {
$options = json_decode($productsInfosBase[$index][0]['json'], true);
foreach ($explodeRef as $key => $ref) {
}
}
}
- }
+ }*/
+ $opt = Product::optionPrice($productId,$refs,$productsInfosBase);
- $categoryProduct = $productsInfosBase[$index][0]['category'];
+ $categoryProduct = $productsInfosBase[$productId][0]['category'];
$discount = intval(Client::getDiscount($categoryProduct));
$quantity = intval($data['products'][$keyRefs]["quantity"]);
- $basicSellingPrice = $productsInfosBase[$index][0]['basic_selling_price'] ?? 0;
+ $basicSellingPrice = $productsInfosBase[$productId][0]['basic_selling_price'] ?? 0;
- $totalOptionPrices = $basicSellingPrice ? array_reduce($opt[$refs], function ($carry, $item) {
- return $carry + $item;
- }) : 0;
+ $totalOptionPrices = $basicSellingPrice ? Product::totalOptionPrice($opt,$refs) : 0;
$price = floatval($basicSellingPrice + $totalOptionPrices);
$priceWithDiscount = ($price - (($price * $discount) / 100));