Adding custom discount adds 2 times Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Dynamically change discount cost in cartDiscounted shopping cart not working with PayPalMagento 2 - Add Custom Discount to Order Totals on Cart pageMagento 2 - Update Cart Block with Custom Discount Valueshopping cart discount rule only applying to specific productsHow to Round off Discount price?Magento 2: Sub total is not updating on custom discount (Substraction is not working with dynamic value in cart)Magento 2 : How to Apply Custom Discount from Controller?Magento 2 : How to Set custom Discount from controller?Magento 2: How to get discount price for each cart rule in quote

If I can make up priors, why can't I make up posteriors?

What do you call the holes in a flute?

grandmas drink with lemon juice

90's book, teen horror

Typsetting diagram chases (with TikZ?)

How to say 'striped' in Latin

Area of a 2D convex hull

Who can trigger ship-wide alerts in Star Trek?

Passing functions in C++

Why don't the Weasley twins use magic outside of school if the Trace can only find the location of spells cast?

How to set letter above or below the symbol?

Estimate capacitor parameters

Did the new image of black hole confirm the general theory of relativity?

Using "nakedly" instead of "with nothing on"

How to say that you spent the night with someone, you were only sleeping and nothing else?

Why is "Captain Marvel" translated as male in Portugal?

How to rotate it perfectly?

Can a zero nonce be safely used with AES-GCM if the key is random and never used again?

The following signatures were invalid: EXPKEYSIG 1397BC53640DB551

When communicating altitude with a '9' in it, should it be pronounced "nine hundred" or "niner hundred"?

Autumning in love

Is drag coefficient lowest at zero angle of attack?

Can a non-EU citizen traveling with me come with me through the EU passport line?

3 doors, three guards, one stone



Adding custom discount adds 2 times



Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Dynamically change discount cost in cartDiscounted shopping cart not working with PayPalMagento 2 - Add Custom Discount to Order Totals on Cart pageMagento 2 - Update Cart Block with Custom Discount Valueshopping cart discount rule only applying to specific productsHow to Round off Discount price?Magento 2: Sub total is not updating on custom discount (Substraction is not working with dynamic value in cart)Magento 2 : How to Apply Custom Discount from Controller?Magento 2 : How to Set custom Discount from controller?Magento 2: How to get discount price for each cart rule in quote



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am adding custom discount to my cart but it seems it is adding 2 times in the cart.



Here is my model file code.



$discount = 10;
$baseDiscount = 10;

$total->addTotalAmount('plandiscount', -$discount);
$total->addBaseTotalAmount('plandiscount', -$baseDiscount);
$total->setPlanDiscount(-$discount);
$total->setBasePlanDiscount(-$baseDiscount);
$quote->setGrandTotal($total->getGrandTotal() - $discount);
$quote->setBaseGrandTotal($total->getBaseGrandTotal() - $baseDiscount);

$quote->setPlanDiscount(-$discount);
$quote->setBasePlanDiscount(-$baseDiscount);


It is really strange that if the value is positive, it is working fine but in case of negative, it is adding 2 times.










share|improve this question






















  • Why you added setPlanDiscount and setBasePlanDiscount twice? that might be causing the issue, please check your code again.

    – Aasim Goriya
    9 mins ago











  • No that is not the trouble. The line $total->addTotalAmount('plandiscount', -$discount); is adding the discount. If i comment everything except that line, then also discount will work.

    – Yash Shah
    7 mins ago











  • I'm talking about this line : $quote->setPlanDiscount(-$discount);

    – Aasim Goriya
    6 mins ago











  • i understand but that line is not creating trouble, i just checked removing as u said.

    – Yash Shah
    5 mins ago











  • Please check my ans, hope it will fix your issue.

    – Aasim Goriya
    just now

















0















I am adding custom discount to my cart but it seems it is adding 2 times in the cart.



Here is my model file code.



$discount = 10;
$baseDiscount = 10;

