Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

HELP! Need help with PHP in OScommerce!


nmaster64

Recommended Posts

If this is newbish, sorry, PHP just isn't my thing.

 

Ok, I've got OScommerce and I've added columns to the 'customers' database for membership levels, most notably 'customers_group_id', which identifies their group.

 

For instance, if 'customers_group_id' for a specific customer is 1, they are a bronze member, if 2, a silver, 3, a gold, and there are a couple more. 0 is default.

 

I've set up another box in the right column for Member Links. I've got EVERYTHING set up except for one thing, member_links.php in the 'box' folder. This is what I need to do.

 

Using the standard right-side box layout for OScommerce (2.2), I need the PHP code to do the following:

 

A.) If the user isn't logged in, or 'customers_group_id' = 0, then this box is invisible.

 

B.) If the logged in user's 'customers_group_id' field = 1, then display the box, containing a set of links (to a standard html pages).

 

C.) If the logged in user's 'customers_group_id" field = 2, then they get a different set containing more links.

 

D.) If the logged in user's 'customers_group_id" field = 3, then they will get another set with even more links.

 

D.) If the logged in user's 'customers_group_id" field = 4, then they get a totally different link set.

 

If ANYONE could help me even a little bit, I would REALLY appreciate it. Thanks.

Link to comment
Share on other sites

Anyone? Anything? Please?

 

there might be a contribution that deals with groups or memberships like this. I would suggest searching the contribution section.

 

What you are describing is not a simple hack and the fact that you don't know PHP....

Link to comment
Share on other sites

there might be a contribution that deals with groups or memberships like this. I would suggest searching the contribution section.

 

What you are describing is not a simple hack and the fact that you don't know PHP....

 

See, I figured it wouldn't be that hard. It sounded like something that was commonly done. "If database value = X, then run command X, if Y, run Y..."

 

I've already configured everything for the groups and the like, now it's just a matter of utilizing it. I've set everything up for the new box too, the hard part is just getting the content to load based upon the script.

Link to comment
Share on other sites

Maybe something like

 

$my_query = tep_db_query("select customers_group_id from customers where customers_id = " . $customer_id);

 

$my_array = tep_db_fetch_array($my_query);

 

switch ($my_array['customers_group_id']) {

case 1:

do whatever;

break;

case 2:

do whateer

break;

}

 

etc.

osCommerce is a great piece of software with wonderful contributions.

Spend some time in the contribution area. There are a lot of gems there.

Link to comment
Share on other sites

Maybe something like

 

$my_query = tep_db_query("select customers_group_id from customers where customers_id = " . $customer_id);

 

$my_array = tep_db_fetch_array($my_query);

 

switch ($my_array['customers_group_id']) {

?  case 1:

? ? ? do whatever;

? ? ? break;

?  case 2:

? ? ? do whateer

? ?  break;

}

 

etc.

 

Thanks a ton! That gives me a good place to start.

 

By the way, does that query code get the data from the currently logged in user (it looks like it does), and what happens if they aren't logged in?

Link to comment
Share on other sites

Thanks a ton! That gives me a good place to start.

 

By the way, does that query code get the data from the currently logged in user?

 

I can't remeber if it's $customers_id or just $customer_id but one of those should give you the current customer ID number.

osCommerce is a great piece of software with wonderful contributions.

Spend some time in the contribution area. There are a lot of gems there.

Link to comment
Share on other sites

Maybe something like

 

$my_query = tep_db_query("select customers_group_id from customers where customers_id = " . $customer_id);

 

$my_array = tep_db_fetch_array($my_query);

 

switch ($my_array['customers_group_id']) {

  case 1:

      do whatever;

      break;

  case 2:

      do whateer

    break;

}

 

etc.

 

For case X, will that refer to the array for the corresponding number? As in, if the found value is in fact 1, is it going to automatically run case 1? (Sincere apologizes for my PHP ignorance)

 

For the "do whatever" part, what kind of syntax do/can I use. Can I just use plain HTML? For example, will the following work:

 

$my_query = tep_db_query("select customers_group_id from customers where customers_id = " . $customer_id);

$my_array = tep_db_fetch_array($my_query);

switch ($my_array['customers_group_id']) {
  case 1:
     <a href="link1.html">Link 1</a>;
     break;
  case 2:
     <a href="link2.html">Link 2</a>;
     break;
}

 

