Adding custom discount adds 2 times in EE 2.2.6 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

How to tell that you are a giant?

Why did the IBM 650 use bi-quinary?

Seeking colloquialism for “just because”

Why am I getting the error "non-boolean type specified in a context where a condition is expected" for this request?

How to react to hostile behavior from a senior developer?

Output the ŋarâþ crîþ alphabet song without using (m)any letters

What causes the vertical darker bands in my photo?

Denied boarding although I have proper visa and documentation. To whom should I make a complaint?

Withdrew £2800, but only £2000 shows as withdrawn on online banking; what are my obligations?

How to answer "Have you ever been terminated?"

Identify plant with long narrow paired leaves and reddish stems

What does the "x" in "x86" represent?

What is the role of the transistor and diode in a soft start circuit?

How would the world control an invulnerable immortal mass murderer?

How to find all the available tools in macOS terminal?

Is the Standard Deduction better than Itemized when both are the same amount?

51k Euros annually for a family of 4 in Berlin: Is it enough?

Selecting the same column from Different rows Based on Different Criteria

Why is "Consequences inflicted." not a sentence?

What's the purpose of writing one's academic biography in the third person?

Check which numbers satisfy the condition [A*B*C = A! + B! + C!]

Storing hydrofluoric acid before the invention of plastics

How to deal with a team lead who never gives me credit?

What exactly is a "Meth" in Altered Carbon?



Adding custom discount adds 2 times in EE 2.2.6



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;








1















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
    yesterday











  • 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
    yesterday











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

    – Aasim Goriya
    yesterday











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

    – Yash Shah
    yesterday











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

    – Aasim Goriya
    yesterday


















1















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
    yesterday











  • 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
    yesterday











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

    – Aasim Goriya
    yesterday











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

    – Yash Shah
    yesterday











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

    – Aasim Goriya
    yesterday














1












1








1








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








edited yesterday







Yash Shah

















asked yesterday









Yash ShahYash Shah

83118




83118












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

    – Aasim Goriya
    yesterday











  • 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
    yesterday











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

    – Aasim Goriya
    yesterday











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

    – Yash Shah
    yesterday











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

    – Aasim Goriya
    yesterday


















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

    – Aasim Goriya
    yesterday











  • 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
    yesterday











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

    – Aasim Goriya
    yesterday











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

    – Yash Shah
    yesterday











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

    – Aasim Goriya
    yesterday

















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

– Aasim Goriya
yesterday





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

– Aasim Goriya
yesterday













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
yesterday





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
yesterday













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

– Aasim Goriya
yesterday





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

– Aasim Goriya
yesterday













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

– Yash Shah
yesterday





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

– Yash Shah
yesterday













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

– Aasim Goriya
yesterday






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

– Aasim Goriya
yesterday











1 Answer
1






active

oldest

votes


















1














Please try this way to apply custom discount



<?php
namespace VendorMymoduleModelQuote;
class Discount extends MagentoQuoteModelQuoteAddressTotalAbstractTotal

public function __construct(
MagentoFrameworkEventManagerInterface $eventManager,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoSalesRuleModelValidator $validator,
MagentoFrameworkPricingPriceCurrencyInterface $priceCurrency
)

$this->setCode('testdiscount');
$this->eventManager = $eventManager;
$this->calculator = $validator;
$this->storeManager = $storeManager;
$this->priceCurrency = $priceCurrency;


public function collect(
MagentoQuoteModelQuote $quote,
MagentoQuoteApiDataShippingAssignmentInterface $shippingAssignment,
MagentoQuoteModelQuoteAddressTotal $total
)

parent::collect($quote, $shippingAssignment, $total);
$address = $shippingAssignment->getShipping()->getAddress();
$label = 'My Custom Discount';
$TotalAmount=$total->getSubtotal();
$TotalAmount=$TotalAmount/10; //Set 10% discount

$discountAmount ="-".$TotalAmount;
$appliedCartDiscount = 0;

if($total->getDiscountDescription())

$appliedCartDiscount = $total->getDiscountAmount();
$discountAmount = $total->getDiscountAmount()+$discountAmount;
$label = $total->getDiscountDescription().', '.$label;


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

if(isset($appliedCartDiscount))

$total->addTotalAmount($this->getCode(), $discountAmount - $appliedCartDiscount);
$total->addBaseTotalAmount($this->getCode(), $discountAmount - $appliedCartDiscount);

else

$total->addTotalAmount($this->getCode(), $discountAmount);
$total->addBaseTotalAmount($this->getCode(), $discountAmount);

