I'm trying to add the number of backorder products to the email template that comes out in the new order email.
So far I've managed to get the product but I just can't seem to get it's quantity. I've tried a variety of methods but nothing seems to work. Here is my latest attempt:
The file is app/design/frontend/base/default/template/email/order/items/order/default/phtml
<?php
// 1. Get Qty of Product in Store.
// 2. Get Qty of product from order
// 3. IF qty from order > qty in store then get number over
// 4. Display number over
$_sku = $this->getItem()->getSku();
$_product = Mage::getModel('catalog/product')->loadByAttribute('sku', $_sku);
//print_r($_product);
echo 'qty in shop: '.$qtyInStock = $_product->getStockItem()->getQty(); //debugging
echo 'qty ordered: '.$qtyOrdered = $_item->getQtyOrdered()*1; //debugging
?>
<?php if($qtyOrdered > $qtyInStock): $back_order = $qtyOrdered - $qtyInStock; ?>
<p>* This product is not available in the requested quantity. <?php echo $back_order; ?> of the item(s) will be backordered.</p>
<?php endif; ?>
I'm not finished with the logic yet. I'm just stuck on getting the products quantity.
$_product->getStockItem()->getQty();
Any help most appreciated.
Billy
Found a solution:
$_product = Mage::getModel('catalog/product')->loadByAttribute('sku', $_sku);
$stock_count = (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
Seems quite roundabout but it does the job.
Feel free to suggest better...
Related
I want to insert this attrribute that I have created into the product page above the add to cart button but only if the qty is ZERO. Basically an estimated arrival date. Items that are available on back order only have a note above the add to cart button of when the product will actually be available from. I have put the below in and it works but I don't want it to show for products already available.
<p><font color="red">AVAILABLE FROM: <?php echo $_product->getResource()->getAttribute('due_date')->getFrontend()->getValue($_product); ?></font></p>
Can someone let me know what I need to add please.
Most appreciated
Anthony
You should be able to get the stock quantity on the product page by using:
Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()
You can then use that in a conditional to show the piece of code that you want. However, I'm not sure you need all of that to show the due date. Because you're already loading the product when you are on the product page, you should just be able to use:
<p class="red">AVAILABLE FROM: <?php echo $_product->getDueDate(); ?></p>
If that doesn't work, make sure that you have your due date attribute set to be visible on the product page. It'll be the one called, "Visible on Product View Page on Front-end".
Full code block could look something like this:
<?php
$qty = Mage::getModel(cataloginventory/stock_item)->loadByProduct($_product)->getQty();
if ($qty <= 0): ?>
<p class="red">AVAILABLE FROM: <?php echo $_product->getDueDate(); ?></p>
<?php endif; ?>
If you allow backorders, it's important you check for <= 0, rather than == 0. This is because if someone backorders it, your stock will go negative.
Also, it's more clean to remove the font tag and use CSS to style the text.
I am trying to echo the product price minus a discount on the product-page, based on checking the product price. The checking is working, however I can't manage to output the discounted price.
Example: If the price is between 50 and 100, i'd like to echo product price * 0.8 (20% discount)
<?php if ($_product->getFinalPrice() >= 50 && $_product->getFinalPrice() < 100 ) : ?>
<?php echo $this->getPriceHtml($_product)*0.8 ?>
<?php endif; ?>
I have tested that the rule works ok. I also manage to output only the price. But the *0.8 doesn't works (It is probably not the correct way to calculate it, but I've tried just about everything except the correct thing)
No that wont work. The problem is you are trying to apply a mathematical equation on a block of html.
Try this instead to express the price with the modification while maintaining the current currency character and decimal rules;
<?php echo Mage::helper('core')->currency($_product->getFinalPrice()*.8, true, false); ?>
Hey you must do something like that:
<?php if ($_product->getFinalPrice() >= 50 && $_product->getFinalPrice() < 100 ) : ?>
<?php
$valWithDiscount = $this->getPriceHtml($_product)*0.8;
echo $valWithDiscount;
?>
<?php endif; ?>
That shoud solve your problem, let me know.
Live Long and Prosper \//
we sell bunch of product and we need to display each price product and entire box price.For that reason i have created attribute with each price and calling it on product page.So main price of product will be box price and each price will be display from attribute.but now i when i add tax i can see the main price with excluding and including tax but how to apply that tax on attribute based price?
this would be each product price
<?php echo $_product->getResource()->getAttribute('each_price')->getFrontend()- >getValue($_product)?>
this would be whole box price
<?php echo $this->getPriceHtml($_product, true);?>
some thing like this can be done to achive this.please look the code below
<?php $txrate= $_product->getData('tax_percent');
if($txrate!=""):
echo '<div class="each-inc-tax">';
$ech_price= $_product->getResource()->getAttribute('each_price')->getFrontend()->getValue($_product);
$tx=($txrate*$ech_price)/100;
$each_tax=$ech_price+$tx;
echo ' <b>Each Price Including Tax:</b> <b>'. $each_tax.'</b>';
echo '</div>';
endif;
I was using the MSRP attribute in my magento and storing the value excluding Tax, but wishing to display on the frontend including Tax.
I used the following code...
<?php
$_finalPriceExclTax = $this->helper('tax')->getPrice($_product, $_product->getPrice(), false);
$_finalPriceInclTax = $this->helper('tax')->getPrice($_product, $_product->getFinalPrice(), true);
$_taxpercent = $_finalPriceInclTax / $_finalPriceExclTax;
$_msrpPrice = $_product->getMsrp() * $_taxpercent;
?>
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.
how can I show the stock indicator on Magento product list ?
Thanks a lot.
To show the quantity of items left in stock use this:
<?php echo (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty(); ?>