Closed tixaskiy closed 5 years ago
Hi,
$item is not available in global context. You probably want to sum this value for any item in cart.
You must use $request->all_items object like explained in the documentation:
https://owebia.com/doc/en/magento2-module-advanced-shipping#examples_using_sum
addMethod('id_024', [
'title' => "Calculate shipping fees by product",
'price' => array_sum(
array_map(
function ($item) {
// shipping_price is a custom product attribute
return $item->product->shipping_price * $item->qty;
},
$request->all_items
)
),
]);
Thanks so much
I want each product to have its own field with the cost of delivery. Each product has an individual fixed cost of delivery. I created product attributes shipping_price. create such method:
addMethod('method1', [ 'title' => "Shipping", 'price' => $item->product->shipping_price
]);
I expect that the shipping cost will be equal to the value I specified for the product in the shipping_price attribute The shipping cost is zero. debag shows that $item has a null value. Help me please.