4

magento 2 checkout extra fee adding twice to grand total collect function calling 4 to 5 times

parent::collect($quote, $shippingAssignment, $total);
    if (!count($shippingAssignment->getItems())) {
        return $this;
    }

+

$address = $shippingAssignment->getShipping()->getAddress();
    if($address->getAddressType() != 'billing'){
        return $this;
    }
    // My code
    return $this;

(or)

$address = $shippingAssignment->getShipping()->getAddress();
    if($address->getAddressType() == 'billing'){

        // My code
        return $this;
    }

Reference: https://stackoverflow.com/a/42141291/8237294

1 Answer 1

3

Please check if shipping assignment contain item(s) when it apply the extra fee:

$items = $shippingAssignment->getItems();
    if (!count($items)) {
        return $this;
    }

Please add above code in collect method at very first like below:

public function collect(
\Magento\Quote\Model\Quote $quote,
\Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment,
\Magento\Quote\Model\Quote\Address\Total $total
) {
      $items = $shippingAssignment->getItems();
      if (!count($items)) {
           return $this;
      }
      parent::collect($quote, $shippingAssignment, $total);

      /* your cusotm code ....*/

}
1
  • still adding twice Commented Dec 29, 2017 at 10:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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