Author Topic: Adding "select" options to simple attributes drop down list  (Read 8984 times)

q-styler

  • Beginner
  • *
  • Posts: 22
Adding "select" options to simple attributes drop down list
« on: March 14, 2009, 18:12:39 pm »
Hi! One of my clients was adding "please select" as one of the options manually to the list of attributes. And he wanted virtuemart to notify if the attribute's option was not selected.

So i've done this.

First of all I added "please select" option to every drop down list for simple attributes.
We're going to the file 'ps_product_attribute.php' (in the classes folder).
Search for the function list_advanced_attribute of the class ps_product_attribute.
And adding these lines:
Code: [Select]
$options_item['base_var'] = '';
$options_item['base_value'] = $VM_LANG->_( 'PHPSHOP_SELECT' );

// before this:
$options_list[] = $options_item ;
// and then goes foreach section when all other attribute's values are added

And don't forget to list $VM_LANG in the declaration of global variables of the function list_advanced_attribute.

But that's not all.
I was a little happy when I figured out that virtuemart checks if attribute's value was empty. But then it appeared that  it returnes true if at least one of the attributes was filled. I needed virtuemart to warn if any of attributes were left empty.
For this i went to cartGetAttributes function of that class and made this:
Code: [Select]
$attribute_given =  false;changed to
Code: [Select]
$attribute_given =  (count($attributes) > 0 ) ;
and this:
Code: [Select]
if( ! empty( $d[$pagevar] ) ) {
  $attribute_given = true ;
}

to this:
Code: [Select]
$attribute_given = ($attribute_given && (!empty( $d[$pagevar] ))) ;


This works in ajax and non-ajax modes both.
That's it. Seems easy from the first sight, doesn't it?
Thank you for watching.

arczi866

  • Beginner
  • *
  • Posts: 12
Re: Adding "select" options to simple attributes drop down list
« Reply #1 on: March 17, 2009, 17:34:07 pm »
I did everything as written, and writes a message.
Code: [Select]
Fatal error: Call to a member function _() on a non-object in E:\xampp\htdocs\administrator\components\com_virtuemart\classes\ps_product_attribute.php on line 772
I do not know what to do next. Please help.

q-styler

  • Beginner
  • *
  • Posts: 22
Re: Adding "select" options to simple attributes drop down list
« Reply #2 on: March 17, 2009, 18:53:40 pm »
What's the code on line 772 in your case?

arczi866

  • Beginner
  • *
  • Posts: 12
Re: Adding "select" options to simple attributes drop down list
« Reply #3 on: March 18, 2009, 14:12:02 pm »
Code: [Select]
} else {
$base_var = str_replace( " ", "_", $base_value ) ;
$options_item['base_var'] = '';
$options_item['base_value'] = $VM_LANG->_( 'PHPSHOP_SELECT' );
}
$options_list[] = $options_item ;
}

q-styler

  • Beginner
  • *
  • Posts: 22
Re: Adding "select" options to simple attributes drop down list
« Reply #4 on: March 18, 2009, 14:18:50 pm »
Oh yeah sorry for that.
Just list $VM_LANG in the declaration of global variables.

arczi866

  • Beginner
  • *
  • Posts: 12
Re: Adding "select" options to simple attributes drop down list
« Reply #5 on: March 18, 2009, 14:25:11 pm »
What you need to do now is to work well?

q-styler

  • Beginner
  • *
  • Posts: 22
Re: Adding "select" options to simple attributes drop down list
« Reply #6 on: March 18, 2009, 14:28:12 pm »
Code: [Select]
function list_advanced_attribute( $product_id, $prod_id = null ) {
global $CURRENCY_DISPLAY, $VM_LANG;


arczi866

  • Beginner
  • *
  • Posts: 12
Re: Adding "select" options to simple attributes drop down list
« Reply #7 on: March 18, 2009, 14:47:09 pm »
It is a further problem. When properties are added to the price and type a zero to me shows you the words "Select". And I want to show the name without the normal price.
If the invisible I mean what can I do a few photos.

shafee85

  • Beginner
  • *
  • Posts: 10
Re: Adding "select" options to simple attributes drop down list
« Reply #8 on: November 22, 2009, 12:45:37 pm »
I am having problems getting this to work too. If someone can shed some light as to how I can fix this it would be really really helpful.

depika

  • Beginner
  • *
  • Posts: 46
Re: Adding "select" options to simple attributes drop down list
« Reply #9 on: May 24, 2010, 13:43:32 pm »
In case someone else faces the same problem with the word Select appearing in every dropdown selection here is the solution:

In line 1475 before
Code: [Select]
foreach( $fields as $field ) {
add this
Code: [Select]
$stack = array( ) ;
$stack[0] = array('base_var'=>'', 'base_value'=>$VM_LANG->_( 'PHPSHOP_SELECT' ));

In line around 1568 replace
Code: [Select]
$options_list[] = $options_item ;

with
Code: [Select]
array_push($stack, $options_item);


In line 1575 replace
Code: [Select]
$attributes[$i]['options_list'] = $options_list[];
with
Code: [Select]
$attributes[$i]['options_list'] = $stack ;
Now the word select appears only in the first option.