I need to calculate some custom value in the checkout summary section, for that, I have written some code In the model file, but it was doing only Addition in the Order total. I need multiplication or Division in that calculation.

Here is my 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);
        $items = $shippingAssignment->getItems();
        if (!count($items)) {
            return $this;
        $enabled = $this->helperData->isModuleEnabled();
        $gstin   = $this->helperData->gst_in();
        if ($enabled && $gstin) 
            $exist_amount = $quote->getGstrate(); 
            $gstrate = $this->helperData->gst_rate();
            $gst_rate = floatval($gstrate);
            $balance = $gst_rate - $exist_amount;
            $total->setTotalAmount('gst_rate', $balance);
            $total->setBaseTotalAmount('gst_rate', $balance);


            //$subTotal = $total['subtotal'];
            //$total->setGrandTotal($total->getGrandTotal() + $balance);
            $total->setBaseGrandTotal($total->getBaseGrandTotal() + $balance);
            //echo "<pre>"; print_r($total); echo '</pre>';
            return $this;


Output is:

Now I want to do the calculation something like below.

<?php  if ($block->gstEnable()): ?>    
    <?php if ($helper->gst_in()): ?>
        <?php echo 'GST'. $getgstrate; echo "<br>"; ?>
            /* Convert Percentage Value in to Number Code */
             $gst_float = floatval($getgstrate);            
            /* Convert Percentage Value in to Number Code */

            $subTotal = $block->getSubtotal();
            $totalgst = $subTotal * $gst_float / 100;
            echo "GST".$totalgst;
            echo "<br>";
            $devidedgst= $totalgst / 2;

            echo "CGST".(round($devidedgst, 2));
            echo "<br>";
            echo "SGST".(round($devidedgst, 2));
            echo "<br>";

    <?php endif; ?>    
<?php endif; ?>

How can I do this in Order Total? Please guide me on this.


Your Answer

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

Browse other questions tagged or ask your own question.