Skip to content
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

adding gift card support for underarmour #504

Open
wants to merge 1 commit into
base: magic_integration_latest
Choose a base branch
from
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());
}
$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',
];

$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',
'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