I am new to magento, I have created an attribute language from the magento back-end.
By following this. Customer > Attributes Manager
Attribute has an input type dropdown.
I want to show this on my front-end in phtml file to take input from the user.
How can i do this.
Thanks
Try this
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'language'); //here, "language" is the attribute_code
$allOptions = $attribute->getSource()->getAllOptions(true, true);
foreach ($allOptions as $instance) {
$myArray[$instance['value']] = $instance['label'];
}
print_r(($myArray));
Related
I use Magento and I need help to use in frontend the translation of an attribute label !
I use this on my marketplace.phtml to load the attribute label
<?php
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'etat_verres');
$allOptions = $attribute->getSource()->getAllOptions(true, true);
foreach ($allOptions as $instance) { if($instance['label']) {
echo $instance['value'] // to show the value
echo $instance["label"] // to show the label
} }
?>
The problem is that Magento use Admin Value and not french value or english value.
Thanks in advance !
Sincerely yours,
John
Using the $this->__ is the core Magento helper which also contains the translation functionality, now assuming your module has extends the core Magento helper this will work. Now you can use a theme translate.csv file to translate your text.
<?php
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'etat_verres');
$allOptions = $attribute->getSource()->getAllOptions(true, true);
foreach($allOptions as $instance)
{
if ($instance['label'])
{
echo $this->__($instance['value']) // to show the value
echo $this->__($instance["label"]) // to show the label
}
}
Also keep in mind, translating the "labels" should not be necessary as you can use the Magento admin store view translations within Catalog->Manage Attributes Select your attribute and manage attributes per store view, however, I'm not entirely sure of the context. While what I provided should work, having context will provide a better solution.
Elgg is build on the MVC framework. My main agenda is to be able to save the value selected from the dropdown list, after which is to then display the chosen value the item listing. The following code is actually constructed in PHP that is following the Elgg framework closely.
What I have managed to do is to make use of the existing Elgg framework to display the dropdown list. In which, the dropdown list is created by the creation of a form in the following directory: mod/plugin/views/default/forms/plugin/form.php. I have hence made use of the existing Elgg framework (input/dropdown)to create my dropdown list as a form.
Secondly, I have managed to save the values chosen in the dropdown list and display the value in a success message. This is done in the action directory which will allow the values to be saved into the database when user clicks on 'save' button.
Code for saving and displaying value:
<?php
/**
* Elgg options uploader/submit action
*
* #package ElggFile
*/
// get the input variables
$list = get_input('OptionItems');
$container_guid = (int) get_input('container_guid', 0);
if ($container_guid == 0)
{
$container_guid = elgg_get_logged_in_user_guid();
}
$my_select_guid = (int) get_input (file_guid);
//create a new my_select object
$my_select = new ElggObject();
$my_select -> dropdown = $list;
$my_select ->container_guid = $container_guid;
//save to database and get id of the new my_blog
$my_select_guid = $my_select->save();
if($my_select_guid){
system_message("Your action post = " . $list);
//to add new muy_select object to river
add_to_river('river/object/file/create', 'create', elgg_get_logged_in_user_guid(), $list->guid);
}
else{
register_error("Your action post is not saved");
}
However, at this point, I am stuck in displaying the chosen value of the dropdown list as an extended view, within the view/default/object/file/
How am I able to do this?
It's all in Elgg documentation about the views that I linked for you before: http://learn.elgg.org/en/1.12/guides/views.html#extending-views
Duplicated attriubte set for new product line.
Attributes set show in backend and front end.
Created new attribute and added to attribute set.
New attribute show's in back end but not front end.
If I add the new attribute to the origonal set that was duplicated the new attribute will now show on the front end for the product assoiated with the duplicated attribute group.
So basicly A new attribute added to a duplicate set won't show on the front end until its added to the attribute set that was duplicated.
I've checked to make sure the attribute is visable on front end etc and tried it several times checking the settings.
The goal is to be able to duplicate a attribute set and add new attributes for different product types. Then call the folder by id and display the assoiated attributes.
I've called the attribute group by ID (spec's). This code is working.
<?php
require_once 'app/Mage.php';
Mage::app();
$attributeGroupCollection = Mage::getResourceModel('eav/entity_attribute_group_collection');
$product = $this->getProduct();
foreach ($attributeGroupCollection as $attributeGroup) {
$attributeGroup->getAttributeGroupId();
$attributeSpecs = Mage::getResourceModel('eav/entity_attribute_collection')
->setAttributeGroupFilter(41);
}
?>
Help is appreciated, thanks
Duplicating an attribute set is duplicating at a time (the moment when you click the button). If you want to add an attribute in both attribute sets, you need to create it in both, for that, you just need to create your attribute and drop it in the section you want to have it linked to (what you call "folder"). If you want to do it programmatically. You need to create an observer that will be fired after the attribute set is saved and that will add the attribute to the duplicated attribute set. I would not advise to do so because it means that you need to enter the ID of the attribute set duplicated and it can be tricky thing when it comes to pushing the development to the production. I am sure there is a workaround for what you want to achieve.
The problem was is magento creates a new id for each new group folder in the new duplicated attribute set (makes sense). I was calling by ID for the group and as a result will only show attributes in the origional folder (weird) even if the product was assoicated with the new attribute set. What I did was get the current attribute set id and then sort out the attribute groups by name so even if the attribute sets are coppied as long as the folde has the name it will display in the custom loop displaying the attributes. Here is my working code:
$attributeSetModel = Mage::getModel("eav/entity_attribute_set");
$attributeSetModel->load($product->getAttributeSetId());
$attributeSetName = $attributeSetModel->getAttributeSetName();
$attributeSetID = $attributeSetModel->getAttributeSetID();
$groups = Mage::getModel('eav/entity_attribute_group')
->getResourceCollection()
->setAttributeSetFilter($attributeSetID)
->setSortOrder()
->load();
$attributeCodes = array();
foreach ($groups as $group) {
echo $groupName = $group->getAttributeGroupName();
$groupId = $group->getAttributeGroupId();
if (strpos($groupName , 'Specifications') !== false) {
echo 'true';
$specificationsNum = $groupId;
};
if (strpos($groupName , 'eatures') !== false) {
echo 'true';
$prodfeaturesNum = $groupId;
};
}
//echo $specifications;
$specifications = Mage::getResourceModel('eav/entity_attribute_collection')
->setAttributeGroupFilter($specificationsNum);
$prodfeatures = Mage::getResourceModel('eav/entity_attribute_collection')
->setAttributeGroupFilter($prodfeatures);
I am trying to get selected bundle option title and value on product detail page.
Unit Colour* : Antelope Audio Zodiac Digital to Anologue Converter +£0.00
I use the below code but it return me option list and not selected option value but not title like Unit color
$bundled_product = new Mage_Catalog_Model_Product();
$bundled_product->load($_product->getId());
$selectionCollection = $bundled_product->getTypeInstance(true)->getSelectionsCollection(
$bundled_product->getTypeInstance(true)->getOptionsIds($bundled_product), $bundled_product
);
$bundled_items = array();
foreach($selectionCollection as $option)
{
echo "<pre>";
print_r($option);die;
$bundled_items[] = $option->product_id;
}
Please check below image also.
So please suggest me idea how can i get title and selected value.
Thanks
Disclaimer: this snippet works fine with the bundle product on magento demo site:
http://demo.magentocommerce.com/my-computer.html
If I put into browser URL bar the below snippet with prefix javascript: and postfix generate_options_label_and_value(), it works fine for the radio buttons. If you need more extended case (supporting dropdowns/checkboxes), let me know. This is just a quick snippet:
function generate_options_label_and_value(){
var generated_html = '';
$$("#product-options-wrapper>dl>dt").each( function (dt){
if(dt.next('dd').select('input:checked[type=radio]').length > 0 ){
generated_html += dt.select("label")[0].innerHTML;
generated_html += dt.next('dd').select('input:checked[type=radio]')[0].next('span').innerHTML;
}
});
if(!$('selected_options_div')){
$$('.add-to-cart')[0].insert({ top : "<div id='selected_options_div'></div>"});
}
$('selected_options_div').update(generated_html);
}
This is written in prototype
I have created a new IMEI attribute of type textarea for all products, see from the image. Can anyone point out a function to update the its value. I have the code like the following.
$this belogns to Mage_Sales_Model_Order.
foreach ($this->getAllItems() as $item) {
$item->setImei('123');
$item->save();
echo $item->getImei();
}
I am getting 123 from the last statement but when I am viewing from admin. Its not changing there. Also in which table the attribute and value will be stored, So I can debug from there.
What class is $this->getAllItems() is it Mage_Catalog_Model_Product?
If it not Mage_Catalog_Model_Product then load the product by id and save the product
foreach ($this->getAllItems() as $item) {
$product = Mage::getModel('catalog/product')->load($item->getId() or $item->getProductId())
$product->setImei($product->getImei() . '123');
$product->save();
}
The values of catalog product attributes of type text are stored in the table catalog_product_entity_text. An SQL would be
select * from catalog_product_entity_text where attribute_id = {insert your attribute id} and entity_id = {insert your product id}
The query will return results for every store view in the system.
The reason why you do not see a change to the attribute in the backend is probably because the new value is set for a different website/store than the one loaded in the backend.
You are already using a correct way to set the attribute value assuming $item is of type Mage_Catalog_Model_Product:
$item->setImei('123');
$item->save();
heres how you do it differently: (color = attribute name, red = attribute value id)
starts assuming you already have $product available.
$attr = $product->getResource()->getAttribute('color');
if ($attr->usesSource()) {
$avid = $attr->getSource()->getOptionId('red');
$product->setData('color', $avid);
$product->save();
}