$total->addTotalAmount('plandiscount', -$discount);
$total->addBaseTotalAmount('plandiscount', -$baseDiscount);
$total->setPlanDiscount(-$discount);
$total->setBasePlanDiscount(-$baseDiscount);
$quote->setGrandTotal($total->getGrandTotal() - $discount);
$quote->setBaseGrandTotal($total->getBaseGrandTotal() - $baseDiscount);

$quote->setPlanDiscount(-$discount);
$quote->setBasePlanDiscount(-$baseDiscount);


It is really strange that if the value is positive, it is working fine but in case of negative, it is adding 2 times.










share|improve this question






















  • Why you added setPlanDiscount and setBasePlanDiscount twice? that might be causing the issue, please check your code again.

    – Aasim Goriya
    9 mins ago











  • No that is not the trouble. The line $total->addTotalAmount('plandiscount', -$discount); is adding the discount. If i comment everything except that line, then also discount will work.

    – Yash Shah
    7 mins ago











  • I'm talking about this line : $quote->setPlanDiscount(-$discount);

    – Aasim Goriya
    6 mins ago











  • i understand but that line is not creating trouble, i just checked removing as u said.

    – Yash Shah
    5 mins ago











  • Please check my ans, hope it will fix your issue.

    – Aasim Goriya
    just now













0












0








0








I am adding custom discount to my cart but it seems it is adding 2 times in the cart.



Here is my model file code.



$discount = 10;
$baseDiscount = 10;

$total->addTotalAmount('plandiscount', -$discount);
$total->addBaseTotalAmount('plandiscount', -$baseDiscount);
$total->setPlanDiscount(-$discount);
$total->setBasePlanDiscount(-$baseDiscount);
$quote->setGrandTotal($total->getGrandTotal() - $discount);
$quote->setBaseGrandTotal($total->getBaseGrandTotal() - $baseDiscount);

$quote->setPlanDiscount(-$discount);
$quote->setBasePlanDiscount(-$baseDiscount);


It is really strange that if the value is positive, it is working fine but in case of negative, it is adding 2 times.










share|improve this question














I am adding custom discount to my cart but it seems it is adding 2 times in the cart.



Here is my model file code.



$discount = 10;
$baseDiscount = 10;

$total->addTotalAmount('plandiscount', -$discount);
$total->addBaseTotalAmount('plandiscount', -$baseDiscount);
$total->setPlanDiscount(-$discount);
$total->setBasePlanDiscount(-$baseDiscount);
$quote->setGrandTotal($total->getGrandTotal() - $discount);
$quote->setBaseGrandTotal($total->getBaseGrandTotal() - $baseDiscount);

$quote->setPlanDiscount(-$discount);
$quote->setBasePlanDiscount(-$baseDiscount);


It is really strange that if the value is positive, it is working fine but in case of negative, it is adding 2 times.







magento2 discount






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 15 mins ago









Yash ShahYash Shah

78118




78118












  • Why you added setPlanDiscount and setBasePlanDiscount twice? that might be causing the issue, please check your code again.

    – Aasim Goriya
    9 mins ago











  • No that is not the trouble. The line $total->addTotalAmount('plandiscount', -$discount); is adding the discount. If i comment everything except that line, then also discount will work.

    – Yash Shah
    7 mins ago











  • I'm talking about this line : $quote->setPlanDiscount(-$discount);

    – Aasim Goriya
    6 mins ago











  • i understand but that line is not creating trouble, i just checked removing as u said.

    – Yash Shah
    5 mins ago











  • Please check my ans, hope it will fix your issue.

    – Aasim Goriya
    just now

















  • Why you added setPlanDiscount and setBasePlanDiscount twice? that might be causing the issue, please check your code again.

    – Aasim Goriya
    9 mins ago











  • No that is not the trouble. The line $total->addTotalAmount('plandiscount', -$discount); is adding the discount. If i comment everything except that line, then also discount will work.

    – Yash Shah
    7 mins ago











  • I'm talking about this line : $quote->setPlanDiscount(-$discount);

    – Aasim Goriya
    6 mins ago











  • i understand but that line is not creating trouble, i just checked removing as u said.

    – Yash Shah
    5 mins ago











  • Please check my ans, hope it will fix your issue.

    – Aasim Goriya
    just now
















