Magento save order total in checkout page - magento

We have a system like gift cards balance usage in the checkout page.While customers on the checkout page customers can use their Gift card balance amount to buy products.
So i have added a a tab before payment tab in which customers have option to enter the amount o use from their gift card balance amount so when they say proceed am getting the entered value in custom Onepage controller and pass it to Onepage.php(Model class) to reduce the total amount.
This is what am doing on the model class.
public function saveCustomDiscount($discount=0)
{
$this->getQuote()->setGrandTotal($this->getQuote()->getGrandTotal() - $discount);
$this->getQuote()->setBaseGrandTotal($this->getQuote()->getBaseGrandTotal() - $discount);
$this->getQuote()->save();
//$this->getQuote()->collectTotals()->save();
$order = $this->getQuote()->getData();
Zend_Debug::dump($order);
return array();
}
And am calling this function from the controller Action function were am getting the user input.
Here what ever am passing as discount the total amount and base total is not reducing. Its same as original.
Note :
Before custom order save.
array(51) {
---------------
["grand_total"] => string(8) "243.7200"
["base_grand_total"] => string(8) "243.7200"
-----------------
}
After custom order save.
array(51) {
---------------
["grand_total"] => float(223.72)
["base_grand_total"] => float(223.72)
-----------------
}
The data type is changed from string to float when am doing debug. What i have to do, to reduce the order total from the custom discount. Please help me.
Thanks

Did you set the discountCode?
i.e. $quote->setCouponCode(strlen($couponCode) ? $couponCode : '')
->collectTotals()
->save();
Later on, in the Quote, did you apply the discount?
i.e. $order->setDiscountAmount(Mage::getSingleton('checkout/session')->getQuote()->getSubtotalWithDiscount() - Mage::getSingleton('checkout/session')->getQuote()->getSubtotal());
$order->setShippingAmount(Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingAmount());
$order->setSubtotalWithDiscount(Mage::getSingleton('checkout/session')->getQuote()->getSubtotalWithDiscount());
$order->setGrandTotal(Mage::getSingleton('checkout/session')->getQuote()->getGrandTotal());
etc.
EDIT:
I've worked with a team to do a Wordpress / Magento hybrid and it's definitely left some learning lessons on me. Magento was used as a purely transactional engine and we had to do this entire checkout process by hand (including creating a custom WP plugin to handle each step in the cart).
Log this out at the end so we can see what you have (possibly put this in your edited question):
Mage::log("checkoutprocess: getSubtotal: " . $order->getSubtotal());
Mage::log("checkoutprocess: getTaxAmount: " . $order->getTaxAmount());
Mage::log("checkoutprocess: getDiscountAmount: " . $order->getDiscountAmount());
Mage::log("checkoutprocess: getShippingAmount: " . $order->getShippingAmount());
Mage::log("checkoutprocess: getGrandTotal: " . $order->getGrandTotal());
Mage::log("checkoutprocess: getBaseSubtotal: " . $order->getBaseSubtotal());
Mage::log("checkoutprocess: getBaseDiscountAmount: " . $order->getBaseDiscountAmount());
Mage::log("checkoutprocess: getSubtotalWithDiscount: " . $order->getSubtotalWithDiscount());
Mage::log("checkoutprocess: getBaseGrandTotal: " . $order->getBaseGrandTotal());

Related

Google Fit API - International users sync issue

I'm using the Google Fit API Rest
Here is the data I'm retrieving from Google Fit using the API:
2021-03-21 29989 Steps
2021-03-20 12 Steps
Here is the data the user exported from Google:
3/22/2021 16,480 Steps
3/21/2021 13,521 Steps
In both circumstances, the steps equal 30,001
The dates are clearly off by one day because of the time zone. The daily count is also off for the same reason, however, it added up to the same steps.
What general approach/strategy can I take to get the steps obtained from the API match those on Google Fit when I don't have a timezone?
My API currently loops through the database and syncs all user data, not distinguishing domestic vs international users.
Here is the code snippet used to get steps:
//***** Get steps
case DATATYPE_STEP_COUNT_DELTA:
if ($dataStreamId == 'derived:com.google.step_count.delta:com.google.android.gms:estimated_steps') {
$listDatasets = $dataSets->get("me", $dataStreamId, $startTime . '000000000' . '-' . $endTime . '000000000');
if ($debug == 1) PrintR($listDatasets,"DATATYPE_STEP_COUNT_DELTA");
$step_count = 0;
foreach ($listDatasets as $dataSet) {
if ($dataSet['startTimeNanos']) {
$sec = $dataSet['startTimeNanos'] / 1000000000;
$activity_date = date('Y-m-d', $sec);
$dataSetValues = $dataSet['value'];
if ($dataSetValues && is_array($dataSetValues)) {
foreach ($dataSetValues as $dataSetValue) {
if(!isset($stepsArr[$studentencodedid][$activity_date])) $stepsArr[$studentencodedid][$activity_date] = 0;
$stepsArr[$studentencodedid][$activity_date] += $dataSetValue['intVal'];
$step_count += $dataSetValue['intVal'];
}
}
}
}
}
break;
//***** End get steps

