1

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

closed as off-topic by Jai, Manoj Deswal, Keyur Shah, Dhiren Vasoya, Manashvi Birla Apr 23 '18 at 5:11

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced OR seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Jai, Manoj Deswal, Dhiren Vasoya, Manashvi Birla
If this question can be reworded to fit the rules in the help center, please edit the question.

1

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;
  • I did that, but i still don't see no diference – Ruben Perdigao Apr 21 '18 at 16:32
  • did you got the qty? if you got it you need to check if it is valid quantity then you need to continue to add the shipping method by this ( $result->append($method)). – WISAM HAKIM Apr 22 '18 at 5:30
  • @WISAMHAKIM can you please explain logic of above code? – Khushbu Feb 19 at 12:46
  • @Khushbu, the above code is only get the quantities of current cart products, it was requested in this Question, i think it was needed for special logic – WISAM HAKIM Feb 19 at 14:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.