I need to know, if any solution how to add in magento success.phtml order's total price?
Because I want after placed order, customer get all info how to make payment including what price need to pay, because customer don't remember in last step what is total price.
You could use something like this in your success.phtml:
$sOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$oOrder = Mage::getModel('sales/order')->load($sOrderId);
echo $oOrder->getGrandTotal();
in success.phtml template you can use
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$total = $order->getGrandTotal();
proper way is to extend the Mage_Checkout_Block_Onepage_Success and add your own method for loading the order again (As in this page quote is inactive already) as it is not nice to load such stuff in templates
Related
I'm integrating a system with Magento.
When I create an order, if my non-Magento system indicates the order does have a coupon I would like to mark the coupon code as "used" for that customer, so the next time he tries to use it, Magento will know that customer already used it.
How can I accomplish this?
I manage to do it like this:
$coupon = mage::getModel('salesrule/coupon')->load($code, 'code');
$coupon->setTimesUsed($coupon->getTimesUsed()+1);
$coupon->save();
$rule = Mage::getModel('salesrule/rule')->load($coupon->getRuleId());
$rule->setTimesUsed($rule->getTimesUsed()+1);
$rule->save();
$couponUsage = Mage::getResourceModel('salesrule/coupon_usage');
$couponUsage->updateCustomerCouponTimesUsed($customerId,$coupon->getCouponId());
Thanks to this post:
Magento - Single Coupon marked as used when payment pending
Set the Shopping Cart Rule's Uses per Customer to 1.
----EDIT----
If you want to apply the coupon in your code then you can do something like this:
$coupon_code = "YOUR_CODE";
Mage::getSingleton('checkout/cart')
->getQuote()
->setCouponCode($coupon_code)
->collectTotals()
->save();
I want to display the discounted price the client can have depending on the payment method he chooses directly on the product page.
Basically, what I need is a way to get the shopping cart rules that apply for payment methods. So then I could use it to build a table of payment methods X discounts like this:
Cash: $90 (10% discount)
CC: $100 (Full price)
Transfer: $100 (Full price)
So far I couldn't find a way to access the shopping cart rules. Any insights?
UPDATE:
For those wondering, I've found a way to get the shopping cart rules. Pretty simple actually:
$model = Mage::getModel('salesrule/rule')
->getCollection();
With this information I can loop through the rules and find the ones that apply to payment methods.
$conditions = unserialize($item['conditions_serialized']);
But I realized that this way is too much work and can get complex if rules are complex. I decided to get the rules that I want by ID and get the discount value, since it won't change all the time.
If you know how to make Magento calculate everything for me, like me asking "If a user chose this payment method, besides everything else (user group, catalog discounts, etc) what would be the final price?".
$model = Mage::getModel('salesrule/rule')
->getCollection();
foreach($model as $item){
// check, do whatever and get discount
}
A client wants all products that are sold out to appear at the end of the product listings and I'm struggling to get it to work at the minute, hence the question. It's worth noting that all the categories in the system are set to only use 'Best Value' positioning for their product ordering and that this repositioning must be done automatically.
Currently I've added an observer to the 'sales_convert_quote_item_to_order_item' event which is the point where the cart items are added to the order itself (seemed like a sensible place to target).
The problem I've found is that obviously the qty available for a product is stored on the products inventory record but the products positioning is stored against the category itself (and then indexed).
I don't really want to resort to using SQL so was hoping someone here would be able to offer some sort of suggestion for a method to use.
My Observer method currently looks like this but it doesn't work because the getUsedProducts method isn't available for some reason. Here it is anyway:
$cart = Mage::getModel('checkout/cart')->getQuote();
foreach($cart->getAllItems() as $key=>$item):
print_r(get_class_methods($item));
echo ">>> ".$item->getProductType();
if($item->getProductType()):
$item = $item->load($item->getId());
//print_r(get_class_methods($item));
$_productCollection = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$item);
print_r($_productCollection);
$stockLevel = 0;
foreach($_productCollection as $product):
$childProductData = $product->getData();
$stockLevel+= $childProductData['stock_item']['qty'];
endforeach;
echo "<br />STOCK LEVEL: $stockLevel<br />";
if($stockLevel <= 0):
echo "ZERO";
//return true;
endif;
endif;
echo "<br />";
endforeach;
I recognise that this isn't a great way of doing this and as such would be quite intensive it there were a lot of products in the cart. But as the order isn't created at this point then I can't use that either.
Any pointers or suggestions would be gratefully received.
Thanks.
If I am correctly understood from the Problem:
...A client wants all products that are sold out to appear at the end of the product listings...
If listings = categories then why don't u change rendering logic? Simply extend catalog product list and override get product collection method.
What u need to achieve is that all sold out products are at the end of the list. So you can sort loaded collection of products with one of these functions.
You can also use Bestseller logic for listing the products.With the help of this link http://inchoo.net/ecommerce/magento/bestseller-products-in-magento/ Or http://blog.magikcommerce.com/how-to-display-best-selling-products-on-magento-store-home-page/ you will know how to get the bestseller products and then you need to call this best seller block in product list.Hope this will help you if you are still searching for the solution.
We have a Magento multi-site that give a percentage back to a non-profit, and what we would like to do is to allow customers to select which non-profit or a group within that non-profit to receive the percentage.
Trying to keep it simple we thought allowing customers to enter a discount code named something like "GIVE BACK to {non-profit name}" (but no actual dollar amount subtracted from the purchase or maybe just a penny, I don't think you can have a 0 to a discount code), then internally we know to give the percentage back to that non-profit.
It just seems a little bit of an odd way of doing this, it would be better to have a drop down of the none-profits at the end, but we are not sure how to create that.
Does anyone have any suggestions, on an easy way of doing this?
Thanks in advance!
You could add an attribute to the quote/order model and then populate that with an appropriate value, populated at the cart level? It's the kind of think we've done for affiliate modules we've built in the past.
You'll need a custom controller to grab the value when the customer moves from the cart to the checkout, which means you'll also need to make the Cart -> Checkout step a form submission instead of a straight link.
Then, at the end of the month, you'll need to run a report on the collection with something along the lines of:
// I've added a * in the SELECT because I'm not sure of the attribute names off the top of my head :)
$collection = Mage::getModel('sales/order')->getCollection()
->addAttributeToSelect('*')
// Make sure the orders are in the correct date range
->addAttributeToFilter(...)
// Make sure the orders are in a valid state, e.g. processing, pending, complete, etc..
->addAttributeToFilter(...)
$donation_total = array();
foreach ($collection as $order) {
// You'll have to investigate the attribute values for these
$charity = $order->getData('charity_attribute_code');
$order_total = $order->getData('order_total_attribute_code');
if (!isset($donation_total[$charity])) {
$donation_total[$charity] = 0;
}
$donation_total[$charity] += $order_total;
}
print_r($donation_total);
You could make this more efficient with proper SUM()ing in the query.
I'm struggling to figure out how to display the percentage or the amount of discount that is applied to a product in Magento via the Catalog Price Rules.
For example: I want the price to be displayed in the front-end as follows: [old-price] [special-price] [discount info] where [old-price] has a css strike through.
The [old-price] and [special-price] is available by default through the tax helper. I've tried using the CatalogRule model, but I have no way to load it with a product id as the load function expects an entity id and from what I can tell, there aren't any other useful methods to load by product ID. I've var dumped (as well as using get_class_methods) just about everything that I found in the price.phtml file (apart from $this of course), but nothing helps.
I could just use a simple calculation to work out the discount percentage or amount, but I have no way of knowing whether the catalog rule is based on a percentage, or fixed amount.
I hope this all makes sense?Thanks for the help.Rémy
I do agree Magento makes this kind of thing a bit too hard. I wanted to display the description of the coupon code next to the entered coupon code. I suspect my code will be able to help you on your way. I put this code at the top in the template checkout/cart/coupon.phtml:
<?php
$c = Mage::getResourceModel('salesrule/rule_collection');
$c->addBindParam('coupon_code', $this->getCouponCode());
$c->getSelect()->where("coupon_code is null or coupon_code='' or coupon_code=:coupon_code");
foreach ($c->getItems() as $item) {
$coupon_description = $item->getDescription();
}
?>
So you can see $coupon_description now holds the description of the Shopping Cart Price Rule as long as the user specified a coupon code. You can add more properties from the coupon this way.