magento show all discount coupons in shopping cart - magento

<?php $rulesCollection = Mage::getModel('salesrule/rule')->getCollection();
$i=1;
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
$totalPrice = 0;
foreach($items as $item) {
$totalPrice+=$item->getPrice();
}
$coll = Mage::getResourceModel('salesrule/rule_collection')->load();
echo '<div class=vip_test>';
foreach($coll as $rule){
$productDetail = $rule->afterLoad();
$discountAmount = $productDetail['discount_amount'];
echo "<div class=ssk><span> You Save : </span>".$totalAmount = $totalPrice-($discountAmount/100*$totalPrice)."</div>";
$ruleID = $productDetail['rule_id'];
}
foreach($rulesCollection as $rule){
$coupon = $rule->getCode();
$couponName = $rule->getName()
?>
In Magento, with this I am getting only the coupon code and coupon name. I want to display if there is any coupon code for particular product in shopping cart, in front of coupon - its showing the saving amount. Is it possible or not? Am I doing Wrong? please help me

First you need to get the collection of products which are in your cart. Then you need to check if there are any active coupons in catalog price rules or shopping cart price rules for the products which are in your cart. If all the above conditions becomes true then you need to display the coupon code of it.
On the next side, you need to calculate the difference amount of it and also you need to display if the user increases his quantity then the savings amount value also has to be increased.

Related

Product price is zero in cart page when add product 2nd time

When i added product to cart 1st time, Its working fine. But in 2nd time add product to cart (Same or other product - in both situation), cart item price will be 0. But in checkout page, its showing fine.
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
foreach($items as $item) {
echo 'Price: '.$item->getPrice().'<br />';
echo 'Product Price: '.$item->getProduct()->getPrice().'<br />';
}
When i dubug by above code,I got below answer
Price:
Product Price: 159.00
Cart price returns empty. I dunno why. I have checked shopping cart and Catalog Price rules too. There is no promotions rules are exist.
Have any idea, how to fix this issue?
Thank you though!

Could I get Status Shopping Cart in magento from anywhere

Let me know how can I get status of shopping cart in magento from anywhere ?
I mean that Is It possible to get an error like
- your item "marlboro" count has been exceeded ! At present .
There is no so much in stock, please decrease it
Thanks
You can use something like that on an event that is fired on every page like controller_front_init_before
$cart = Mage::getModel('checkout/cart')->getQuote();
foreach ($cart->getAllItems() as $item) {
$product = $item->getProduct();
$stocklevel = (int)Mage::getModel('cataloginventory/stock_item')
->loadByProduct($product)->getQty();
if ($stocklevel<$item->getQty()){
...the logic that will permit to show the customer that the requested
product is not avaiable in this quantity...
}
}

Show qty for tier_price in product list

I need to show qty field for tier_price near regular price in product list (highest qty for lowest tier_price). Now $_product->getTierPrice() in product list gives me array(1) with 'tier_price'=>xxx and 'qty'=>1 (where xxx is lowest of my tier prices). Is it possible to get qty for tier_price in product list?
PS. In product view I can see array of tier prices with $_product->getTierPrice().
Magento CE 1.7.0.2
You can put this code in list.phtml or in view.phtml to show tier prices for each quantity.
$attribute = $_product->getResource()->getAttribute('tier_price');
$currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
$symbol = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();
if ($attribute) {
$attribute->getBackend()->afterLoad($_product);
$tierPrices = $_product->getTierPrice();
foreach($tierPrices as $tierPrice)
{
?>
<span class="priceqty"><?php echo '+'.round($tierPrice["price_qty"], 0);?></span><br>
<span class="pricetitle"><?php echo $symbol.number_format($tierPrice["price"], 2, '.', '');?></span>
<?php
}
}
?>
If you are looking for a Magento way:
$attribute = $_product->getResource()->getAttribute('tier_price');
if ($attribute) {
$attribute->getBackend()->afterLoad($_product);
$tierPrices = $_product->getTierPrice();
}
From /app/code/core/Mage/Catalog/Model/Product/Type/Price.php getTierPrice()
I have tested on Magento 1.4.0.2 (it should work also on other version ) on category pages and it works
In case you want to do it with SQL look here:
Magento: Display tier prices at category listing page

How to get preconfigure price from product view page to listing page in magento

Recently i came across the issue is When i display price of bundle product on listing page which shows either lowest price or highest price total by making total of all product within a bundle.
As i have set few product to default selected within a group so, on the product view page that default poduct price from perticualar group has been calculated in final total. but on price of product listing page count the minimum amount from the group of product.
So, what happens that customer view the product detail from product listing where it shows the lowest price but, on product view page it shows different price because now it counts default product price instead of minimum price from the group.
I want to display pre-configured product price from view page to product listing page.
Thanks in advance!
// load product
$product = new Mage_Catalog_Model_Product();
$product->load(165);
$priceModel = $product->getPriceModel();
// get options
$block = Mage::getSingleton('core/layout')->createBlock('bundle/catalog_product_view_type_bundle');
$options = $block->setProduct($product)->getOptions();
$price = 0;
foreach ($options as $option) {
$selection = $option->getDefaultSelection();
if ($selection === null) {
continue;
}
$price += $priceModel->getSelectionPreFinalPrice($product, $selection, $selection->getSelectionQty());
}

Magento : how to get the coupon code percent-off amount in the sidebar cart?

I'm using Magento 1.5.1 and I try to show the total of the cart in the sidebar cart like the checkout/cart page.
I'd like to show the coupon code percent amount if only a coupon has been applied.
For now, I show the cart price with the shipping price but I need this coupon code amount to have the final cart price.
I've just managed to show the coupon code name :
$couponCode = Mage::getSingleton('checkout/session')->getQuote()->getCouponCode();
But not its value...
I find discount, subtotal, shipping, tax and grand total with the code below :
// Totals : discount, subtotal, shipping, tax, grand_total
$totals = Mage::getSingleton('checkout/cart')->getQuote()->getTotals();
foreach($this->getTotals() as $total)
{
if ($total->getCode() == 'discount')
{
$discount = $total->getValue();
break;
}
}
?>

Resources