How to show invoice no and date in Magento? - php

I am using a page to display order details and want to show invoice no and date in that page. Please tell me how to show invoice no. Here is the code:
<div class="col-sm-4 invoice-`co`l">
<b>Order No. </b>#
<?php if ($this->getNoUseOrderLink()): ?>
<?php echo $_order->getRealOrderId(); ?>
<?php else: ?>
<?php echo $_order->getRealOrderId(); ?>
<?php endif; ?>
<br>
<b>Amount:</b> <?php echo "&nbsp".$this->gettotalamount(); ?><br>
<b>Payment Type:</b> <?php echo $_order->getPayment()->getMethodInstance()->getTitle(); ?>

Below is the code snippet to get Invoice info associated with any order. Based on your code, you have already loaded order model on $_order, so try below code.
<?php
// ignore below two lines if you already have order model
// $_order=Mage::getModel('sales/order')->loadByIncrementId($anyorderincrementid);
// $_order=Mage::getModel('sales/order')->load($anyorderentityid);
if ($_order->hasInvoices()) {
$invIncrementIDs = array();
foreach ($_order->getInvoiceCollection() as $inv) {
echo "Invoice Id- ".$inv->getIncrementId();
echo "Invoice Date- ".date('d-m-Y',strtotime($inv->getCreatedAt()));
}
}
?>
To get date in d-m-y format (answer of your question which is in comments)
<?php
// format admin and store date
$orderAdminDate=date('d-m-y',strtotime($orderAdminDate));
$orderStoreDate=date('d-m-y',strtotime($orderStoreDate));
echo $orderAdminDate;
if ($orderAdminDate != $orderStoreDate):
echo date('d-m-y',strtotime($_order->getCreatedAtStoreDate()));
echo $orderStoreDate;
endif;
?>

Related

how to do multiplication in php and mysql

I need to multiply the price by the quantity to get the total cost but i am not sure how to do this.
This is what i have done so far:
<?php do { ?>
<p align="Center">
<?php echo $row3['unitprice'] ?>
<?php echo $row3['quantity']; ?>
</p>
<?php } while ($row3 = mysqli_fetch_assoc($resultCustomer3))?>
at the moment i am only printing out unit price and the quantity.
how would i multiply the two to get the total?
HELP please!!
Try this
<?php while ($row3 = mysqli_fetch_assoc($resultCustomer3)) {?>
<p align="Center">
<?php echo $row3['unitprice']; ?>
<?php echo $row3['quantity']; ?>
<?php echo $row3['quantity']*$row3['unitprice']; ?>
</p>
<?php } ?>
To multiply two fields in php, you need this code:
$total = $mnth_190 * $rate_190;
After having calculated the result, you can normally output the variable total!

using and multiple else if statement- output unexpected end of file

i have been trying to echo the codes and it not working properly. after reading up ifelse statement, i still cant figure what wrong with this statement in php outputting unexpected end of file.
<?php if($current_type){?>
<?php echo " Manage Product Type ";
echo "Menu Name:". $current_type["product_type"]."<br>";?>
Edit Subject;
<?php}elseif($current_category){?>
<h1> Manage Product category </h1>
<?php echo "Menu Name:". $current_category["category_name"];?>
<?php}elseif ($current_product){?>
<h1> Manage Products </h1>
<?php echo "Menu Name:". $current_product["product_names"];?>
<?php }else{?>
Please select a Product, category, or type
<?php};?>
This is a huge improvement on the readability of your code. It uses PHP alternate syntax for control structures.
<?php if($current_type): ?>
<h1>Manage Product Type</h1>
Menu Name: <?php echo $current_type["product_type"] ?><br>
Edit Subject
<?php elseif ($current_category): ?>
<h1>Manage Product category</h1>
Menu Name: <?php echo $current_category["category_name"] ?>
<?php elseif ($current_product): ?>
<h1>Manage Products</h1>
Menu Name <?php echo $current_product["product_names"] ?>
<?php else: ?>
Please select a Product, category, or type
<?php endif ?>
try this,
<?php if($current_type){ ?>
<?php echo " Manage Product Type ";
echo "Menu Name:". $current_type["product_type"]."<br>";?>
Edit Subject;
<?php } else if($current_category){ ?>
<h1> Manage Product category </h1>
<?php echo "Menu Name:". $current_category["category_name"];?>
<?php } else if ($current_product){?>
<h1> Manage Products </h1>
<?php echo "Menu Name:". $current_product["product_names"];?>
<?php } else {?>
Please select a Product, category, or type
<?php }?>
Use this rationale
<?php if(1 == 1) { ?>
<?php echo "xxxxx"; ?>
<?php } elseif(1 == 2) { ?>
<?php echo "xxxxx"; ?>
<?php } elseif (1 == 3){ ?>
<?php echo "xxxxx"?>
<?php } else { ?>
<?php echo "xxxxx"?>
<?php } ?>