return $this;


public function fetch(MagentoQuoteModelQuote $quote, MagentoQuoteModelQuoteAddressTotal $total)

$result = null;
$amount = $total->getDiscountAmount();

if ($amount != 0)

$description = $total->getDiscountDescription();
$result = [
'code' => $this->getCode(),
'title' => strlen($description) ? __('Discount (%1)', $description) : __('Discount'),
'value' => $amount
];

return $result;







share|improve this answer

























  • Not working, in any case $appliedCartDiscount returning 0.

    – Yash Shah
    yesterday











  • it is just checking code, if discount is applied before or not, let me add full code so you can understand better.

    – Aasim Goriya
    yesterday











  • I have added my code which I have used in one of my project and its working fine for me, so please try this way and let me know if any issue.

    – Aasim Goriya
    yesterday











  • i applied your code and is working with default magento discount, but if i take it as seprate discount column, its not working.

    – Yash Shah
    yesterday











  • as per your question you need to add custom discount code and now you asking for extra discount option right ?

    – Aasim Goriya
    yesterday











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-in-ee-2-2-6%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









1














Please try this way to apply custom discount



<?php
namespace VendorMymoduleModelQuote;
class Discount extends MagentoQuoteModelQuoteAddressTotalAbstractTotal

public function __construct(
MagentoFrameworkEventManagerInterface $eventManager,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoSalesRuleModelValidator $validator,
MagentoFrameworkPricingPriceCurrencyInterface $priceCurrency
)

$this->setCode('testdiscount');
$this->eventManager = $eventManager;
$this->calculator = $validator;
$this->storeManager = $storeManager;
$this->priceCurrency = $priceCurrency;


public function collect(
MagentoQuoteModelQuote $quote,
MagentoQuoteApiDataShippingAssignmentInterface $shippingAssignment,
MagentoQuoteModelQuoteAddressTotal $total
)

parent::collect($quote, $shippingAssignment, $total);
$address = $shippingAssignment->getShipping()->getAddress();
$label = 'My Custom Discount';
$TotalAmount=$total->getSubtotal();
$TotalAmount=$TotalAmount/10; //Set 10% discount

$discountAmount ="-".$TotalAmount;
$appliedCartDiscount = 0;

if($total->getDiscountDescription())

$appliedCartDiscount = $total->getDiscountAmount();
$discountAmount = $total->getDiscountAmount()+$discountAmount;
$label = $total->getDiscountDescription().', '.$label;


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

if(isset($appliedCartDiscount))

$total->addTotalAmount($this->getCode(), $discountAmount - $appliedCartDiscount);
$total->addBaseTotalAmount($this->getCode(), $discountAmount - $appliedCartDiscount);

else

$total->addTotalAmount($this->getCode(), $discountAmount);
$total->addBaseTotalAmount($this->getCode(), $discountAmount);

return $this;


public function fetch(MagentoQuoteModelQuote $quote, MagentoQuoteModelQuoteAddressTotal $total)

$result = null;
$amount = $total->getDiscountAmount();

if ($amount != 0)

$description = $total->getDiscountDescription();
$result = [
'code' => $this->getCode(),
'title' => strlen($description) ? __('Discount (%1)', $description) : __('Discount'),
'value' => $amount
];

return $result;







share|improve this answer

























  • Not working, in any case $appliedCartDiscount returning 0.

    – Yash Shah
    yesterday











  • it is just checking code, if discount is applied before or not, let me add full code so you can understand better.

    – Aasim Goriya
    yesterday











  • I have added my code which I have used in one of my project and its working fine for me, so please try this way and let me know if any issue.

    – Aasim Goriya
    yesterday











  • i applied your code and is working with default magento discount, but if i take it as seprate discount column, its not working.

    – Yash Shah
    yesterday











  • as per your question you need to add custom discount code and now you asking for extra discount option right ?

    – Aasim Goriya
    yesterday















1














Please try this way to apply custom discount



<?php
namespace VendorMymoduleModelQuote;
class Discount extends MagentoQuoteModelQuoteAddressTotalAbstractTotal

public function __construct(
MagentoFrameworkEventManagerInterface $eventManager,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoSalesRuleModelValidator $validator,
MagentoFrameworkPricingPriceCurrencyInterface $priceCurrency
)

$this->setCode('testdiscount');
$this->eventManager = $eventManager;
$this->calculator = $validator;
$this->storeManager = $storeManager;
$this->priceCurrency = $priceCurrency;


