Hi, I have successfully merged 99% of both the Dual Pricing Module and the Group Pricing Module which basically gives me 4 Group prices per product and as many wholesale prices as I wish to enter, I can also add more groups later should I wish - this all works as expected except I am having some trouble with the very last part of the integration where the prices are displayed - The problem is in the functions_prices.php file under
// computes products_price + option groups lowest attributes price of each group when on
If I enter the code from either the Dual Pricing Module or the Group Pricing Module into this section the relevant part works as expected - I don't believe the issue is that it won't work and more that I am very inexperienced with PHP coding and that I am not editing it correctly.
Any help would be gratefully appreciated - and please without wishing to sound rude I really don't want this to turn into a debate about the right and wrong way to price products - I have read so many forum posts about the pricing mods and they always seem to turn into heated debates as to how pricing should and shouldn't be done.
If I can sort this small issue I am sure others would be able to make use of this new super mod so to speak as it gives many different pricing options per product and it only shows sale prices to group (or retail) customers and not to wholesale customers.
Please don't be too harsh - whilst I have reasonable experience with Zen Cart my knowledge with PHP is sadly lacking.
This is how I have coded it - (I should say one of the ways I have tried - having spent a fair few hours editing this section of code)
PHP Code:
////
// computes products_price + option groups lowest attributes price of each group when on
//Dual Pricing
function zen_get_products_base_price($products_id) {
global $db;
if($_SESSION['customer_id']){
$customer_group_query = "select gp.group_name
from " . TABLE_CUSTOMERS . " cu
left join " . TABLE_GROUP_PRICING . " gp on cu.customers_group_pricing=gp.group_id
where cu.customers_id = " . $_SESSION['customer_id'];
if($customer_group = $db->Execute($customer_group_query)) {
$customers_group=$customer_group->fields['group_name'];
}
}
$product_check = $db->Execute("select products_price, products_price_w, products_group_a_price, products_group_b_price, products_group_c_price, products_group_d_price, products_priced_by_attribute from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
// is there a products_price to add to attributes
if($customers_group) {
if($customers_group == GROUP_PRICE_PER_ITEM1 && $product_check->fields['products_group_a_price'] != 0) {
$products_price = $product_check->fields['products_group_a_price'];
} elseif($customers_group == GROUP_PRICE_PER_ITEM2 && $product_check->fields['products_group_b_price'] != 0) {
$products_price = $product_check->fields['products_group_b_price'];
} elseif($customers_group == GROUP_PRICE_PER_ITEM3 && $product_check->fields['products_group_c_price'] != 0) {
$products_price = $product_check->fields['products_group_c_price'];
} elseif($customers_group == GROUP_PRICE_PER_ITEM4 && $product_check->fields['products_group_d_price'] != 0) {
$products_price = $product_check->fields['products_group_d_price'];
} elseif ($_SESSION['customer_whole']) {
if ($_SESSION['customer_whole'] != '0') {
$i = (int)$_SESSION['customer_whole'];
$i--;
$products_price_array = $product_check->fields['products_price_w'];
$productsprice = explode("-",$products_price_array);
$products_price = (float)$productsprice[$i];
if ($products_price == '0' || $products_price == '') {
$products_price = (float)$productsprice[0];
}
if ($products_price=='0'){
$products_price = $product_check->fields['products_price'];
}
} else {
$products_price = $product_check->fields['products_price'];
}
} else {
$products_price = $product_check->fields['products_price'];
}
}
}
And here are the two sections of code I have been trying to integrate
Original code from Dual Pricing module
PHP Code:
////
// computes products_price + option groups lowest attributes price of each group when on
//Dual Pricing
function zen_get_products_base_price($products_id) {
global $db;
$product_check = $db->Execute("select products_price, products_price_w, products_priced_by_attribute from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
// is there a products_price to add to attributes
//Dual Pricing start
if ($_SESSION['customer_whole']) {
if ($_SESSION['customer_whole'] != '0') {
$i = (int)$_SESSION['customer_whole'];
$i--;
$products_price_array = $product_check->fields['products_price_w'];
$productsprice = explode("-",$products_price_array);
$products_price = (float)$productsprice[$i];
if ($products_price == '0' || $products_price == '') {
$products_price = (float)$productsprice[0];
}
if ($products_price=='0'){
$products_price = $product_check->fields['products_price'];
}
} else {
$products_price = $product_check->fields['products_price'];
}
} else {
$products_price = $product_check->fields['products_price'];
}
// do not select display only attributes and attributes_price_base_included is true
$product_att_query = $db->Execute("select options_id, price_prefix, options_values_price, options_values_price_w, attributes_display_only, attributes_price_base_included, round(concat(price_prefix, options_values_price), 5) as value from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and attributes_display_only != '1' and attributes_price_base_included='1'". " order by options_id, value");
//Dual Pricing end
$the_options_id= 'x';
$the_base_price= 0;
// add attributes price to price
if ($product_check->fields['products_priced_by_attribute'] == '1' and $product_att_query->RecordCount() >= 1) {
while (!$product_att_query->EOF) {
if ( $the_options_id != $product_att_query->fields['options_id']) {
$the_options_id = $product_att_query->fields['options_id'];
//Dual Pricing start
if ($_SESSION['customer_whole']) {
if ($_SESSION['customer_whole'] != '0') {
$i = (int)$_SESSION['customer_whole'];
$i--;
$option_price_array = $product_att_query->fields['options_values_price_w'];
$optionprice = explode(",",$option_price_array);
$options_values_price = (float)$optionprice[$i];
if ($options_values_price=='0' || $options_values_price==''){
$options_values_price = (float)$optionprice[0];
}
$the_base_price += $options_values_price;
if ($options_values_price=='0'){
$the_base_price += (($product_att_query->fields['price_prefix'] == '-') ? -1 : 1) * $product_att_query->fields['options_values_price'];
}
} else {
$the_base_price += (($product_att_query->fields['price_prefix'] == '-') ? -1 : 1) * $product_att_query->fields['options_values_price'];
}
} else {
$the_base_price += (($product_att_query->fields['price_prefix'] == '-') ? -1 : 1) * $product_att_query->fields['options_values_price'];
}
}
//Dual Pricing end
$product_att_query->MoveNext();
}
$the_base_price = $products_price + $the_base_price;
} else {
$the_base_price = $products_price;
}
return $the_base_price;
}
And the original code from Group Pricing module
PHP Code:
////
// computes products_price + option groups lowest attributes price of each group when on
function zen_get_products_base_price($products_id) {
global $db;
if($_SESSION['customer_id']) {
$customer_group_query = "select gp.group_name
from " . TABLE_CUSTOMERS . " cu
left join " . TABLE_GROUP_PRICING . " gp on cu.customers_group_pricing=gp.group_id
where cu.customers_id = " . $_SESSION['customer_id'];
if($customer_group = $db->Execute($customer_group_query)) {
$customers_group=$customer_group->fields['group_name'];
}
}
$product_check = $db->Execute("select products_price, products_group_a_price, products_group_b_price, products_group_c_price, products_group_d_price, products_priced_by_attribute from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
// is there a products_price to add to attributes
$products_price = $product_check->fields['products_price'];
if($customers_group) {
if($customers_group == GROUP_PRICE_PER_ITEM1 && $product_check->fields['products_group_a_price'] != 0) {
$products_price = $product_check->fields['products_group_a_price'];
} elseif($customers_group == GROUP_PRICE_PER_ITEM2 && $product_check->fields['products_group_b_price'] != 0) {
$products_price = $product_check->fields['products_group_b_price'];
} elseif($customers_group == GROUP_PRICE_PER_ITEM3 && $product_check->fields['products_group_c_price'] != 0) {
$products_price = $product_check->fields['products_group_c_price'];
} elseif($customers_group == GROUP_PRICE_PER_ITEM4 && $product_check->fields['products_group_d_price'] != 0) {
$products_price = $product_check->fields['products_group_d_price'];
}
}
// do not select display only attributes and attributes_price_base_included is true
$product_att_query = $db->Execute("select options_id, price_prefix, options_values_price, attributes_display_only, attributes_price_base_included, round(concat(price_prefix, options_values_price), 5) as value from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and attributes_display_only != '1' and attributes_price_base_included='1'". " order by options_id, value");
$the_options_id= 'x';
$the_base_price= 0;
// add attributes price to price
if ($product_check->fields['products_priced_by_attribute'] == '1' and $product_att_query->RecordCount() >= 1) {
while (!$product_att_query->EOF) {
if ( $the_options_id != $product_att_query->fields['options_id']) {
$the_options_id = $product_att_query->fields['options_id'];
$the_base_price += (($product_att_query->fields['price_prefix'] == '-') ? -1 : 1) * $product_att_query->fields['options_values_price'];
}
$product_att_query->MoveNext();
}
$the_base_price = $products_price + $the_base_price;
} else {
$the_base_price = $products_price;
}
return $the_base_price;
}