Пишу, как делал динамическое изменение цены при выборе дополнительного свойства.
Поскольку у меня стояла задача под radio-кнопки, то делал под них.
Под другие поля делается аналогично.
Устанавливаем данный хак и открываем файл ps_product_custom_type
Находим строку 158 - function customTypeHTML($field=array()) {
перед ней добавляем новую функцию
function getPriceIncludTax($value) {
global $CURRENCY_DISPLAY;
static $tax_rate=null;
if ($tax_rate===null) {
$tax_rate=ps_product::get_taxrate();
}
$operand = '';
$price = 0;
// Get the price modification for this attribute value
$start = strpos( $value, "[" ) ;
$finish = strpos( $value, "]", $start ) ;
if (is_int($finish) && is_int($start)) {
$length = $finish - $start ;
if( $length > 1 ) {
$price = substr( $value, $start + 1, $length - 1 ) ;
$operand = substr( $price, 0, 1 ) ;
$price = substr( $price, 1 ) ;
if ($operand=='=') $operand='+';
}
}
if( $price > 0 ) {
$value = substr( 0, $start ) ;
$price_with_tax=$CURRENCY_DISPLAY->getValue($price * (1 + $tax_rate),2);
$value .= $operand.$price_with_tax;
}
return $value;
}
Находим строку ниже
$show_value=$this->getPriceWithTax($value);
под ней дописываем
$show_value2=$this->getPriceIncludTax($value);
Еще ниже строку
$html .= "<input type=\"radio\" class=\"inputbox\" id=\"".$titlevar."_field\" name=\"$titlevar\" value=\"".$base_var."\" ". $checked ."/>".$show_value;
Меняем ее на
$html .= "<input type=\"radio\" class=\"inputbox\" id=\"".$titlevar."_field\" name=\"$titlevar\" onClick=\"cal(document.forms.r1, $show_value2 )\" value=\"".$base_var."\" ". $checked ." />".$show_value;
Теперь идем в файл price.tpl
Пишем, там где выводится цена, скрипт и форму:
<SCRIPT LANGUAGE="JavaScript">
function cal(fo, v) {
c = v+eval(fo.a.value);
fo.total.value = c.toFixed(2);
}
</SCRIPT>
<form name="r1" action="">
<input type="text" style="border:0; text-align:center;background:transparent;" name="total" value="<?php echo $CURRENCY_DISPLAY-> getFullValue($base_price)?>" id="resultbox" readonly="readonly" />
<input type="hidden" name="a" value="<?php echo $base_price ?>" />
</form>
все.