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

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')); ?>

Related

How do i display the selected value in multiselect while editing and updating the options(codeigniter)

How do i display the selected value in multiselect while editing and updating the options.
my multiselect function is:
foreach ($subjects as $sub){
$subject_selected[]=$sub['subject_name'];
}
echo form_multiselect('subject[]',$subject_list,'',$js,$subject_selected); ?>
if I m wrong please correct me..
It should be like
echo form_multiselect('subject[]',$subject_list,$subject_selected,$js); ?>
Lets you create a standard multiselect field. The first parameter will contain the name of the field, the second parameter will contain an associative array of options, and the third parameter will contain the value or values you wish to be selected. The parameter usage is identical to using form_dropdown() above, except of course that the name of the field will need to use POST array syntax, e.g. foo[].
I have searched for this thing and have failed so many times. But at last find a way around to resolve the issue.
This is the way that I have came across with.
<?php
$manpower_list = array();
$manpowers = $this->db->select('m.id, m.manpower_name')
->from('task_manpower tm')
->join('manpower m', 'tm.manpower_id = m.id')
->where('tm.deleted', 0)->where('m.deleted', 0)
->where('tm.task_id', $model_info->id)
->get()->result();
foreach ($manpowers as $power) {
$manpower_list[] = $power->id;
}
?>
<?php echo form_dropdown("manpower_id[]", $manpower_dropdown, $manpower_list, "class='select2 validate-hidden form-control' id='manpower_id' multiple='multiple'"); ?>
Hope it helps someone.

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;

Magento:how to get manufacturer name in Product page?

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');

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.

Resources