-
Notifications
You must be signed in to change notification settings - Fork 9.4k
add coupon code to totals model #32797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
namespace Magento\Sales\Block\Order; | ||
|
||
use Magento\Sales\Model\Order; | ||
use Magento\Sales\Model\Order\Invoice; | ||
|
||
/** | ||
* Order totals. | ||
|
@@ -126,16 +127,21 @@ protected function _initTotals() | |
* Add discount | ||
*/ | ||
if ((double)$this->getSource()->getDiscountAmount() != 0) { | ||
if ($this->getSource()->getDiscountDescription()) { | ||
$discountLabel = __('Discount (%1)', $source->getDiscountDescription()); | ||
if ($this->getSource() instanceof Invoice) { | ||
$discountSource = $this->getSource()->getOrder(); | ||
} else { | ||
$discountSource = $this->getSource(); | ||
} | ||
if ($this->getSource()->getCouponCode()) { | ||
$discountLabel = __('Discount (%1)', $discountSource->getCouponCode()); | ||
Comment on lines
+130
to
+136
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I see from the suggested solution, the coupon code description will not be shown anymore, but it was expected to be shown. In other words, this solution replaces coupon code description with its code. It is not correct from the user experience. I can suggest to implement something like this: $discountLabel = $this->getSource()->getDiscountDescription()
? __('Discount (%1)', $source->getDiscountDescription())
: __('Discount (%1)', $source->getCouponCode()); With this, we will have a coupon code or description in the Discount line. And not the BIC change. |
||
} else { | ||
$discountLabel = __('Discount'); | ||
} | ||
$this->_totals['discount'] = new \Magento\Framework\DataObject( | ||
[ | ||
'code' => 'discount', | ||
'field' => 'discount_amount', | ||
'value' => $source->getDiscountAmount(), | ||
'value' => $discountSource->getDiscountAmount(), | ||
'label' => $discountLabel, | ||
] | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @SilinMykola
Thank you for your contribution;
Please don't forget to keep an empty string after imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @andrewbess
Thanks for your reviewing, I fixed your remark.