Magento: Getting Discounted price - magento

We have a mixture of products, some with specialPrice and some with Catalog Rules set.
I need to display the discounted % for all my products on my frontend.
We were using $_product->getSpecialPrice() to get the discounted price, but this fails for products which prices based on catalog rules.
Is it possible to get the Discounted prices based on the catalog rule or from the specialPrice ?

Yes you can use $_product->getFinalPrice().
Here is the difference in the three prices:
$regularPrice = number_format($_product->getPrice(), 2);
$discountedPrice = number_format($_product->getFinalPrice(), 2);
$specialPrice = number_format($_product->getSpecialPrice(), 2);

Try this snippet:
This one will calculate price rules.
Mage::getModel('catalogrule/rule')->calcProductPriceRule($product,$product->getPrice());
Is is what you looking for?

Related

Getting list of all applied discounts in magento cart

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

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

Magento: price on cart is from configurable product, not from simple-product

I had a similar problem last time, but the solution just helps with my test-product, whre I can add price +/- in my configurable product. Price in Cart is not correct Magento 1.8
Is it possible to take the price of the simple product, without adding some prices +/- at the configurable one?
On cart I get the SKU of the simple-product, but with $_item->getPrice() I only get the Price of the configurable product.
Thanks for help!
Use the sku of the item to load the simple product, for example:
$_productSku = $_item->getSku();
$_product = Mage::getModel('catalog/product');
$_productId = $_product->getIdBySku($_productSku);
$_product->load($_productId);
then use
$_product->getPrice();
Regards
Hans
Shorter solution is:
$_product = Mage::getModel('catalog/product')->loadByAttribute('sku', $_item->getSku());
$_product->getPrice();

Add additional product price with mangento base product price

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.

Magento: use tier_price instead of price

How can I show and use the Tier Price of the "Customer Group" to which the current user belongs?
I'm using Magento ver. 1.4.1.1
You can use:
$oProduct = Mage::getModel('catalog/product')->load($product_id);
$aTierPrice = $oProduct->getTierPrice();
to get the proper tier price(s) of a product.
If you define distinct tier prices for a product, e.g.
price of x for customer group 'NOT_LOGGED_IN'
price of y for customer group 'General'
getTierPrice() will only return the matching tier price.

Resources