Magento - get store translated custom attribute label in "checkout/cart.phtml" - magento

In the shoppin cart; "checkout/cart.phtml" page, I want to add a column that contains a custom attribute. Working with a multilingual Website, I have to show the translated label of each Store.
I have tried this code:
$attributeLabel = Mage::getResourceModel('eav/entity_attribute_collection')
->setCodeFilter('length')
->getFirstItem()
->getFrontend_label();
echo "<pre>"; var_dump($attributeLabel); echo "</pre>";
but this shows the attribute admin label.
How can I get the translated labels for earch store ?
Thanks.

you will need to get the resource. Simply pull it from the product (or from the resource model). Then get the Attribute Object and instead of getting the frontend label you will need to get the store label.
$_product->getResource()->getAttribute('attributecode')->getStoreLabel();
alternatively
Mage::getModel('catalog/resource_product')->getAttribute($_attribute)->getStoreLabel();
also IMPORTANT: your attribute needs to have a Value Configured for that Language. (this is what got me here ;) )

getFrontendLabel() or getData('frontend_label'). You're confusing syntaxes.

Related

Including Joomla! 3 module in custom position on custom component

I've seen alot of examples of how to include modules on a custom joomla! component using JModuleHelper::getModules, however, when trying to include modules in a custom position, the array come back empty. Here's my code in my component's template:
<?php
jimport('joomla.application.module.helper');
$modules = JModuleHelper::getModules('comwhcustomer');
foreach ($modules as $module){
echo JModuleHelper::renderModule($module);
}
?>
You'll notice the position I'm passing the getModules function is comwhcustomer. This code is returning a blank array. If I pass "footer", I do successfully get the module in the footer position.
I'm using an adapted protostar tempalte and I have added the comwhcustomer position to the xml definition file for the template. I've created the module in module manager and in the position filed, I've selected the "comwhcustomer" position that shows up in the dropdown. On the modules manager page, I see the module listed in the position selected (comwhcustomer). I've confirmed in the database table #__modules that the position is saved correctly.
However, the array is still coming back empty on the getModules call. What am I missing?
Joomla version 3.4.1
Local environment
Windows IIS
PHP 5.4.24
MySQL db
PS - As an alternative, I have sucessfully loaded the module with JModuleHelper::getModule() however, none of the attributes I define in the module manager come over, because they're not supposed to. I'd like to use the method mentioned above so I can control the module behavior from the manager rather than attributes in the code, because this position will be used in multiple views of this component.
This is my first time posting to SO. I do appreciate the support :-)
itoctopus, you were exactly right! The module itself was not assigned to any pages, that's the piece I was not taking into consideration! Thank you so much for your help! I set it to display on all pages and it worked!
Of course, it doesn't show up on all the other pages because they do not contain a position called "comwhcustomer" so it is exactly what I was looking for!

Product attribute as link on other page

I have product with attribute address - where is product places. It is dropdown list. I want this atttribute will be a link on other site page with map and some other info about this address. But when i use html code in editor of attribute options it's not working. At the same time i checked property "Allow HTML Tags on Frontend" - it has "Yes" value. How can i do this?
Here is how my attribute looks like. and it seams to work:
For the attribute settings I just set to Yes Allow HTML Tags on Frontend and Visible on Product View Page on Front-end. The rest is set to No.
Here is how it looks like in the backend when editing a product.
And here is how looks in the frontend. And the link actually works.
I'm using CE-1.7.0.2.
Maybe the version is the problem. You can also try reindexing after you add the attribute.
[EDIT]
It seams that for 1.9 something changed.
See these lines in the attribute controller _filterPostData method:
foreach ($data['option']['value'] as $key => $values) {
$data['option']['value'][$key] = array_map(array($helperCatalog, 'stripTags'), $values);
}
You can view them here also: https://github.com/OpenMage/magento-mirror/blob/magento-1.9/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php#L167
The filter method looked differently in 1.8 and before: https://github.com/OpenMage/magento-mirror/blob/magento-1.8/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php#L153. It didn't have the strip tags on the options. Just the label.
I guess you can try to override the Mage_Adminhtml_Catalog_Product_AttributeController::_filterPostData method and make it look like it does in 1.8. But I don't know the risks.

Magento Can't mass update attributes for Required Field Error

