function dscCalculateDiscount($orderPrice, $log) { $discount = array("discount_percent" => 0, "discount_standart_unit" => 0, "discount_current_unit" => 0, "rest_standart_unit" => 0, "rest_current_unit" => 0, "priceUnit" => getPriceUnit()); $customerID = (int) regGetIdByLogin($log); switch (CONF_DISCOUNT_TYPE) { // discount is switched off case 1: return $discount; break; // discount is based on customer group // discount is based on customer group case 2: if (!is_bool($customerID = regGetIdByLogin($log))) { $customer_group = GetCustomerGroupByCustomerId($customerID); if ($customer_group) { $discount["discount_percent"] = $customer_group["custgroup_discount"]; } else { $discount["discount_percent"] = 0; } } else { return $discount; } break; // discount is calculated with help general order price // discount is calculated with help general order price case 3: $discount["discount_percent"] = _calculateGeneralPriceDiscount($orderPrice, $log); break; // discount equals to discount is based on customer group plus // discount calculated with help general order price // discount equals to discount is based on customer group plus // discount calculated with help general order price case 4: if (!is_bool($customerID)) { $customer_group = GetCustomerGroupByCustomerId($customerID); if (!$customer_group) { $customer_group = array("custgroup_discount" => 0); } } else { $customer_group["custgroup_discount"] = 0; } $discount["discount_percent"] = $customer_group["custgroup_discount"] + _calculateGeneralPriceDiscount($orderPrice, $log); break; // discount is calculated as MAX( discount is based on customer group, // discount calculated with help general order price ) // discount is calculated as MAX( discount is based on customer group, // discount calculated with help general order price ) case 5: if (!is_bool($customerID)) { $customer_group = GetCustomerGroupByCustomerId($customerID); } else { $customer_group["custgroup_discount"] = 0; } if ($customer_group["custgroup_discount"] >= _calculateGeneralPriceDiscount($orderPrice, $log)) { $discount["discount_percent"] = $customer_group["custgroup_discount"]; } else { $discount["discount_percent"] = _calculateGeneralPriceDiscount($orderPrice, $log); } break; } $discount["discount_standart_unit"] = (double) $orderPrice / 100 * (double) $discount["discount_percent"]; $discount["discount_current_unit"] = show_priceWithOutUnit($discount["discount_standart_unit"]); $discount["rest_standart_unit"] = $orderPrice - $discount["discount_standart_unit"]; $discount["rest_current_unit"] = show_priceWithOutUnit($discount["rest_standart_unit"]); return $discount; }
function psGetExtra($productID) { if (!is_array($productID)) { $ProductIDs = array($productID); $IsProducts = false; } elseif (count($productID)) { $ProductIDs =& $productID; $IsProducts = true; } else { return array(); } $extra = array(); $sql = ' SELECT v.productID, v.option_value, v.option_type, v.option_show_times, v.variantID, v.optionID, t.optionID, t.name FROM ?#PRODUCT_OPTIONS_VALUES_TABLE AS v LEFT JOIN ?#PRODUCT_OPTIONS_TABLE AS t ON (t.optionID = v.optionID) WHERE v.productID IN (?@) ORDER BY t.sort_order, t.name '; $q = db_phquery($sql, $ProductIDs); while ($row = db_fetch_assoc($q)) { if (($row['option_type'] == 0 || $row['option_type'] == NULL) && strlen(trim($row['option_value'])) > 0) { $extra[$row['productID']][$row['optionID']] = array('option_type' => $row['option_type'], 'name' => $row['name'], 'option_value' => $row['option_value'], 'optionID' => $row['optionID']); //if set Ресурс (стр) if ($row['optionID'] == 6) { $extra[$row['productID']][37] = array('option_type' => $row['option_type'], 'name' => 'Себестоимость печати', 'option_value' => $row['option_value'], 'optionID' => 37); } } else { if ($row['option_type'] == 1) { $sql = ' SELECT v.option_value, v.variantID, o.price_surplus FROM ' . PRODUCTS_OPTIONS_SET_TABLE . ' AS o LEFT JOIN ' . PRODUCTS_OPTIONS_VALUES_VARIANTS_TABLE . ' AS v ON (v.variantID = o.variantID) WHERE v.optionID=' . $row['optionID'] . ' AND o.productID=' . $row['productID'] . ' AND v.optionID=' . $row['optionID'] . ' ORDER BY v.sort_order, v.option_value'; $q2 = db_query($sql); $row['values_to_select'] = array(); $i = 0; while ($r = db_fetch_assoc($q2)) { if ($r['variantID'] === $row['variantID']) { $row['variant_name'] = $r['option_value']; } $row['values_to_select'][$i] = array(); $row['values_to_select'][$i]['variantID'] = $r['variantID']; $row['values_to_select'][$i]['option_value'] = $r['option_value']; // if ( $r['price_surplus'] > 0 )$row['values_to_select'][$i]['option_value'] .= ' (+ '.show_price($r['price_surplus']).')'; // elseif($r['price_surplus'] < 0 )$row['values_to_select'][$i]['option_value'] .= ' (- '.show_price(-$r['price_surplus']).')'; $row['values_to_select'][$i]['option_valueWithOutPrice'] = $r['option_value']; $row['values_to_select'][$i]['price_surplus'] = show_priceWithOutUnit($r['price_surplus']); $i++; } $row['values_to_select_count'] = count($row['values_to_select']); $extra[$row['productID']][$row['optionID']] = $row; } } } if (!$IsProducts) { if (!count($extra)) { return array(); } else { return $extra[$productID]; } } return $extra; }
if ($a["big_picture"]) { $size = getimagesize(DIR_PRODUCTS_PICTURES . "/" . $a["big_picture"]); $a['picture_width'] = $size[0] + 40; $a['picture_height'] = $size[1] + 30; } } if (!$a['picture'] && !$a['thumbnail']) { $a['picture'] = ''; $a['thumbnail'] = ''; $a['big_picture'] = ''; } $a[12] = show_price($a["Price"]); $a[13] = show_price($a["list_price"]); $a[14] = show_price($a["list_price"] - $a["Price"]); //you save (value) $a["PriceWithOutUnit"] = show_priceWithOutUnit($a["Price"]); if ($a["list_price"]) { $a[15] = ceil(($a["list_price"] - $a["Price"]) / $a["list_price"] * 100); //you save (%) } $all_product_pictures = array(); $dbres = db_phquery("SELECT * FROM ?#PRODUCT_PICTURES WHERE productID=? ORDER BY priority", $productID); while ($row = db_fetch_assoc($dbres)) { if (!$row['thumbnail'] || !file_exists(DIR_PRODUCTS_PICTURES . '/' . $row['thumbnail'])) { continue; } if (!$row['filename'] || !file_exists(DIR_PRODUCTS_PICTURES . '/' . $row['filename'])) { continue; } if ($row['enlarged'] && file_exists(DIR_PRODUCTS_PICTURES . '/' . $row['enlarged'])) { list($row['width'], $row['height']) = getimagesize(DIR_PRODUCTS_PICTURES . '/' . $row['enlarged']);
function GetProductInSubCategories($callBackParam, &$count_row, $navigatorParams = null) { if ($navigatorParams != null) { $offset = $navigatorParams['offset']; $CountRowOnPage = $navigatorParams['CountRowOnPage']; } else { $offset = 0; $CountRowOnPage = 0; } $categoryID = $callBackParam['categoryID']; $subCategoryIDArray = catGetSubCategories($categoryID); $cond = ''; foreach ($subCategoryIDArray as $subCategoryID) { if ($cond != '') { $cond .= ' OR categoryID=' . (int) $subCategoryID; } else { $cond .= ' categoryID=' . (int) $subCategoryID . ' '; } } $whereClause = ''; if ($cond != '') { $whereClause = ' where ' . $cond; } $result = array(); if ($whereClause == '') { $count_row = 0; return $result; } $sql = ' SELECT categoryID, name, brief_description, customers_rating, customer_votes, productID, default_picture, sort_order, currencyID ' . convert_prices() . ' FROM ' . PRODUCTS_TABLE . ' ' . $whereClause . ' ORDER BY ' . CONF_DEFAULT_SORT_ORDER; $q = db_query($sql); $i = 0; while ($row = db_fetch_row($q)) { if ($i >= $offset && $i < $offset + $CountRowOnPage || $navigatorParams == null) { $row["PriceWithUnit"] = show_price($row["Price"]); $row["list_priceWithUnit"] = show_price($row["list_price"]); // you save (value) $row["SavePrice"] = show_price($row["list_price"] - $row["Price"]); // you save (%) if ($row["list_price"]) { $row["SavePricePercent"] = ceil(($row["list_price"] - $row["Price"]) / $row["list_price"] * 100); } _setPictures($row); //$row["product_extra"] = GetExtraParametrs($row["productID"]); $row["PriceWithOutUnit"] = show_priceWithOutUnit($row["Price"]); $result[] = $row; } $i++; } $count_row = $i; return $result; }