Magento 2 How to grandtotal in order summary set via model?main.CRITICAL: Plugin class doesn't existMagento 2: How to override newsletter Subscriber modelMagento2 How to show sku in order summary?Magento : Minimum Grandtotal AmountIn Magento 2.2, How to Place the order after GrandTotal is Rs. 0?Checkout Order Summary Update Selected Payment MethodMagento offline custom Payment method with drop down listMonolog Error After 2.2 UpgradeHow to solve Front controller reached 100 router match iterations in magento2In Magento 2, how to set custom grandtotal amount in order, invoice and credit memos

Is there anyway, I can have two passwords for my wi-fi

Air travel with refrigerated insulin

How do I fix the group tension caused by my character stealing and possibly killing without provocation?

Do I have to know the General Relativity theory to understand the concept of inertial frame?

Proving an identity involving cross products and coplanar vectors

Quoting Keynes in a lecture

Why do Radio Buttons not fill the entire outer circle?

Can I say "fingers" when referring to toes?

How were servants to the Kaiser of Imperial Germany treated and where may I find more information on them

I'm just a whisper. Who am I?

How would you translate "more" for use as an interface button?

Personal or impersonal in a technical resume

Does Doodling or Improvising on the Piano Have Any Benefits?

Thank You : 谢谢 vs 感谢 vs 跪谢 vs 多谢

In One Punch Man, is King actually weak?

What the heck is gets(stdin) on site coderbyte?

Is there a RAID 0 Equivalent for RAM?

Can you identify this lizard-like creature I observed in the UK?

Why does the Persian emissary display a string of crowned skulls?

How can I, as DM, avoid the Conga Line of Death occurring when implementing some form of flanking rule?

How do I Interface a PS/2 Keyboard without Modern Techniques?

What (the heck) is a Super Worm Equinox Moon?

The Digit Triangles

When is "ei" a diphthong?



Magento 2 How to grandtotal in order summary set via model?


main.CRITICAL: Plugin class doesn't existMagento 2: How to override newsletter Subscriber modelMagento2 How to show sku in order summary?Magento : Minimum Grandtotal AmountIn Magento 2.2, How to Place the order after GrandTotal is Rs. 0?Checkout Order Summary Update Selected Payment MethodMagento offline custom Payment method with drop down listMonolog Error After 2.2 UpgradeHow to solve Front controller reached 100 router match iterations in magento2In Magento 2, how to set custom grandtotal amount in order, invoice and credit memos













0















I am using Magento2 and in order summary, some customize in tax after grandtotal display old not new so anyone idea to setGrandTotal via a model.



If anyone idea reply to me



Below my code added in this file /vendor/magento/module-tax/Model/Sales/Total/Quote/Tax.php



this is my code added here but in log i get grandtotal proper but in froented side old total display.



public function collect(
MagentoQuoteModelQuote $quote,
MagentoQuoteApiDataShippingAssignmentInterface $shippingAssignment,
MagentoQuoteModelQuoteAddressTotal $total
)
$this->clearValues($total);
if (!$shippingAssignment->getItems())
return $this;


$baseTaxDetails = $this->getQuoteTaxDetails($shippingAssignment, $total, true);
$taxDetails = $this->getQuoteTaxDetails($shippingAssignment, $total, false);

//Populate address and items with tax calculation results
$itemsByType = $this->organizeItemTaxDetailsByType($taxDetails, $baseTaxDetails);
if (isset($itemsByType[self::ITEM_TYPE_PRODUCT]))
$this->processProductItems($shippingAssignment, $itemsByType[self::ITEM_TYPE_PRODUCT], $total);


if (isset($itemsByType[self::ITEM_TYPE_SHIPPING]))
$shippingTaxDetails = $itemsByType[self::ITEM_TYPE_SHIPPING][self::ITEM_CODE_SHIPPING][self::KEY_ITEM];
$baseShippingTaxDetails =
$itemsByType[self::ITEM_TYPE_SHIPPING][self::ITEM_CODE_SHIPPING][self::KEY_BASE_ITEM];
$this->processShippingTaxInfo($shippingAssignment, $total, $shippingTaxDetails, $baseShippingTaxDetails);


//Process taxable items that are not product or shipping
$this->processExtraTaxables($total, $itemsByType);

//Save applied taxes for each item and the quote in aggregation
$this->processAppliedTaxes($total, $shippingAssignment, $itemsByType);

if ($this->includeExtraTax())
$total->addTotalAmount('extra_tax', $total->getExtraTaxAmount());
$total->addBaseTotalAmount('extra_tax', $total->getBaseExtraTaxAmount());



// custom code for

if($regon_id==43)

$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerSession = $objectManager->create('MagentoCheckoutModelSession');
$cart = $objectManager->get('MagentoCheckoutModelCart');
$billingAddress = $cart->getQuote()->getShippingAddress();
$regon_id = $billingAddress->getData('region_id');
$zipcode = $billingAddress->getData('postcode');
$subtotal = $total->getTotalAmount('subtotal');

$writer = new ZendLogWriterStream(BP . '/var/log/tax.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);


$deliveryId = $customerSession->getDeliveryid();

$nyczipcode = $objectManager->get('MagentoFrameworkAppConfigScopeConfigInterface')->getValue('deliveryoptions_customfee/deliveryoptions_customfee/deliveryoptions_zipcode');
$nyczipcode = explode(',', $nyczipcode);

$resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
$connection = $resource->getConnection();
$tcr = $resource->getTableName('tax_calculation_rate');
$taxrate = "select rate from " . $tcr . " WHERE tax_postcode = $zipcode";
$result = $connection->fetchAll($taxrate);


if (!in_array($zipcode, $nyczipcode))
if($deliveryId==11)
$newsubvalue = $subtotal + 200.00;
$taxamount = $newsubvalue / 100 * $result[0]["rate"];


$total->setTaxAmount($taxamount);
$total->setBaseTaxAmount($taxamount);

$setGrandTotal = $newsubvalue + $taxamount;


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

$logger->info("tax if here ".$subtotal);
$logger->info("tax if here ".$taxamount);
$logger->info("tax if here ".$setGrandTotal);

else
$taxamount = $subtotal / 100 * $result[0]["rate"];
$setGrandTotal = $subtotal + $taxamount;

$total->setTaxAmount($taxamount);
$total->setBaseTaxAmount($taxamount);
$total->setGrandTotal($setGrandTotal);
$total->setBaseGrandTotal($setGrandTotal);

$logger->info("tax else dddddhere ".$subtotal);
$logger->info("tax else dddddhere ".$taxamount);
$logger->info("tax else dddddhere ".$setGrandTotal);


else
$setGrandTotal = $subtotal + $taxamount;
$taxamount = $subtotal / 100 * $result[0]["rate"];
$total->setTaxAmount($taxamount);
$total->setBaseTaxAmount($taxamount);
$total->setGrandTotal($setGrandTotal);
$total->setBaseGrandTotal($setGrandTotal);

$logger->info("tax else here ".$subtotal);
$logger->info("tax else here ".$taxamount);
$logger->info("tax else here ".$setGrandTotal);






return $this;










share|improve this question




























    0















    I am using Magento2 and in order summary, some customize in tax after grandtotal display old not new so anyone idea to setGrandTotal via a model.



    If anyone idea reply to me



    Below my code added in this file /vendor/magento/module-tax/Model/Sales/Total/Quote/Tax.php



    this is my code added here but in log i get grandtotal proper but in froented side old total display.



    public function collect(
    MagentoQuoteModelQuote $quote,
    MagentoQuoteApiDataShippingAssignmentInterface $shippingAssignment,
    MagentoQuoteModelQuoteAddressTotal $total
    )
    $this->clearValues($total);
    if (!$shippingAssignment->getItems())
    return $this;


    $baseTaxDetails = $this->getQuoteTaxDetails($shippingAssignment, $total, true);
    $taxDetails = $this->getQuoteTaxDetails($shippingAssignment, $total, false);

    //Populate address and items with tax calculation results
    $itemsByType = $this->organizeItemTaxDetailsByType($taxDetails, $baseTaxDetails);
    if (isset($itemsByType[self::ITEM_TYPE_PRODUCT]))
    $this->processProductItems($shippingAssignment, $itemsByType[self::ITEM_TYPE_PRODUCT], $total);


    if (isset($itemsByType[self::ITEM_TYPE_SHIPPING]))
    $shippingTaxDetails = $itemsByType[self::ITEM_TYPE_SHIPPING][self::ITEM_CODE_SHIPPING][self::KEY_ITEM];
    $baseShippingTaxDetails =
    $itemsByType[self::ITEM_TYPE_SHIPPING][self::ITEM_CODE_SHIPPING][self::KEY_BASE_ITEM];
    $this->processShippingTaxInfo($shippingAssignment, $total, $shippingTaxDetails, $baseShippingTaxDetails);


    //Process taxable items that are not product or shipping
    $this->processExtraTaxables($total, $itemsByType);

    //Save applied taxes for each item and the quote in aggregation
    $this->processAppliedTaxes($total, $shippingAssignment, $itemsByType);

    if ($this->includeExtraTax())
    $total->addTotalAmount('extra_tax', $total->getExtraTaxAmount());
    $total->addBaseTotalAmount('extra_tax', $total->getBaseExtraTaxAmount());



    // custom code for

    if($regon_id==43)

    $objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $customerSession = $objectManager->create('MagentoCheckoutModelSession');
    $cart = $objectManager->get('MagentoCheckoutModelCart');
    $billingAddress = $cart->getQuote()->getShippingAddress();
    $regon_id = $billingAddress->getData('region_id');
    $zipcode = $billingAddress->getData('postcode');
    $subtotal = $total->getTotalAmount('subtotal');

    $writer = new ZendLogWriterStream(BP . '/var/log/tax.log');
    $logger = new ZendLogLogger();
    $logger->addWriter($writer);


    $deliveryId = $customerSession->getDeliveryid();

    $nyczipcode = $objectManager->get('MagentoFrameworkAppConfigScopeConfigInterface')->getValue('deliveryoptions_customfee/deliveryoptions_customfee/deliveryoptions_zipcode');
    $nyczipcode = explode(',', $nyczipcode);

    $resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
    $connection = $resource->getConnection();
    $tcr = $resource->getTableName('tax_calculation_rate');
    $taxrate = "select rate from " . $tcr . " WHERE tax_postcode = $zipcode";
    $result = $connection->fetchAll($taxrate);


    if (!in_array($zipcode, $nyczipcode))
    if($deliveryId==11)
    $newsubvalue = $subtotal + 200.00;
    $taxamount = $newsubvalue / 100 * $result[0]["rate"];


    $total->setTaxAmount($taxamount);
    $total->setBaseTaxAmount($taxamount);

    $setGrandTotal = $newsubvalue + $taxamount;


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

    $logger->info("tax if here ".$subtotal);
    $logger->info("tax if here ".$taxamount);
    $logger->info("tax if here ".$setGrandTotal);

    else
    $taxamount = $subtotal / 100 * $result[0]["rate"];
    $setGrandTotal = $subtotal + $taxamount;

    $total->setTaxAmount($taxamount);
    $total->setBaseTaxAmount($taxamount);
    $total->setGrandTotal($setGrandTotal);
    $total->setBaseGrandTotal($setGrandTotal);

    $logger->info("tax else dddddhere ".$subtotal);
    $logger->info("tax else dddddhere ".$taxamount);
    $logger->info("tax else dddddhere ".$setGrandTotal);


    else
    $setGrandTotal = $subtotal + $taxamount;
    $taxamount = $subtotal / 100 * $result[0]["rate"];
    $total->setTaxAmount($taxamount);
    $total->setBaseTaxAmount($taxamount);
    $total->setGrandTotal($setGrandTotal);
    $total->setBaseGrandTotal($setGrandTotal);

    $logger->info("tax else here ".$subtotal);
    $logger->info("tax else here ".$taxamount);
    $logger->info("tax else here ".$setGrandTotal);






    return $this;










    share|improve this question


























      0












      0








      0








      I am using Magento2 and in order summary, some customize in tax after grandtotal display old not new so anyone idea to setGrandTotal via a model.



      If anyone idea reply to me



      Below my code added in this file /vendor/magento/module-tax/Model/Sales/Total/Quote/Tax.php



      this is my code added here but in log i get grandtotal proper but in froented side old total display.



      public function collect(
      MagentoQuoteModelQuote $quote,
      MagentoQuoteApiDataShippingAssignmentInterface $shippingAssignment,
      MagentoQuoteModelQuoteAddressTotal $total
      )
      $this->clearValues($total);
      if (!$shippingAssignment->getItems())
      return $this;


      $baseTaxDetails = $this->getQuoteTaxDetails($shippingAssignment, $total, true);
      $taxDetails = $this->getQuoteTaxDetails($shippingAssignment, $total, false);

      //Populate address and items with tax calculation results
      $itemsByType = $this->organizeItemTaxDetailsByType($taxDetails, $baseTaxDetails);
      if (isset($itemsByType[self::ITEM_TYPE_PRODUCT]))
      $this->processProductItems($shippingAssignment, $itemsByType[self::ITEM_TYPE_PRODUCT], $total);


      if (isset($itemsByType[self::ITEM_TYPE_SHIPPING]))
      $shippingTaxDetails = $itemsByType[self::ITEM_TYPE_SHIPPING][self::ITEM_CODE_SHIPPING][self::KEY_ITEM];
      $baseShippingTaxDetails =
      $itemsByType[self::ITEM_TYPE_SHIPPING][self::ITEM_CODE_SHIPPING][self::KEY_BASE_ITEM];
      $this->processShippingTaxInfo($shippingAssignment, $total, $shippingTaxDetails, $baseShippingTaxDetails);


      //Process taxable items that are not product or shipping
      $this->processExtraTaxables($total, $itemsByType);

      //Save applied taxes for each item and the quote in aggregation
      $this->processAppliedTaxes($total, $shippingAssignment, $itemsByType);

      if ($this->includeExtraTax())
      $total->addTotalAmount('extra_tax', $total->getExtraTaxAmount());
      $total->addBaseTotalAmount('extra_tax', $total->getBaseExtraTaxAmount());



      // custom code for

      if($regon_id==43)

      $objectManager = MagentoFrameworkAppObjectManager::getInstance();
      $customerSession = $objectManager->create('MagentoCheckoutModelSession');
      $cart = $objectManager->get('MagentoCheckoutModelCart');
      $billingAddress = $cart->getQuote()->getShippingAddress();
      $regon_id = $billingAddress->getData('region_id');
      $zipcode = $billingAddress->getData('postcode');
      $subtotal = $total->getTotalAmount('subtotal');

      $writer = new ZendLogWriterStream(BP . '/var/log/tax.log');
      $logger = new ZendLogLogger();
      $logger->addWriter($writer);


      $deliveryId = $customerSession->getDeliveryid();

      $nyczipcode = $objectManager->get('MagentoFrameworkAppConfigScopeConfigInterface')->getValue('deliveryoptions_customfee/deliveryoptions_customfee/deliveryoptions_zipcode');
      $nyczipcode = explode(',', $nyczipcode);

      $resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
      $connection = $resource->getConnection();
      $tcr = $resource->getTableName('tax_calculation_rate');
      $taxrate = "select rate from " . $tcr . " WHERE tax_postcode = $zipcode";
      $result = $connection->fetchAll($taxrate);


      if (!in_array($zipcode, $nyczipcode))
      if($deliveryId==11)
      $newsubvalue = $subtotal + 200.00;
      $taxamount = $newsubvalue / 100 * $result[0]["rate"];


      $total->setTaxAmount($taxamount);
      $total->setBaseTaxAmount($taxamount);

      $setGrandTotal = $newsubvalue + $taxamount;


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

      $logger->info("tax if here ".$subtotal);
      $logger->info("tax if here ".$taxamount);
      $logger->info("tax if here ".$setGrandTotal);

      else
      $taxamount = $subtotal / 100 * $result[0]["rate"];
      $setGrandTotal = $subtotal + $taxamount;

      $total->setTaxAmount($taxamount);
      $total->setBaseTaxAmount($taxamount);
      $total->setGrandTotal($setGrandTotal);
      $total->setBaseGrandTotal($setGrandTotal);

      $logger->info("tax else dddddhere ".$subtotal);
      $logger->info("tax else dddddhere ".$taxamount);
      $logger->info("tax else dddddhere ".$setGrandTotal);


      else
      $setGrandTotal = $subtotal + $taxamount;
      $taxamount = $subtotal / 100 * $result[0]["rate"];
      $total->setTaxAmount($taxamount);
      $total->setBaseTaxAmount($taxamount);
      $total->setGrandTotal($setGrandTotal);
      $total->setBaseGrandTotal($setGrandTotal);

      $logger->info("tax else here ".$subtotal);
      $logger->info("tax else here ".$taxamount);
      $logger->info("tax else here ".$setGrandTotal);






      return $this;










      share|improve this question
















      I am using Magento2 and in order summary, some customize in tax after grandtotal display old not new so anyone idea to setGrandTotal via a model.



      If anyone idea reply to me



      Below my code added in this file /vendor/magento/module-tax/Model/Sales/Total/Quote/Tax.php



      this is my code added here but in log i get grandtotal proper but in froented side old total display.



      public function collect(
      MagentoQuoteModelQuote $quote,
      MagentoQuoteApiDataShippingAssignmentInterface $shippingAssignment,
      MagentoQuoteModelQuoteAddressTotal $total
      )
      $this->clearValues($total);
      if (!$shippingAssignment->getItems())
      return $this;


      $baseTaxDetails = $this->getQuoteTaxDetails($shippingAssignment, $total, true);
      $taxDetails = $this->getQuoteTaxDetails($shippingAssignment, $total, false);

      //Populate address and items with tax calculation results
      $itemsByType = $this->organizeItemTaxDetailsByType($taxDetails, $baseTaxDetails);
      if (isset($itemsByType[self::ITEM_TYPE_PRODUCT]))
      $this->processProductItems($shippingAssignment, $itemsByType[self::ITEM_TYPE_PRODUCT], $total);


      if (isset($itemsByType[self::ITEM_TYPE_SHIPPING]))
      $shippingTaxDetails = $itemsByType[self::ITEM_TYPE_SHIPPING][self::ITEM_CODE_SHIPPING][self::KEY_ITEM];
      $baseShippingTaxDetails =
      $itemsByType[self::ITEM_TYPE_SHIPPING][self::ITEM_CODE_SHIPPING][self::KEY_BASE_ITEM];
      $this->processShippingTaxInfo($shippingAssignment, $total, $shippingTaxDetails, $baseShippingTaxDetails);


      //Process taxable items that are not product or shipping
      $this->processExtraTaxables($total, $itemsByType);

      //Save applied taxes for each item and the quote in aggregation
      $this->processAppliedTaxes($total, $shippingAssignment, $itemsByType);

      if ($this->includeExtraTax())
      $total->addTotalAmount('extra_tax', $total->getExtraTaxAmount());
      $total->addBaseTotalAmount('extra_tax', $total->getBaseExtraTaxAmount());



      // custom code for

      if($regon_id==43)

      $objectManager = MagentoFrameworkAppObjectManager::getInstance();
      $customerSession = $objectManager->create('MagentoCheckoutModelSession');
      $cart = $objectManager->get('MagentoCheckoutModelCart');
      $billingAddress = $cart->getQuote()->getShippingAddress();
      $regon_id = $billingAddress->getData('region_id');
      $zipcode = $billingAddress->getData('postcode');
      $subtotal = $total->getTotalAmount('subtotal');

      $writer = new ZendLogWriterStream(BP . '/var/log/tax.log');
      $logger = new ZendLogLogger();
      $logger->addWriter($writer);


      $deliveryId = $customerSession->getDeliveryid();

      $nyczipcode = $objectManager->get('MagentoFrameworkAppConfigScopeConfigInterface')->getValue('deliveryoptions_customfee/deliveryoptions_customfee/deliveryoptions_zipcode');
      $nyczipcode = explode(',', $nyczipcode);

      $resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
      $connection = $resource->getConnection();
      $tcr = $resource->getTableName('tax_calculation_rate');
      $taxrate = "select rate from " . $tcr . " WHERE tax_postcode = $zipcode";
      $result = $connection->fetchAll($taxrate);


      if (!in_array($zipcode, $nyczipcode))
      if($deliveryId==11)
      $newsubvalue = $subtotal + 200.00;
      $taxamount = $newsubvalue / 100 * $result[0]["rate"];


      $total->setTaxAmount($taxamount);
      $total->setBaseTaxAmount($taxamount);

      $setGrandTotal = $newsubvalue + $taxamount;


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

      $logger->info("tax if here ".$subtotal);
      $logger->info("tax if here ".$taxamount);
      $logger->info("tax if here ".$setGrandTotal);

      else
      $taxamount = $subtotal / 100 * $result[0]["rate"];
      $setGrandTotal = $subtotal + $taxamount;

      $total->setTaxAmount($taxamount);
      $total->setBaseTaxAmount($taxamount);
      $total->setGrandTotal($setGrandTotal);
      $total->setBaseGrandTotal($setGrandTotal);

      $logger->info("tax else dddddhere ".$subtotal);
      $logger->info("tax else dddddhere ".$taxamount);
      $logger->info("tax else dddddhere ".$setGrandTotal);


      else
      $setGrandTotal = $subtotal + $taxamount;
      $taxamount = $subtotal / 100 * $result[0]["rate"];
      $total->setTaxAmount($taxamount);
      $total->setBaseTaxAmount($taxamount);
      $total->setGrandTotal($setGrandTotal);
      $total->setBaseGrandTotal($setGrandTotal);

      $logger->info("tax else here ".$subtotal);
      $logger->info("tax else here ".$taxamount);
      $logger->info("tax else here ".$setGrandTotal);






      return $this;







      magento2 checkout grand-total order-summary






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday







      Rv Singh

















      asked yesterday









      Rv SinghRv Singh

      696417




      696417




















          1 Answer
          1






          active

          oldest

          votes


















          0














          I did it before with this code.



          if ($discountAmount >= 0) 
          $total = $quote->getBaseSubtotal();
          $quote->setSubtotal(0);
          $quote->setBaseSubtotal(0);

          $quote->setSubtotalWithDiscount(0);
          $quote->setBaseSubtotalWithDiscount(0);

          $quote->setGrandTotal(0);
          $quote->setBaseGrandTotal(0);

          $canAddItems = $quote->isVirtual() ? ('billing') : ('shipping');
          foreach ($quote->getAllAddresses() as $address)

          $address->setSubtotal($priceTotal);
          $address->setBaseSubtotal($priceTotal);

          $address->setGrandTotal($priceTotal - $discountAmount + $taxTotal);
          $address->setBaseGrandTotal($priceTotal - $discountAmount + $taxTotal);

          $quote->setSubtotal($priceTotal);
          $quote->setBaseSubtotal($priceTotal);

          $quote->setSubtotalWithDiscount(
          ($priceTotal - $discountAmount)
          );
          $quote->setBaseSubtotalWithDiscount(
          ($priceTotal - $discountAmount)
          );

          $quote->setGrandTotal($priceTotal - $discountAmount + $taxTotal);
          $quote->setBaseGrandTotal($priceTotal - $discountAmount + $taxTotal);

          $quote->save();

          $quote->setGrandTotal($priceTotal - $discountAmount + $taxTotal)
          ->setBaseGrandTotal($priceTotal - $discountAmount + $taxTotal)
          ->setSubtotalWithDiscount($priceTotal - $discountAmount)
          ->setBaseSubtotalWithDiscount($priceTotal - $discountAmount)
          ->save();

          if ($address->getAddressType() == $canAddItems)
          $address->setSubtotalWithDiscount($priceTotal - $discountAmount + $taxTotal);
          $address->setGrandTotal($priceTotal - $discountAmount + $taxTotal);
          $address->setBaseSubtotalWithDiscount($priceTotal - $discountAmount + $taxTotal);
          $address->setBaseGrandTotal($priceTotal - $discountAmount + $taxTotal);

          $address->setTaxAmount($taxTotal);
          $address->setBaseTaxAmount($taxTotal);

          if ($address->getDiscountDescription())
          $address->setDiscountAmount(-($discountAmount));
          // $address->setDiscountDescription($address->getDiscountDescription() . ', Gift Sets');
          $address->setBaseDiscountAmount(-($discountAmount));
          else
          $address->setDiscountAmount(-($discountAmount));
          // $address->setDiscountDescription('');
          $address->setBaseDiscountAmount(-($discountAmount));

          $address->save();



          foreach ($quote->getAllItems() as $item)
          $item->setDiscountAmount(0);
          $item->setBaseDiscountAmount(0)->save();




          Update :
          Yes, you will get wrong in the frontend side, cause you don't do it with event. Try to did it too with sales_quote_collect_totals_afterevent to change the grand total.






          share|improve this answer
























            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "479"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f266604%2fmagento-2-how-to-grandtotal-in-order-summary-set-via-model%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I did it before with this code.



            if ($discountAmount >= 0) 
            $total = $quote->getBaseSubtotal();
            $quote->setSubtotal(0);
            $quote->setBaseSubtotal(0);

            $quote->setSubtotalWithDiscount(0);
            $quote->setBaseSubtotalWithDiscount(0);

            $quote->setGrandTotal(0);
            $quote->setBaseGrandTotal(0);

            $canAddItems = $quote->isVirtual() ? ('billing') : ('shipping');
            foreach ($quote->getAllAddresses() as $address)

            $address->setSubtotal($priceTotal);
            $address->setBaseSubtotal($priceTotal);

            $address->setGrandTotal($priceTotal - $discountAmount + $taxTotal);
            $address->setBaseGrandTotal($priceTotal - $discountAmount + $taxTotal);

            $quote->setSubtotal($priceTotal);
            $quote->setBaseSubtotal($priceTotal);

            $quote->setSubtotalWithDiscount(
            ($priceTotal - $discountAmount)
            );
            $quote->setBaseSubtotalWithDiscount(
            ($priceTotal - $discountAmount)
            );

            $quote->setGrandTotal($priceTotal - $discountAmount + $taxTotal);
            $quote->setBaseGrandTotal($priceTotal - $discountAmount + $taxTotal);

            $quote->save();

            $quote->setGrandTotal($priceTotal - $discountAmount + $taxTotal)
            ->setBaseGrandTotal($priceTotal - $discountAmount + $taxTotal)
            ->setSubtotalWithDiscount($priceTotal - $discountAmount)
            ->setBaseSubtotalWithDiscount($priceTotal - $discountAmount)
            ->save();

            if ($address->getAddressType() == $canAddItems)
            $address->setSubtotalWithDiscount($priceTotal - $discountAmount + $taxTotal);
            $address->setGrandTotal($priceTotal - $discountAmount + $taxTotal);
            $address->setBaseSubtotalWithDiscount($priceTotal - $discountAmount + $taxTotal);
            $address->setBaseGrandTotal($priceTotal - $discountAmount + $taxTotal);

            $address->setTaxAmount($taxTotal);
            $address->setBaseTaxAmount($taxTotal);

            if ($address->getDiscountDescription())
            $address->setDiscountAmount(-($discountAmount));
            // $address->setDiscountDescription($address->getDiscountDescription() . ', Gift Sets');
            $address->setBaseDiscountAmount(-($discountAmount));
            else
            $address->setDiscountAmount(-($discountAmount));
            // $address->setDiscountDescription('');
            $address->setBaseDiscountAmount(-($discountAmount));

            $address->save();



            foreach ($quote->getAllItems() as $item)
            $item->setDiscountAmount(0);
            $item->setBaseDiscountAmount(0)->save();




            Update :
            Yes, you will get wrong in the frontend side, cause you don't do it with event. Try to did it too with sales_quote_collect_totals_afterevent to change the grand total.






            share|improve this answer





























              0














              I did it before with this code.



              if ($discountAmount >= 0) 
              $total = $quote->getBaseSubtotal();
              $quote->setSubtotal(0);
              $quote->setBaseSubtotal(0);

              $quote->setSubtotalWithDiscount(0);
              $quote->setBaseSubtotalWithDiscount(0);

              $quote->setGrandTotal(0);
              $quote->setBaseGrandTotal(0);

              $canAddItems = $quote->isVirtual() ? ('billing') : ('shipping');
              foreach ($quote->getAllAddresses() as $address)

              $address->setSubtotal($priceTotal);
              $address->setBaseSubtotal($priceTotal);

              $address->setGrandTotal($priceTotal - $discountAmount + $taxTotal);
              $address->setBaseGrandTotal($priceTotal - $discountAmount + $taxTotal);

              $quote->setSubtotal($priceTotal);
              $quote->setBaseSubtotal($priceTotal);

              $quote->setSubtotalWithDiscount(
              ($priceTotal - $discountAmount)
              );
              $quote->setBaseSubtotalWithDiscount(
              ($priceTotal - $discountAmount)
              );

              $quote->setGrandTotal($priceTotal - $discountAmount + $taxTotal);
              $quote->setBaseGrandTotal($priceTotal - $discountAmount + $taxTotal);

              $quote->save();

              $quote->setGrandTotal($priceTotal - $discountAmount + $taxTotal)
              ->setBaseGrandTotal($priceTotal - $discountAmount + $taxTotal)
              ->setSubtotalWithDiscount($priceTotal - $discountAmount)
              ->setBaseSubtotalWithDiscount($priceTotal - $discountAmount)
              ->save();

              if ($address->getAddressType() == $canAddItems)
              $address->setSubtotalWithDiscount($priceTotal - $discountAmount + $taxTotal);
              $address->setGrandTotal($priceTotal - $discountAmount + $taxTotal);
              $address->setBaseSubtotalWithDiscount($priceTotal - $discountAmount + $taxTotal);
              $address->setBaseGrandTotal($priceTotal - $discountAmount + $taxTotal);

              $address->setTaxAmount($taxTotal);
              $address->setBaseTaxAmount($taxTotal);

              if ($address->getDiscountDescription())
              $address->setDiscountAmount(-($discountAmount));
              // $address->setDiscountDescription($address->getDiscountDescription() . ', Gift Sets');
              $address->setBaseDiscountAmount(-($discountAmount));
              else
              $address->setDiscountAmount(-($discountAmount));
              // $address->setDiscountDescription('');
              $address->setBaseDiscountAmount(-($discountAmount));

              $address->save();



              foreach ($quote->getAllItems() as $item)
              $item->setDiscountAmount(0);
              $item->setBaseDiscountAmount(0)->save();




              Update :
              Yes, you will get wrong in the frontend side, cause you don't do it with event. Try to did it too with sales_quote_collect_totals_afterevent to change the grand total.






              share|improve this answer



























                0












                0








                0







                I did it before with this code.



                if ($discountAmount >= 0) 
                $total = $quote->getBaseSubtotal();
                $quote->setSubtotal(0);
                $quote->setBaseSubtotal(0);

                $quote->setSubtotalWithDiscount(0);
                $quote->setBaseSubtotalWithDiscount(0);

                $quote->setGrandTotal(0);
                $quote->setBaseGrandTotal(0);

                $canAddItems = $quote->isVirtual() ? ('billing') : ('shipping');
                foreach ($quote->getAllAddresses() as $address)

                $address->setSubtotal($priceTotal);
                $address->setBaseSubtotal($priceTotal);

                $address->setGrandTotal($priceTotal - $discountAmount + $taxTotal);
                $address->setBaseGrandTotal($priceTotal - $discountAmount + $taxTotal);

                $quote->setSubtotal($priceTotal);
                $quote->setBaseSubtotal($priceTotal);

                $quote->setSubtotalWithDiscount(
                ($priceTotal - $discountAmount)
                );
                $quote->setBaseSubtotalWithDiscount(
                ($priceTotal - $discountAmount)
                );

                $quote->setGrandTotal($priceTotal - $discountAmount + $taxTotal);
                $quote->setBaseGrandTotal($priceTotal - $discountAmount + $taxTotal);

                $quote->save();

                $quote->setGrandTotal($priceTotal - $discountAmount + $taxTotal)
                ->setBaseGrandTotal($priceTotal - $discountAmount + $taxTotal)
                ->setSubtotalWithDiscount($priceTotal - $discountAmount)
                ->setBaseSubtotalWithDiscount($priceTotal - $discountAmount)
                ->save();

                if ($address->getAddressType() == $canAddItems)
                $address->setSubtotalWithDiscount($priceTotal - $discountAmount + $taxTotal);
                $address->setGrandTotal($priceTotal - $discountAmount + $taxTotal);
                $address->setBaseSubtotalWithDiscount($priceTotal - $discountAmount + $taxTotal);
                $address->setBaseGrandTotal($priceTotal - $discountAmount + $taxTotal);

                $address->setTaxAmount($taxTotal);
                $address->setBaseTaxAmount($taxTotal);

                if ($address->getDiscountDescription())
                $address->setDiscountAmount(-($discountAmount));
                // $address->setDiscountDescription($address->getDiscountDescription() . ', Gift Sets');
                $address->setBaseDiscountAmount(-($discountAmount));
                else
                $address->setDiscountAmount(-($discountAmount));
                // $address->setDiscountDescription('');
                $address->setBaseDiscountAmount(-($discountAmount));

                $address->save();



                foreach ($quote->getAllItems() as $item)
                $item->setDiscountAmount(0);
                $item->setBaseDiscountAmount(0)->save();




                Update :
                Yes, you will get wrong in the frontend side, cause you don't do it with event. Try to did it too with sales_quote_collect_totals_afterevent to change the grand total.






                share|improve this answer















                I did it before with this code.



                if ($discountAmount >= 0) 
                $total = $quote->getBaseSubtotal();
                $quote->setSubtotal(0);
                $quote->setBaseSubtotal(0);

                $quote->setSubtotalWithDiscount(0);
                $quote->setBaseSubtotalWithDiscount(0);

                $quote->setGrandTotal(0);
                $quote->setBaseGrandTotal(0);

                $canAddItems = $quote->isVirtual() ? ('billing') : ('shipping');
                foreach ($quote->getAllAddresses() as $address)

                $address->setSubtotal($priceTotal);
                $address->setBaseSubtotal($priceTotal);

                $address->setGrandTotal($priceTotal - $discountAmount + $taxTotal);
                $address->setBaseGrandTotal($priceTotal - $discountAmount + $taxTotal);

                $quote->setSubtotal($priceTotal);
                $quote->setBaseSubtotal($priceTotal);

                $quote->setSubtotalWithDiscount(
                ($priceTotal - $discountAmount)
                );
                $quote->setBaseSubtotalWithDiscount(
                ($priceTotal - $discountAmount)
                );

                $quote->setGrandTotal($priceTotal - $discountAmount + $taxTotal);
                $quote->setBaseGrandTotal($priceTotal - $discountAmount + $taxTotal);

                $quote->save();

                $quote->setGrandTotal($priceTotal - $discountAmount + $taxTotal)
                ->setBaseGrandTotal($priceTotal - $discountAmount + $taxTotal)
                ->setSubtotalWithDiscount($priceTotal - $discountAmount)
                ->setBaseSubtotalWithDiscount($priceTotal - $discountAmount)
                ->save();

                if ($address->getAddressType() == $canAddItems)
                $address->setSubtotalWithDiscount($priceTotal - $discountAmount + $taxTotal);
                $address->setGrandTotal($priceTotal - $discountAmount + $taxTotal);
                $address->setBaseSubtotalWithDiscount($priceTotal - $discountAmount + $taxTotal);
                $address->setBaseGrandTotal($priceTotal - $discountAmount + $taxTotal);

                $address->setTaxAmount($taxTotal);
                $address->setBaseTaxAmount($taxTotal);

                if ($address->getDiscountDescription())
                $address->setDiscountAmount(-($discountAmount));
                // $address->setDiscountDescription($address->getDiscountDescription() . ', Gift Sets');
                $address->setBaseDiscountAmount(-($discountAmount));
                else
                $address->setDiscountAmount(-($discountAmount));
                // $address->setDiscountDescription('');
                $address->setBaseDiscountAmount(-($discountAmount));

                $address->save();



                foreach ($quote->getAllItems() as $item)
                $item->setDiscountAmount(0);
                $item->setBaseDiscountAmount(0)->save();




                Update :
                Yes, you will get wrong in the frontend side, cause you don't do it with event. Try to did it too with sales_quote_collect_totals_afterevent to change the grand total.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 22 hours ago

























                answered yesterday









                Edwin WidhiyantoEdwin Widhiyanto

                432421




                432421



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Magento Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f266604%2fmagento-2-how-to-grandtotal-in-order-summary-set-via-model%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Sum ergo cogito? 1 nng

                    419 nièngy_Soadمي 19bal1.5o_g

                    Queiggey Chernihivv 9NnOo i Zw X QqKk LpB