Magento:how to get manufacturer name in Product page? - magento

I want to display manufacturer name in product/view.phtml .I have all used all sort of functions like
<?php echo $_product->getAttributeText('manufacturer');?>
<?php echo $this->htmlEscape($_product->getData('manufacturer'));
<?php echo $_product->getData('manufacturer'); ?>
But none of them helped.So how to get manufacturer name in product view page .

As mentioned above you will need to follow a few steps:
1) goto Attribute Sets, and make sure "manufacturer" is assigned to the attribute set you are using.
2) Make sure you have added some manufacturers into the attribute options.
3) Assign one of the options to your product.
Depending on your magento version this should work:
<?php echo $_product->getAttributeText('manufacturer') ?>
I can see the error you are getting:
gives error Call to a member function getManufacturer() on a non-object in
Are you sure you are putting this code after this line:
<?php $_product = $this->getProduct(); ?>

you can use something like this to get manufacture name
$_product->getResource()->getAttribute('manufacture')->getFrontend()->getValue($_product);

Make sure the following things
1. Your attribute code is "manufacturer".
2. "Manufacturer" attribute is added to your attribute set.
3. You have chosen attribute values in admin catalog product.
4. That corresponding product is visible on frontend.
If all the 4 points are yes your code should work.

Try:
$_procuct->getManufacturer();

<?php
echo $_helper->productAttribute($_product, $_product->getManufacturer(), 'manufacturer')
?>

manufacturer (and all other attributes) is part of the optionslist, which is accessible by getOptionsList.
Try this snippet:
<?php
$_options = $this->getOptionList();
echo $_options['manufacturer']['value'];
?>

Make sure that the "Used in product listing" option for the manufacturer attribute has been set to "Yes".
After that you should be able to do
$_product->getManufacturer();

$_product->getAttributeText('country_of_manufacture');

Related

Why cakephp FormHelper::input() doesn't create a multiple select input on a hasMany association?

I have a model for which exists some model associations whose hasmay and HABTM.
In the edit view,
<?php echo $this->Form->input('myHABTMModel'); ?>
create a select>multiple input, but
<?php echo $this->Form->input('myHasManyModel'); ?>
create a select input with unique choice.
Why ? It is normal ?
I must specify ?
Or something is wrong somewhere ?
Indeed, it must specify the multiplicity in the input method options :
<?php echo $this->Form->input('myHasManyModel',array('multiple'=>'multiple')); ?>

Add static block in product detail page only for certain categories

I want to add a static block in Product detail page for category 4. I did like this:
$catid = $this->helper('catalog/data')->getProduct()->getCategoryIds();
?>
<?php $blockID = "free_shipping_" + $catid ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId($blockID)->toHtml()
?>
and then in admin I created a static block with URL and blocktitle free_shipping_4.
(4 in free_shipping_4 stands for category 4).
I get the error :
Fatal error: Unsupported operand types in C:\wamp\www\mydomain\app\design\frontend\default\mytheme\template\catalog\product\view.phtml on line 140
yes you are right. I found out that now that $catid is an array. So I used
$catid[1] to get the catalog ID. So my code looks like this
<?php $blockID = "free_shipping_" . $catid[1]?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId($blockID)->toHtml();
To find the catalog id I am interested to use in the Static block name (free_shipping_4) I used the following code
SELECT entity_id AS categoryID, value AS categoryName
FROM catalog_category_entity_varchar
WHERE attribute_id =4
LIMIT 0 , 30
It is solved now. Although there must be a better and easier way to do it.
$catid = $this->helper('catalog/data')->getProduct()->getCategoryIds();
?>
getLayout()->createBlock('cms/block')->setBlockId($blockID)->toHtml() ?>
$catid will contain array of id product is associated with.
I think one way is to create an product attribute and that will contain category id need to show and then you can retrieve product attribute.
<?php $blockID = "free_shipping_" + $productattributevalue ?>

Magento Pre Order Product with Date attribute

I am new to Magento and maybe its a very basic question, but I want to display Pre-Order products on my home page. I have created an attribute Product_Release_Date and set it to a future date. When I try to get Product_Release_Date its returning blank. What I am doing wrong?
$_productCollection=$this->getLoadedProductCollection(); to get all products
foreach ($_productCollection as $_product):
<?php $currentDate = Mage::getModel('core/date')->date('Y-m-d H:i:s'); to get current date for compare
echo $_product->getResource()->getAttribute('Product_Release_Date');
When I try to display its showing blank, but it returns productName and other things. Only this date is not showing. Please help or provide some tutorial where it shows how to enable pre-order.
The $_product->getResource()->getAttribute('Product_Release_Date'); line is only loading the attribute collection. You can do this after to see what it contains: var_dump($_product->getResource()->getAttribute('Product_Release_Date'));. If it's NULL then make sure your new attribute is really set to Product_Release_Date and not product_release_date (lower-case).
You can use a "magic get" to retrieve the value, like this:
echo $_product->getProductReleaseDate();
Here is a fairly recent tutorial on how to enable display of out-of-stock items:
http://www.inmotionhosting.com/support/edu/magento/103-magento-products-and-inventory-settings/how-to-display-products-that-are-out-of-stock-in-magento
Its very likely the product attribute "Product_Release_Date" is not in the loaded product collection.
If you need to get it then load the products from Magento Product Resource Model
$productCollection = Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect('*');
foreach($productCollection as $product):
echo '<br/>' . $product->getProductReleaseDate();
endforeach;

How to show current time in magento admin panel?

I'd like to show current system time in mangeto admin panel at the top.
I tried to find the code and I found this line:
<?php echo $this->formatDate(null, 'full') ?>
in
app\design\adminhtml\default\default\template\page\header.php
But I don't know how to change it.
I've seen that there is a different time for mangento. see post.
This is what I was expecting:
<?php echo date("m/d/Y h:i:s a", Mage::getModel('core/date')->timestamp(time())); ?>
Magento has function Mage::getModel('core/date')->date('Y-m-d H:i:s')
< ?php echo $this->formatDate(null, 'full',true ) ?>
You can pass 3rd parameter true for show time.

Magento $this->getPriceHtml($_product, true) not showing

I'm not entirely sure why this is not working, and I've been stuck on it for hours.
I have a file called banners.phtml, which is created using the following layout update:
<block type="catalog/product" name="banners" template="page/html/banners.phtml">
<!-- there are further blocks in here, but aren't important --->
</block>
The type is catalog/product, and on the page I have a loop which feeds an SKU to each product Model load:
<?php $_product = Mage::getModel('catalog/product')->loadByAttribute('sku', get_field('product_sku')); ?>
Then when I use:
<?php echo $this->getPriceHtml($_product, true) ?>
Nothing shows - it doesn't break the site, but nothing shows. I've seen it mentioned that the product block type needs to be loaded - but I thought that's what catalog/product was doing... Does anyone have any ideas?
I realised the reason was because my collection was full of grouped products only. Therefore I added
->addMinimalPrice()
to the collection query and it worked.
Go to the list.phtml file
Remove the code " getPriceHtml() ?>".
Add the following code to get the simple price for the product:-
"echo $_helper->productAttribute($_product, $_product->getPrice(), 'price')"
Or
To get the special price of the product use the following code:-
" echo $_helper->productAttribute($_product, $_product->getSpecialPrice(), 'price') "
It surely works man. :)

Resources