I'm trying to rewrite a template for the cart.
I need to retrieve the discount amount but I was not able to find where.
Ie If my coupon code gives me $10 discount I want to retrieve 10, if I have a discount of 5% I want to retrieve 5 if the total price is $100.
Thank you.
you can debug your object by printing it out and observing what values it contains
print_r($this->getQuote()->getData());
I used the following code to access discount price. I was accessing the details of last order in a phtml file. For the last order if there was a discount coupon used then I used following code to access the Discount Amount.
$lastOrderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order=Mage::getModel('sales/order')->loadByIncrementID($lastOrderId);
if($lastOrderId) //If order was placed then only display coupon code
{
$coupon=$order->getCouponCode();
echo "<b>Discount coupon used during order:</b>".$coupon;
$disAmount=$order->getDiscountAmount();
echo "<br/>Discount Amount: ".$disAmount;
}
Related
I am writing am extension for my magento shop which basically gives 5% discount to all newsletter subscribed customers. the extension is working but now problem is it doesn't show the promotion code discounts entered by customers.
I am using this code to get discount:
$address->setDiscountAmount($total - $discountAmount);
$address->setDiscountDescription("5% Discounted Subtotal");
$address->setBaseDiscountAmount($total - $discountAmount);
I was wondering if there is any magento method or functions which gets an array of all applied discounts for the cart.
Or if anyone can tell me where can i find list of all the available functions in magento.
To get total discount for all the items in the cart, you can try this,
$quote2 = Mage::getSingleton('checkout/session')->getQuote();
$discountTotal = 0;
foreach ($quote2->getAllItems() as $item){
$discountTotal += $item->getDiscountAmount();
}
magento i need to apply discount 20% for the total if above 50euros but not to the discounted items if customers selects some already discounted items that should not include in the total can any one help
Thanks in advance
You need to create a custom module or say shopping cart price rule and an event observer to check whether the "special price" is zero or not. If it is "Zero" that means it is not a already discounted product or you can even check the "final price" with the "price" , if the final price is lesser than price it is already discounted.
If these conditions are satisfied get the prices of remaining products prices and discount them then add the already discounted products price to make the total amount.
I hope You understood this concept and write your own module.
you have to use a check in view page.
for example
$price = $product->getPrice();
$specialprice = $product->getFinalPrice();
if(!empty($specialprice)){
//then your price would be same
}
elseif(empty($specialprice)){
then price would be = $price*20/100;
}
hope this would help you and don't forget to like if it was helpful
On the Order Confirmation page of Magento 1.5 (using the template , I have the a number of analytics conversion code scripts (like Google AdWords Conversion tracking).
The code that is currently used to get the subtotal is
<?php $order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId(); ?>
<?php $order_details = Mage::getModel('sales/order')->loadByIncrementId($order_id); ?>
<?php $subtotal = $order_details->subtotal; ?>
And then the $subtotal variable is used throughout. The problem is that this is the subtotal BEFORE any coupons or discounts are applied. I need it to be the total AFTER coupons or discounts.
Can anyone help me with the code to get at that value?
You can call var_dump($order_details->debug()) to see all the data fields of the order object. I don't see anything that matches the subtotal with discount, but I do see a discount_amount field, which has the total discount amount (as a negative number); add this to your subtotal.
If you want the grand total, with discounts and shipping included, use the grand_total field.
I want to add additional price with product(simple) price, I am trying to do this with the help of custom attributes. I add a custom attribute "Margin Price" and I want to add up this custom attribute value (margin price) with the base price of the product in the template file.
I am updating all product price after each 5 minutes by cron job, thats why I think I have to do add margin price with base product price by this way.
I added it successfully in product list page and in product view page, but have problem with how to add this margin price with base price in the cart and onepage checkout?
Here is the code on the product list page and same for the product detail page which works fine for me in magento 1.6.x.
$regularPrice = number_format($_product->getFinalPrice(), 2);
//echo $regularPrice = $this->getPriceHtml($_product, true
$priceWithoutComma = str_replace(",", "",$regularPrice);
settype($priceWithoutComma, "float");
$marPrice = $_product->getMarginPrice();
settype($marPrice, "integer");
$finalPrice = $priceWithoutComma + $marPrice;
echo $finalPrice.Mage::app()->getLocale()->currency(Mage::app()->getStore()->
getCurrentCurrencyCode())->getSymbol();
I am doing this right way or I have to changes the whole process?
Looks like you might need to consider a different approach. The reason being that echoing the price from a template file does not modify the price of the item in any way. It simply outputs a calculation.
You'll need to learn a bit about event listeners for this one to work.
Here's a blog post of mine on how to do this.
I have a product collection called using the following (set to show 6 items):
$_testproductCollection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->setPageSize(6);
$_testproductCollection->load();
then i get the 6 products details with a foreach:
foreach($_testproductCollection as $_testproduct){
echo "Price is ".$this->htmlEscape($this->getPriceHtml($_product, true))."<br/>";
};
this works ok until I set my store to show prices inclusive of tax. Instead of showing 2 different prices, for example:
Excl. Tax: $138.56
Incl. Tax: $149.99
it shows the same price for both. If I add a call to the loaded product collection again immediately after it's loaded:
$_productCollection=$this->getLoadedProductCollection();
...it works fine, the prices are correct, but then it's skipping the setPageSize function and returning the full store collection of products.
How can I get the correct tax prices to show, and what is it in the getLoadedProductCollection that corrects this? The function is in Mage/Catalog/Block/Product/List.php
See Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection::addTaxPercents
Also, the getLoadedProductCollection calls (via a catalog layer) the addMinimalPrice and addFinalPrice methods. From those docs you can see there are methods for adding tiered pricing and URL rewrites. That is nice to know.