Forums / Setting Up Categories, Products, Attributes / Direct price entry attribute?

Direct price entry attribute?

Locked
Results 1 to 20 of 20
This thread is locked. New replies are disabled.
17 Sep 2007, 20:04
#1
dhcernese avatar

dhcernese

Zen Follower

Join Date:
Mar 2007
Posts:
232
Plugin Contributions:
0

Direct price entry attribute?

Is there any way to have an attribute allow the direct entry of a monetary value?

Yea, I know, 'let the customers pick their own prices?' No, it's like a "donation".. ..they have to enter an amount and that gets added to the price. I tried pulldowns, but the list is too long and tedious to maintain.
09 Dec 2007, 03:13
#2
tj1 avatar

tj1

Totally Zenned

Join Date:
Mar 2005
Posts:
628
Plugin Contributions:
0

Re: Direct price entry attribute?

If you do find out, please let me know, I need this too.
19 Dec 2007, 18:44
#3
dhcernese avatar

dhcernese

Zen Follower

Join Date:
Mar 2007
Posts:
232
Plugin Contributions:
0

Re: Direct price entry attribute?

This would likely require a new PRODUCTS_OPTIONS_TYPE which are stored in the table of the same name and all the associated code to handle it.
01 Jan 2008, 02:33
#4
jaycode avatar

jaycode

Zen Follower

Join Date:
Jun 2007
Posts:
306
Plugin Contributions:
1

Re: Direct price entry attribute?

Well, I just recently made a module similar to this, yes you are right dhcernese I added a new PRODUCTS_OPTIONS_TYPE and PRODUCTS_OPTIONS_VALUE

and um... I guess it is slightly better than what you had in mind, I use sliders :D

Check this out:
http://www.webextremecustomiser.com/index.php?main_page=product_info&cPath=1&products_id=1

But I got one problem though:

This module changed 3 core files, attribute.php and both header_php.php files in checkout_confirmations and shopping_cart pages. I still cannot find a workaround to this, do you think that is fine?

Not sure if it's working?

Try to make an actual donation with it ;)
01 Jan 2008, 14:16
#5
dhcernese avatar

dhcernese

Zen Follower

Join Date:
Mar 2007
Posts:
232
Plugin Contributions:
0

Re: Direct price entry attribute?

More experienced Zenners could better comment on the structure of your modifications. However, I believe you cannot make this change without modifying several core files-- and if you do, they should use the override system (perhaps in your template subdirectories!).

I'm surprised it's only 3 files.. ..I started down this path and found myself modifying more. I started by creating custom defines in my own files, to support a type of "monetary".

Going down this path one notices that there are then three exceptions to most of the code, _FILE, _TEXT, and now this new one. Hints at some refactoring required to more directly support a base type that does not come with a set of specified values.

Dan
p.s. your slider is interesting. it did not slide in real-time response to my mouse only moved after releasing, however. is it supposed to follow the mouse?
03 Jan 2008, 11:08
#6
jaycode avatar

jaycode

Zen Follower

Join Date:
Jun 2007
Posts:
306
Plugin Contributions:
1

Re: Direct price entry attribute?

dhcernese:

More experienced Zenners could better comment on the structure of your modifications. However, I believe you cannot make this change without modifying several core files-- and if you do, they should use the override system (perhaps in your template subdirectories!).

I'm surprised it's only 3 files.. ..I started down this path and found myself modifying more. I started by creating custom defines in my own files, to support a type of "monetary".


Well I cheated a bit, to tell you the truth, For example for the classes/shopping_cart.php I did actually changed that file but instead of directly changing it there, I made my changes to a new file sliderview_donation_shopping_cart.class.php and pointed Zen-Cart to load that class instead of shopping_cart.php.

One thing I'd like to see Zen-Cart would be able to handle is the ability for developers to add new attribute types. One way to help this is by dividing the includes/modules/attributes.php into several auto-loaded files. But looks like they got more important issues to resolve than this eh?

dhcernese:

Going down this path one notices that there are then three exceptions to most of the code, _FILE, _TEXT, and now this new one. Hints at some refactoring required to more directly support a base type that does not come with a set of specified values.


Exactly, looks like you went to the right direction here.

dhcernese:


p.s. your slider is interesting. it did not slide in real-time response to my mouse only moved after releasing, however. is it supposed to follow the mouse?


Ah yes you are right, looks like the changing of bubble talk content caused memory leak in IE, it was perfect in Mozilla, as usual. I have changed that, the content is now changing only after the handler set to a position. Thanks for letting me know.
16 Jan 2008, 02:44
#7
tj1 avatar

tj1

Totally Zenned

Join Date:
Mar 2005
Posts:
628
Plugin Contributions:
0

Re: Direct price entry attribute?

Hi jaycode, have you released this as a contribution or is it available for purchase somewhere?

I don't need anything fancy like you have with the slider. I actually did want it to let customers choose their price and also to use as a general payment product.
16 Jan 2008, 05:11
#8
jaycode avatar

