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.
Related
Using code from a previous discussion (link:https://magento.stackexchange.com/questions/12504/how-to-add-hreflang-tags-or-other-meta-tags-to-pages-in-magento), I was able to implement the hreflang links into our Magento site.
Here is the code that worked for me:
<?php foreach (Mage::app()->getWebsites() as $website) {
foreach ($website->getGroups() as $group) {
$stores = $group->getStores();
foreach ($stores as $store) {
$storeId = $store->getId();
$storeCode = substr(Mage::getStoreConfig('general/locale/code', $storeId),0,2);
if (Mage::registry('product')) {
$productId = Mage::registry('product')->getId();
$base_url = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
$url = Mage::getModel('catalog/product')->setStoreId($storeId)->load($productId)->getProductUrl();
$url = preg_replace('/\?.*/', '', $url);
echo '<link rel="alternate" hreflang="' . $storeCode . '" href="' . $url . '"/>';}
elseif(Mage::registry('current_category')) {
$categoryId = Mage::registry('current_category')->getId();
$base_url = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
$url = Mage::getModel('catalog/category')->setStoreId($storeId)->load($categoryId)->getUrlPath();
echo '<link rel="alternate" hreflang="' . $storeCode . '" href="' . $base_url . $url . '"/>' . "\n";
}}}}
?>
<?php
$storeId = 1;
if (Mage::registry('product')) {
$productId = Mage::registry('product')->getId();
$base_url = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
$url = Mage::getModel('catalog/product')->setStoreId($storeId)->load($productId)->getProductUrl();
$url = preg_replace('/\?.*/', '', $url);
echo '<link rel="alternate" hreflang="x-default" href="' . $url . '"/>';
}
elseif(Mage::registry('current_category')) {
$categoryId = Mage::registry('current_category')->getId();
$base_url = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
$url = Mage::getModel('catalog/category')->setStoreId($storeId)->load($categoryId)->getUrlPath();
echo '<link rel="alternate" hreflang="x-default" href="' . $base_url . $url . '"/>' . "\n";
}
?>
I'm having an issue with layered navigation URL's and canonical links disappearing on category pages.
Is there something I can add to this code to make sure that layered navigation URL's that contain "?" after .html get written as shown in the browsers address bar?
Also, on these types of category pages the canonical link does not show.
The code works perfectly on product pages.
Any help would be greatly appreciated!
Thanks in advance.
To solve this I need to know:
Where have you put this code? Is executed in categories?
Is the current_category empty?
Regards.
I missunderstood the question. Could you show an example?
The code only shows the category base URLs. When applying filters the module change the URL adding parameters filtered but your code doesn't have those parameters.
Usually people do not position the filters because it gives many problems of duplicate content. Take a look at this link:
https://amasty.com/blog/magento-layered-navigation-best-settings-for-seo/
In my opinion, I would left canonical URLs in categories using its base URL and disallow to index anything layered because could give duplicated content issues.
Kind regards
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);
?>
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";
}
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();
I'm using this code to display the child categories of a specific category in Magento:
$parentCategoryId = 3;
foreach Mage::getModel('catalog/category')->load($parentCategoryId)->getChildrenCategories() as $childCategory) {
echo $childCategory->getName() . '<br />';
echo $childCategory->getUrl() . '<br />';
}
That works quiet fine. But now I like to display description and category image of these child categories. I've tried it with the descriptions and added this line:
echo $childCategory->getDescription() . '<br />';
But the output is empty. Does anybody has an idea what I can do to display the description and later the category image?
Thank you for your help.
Please try this one, its working fine at my end
<?php
$parentCategoryId = 10;
$categories = Mage::getModel('catalog/category')->load($parentCategoryId)->getChildren();
$catArray = explode(',', $categories);
foreach($catArray as $child){
$_child = Mage::getModel( 'catalog/category' )->load( $child );
echo $_child->getName() . '<br />';
echo $_child->getUrl() . '<br />';
echo $_child->getDescription() . '<br />';
}
?>
we will not get category description attribute from this function getChildrenCategories(). A better explanation about this function can be found here on Stackoverflow answer