Get Image on onepage success page - magento

I want to get image of products on order succes page of magento here is the code
<?php
$order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
foreach ($order->getAllItems() as $item) {
//Need image code here
}
?>
Does anybody know how to get product image on onepage success page
Thank you

Check this peace of code for image with thumbnail
<?php
$model = Mage::getModel('sales/order') //getting product model
$_product = $model->load(Mage::getSingleton('checkout/session')->getLastRealOrderId()); //getting product object for particular product id
echo $_product->getImageUrl(); //product's image url
echo $_product->getSmallImageUrl(); //product's small image url
echo $_product->getThumbnailUrl(); //product's thumbnail image url
?>

$orderIcrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIcrementId);
$orderItems = $order->getAllItems();
foreach($orderItems as $orderItem):
$_product = Mage::getModel('catalog/product')->load($orderItem->getProductId());
$product_small_image_path = Mage::helper('catalog/image')->init($_product, 'small_image')->resize(135);
$product_thumbnail_path = Mage::helper('catalog/image')->init($_product, 'thumbnail')->resize(56);
endforeach;

Related

Magento - Display product count views?

I am using magento 1.9 and i am trying to display the views of the product in the product view page.
Here is what code i am using right now but it's not displaying anything:
<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>
<?PHP echo $_product->getViews();?>
Is it possible to display the number of the views of the displayed product or where i am doing wrong.
Thanks in advance!
You could create an observer for catalog_product_load_after and add views to the $_data array with
$product = $observer->getEvent()->getProduct();
$resource = Mage::getSingleton('core/resource');
$read = $resource->getConnection('core_read');
$select = $read->select()
->from(
$resource->getTableName('log/url_info_table'),
'COUNT(*) views'
)
->where('url LIKE "%catalog/product/view/id/' . $product->getId() . '"');
$result = $read->query($select)->fetch();
$product->setData('views', $result['views']);

How do I get the product image url from a product collection?