jaycode

Zen Follower

Join Date:
Jun 2007
Posts:
306
Plugin Contributions:
1

Re: Direct price entry attribute?

Hi tj1, yes I plan to make this as a contribution someday later, I just switched to Mootools from Scriptaculous, so I need to re-write all my existing code, which is crazy...

Plus, the exams are coming. At current rate, I think I can start working on it by March, sorry :( I hope you do not need the module ready soon?
09 Jun 2008, 21:18
#9
tj1 avatar

tj1

Totally Zenned

Join Date:
Mar 2005
Posts:
628
Plugin Contributions:
0

Re: Direct price entry attribute?

Hi, just checking again to see if you've already made a contribution of this.

Thanks.
10 Jun 2008, 08:53
#10
jaycode avatar

jaycode

Zen Follower

Join Date:
Jun 2007
Posts:
306
Plugin Contributions:
1

Re: Direct price entry attribute?

tj1:

Hi, just checking again to see if you've already made a contribution of this.

Thanks.


Nope I haven't, been very busy to deal with contributions these days. I can give you the module with slider still attached and you can remove them yourself if you want?
10 Jun 2008, 09:10
#11
steven300 avatar

steven300

Totally Zenned

Join Date:
Jan 2008
Posts:
1,564
Plugin Contributions:
0

Re: Direct price entry attribute?

I'm also interested in the slider function and letting the customer choose their price.
10 Jun 2008, 15:13
#12
teeb avatar

teeb

New Zenner

Join Date:
Mar 2008
Posts:
21
Plugin Contributions:
0

Re: Direct price entry attribute?

Ditto for me.

Need a way for customers to submit offers on products. Don't need the slider, but just getting to see what you've changed would be immensely helpful to me figuring it out myself.
11 Jun 2008, 08:37
#13
car86l avatar

car86l

New Zenner

Join Date:
Jun 2008
Posts:
18
Plugin Contributions:
0

Re: Direct price entry attribute?

I too am very interested in this option

i sell custom gift hampers and need the customer to be able to specify what price they want to spend up to.

I like the slider option too, so dont mind if its still got that.
20 Jun 2008, 15:12
#14
teeb avatar

teeb

New Zenner

Join Date:
Mar 2008
Posts:
21
Plugin Contributions:
0

Re: Direct price entry attribute?

Ok...

So I scraped something together to make this work... Kinda.

This isn't exactly perfect, as it relies on customer input in a text field, and currently I'm not filtering the values down to numerical only. Hopefully I"ll have time to work that part out next week.


I had to edit /includes/classes/shopping_cart.php


I had to add things to two areas of the file. If anyone looks at this and knows of ways to tweak it to make it work better, by all means, let me know! I knew nothing at all about the actual PHP coding language as of about a month ago, and didn't ACTUALLY dig into it until I started trying to figure this out a week and a half ago. I'm sure it's fairly hackish, but it gets the job done. I'd love to make it cleaner if possible though.

I've been tweaking the file, so the line numbers might not be exactly standard anymore...


Note, the 4 in
$attribute_price->fields['options_id'] == 4


Is the options_id value that goes with the option name you're using. So if your have an option name called "Donation Amount", check the option ID for that option, and use that number in those locations. That should be the only variable thing in this code... iirc.


But right around line 700:

I changed this
// bottom total
          //            if ($attribute_price->fields['product_attribute_is_free']) {
          if ($attribute_price->fields['product_attribute_is_free'] == '1' and zen_get_products_price_is_free((int)$prid)) {
            // no charge for attribute            
          } else {
            // + or blank adds






To this


// bottom total
          //            if ($attribute_price->fields['product_attribute_is_free']) {
          if ($attribute_price->fields['product_attribute_is_free'] == '1' and zen_get_products_price_is_free((int)$prid)) {
            // no charge for attribute
            
          	
          } elseif ($attribute_price->fields['options_id'] == 4) {
            $attr_value = $this->contents[$products_id]['attributes_values'][$option];
            $this->total += $qty * ($attr_value - $products_price);
                           
           } else {
            // + or blank adds




That edits the total at the bottom of the page, but not the price/total on each line for the items.

To do that, I had to tweak the attributes function, and the SQL query at the beginning of it.



Around line 850 or so (I added big multi-line /////////comment flags///////) around my stuff, to mark it clearly for myself, so my lines might be off a bit.. But around 850, I added the products table to the query, so I can call the product price variable.

The query statement now looks like this (added 3rd and 4th line, tweaked 5th from where to and):

        $attribute_price_query = "select *
                                    from " . TABLE_PRODUCTS_ATTRIBUTES . "
                                    inner join " . TABLE_PRODUCTS . "
                                    where " . TABLE_PRODUCTS . ".products_id = " . TABLE_PRODUCTS_ATTRIBUTES . ".products_id
                                    and " . TABLE_PRODUCTS_ATTRIBUTES . ".products_id = '" . (int)$products_id . "'
                                    and " . TABLE_PRODUCTS_ATTRIBUTES . ".options_id = '" . (int)$option . "'
                                    and " . TABLE_PRODUCTS_ATTRIBUTES . ".options_values_id = '" . (int)$value . "'";





And around 890, I added a similar block of code to the change I made around line 700.

Went from this:

  // calculate proper discount for attributes
              $discount_type_id = '';
              $sale_maker_discount = '';
              $new_attributes_price = zen_get_discount_calc($products_id, $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price'], $qty);
              $attributes_price += ($new_attributes_price);
            }  else {
              $attributes_price += $attribute_price->fields['options_values_price'];
            }
          }
							
          //////////////////////////////////////////////////
          // calculate additional charges
          // products_options_value_text




To this:


 // calculate proper discount for attributes
              $discount_type_id = '';
              $sale_maker_discount = '';
              $new_attributes_price = zen_get_discount_calc($products_id, $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price'], $qty);
              $attributes_price += ($new_attributes_price);
            }  else {
              $attributes_price += $attribute_price->fields['options_values_price'];
            }
          }
          
		
        $products_price = $attribute_price->fields['products_price'];
                		
       		 if ($attribute_price->fields['options_id'] == 4) {
        		$attr_value = $this->contents[$products_id]['attributes_values'][$option];
				$attributes_price += ($attr_value - $products_price);
				}
							
          //////////////////////////////////////////////////
          // calculate additional charges
          // products_options_value_text




That might not be the BEST way to do it, but it's working for me. It adds the whatever they put in the blank to the product price as an attributes charge. If you set your initial product price as 0, it would then be the only thing setting the price for the product. If your initial minimum donation is... 10 bucks... and they put in 20... it will charge 20... not 30. If you wanted it to ADD to the price, rather than replace it... just take the "- $products_price" parts out of the math equations in the first and 3rd bits of custom code.


Our operation isn't overly automated, so this works well enough for it, as we check every order carefully anyways, even as is... BUT, it doesn't filter the input for numerical values only, and if they even use so much as a $ before the price they put in, it will treat it as if they entered 0 for the value. I don't think that would actually take too much to just throw a filter on the backend of it to clean up things like a dollar sign throwing it off... But I want to actually block them from adding things to the shopping cart unless the input is valid after filtering, and I think that's going to take me considerably more work to get that figured out.
20 Jun 2008, 15:22
#15
teeb avatar

teeb

New Zenner

Join Date:
Mar 2008
Posts:
21
Plugin Contributions:
0

Re: Direct price entry attribute?

Bah, timer just ran out on editing when I had one last change to make for clarification:



That might not be the BEST way to do it, but it's working for me. It adds the difference between whatever they put in the attributes blank and the product price (attr_value - product_price) back to the product price as an attributes charge. If you set your initial product price as 0, it would then be the only thing setting the price for the product. If your initial minimum donation is... 10 bucks... and they put in 20... it will charge 20... not 30. If you wanted it to ADD to the price, rather than replace it... just take the "- $products_price" parts out of the math equations in the first and 3rd bits of custom code.




I would love to get some feedback on this, as it's the first functional coding I've ever done in PHP.
22 Aug 2008, 23:07
#16
judah avatar

judah

New Zenner

Join Date:
Nov 2007
Posts:
68
Plugin Contributions:
0

Re: Direct price entry attribute?

Can you explain how you did this?
30 Sep 2008, 15:24
#17
alex_clarke avatar

alex_clarke

Totally Zenned

Join Date:
Mar 2006
Posts:
909
Plugin Contributions:
0

Re: Direct price entry attribute?

Teeb:

I would love to get some feedback on this, as it's the first functional coding I've ever done in PHP.


Just wanted to say thanks for posting your findings.

I managed to implement your solution with no problems and it's working really well! :)
10 Dec 2008, 19:59
#18
dhcernese avatar

dhcernese

Zen Follower

Join Date:
Mar 2007
Posts:
232
Plugin Contributions:
0

Re: Direct price entry attribute?

Any improvements recently?
26 Feb 2009, 17:48
#19
rustwood avatar

rustwood

New Zenner

Join Date:
Jul 2005
Posts:
25
Plugin Contributions:
0

Re: Direct price entry attribute?

sorry - deleted
28 May 2009, 17:15
#20
planetjune avatar

planetjune

New Zenner

Join Date:
Jul 2008
Posts:
36
Plugin Contributions:
0

Re: Direct price entry attribute?

I'm just implementing this mod - it seems to work perfectly (thank you Teeb!) except that I want my initial price to be the minimum value they can enter. With Teeb's code, if your initial value is 10 and they enter 2, it overrides the 10 with a 2.

I have modded the following two lines of Teeb's code so it will replace the initial value with the value they enter only if it is greater than the initial value.

The lines are

$this->total += $qty * (max(($attr_value - $products_price), 0));


and

$attributes_price += (max(($attr_value - $products_price), 0));


from the first and third custom pieces Teeb provided.

Hope this is useful to someone :smile: