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

Quoting Keynes in a lecture

What is the meaning of "You've never met a graph you didn't like?"

What does "Scientists rise up against statistical significance" mean? (Comment in Nature)

If Captain Marvel (MCU) were to have a child with a human male, would the child be human or Kree?

Pre-Employment Background Check With Consent For Future Checks

Proving an identity involving cross products and coplanar vectors

Can I run 125kHz RF circuit on a breadboard?

Does the Crossbow Expert feat's extra crossbow attack work with the reaction attack from a Hunter ranger's Giant Killer feature?

How do I tell my boss that I'm quitting in 15 days (a colleague left this week)

Difference between shutdown options

Why is the Sun approximated as a black body at ~ 5800 K?

How would a solely written language work mechanically

Isometric embedding of a genus g surface

Has the laser at Magurele, Romania reached a tenth of the Sun's power?

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

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

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

How to leave product feedback on macOS?

How do I prevent inappropriate ads from appearing in my game?

Can I cause damage to electrical appliances by unplugging them when they are turned on?

Why Shazam when there is already Superman?

If the only attacker is removed from combat, is a creature still counted as having attacked this turn?

Alignment of six matrices

Given this phrasing in the lease, when should I pay my rent?



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

                    三茅街道4182Guuntc Dn precexpngmageondP