Hallo,
danke, danke f?r euer Lob. Es kann sein, dass ich mal noch weitere Shops mit XTC machen werde. Aber nicht bevor ich noch mehr ?ber die Funktionsweise herausgefunden hab. Da sind schon noch einige Dinger drin, die ich noch nicht nachvolziehen kann.
Aber man lernt ja nie! Aus! ;-))
Nettopreis:
Ich hab festgestellt, dass die Preis erst aus der Datenbank geholt werden, dann wird er formatiert und erst dann ins Template geschrieben. Und da muss man ansetzten.
Zuerst mal kommt in "xtc_add_tax.inc.php" diese Funktion zus?tzlich rein.
Code:
function xtc_addno_tax($price, $tax)
{
return $price;
}
Dabei wird einfach keine Steuer draufgerechnet.
In der Datei "xtc_get_products_price.inc.php" hab ich folgende Funktion hinzugef?gt:
Code:
function xtc_get_products_price_netto($products_id,$price_special_netto,$quantity)
{
// check if customer is allowed to see prices (if not -> no price calculations , show error message)
if ($_SESSION['customers_status']['customers_status_show_price'] == '1') {
// load price data into array for further use!
$product_price_query = xtc_db_query("SELECT products_price,
products_discount_allowed,
products_tax_class_id
FROM ". TABLE_PRODUCTS ."
WHERE
products_id = '".$products_id."'");
$product_price_netto = xtc_db_fetch_array($product_price_query);
$price_data_netto=array();
$price_data_netto=array(
'PRODUCTS_PRICE'=>$product_price_netto['products_price'],
'PRODUCTS_DISCOUNT_ALLOWED'=>$product_price_netto['products_discount_allowed'],
// 'PRODUCT_TAX_CLASS_ID'=>$product_price_netto['products_tax_class_id'],
'PRODUCT_TAX_CLASS_ID'=>'',
'PRODUCTS_PRICE_NETTO'=>$product_price_netto['products_price']
);
// get tax rate for tax class
$products_tax=xtc_get_tax_rate($price_data_netto['PRODUCT_TAX_CLASS_ID']);
// check if user is allowed to see tax rates
if ($_SESSION['customers_status']['customers_status_show_price_tax'] =='0') {
$products_tax='';
} // end $_SESSION['customers_status']['customers_status_show_price_tax'] =='0'
// check if special price is aviable for product (no product discount on special prices!)
if ($special_price_netto=xtc_get_products_special_price($products_id)) {
$special_price_netto= (xtc_addno_tax($special_price,$products_tax));
$price_data_netto['PRODUCTS_PRICE']= (xtc_add_tax($price_data['PRODUCTS_PRICE'],$products_tax));
$price_string_netto=xtc_format_special_price($special_price_netto,$price_data_netto['PRODUCTS_PRICE'],$price_special_netto,$calculate_currencies=true,$quantity,$products_tax);
}
else {
// if ($special_price=xtc_get_products_special_price($products_id))
// Check if there is another price for customers_group (if not, take norm price and calculte discounts (NOTE: no discount on group PRICES(only OT DISCOUNT!)!
$group_price_query_netto=xtc_db_query("SELECT personal_offer
FROM personal_offers_by_customers_status_".$_SESSION['customers_status']['customers_status_id']."
WHERE products_id='".$products_id."'");
$group_price_data_netto=xtc_db_fetch_array($group_price_query_netto);
// if we found a price, everything is ok if not, we will use normal price
if ($group_price_data_netto['personal_offer']!='' and $group_price_data_netto['personal_offer']!='0.0000') {
$price_string_netto=$group_price_data_netto['personal_offer'];
// check if customer is allowed to get graduated prices
if ($_SESSION['customers_status']['customers_status_graduated_prices']=='1'){
// check if there are graduated prices in db
// get quantity for products
// modifikations for new graduated prices
$qty=xtc_get_qty($products_id);
if (!xtc_get_qty($products_id)) $qty=$quantity;
$graduated_price_query_netto=xtc_db_query("SELECT max(quantity)
FROM personal_offers_by_customers_status_".$_SESSION['customers_status']['customers_status_id']."
WHERE products_id='".$products_id."'
AND quantity<='".$qty."'");
$graduated_price_data_netto=xtc_db_fetch_array($graduated_price_query);
// get singleprice
$graduated_price_query_netto=xtc_db_query("SELECT personal_offer
FROM personal_offers_by_customers_status_".$_SESSION['customers_status']['customers_status_id']."
WHERE products_id='".$products_id."'
AND quantity='".$graduated_price_data_netto['max(quantity)']."'");
$graduated_price_data_netto=xtc_db_fetch_array($graduated_price_query_netto);
$price_string_netto=$graduated_price_data_netto['personal_offer'];
} // end $_SESSION['customers_status']['customers_status_graduated_prices']=='1'
// $price_string_netto= (xtc_add_tax($price_string_netto,$products_tax));//*$quantity;
}
else {
// if ($group_price_data['personal_offer']!='' and $group_price_data['personal_offer']!='0.0000')
$price_string_netto= (xtc_add_tax($price_data_netto['PRODUCTS_PRICE'],$products_tax)); //*$quantity;
$price_string_netto= $price_string_netto;
// check if product allows discount
if ($price_data_netto['PRODUCTS_DISCOUNT_ALLOWED'] != '0.00') {
$discount_netto=$price_data_netto['PRODUCTS_DISCOUNT_ALLOWED'];
// check if group discount > max. discount on product
if ($discount_netto > $_SESSION['customers_status']['customers_status_discount']) {
$discount_netto=$_SESSION['customers_status']['customers_status_discount'];
}
// calculate price with rabatt
$rabatt_string_netto = $price_string_netto - ($price_string_netto/100*$discount_netto);
if ($price_string_netto==$rabatt_string_netto) {
$price_string_netto=xtc_format_price($price_string_netto*$quantity,$price_special,$calculate_currencies=true);
} else {
$price_string_netto=xtc_format_special_price($rabatt_string_netto,$price_string_netto,$price_special_netto,$calculate_currencies=false,$quantity,$products_tax);
}
return $price_string_netto;
break;
}
}
// format price & calculate currency
$price_string_netto=xtc_format_price($price_string_netto*$quantity,$price_special_netto,$calculate_currencies=true);
}
}
else {
// return message, if not allowed to see prices
$price_string_netto=NOT_ALLOWED_TO_SEE_PRICES;
} // end ($_SESSION['customers_status']['customers_status_show_price'] == '1')
return $price_string_netto;
}
Wie man sieht, gibts da schon mal den netto Preis zur?ck.
Dann wird der Einzelpreis in "xtc_get_single_prducts_price.inc.php" gebaut:
Code:
function xtc_get_single_products_price_netto($products_id,$price_special,$quantity)
{
// check if customer is allowed to see prices (if not -> no price calculations , show error message)
if ($_SESSION['customers_status']['customers_status_show_price'] == '1') {
// load price data into array for further use!
$product_price_query = xtc_db_query("SELECT products_price,
products_discount_allowed,
products_tax_class_id
FROM ". TABLE_PRODUCTS ."
WHERE
products_id = '".$products_id."'");
$product_price = xtc_db_fetch_array($product_price_query);
$price_data=array();
$price_data=array(
'PRODUCTS_PRICE'=>$product_price['products_price'],
'PRODUCTS_DISCOUNT_ALLOWED'=>$product_price['products_discount_allowed'],
'PRODUCT_TAX_CLASS_ID'=>$product_price['products_tax_class_id']
);
// get tax rate for tax class
$products_tax=xtc_get_tax_rate($price_data['PRODUCT_TAX_CLASS_ID']);
// check if user is allowed to see tax rates
if ($_SESSION['customers_status']['customers_status_show_price_tax'] =='0') {
$products_tax='';
} // end $_SESSION['customers_status']['customers_status_show_price_tax'] =='0'
// check if special price is aviable for product (no product discount on special prices!)
if ($special_price=xtc_get_products_special_price($products_id)) {
$special_price= (xtc_addno_tax($special_price,$products_tax));
$price_data['PRODUCTS_PRICE']= (xtc_addno_tax($price_data['PRODUCTS_PRICE'],$products_tax));
$price_string=xtc_format_special_price($special_price,$price_data['PRODUCTS_PRICE'],$price_special,$calculate_currencies=true,$quantity,$products_tax);
} else { // if ($special_price=xtc_get_products_special_price($products_id))
// Check if there is another price for customers_group (if not, take norm price and calculte discounts (NOTE: no discount on group PRICES(only OT DISCOUNT!)!
$group_price_query=xtc_db_query("SELECT personal_offer
FROM personal_offers_by_customers_status_".$_SESSION['customers_status']['customers_status_id']."
WHERE products_id='".$products_id."'");
$group_price_data=xtc_db_fetch_array($group_price_query);
// if we found a price, everything is ok if not, we will use normal price
if ($group_price_data['personal_offer']!='' and $group_price_data['personal_offer']!='0.0000')
{
$price_string=$group_price_data['personal_offer'];
// check if customer is allowed to get graduated prices
if ($_SESSION['customers_status']['customers_status_graduated_prices']=='1'){
// check if there are graduated prices in db
// get quantity for products
$graduated_price_query=xtc_db_query("SELECT max(quantity)
FROM personal_offers_by_customers_status_".$_SESSION['customers_status']['customers_status_id']."
WHERE products_id='".$products_id."'
AND quantity<='".$quantity."'");
$graduated_price_data=xtc_db_fetch_array($graduated_price_query);
// get singleprice
$graduated_price_query=xtc_db_query("SELECT personal_offer
FROM personal_offers_by_customers_status_".$_SESSION['customers_status']['customers_status_id']."
WHERE products_id='".$products_id."'
AND quantity='".$graduated_price_data['max(quantity)']."'");
$graduated_price_data=xtc_db_fetch_array($graduated_price_query);
$price_string=$graduated_price_data['personal_offer'];
} // end $_SESSION['customers_status']['customers_status_graduated_prices']=='1'
$price_string= (xtc_addno_tax($price_string,$products_tax));
} else { // if ($group_price_data['personal_offer']!='' and $group_price_data['personal_offer']!='0.0000')
$price_string= (xtc_addno_tax($price_data['PRODUCTS_PRICE'],$products_tax));
// check if product allows discount
if ($price_data['PRODUCTS_DISCOUNT_ALLOWED'] != '0.00') {
$discount=$price_data['PRODUCTS_DISCOUNT_ALLOWED'];
// check if group discount > max. discount on product
if ($discount > $_SESSION['customers_status']['customers_status_discount']) {
$discount=$_SESSION['customers_status']['customers_status_discount'];
}
// calculate price with rabatt
$price_string = $price_string - ($price_string/100*$discount);
}
}
// format price & calculate currency
$price_string=xtc_format_price($price_string,$price_special,$calculate_currencies=true);
}
} else {
// return message, if not allowed to see prices
$price_string=NOT_ALLOWED_TO_SEE_PRICES;
} // end ($_SESSION['customers_status']['customers_status_show_price'] == '1')
return $price_string;
So, das waren soweit alle Vorbereitungen. Jetzt geht's weiter und man muss an bestimmten Stellen im Code die richtigen Variablen einsetzten. Alle Seiten, in denen irgend ein Preis vorkommt, m?ssen nun bearbeitet werden. product_info.php: Da muss an mehreren Stellen der netto Preis rein.
Zeile 86
Code:
$products_price_netto=xtc_get_products_price_netto($product_info['products_id'], $price_special=1, $quantity=1);
Zeile 124
Code:
$info_smarty->assign('PRODUCTS_PRICE_NETTO',$products_price_netto);
"new_products.php" die Zeilen hinzu
Zeile 94
Code:
'PRODUCTS_PRICE_NETTO' => xtc_get_products_price_netto($new_products['products_id'],$price_special=1,$quantity=1),
Zeile 109
Code:
'PRODUCTS_PRICE_NETTO' => xtc_get_products_price_netto($new_products['products_id'],$price_special=1,$quantity=1),
In den Zeilen wird der Nettopreis in die Arrays reingeschrieben, damit er dann an den richtigen Stellen wieder rauskommt.
Und nun geht's daran, die Nettopreise in die Templates einzubauen, damit sie auch angezeigt werden.
Dazu mehr im n?chsten Abschnitt