public function collect(
MagentoQuoteModelQuote $quote,
MagentoQuoteApiDataShippingAssignmentInterface $shippingAssignment,
MagentoQuoteModelQuoteAddressTotal $total
)

parent::collect($quote, $shippingAssignment, $total);
$address = $shippingAssignment->getShipping()->getAddress();
$label = 'My Custom Discount';
$TotalAmount=$total->getSubtotal();
$TotalAmount=$TotalAmount/10; //Set 10% discount

$discountAmount ="-".$TotalAmount;
$appliedCartDiscount = 0;

if($total->getDiscountDescription())

$appliedCartDiscount = $total->getDiscountAmount();
$discountAmount = $total->getDiscountAmount()+$discountAmount;
$label = $total->getDiscountDescription().', '.$label;


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

if(isset($appliedCartDiscount))

$total->addTotalAmount($this->getCode(), $discountAmount - $appliedCartDiscount);
$total->addBaseTotalAmount($this->getCode(), $discountAmount - $appliedCartDiscount);

else

$total->addTotalAmount($this->getCode(), $discountAmount);
$total->addBaseTotalAmount($this->getCode(), $discountAmount);

return $this;


public function fetch(MagentoQuoteModelQuote $quote, MagentoQuoteModelQuoteAddressTotal $total)

$result = null;
$amount = $total->getDiscountAmount();

if ($amount != 0)

$description = $total->getDiscountDescription();
$result = [
'code' => $this->getCode(),
'title' => strlen($description) ? __('Discount (%1)', $description) : __('Discount'),
'value' => $amount
];

return $result;







share|improve this answer

























  • Not working, in any case $appliedCartDiscount returning 0.

    – Yash Shah
    yesterday











  • it is just checking code, if discount is applied before or not, let me add full code so you can understand better.

    – Aasim Goriya
    yesterday











  • I have added my code which I have used in one of my project and its working fine for me, so please try this way and let me know if any issue.

    – Aasim Goriya
    yesterday











  • i applied your code and is working with default magento discount, but if i take it as seprate discount column, its not working.

    – Yash Shah
    yesterday











  • as per your question you need to add custom discount code and now you asking for extra discount option right ?

    – Aasim Goriya
    yesterday













1












1








1







Please try this way to apply custom discount



<?php
namespace VendorMymoduleModelQuote;
class Discount extends MagentoQuoteModelQuoteAddressTotalAbstractTotal

public function __construct(
MagentoFrameworkEventManagerInterface $eventManager,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoSalesRuleModelValidator $validator,
MagentoFrameworkPricingPriceCurrencyInterface $priceCurrency
)

$this->setCode('testdiscount');
$this->eventManager = $eventManager;
$this->calculator = $validator;
$this->storeManager = $storeManager;
$this->priceCurrency = $priceCurrency;


public function collect(
MagentoQuoteModelQuote $quote,
MagentoQuoteApiDataShippingAssignmentInterface $shippingAssignment,
MagentoQuoteModelQuoteAddressTotal $total
)

parent::collect($quote, $shippingAssignment, $total);
$address = $shippingAssignment->getShipping()->getAddress();
$label = 'My Custom Discount';
$TotalAmount=$total->getSubtotal();
$TotalAmount=$TotalAmount/10; //Set 10% discount

$discountAmount ="-".$TotalAmount;
$appliedCartDiscount = 0;

if($total->getDiscountDescription())

$appliedCartDiscount = $total->getDiscountAmount();
$discountAmount = $total->getDiscountAmount()+$discountAmount;
$label = $total->getDiscountDescription().', '.$label;


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

if(isset($appliedCartDiscount))

$total->addTotalAmount($this->getCode(), $discountAmount - $appliedCartDiscount);
$total->addBaseTotalAmount($this->getCode(), $discountAmount - $appliedCartDiscount);

else

$total->addTotalAmount($this->getCode(), $discountAmount);
$total->addBaseTotalAmount($this->getCode(), $discountAmount);

return $this;


public function fetch(MagentoQuoteModelQuote $quote, MagentoQuoteModelQuoteAddressTotal $total)

$result = null;
$amount = $total->getDiscountAmount();

if ($amount != 0)

$description = $total->getDiscountDescription();
$result = [
'code' => $this->getCode(),
'title' => strlen($description) ? __('Discount (%1)', $description) : __('Discount'),
'value' => $amount
];

return $result;







share|improve this answer















Please try this way to apply custom discount



<?php
namespace VendorMymoduleModelQuote;
class Discount extends MagentoQuoteModelQuoteAddressTotalAbstractTotal

