Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How do I display a specific product? 
 
Dementianati
Jr. Member
 
Total Posts:  2
Joined:  2007-11-14
 

I would like to have a specific product or products show up on an arbitrary page, such as the home page or an about us page.  I need to have all the components show up also, such as the image and the option choices.  I know the product id and can reference it by that.  I have been able to create a product object with

$product_inst = Mage::getModel(’catalog/product’)->load(1234); // 1234 is the product id

however, I am unable to use that to display the data.  With $product_inst, I can determine if the product has options with

if($product_inst->isSuperConfig()) {
// some code
}

However, in order to get the actual HTML that displays the options, I need to call

$this->getChildHtml(’super_config’);

where $this is an object of type Mage_Catalog_Block_Product_View.  I do not know how to properly create this object so it is associated with the product in question.  I have followed the inheritance tree and do not see how to set up the object properly.  Is the Object Model for Magento documented somewhere?

Or, am I simply going about this the wrong way?

Thanks much, for what looks like a very impressive system.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

@Dementianati: hi, I appologize it took long time to answer, lost this post for a while…

In class Mage_Catalog_Block_Product_View_Super_Config you can find public function getProduct():

public function getProduct()
{
    
return Mage::registry('product');
}
You can replace it with:
public function getProduct()
{
    
if (!$this->hasData('product')) {
        $this
->setProduct(Mage::registry('product'));
    
}
    
return $this->getData('product');
}

Now you can set product in super configurable block from Mage_Catalog_Block_Product_View like this:

$product Mage::getModel(’catalog/product’)->load(1234);

$super $this->getChild('super_config');
$super->setProduct($product);

$html $super->toHtml();
 
Magento Community Magento Community
Magento Community
Magento Community
 
Electric-dsctc
Member
 
Avatar
Total Posts:  35
Joined:  2008-01-21
 

Hello
I tried using the code dementianati posted...but by using it my hole sites crashes! (as in displaying a white page without code ....)

Thanks in advice

 
Magento Community Magento Community
Magento Community
Magento Community
 
Electric-dsctc
Member
 
Avatar
Total Posts:  35
Joined:  2008-01-21
 

Hello again...Still blocked with this one…
Isn’t there a way for me to display a product...say, with it’s ID ?
Something like $this->ShowProduct("id") tongue rolleye

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

@Electric-dsctc: well, i don’t see how product ID can benefit you on the frontend, but if you want to show sku:

<?=$_product->getSku()?>
$_product is the name of local variable that contains product object. May differ depending on context.
 
Magento Community Magento Community
Magento Community
Magento Community
 
Electric-dsctc
Member
 
Avatar
Total Posts:  35
Joined:  2008-01-21
 

Moshe thanks, I’ll give that a try!
but FYI ...I meant that I wanted to show the product (name, image, whatever) with some funtion that takes ID as the parameter, or something else as parameter.
This is because I saw that on catalog/product/view.phtml the product is retrieved with “ $_product=$this->getProduct()” . I was looking for something really similar to that but with a given parameter.
Something really similar to what Dementianati posted on the beginning on this post
Thanks, and sorry for my English, can be misleading sometimes

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

To load a product by id would be still the same as it is in previous posts:

$product Mage::getModel(’catalog/product’)->load(1234);
 
Magento Community Magento Community
Magento Community
Magento Community
 
Electric-dsctc
Member
 
Avatar
Total Posts:  35
Joined:  2008-01-21
 

if I use

$product Mage::getModel('catalog/product')->load(136);
(notice the simple quotes)
My hole site crashes. and if I use
$product Mage::getModel(`catalog/product`)->load(136);

as posted; I get a truckload of errors and warnings! So I don’t know whats up with that...can’t seem to make it work
I attached the errors just in case.

Thanks again Moshe for your patience.

File Attachments
errors.log  (File Size: 8KB - Downloads: 651)
 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

The simple quotes is the correct way.

Where do you try to put this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Pablo Lopez
Member
 
Avatar
Total Posts:  51
Joined:  2008-01-17
 

Hi Moshe...thanks a lot for the help!
I am displaying this on a template, more specifically on a sidebar.
I was doing a couple of things wrong.... the site crashed because I tried using “ echo $product “ which was plain dumb rasberry. Then I try using $product->toHtml(); which didn’t work either.
Then I get to realised that I was doing all wrong and use the correct methods like getName() or getThumbnailUrl()

Again..thanks a lot for the help...needed to bump my head to the wall a couple of times before I start getting this .

Now.... having this solved :
I saw on the reorder sidebar this “getItemsRandomCollection(number)” . How can I use something similar on my sidebar template?
For example get the collection of products inside a category and then displaying the info for one?

btw - Electric-dsctc was my other account - I forgot my user name so did a new account

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top