???

Link to comment
Share on other sites

For case X, will that refer to the array for the corresponding number? As in, if the found value is in fact 1, is it going to automatically run case 1? (Sincere apologizes for my PHP ignorance)

 

For the "do whatever" part, what kind of syntax do/can I use. Can I just use plain HTML? For example, will the following work:

 

$my_query = tep_db_query("select customers_group_id from customers where customers_id = " . $customer_id);

$my_array = tep_db_fetch_array($my_query);

switch ($my_array['customers_group_id']) {
? case 1:
? ? ?<a href="link1.html">Link 1</a>;
? ? ?break;
? case 2:
? ? ?<a href="link2.html">Link 2</a>;
? ? ?break;
}

 

???

 

case x will be what gets pulled out of the database for customers_group_id.

 

If you want to add plain html in the case statement you need to delimit the php like

 

case 1:

?>

<a href="blah HTML">So on and so forth

<?php

break;

 

 

 

Also, if the user isn't logged in, you will probably want to add a default case to the end of oth switch so

 

case 1:

Blah

break;

 

case 2:

Blah

break;

 

default:

If user isn't logged in, or no matching case exists, do whatever

break;

osCommerce is a great piece of software with wonderful contributions.

Spend some time in the contribution area. There are a lot of gems there.

Link to comment
Share on other sites

case x will be what gets pulled out of the database for customers_group_id.

 

If you want to add plain html in the case statement you need to delimit the php like

 

case 1:

  ?>

    <a href="blah HTML">So on and so forth

  <?php

  break;

Also, if the user isn't logged in, you will probably want to add a default case to the end of oth switch so

 

case 1:

  Blah

  break;

 

case 2:

  Blah

  break;

 

default:

  If user isn't logged in, or no matching case exists, do whatever

  break;

 

That should work, I think I've got it down now. Thanks a lot for your help, I'll let you know how it turns out.

 

Thanks a million!

Link to comment
Share on other sites

By the way, I forgot to mention, if your placing hypertext links in osCommerce, you will want to use the syntax

 

echo '<a href="' . tep_href_link('mypage.php', 'my query string parameters') . '">link text</a>';

 

Otherwise your customers will loose their osCsid and their shopping cart at the same time.

 

Just FYI

osCommerce is a great piece of software with wonderful contributions.

Spend some time in the contribution area. There are a lot of gems there.

Link to comment
Share on other sites

By the way,  I forgot to mention,  if your placing hypertext links in osCommerce, you will want to use the syntax

 

echo '<a href="' . tep_href_link('mypage.php', 'my query string parameters') . '">link text</a>';

 

Otherwise your customers will loose their osCsid and their shopping cart at the same time.

 

Just FYI

 

Thanks, that will really come in handy later.

Link to comment
Share on other sites

Instead of ending the PHP everytime I want to add HTML, would it be better if I just used something like: echo '<a href="link.html">link text</a>'; inside of the PHP?

 

It's kind of a personal preference. The results end up the same. osCommerce has a bunch of HTML output functions that you can find in includes/functions/html_output.php but a lot of these aren't necessary. If I'm writing big table structures, I tend to delimit the php, however if it's just short peices of HTML I'll use the echo function.

osCommerce is a great piece of software with wonderful contributions.

Spend some time in the contribution area. There are a lot of gems there.

Link to comment
Share on other sites

Help! It's not working! I don't see anything at all.

 

Here's my code:

 

<!-- member_links //-->
 <tr>
   <td class="infoBox_right">
<?php
$my_query = tep_db_query("select customers_group_id from customers where customers_id = " . $customer_id);

$my_array = tep_db_fetch_array($my_query);

$info_box_contents = array();
$info_box_contents[] = array('text' => BOX_HEADING_MEMBER_LINKS);

new infoBoxHeading($info_box_contents, false, true, tep_href_link(FILENAME_MEMBER_LINKS));

