Here's to save some pain (but still requires a text editor).
For the ones out there, with absolutely no php skills and stuck with those out-of-this-world products, such as a cartboard box, that requires a price calculaded from any value in lenght, height, and width: there is hope. (The following modifications have been tested with zencart 1.3.0, it is assumed that backward compatibility is not a myth.)
First thing to do, is BACKUP, then open the file located at:
/includes/functions/functions_prices.php
locate the comment/line that says: "// calculate letters" (about line 1179)
Just under that comment, there should be a function definition that should look like:
function zen_get_letters_count($string, $free=0) {
while (strstr($string, ' ')) $string = str_replace(' ', ' ', $string);
$string = trim($string);
if (TEXT_SPACES_FREE == '1') {
$letters_count = strlen(str_replace(' ', '', $string));
} else {
$letters_count = strlen($string);
}
if ($letters_count - $free >= 1) {
return ($letters_count - $free);
} else {
return 0;
}
}
In order for your text input attributes to process numeric values instead of series of letters we have to purge some things up there.
IMPORTANT NOTE: if you do modify this function, know that every "text per letter" attribute, for now on and ever, will use the direct data input by the user. If you still wish to use
So, the modification is (with very few error handling):
function zen_get_letters_count($string, $free=0) {
if ($string > 0)
{
return ($string);
} else {
return 0;
}
}
Just below, there's another function that should look like this one:
function zen_get_letters_count_price($string, $free=0, $price) {
$letters_price = zen_get_letters_count($string, $free) * $price;
if ($letters_price <= 0) {
return 0;
} else {
return $letters_price;
}
}
It determines a price based on the sum of letters, we have to make it spit out a price simply based on the input times the price hence, simply replace it with:
function zen_get_letters_count_price($string, $free=0, $price) {
$letters_price = $string * $price;
if ($letters_price <= 0) {
return 0;
} else {
return $letters_price;
}
}
Now to the scotch tape part.
If you need to calculate a price relatively to the product of your text attributes values in the form of "price = price x attribute1 x attribute2 x attribute3 ..." then follow the next modifications.
IMPORTANT NOTE: if you do apply the following modifications, know that every "text per letter" attribute, for now on and ever, will multiply itself with the other "text per letter" attributes assigned for a specific product. If you still wish to use text attributes that do not multiply themselves together, you can always sacrifice the "text per words attributes"; we'll cover the necessary modifications in the so called: annex A.
First, open the file located at: /includes/classes/shopping_cart.php
Here we need to replace two peices of code. At about line 561, you should a line that look like this:
$this->total += $qty * zen_add_tax($text_letters, $products_tax);
It's used for calculating the products sub-total with taxes applied. We replace it with:
if($this->total == 0)
{
$this->total += ($qty * $text_letters);
if(count($this->contents[$products_id]['attributes']) == 1)
{
$this->total += $this->total * 0.15;
}
}
else
{
$this->total *= $qty * $text_letters;
$this->total += $this->total * 0.15;
}
What we do here is simply modify the += operator for using multiplication instead of addition. Note that since we want
to calculate our products prices ONLY from their parametric attributes and that, indeed, the initial price should be set to 0, I calculate the taxe in another manner then the one used by default. This is what the 0.15 stands for, a tax rate which you can replace with your own.
Next, you need to replace the lined used to calculate the raw prices total. Look around line 694, where you should find the
following peice of code:
$attributes_price += $text_letters;
Replace it with:
if($attributes_price == 0)
{
$attributes_price = $text_letters;
}
else
{
$attributes_price *= $text_letters;
}
You should now be set to process parametric products with text attributes that multiply each other. Other attributes such
as check boxes, radio buttons, well be added or substracted in the usual way. If you wish to multiply EVERY attributes against each other, you should look at line 961 where there is the line:
'final_price' => ($products_price + $this->attributes_price($products_id)),
simply replace it with:
'final_price' => ($products_price * $this->attributes_price($products_id)),
And that's it.
PLEASE. Don't email me for comments, bugs and all. Use this forum.
ANNEX A.
IMPORTANT NOTE: I didn't tested if these modifications works as I say. Experiment at your own risk.
To use text atrributes that won't multiply with each others, (by using the per word attribute)
open the file located at:
/includes/functions/functions_prices.php
locate the comment/line that says: "// calculate words" (about line 1179)
Just under that comment, there should be a function definition that should look like:
function zen_get_word_count($string, $free=0) {
if ($string != '') {
while (strstr($string, ' ')) $string = str_replace(' ', ' ', $string);
$string = trim($string);
$word_count = substr_count($string, ' ');
return (($word_count+1) - $free);
} else {
// nothing to count
return 0;
}
}
Replace it with:
function zen_get_word_count($string, $free=0) {
if ($string > 0)
{
return ($string);
} else {
return 0;
}
}
And replace the function just below with:
function zen_get_words_count_price($string, $free=0, $price) {
$words_price = $string * $price;
if ($letters_price <= 0) {
return 0;
} else {
return $words_price;
}
}



