I'm trying to translate the prefix like 'mr.' and 'mrs.' those are set in: System >> Configuration >> Customer Configuration >> Prefix Dropdown Options
I need it in English, Dutch and German. Each language is a separate storeview.
I've added the translation to multiple .csv files like the themes translate.csv and the Mage_Core.csv
The default <?php echo $this->__($prefix) ?> works on the frontend like the checkout. But in the backend and emails it isn't translated.
Any way to translate those?
I found two ways to fix this.
remove the build in prefix and add a new one with custom prefixes.
overrule the Mage_Customer_Helper_Data class and it's getNamePrefixOptions method.
I used Nr2
NR 1: is more work, you will need to update tempaltes. But it is easier to manage for a customer if needs to ad a new translation.
NR2: You can add more prefix values in the config. Then in the class make a switch which to use in which store/language. Adding a new language will probably need to add more code the the class.
What I used to overrule the getNamePrefixOptions
public function getNamePrefixOptions($store = null)
{
$pre_val = $this->_prepareNamePrefixSuffixOptions(
Mage::helper('customer/address')->getConfig('prefix_options', $store)
);
// Show all prefixes in the admin
if (Mage::app()->getStore()->isAdmin()) {
return $pre_val;
}
// Transform array keys to integers
$pre_val = array_values( $pre_val );
$lang_code = Mage::app()->getLocale()->getDefaultLocale();
$new_prefixes_values = array();
// Add language codes here, and add their prefix key's, count starts at 0
switch ( $lang_code ) {
case "nl_NL":
// Set key the same as the value, that's how Magetnto gives it at first
$new_prefixes_values = array( $pre_val[0] => $pre_val[0], $pre_val[1] => $pre_val[1]);
break;
case "de_DE":
$new_prefixes_values = array( $pre_val[2] => $pre_val[2], $pre_val[3] => $pre_val[3]);
break;
default: // other languages
$new_prefixes_values = array( $pre_val[0] => $pre_val[0], $pre_val[1] => $pre_val[1]);
break;
}
return $new_prefixes_values;
}
What I filled in the Prefix Dropdown Options setting: Dhr.;Mevr.;Herr;Frau
It is a bit hard coded but works and allows you to change the values
Related
I adjusted app.php as per instruction:
'locale' => 'ru',
'fallback_locale' => 'en',
But on first visiting the site it always shows an english version. Thus russia based user always needs to click "Russian" button to view russian version of the site.(language switching was created with Session::put('lang', $lang) and redirect to /).
I also tried using handling session language in App::before filter but no luck: it shows in russian all the database content but all that in trans('message.<word>') remains in english (the code is now commented in filter.php).
The project is available on github (to look through files where you may suspect a reason).
The site address www.izutov.com (there are "English" and "Russian" buttons in the left top corner)
Thnx in advance!
This is what I have done to set language selection in Laravel 4 :
in app/filters.php
App::before(function($request) {
Route::matched(function($route, $request) {
if($route->getName() != 'admin') { // don't do it for admin area, (for example)
$language = $_ENV['FALLBACK_LOCALE'];
$lgs = explode(',', $_ENV['LANGUAGES']); // your set of languages
// get the default browser language with the $request object
$browserLg = substr($request->server->get('HTTP_ACCEPT_LANGUAGE'), 0, 2);
// language set from route (for example /en/some-url)
$requestLg = $request->segment(1);
# if the language called in url request matches your set of languages
if (null !== $requestLg && in_array($requestLg, $lgs)) {
$language = $requestLg;
# default browser lg
} else {
if(in_array($browserLg, $lgs)) {
$language = $browserLg;
}
}
// set the validated language
$_ENV['LOCALE'] = $language;
Config::set('locale',$language);
App::setLocale($language);
// share it with views if you want
View::share('locale', $language);
});
});
I am using a Single Sign On technique from a Wordpress website,once the user logs on, they are automatically directed to the Moodle LMS namely 'courses/view.php?id=*relevant_id*'.
The $USER object already has the user type (called 'department' in this case) set up.
I want to do a theme switch based on this user type.
Something like:
if($USER->department == 'redTeam') {
$theme = 'RedteamTheme';
}
My question is:
Where would I place this code snippet?
Does anyone know the exact syntax?
I have looked around Google for hours and I cannot get the syntax
I have found how to do it in code.
In the lib folder you will need to amend 2 files:
pagelib and weblib. The pagelib file is a lengthy extension so I won't paste that code here. If anyone wants it, they can contact me, I will happily share.
the weblib needs to have this added to it for theme switching to work:
//create the function
function _setTheme(){
global $DB,$USER, $CFG, $THEME, $COURSE;//open abstraction layers
//set the criteria for te switch in this case I used the department field, it can also //be roles
$getRole = $USER->department;
if(!empty($getRole)) { //If the variable is not empty proceed with the switch
switch($getRole){
case 'role1':
$val = 'sky_high';
break;
case 'role2':
$val = 'leatherbound';
break;
}
} else {
//default theme
return 'leatherbound';
}
return $val;
}
I'm trying to make new product statuses but i can't figure out how to do it and all the stuff set on the web is not consistent or simply talks about order status which i don't want to change.
What is your motivation to have new product statuses? I think it's little bit risky to change this part of app. I suggest you to add new attribute and use this one instead system product's attribute 'status', this attribute tells to system if product is enabled or disabled. I guess there is nothing between :)
Override class Mage_Catalog_Model_Product_Status to the local folder. Then open the file
\app\code\local\Mage\Catalog\Model\Product\Status.php
At the top of the file you can see the constants
const STATUS_ENABLED = 1;
const STATUS_DISABLED = 2;
Add your custom status below them, for example
const STATUS_SUSPENDED = 3;
Then edit the function getOptionArray
static public function getOptionArray()
{
return array(
self::STATUS_ENABLED => Mage::helper('catalog')->__('Enabled'),
self::STATUS_DISABLED => Mage::helper('catalog')->__('Disabled'),
self::STATUS_SUSPENDED => Mage::helper('catalog')->__('Suspended')
);
}
That's it. Don't forget to clear the cache.
I want to prevent customers entering PO Boxes into the shipping address for selected Shipping Methods (UPS specifically in this case). I could override js/prototype/validation.js to insert a new validation pattern, but I don't want to fork such a key file.
Is there a mechanism to unobtrusively validate the customer's shipping address AFTER they select a shipping method via Javascript without overriding core files?
I see that Validation.add is used inside the validation.js, so it may be possible to add a new validation method outside of the core file?
The regex that I want to apply is:
\b([P|p](OST|ost)?\.?\s?[O|o|0](ffice|FFICE)?\.?\s)?([B|b][O|o|0][X|x])\s(\d+)
If the validation cannot be performed elegantly in the JS, I would be interested in an Observer on the controller_action_predispatch_onepage_saveShippingMethod that inspects the data and performs an Ajax redirect back to the shipping address form if necessary.
The library used is Really Easy Field Validation and that page does explain how to extend it. I guess you will need something like this:
Validation.add('address', 'Error message text', {
pattern : /\b([P|p](OST|ost)?\.?\s?[O|o|0](ffice|FFICE)?\.?\s)?([B|b][O|o|0][X|x])\s(\d+)/
});
As a brief look into it without debugging the checkout
# Unfortunately Magento 1.3.2.3 - Find real postcode from debugging checkout
public function saveShippingAction()
{
$this->_expireAjax();
if ($this->getRequest()->isPost()) {
$data = $this->getRequest()->getPost('shipping', array());
$customerAddressId = $this->getRequest()->getPost('shipping_address_id', false);
$result = $this->getOnepage()->saveShipping($data, $customerAddressId);
$preg_search = '\b([P|p](OST|ost)?\.?\s?[O|o|0](ffice|FFICE)?\.?\s)?([B|b][O|o|0][X|x])\s(\d+)';
$address = $this->getQuote()->getShippingAddress(); #find real postcode
if(preg_match($preg_search, $address['postcode']){
$result = array(
'error' => 1,
'message' => Mage::helper('checkout')->__('Invalid PO Box postcode');
);
}
else{
if (!isset($result['error'])) {
$result['goto_section'] = 'shipping_method';
$result['update_section'] = array(
'name' => 'shipping-method',
'html' => $this->_getShippingMethodsHtml()
);
}
}
$this->getResponse()->setBody(Zend_Json::encode($result));
}
}
I'm building an admin utility for adding a bulk of images to an app I'm working on. I also need to to log certain properties that are associated with the images and then store it all into the database.
So basically the script looks into a folder, compares the contents of the folder to records in the database. All of the info must be entered in order for the database record to be complete, hence the form validation.
The validation is working, when there are no values entered it prompts the entry of the missing fields. However it happens even when the fields ARE filled.
I'm doing something a bit funny which may be the reason.
Because I'm adding a bulk of images I'm creating the data within a for loop and adding the validation rules within the same for loop.
Here is the results:
http://s75151.gridserver.com/CI_staging/index.php/admin_panel/bulk_emo_update
Right now I have default test values in the form while testing validation. The submit button is way at the bottom. I'm printing POST variable for testing purposes.
Here is the code:
function bulk_emo_update() {
$img_folder_location = 'img/moodtracker/emos/';//set an image path
$emo_files = $this->mood_model->get_emo_images('*.{png,jpg,jpeg,gif}', $img_folder_location); //grab files from folder
$emo_records = $this->mood_model->get_all_emos(); //grab records from db
$i=1; //sets a counter to be referenced in the form
$temp_emo_info = array(); //temp vairable for holding emo data that will be sent to the form
//loop through all the files in the designated folder
foreach($emo_files as $file) {
$file_path = $img_folder_location.$file;//builds the path out of the flder location and the file name
//loops through all the database reocrds for the pupose of checking to see if the image file is preasent in the record
foreach($emo_records as $record) {
//compairs file paths, if they are the
if($record->picture_url != $file_path) {
//FORM VALIDATION STUFF:
$rules['segment_radio['.$i.']'] = "required";
$rules['emo_name_text_feild['.$i.']'] = "required";
//populating the temp array which will be used to construct the form
$temp_emo_info[$i]['path'] = $file_path;
$temp_emo_info[$i]['name'] = $file;
}
}
$i++;
}
//sets the reference to validation rules
$this->validation->set_rules($rules);
//checks to see if the form has all it's required fields
if ($this->validation->run() == FALSE) { //if validation fails:
print_r($_POST);
//prepairs the data array to pass into the view to build the form
$data['title'] = 'Bulk Emo Update';
$data['intro_text'] = 'fill out all fields below. hit submit when finished';
$data['emos_info'] = $temp_emo_info;
$this->load->view('admin_bulk_emo_update_view',$data);
} else { // if it succeeds:
//printing for test purposes
print_r($_POST);
$this->load->view('form_result');
}
}
I'm new to codeigniter and php in general so if anything looks outrageously weird please tell me, don't worry about my feelings I've got thick skin.
if ($this->validation->run() == FALSE)
if you are calling the run() method of the validation class every time the script is run, will it ever return TRUE and run the else? Maybe a different return?
I'm a little cornfused by what's going on. Generally, if I'm having a problem like this, I will figure out a way to force the result I'm looking for. e.g. in your code, I'd force that else to run... once I get it to run, break down what happened to make it run. Rudimentary, but it has served me well.
You use array of rules in
$this->form_validation->set_rules()
wrong.
If you want to pass the rules in array you must stick to the key names like described here http://codeigniter.com/user_guide/libraries/form_validation.html#validationrulesasarray
So instead of
$rules['input_name'] = "required"
try this:
array(
'field' => 'input_name',
'label' => 'Name that you output in error message',
'rules' => 'required'
)