Jump to content
Sign in to follow this  
sv1eez

SPPC and Bundled Products working together

Recommended Posts

Hi all, thanks to the creators of SPPC for a great contribution.

 

I installed SPPC and after two days of fighting with my other installed contributions

it seems to work well with all of them except one, the Bundled Products contribution. In this contribution, on the product_info.php page there is a reference about the total cost of the bundled products when purchased separately and the total amount of money the customer pays less if they are bought as a bundle. The problem is that althought I have entered prices for the bundled products for my "wholesale" group of customers the amount of the total bundle cost and the money the customer pays less when bying a bundle are those derived from the retail customer group pricing. I know where to look to fix this but my php knoeledge is not that good. If anyone could help I would be grateful.

 

Here is the part of my product_info.php which produces the total cost and the bundle gain amounts.

 

 

<!-- start bundle -->

<?php

if ($product_info['products_bundle'] == "yes") {

$products_bundle = $product_info['products_bundle'];

echo TEXT_BUNDLE_CONTENTS . "<br><table>";

$bundle_query = tep_db_query(" SELECT pd.products_name, pb.*, p.products_bundle, p.products_id, p.products_price

FROM products p

INNER JOIN products_description pd

ON p.products_id=pd.products_id

INNER JOIN products_bundles pb

ON pb.subproduct_id=pd.products_id

WHERE pb.bundle_id = " . tep_get_prid($products_id) . " and language_id = '" . (int)$languages_id . "'");

while ($bundle_data = tep_db_fetch_array($bundle_query)) {

if ($bundle_data['products_bundle'] == "yes") {

// uncomment the following line to display subproduct qty

//echo "<br>» <b>" . $bundle_data['subproduct_qty'] . " x " . $bundle_data['products_name'] . "</b>";

//echo "<br>» <b> " . $bundle_data['products_name'] . "</b>";

echo '<tr><td valign="top" class="main">» <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $bundle_data['products_id']) . '"><b><u>' . $bundle_data['products_name'] . '</u></b></a></td></tr>';

 

 

$bundle_query_nested = tep_db_query(" SELECT pd.products_name, pb.*, p.products_bundle, p.products_id, p.products_price

FROM products p

INNER JOIN products_description pd

ON p.products_id=pd.products_id

INNER JOIN products_bundles pb

ON pb.subproduct_id=pd.products_id

WHERE pb.bundle_id = " . $bundle_data['products_id'] . " and language_id = '" . (int)$languages_id . "'");

while ($bundle_data_nested = tep_db_fetch_array($bundle_query_nested)) {

// uncomment the following line to display subproduct qty

//echo "<br><i>     " . $bundle_data_nested['subproduct_qty'] . " x " . $bundle_data_nested['products_name'] . "</i>";

//echo "<br><i>     " . $bundle_data_nested['products_name'] . "</i>";

echo '<tr><td valign="top" class="main">     <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $bundle_data_nested['products_id']) . '"><i><u>' . $bundle_data_nested['products_name'] . '</u></i></a></td></tr>';

 

// CB use special price if available

if ($new_price = tep_get_products_special_price($bundle_data_nested['products_id'])) {

$bundle_sum += $new_price*$bundle_data_nested['subproduct_qty'];

} else {

$bundle_sum += $bundle_data_nested['products_price']*$bundle_data_nested['subproduct_qty'];

}

// endof CB mod

 

}

} else {

// uncomment the following line to display subproduct qty

// echo "<br>» <b>" . $bundle_data['subproduct_qty'] . " x " . $bundle_data['products_name'] . "</b>";

//echo "<br>» <b> " . $bundle_data['products_name'] . "</b>";

echo '<tr><td valign="top" class="main">» <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $bundle_data['products_id']) . '"><b><u>' . $bundle_data['products_name'] . '</u></b></a></td></tr>';

 

 

// CB use special price if available

if ($new_price = tep_get_products_special_price($bundle_data_nested['products_id'])) {

$bundle_sum += $new_price*$bundle_data['subproduct_qty'];

} else {

$bundle_sum += $bundle_data['products_price']*$bundle_data['subproduct_qty'];

}

// endof CB mod

 

}

}

// CB use special bundle price if available

if ($new_price = tep_get_products_special_price($product_info['products_id'])) {

$bundle_saving = $bundle_sum - $new_price;

} else {

$bundle_saving = $bundle_sum - $product_info['products_price'];

}

// endof CB mod

 

$bundle_sum = $currencies->display_price($bundle_sum, tep_get_tax_rate($product_info['products_tax_class_id']));

$bundle_saving = $currencies->display_price($bundle_saving, tep_get_tax_rate($product_info['products_tax_class_id']));

// comment out the following line to hide the "saving" text

echo '</table><p><table><tr><td class="main" align="right">' . TEXT_BUNDLE_SUM . '</td><td class="main"><span class="productPrice">' . $bundle_sum . '</span></td></tr><tr><td class="main" align="right">' . TEXT_BUNDLE_SAVINGS . '</td><td class="main"><span class="productSpecialPrice">' . $bundle_saving . '</span></td></tr></table>';

 

}

?>

<!-- end bundle -->

 

Thank you in advance.

Share this post


Link to post
Share on other sites

It is a bit tricky perhaps, because you rely on a "derived" table of prices, but I think it is the simplest solution (hopefully a solution anyway) by using the dynamically generated table with the products price and specials price for the customer group (normally only used for sorting on price in index.php and advanced_search_results.php when a search is done on a price range):

<?php 
  // BOF Separate Pricing Per Customer
    if(!tep_session_is_registered('sppc_customer_group_id')) { 
    $customer_group_id = '0';
    } else {
     $customer_group_id = $sppc_customer_group_id;
    }
  // EOF Separate Pricing Per Customer

if ($product_info['products_bundle'] == "yes") {
$products_bundle = $product_info['products_bundle'];
echo TEXT_BUNDLE_CONTENTS . "<br><table>";
if ($customer_group_id != '0') {
$bundle_query = tep_db_query(" SELECT pd.products_name, pb.*, p.products_bundle, p.products_id, pgp.products_price
FROM products p LEFT JOIN products_group_prices_cg_".(int)$customer_group_id." pgp using(products_id)
INNER JOIN products_description pd
ON p.products_id=pd.products_id
INNER JOIN products_bundles pb
ON pb.subproduct_id=pd.products_id 
WHERE pb.bundle_id = " . tep_get_prid($products_id) . " and language_id = '" . (int)$languages_id . "'");
} else {
$bundle_query = tep_db_query(" SELECT pd.products_name, pb.*, p.products_bundle, p.products_id, p.products_price
FROM products p 
INNER JOIN products_description pd
ON p.products_id=pd.products_id
INNER JOIN products_bundles pb
ON pb.subproduct_id=pd.products_id 
WHERE pb.bundle_id = " . tep_get_prid($products_id) . " and language_id = '" . (int)$languages_id . "'");
}
while ($bundle_data = tep_db_fetch_array($bundle_query)) {
etc. etc.

Perhaps if this works it would be good to include the check on the status of that table:

tep_db_check_age_products_group_prices_cg_table($customer_group_id);

Share this post


Link to post
Share on other sites
It is a bit tricky perhaps, because you rely on a "derived" table of prices, but I think it is the simplest solution (hopefully a solution anyway) by using the dynamically generated table with the products price and specials price for the customer group (normally only used for sorting on price in index.php and advanced_search_results.php when a search is done on a price range):

<?php 
  // BOF Separate Pricing Per Customer
 if(!tep_session_is_registered('sppc_customer_group_id')) { 
 $customer_group_id = '0';
 } else {
  $customer_group_id = $sppc_customer_group_id;
 }
  // EOF Separate Pricing Per Customer

if ($product_info['products_bundle'] == "yes") {
$products_bundle = $product_info['products_bundle'];
echo TEXT_BUNDLE_CONTENTS . "<br><table>";
if ($customer_group_id != '0') {
$bundle_query = tep_db_query(" SELECT pd.products_name, pb.*, p.products_bundle, p.products_id, pgp.products_price
FROM products p LEFT JOIN products_group_prices_cg_".(int)$customer_group_id." pgp using(products_id)
INNER JOIN products_description pd
ON p.products_id=pd.products_id
INNER JOIN products_bundles pb
ON pb.subproduct_id=pd.products_id 
WHERE pb.bundle_id = " . tep_get_prid($products_id) . " and language_id = '" . (int)$languages_id . "'");
} else {
$bundle_query = tep_db_query(" SELECT pd.products_name, pb.*, p.products_bundle, p.products_id, p.products_price
FROM products p 
INNER JOIN products_description pd
ON p.products_id=pd.products_id
INNER JOIN products_bundles pb
ON pb.subproduct_id=pd.products_id 
WHERE pb.bundle_id = " . tep_get_prid($products_id) . " and language_id = '" . (int)$languages_id . "'");
}
while ($bundle_data = tep_db_fetch_array($bundle_query)) {
etc. etc.

Perhaps if this works it would be good to include the check on the status of that table:

tep_db_check_age_products_group_prices_cg_table($customer_group_id);

 

>_<

 

Sorry to dig this out from the grave, but hopefully someone will read it and help us here.

 

I tried the code but still doesnt work.... if anyone has better solution please help here..

 

hard to find products that can bundled together but also work for sppc.

by the way i am using sppc 4.1

 

thanks in advance....

Share this post


Link to post
Share on other sites

I am also trying to do this, with my severely limited php knowledge...

 

if i get it working then i will post my product_info page code here...

 

Does anybody know if this tricky one has been solved elsewhere?

 

Would be great to find, as both these contribs are superb in their own right.

 

bee

 

:-)


There are 10 types of people in this world, those who understand binary and those who don't...

Share this post


Link to post
Share on other sites
Does anybody know if this tricky one has been solved elsewhere?

How does this change work:

// CB use special price if available
if ($new_price = tep_get_products_special_price($bundle_data_nested['products_id'])) {
$bundle_sum += $new_price*$bundle_data_nested['subproduct_qty'];
} else { 
 $bundle_data_nested['products_price'] = getSppcPrice($bundle_data_nested['products_id'], $bundle_data_nested['products_price']);
$bundle_sum += $bundle_data_nested['products_price']*$bundle_data_nested['subproduct_qty'];
}
// endof CB mod

}
} else {
// uncomment the following line to display subproduct qty 
// echo "<br>» <b>" . $bundle_data['subproduct_qty'] . " x " . $bundle_data['products_name'] . "</b>";
//echo "<br>» <b> " . $bundle_data['products_name'] . "</b>";
echo '<tr><td valign="top" class="main">» <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $bundle_data['products_id']) . '"><b><u>' . $bundle_data['products_name'] . '</u></b></a></td></tr>';


// CB use special price if available
if ($new_price = tep_get_products_special_price($bundle_data_nested['products_id'])) {
$bundle_sum += $new_price*$bundle_data['subproduct_qty'];
} else { 
 $bundle_data['products_price'] = getSppcPrice($bundle_data['products_id'], $bundle_data['products_price']);
$bundle_sum += $bundle_data['products_price']*$bundle_data['subproduct_qty'];
}
// endof CB mod

}
}
// CB use special bundle price if available
if ($new_price = tep_get_products_special_price($product_info['products_id'])) {
$bundle_saving = $bundle_sum - $new_price;
} else {
// assuming that $product_info['products_price'] has already been set to customer group price
$bundle_saving = $bundle_sum - $product_info['products_price'];
}
// endof CB mod

You would need to add this function to includes/functions/general.php:

  function getSppcPrice ($products_id, $products_price = 0) {
$cust_group_price = '';
if (isset($_SESSION['sppc_customer_group_id']) && $_SESSION['sppc_customer_group_id'] != '0') {
  $customer_group_id = $_SESSION['sppc_customer_group_id'];
} else {
  $customer_group_id = '0';
}

if ($customer_group_id == '0') {
  return $products_price; // customer is retail: price is retail price
}
$customer_group_price_query = tep_db_query("select customers_group_price from " . TABLE_PRODUCTS_GROUPS . " where products_id = '" . (int)$products_id . "' and customers_group_id =  '" . $customer_group_id . "'");
if ($customer_group_price = tep_db_fetch_array($customer_group_price_query)) {
  $cust_group_price = $customer_group_price['customers_group_price'];
  return $cust_group_price;
  } else {
  return $products_price; // price stays retail price since there is no customer group price
  }
 }

Share this post


Link to post
Share on other sites

Thanks Jan

The last solution with the Sppc function works perfectly.

 

Bee


There are 10 types of people in this world, those who understand binary and those who don't...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×