Getting product name and phone number in the success page for Magento - magento

I am using Magento 1.9 and I need to use customer name, number, and product name in the success page. How can I achieve that?

get customer name and phone number using below fields
$order = Mage::getModel('sales/order')->load($this->getOrderId());
if($order->getCustomerIsGuest()){
echo $order->getBillingAddress()->getName();
echo $order->getBillingAddress()->getTelephone();
}
else{
echo $order->getCustomerName();
echo $order->getTelephone();
}

Assuming you already have the order object in success page
$order->getBillingAddress()->getTelephone();
$order->getCustomerName();
$ordered_items = $order->getAllVisibleItems();
foreach($ordered_items as $item)
$product_name[] = $item->getName();

Even if some one searching for same.
$orderDetails = Mage::getModel(‘sales/order’)->loadByIncrementId($this->getOrderId());
To get Contact Number
echo $telePhone=$orderObj->getBillingAddress()->getTelephone();
To get Complete array use print_r($orderDetails);

Related

Active records on codeigniter page

I want print a table from database on view page with where condition, means I want print table of student where class is seven and fee status is paid.
How we do this?
i tried it but not work:
<?php
$students = $this->db->get_where('student' , array('status' => paid,'class_id'=>7))->result_array();
foreach($students as $row):?>
I have used this code to find the answer for you Please see it and try it out
$query = $this->db->get_where('tasks', array('description' => 7,'status' => 1));
echo "<pre>";
print_r($query->result_array());
change your array element as this since paid is a string it must be in quots
array('description' => "paid",'class_id'=>7)

Magento - get order id from increment id

How do you get the Order Id from magento Order Increment Id?
I can use the following get the product id from SKU:
$product_id = Mage::getModel('catalog/product')->getIdBySku('ABCD1234');
The above example lets me get just the database entity_id of a product without loading everything. I want to achieve the same for order.
In a Magento model, the load method can take an optional second argument of what attribute to load by.
So, in your case, the following should work:
$order = Mage::getModel('sales/order')->load($incrementId, 'increment_id');
$id = $order->getId();
In more complex cases, e.g. where you want to load by a combination of fields, you can load a collection, and get the first element of the collection. In your case, you'd do it like this:
$order = Mage::getModel('sales/order')->getCollection()
->addFieldToFilter('increment_id', $increment_id)
->getFirstItem();
You can load an order from the IncrementId.
$orderIncrementId = "1000001";
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
echo $order->getId();
If you want to fetch only order_id then simply use mysql query, if you want order_id in for loop, it is not load entire order object and it is very quick and fast, you don't need to load order object model.
$write = Mage::getSingleton('core/resource')->getConnection('core_read');
$result=$write->query("SELECT entity_id FROM `sales_flat_order` WHERE `increment_id` = 'your increment id' ");
$row = $result->fetch();
echo $row['entity_id'];

In Prestashop, how to get category of last product added?

I don't have that much experience with Prestashop, php, and Smarty.
How do I get the category of lastProductAdded?
I am trying to make the "continue shopping" button redirect to the category of the last product added.
« {l s='Continue shopping'}
The following code doesn't seem to work, giving category id of 0 for some reason. (I have no idea whether it makes sense either)
Any help would be much appreciated. Thank you!
(The variable lastProductAdded and function getCategoryLink are already defined in-built)
For Prestashop 1.4.x you need to modificate Cart::getLastProduct() with this code:
public function getLastProduct()
{
$sql = '
SELECT cp.`id_product`, cp.`id_product_attribute`, p.`id_category_default`
FROM `'._DB_PREFIX_.'cart_product` cp
JOIN `'._DB_PREFIX_.'product` p ON (cp.`id_product` = p.`id_product`)
WHERE `id_cart` = '.(int)($this->id).'
ORDER BY cp.`date_add` DESC';
$result = Db::getInstance()->getRow($sql);
if ($result AND isset($result['id_product']) AND $result['id_product'])
return $result;
return false;
}
Regards
you need to use $lastProductAdded.id_category_default instead of $lastProductAdded.category->id
Regards

Magento - addStoreFilter not working?