switch ($my_array['customers_group_id']) {
  default:
     echo 'Please Logon to see Member Support Links.';
     break;
  case 0:
     echo 'Your Membership level is: Basic<br>Member Support Links are available to higher level members';
     break;
  case 1:
     echo 'Your Membership level is: Silver<br><a href="tickets.html">Support Tickets</a>';
     break;
  case 2:
     echo 'Your Membership level is: Gold<br><a href="tickets.html">Support Tickets</a><br><a href="phone.html">Phone Support</a><br><a href="chatsupport.html">Chat Support</a>';
     break;
  case 3:
     echo 'Your Membership level is: DotCom<br><a href="tickets.html">Support Tickets</a><br><a href="phone.html">Phone Support</a><br><a href="chatsupport.html">Chat Support</a><br><a href="sitestats.html">Your Sites Statistics</a><br><a href="siteadmin.html">Manage your Website</a>';
    break;
}

new infoBox($info_box_contents);
?>
   </td>
 </tr>
<!-- member_links_eof //-->

Link to comment
Share on other sites

Well right off the get go, I can see that your default clause is in the wrong place. You should always have your default case as the last case statement, otherwise none of the other cases will ever happen. I don't see any parse errors, but sometimes those are hard to see just by looking at it. I'll spend some more time reviewing it, but for now, make the default case the last one

osCommerce is a great piece of software with wonderful contributions.

Spend some time in the contribution area. There are a lot of gems there.

Link to comment
Share on other sites

Well right off the get go, I can see that your default clause is in the wrong place.  You should always have your default case as the last case statement, otherwise none of the other cases will ever happen.  I don't see any parse errors, but sometimes those are hard to see just by looking at it.  I'll spend some more time reviewing it, but for now, make the default case the last one

 

 

Thanks, although that didn't fix the problem, I never would have caught that.

Link to comment
Share on other sites

no luck yet...

 

Do you have error reporting turned on??? if not, you can turn it on in your php.ini file. do a search on error, and you should find it. THis will help find the error

osCommerce is a great piece of software with wonderful contributions.

Spend some time in the contribution area. There are a lot of gems there.

Link to comment
Share on other sites

Wondered if anyone had looked at the code and knew what was wrong.

 

Here's the code again:

 

<!-- member_links //-->
?<tr>
? ?<td class="infoBox_right">
<?php
$my_query = tep_db_query("select customers_group_id from customers where customers_id = " . $customer_id);

$my_array = tep_db_fetch_array($my_query);

$info_box_contents = array();
$info_box_contents[] = array('text' => BOX_HEADING_MEMBER_LINKS);

new infoBoxHeading($info_box_contents, false, true, tep_href_link(FILENAME_MEMBER_LINKS));

switch ($my_array['customers_group_id']) {
? default:
? ? ?echo 'Please Logon to see Member Support Links.';
? ? ?break;
? case 0:
? ? ?echo 'Your Membership level is: Basic<br>Member Support Links are available to higher level members';
? ? ?break;
? case 1:
? ? ?echo 'Your Membership level is: Silver<br><a href="tickets.html">Support Tickets</a>';
? ? ?break;
? case 2:
? ? ?echo 'Your Membership level is: Gold<br><a href="tickets.html">Support Tickets</a><br><a href="phone.html">Phone Support</a><br><a href="chatsupport.html">Chat Support</a>';
? ? ?break;
? case 3:
? ? ?echo 'Your Membership level is: DotCom<br><a href="tickets.html">Support Tickets</a><br><a href="phone.html">Phone Support</a><br><a href="chatsupport.html">Chat Support</a><br><a href="sitestats.html">Your Sites Statistics</a><br><a href="siteadmin.html">Manage your Website</a>';
? ? break;
}

new infoBox($info_box_contents);
?>
? ?</td>
?</tr>
<!-- member_links_eof //-->

Link to comment
Share on other sites

it appears harder than you thought. perhaps would be a good time to go back to the contribution already created . . totalb2b works well, and there are other contributions

why reinvent the wheel?

Link to comment
Share on other sites

I have yet to see a contribution that will do this. (I looked at Total B2B and all the rest) They all set special pricing for customer groups, but that's not what I want! I just want to make another InfoBox with links on it that differ depending on which group your in.

 

If someone knows of a contribution that will do that, please tell me, but the "special pricing per customer" type isn't going to help me any.

Link to comment
Share on other sites

Got error-checking to work, the error is in the SQL part of the following:

 

$my_query = tep_db_query("select customers_group_id from customers where customers_id = " . $customer_id);

I don't really see it, I'm guessing it's after the "=", but I wouldn't know what the correct syntax is.

 

Any help?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...