1

I have code for add extra fee in order in magento 2, now my requirement is the extra fee can only show will be not add in order total

enter image description here

the extra free can also add in order total but I can not add that

I need order total 155 not 160

my code is that

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

        $enabled = $this->helperData->isModuleEnabled();
        $minimumOrderAmount = $this->helperData->getMinimumOrderAmount();
        $subtotal = $total->getTotalAmount('subtotal');
        if ($enabled && $minimumOrderAmount <= $subtotal) {
            $fee = $quote->getFee();
            $total->setTotalAmount('fee', $subtotal);
            $total->setBaseTotalAmount('fee', $subtotal);
            $total->setFee($fee);
            $quote->setFee($fee);
            $total->setGrandTotal($total->getGrandTotal());
            $total->setBaseGrandTotal($total->getBaseGrandTotal());
        }
        return $this;
    }
2

can you add following updated code ?

  public function collect(
    \Magento\Quote\Model\Quote $quote,
    \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment,
    \Magento\Quote\Model\Quote\Address\Total $total
) {
    parent::collect($quote, $shippingAssignment, $total);


    $exist_amount = 0; //$quote->getFee(); 
    $fee = 100; //Excellence_Fee_Model_Fee::getFee();
    $balance = $fee - $exist_amount;

    $total->setTotalAmount('fee', $balance);
    $total->setBaseTotalAmount('fee', $balance);

    $total->setFee($balance);
    $total->setBaseFee($balance);

    $total->setGrandTotal($total->getGrandTotal());
    $total->setBaseGrandTotal($total->getBaseGrandTotal());


    return $this;
} 

protected function clearValues(Address\Total $total)
{
    $total->setTotalAmount('subtotal', 0);
    $total->setBaseTotalAmount('subtotal', 0);
    $total->setTotalAmount('tax', 0);
    $total->setBaseTotalAmount('tax', 0);
    $total->setTotalAmount('discount_tax_compensation', 0);
    $total->setBaseTotalAmount('discount_tax_compensation', 0);
    $total->setTotalAmount('shipping_discount_tax_compensation', 0);
    $total->setBaseTotalAmount('shipping_discount_tax_compensation', 0);
    $total->setSubtotalInclTax(0);
    $total->setBaseSubtotalInclTax(0);
}
| improve this answer | |
  • hello i have add new question can you please review that and please help me – Jay Parmar Jun 30 at 12:27
1

you can change following function in your code like this

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

            $enabled = $this->helperData->isModuleEnabled();
            $minimumOrderAmount = $this->helperData->getMinimumOrderAmount();
            $subtotal = $total->getTotalAmount('subtotal');
            if ($enabled && $minimumOrderAmount <= $subtotal) {
                $fee = $quote->getFee();
                $total->setFee($fee);
                $quote->setFee($fee);
            }
            return $this;
} 
| improve this answer | |
  • in witch file can you guide me – Jay Parmar Jun 11 at 10:03
  • app\code\Webkul\Test\Model\Total\Customfee.php – ParulThakkar Jun 11 at 10:21
  • $enabled = $this->helperData->isModuleEnabled(); $minimumOrderAmount = $this->helperData->getMinimumOrderAmount(); $subtotal = $total->getTotalAmount('subtotal'); if ($enabled && $minimumOrderAmount <= $subtotal) { $fee = $quote->getFee(); $total->setTotalAmount('fee', $subtotal); $total->setBaseTotalAmount('fee', $subtotal); $total->setFee($fee); $quote->setFee($fee); $total->setGrandTotal($total->getGrandTotal()); $total->setBaseGrandTotal($total->getBaseGrandTotal – Jay Parmar Jun 11 at 10:27
  • see my code and guide me – Jay Parmar Jun 11 at 10:37
  • 1
    check I have I edited my answer – ParulThakkar Jun 11 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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