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
Code:
$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
Code:
// 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
Code:
// 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):
Code:
$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:
Code:
// 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:
Code:
// 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.