Text outputs as multiple separate lines instead of one paragraph with linebreaks

I have a bot that writes my message to a webpage. I want the message to be sent as one paragraph, but with the lines separated by a linebreak. However, when I actually run the code, the bot inputs and enters each line separately, instead of as one paragraph
I've tried messing with the linebreak formatting and string formatting, but the issue persists
reply_messages = []
reply_messages.push([
"FREE BABY AVOCUDDLE - Thank you for your patience!",
"To redeem your FREE avocuddle, just use the LINK IN OUR BIO and ADD TO CART - just cover shipping, no additional charges!",
"Discount AUTOMATICALLY APPLIES! Super simple, no code!",
"If you order another avocuddle in addition, we cover shipping PLUS the free baby avocuddle! :)",
"Feel free to DM us if you need anything!"
].join("\n")+"\n")
.
.
.
while true
browser.get 'https://twitter.com/messages/requests'
sleep 5
request = wait.until {
el = browser.find_element(:css, "[data-testid='conversation']")
el if el.displayed?
}
break if request.nil?
request.click
not_acceptable_link = true
na_link_index = 1
while not_acceptable_link == true
accept_btn = browser.find_element(:xpath, "//*[contains(text(), 'Accept')]")
unless accept_btn.displayed?
request_2 = wait.until {
el = browser.find_elements(:css, "[data-testid='conversation']")[na_link_index]
el if el.displayed?
}
request_2.click
else
not_acceptable_link = false
end
na_link_index += 1
end
accept_btn = browser.find_element(:xpath, "//*[contains(text(), 'Accept')]")
accept_btn.click
sleep 1
reply_input = wait.until {
el = browser.find_element(:css, "[data-testid='dmComposerTextInput']")
el if el.displayed?
}
reply_input.click
reply_input.send_keys(reply_messages)
.
.
.
I would like for the code to output the entire text as one block of text. However, instead, it outputs as separate lines.
Output currently looks like:
FREE BABY AVOCUDDLE - Thank you for your patience!
(enters this into text box)
To redeem your FREE avocuddle, just use the LINK IN OUR BIO and ADD TO CART - just cover shipping, no additional charges!
(enters this into text box)
etc.
Instead I would like for it to send as one message.

How calculate the number prorated day with Stripe API?

i am using Stripe. I would like to know how can calculate number of day prorated
I want display something like that
1 additional seat ($9/month each - prorated for 26 days)
in the api i don't see any item prorate_day
Bolo
subscription_proration_date what you are looking for? Then it will calculate it for you.
See more at https://stripe.com/docs/subscriptions/guide
The example of pro-rated subscription in ruby is as follows
# Set your secret key: remember to change this to your live secret key in production
# See your keys here https://dashboard.stripe.com/account/apikeys
Stripe.api_key = "sk_test_9OkpsFpKa1HDHaZa7e0BeGaO"
proration_date = Time.now.to_i
invoice = Stripe::Invoice.upcoming(:customer => "cus_3R1W8PG2DmsmM9", :subscription => "sub_3R3PlB2YlJe84a",
:subscription_plan => "premium_monthly", :subscription_proration_date => proration_date)
current_prorations = invoice.lines.data.select { |ii| ii.period.start == proration_date }
cost = 0
current_prorations.each do |p|
cost += p.amount
end
# Display the cost of these prorations invoice items to the end user,
# and actually do the update when they agree.
# To make sure that the proration is calculated the same as when it was previewed,
# you need to pass in the proration_date parameter
# later...
subscription = Stripe::Subscription.retrieve("sub_3R3PlB2YlJe84a")
subscription.plan = "premium_monthly"
subscription.proration_date = proration_date
subscription.save

Custom message in New Order Confirmation Shippin Method Magento CE

I am trying to setup a custom message in the New Order Confirmation email for "Shipping Method" when someone selects the shipping method "Store Pickup" at checkout. In the DB the method name is called flatrate2. Here is the snippet that I was attempting to edit...
if ($method) {
foreach ($address->getAllShippingRates() as $rate) {
if ($rate->getCode()==$method) {
$amountPrice = $address->getQuote()->getStore()->convertPrice($rate->getPrice(), false);
$this->_setAmount($amountPrice);
$this->_setBaseAmount($rate->getPrice());
if (!$method=='flatrate2'){
$shippingDescription = $rate->getCarrierTitle() . ' - ' . $rate->getMethodTitle();}
else{ $shippingDescription = 'Your merchandise will be ready for pickup 45 minutes after completing your order.<br/>Store Pickup is available Mon – Friday 11:30 AM – 4:30 PM';}
$address->setShippingDescription(trim($shippingDescription, ' -'));
break;
}
}
}
No matter which shipping method is selected I only get the message 'Your merchandise will be ready for pickup 45 minutes after completing your order.Store Pickup is available Mon – Friday 11:30 AM – 4:30 PM'
Any help would be appreciated. Thank you!
within that code do this:
if ($method=='your specific shipping ')
{ $shippingDescription = $rate->getCarrierTitle() . ' - ' . $rate->getMethodTitle();}
elseif($method=='your other shipping method ')
{ $shippingDescription = $rate->getCarrierTitle() . ' - ' . $rate->getMethodTitle();}
and so on.
To summarize all times your code condition if (!$method=='flatrate2'){ is failing resulting in else condition getting executed.
I approached this a different way. In my email template I added.
{{block type='core/template' area='frontend' template='cms/orderemail.phtml' order=$order}}
Then in my orderemail.phtml I placed this snippet in it...
$pShipping = $this->getData('order')->getShippingDescription();
if ($pShipping == 'Store Pickup - Store Pickup') {
This solved my problem.

Magento: How to remove the price for bundled product options on the shopping cart page, checkout etc

Please help me removing the price for bundled product options on the shopping cart page, checkout, etc. Here is a pic.
What do i need to do?
To remove this edit:
Mage_Bundle_Block_Checkout_Cart_Item_Renderer
Look for the _getBundleOptions() method and at around line 77 change it as follows
//$option['value'][] = $this->_getSelectionQty($bundleSelection->getSelectionId()).' x '. $this->htmlEscape($bundleSelection->getName()). ' ' .Mage::helper('core')->currency($this->_getSelectionFinalPrice($bundleSelection));
//New line
$option['value'][] = $this->_getSelectionQty($bundleSelection->getSelectionId()).' x '. $this->htmlEscape($bundleSelection->getName());
Then edit:
Mage_Bundle_Block_Sales_Order_Items_Renderer
Look for the getValueHtml() method at around line 115 change the code as follows
public function getValueHtml($item)
{
if ($attributes = $this->getSelectionAttributes($item)) {
//Old code
/*
return sprintf('%d', $attributes['qty']) . ' x ' .
$this->htmlEscape($item->getName()) .
" " . $this->getOrder()->formatPrice($attributes['price']);
*/
return sprintf('%d', $attributes['qty']) . ' x ' .
$this->htmlEscape($item->getName());
} else {
return $this->htmlEscape($item->getName());
}
}
The usual caveats about not editing core code and using local or module rewrites apply!
let me know if i can help you more.
OR Also you can hide with css like below
Assuming that you want to remove it from all items regardless of the price, then you could add this css
#shopping-cart-table dd span.price{
display:none;
}
If you only want to remove the price if it is zero,you can also do in this way
/app/design/frontend/default/{theme path}/template/checkout/cart/item/default.phtml (around line # 46)
Figure out where it is add the price and only append the price if it is greater than 0
or
Do a find a replace str_replace("$0.00", "", $_formatedOptionValue['value']) on the string that display that line (make sure to add the currency sign so that $10.00 dont get replace)
I found another way to do it. Hopefully it will help somebody.
1 - Go to /public_html/app/code/core/Mage/Bundle/Helper/Catalog/Product
2 - open the file Configuration.php
3 - from about line 119 till about 127 you will find this code:
foreach ($bundleSelections as $bundleSelection) {
$qty = $this->getSelectionQty($product, $bundleSelection->getSelectionId()) * 1;
if ($qty) {
$option['value'][] = $qty . ' x ' . $this->escapeHtml($bundleSelection->getName())
. ' ' . Mage::helper('core')->currency(
$this->getSelectionFinalPrice($item, $bundleSelection)
);
}
}
Change that with this code:
foreach ($bundleSelections as $bundleSelection) {
$qty = $this->getSelectionQty($product, $bundleSelection->getSelectionId()) * 1;
if ($qty) {
$option['value'][] = $this->escapeHtml($bundleSelection->getName());
}
}
One caution note, be careful about editing the core file. You can also use local or module rewrites.

Resources