File: D:/HostingSpaces/Eurotools/euro-tools.nl/app/KommaApp/Shop/Checkout/QuotationRequest.php
<?php
namespace App\KommaApp\Shop\Checkout;
use Illuminate\Foundation\Http\FormRequest;
class QuotationRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'productables' => 'required|array',
'cart_total' => 'required|integer',
'cart_total_including_discounts' => 'required|integer',
];
}
/**
* Returns an array of arrays (representing lines) containing line parameters for a mail message that must include productables
*
* @return array
*/
public function getProductableLineParametersForMail()
{
$productabalesArray = json_decode($this->query('productables'), true);
$parameters = [];
foreach($productabalesArray as $productableArray)
{
$parameters[] = [
'stock_keeping_unit' => isset($productableArray['stock_keeping_unit']) ? (string)$productableArray['stock_keeping_unit'] : '',
'amount' => isset($productableArray['amount']) ? (string)$productableArray['amount'] : '0',
'name' => isset($productableArray['name']) ? $productableArray['name'] : '',
'original_total' => isset($productableArray['original_total']) ? $this->formatAsValuta($productableArray['original_total']) : '0',
'total_with_discounts' => isset($productableArray['total_with_discounts']) ? $this->formatAsValuta($productableArray['total_with_discounts']) : '0'
];
}
return $parameters;
}
/**
* @param $valueInCents
* @return string
*/
public function formatAsValuta($valueInCents)
{
$value = (string)round($valueInCents / 100, 2);
if(strpos($value, '.') !== false) {
$valueParts = explode('.', $value);
if(strlen($valueParts[1]) == 1) $valueParts[1] .= '0';
$value = implode(',', $valueParts);
}
return $value;
}
}