When getting a product collection in Magento, I would expect the StoreFilter to do just that, filter by the current store. But I can't get it to work.
Say I have 2 stores set up like so:
And both stores have a different root category. Main Store is the default sample data, Store2 has just one product I added. I would have thought that using the store filter, only products within the root category of the current store would show up. But I'm getting every product showing. I'm testing this by placing the following in my category view template:
$store_id = Mage::app()->getStore()->getId();
$_testproductCollection = Mage::getResourceModel('reports/product_collection')
->setStoreId($storeId)
->addStoreFilter($store_id)
->addAttributeToSelect('*');
$_testproductCollection->load();
foreach($_testproductCollection as $_testproduct){
echo $this->htmlEscape($_testproduct->getName());
};
If I echo the store ID, it's giving me the correct number. I have only one product in Store 2, so why am I getting every product from all stores returned? I can set every product in Main Store to not show in Store2 and then add a visibility filter, but that would take forever.
Also, I just noticed, if I echo the products store ID, I get the current ID, not the store it's assigned to:
echo $_testproduct->getStoreId()
What's going on?
UPDATE (April 8 2011):
OK, so I tried joining the fields so that the store_id is included (as suggested below), the section of code {{table}}.store_id = 1 is just setting all the products to have a store_id of 1. How can I just get the store_id associated with the product?
$_testproductCollection = Mage::getResourceModel('catalog/product_collection');
$_testproductCollection->joinField('store_id', 'catalog_category_product_index', 'store_id', 'product_id=entity_id', '{{table}}.store_id = 1', 'left');
$_testproductCollection->getSelect()->distinct(true);
$_testproductCollection->addAttributeToSelect('*')->load();
foreach($_testproductCollection as $_testproduct){
echo $this->htmlEscape($_testproduct->getName())."<br/>";
echo "STORE IS ".$_testproduct->getData('store_id')."<br/>";
};
If I check the catalog_category_product_index table of my db, the store_id's are correct.
$_testproductCollection should look like this $_testproductCollection = Mage::getResourceModel('reports/product_collection')->addAttributeToSelect('*')->addStoreFilter().
If You print SELECT from that collection You will see that there ain't any store column, so addStoreFilter() can't apply WHERE.
You should use joinField() on Your collection and add store_id column from catalog_product_entity_varchar table.
EDIT
Sorry to keep You waiting ;)
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->joinField('store_id', 'catalog_category_product_index', 'store_id', 'product_id=entity_id', '{{table}}.store_id = 1', 'left');
$collection->getSelect()->distinct(true);
This should do the trick, but just to be sure, please check if you're getting right products :)
This worked for me:
Mage::app()->setCurrentStore($storeId);
$productCollection = Mage::getModel('catalog/product')
->getCollection()
->addStoreFilter()
->addAttributeToSelect(array('sku','price'));
OK, I think this works, haven't tested too much but seems to have done the trick. You need to first get your stores root category id, then join some fields so you have access to the products "category_id", then filter using that:
$_rootcatID = Mage::app()->getStore()->getRootCategoryId();
$_testproductCollection = Mage::getResourceModel('catalog/product_collection')
->joinField('category_id','catalog/category_product','category_id','product_id=entity_id',null,'left')
->addAttributeToFilter('category_id', array('in' => $_rootcatID))
->addAttributeToSelect('*');
$_testproductCollection->load();
foreach($_testproductCollection as $_testproduct){
echo $this->htmlEscape($_testproduct->getName())."<br/>";
};
I think
You don't need to do any joins as the magento's setStoreId() will work.
$collection = Mage::getModel("catalog/product")
->getCollection()
->setStoreId(1) //change store Id according your needs
->addAttributeToSelect(array('name','url','sku'))
->setPageSize(20);
This will get maximum 20 products from store id 1

How to get last running transaction Id in magento

How can I get the last running transaction Id ? (eg: 10000001)
I've tried numerous ways, with no success.
I was suddenly enlightened when I looked at the problem again at home. Why not get the last order increment id from the sales/order collection?
$orders = Mage::getModel('sales/order')->getCollection()
->setOrder('increment_id','DESC')
->setPageSize(1)
->setCurPage(1);
echo $orders->getFirstItem()->getIncrementId();
Tested and working on Magento 1.3.2.3
Try this:
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$dbc_collect_order = Mage::getSingleton('core/resource')->getConnection('core_read');
$items_collect_order = $dbc_collect_order->fetchAll("SELECT `increment_id` FROM `sales_flat_order` ORDER BY `entity_id` DESC LIMIT 1");
echo $last_main_order_id = $items_collect_order['0']['increment_id'];
Please note that there is a more simpler answer to silvo's:
$orders = Mage::getModel('sales/order')->getCollection();
echo $orders->getLastItem()->getIncrementId();

Resources