If column value = NO don't display

I have an if statement
<p>Included Services</p>
<?php foreach($services as $service): ?>
<?php if(!empty($service['service_webdesign'])){ ?>
<div><strong>web Design:</strong> <?php echo $service['service_webdesign'] ?></div>
<?php } ?>
<?php endforeach ?>
<p>Services charged by the hour</p>
<?php foreach($services as $service): ?>
<?php if(!empty($service['service_webdesign'])){ ?>
<div><strong>Service:</strong> <?php echo $service['service_webdesign'] ?></div>
<?php } ?>
<?php endforeach ?>
There are three possible values Yes, hourly rate or no.
In the first block I want to be able to echo the service column values
<div><strong>Service:</strong> <?php echo $service['service_webdesign'] ?></div>
only if the database value is 'yes'.
In the second block I want to echo the service fee column
<div><strong>Web Design:</strong> <?php echo $service['service_fee_webdesign'] ?>
</div>
only if the value of the 'service_webdesign' is set to 'hourly rate' but I do not actually want to show the value of 'service_webdesign' ('hourly rate').
An example of my database table structure is as follows
service_webdesign = Yes
service_fee_webdesign = NULL
service_graphicdesign = Hourly
service_fee_graphicdesign = 20
How can I achieve that within an if statement? Or would I need to create another SQL query for each of the blocks?

display text based on category in wordpress

how can i solve the following problem. Basically I want to show different sub headings based on the wordpress category being used.
this is the following code:
$categ = the_category(' ');
if($categ == 'News'){
$second_header = " secondry header displayed here";
}else{
$second_header = "Error";
}
?>
<h2> <?php the_category(' '); ?></h2>
<p> <?php echo $second_header; ?></p>
Right now this is not working, instead of checking against the text 'news' is there any way to check against the category id?
thanks in advance.
You can use the following to store the current category id:
<?php $catID = the_category_ID($echo=false);?>
The echo false stops any echo on the page and stores the variable. You can then do the following:
<?php
$categ = the_category_ID($echo=false);
if($categ == 1)
{
$second_header = " secondry header displayed here";
}
else
{
$second_header = "Error";
}
?>
<h2> <?php the_category(' '); ?></h2>
<p> <?php echo $second_header; ?></p>
Alternatively to this you could also use the following (as I believe the_category_ID is now deprecated http://codex.wordpress.org/Function_Reference/the_category_ID):
$categories = get_the_category();
$categ = $categories[0]->cat_ID;
if($categ == 1)
{
$second_header = " secondry header displayed here";
}
else
{
$second_header = "Error";
}
?>
<h2> <?php the_category(' '); ?></h2>
<p> <?php echo $second_header; ?></p>
Different Text on some Category Pages:
<?php if (is_category('Category A')) : ?>
<p>This is the text to describe category A</p>
<?php elseif (is_category('Category B')) : ?>
<p>This is the text to describe category B</p>
<?php else : ?>
<p>This is some generic text to describe all other category pages,
I could be left blank</p>
<?php endif; ?>
if you need category id you will need to first get category through <?php get_the_category_by_ID( $cat_ID ); ?>
Because the_category_ID is deprecated, then you can do the same with some modification.
More here - http://codex.wordpress.org/Category_Templates

Magento static Blocks is not displaying properly.

I have created few static blocks just based on the category Id trying to display different blocks .
The problem being some times the block is displayed while some other times it is not .
I guess there is prob with code ? or the way magneto displays static blocks not sure ?
CODE:
<?php
<?php $_description = $this->getProduct()->getDescription(); ?>
<?php if ($_description): ?>
<div class="std">
<?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), $_description, 'description') ?>
<?php $category = Mage::getModel('catalog/layer')->getCurrentCategory();?>
<?php if($category->getId()==14): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==15): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==16): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==18): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==19): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==86): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==25): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==13): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==98): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information_fbyz')->toHtml();?>
<?php else: ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information_others')->toHtml();?>
<?php endif; ?>
</div>
<?php endif; ?>
please resolve my problem.
If you put this code in product view page then it it not properly way to get current category in product page..
Used Mage::registry("current_category") instead of Mage::getModel('catalog/layer')->getCurrentCategory();
If you come to category directly then you can get current category id product page.then you used to fetch current product categories ids.
$categoryIds = Mage::registry('current_product')->getCategoryIds();
if(Mage::registry("current_category"))
{
$category = Mage::getModel('catalog/category')
->load(Mage::registry("current_category")->getId());
}elseif(is_array($categoryIds )){
//multiple categories id of product. that way i was taken on list category
$category = Mage::getModel('catalog/category')->load($categoryIds[0]);
}
elseif(!is_null($categoryIds)){
$category = Mage::getModel('catalog/category')->load($categoryIds);
}
else{
//no categoies
}

Categories