is there a way to set up variable on top of list of methods?
I setup a function (return bool) looking for a custom attribute > OK I display or hide each method on it > OK
exemple on one method :
//check if dangerous products
$allItems = $request->all_items;
$hasDangerousProduct = function ($allItems) use ($request) {
$count = count(array_filter($allItems, function ($item) {
return $item->product->dangerous_product == true;
}
)
);
if($count > 0){
return true;
}
return false;
};
// France Relais Colis
addMethod('id_1', [
'title' => "Relais Colis",
'enabled' => in_array($request->dest_country_id, ['FR']) && $hasDangerousProduct($allItems) == false,
'price' => array_reduce([ [0,0.5,5.8], [0.51,1,6], [1.01,2,6.66], [2.01,3,6.95], [3.01,4,7.5], [4.01,5,8.10], [5.01,6,8.5], [6.01,7,8.72], [7.01,8,9.23], [8.01,9,9.9], [9.01,10,11], [10.01,11,12], [11.01,12,13], [12.01,13,13.5], [13.01,14,14], [14.01,15,15], [15.01,16,16], [16.01,17,17], [17.01,18,18] ], function ($carry, $item) use ($request) {
if (isset($carry)) return $carry;
if (isset($item[0]) && ($request->package_weight >= $item[0] && $request->package_weight <= $item[1])) {
$carry = $item[2];
}
return $carry;
}),
'description' => ""
])
->set('delivery_delay', 2);
I need to display a message if at least one method has been hidden depending on my function returning bool. Or If you prefer if this function return false, I have to display a message.
My idea is to get this result with ko and make my render template dynamic with it, but how to get a global information above shipping methids defined by Owebia ?
Thanks a lot !