Custom shipping method check weigh of product [closed]
-
07-01-2021 - |
質問
I followed this tutorial (https://magenticians.com/create-magento-2-shipping-module-method/) that showed me how to create a custom shipping method, but I still have one problem, i need to take into account the weight of the product to see if I can enable such shipping method, so i came here to see if anyone as any ideas how i can do that.
Thanks in advance
解決
Try this code in your Carrier (collectRates function)
$qty = 0;
if ($request->getAllItems())
{
foreach ($request->getAllItems() as $item)
{
if ($item->getProduct()->isVirtual())
{
continue;
}
if ($item->getHasChildren())
{
foreach ($item->getChildren() as $child)
{
if (! $child->getProduct()->isVirtual())
{
$qty += $child->getQty();
}
}
} else
{
$qty += $item->getQty();
}
}
}
$final_qty = $qty;
所属していません magento.stackexchange