Closed Aspartam33 closed 3 years ago
Hi,
From what I can see, you can't compare an array to a single value $item->product->category_ids == 13
.
You have to use the in_array()
function like this: in_array(13, $item->product->category_ids)
.
There are also missing multiplication signs, I don't know if github removed them from your post or if they are not in the original configuration: $price * 10
and $plazas * $cost
.
Best Regards, A.L.
Thank you for taking your time to clarify the doubt I had.
Now the drawback is that when the zip code is entered and the item is purchased according to the category that is going to key, the collection part of the sample is the free shipping and not the one I made. And what is the checkout showing
I have also done the reindex and deploy steps, thank you for your attention, I am attentive to your response.
Have you tried to enable the debug setting of the module to see how your configuration is evaluated?
Hello It´s me again I changed tho code and did it on carrier.php but it´s allowed for al methods so i did it again in the controller, and im getting this error
the shipping method is based on this attribute
this is the code `addMethod('id_006', ['title' => 'Envío por mensajería 10 días hábiles (estándar)',
'price' => array_reduce($arrayPreciosCotramu, function ($carry, $item) {
$count_Price = 0;
global $request;
global $quote;
if (isset($carry)) {
return $carry;
}
if (isset($item[0]) && ($quote->base_grand_total <= $item[0] || $item[0] == '')) {
$carry = $item[1];
}
else if (isset($item[0]) && ($item->product->number_of_seats >= 0)){
$carry += (50$item->product->number_of_seats) - ($item->price_incl_tax *0.10);
return $carry;
}
if($carry<0)
{
$carry = 0;
}
return $carry;
}), 'enabled' => $_allowedCotramu && preg_match('/^(?!28).*$/i', $request->dest_postcode)]);
/**`
and whay im getting in the debugger
What do you have on line 434 of the configuration? Is it possible that the configuration is truncated when stored in the database?
in the line 434 I have this if (isset($item[0]) && ($quote->base_grand_total <= $item[0] || $item[0] == '')) { $carry = $item[1]; } else if (isset($item[0]) && ($item->product->number_of_seats >= 0)){ $carry += (50$item->product->number_of_seats) - ($item->price_incl_tax *0.10); return $carry; }
I don't see any error on this line. You said you changed the carrier.php file and a controller file? Are you using a modified version of the module?
I modiefied the module by myself but it didn't work so I downloaded the original and did this in the controller and now is working. $numSeats = array_sum(array_map(function ($item) { return $item->product->number_of_seats * $item->qty; }, $request->all_items));
addMethod('id_006', ['title' => 'Envío por mensajería 10 días hábiles (estándar)', 'price' => array_reduce($arrayPreciosCotramu, function ($carry, $item) { $count_Price = 0; global $request; global $quote; if (isset($carry)) { return $carry; } if (isset($item[0]) && ($numSeats > 0)){ $carry += (50 $numSeats) - ($item->price_excl_tax 0.10);
}else{
$carry = $item[1];
}
if($carry<0)
{
$carry = 0;
}
return $carry;
}), 'enabled' => $_allowedCotramu && preg_match('/^(?!28).*$/i', $request->dest_postcode)]);
What did you put in the controller and in which controller? Can you post the whole file? You are not supposed to do this. We don't provide support for modified version of the module.
here
I didn't know that
It was a test that I did but it didn´t work so I uninstalled the module and downloaded the github version and worked it based in the documentation
Can you put the whole configuration into a code block with triple backticks please (see https://docs.github.com/en/github/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks)?
$arrayPrecios = [[5, 3.93], [10, 5.36], [15, 7.14], [20, 8.62], [25, 8.34], [30, 10.09], [35, 13.04], [40, 14.52], [45, 16], [50, 17.47], [55, 18.95], [60, 20.42], [65, 21.9], [70, 23.38], [75, 24.85], [80, 26.33]];
$_allowedCAC = false;
$_allowedCAC2 = false;
$_allowedClick = false;
$_allowedExpedicion = false;
$_allowedEcommerce = false;
// Comprueba si los items en carrito tienen montaje a true
$montaje = array_map(function ($item) {
$result = true;
return $result * $item->product->montaje;
}, $request->all_items);
// Comprueba si los items en carrito tienen bazar a true
$bazar = array_map(function ($item) {
$result = true;
return $result * $item->product->bazar;
}, $request->all_items);
// Calcula el numero total de bultos
$numBultos = array_sum(array_map(function ($item) {
return $item->product->numero_bultos * $item->qty;
}, $request->all_items));
// Coge todos los bultos y saca el valor más alto
$dimensiones = array_sum(array_map(function ($item) {
return array_sum([
$item->product->alto_bulto_1,
$item->product->ancho_bulto_1,
$item->product->fondo_bulto_1,
$item->product->alto_bulto_2,
$item->product->ancho_bulto_2,
$item->product->fondo_bulto_2,
$item->product->alto_bulto_3,
$item->product->ancho_bulto_3,
$item->product->fondo_bulto_3,
$item->product->alto_bulto_4,
$item->product->ancho_bulto_4,
$item->product->fondo_bulto_4]);
}, $request->all_items));
// Saca el peso del bulto mas pesado
$pesoMaxBulto = max(array_map(function ($item) {
return max([
$item->product->peso_bulto_1,
$item->product->peso_bulto_2,
$item->product->peso_bulto_3,
$item->product->peso_bulto_4]);
}, $request->all_items));
// Peso total bultos
$pesoTotalBultos = array_sum(array_map(function ($item) {
return array_sum([
$item->product->peso_bulto_1,
$item->product->peso_bulto_2,
$item->product->peso_bulto_3,
$item->product->peso_bulto_4]) * $item->qty;
}, $request->all_items));
// Decide si los articulos del carrito son de decoracion
$attrDecoracion = min(array_map(function ($item) {
$decoracion = true;
if ($item->product->attribute_set_id == 11 || $item->product->attribute_set_id == 14
|| $item->product->attribute_set_id == 18 || $item->product->attribute_set_id == 19
|| $item->product->attribute_set_id == 20 || $item->product->attribute_set_id == 21) {
$decoracion = $decoracion * true;
} else {
$decoracion = $decoracion * false;
}
return $decoracion;
}, $request->all_items));
/**
* Logica
*/
if (!in_array(1, $montaje) && !in_array(1, $bazar)) {
if ($attrDecoracion) {
$_allowedCAC = true;
} else {
$_allowedCAC2 = true;
}
} else if (in_array(1, $montaje) && in_array(1, $bazar)) {
if (($attrDecoracion && $dimensiones >= 300) || ($attrDecoracion && $pesoTotalBultos >= 250)) {
$_allowedCAC = true;
} else if (($attrDecoracion && $dimensiones <= 300) && ($attrDecoracion && $pesoTotalBultos <= 250)) {
if ($pesoMaxBulto >= 80 || $pesoTotalBultos >= 40) {
$_allowedExpedicion = true;
} else {
$_allowedEcommerce = true;
}
} else {
$_allowedCAC2 = true;
}
} else if (in_array(1, $montaje) && !in_array(1, $bazar)) {
if ($attrDecoracion) {
$_allowedCAC = true;
} else {
$_allowedCAC2 = true;
}
} else if (!in_array(1, $montaje) && in_array(1, $bazar)) {
if (($attrDecoracion && $dimensiones >= 300) || ($attrDecoracion && $pesoTotalBultos >= 250)) {
$_allowedCAC = true;
} else if (($attrDecoracion && $dimensiones <= 300) && ($attrDecoracion && $pesoTotalBultos <= 250)) {
if ($pesoMaxBulto >= 80 || $pesoTotalBultos >= 40) {
$_allowedExpedicion = true;
$_allowedClick = true;
} else {
$_allowedEcommerce = true;
$_allowedClick = true;
}
} else {
$_allowedCAC2 = true;
}
}
/**
* Final logica
*/
addMethod('id_001', ['title' => 'Guante blanco: Envío y Montaje',
'price' => array_reduce($arrayPrecios, function ($carry, $item) {
global $request;
$pesoTotalBultos = array_sum(array_map(function ($item) {
return array_sum([
$item->product->peso_bulto_1,
$item->product->peso_bulto_2,
$item->product->peso_bulto_3,
$item->product->peso_bulto_4]) * $item->qty;
}, $request->all_items));
if (isset($carry)) {
return $carry;
}
if (isset($item[0]) && ($pesoTotalBultos <= $item[0] || $item[0] == '*')) {
$carry = $item[1];
} else if (isset($item[0]) && ($pesoTotalBultos > 80)) {
$carry = 0.1 * $request->package_value;
}
return $carry;
}), 'enabled' => $_allowedCAC && preg_match('/^28.*$/i', $request->dest_postcode)]);
/**
* Tarifa Ecommerce
* Cambio $pesoTotalBultos por $request->package_weight
*/
addMethod('id_002', ['title' => 'Envío en 4 días (estándar)',
'price' => array_reduce($arrayPrecios, function ($carry, $item) {
global $request;
$cantidadSinSobrecoste = 2; //Cantidad de bultos sin sobrecoste
$pesoTotalBultos = array_sum(array_map(function ($item) {
return array_sum([
$item->product->peso_bulto_1,
$item->product->peso_bulto_2,
$item->product->peso_bulto_3,
$item->product->peso_bulto_4]) * $item->qty;
}, $request->all_items));
$numBultos = array_sum(array_map(function ($item) {
return $item->product->numero_bultos * $item->qty;
}, $request->all_items));
if (isset($carry)) {
return $carry;
}
if ($request->package_value >= 30) {
$carry = 0;
}else{
if (isset($item[0]) && ($pesoTotalBultos <= $item[0] || $item[0] == '*') && $numBultos <= $cantidadSinSobrecoste) {
$carry = $item[1];
} else if (isset($item[0]) && ($pesoTotalBultos <= $item[0] || $item[0] == '*') && $numBultos >= $cantidadSinSobrecoste) {
$carry = $item[1] + (($numBultos - $cantidadSinSobrecoste) * 3);
}
}
return $carry;
}), 'enabled' => $_allowedEcommerce && preg_match('/^28.*$/i', $request->dest_postcode)]);
/**
* Tarifa Expedicion
* Cambio $pesoTotalBultos por $request->package_weight
*/
addMethod('id_003', ['title' => 'Envío en 4 días (estándar)',
'price' => array_reduce([[2, 4.25], [5, 4.57], [10, 5.31]], function ($carry, $item) {
global $request;
$cantidadSinSobrecoste = 2; //Cantidad de paquetes sin sobrecoste
$pesoTotalBultos = array_sum(array_map(function ($item) {
return array_sum([
$item->product->peso_bulto_1,
$item->product->peso_bulto_2,
$item->product->peso_bulto_3,
$item->product->peso_bulto_4]) * $item->qty;
}, $request->all_items));
$dimensiones = array_sum(array_map(function ($item) {
return array_sum([
$item->product->alto_bulto_1,
$item->product->ancho_bulto_1,
$item->product->fondo_bulto_1,
$item->product->alto_bulto_2,
$item->product->ancho_bulto_2,
$item->product->fondo_bulto_2,
$item->product->alto_bulto_3,
$item->product->ancho_bulto_3,
$item->product->fondo_bulto_3,
$item->product->alto_bulto_4,
$item->product->ancho_bulto_4,
$item->product->fondo_bulto_4]);
}, $request->all_items));
if (isset($carry)) {
return $carry;
}
if (isset($item[0]) && ($pesoTotalBultos <= $item[0] || $item[0] == '*')) {
$carry = $item[1];
} else if (isset($item[0]) && ($pesoTotalBultos > 10)) {
$carry = 5.31 + (0.37 * ($pesoTotalBultos - 10));
}
//Cambio $pesoTotalBultos por $request->package_weight
if ($pesoTotalBultos >= 40 && $pesoTotalBultos <= 59) {
$carry = $carry + 9;
} else if ($pesoTotalBultos >= 60 && $pesoTotalBultos <= 80) {
$carry = $carry + 15;
} else {
$carry = $carry + (($pesoTotalBultos - 80) / 20) * 6;
}
if (isset($item[0]) && ($pesoTotalBultos <= $item[0] || $item[0] == '*') && $numBultos >= $cantidadSinSobrecoste) {
$carry = $item[1] + (($numBultos - $cantidadSinSobrecoste) * 3);
}
if ($dimensiones >= 150 && $dimensiones <= 200) {
$carry = $carry + 2.11;
} else if ($dimensiones >= 201 && $dimensiones <= 250) {
$carry = $carry + 3.14;
} else if ($dimensiones >= 251 && $dimensiones <= 300) {
$carry = $carry + 9.79;
}
return $carry;
}), 'enabled' => $_allowedExpedicion && preg_match('/^28.*$/i', $request->dest_postcode)]);
addMethod('click_and_collect_ortega', ['title' => 'Click & Collect - Ortega y Gasset, 34',
'price' => 0, 'enabled' => $_allowedClick && preg_match('/^28.*$/i', $request->dest_postcode)]);
addMethod('click_and_collect_san_fernando', ['title' => 'Click & Collect - San Fernando de Henares (Crt. Barcelona km 19)',
'price' => 0, 'enabled' => $_allowedClick && preg_match('/^28.*$/i', $request->dest_postcode)]);
addMethod('click_and_collect_fuenla', ['title' => 'Click & Collect - Fuenlabrada ( Autovía de Toledo, km 19)',
'price' => 0, 'enabled' => $_allowedClick && preg_match('/^28.*$/i', $request->dest_postcode)]);
addMethod('click_and_collect_majadahonda', ['title' => 'Click & Collect - Majadahonda ( C.C. Equinoccio ) ',
'price' => 0, 'enabled' => $_allowedClick && preg_match('/^28.*$/i', $request->dest_postcode)]);
addMethod('id_005', ['title' => 'Guante blanco: Envío y Montaje',
'price' => array_reduce($arrayPrecios, function ($carry, $item) {
global $request;
$attrDecoracion = array_filter(array_map(function ($item) {
if ($item->product->attribute_set_id == 11 || $item->product->attribute_set_id == 14
|| $item->product->attribute_set_id == 18 || $item->product->attribute_set_id == 19
|| $item->product->attribute_set_id == 20 || $item->product->attribute_set_id == 21) {
$decoracion = $item;
}
return $decoracion;
}, $request->all_items));
$pesoTotalBultos = array_sum(array_map(function ($item) {
return array_sum([
$item->product->peso_bulto_1,
$item->product->peso_bulto_2,
$item->product->peso_bulto_3,
$item->product->peso_bulto_4]) * $item->qty;
}, $attrDecoracion));
if (isset($carry)) {
return $carry;
}
if (!$attrDecoracion) {
$carry = 0;
}else{
if (isset($item[0]) && ($pesoTotalBultos <= $item[0] || $item[0] == '*')) {
$carry = $item[1];
} else if (isset($item[0]) && ($pesoTotalBultos > 80)) {
$carry = 0.1 * $request->package_value;
}
}
return $carry;
}), 'enabled' => $_allowedCAC2 && preg_match('/^28.*$/i', $request->dest_postcode)]);
// ONLINE
$arrayPreciosCotramu = [[100, 54.45], [200, 36.3], [300, 24.20], [400, 12.1], ['*', 0]];
$online_arrayPrecios = [[0, 3.93],[5, 3.93], [10, 5.36], [15, 7.14], [20, 8.62], [25, 8.34], [30, 10.09], [35, 13.04], [40, 14.52], [45, 16], [50, 17.47], [55, 18.95], [60, 20.42], [65, 21.9], [70, 23.38], [75, 24.85], [80, 26.33]];
$_allowedCotramu = false;
$_allowedCotramu2 = false;
$_allowedExpedicion = false;
$_allowedEcommerce = false;
// Calcula el numero total de bultos
$numBultos = array_sum(array_map(function ($item) {
return $item->product->numero_bultos * $item->qty;
}, $request->all_items));
// Saca el peso del bulto mas pesado
$pesoMaxBulto = max(array_map(function ($item) {
return max([
$item->product->peso_bulto_1,
$item->product->peso_bulto_2,
$item->product->peso_bulto_3,
$item->product->peso_bulto_4]);
}, $request->all_items));
// Peso total bultos
$pesoTotalBultos = array_sum(array_map(function ($item) {
return array_sum([
$item->product->peso_bulto_1,
$item->product->peso_bulto_2,
$item->product->peso_bulto_3,
$item->product->peso_bulto_4]) * $item->qty;
}, $request->all_items));
// Saca el attribute id
$attrId = array_map(function ($item) {
return $item->product->attribute_set_id;
}, $request->all_items);
// Decide si los articulos del carrito son de decoracion
$attrDecoracion = min(array_map(function ($item) {
$decoracion = true;
if ($item->product->attribute_set_id == 11 || $item->product->attribute_set_id == 14
|| $item->product->attribute_set_id == 18 || $item->product->attribute_set_id == 19
|| $item->product->attribute_set_id == 20 || $item->product->attribute_set_id == 21) {
$decoracion = $decoracion * true;
} else {
$decoracion = $decoracion * false;
}
return $decoracion;
}, $request->all_items));
$attrSofaColchon = min(array_map(function ($item) {
$sofaColchon = true;
if ($item->product->attribute_set_id == 10 || $item->product->attribute_set_id == 9) {
$sofaColchon = $sofaColchon * true;
} else {
$sofaColchon = $sofaColchon * false;
}
return $sofaColchon;
}, $request->all_items));
// Coge todos los bultos y saca el valor más alto
/*$dimensiones = array_sum(array_map(function ($item) {
return array_sum([
$item->product->alto_bulto_1,
$item->product->ancho_bulto_1,
$item->product->fondo_bulto_1,
$item->product->alto_bulto_2,
$item->product->ancho_bulto_2,
$item->product->fondo_bulto_2,
$item->product->alto_bulto_3,
$item->product->ancho_bulto_3,
$item->product->fondo_bulto_3,
$item->product->alto_bulto_4,
$item->product->ancho_bulto_4,
$item->product->fondo_bulto_4]);
}, $request->all_items));*/
$dimensiones = max(array_map(function ($item) {
$bulto1 = array_sum([$item->product->alto_bulto_1,
$item->product->ancho_bulto_1,
$item->product->fondo_bulto_1]);
$bulto2 = array_sum([$item->product->alto_bulto_2,
$item->product->ancho_bulto_2,
$item->product->fondo_bulto_2]);
$bulto3 = array_sum([$item->product->alto_bulto_3,
$item->product->ancho_bulto_3,
$item->product->fondo_bulto_3]);
$bulto4 = array_sum([$item->product->alto_bulto_4,
$item->product->ancho_bulto_4,
$item->product->fondo_bulto_4]);
return max([$bulto1, $bulto2, $bulto3, $bulto4]);
}, $request->all_items));
/**
* Logica
*/
if (($dimensiones < 300) && ($pesoTotalBultos < 250)) {
if ($pesoTotalBultos < 40 ) {
$_allowedEcommerce = true;
} else if ($pesoMaxBulto < 80 && $pesoTotalBultos >=40){
$_allowedExpedicion = true;
} else {
$_allowedCotramu = true;
}
} else {
$_allowedCotramu = true;
}
if($attrSofaColchon == true){
$_allowedCotramu = true;
$_allowedEcommerce = false;
}
/**
* Final logica
*/
$numSeats = array_sum(array_map(function ($item) {
return $item->product->number_of_seats * $item->qty;
}, $request->all_items));
addMethod('id_006', ['title' => 'Envío por mensajería 10 días hábiles (estándar)',
'price' => array_reduce($arrayPreciosCotramu, function ($carry, $item) {
$count_Price = 0;
global $request;
global $quote;
if (isset($carry)) {
return $carry;
}
if (isset($item[0]) && ($numSeats > 0)){
$carry += (50 * $numSeats) - ($item->price_excl_tax * 0.11);
}else{
$carry = $item[1];
}
if($carry<0)
{
$carry = 0;
}
return $carry;
}), 'enabled' => $_allowedCotramu && preg_match('/^(?!28).*$/i', $request->dest_postcode)]);
/**
* Tarifa Ecommerce
*/
addMethod('id_007', ['title' => 'Envío en 4 días (estándar)',
'price' => array_reduce($online_arrayPrecios, function ($carry, $item) {
global $request;
$cantidadSinSobrecoste = 2; //Cantidad de bultos sin sobrecoste
$pesoTotalBultos = array_sum(array_map(function ($item) {
return array_sum([
$item->product->peso_bulto_1,
$item->product->peso_bulto_2,
$item->product->peso_bulto_3,
$item->product->peso_bulto_4]) * $item->qty;
}, $request->all_items));
if (isset($carry)) {
return $carry;
}
if ($request->package_value <= 30) {
if (isset($item[0]) && ($pesoTotalBultos <= $item[0] || $item[0] == '*') && $numBultos <= $cantidadSinSobrecoste) {
$carry = $item[1];
} else if (isset($item[0]) && ($pesoTotalBultos <= $item[0] || $item[0] == '*') && $numBultos >= $cantidadSinSobrecoste) {
$carry = $item[1] + (($numBultos - $cantidadSinSobrecoste) * 3);
}
} else {
$carry = 0;
}
return $carry;
}), 'enabled' => $_allowedEcommerce && preg_match('/^(?!28|07).*$/i', $request->dest_postcode)]);
/**
* Tarifa Expedicion
*/
addMethod('id_008', ['title' => 'Envío en 4 días (estándar)',
'price' => array_reduce([[2, 4.25], [5, 4.57], [10, 5.31]], function ($carry, $item) {
global $request;
$cantidadSinSobrecoste = 2; //Cantidad de paquetes sin sobrecoste
$pesoTotalBultos = array_sum(array_map(function ($item) {
return array_sum([
$item->product->peso_bulto_1,
$item->product->peso_bulto_2,
$item->product->peso_bulto_3,
$item->product->peso_bulto_4]) * $item->qty;
}, $request->all_items));
$dimensiones = array_sum(array_map(function ($item) {
return array_sum([
$item->product->alto_bulto_1,
$item->product->ancho_bulto_1,
$item->product->fondo_bulto_1,
$item->product->alto_bulto_2,
$item->product->ancho_bulto_2,
$item->product->fondo_bulto_2,
$item->product->alto_bulto_3,
$item->product->ancho_bulto_3,
$item->product->fondo_bulto_3,
$item->product->alto_bulto_4,
$item->product->ancho_bulto_4,
$item->product->fondo_bulto_4]);
}, $request->all_items));
if (isset($carry)) {
return $carry;
}
if ($request->package_value >= 30) {
$carry = 0;
return $carry;
}
if (isset($item[0]) && ($pesoTotalBultos <= $item[0] || $item[0] == '*')) {
$carry = $item[1];
} else if (isset($item[0]) && ($pesoTotalBultos > 10)) {
$carry = 5.31 + (0.37 * ($pesoTotalBultos - 10));
}
//Cambio $pesoTotalBultos por $request->package_weight
if ($pesoTotalBultos >= 40 && $pesoTotalBultos <= 59) {
$carry = $carry + 9;
} else if ($pesoTotalBultos >= 60 && $pesoTotalBultos <= 80) {
$carry = $carry + 15;
} else {
$carry = $carry + (($pesoTotalBultos - 80) / 20) * 6;
}
if (isset($item[0]) && ($pesoTotalBultos <= $item[0] || $item[0] == '*') && $numBultos >= $cantidadSinSobrecoste) {
$carry = $item[1] + (($numBultos - $cantidadSinSobrecoste) * 3);
}
if ($dimensiones >= 150 && $dimensiones <= 200) {
$carry = $carry + 2.11;
} else if ($dimensiones >= 201 && $dimensiones <= 250) {
$carry = $carry + 3.14;
} else if ($dimensiones >= 251 && $dimensiones <= 300) {
$carry = $carry + 9.79;
}
return $carry;
}), 'enabled' => $_allowedExpedicion && preg_match('/^(?!28).*$/i', $request->dest_postcode)]);
/**
* Falta saber especificaciones de tarifa cotramu,
* preguntadas a CAC para resolver las dudas
*/
addMethod('id_009', ['title' => 'Envío por mensajería (estándar)',
'price' => array_reduce($online_arrayPrecios, function ($carry, $item) {
global $request;
$pesoTotalBultos = array_sum(array_map(function ($item) {
return array_sum([
$item->product->peso_bulto_1,
$item->product->peso_bulto_2,
$item->product->peso_bulto_3,
$item->product->peso_bulto_4]) * $item->qty;
}, $request->all_items));
if (isset($carry)) {
return $carry;
}
if ($request->package_value <= 30) {
if (isset($item[0]) && ($pesoTotalBultos <= $item[0] || $item[0] == '*')) {
$carry = $item[1];
}
} else {
$carry = 0;
}
return $carry;
}), 'enabled' => $_allowedCotramu2 && preg_match('/^(?!28).*$/i', $request->dest_postcode)]);
/* ENVIOS a Baleares son un porcentaje del valor total del pedido, iva incluido antes de restar descuentos*/
$precioTotal = array_sum(
array_map(
function ($item) {
// shipping is a custom product attribute
return $item->price_incl_tax * $item->qty;
},
$request->all_items
)
);
/**
* Envíos a Mallorca
**/
addMethod('mallorca', ['title' => 'Envío a Mallorca', 'price' => $precioTotal * 0.12, 'enabled' => preg_match('/^070|^071|^072|^073|^074|^075|^076|^079.*$/i', $request->dest_postcode)]);
/**
* Envíos a Baleares
**/
addMethod('baleares', ['title' => 'Envío a Baleares', 'price' => $precioTotal * 0.14, 'enabled' => preg_match('/^077|^078.*$/i', $request->dest_postcode)]);
I don't have any error in the debug when I use your whole configuration. Are you using the latest version of the module? Have you checked that the configuration is not truncated in the database? Is it possible that out module is catching an error thrown by another piece of code that you added recently? You should isolate the configuration part that generates this error by trying to remove/add parts of the configuration until you have no error.
Something I noticed: you use some variables in functions (for example $numBultos) without making them available in the function context.
You should use function (...) use ($numBultos) {
or global $numBultos;
inside the function to make the variables available.
well I just added this to the configuration
return $item->product->number_of_seats * $item->qty;
}, $request->all_items);
addMethod('id_006', ['title' => 'Envío por mensajería 10 días hábiles (estándar)',
'price' => array_reduce($arrayPreciosCotramu, function ($carry, $item) {
$count_Price = 0;
global $request;
global $quote;
if (isset($carry)) {
return $carry;
}
if (isset($item[0]) && ($numSeats > 0)){
$carry += (50 * $numSeats) - ($item->price_excl_tax * 0.11);
}else{
$carry = $item[1];
}
if($carry<0)
{
$carry = 0;
}
return $carry;
}), 'enabled' => $_allowedCotramu && preg_match('/^(?!28).*$/i', $request->dest_postcode)]);```
On line 434, I have $carry += (50 * $numSeats) - ($item->price_excl_tax * 0.11);
and there is no double arrow on this line.
Anyway, there are a lot of errors in your configuration: variables not available in context (e.g. $numSeats
), unused variables (e.g. $count_Price
), misuse of variables (here $item
is an item of $arrayPreciosCotramu
and not a quote item so you can't use $item->price_excl_tax
).
Please, do some cleanup and indentation before requesting further help.
I changed the code this way
$numSeats = array_sum(
array_map(
function ($item) {
return $item->product->number_of_seats * $item->qty;
},
$request->all_items
)
);
$precioSofas = array_sum(
array_map(
function ($item) {
// shipping is a custom product attribute
return $item->price_incl_tax * $item->qty;
},
$request->all_items
)
);
addMethod('id_006', ['title' => 'Envío por mensajería 10 días hábiles (estándar)',
'price' => ((50*$numSeats) - ($precioSofas *0.10)) , 'enabled' => preg_match('/^(?!28).*$/i', $request->dest_postcode)]);
This code is nicer
``Hello, I have a problem with your module, I am trying to set a custom shipping method as indicated in the documentation, the custom method consists in that the shipping cost is equal to 10% of the price of the item and then the number of seats for $ 50, the shipping cost would be (number of seats * $ 50) - 10% of the price.
however, when I run it in my store it does not show the shipping method I created and it shows the standard one. I attach code and what it shows in checkout.
//plazas = number of seats $fn = function ($price,$plazas) { $cost=50; $calc_plazas=($price10)/100; $shippng_calc=($plazas$cost) - $calc_plazas;
}
I upload the file to "/var/www/m3.caminoacasa.com/vendor/owebia/magento2-module-advanced-shipping/Controller/Adminhtml/Help/Test.php" I save the file and update but it does not show the method created in cart and checkout.