I need to re-size an image for an XML feed. I am looping through the products fine but when trying to get the URL of a re-sized image I am running into problems.
foreach ($collection as $_product) {
$MainImage = Mage::helper('catalog/image')->init($_product, 'small_image')->constrainOnly(false)->keepAspectRatio(true)->keepFrame(true)
->keepTransparency(true)->resize(300, 150);
$arr['Image'] = $_product->getSmallImageUrl();
$arr['MainImage'] = $MainImage;
$arr['Name'] = $_product->getName();
}
If I echo out $MainImage it returns a URL, but for some reason it doesn't like being in a string.
Basically if I then echo out the array it does not show the URL of the image, it's just blank.
Can anyone point me in the right direction?
If you take a look # /app/design/frontend/default/base/template/catalog/product/view/media.phtml
$_helper = Mage::helper('catalog/output');
....
foreach ($collection as $_product) {
$MainImage = Mage::helper('catalog/image')->init($_product, 'small_image')->resize(410,420);
$MainImage = $_helper->productAttribute($_product, $MainImage, 'small_image');
or cast the return as string
$MainImage = (string)Mage::helper('catalog/image')->init($_product, 'small_image')->constrainOnly(false)->keepAspectRatio(true)->keepFrame(true)->keepTransparency(true)->resize(300, 150);
Did you try
$arr['MainImage'] = (string)Mage::helper('catalog/image')->init($_product, 'small_image');?

unable to get product price in custom file magento

Hi i am new to magento and i need to get the products from a particular category
for this i have use
<?php
$id1=4;
$category1 = Mage::getModel('catalog/category')->load($id1);
$collection1 = $category1->getProductCollection();
$collection1->addAttributeToSelect('name');
$collection1->addAttributeToSelect('description');
$collection1->addAttributeToSelect('image');
$collection1->addAttributeToSelect('producturl');
$collection1->addAttributeToSelect('prlce');
$products1 = $collection1->getItems();
$_helper1 = $this->helper('catalog/output'); ?>
<?php foreach ($products1 as $product1){ ?>
<?php echo $this->htmlEscape($product1->getPrice()) ?>
<?php } ?>
in this it is showing the name , image and url but when i am trying to echo price it doenot show anyhing.Please suggest me where i am doing mistake
This is how you do it:
<?php
// Test Params
$cat_id = 4;
$store_id = 1;
// Load Category
$category = Mage::getModel('catalog/category')->load($cat_id);
// Load Category Products
$categoryProducts = $category->getProductCollection();
// Iterate Through Product Collection
foreach ($categoryProducts as $categoryProduct)
{
// Load Product At Specified Store Id
$product = Mage::getModel('catalog/product')
->setStoreId($store_id)
->load($categoryProduct->getId());
// Debug
print_r($product->getData());
// Get Price (e.g.)
echo 'Product Price: '. $product->getPrice()
}
?>

Creating downloadable information dynamically

How to create downloadable information(small,medium,large) dynamically(at time of uploding image and save it.),before saving product,using images details
You can use Magento API to create downloadable product information dynamically.
$items = Mage::getModel('cart/mycart')->getCollection()->addFieldToFilter('customer_id', Mage::getSingleton('customer/session')->getCustomer()->getId()); foreach($items as $item) : $incrementId = Mage::getModel('sales/order')->load($item->getOrderId())->getIncrementId();//->addFieldToFilter('product_id',$item->getItemId());
$linkPurchased = Mage::getModel('downloadable/link_purchased')->load($incrementId, 'order_increment_id'); $downloadableItems = Mage::getResourceModel('downloadable/link_purchased_item_collection') ->addFieldToFilter('purchased_id', $linkPurchased->getPurchasedId()); //->addFieldToFilter('product_id', $item->getItemId()); $links = array(); foreach ($downloadableItems as $li): $links[] = Mage::getModel('core/url')->getUrl('downloadable/download/link', array('id' => $li->getLinkHash(), '_secure' => true)); endforeach; foreach($links as $link): ?> " target="_blank">

Magento - Product Collection with the current user's Wishlist

Within a Magento php Controller, how can I get a Product Collection containing the products listed in the logged in user's (ie current user's) Wishlist.
I am getting the Wishlist using:
$wishList = Mage::getModel('wishlist/wishlist')->loadByCustomer(Mage::getSingleton('customer/session')->getCustomer());
and this contains the correct number of items.
But I would like to get a Product Collection. I have tried:
$productCollection = $wishList->getProductCollection();
and
$productCollection = $wishList->getProductCollection()->addAttributeToSelect('id')->load();
but the Product Collection I get has a length of 0.
How do I get the Product Collection?
You can use the getWishlistItemCollection (see link for more details) off the wishlist helper to return a collection of items, you then need to get the product from the item.
I have been using the following code to create an associative array of the products, which I then use to determine if a product I am displaying in the list page is in the wishlist...hopefully this will help:
public function getWishList() {
$_itemCollection = Mage::helper('wishlist')->getWishlistItemCollection();
$_itemsInWishList = array();
foreach ($_itemCollection as $_item) {
$_product = $_item->getProduct();
$_itemsInWishList[$_product->getId()] = $_item;
}
return $_itemsInWishList;
}
Try this with product all details like name, images etc...
<?php
$customer = Mage::getSingleton('customer/session')->getCustomer();
if($customer->getId())
{
$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer, true);
$wishListItemCollection = $wishlist->getItemCollection();
foreach ($wishListItemCollection as $item)
{
echo $item->getName()."</br>";
echo $item->getId()."</br>";
echo $item->getPrice()."</br>";
echo $item->getQty()."</br>";
$item = Mage::getModel('catalog/product')->setStoreId($item->getStoreId())->load($item->getProductId());
if ($item->getId()) :
?>
<img src="<?php echo Mage::helper('catalog/image')->init($item, 'small_image')->resize(113, 113); ?>" width="113" height="113" />
<?php endif; } } ?>
$customer = Mage::getSingleton('customer/session')->getCustomer();
$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer, true);
$wishListItemCollection = $wishlist->getItemCollection();
foreach ($wishListItemCollection as $item)
{
// do things
}

Resources