I’m hoping someone can shed some light on this:
I’m using the search facility in Magento to find products with a certain attribute, and then selecting those products and using the “update attributes” feature to add data to (update) a different attribute field.
In some cases, this works fine, the new attribute data is recorded and all is well. On other selections when I try and save the new attribute data it comes up with the red warning “this is a required field”. Sure enough, the field it specifies IS a required field, but as I’m not updating that particular field I’ve not ticked the check box underneath it and this field should be ignored.
If I turn off the “required field” option for the highlighted fields then the new attribute data gets saved BUT: It wipes the data in loads of the other attributes, meaning I lose valuable data from my product attributes. It seems as if it works the first couple of times I use it in a day then it spits its dummy out and comes up with the required field issue.
I’ve tried this with both Google Chrome and Firefox. As I’ve said though, sometimes it will work , sometimes it won’t . I’m selecting 20-100 products at a time. I’ve even tried selecting just one product, and can still get the same error on that one product.
I’m on Magento 1.7.0.2
I did have a similar problem with attribute data getting wiped last year when we were on 1.6 but I seem to remember it was a Magento bug which was fixed when we upgraded to a newer version.
Can anyone shed any light on why this might be happening? There’s nothing coming up in the search engines for it and its really slowing me down!
The problem is that the attributes are NOT getting disabled by default in the update attributes page, hence require a value.
Why?
Most likely due to a faulty attribute failing somewhere above your attribute.
Option 1. As I don't know what attribute or the attribute problem, hack js/mage/adminhtml/product.js and change this function to ignore the faulty attribute.
function disableFieldEditMode(fieldContainer) {
try {
$(fieldContainer).disabled = true;
if ($(fieldContainer + '_hidden')) {
$(fieldContainer + '_hidden').disabled = true;
}
}
catch(exception) {
}
}
Option 2. Remove the faulty attribute from the product (You might need to remove restrictions ).
update eav_attribute set is_user_defined = 1 where attribute_code like 'foo_bar';
Option 3. Fix the faulty attribute. In my case the offending module was AW_Onsale.
it attempted to render a nonexistent frontend model: onsale/system_entity_form_element_position
select attribute_code, frontend_model from eav_attribute where attribute_code like '%aw_os_%';
aw_os_product_position | onsale/entity_attribute_frontend_position
update eav_attribute set frontend_model = null where attribute_code like '%aw_os_product_position%';
update eav_attribute set frontend_model = null where attribute_code like '%aw_os_category_position%';

Magento Order PDF logo function

I'm using an add Print order button to print a customer's order (not invoice) and I can't figure out how to get the logo to show up on the pdf. The following is the code that is in the extension but I can't find the function to manipulate it and I don't understand why it's not pulling the logo that I have in configuration. Please advise. :)
$this->insertLogo($page, $order->getStore());
You probably don't have store logo for PDF set. In admin you should go to
System -> Configuration -> Sales -> Sales -> Invoice and Packing Slip Design
and set your logo there.
Now for the logn explanation in case the above won't work :)
insertLogo function is located in class Mage_Sales_Model_Order_Pdf_Abstract (I asume that your class derives from it).
The rows that you should note are $image = Mage::getStoreConfig('sales/identity/logo', $store); and $image = Mage::getBaseDir('media') . '/sales/store/logo/' . $image;
getStoreConfig function is looking for the name of logo image in core_config_data table. You can check if the value is set with
SELECT * FROM core_config_data WHERE path = 'sales/identity/logo'
If the query won't return anything or will return value that is not an image name then you'll have to set that value first.
If that value is set you should have a look in
/your_store_root_dir/media/sales/store/logo/value_that_is_in_the_database
to see if the store logo image realy exists and if it doesn't add it there.
Did you check code in that class ($this) and/or its parent class? You'll see function inserLogo there.

Magento - Save a Product without setting "Use Default Value"

I have a multi-store setup - StoreA, StoreB and StoreC. And within a controller (using the StoreA url) I'm editing a product as follows:
$_product = new Mage_Catalog_Model_Product();
$_product->load($productId);
$_product->setData('attribute1','somevalue');
$_product->save();
If I then go to the Admin / Edit Product for that particular product, I find that attribute1 has been correctly set BUT I also find that if I select StoreA in the "Choose Shop View" I find that all the "Use Default Value" check-boxes (for StoreA) have been set to false.
Questions:
How do I modify the code above so the "Use Default Value"
check-boxes for StoreA remain true
Once that the above code has been executed (and the "Use Default
Value" for StoreA set to false), how do I revert the "Use Default
Value" values back to true for StoreA?
Edit:
Added screenshot:
I'm not entirely clear on the 'Use Default Value' check-boxes you are seeing, but there are two things I noticed.
Using The Factory Pattern
Your code:
$_product = new Mage_Catalog_Model_Product();
Use the factory pattern, which is standard in Magento:
$_product = Mage::getModel('catalog/product');
That in itself isn't the problem, but it's something to keep in mind.
Updating Only The Product Attribute
Next, if you are only saving a specific attribute it would be quicker (and potentially avoid your problem) if you update only that attribute. Like so:
$attribute = array('attribute_code' => 'attribute_value');
Mage::getSingleton('catalog/product_action')
->updateAttributes($_product->getId(), $attribute, 0);
Reference for the updateAttributes() method. My reasoning here is that it's possible default values are being added by saving the entire product, and not just a specific attribute.
If that doesn't help, perhaps a screenshot of what you are seeing could better help me visualize the issue.

Resources