public function __construct(
MagentoFrameworkEventManagerInterface $eventManager,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoSalesRuleModelValidator $validator,
MagentoFrameworkPricingPriceCurrencyInterface $priceCurrency
)

$this->setCode('testdiscount');
$this->eventManager = $eventManager;
$this->calculator = $validator;
$this->storeManager = $storeManager;
$this->priceCurrency = $priceCurrency;


public function collect(
MagentoQuoteModelQuote $quote,
MagentoQuoteApiDataShippingAssignmentInterface $shippingAssignment,
MagentoQuoteModelQuoteAddressTotal $total
)

parent::collect($quote, $shippingAssignment, $total);
$address = $shippingAssignment->getShipping()->getAddress();
$label = 'My Custom Discount';
$TotalAmount=$total->getSubtotal();
$TotalAmount=$TotalAmount/10; //Set 10% discount

$discountAmount ="-".$TotalAmount;
$appliedCartDiscount = 0;

if($total->getDiscountDescription())

$appliedCartDiscount = $total->getDiscountAmount();
$discountAmount = $total->getDiscountAmount()+$discountAmount;
$label = $total->getDiscountDescription().', '.$label;


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

if(isset($appliedCartDiscount))

$total->addTotalAmount($this->getCode(), $discountAmount - $appliedCartDiscount);
$total->addBaseTotalAmount($this->getCode(), $discountAmount - $appliedCartDiscount);

else

$total->addTotalAmount($this->getCode(), $discountAmount);
$total->addBaseTotalAmount($this->getCode(), $discountAmount);

return $this;


public function fetch(MagentoQuoteModelQuote $quote, MagentoQuoteModelQuoteAddressTotal $total)

$result = null;
$amount = $total->getDiscountAmount();

if ($amount != 0)

$description = $total->getDiscountDescription();
$result = [
'code' => $this->getCode(),
'title' => strlen($description) ? __('Discount (%1)', $description) : __('Discount'),
'value' => $amount
];

return $result;








share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered yesterday









Aasim GoriyaAasim Goriya

2,99111039




2,99111039












  • Not working, in any case $appliedCartDiscount returning 0.

    – Yash Shah
    yesterday











  • it is just checking code, if discount is applied before or not, let me add full code so you can understand better.

    – Aasim Goriya
    yesterday











  • I have added my code which I have used in one of my project and its working fine for me, so please try this way and let me know if any issue.

    – Aasim Goriya
    yesterday











  • i applied your code and is working with default magento discount, but if i take it as seprate discount column, its not working.

    – Yash Shah
    yesterday











  • as per your question you need to add custom discount code and now you asking for extra discount option right ?

    – Aasim Goriya
    yesterday

















  • Not working, in any case $appliedCartDiscount returning 0.

    – Yash Shah
    yesterday











  • it is just checking code, if discount is applied before or not, let me add full code so you can understand better.

    – Aasim Goriya
    yesterday











  • I have added my code which I have used in one of my project and its working fine for me, so please try this way and let me know if any issue.

    – Aasim Goriya
    yesterday











  • i applied your code and is working with default magento discount, but if i take it as seprate discount column, its not working.

    – Yash Shah
    yesterday











  • as per your question you need to add custom discount code and now you asking for extra discount option right ?

    – Aasim Goriya
    yesterday
















Not working, in any case $appliedCartDiscount returning 0.

– Yash Shah
yesterday





Not working, in any case $appliedCartDiscount returning 0.

– Yash Shah
yesterday













it is just checking code, if discount is applied before or not, let me add full code so you can understand better.

– Aasim Goriya
yesterday





it is just checking code, if discount is applied before or not, let me add full code so you can understand better.

– Aasim Goriya
yesterday













I have added my code which I have used in one of my project and its working fine for me, so please try this way and let me know if any issue.

– Aasim Goriya
yesterday





I have added my code which I have used in one of my project and its working fine for me, so please try this way and let me know if any issue.

– Aasim Goriya
yesterday













i applied your code and is working with default magento discount, but if i take it as seprate discount column, its not working.

– Yash Shah
yesterday





i applied your code and is working with default magento discount, but if i take it as seprate discount column, its not working.

– Yash Shah
yesterday













as per your question you need to add custom discount code and now you asking for extra discount option right ?

– Aasim Goriya
yesterday





as per your question you need to add custom discount code and now you asking for extra discount option right ?

– Aasim Goriya
yesterday

















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-in-ee-2-2-6%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

Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림