Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions Controller/OneClick/PlaceOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ public function execute()
$resultJson = $this->resultJsonFactory->create();

try {
$giftCardDiscountAmount = 0;
//Check if the customer has applied GiftCards
if($quote->getMageworxGiftcardsAmount()) {
$giftCardDiscountAmount = abs($quote->getMageworxGiftcardsAmount());
}
Comment on lines +195 to +199

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified with:

Suggested change
$giftCardDiscountAmount = 0;
//Check if the customer has applied GiftCards
if($quote->getMageworxGiftcardsAmount()) {
$giftCardDiscountAmount = abs($quote->getMageworxGiftcardsAmount());
}
// Check if the customer has applied GiftCards
$giftCardDiscountAmount = !empty($quote->getMageworxGiftcardsAmount())
? abs($quote->getMageworxGiftcardsAmount())
: 0;

$maskedId = $this->maskedQuoteIdInterface->execute($quoteId);

if ($maskedId === '') {
Expand Down Expand Up @@ -240,6 +245,7 @@ public function execute()
$productUrl = $product->getProductUrl();

$offerPrice = $quoteItem->getPrice() * 100;

// Check if the item has applied discounts
if ($quoteItem->getDiscountAmount()) {
// Get the discount amount applied to the item
Expand Down Expand Up @@ -323,6 +329,20 @@ public function execute()
];
$orderNotes = array_merge($orderNotes, $customerEmailNotes);
}
if($giftCardDiscountAmount > 0)
{
$totalAmount = $totalAmount - $giftCardDiscountAmount;
$giftCardDiscount = [
'gift_card_discount'=> $giftCardDiscountAmount,
];
$orderNotes = array_merge($orderNotes, $giftCardDiscount);
}
$promotions = [
'type' => 'gift_card',
'code' => 'gift_card_number',
'value' => $giftCardDiscountAmount,
'description' => 'applied',
];
Comment on lines +332 to +345

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When there's no Gift Card Discount applied, I believe the $promotions should be empty

Suggested change
if($giftCardDiscountAmount > 0)
{
$totalAmount = $totalAmount - $giftCardDiscountAmount;
$giftCardDiscount = [
'gift_card_discount'=> $giftCardDiscountAmount,
];
$orderNotes = array_merge($orderNotes, $giftCardDiscount);
}
$promotions = [
'type' => 'gift_card',
'code' => 'gift_card_number',
'value' => $giftCardDiscountAmount,
'description' => 'applied',
];
$promotions = [];
if($giftCardDiscountAmount > 0)
{
$totalAmount = $totalAmount - $giftCardDiscountAmount;
$giftCardDiscount = [
'gift_card_discount'=> $giftCardDiscountAmount,
];
$orderNotes = array_merge($orderNotes, $giftCardDiscount);
$promotions = [
'type' => 'gift_card',
'code' => 'gift_card_number',
'value' => $giftCardDiscountAmount,
'description' => 'applied',
];
}


$razorpay_order = $this->rzp->order->create([
'amount' => $totalAmount,
Expand All @@ -332,7 +352,8 @@ public function execute()
'app_offer' => 0,
'notes' => $orderNotes,
'line_items_total' => $totalAmount,
'line_items' => $lineItems
'line_items' => $lineItems,
'promotions' => $promotions,
]);

if (null !== $razorpay_order && !empty($razorpay_order->id)) {
Expand All @@ -348,7 +369,8 @@ public function execute()
'allow_coupon_application' => $allowCouponApplication == 1 ? true : false,
'rzp_order_id' => $razorpay_order->id,
'items' => $items,
'message' => 'Razorpay Order created successfully'
'message' => 'Razorpay Order created successfully',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered using __() for translation support?

'gift_card_discount' => $giftCardDiscount,
];

$orderLink = $this->_objectManager->get('Razorpay\Magento\Model\OrderLink')
Expand Down
2 changes: 2 additions & 0 deletions view/frontend/web/js/magic-buy-now.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ define([
renderIframe: function(data) {
var self = this;
var rzp_order_id = data.rzp_order_id;
var gift_card_discount = data.gift_card_discount;

var options = {
key: data.rzp_key_id,
Expand Down Expand Up @@ -182,6 +183,7 @@ define([
},
// callback_url : self.options.callbackURL,
prefill: {
gift_card_discount: gift_card_discount,
name: '',
contact: '',
email: ''
Expand Down
2 changes: 2 additions & 0 deletions view/frontend/web/js/magic-cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ define([
renderIframe: function(data) {
var self = this;
var rzp_order_id = data.rzp_order_id;
var gift_card_discount = data.gift_card_discount;

var options = {
key: data.rzp_key_id,
Expand Down Expand Up @@ -184,6 +185,7 @@ define([
notes: {},
// callback_url : self.options.callbackURL,
prefill: {
gift_card_discount: gift_card_discount,
name: '',
contact: '',
email: ''
Expand Down