Do you know of a way how to check if current_url() is equivalent to a link's href without using javascript? In doing so, if the href is the same then add class="active" to the link.
Edit: The first thing which comes to mind is making an array of all href values then using foreach to compare each one but maybe you have a better way than this?
Answer thanks to Nick Pyett:
if(!function_exists('anchor')){
function anchor($uri = '', $title = '', $attributes = '', $apply_active = FALSE){
if(!is_array($uri)){
$site_url = (!preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri;
}
else {
$site_url = site_url($uri);
}
$title = (bool)$title ? $title : $site_url;
if($attributes != '') $attributes = _parse_attributes($attributes);
$active = $uri == uri_string() && $apply_active ? ' class="'.$apply_active.'"' : NULL;
return '<a href="'.$site_url.'"'.$attributes.$active.'>'.$title.'</a>';
}
}
You could extend the anchor function in the URL helper like this.
if ( ! function_exists('anchor'))
{
function anchor($uri = '', $title = '', $attributes = '', $apply_active = FALSE)
{
$title = (string) $title;
if ( ! is_array($uri))
{
$site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri;
}
else
{
$site_url = site_url($uri);
}
if ($title == '')
{
$title = $site_url;
}
if ($attributes != '')
{
$attributes = _parse_attributes($attributes);
}
if ( $uri == uri_string() AND $apply_active )
{
$active = ' class="'.$apply_active.'"';
}
else $active = NULL;
return '<a href="'.$site_url.'"'.$attributes.$active.'>'.$title.'</a>';
}
}
I haven't tested this so check a look for bugs. Call the anchor function like this:
anchor('my_page', 'My Page', '', 'active');
See the docs for how to extend helpers: http://ellislab.com/codeigniter/user_guide/general/helpers.html
Edit: OK I've tested it and updated my answer so it should work well now.
Related
I am trying to get value of meta key from table called site.management
this table
=>http://www.mediafire.com/file/pa4gs0pbwpoalqj/Homemetakey.PNG/file
public function index()
{
if (Schema::hasTable('site_managements')) {
$homepage = SiteManagement::getMetaValue('homepage');
if (!empty($homepage['home'])) {
$sections = Helper::getPageSections();
$selected_page = Page::find($homepage['home']);
$page_data = $selected_page->toArray();
$page = array();
$home = true;
$page['id'] = $page_data['id'];
$page['title'] = $page_data['title'];
$page['slug'] = $page_data['slug'];
$page['section_list'] = !empty($page_data['sections']) ? Helper::getUnserializeData($page_data['sections']) : array();
$description = $page_data['body'];
$page_meta = SiteManagement::where('meta_key', 'seo-desc-' . $homepage['home'])->select('meta_value')->pluck('meta_value')->first();
$page_banner = SiteManagement::where('meta_key', 'page-banner-' . $homepage['home'])->select('meta_value')->pluck('meta_value')->first();
$show_banner = SiteManagement::where('meta_key', 'show-banner-' . $homepage['home'])->select('meta_value')->pluck('meta_value')->first();
$breadcrumbs_settings = SiteManagement::getMetaValue('show_breadcrumb');
$show_breadcrumbs = !empty($breadcrumbs_settings) ? $breadcrumbs_settings : 'true';
$show_banner_image = false;
if ($show_banner == false) {
$show_banner_image = false;
} else {
$show_banner_image = true;
}
$banner = !empty($page_banner) ? Helper::getBannerImage('uploads/pages/' . $page_banner) : 'images/bannerimg/img-02.jpg';
$meta_desc = !empty($page_meta) ? $page_meta : '';
$type = Helper::getAccessType() == 'services' ? 'service' : Helper::getAccessType();
$slider_section = '';
$slider_style = '';
$slider_order = '';
foreach ($selected_page->meta->toArray() as $key => $meta) {
preg_match_all('!\d+!', $meta['meta_key'], $matches);
$meta_key_modify = preg_replace('/\d/', '', $meta['meta_key']);
if ($meta_key_modify == 'sliders') {
$slider_section = Helper::getUnserializeData($meta['meta_value']);
$slider_style = !empty($slider_section['style']) ? $slider_section['style'] : '';
$slider_order = !empty($slider_section['parentIndex']) ? $slider_section['parentIndex'] : '';
}
}
$categories = Category::latest()->get()->take(8);
$skills = Skill::latest()->get()->take(8);
$locations = Location::latest()->get()->take(8);
$languages = Language::latest()->get()->take(8);
$page_header = '';
$currency = SiteManagement::getMetaValue('commision');
$symbol = !empty($currency) && !empty($currency[0]['currency']) ? Helper::currencyList($currency[0]['currency']) : array();
if (file_exists(resource_path('views/extend/front-end/pages/show.blade.php'))) {
return View::make(
'extend.front-end.pages.show',
compact(
'symbol',
'page_header',
'page',
'meta_desc',
'banner',
'show_banner',
'show_banner_image',
'show_breadcrumbs',
'selected_page',
'sections',
'type',
'slider_style',
'slider_section',
'description',
'slider_order',
'home',
'categories',
'skills',
'locations',
'languages'
)
);
} else {
return View::make(
'front-end.pages.show',
compact(
'symbol',
'page_header',
'page',
'meta_desc',
'banner',
'show_banner',
'show_banner_image',
'show_breadcrumbs',
'selected_page',
'sections',
'type',
'slider_style',
'slider_section',
'description',
'slider_order',
'home',
'categories',
'skills',
'locations',
'languages'
)
);
}
} else {
if (file_exists(resource_path('views/extend/front-end/index.blade.php'))) {
return view('extend.front-end.index');
} else {
return view('front-end.index');
}
}
}
}
and am getting this error
Call to a member function toArray() on null
every thing was working fine but an interruption happened in my DB and I resorted it but home index after login gives me the mentioned error
Call to a member function toArray() on null
*(the project on laravel 5) *
what is the problem here?
I have written a code in the controller which is given below. This code is for login page. In this code, the if statement notification is properly working but the else part is not working. It is not redirect to the url given in the redirect() instead it is showing a blank page. Can anyone tell y it is like that and correct it for me ? I have used header() function but also it is not working.I have placed all the code inside the 'kw' folder. This code is properly working in the localhost but when uploaded the same code to the live server, its not working.Is it due to version of the CI ?
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Login extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->library('session');
$this->load->library('validation');
$this->load->model('studentsmodel');
}
public function index() {
if (isset($_POST['submit']))
{
$post_data = array('stud_cin' => $this->input->post('stud_cin'),'stud_password' => $this->input->post('stud_password'),
);
$this->validation->set_data($post_data);
$this->validation->set_rules('stud_cin','Cin','required|trim');
$this->validation->set_rules('stud_password','Password','required|trim');
if ($this->validation->run() === FALSE)
{
}
else
{
$this->load->model("studentsmodel");
$this->load->helper('url');
$result = $this->studentsmodel->loginCheck($post_data);
if (!$result){
$this->notifications->notify('Wrong username/password; Login Failed','error');
}
else{
$this->session->set_userdata('student_id', $result['id']);
$this->session->set_userdata('stud_cin', $result['stud_cin']);
$this->session->set_userdata('stud_photopath', $result['stud_photopath']);
redirect('student/profile/edit/id/'.$this->session->userdata('student_id'),'refresh');
//header('location:http://www.website.com/kw/application/controller/student/profile/edit/id/$this->session->userdata("student_id")');
}
}
} $this->load->view("login");
}
}
profile controller edit function
public function index()
{
$student_id=$this->session->userdata('student_id');
$data['profile_data'] =$this->studentsmodel->get_Cinprofile($student_id);
$this->load->view("profileDetails.php", $data);
}
public function edit()
{
$uri = $this->uri->uri_to_assoc(4);
$student_id=$uri['id'];
if(isset($_POST['btn_submit']))
{
//echo "<pre>";print_r($_FILES);exit;
$img_val = $this->studentsmodel->getStudent_photo($student_id);
$photo_val = $img_val['stud_photopath'];
$photo_unlink = "";
if ($_FILES['stud_photopath']['name'] != "")
{
/*echo "in";exit;*/
$photo_chk = explode("photo/", $photo_val);
$photo_unlink = $photo_chk[1];
$photo_path = "";
$flag = "";
$f_type_chk = $_FILES['stud_photopath']['type'];
if ($f_type_chk != "image/gif" && $f_type_chk != "image/jpg" && $f_type_chk != "image/jpeg"
&& $f_type_chk != "image/bmp" && $f_type_chk != "image/png" && $f_type_chk != "")
{
$flag = "Select allowed file type and size for photo";
}
if ($_FILES['stud_photopath']['size'] >= 5242880) { $flag = "Select allowed file type and size for photo"; }
$target_path = getcwd() . "/public/photo/";
$db_path = "photo/";
if ($_FILES['stud_photopath']['name'] != '')
{
$file_name = $_FILES["stud_photopath"]["name"];
$file_size = $_FILES["stud_photopath"]["size"] / 1024;
$file_type = $_FILES["stud_photopath"]["type"];
$file_tmp_name = $_FILES["stud_photopath"]["tmp_name"];
$random = rand(111, 999);
$new_file_name = $random . $file_name;
$newfile_name=$cin."_". $file_name;
$upload_path = $target_path . $newfile_name;;
if (move_uploaded_file($file_tmp_name, $upload_path)) { $photo_path = addslashes($db_path . $newfile_name); } /*end if*/
else { $this->notifications->notify('Photo cannot upload', 'error'); }/*end else var_dump($this->validation->show_errors());*/
}/*end if $_FILES['photo']['name']*/
} /*END OF if ($_FILES['photo']['name'] != "") */
else { $photo_path = $photo_val; } /*END OF ELSE ($_FILES['photo']['name'] != "") */
$this->session->unset_userdata('stud_photopath');
$this->session->set_userdata('stud_photopath', $photo_path);
$data['photo_unlink'] = $photo_unlink;
/* echo $dob_dd = $this->input->post('dob_dd');exit;
$dob_mm = $this->input->post('dob_mm');
$dob_yy = $this->input->post('dob_yy');
$dob = $dob_dd . "-" . $dob_mm . "-" . $dob_yy;*/
$stud_age_dob =$this->input->post('stud_age_dob');
$timestamp = strtotime($stud_age_dob);
$dob = date('Y-m-d', $timestamp);
$validation_data = array(
'stud_name' => $this->input->post('stud_name'),
'stud_gender' => $this->input->post('stud_gender'),
'stud_age_dob' =>$this->input->post('stud_age_dob'),
'stud_mobile' => $this->input->post('stud_mobile'),
'stud_email' => $this->input->post('stud_email'),
);
//echo "<pre>";print_r($validation_data); exit;
$this->validation->set_data($validation_data);
$this->validation->set_rules('stud_name', 'Student Name', 'trim|alpha_space|required');
$this->validation->set_rules('stud_gender', 'Gender', 'required');
$this->validation->set_rules('stud_age_dob', 'DOB', 'required');
$this->validation->set_rules('stud_mobile', 'Mobile number', 'numeric|required');
$this->validation->set_rules('stud_email', 'Email Id', 'trim|required|valid_email|xss_clean');
if ($this->validation->run() === FALSE)
{ /* var_dump($this->validation->show_errors()); */ $this->notifications->notify('Please make all entries', 'error');}
else
{
$updation_data=array(
'stud_name' => $this->input->post('stud_name'),
'stud_gender' => $this->input->post('stud_gender'),
'stud_age_dob' => $this->input->post('stud_age_dob'),
'stud_gaurdian' =>$this->input->post('stud_gaurdian'),
'stud_mother' =>$this->input->post('stud_mother'),
'stud_mobile' => $this->input->post('stud_mobile'),
'stud_email' => $this->input->post('stud_email'),
'stud_tel' => $this->input->post('stud_tel'),
'stud_guardian_address' => $this->input->post('stud_guardian_address'),
'stud_pin' => $this->input->post('stud_pin'),
'stud_photopath' => $photo_path,
'stud_age_dob' => $dob
);
/*echo "<pre>";print_r($updation_data); exit; */
$update_status=$this->studentsmodel->update_profile($updation_data, $student_id);
if($update_status==1)
{
//$this->session->set_userdata('profile_status', 'Yes');
/*$this->session->userdata('profile_status');*/
redirect('student/profile/index/', 'refresh');
}
else
{
$this->notifications->notify('profile updted failed', 'error');
}
$data['profile_data']=$_POST;
}
$data['profile_data']=$_POST;
}
$data['profile_data']=$this->studentsmodel->get_Cinprofile($student_id);
$this->load->view("profile_edit.php",$data);
}
Check if you already load this helper
$this->load->helper('url');
This is the information about the redirect function
redirect($uri = '', $method = 'auto', $code = NULL);
Parameters:
$uri (string) URI string $method (string)
Redirect method (‘auto’,
‘location’ or ‘refresh’)
$code (string) HTTP Response code (usually 302 or 303)
Note:
Don't forget add in the config file the value for base_uri
https://www.codeigniter.com/user_guide/helpers/url_helper.html
https://www.codeigniter.com/userguide3/libraries/config.html
remove /id/ from your redirect()
redirect('student/profile/edit/'.$this->session->userdata('student_id'));
I have no problem with using i18n in mydomain.com/en/controller
My problem begin if I used something like mydomain/foldername/en/controller
when I switch language it's coming like mydomain/foldername/en/ar/controller
as ar is the other language
my base_url is mydomain/foldername/
I believe that it coming from one index and i tried to change it in MY_LANG:
// Originaly CodeIgniter i18n library by Jérome Jaglale
// http://maestric.com/en/doc/php/codeigniter_i18n
//modified by Tobin Thomas
class MY_Lang extends CI_Lang {
/**************************************************
configuration
***************************************************/
// Add your languages here
private $languages = array(
'en' => 'english',
'ar' => 'arabic'
);
// special URIs (not localized)
private $special = array (
'admin',
'assets',
'editor'
);
// where to redirect if no language in URI
private $uri;
private $default_uri;
private $lang_code;
/**************************************************/
function MY_Lang()
{
parent::__construct();
global $CFG;
global $URI;
global $RTR;
$this->uri = $URI->uri_string();
$this->default_uri = $RTR->default_controller;
$uri_segment = $this->get_uri_lang($this->uri);
$this->lang_code = $uri_segment['lang'] ;
$url_ok = false;
if ((!empty($this->lang_code)) && (array_key_exists($this->lang_code, $this->languages)))
{
$language = $this->languages[$this->lang_code];
$CFG->set_item('language', $language);
$url_ok = true;
}
if ((!$url_ok) && (!$this->is_special($uri_segment['parts'][0]))) // special URI -> no redirect
{
// set default language
$CFG->set_item('language', $this->languages[$this->default_lang()]);
$uri = (!empty($this->uri)) ? $this->uri: $this->default_uri;
$uri = ($uri[0] != '/') ? '/'.$uri : $uri;
$new_url = $CFG->config['base_url'].$this->default_lang().$uri;
header("Location: " . $new_url, TRUE, 302);
exit;
}
}
// get current language
// ex: return 'en' if language in CI config is 'english'
function lang()
{
global $CFG;
$language = $CFG->item('language');
$lang = array_search($language, $this->languages);
if ($lang)
{
return $lang;
}
return NULL; // this should not happen
}
function is_special($lang_code)
{
if ((!empty($lang_code)) && (in_array($lang_code, $this->special)))
return TRUE;
else
return FALSE;
}
function switch_uri($lang)
{
if ((!empty($this->uri)) && (array_key_exists($lang, $this->languages)))
{
if ($uri_segment = $this->get_uri_lang($this->uri))
{
$uri_segment['parts'][0] = $lang;
$uri = implode('/',$uri_segment['parts']);
}
else
{
$uri = $lang.'/'.$this->uri;
}
}
return $uri;
}
//check if the language exists
//when true returns an array with lang abbreviation + rest
function get_uri_lang($uri = '')
{
if (!empty($uri))
{
$uri = ($uri[0] == '/') ? substr($uri, 0): $uri;
$uri_expl = explode('/', $uri, 2);
$uri_segment['lang'] = NULL;
$uri_segment['parts'] = $uri_expl;
if (array_key_exists($uri_expl[0], $this->languages))
{
$uri_segment['lang'] = $uri_expl[0];
}
return $uri_segment;
}
else
return FALSE;
}
// default language: first element of $this->languages
function default_lang()
{
$browser_lang = !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? strtok(strip_tags($_SERVER['HTTP_ACCEPT_LANGUAGE']), ',') : '';
$browser_lang = substr($browser_lang, 0,2);
return (!empty($browser_lang) && array_key_exists($browser_lang, $this->languages)) ? $browser_lang: 'en';
}
// add language segment to $uri (if appropriate)
function localized($uri)
{
if (!empty($uri))
{
$uri_segment = $this->get_uri_lang($uri);
if (!$uri_segment['lang'])
{
if ((!$this->is_special($uri_segment['parts'][0])) && (!preg_match('/(.+)\.[a-zA-Z0-9]{2,4}$/', $uri)))
{
$uri = $this->lang() . '/' . $uri;
}
}
}
return $uri;
}
}
// END MY_Lang Class
/* End of file MY_Lang.php */
/* Location: ./application/core/MY_Lang.php */
ANY IDEA?
i was facing the same behavior. The problem was not in MY_Lang. It was the call of $this->lang->switch_uri('lang') in the view. I do not used codeigniter functions like anchor, site_url to generate the right link. I used plain html. Small mistake, minutes/hours of code review.
<a href="<?php echo $this->lang->switch_uri('en'); ?>"><img ...
won't work. It adds lang segment twice to uri, instead use anchor or site_url
<a href="<?php echo site_url($this->lang->switch_uri('en')); ?>"><img ...
I'm new to Magento. We've created a custom option. But whenever we choose "radial" it always displays a "None" option that we need to remove. I from what I understand this is pulling in some code from Magento Core.
This is the HTML that I need to edit:
<dt><label>Add a Display Case:</label></dt>
<dd class="last">
<div class="input-box">
<ul id="options-7-list" class="options-list"><li><input type="radio" id="options_7" class="radio product-custom-option" name="options[7]" onclick="opConfig.reloadPrice()" value="" checked="checked" /><span class="label"><label for="options_7">None</label></span></li><li><input type="radio" class="radio product-custom-option" onclick="opConfig.reloadPrice()" name="options[7]" id="options_7_2" value="19" price="45" /><span class="label"><label for="options_7_2">Acrylic Cube <span class="price-notice">+<span class="price">$45.00</span></span></label></span></li><li><input type="radio" class="radio product-custom-option" onclick="opConfig.reloadPrice()" name="options[7]" id="options_7_3" value="20" price="75" /><span class="label"><label for="options_7_3">Lucite Case <span class="price-notice">+<span class="price">$75.00</span></span></label></span></li></ul> </div>
</dd>
This is where I think it outputs....
<?php
class OptionExtended_Block_Product_View_Js extends Mage_Catalog_Block_Product_View_Options
{
protected $config = array();
protected $thumbnailDirUrl = '';
protected $pickerImageDirUrl = '';
protected function _construct()
{
$children = array();
$sd = array();
$configValues = array();
$inPreConfigured = $this->getProduct()->hasPreconfiguredValues();
$storeId = Mage::app()->getStore()->getId();
$product_id = $this->getProduct()->getId();
$filter = Mage::getModel('core/email_template_filter');
$options = $this->getProduct()->getOptions();
foreach ($options as $option){
if (!is_null($option->getLayout())){
$id = (int) $option->getOptionId();
if (!is_null($option->getRowId()))
$option_id_by_row_id[$option->getTemplateId()][(int) $option->getRowId()] = $id;
$this->config[0][$id][0] = $option->getNote() != '' ? $filter->filter($option->getNote()) : '';
$this->config[0][$id][1] = $option->getLayout();
$this->config[0][$id][2] = (int) $option->getPopup();
if ($inPreConfigured){
$configValues[$id] = array();
if (is_null($option->getRowId())){
$configValue = $this->getProduct()->getPreconfiguredValues()->getData('options/' . $id);
if (!is_null($configValue))
$configValues[$id] = (array) $configValue;
}
} else {
$sd[$option->getTemplateId()][$id] = explode(',', $option->getSelectedByDefault());
}
if (!is_null($option->getValues())){
foreach ($option->getValues() as $value) {
$valueId = (int) $value->getOptionTypeId();
$this->prepareImages($value->getImage());
$rowId = (int) $value->getRowId();
$valueId_by_row_id[$value->getTemplateId()][$rowId] = $valueId;
$children[$value->getTemplateId()][$valueId] = explode(',', $value->getChildren());
$this->config[1][$valueId][0] = $value->getImage();
$this->config[1][$valueId][1] = $value->getDescription() != '' ? $filter->filter($value->getDescription()) : '';
$this->config[1][$valueId][2] = array();
$this->config[1][$valueId][3] = array();
}
}
}
}
$options = Mage::getModel('optionextended/option')
->getCollection()
->joinNotes($storeId)
->addFieldToFilter('product_id', $product_id);
foreach ($options as $option){
$id = (int) $option->getOptionId();
if (!is_null($option->getRowId()))
$option_id_by_row_id['orig'][(int) $option->getRowId()] = $id;
$this->config[0][$id][0] = $option->getNote() != '' ? $filter->filter($option->getNote()) : '';
$this->config[0][$id][1] = $option->getLayout();
$this->config[0][$id][2] = (int) $option->getPopup();
if ($inPreConfigured){
$configValues[$id] = array();
if (is_null($option->getRowId())){
$configValue = $this->getProduct()->getPreconfiguredValues()->getData('options/' . $id);
if (!is_null($configValue))
$configValues[$id] = (array) $configValue;
}
} else {
$sd['orig'][$id] = explode(',', $option->getSelectedByDefault());
}
}
$values = Mage::getModel('optionextended/value')
->getCollection()
->joinDescriptions($storeId)
->addFieldToFilter('product_id', $product_id);
foreach ($values as $value) {
$valueId = (int) $value->getOptionTypeId();
$this->prepareImages($value->getImage());
$rowId = (int) $value->getRowId();
$valueId_by_row_id['orig'][$rowId] = $valueId;
$children['orig'][$valueId] = explode(',', $value->getChildren());
$this->config[1][$valueId][0] = $value->getImage();
$this->config[1][$valueId][1] = $value->getDescription() != '' ? $filter->filter($value->getDescription()) : '';
$this->config[1][$valueId][2] = array();
$this->config[1][$valueId][3] = array();
}
if ($inPreConfigured){
foreach ($configValues as $optionId => $v){
$this->config[0][$optionId][3] = array();
foreach($v as $valueId)
$this->config[0][$optionId][3][] = (int) $valueId;
}
} else {
foreach ($sd as $templateId => $v){
foreach ($v as $optionId => $vv){
$this->config[0][$optionId][3] = array();
foreach($vv as $rowId)
if ($rowId != '')
$this->config[0][$optionId][3][] = $valueId_by_row_id[$templateId][(int)$rowId];
}
}
}
foreach ($children as $templateId => $v){
foreach ($v as $valueId => $vv){
foreach ($vv as $rowId){
if ($rowId != ''){
if (isset($option_id_by_row_id[$templateId][(int)$rowId]))
$this->config[1][$valueId][2][] = $option_id_by_row_id[$templateId][(int)$rowId];
else
$this->config[1][$valueId][3][] = $valueId_by_row_id[$templateId][(int)$rowId];
}
}
}
}
}
public function getConfig()
{
return Zend_Json::encode($this->config);
}
public function prepareImages($image)
{
if ($image){
$thumbnailUrl = $this->makeThumbnail($image);
$pickerImageUrl = $this->makePickerImage($image);
if ($this->thumbnailDirUrl == ''){
$this->thumbnailDirUrl = str_replace($image, '', $thumbnailUrl);
$this->pickerImageDirUrl = str_replace($image, '', $pickerImageUrl);
}
}
}
public function makeThumbnail($image)
{
$thumbnailUrl = $this->helper('catalog/image')
->init($this->getProduct(), 'thumbnail', $image)
->keepFrame(true)
// Uncomment the following line to set Thumbnail RGB Background Color:
// ->backgroundColor(array(246,246,246))
// Set Thumbnail Size:
->resize(100,100)
->__toString();
return $thumbnailUrl;
}
public function makePickerImage($image)
{
$pickerImageUrl = $this->helper('catalog/image')
->init($this->getProduct(), 'thumbnail', $image)
->keepFrame(false)
->resize(30,30)
->__toString();
return $pickerImageUrl;
}
public function getThumbnailDirUrl()
{
return $this->thumbnailDirUrl;
}
public function getPickerImageDirUrl()
{
return $this->pickerImageDirUrl;
}
public function getPlaceholderUrl()
{
return Mage::getDesign()->getSkinUrl($this->helper('catalog/image')->init($this->getProduct(), 'small_image')->getPlaceholder());
}
public function getProductBaseMediaUrl()
{
return Mage::getSingleton('catalog/product_media_config')->getBaseMediaUrl();
}
public function getInPreconfigured()
{
return $this->getProduct()->hasPreconfiguredValues() ? 'true' : 'false';
}
}
I think you are doing something wrong.
From this picture you can see that you can add your options which are then displayed in the frontend. Only these options will be displayed!
You do not need to make any changes in the Magento Core code to fix your problem.
If you still have problems please provide us with some screenshots and URL to your Magento web shop if possible.
Are you using an extension such as SWMS Option Image or similar to add extras like images to your custom options? This extension adds the None option.
You will need to go into the community folder and select your extension and edit the default.php and change "None" to "Standard" or something similar.
For SWMS Option image I changed:
/community/Swms/Optionimage/Block/Product/View/Options/Type/Select.php
<label for="options_'.$_option->getId().'">' . $this->__('Standard') . '</label>
I've got another solution. Edit the csv file. Mage_Catalog.csv. Add a row for None and add the word Standard to the next column.
Issue was resolved by modifying the this file:
app/code/local/Mage/Catalog/Block/Product/View/Options/Type/Select.php
modified lines 102-106
<?php
switch ($_option->getType()) {
case Mage_Catalog_Model_Product_Option::OPTION_TYPE_RADIO:
$type = 'radio';
$class = 'radio';
if (!$_option->getIsRequire()) {
// $selectHtml .= '<li><input type="radio" id="options_'.$_option->getId().'" class="'.$class.' product-custom-option" name="options['.$_option->getId().']"' . ($this->getSkipJsReloadPrice() ? '' : ' onclick="opConfig.reloadPrice()"') . ' value="" checked="checked" /><span class="label"><label for="options_'.$_option->getId().'">' . $this->__('None') . '</label></span></li>';
}
break;
case Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX:
$type = 'checkbox';
$class = 'checkbox';
$arraySign = '[]';
break;
}
?>
I have the same issue, also what i have found if the field is not required magento will generate "None" option. Fast solution but not recommended is hide the option by css.
I currently have this set up to display my catalog images in a magento custom grid - I seem to be close but cannot seem to call the final image url to display- can anyone help me?
I have tried calling them from /media/remote/cache also but to no avail :-(
public function render(Varien_Object $row) {
$p = Mage::getModel('catalog/product')->load($row->getproduct_id());
$html = '<img src="' . Mage::getBaseUrl('media').'catalog/product/'.'" width="50" height="50" alt="' . $p->getname() . '" />';
return $html;
}
you have to create your custom render like below
just add this to your grid
$this->addColumn('thumbnail',
array(
'header'=> Mage::helper('catalog')->__('Thumbnail'),
'type' => 'image',
'width' => '100',
'index' => 'thumbnail',
'renderer' => 'NAMESPACE_YOURMODULE_Block_Widget_Grid_Column_Renderer_Image',
));
and create render class at
\NAMESPACE\YOURMODULE\Block\Widget\Grid\Column\Renderer\Image.php
and add below code to this files with proper class name
class NAMESPACE_YOURMODULE_Block_Widget_Grid_Column_Renderer_Image
extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
protected static $showImagesUrl = null;
protected static $showByDefault = null;
protected static $imagesWidth = null;
protected static $imagesHeight = null;
protected static $imagesScale = null;
public function render(Varien_Object $row)
{
return $this->_getValue($row);
}
protected static function initSettings()
{
if(!self::$showImagesUrl)
self::$showImagesUrl = (int)Mage::getStoreConfig('yourmodule/images/showurl') === 1;
if(!self::$showByDefault)
self::$showByDefault = (int)Mage::getStoreConfig('yourmodule/images/showbydefault') === 1;
if(!self::$imagesWidth)
self::$imagesWidth = Mage::getStoreConfig('yourmodule/images/width');
if(!self::$imagesHeight)
self::$imagesHeight = Mage::getStoreConfig('yourmodule/images/height');
if(!self::$imagesScale)
self::$imagesScale = Mage::getStoreConfig('yourmodule/images/scale');
}
protected function _getValue(Varien_Object $row)
{
self::initSettings();
$noSelection = false;
$dored = false;
if ($getter = $this->getColumn()->getGetter())
{
$val = $row->$getter();
}
$val = $val2 = $row->getData($this->getColumn()->getIndex());
$noSelection = ($val == 'no_selection' || $val == '') ? true : $noSelection;
$url = Mage::helper('yourmodule')->getImageUrl($val);
if(!Mage::helper('yourmodule')->getFileExists($val))
{
$dored = true;
$val .= "[*]";
}
$dored = (strpos($val, "placeholder/")) ? true : $dored;
$filename = (!self::$showImagesUrl) ? '' : substr($val2, strrpos($val2, "/")+1, strlen($val2)-strrpos($val2, "/")-1);
$val = ($dored) ?
("<span style=\"color:red\" id=\"img\">$filename</span>") :
"<span>". $filename ."</span>";
$out = (!$noSelection) ?
($val. '<center><a href="#" onclick="window.open(\''. $url .'\', \''. $val2 .'\')" title="'. $val2 .'" '. ' url="'.$url.'" id="imageurl">') :
'';
$outImagesWidth = self::$imagesWidth ? "width='".self::$imagesWidth."'":'';
if(self::$imagesScale)
$outImagesHeight = (self::$imagesHeight) ? "height='".self::$imagesHeight."'":'';
else
$outImagesHeight = (self::$imagesHeight && !self::$imagesWidth) ? "height='".self::$imagesHeight."'":'';
//return '<img src="'.(Mage::helper("catalog/image")->init($productItem, "small_image")->resize(self::$imagesWidth)).'" '.$outImagesWidth.' '.$outImagesHeight.' alt="" />';
$out .= (!$noSelection) ?
"<img src=".(Mage::helper("catalog/image")->init($row, $this->getColumn()->getIndex())->resize(self::$imagesWidth))." ".$outImagesWidth." ".$outImagesHeight." border=\"0\"/>" :
// "<img src=".$url." ".$outImagesWidth." ".$outImagesHeight." border=\"0\"/>" :
// "" :
"<center><strong>[".__('NO IMAGE')."]</strong></center>";
return $out. ((!$noSelection)? '</a></center>' : '');
}
hope this will sure help you.