How Do I Output Delivery Instructions for Magento? - magento

I am trying to create a script that I can access via URL so that it outputs delivery details, specifically the fields I need to display are: orderID, status, gift_message and a custom customer address attribute that is called "delivery_instructions". So far I have the following, but I am stuck with trying to get the delivery instructions, any help would be much appreciated.
<?php
require_once 'app/Mage.php';
Mage::app('default');
$myOrder=Mage::getModel('sales/order');
$orders=Mage::getModel('sales/mysql4_order_collection');
$message = Mage::getModel('giftmessage/message');
$customer = Mage::getModel('customer/customer');
$orders->addFieldToFilter('total_paid',Array('gt'=>0)); //Amount paid larger than 0
//$orders->addFieldToFilter('gift_message_id',Array('gt'=>0));
$allIds=$orders->getAllIds();
foreach($allIds as $thisId) {
$myOrder->reset()->load($thisId);
$shippingAddress = $myOrder->getShippingAddress();
$customerDetails = $myOrder->getCustomer();
//echo $myOrder->shippingaddress->getData('delivery_instructions');
$customer_id = $myOrder->getCustomerId() . "',";
echo $customer_id . "',";
echo "'" . $myOrder->getStatus() . "',";
echo "'" . $myOrder->getIncrementID() . "',";
$gift_message_id = $myOrder->getGiftMessageId();
if(!is_null($gift_message_id)) {
$message->load($gift_message_id);
echo $gift_message = $message->getData('message') . "',";
};
$customer = Mage::getModel('customer/customer')->load( $customer_id);
echo $customer = $customer->getData('incrementId');
echo "\r\n";
echo "<br/ >";
}
?>

You are close with this:
//echo $myOrder->shippingaddress->getData('delivery_instructions');
In order to get the shipping address object you need to use:
$myOrder->getShippingAddress()
and to get the delivery_instruction from the shipping address object:
$myOrder->getShippingAddress()->getDeliveryInstructions()

You can create custom address attributes and custom customer attributes.
Customer attributes can be accessed like this:
// A customer is not mandatory for an order.
if($myOrder->getCustomerId()){
$customer = Mage::getModel(’customer/customer’)->load($myOrder->getCustomerId());
$customer->getDeliveryInstructions();
}
Address attributes can be accessed like this:
$myOrder->getShippingAddress()->getDeliveryInstructions();

Related

Magento Get Option Label by Option Code

I need to get the Custom Option Label based on either the Option ID or Option Code. Here's what I have so far:
$product_id = $product->getId(); //Get the Product Id
echo '<br /><strong>Product ID:</strong> ' . $product_id;
foreach($product->getCustomOptions() as $o) {
echo '<br />[Item ID] ' . $o->getItemId() . '<br />[Value ID] ' . $o->getId() . '<br />[Value] ' . $o->getValue() . '<br />[Code] ' . $o->getCode() . '<br />';
}
So what I have to work with at this point is:
Item ID
Value ID
Value
Code
My end goal is to use the option frontend label to see if the label is equal to "Length" as I am trying to use the "Length" value but seeing how custom options all have unique codes, the code is unreliable in terms of fetching just the "length" values for each item in the cart.
How can I use what I have to get the label for the custom options?
Thank you in advance!
You may follow these steps:
- create a test.php file in your magento root directory and run the codes below.
- it returns an array for each custom option with details.
<?php
require_once "app/Mage.php";
Mage::app('default');
echo "<pre>";
$productId = 13; // change the product id as your need
$product = Mage::getModel('catalog/product')->load($productId);
$productOptionCollection = $product->getProductOptionsCollection();
$customOptions = $productOptionCollection->getData();
print_r($customOptions);
?>

get data from sales order and sales order item in magento

I am working on a magento php code to get the Customer Name, email, product description, sku code, order number and customer id. However I have been feeling a bit stuck when trying to join the "sales/order" and "sales/order_item" models in order to print out the data through a foreach loop and also get only the now date. This is what I got so far:
<?php
set_time_limit(0);
require_once '../app/Mage.php';
Mage::app('uk');
$collection = Mage::getModel('sales/order')
->getCollection()
->addFieldToFilter('store_id', Mage::app()->getStore()->getId())
->addAttributeToFilter('status', Mage_Sales_Model_Order::STATE_COMPLETE)
->addAttributeToSelect('*')
->addAttributeToSort('created_at','DESC');
foreach ($collection as $c) {
echo $c->getCustomerName() . "\t" .
$c->getCustomerEmail() . "\t" .
$c->getCreatedAt() . "\r\n";
}
?>
Could you please give me a hand with this?
Thanks a lot,
Nestor
try below code
foreach ($collection as $c) {
$order = Mage::getModel("sales/order")->load($c->getId());
$ordered_items = $order->getAllItems();
foreach($ordered_items as $item){
echo $item->getItemId();
echo $item->getSku(); -
}
echo $c->getCustomerName() . "\t" .
$c->getCustomerEmail() . "\t" .
$c->getCreatedAt() . "\r\n";
}