Why you added setPlanDiscount and setBasePlanDiscount twice? that might be causing the issue, please check your code again.

– Aasim Goriya
9 mins ago





Why you added setPlanDiscount and setBasePlanDiscount twice? that might be causing the issue, please check your code again.

– Aasim Goriya
9 mins ago













No that is not the trouble. The line $total->addTotalAmount('plandiscount', -$discount); is adding the discount. If i comment everything except that line, then also discount will work.

– Yash Shah
7 mins ago





No that is not the trouble. The line $total->addTotalAmount('plandiscount', -$discount); is adding the discount. If i comment everything except that line, then also discount will work.

– Yash Shah
7 mins ago













I'm talking about this line : $quote->setPlanDiscount(-$discount);

– Aasim Goriya
6 mins ago





I'm talking about this line : $quote->setPlanDiscount(-$discount);

– Aasim Goriya
6 mins ago













i understand but that line is not creating trouble, i just checked removing as u said.

– Yash Shah
5 mins ago





i understand but that line is not creating trouble, i just checked removing as u said.

– Yash Shah
5 mins ago













Please check my ans, hope it will fix your issue.

– Aasim Goriya
just now





Please check my ans, hope it will fix your issue.

– Aasim Goriya
just now










1 Answer
1






active

oldest

votes


















0














Please try this way to applied custom discount



$discountAmount ="-10";
$appliedCartDiscount = $total->getDiscountAmount();

$total->setDiscountAmount($discountAmount);
$total->setBaseDiscountAmount($discountAmount);
$total->setSubtotalWithDiscount($total->getSubtotal() + $discountAmount);
$total->setBaseSubtotalWithDiscount($total->getBaseSubtotal() + $discountAmount);

if(isset($appliedCartDiscount))

$total->addTotalAmount('plandiscount', $discountAmount - $appliedCartDiscount);
$total->addBaseTotalAmount('plandiscount', $discountAmount - $appliedCartDiscount);

else

$total->addTotalAmount('plandiscount', $discountAmount);
$total->addBaseTotalAmount('plandiscount', $discountAmount);





share























    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%2f270055%2fadding-custom-discount-adds-2-times%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














    Please try this way to applied custom discount



    $discountAmount ="-10";
    $appliedCartDiscount = $total->getDiscountAmount();

    $total->setDiscountAmount($discountAmount);
    $total->setBaseDiscountAmount($discountAmount);
    $total->setSubtotalWithDiscount($total->getSubtotal() + $discountAmount);
    $total->setBaseSubtotalWithDiscount($total->getBaseSubtotal() + $discountAmount);

    if(isset($appliedCartDiscount))

    $total->addTotalAmount('plandiscount', $discountAmount - $appliedCartDiscount);
    $total->addBaseTotalAmount('plandiscount', $discountAmount - $appliedCartDiscount);

    else

    $total->addTotalAmount('plandiscount', $discountAmount);
    $total->addBaseTotalAmount('plandiscount', $discountAmount);





    share



























      0














      Please try this way to applied custom discount



      $discountAmount ="-10";
      $appliedCartDiscount = $total->getDiscountAmount();

      $total->setDiscountAmount($discountAmount);
      $total->setBaseDiscountAmount($discountAmount);
      $total->setSubtotalWithDiscount($total->getSubtotal() + $discountAmount);
      $total->setBaseSubtotalWithDiscount($total->getBaseSubtotal() + $discountAmount);

      if(isset($appliedCartDiscount))

      $total->addTotalAmount('plandiscount', $discountAmount - $appliedCartDiscount);
      $total->addBaseTotalAmount('plandiscount', $discountAmount - $appliedCartDiscount);

      else

      $total->addTotalAmount('plandiscount', $discountAmount);
      $total->addBaseTotalAmount('plandiscount', $discountAmount);





      share

























        0












        0








        0







        Please try this way to applied custom discount



        $discountAmount ="-10";
        $appliedCartDiscount = $total->getDiscountAmount();

        $total->setDiscountAmount($discountAmount);
        $total->setBaseDiscountAmount($discountAmount);
        $total->setSubtotalWithDiscount($total->getSubtotal() + $discountAmount);
        $total->setBaseSubtotalWithDiscount($total->getBaseSubtotal() + $discountAmount);

        if(isset($appliedCartDiscount))

        $total->addTotalAmount('plandiscount', $discountAmount - $appliedCartDiscount);
        $total->addBaseTotalAmount('plandiscount', $discountAmount - $appliedCartDiscount);

        else

        $total->addTotalAmount('plandiscount', $discountAmount);
        $total->addBaseTotalAmount('plandiscount', $discountAmount);





        share













        Please try this way to applied custom discount



        $discountAmount ="-10";
        $appliedCartDiscount = $total->getDiscountAmount();

        $total->setDiscountAmount($discountAmount);
        $total->setBaseDiscountAmount($discountAmount);
        $total->setSubtotalWithDiscount($total->getSubtotal() + $discountAmount);
        $total->setBaseSubtotalWithDiscount($total->getBaseSubtotal() + $discountAmount);

        if(isset($appliedCartDiscount))

        $total->addTotalAmount('plandiscount', $discountAmount - $appliedCartDiscount);
        $total->addBaseTotalAmount('plandiscount', $discountAmount - $appliedCartDiscount);

        else

        $total->addTotalAmount('plandiscount', $discountAmount);
        $total->addBaseTotalAmount('plandiscount', $discountAmount);






        share











        share


        share










        answered 33 secs ago









        Aasim GoriyaAasim Goriya

        2,93611039




        2,93611039



























            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%2f270055%2fadding-custom-discount-adds-2-times%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

            Disable / Remove link to Product Items in Cart Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?How can I limit products that can be bought / added to cart?Remove item from cartHide “Add to Cart” button if specific products are already in cart“Prettifying” the custom options in cart pageCreate link in cart sidebar to view all added items After limit reachedLink products together in checkout/cartHow to Get product from cart and add it againHide action-edit on cart page if simple productRemoving Cart items - ObserverRemove wishlist items when added to cart

            Helsingin valtaus Sisällysluettelo Taustaa | Yleistä sotatoimista | Osapuolet | Taistelut Helsingin ympäristössä | Punaisten antautumissuunnitelma | Taistelujen kulku Helsingissä | Valtauksen jälkeen | Tappiot | Muistaminen | Kirjallisuutta | Lähteet | Aiheesta muualla | NavigointivalikkoTeoksen verkkoversioTeoksen verkkoversioGoogle BooksSisällissota Helsingissä päättyi tasan 95 vuotta sittenSaksalaisten ylivoima jyräsi punaisen HelsinginSuomalaiset kuvaavat sotien jälkiä kaupungeissa – katso kuvat ja tarinat tutuilta kulmiltaHelsingin valtaus 90 vuotta sittenSaksalaiset valtasivat HelsinginHyökkäys HelsinkiinHelsingin valtaus 12.–13.4. 1918Saksalaiset käyttivät ihmiskilpiä Helsingin valtauksessa 1918Teoksen verkkoversioTeoksen verkkoversioSaksalaiset hyökkäävät Etelä-SuomeenTaistelut LeppävaarassaSotilaat ja taistelutLeppävaara 1918 huhtikuussa. KapinatarinaHelsingin taistelut 1918Saksalaisten voitonparaati HelsingissäHelsingin valtausta juhlittiinSaksalaisten Helsinki vuonna 1918Helsingin taistelussa kaatuneet valkokaartilaisetHelsinkiin haudatut taisteluissa kaatuneet punaiset12.4.1918 Helsingin valtauksessa saksalaiset apujoukot vapauttavat kaupunginVapaussodan muistomerkkejä Helsingissä ja pääkaupunkiseudullaCrescendo / Vuoden 1918 Kansalaissodan uhrien muistomerkkim

            Adjektiivitarina Tarinan tekeminen | Esimerkki: ennen | Esimerkki: jälkeen | Navigointivalikko