Magento order grid

Hi I need to display Order Details grid in my Magento FRONT END page. I tried different ways, but nothing worked fine.
Also how to find <?php echo $this->getChildHtml('customer.account.dashboard.extra') ?> block.
Any idea please.
Here is the quick way,
<?php
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app()->getStore();
echo '<pre>';
$orders = Mage::getModel('sales/order')->getCollection()
//->addFieldToFilter('status', 'complete')
->addAttributeToSelect('customer_email')
->addAttributeToSelect('status')
->addAttributeToSelect('increment_id')
;
//echo $orders->getSelect();
//exit;
foreach ($orders as $order) {
$email = $order->getCustomerEmail();
echo $order->getIncrementId() . ": '" . $order->getStatus() . "', " . $email . "\n";
}
It fetches all order details. Please comment here if you have any doubt.

Joomla load module on extra place?

On my k2 pages I needed module complete on the top area, a module assign is not possible because the pages are dynamicly from the DB selected. So I installed a module like "loadmodule", the difference is simple I can get module with specific id.
For example: {loadmodulefromarticle|97} if I use it in the extra fields or in the content area then it works, but as written I need it in the top area of my page, so I have an if request and try load k2 content on the top. I get content and that's ok. But I see here only plain text and the module is not loaded. My question is, what is to insert here so that I get the module loaded? I think it can be something around to $result;
<?php
$menuID = JSite::getMenu()->getActive()->id ;
if ($menuID == '713') {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('introtext');
$query->from('#__k2_items');
$query->where('id = ' . JRequest::getInt('id'));
$db->setQuery($query);
$result = $db->loadResult();
?>
<div id="gkHeaderMod">
<div><?php echo $result; ?></div>
</div>
<?php
}
?>
You could do something like the following. It uses Joomla coding standards to get the menu ID and renderModule to display the module.
<?php
$app = JFactory::getApplication();
$menuID = $app->getMenu()->getActive()->id;
if ( $menuID == '713' ) {
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('introtext')
->from('#__k2_items')
->where('id = ' . JRequest::getInt('id'));
$db->setQuery($query);
$result = $db->loadResult();
echo '<div id="gkHeaderMod">';
$module = JModuleHelper::getModule( 'mod_example', 'Module Title' );
echo JModuleHelper::renderModule( $module );
echo '</div>';
}
?>
Note that you will have to change mod_example and Module Title to whatever you require

Print All Users - Joomla 2.5

I am new to Joomla. I have created website using Joomla 2.5. I have login page which is default Joomla user management system.
What I want is display all user data in a tabular format. How could I do the same?
Edit 1
I can see the users with below steps.
Go to administrator page as www.site.com/administrator.
Login as admin
Click Users >> User Manager menu and then I can see the list of users.
I want to print same list, however on the website and not on administrator site at backend.
you can do this run the query on your page where you want to show user list. you can fetch all users table field with $row object.
$db =& JFactory::getDBO();
$query = "SELECT * FROM #__users" ;
$db->setQuery($query);
$rows = $db->loadObjectList();
foreach ($rows as $row) {
echo $row->id.'|'.$row->username.'|'.$row->email;
}
Edit 1
Below is what I used.
Installed extension Flexi Custom Code.
Create module using this, add above code in it and appear that menu on the menu where you want to display.
You'll need some sort of component for this. This user profile component for example (N.B. Using this as my example as a work colleague once used it - not as customizable as I would have liked - but probably OK for what your after. I'm sure there are more as there's an entire member list category.)
Just install one of them and choose what you want to show. Add it to a menu like any other component and off you go!
Two possible solutions
Use the User Profile Component available in JED
Enable "User - Contact Creator" plugin to create a Contact profile for each new user and then use the Joomla built-in Menu Item to list all contacts
// my example with opt-groups, preselected user and better user-ids
function getUserList ($user_id) {
$db = JFactory::getDBO ();
$db->setQuery ("SELECT id, username, usertype FROM ' . $db->quoteName ('#__users') . ' ORDER BY usertype,username ASC");
$rows = $db->loadAssocList ();
static $opt_tag;
$list = '<option value="0">' . JText::_ ('SELECTION') . '</option>';
foreach ($rows as $row) {
if (empty ($opt_tag) || $opt_tag != $row['usertype']) {
$list .= '<optgroup label="' . $row['usertype'] . '">';
$opt_tag = $row['usertype'];
}
if ($row['id'] < 10) {
$id = '000' . $row['id'];
}
elseif ($row['id'] < 100) {
$id = '00' . $row['id'];
}
elseif ($row['id'] < 1000) {
$id = '0' . $row['id'];
}
$list .= '<option value="' . $row['id'] . '"' . (((int) $user_id == $row['id']) ? ' selected="SELECTED"' : '') . '>' . $id . ' - ' . $row['username'] . '</option>';
if (empty ($opt_tag) || $opt_tag != $row['usertype']) {
$list .= '</optgroup>';
}
}
return $list;
}

Resources